mirror of
https://github.com/sigmasternchen/axowall
synced 2025-03-15 08:38:55 +00:00
split into files
This commit is contained in:
parent
d6e10060fb
commit
626888fbd9
3 changed files with 43 additions and 41 deletions
18
src/content.js
Normal file
18
src/content.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
const suffixCharset = [
|
||||||
|
"0123456789",
|
||||||
|
"abcdefghijklmnopqrstuvwxyz",
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||||
|
"+-",
|
||||||
|
].flatMap(set => set.split(""));
|
||||||
|
const suffixCharsetBits = 6;
|
||||||
|
|
||||||
|
export function makeSuffix(index) {
|
||||||
|
let result = "";
|
||||||
|
|
||||||
|
while (index > 0) {
|
||||||
|
result += suffixCharset[index & ((1 << suffixCharsetBits) - 1)];
|
||||||
|
index >>= suffixCharsetBits;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
23
src/hash.js
Normal file
23
src/hash.js
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
const hexCharset = "0123456789abcdef".split("");
|
||||||
|
|
||||||
|
export const sha256 = "SHA-256";
|
||||||
|
|
||||||
|
Uint8Array.prototype.toHex = function() {
|
||||||
|
return [...this].map(c => hexCharset[c >> 4] + hexCharset[c & 15]).join("");
|
||||||
|
};
|
||||||
|
|
||||||
|
Uint8Array.prototype.hasPrefix = function(array, bits) {
|
||||||
|
for(let i = 0; i < array.length && i * 8 < bits; i++) {
|
||||||
|
const bitsForByte = Math.min(8, bits - i * 8);
|
||||||
|
const bitMask = ((1 << bitsForByte) - 1) << (8 - bitsForByte);
|
||||||
|
|
||||||
|
if ((this[i] & bitMask) != (array[i] & bitMask)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function digest(algo, input) {
|
||||||
|
return new Uint8Array(await crypto.subtle.digest(algo, new TextEncoder().encode(input)));
|
||||||
|
}
|
43
src/main.js
43
src/main.js
|
@ -1,44 +1,5 @@
|
||||||
const hexCharset = "0123456789abcdef".split("");
|
import {makeSuffix} from "./content";
|
||||||
const suffixCharset = [
|
import {digest, sha256} from "./hash";
|
||||||
"0123456789",
|
|
||||||
"abcdefghijklmnopqrstuvwxyz",
|
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
||||||
"+-",
|
|
||||||
].flatMap(set => set.split(""));
|
|
||||||
const suffixCharsetBits = 6;
|
|
||||||
|
|
||||||
const sha256 = "SHA-256";
|
|
||||||
|
|
||||||
Uint8Array.prototype.toHex = function() {
|
|
||||||
return [...this].map(c => hexCharset[c >> 4] + hexCharset[c & 15]).join("");
|
|
||||||
};
|
|
||||||
|
|
||||||
Uint8Array.prototype.hasPrefix = function(array, bits) {
|
|
||||||
for(let i = 0; i < array.length && i * 8 < bits; i++) {
|
|
||||||
const bitsForByte = Math.min(8, bits - i * 8);
|
|
||||||
const bitMask = ((1 << bitsForByte) - 1) << (8 - bitsForByte);
|
|
||||||
|
|
||||||
if ((this[i] & bitMask) != (array[i] & bitMask)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
async function digest(algo, input) {
|
|
||||||
return new Uint8Array(await crypto.subtle.digest(algo, new TextEncoder().encode(input)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeSuffix(index) {
|
|
||||||
let result = "";
|
|
||||||
|
|
||||||
while (index > 0) {
|
|
||||||
result += suffixCharset[index & ((1 << suffixCharsetBits) - 1)];
|
|
||||||
index >>= suffixCharsetBits;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function findHashWithPrefix(hashPrefixBits, inputPrefix) {
|
async function findHashWithPrefix(hashPrefixBits, inputPrefix) {
|
||||||
const hashPrefix = new Uint8Array(Array(Math.ceil(hashPrefixBits / 8)).map(c => 0));
|
const hashPrefix = new Uint8Array(Array(Math.ceil(hashPrefixBits / 8)).map(c => 0));
|
||||||
|
|
Loading…
Reference in a new issue