Merge pull request #386 from sachaaaaa/13wordseed

Generate 13 word seeds by default - still accept 25 word seeds.
This commit is contained in:
sachaaaaa 2019-08-09 17:12:31 +10:00 committed by GitHub
commit d424d89fb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -123,7 +123,13 @@
let generateKeypair; let generateKeypair;
if (mnemonic) { if (mnemonic) {
generateKeypair = () => { generateKeypair = () => {
const seedHex = window.mnemonic.mn_decode(mnemonic, mnemonicLanguage); let seedHex = window.mnemonic.mn_decode(mnemonic, mnemonicLanguage);
// handle shorter than 32 bytes seeds
const privKeyHexLength = 32 * 2;
if (seedHex.length !== privKeyHexLength) {
seedHex = seedHex.concat(seedHex);
seedHex = seedHex.substring(0, privKeyHexLength);
}
const privKeyHex = window.mnemonic.sc_reduce32(seedHex); const privKeyHex = window.mnemonic.sc_reduce32(seedHex);
const privKey = dcodeIO.ByteBuffer.wrap( const privKey = dcodeIO.ByteBuffer.wrap(
privKeyHex, privKeyHex,
@ -517,8 +523,11 @@
}); });
}, },
async generateMnemonic(language = 'english') { async generateMnemonic(language = 'english') {
const keys = await libsignal.KeyHelper.generateIdentityKeyPair(); // Note: 4 bytes are converted into 3 seed words, so length 12 seed words
const hex = StringView.arrayBufferToHex(keys.privKey); // (13 - 1 checksum) are generated using 12 * 4 / 3 = 16 bytes.
const seedSize = 16;
const seed = window.Signal.Crypto.getRandomBytes(seedSize);
const hex = StringView.arrayBufferToHex(seed);
return mnemonic.mn_encode(hex, language); return mnemonic.mn_encode(hex, language);
}, },
getCurrentMnemonic() { getCurrentMnemonic() {