Je suis en train de lire le code, c’est vraiment un fork de signal encore rattaché à son dépôt mère.
C’est du beau TypeScript, agréable à lire.
Aaaahh les batards, faut qu’on fork juste pour ça!
C’est abusé, leur mnemonic fait 13 mots ! Juste pour faire chier quoi
Alors en fait c’est 12 mots + un mot checksum:
export async function generateMnemonic() {
// Note: 4 bytes are converted into 3 seed words, so length 12 seed words
// (13 - 1 checksum) are generated using 12 * 4 / 3 = 16 bytes.
const seedSize = 16;
const seed = (await getSodiumRenderer()).randombytes_buf(seedSize);
const hex = toHex(seed);
return mnEncode(hex);
}
…
export function mnEncode(str: string, wordsetName: string = MN_DEFAULT_WORDSET): string {
const wordset = mnWords[wordsetName];
let out = [] as Array<any>;
const n = wordset.words.length;
let strCopy = str;
for (let j = 0; j < strCopy.length; j += 8) {
strCopy =
strCopy.slice(0, j) + mn_swap_endian_4byte(strCopy.slice(j, j + 8)) + strCopy.slice(j + 8);
}
for (let i = 0; i < strCopy.length; i += 8) {
const x = parseInt(strCopy.substr(i, 8), 16);
const w1 = x % n;
const w2 = (Math.floor(x / n) + w1) % n;
const w3 = (Math.floor(Math.floor(x / n) / n) + w2) % n;
out = out.concat([wordset.words[w1], wordset.words[w2], wordset.words[w3]]);
}
if (wordset.prefixLen > 0) {
out.push(out[mn_get_checksum_index(out, wordset.prefixLen)]);
}
return out.join(' ');
}
…
// Verify checksum
if (wordset.prefixLen > 0) {
const index = mn_get_checksum_index(wlist, wordset.prefixLen);
const expectedChecksumWord = wlist[index];
if (
expectedChecksumWord.slice(0, wordset.prefixLen) !== checksumWord.slice(0, wordset.prefixLen)
) {
throw new VerificationError();
}
}
…
function mn_get_checksum_index(words: Array<string>, prefixLen: number) {
let trimmedWords = '';
for (let i = 0; i < words.length; i++) {
trimmedWords += words[i].slice(0, prefixLen);
}
const checksum = crc32.unsigned(trimmedWords as any);
const index = checksum % words.length;
return index;
}
Trop bizarre.