From cc804c2219e7667a762c7fe9d7b8aec318b45c25 Mon Sep 17 00:00:00 2001 From: BokkyPooBah Date: Wed, 17 Apr 2024 22:06:28 +1000 Subject: [PATCH] mnemonic lengths wip --- docs/offline.html | 71 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 17 deletions(-) diff --git a/docs/offline.html b/docs/offline.html index 10eb845..82ff0f8 100644 --- a/docs/offline.html +++ b/docs/offline.html @@ -66,12 +66,16 @@ - + - + + + + + Generate @@ -214,7 +218,7 @@ // --- DATA --- data: { wallet: { - tab: 0, // 0: 'mnemonic', 1: 'keystorefile', 2: 'privatekey', 3: 'new' + tab: 3, // 0: 'mnemonic', 1: 'keystorefile', 2: 'privatekey', 3: 'new' type: 'mnemonic', // 'mnemonic', 'keystorefile', 'privatekey' mnemonic: { phrase: null, @@ -225,6 +229,7 @@ keystoreFilePassword: null, keystoreFileContent: null, privateKey: null, + randomBytesLength: 16, // 12 words newWallet: null, publicKey: null, @@ -256,7 +261,7 @@ { name: 'mnemonic', text: 'Mnemonic Seed Phrase' }, { name: 'keystorefile', text: 'JSON/UTC Keystore File' }, { name: 'privatekey', text: 'Private Key' }, - { name: 'new', text: 'New Wallet' }, + { name: 'new', text: 'Create New' }, ], walletTypeOptions: [ @@ -265,6 +270,14 @@ { value: 'privatekey', text: 'Private Key' }, ], + randomBytesLengthMnemonicWordsOptions: [ + { value: 16, text: '12 Words' }, + { value: 20, text: '15 Words' }, + { value: 24, text: '18 Words' }, + { value: 28, text: '21 Words' }, + { value: 32, text: '24 Words' }, + ], + }, // --- COMPUTED --- @@ -283,22 +296,32 @@ newWallet() { console.log(moment().format("HH:mm:ss") + " newWallet"); + console.log(moment().format("HH:mm:ss") + " newWallet - this.wallet.randomBytesLength: " + this.wallet.randomBytesLength); + try { - const wallet = new ethers.Wallet.createRandom(); - console.table(wallet); - this.wallet.address = wallet.address; - this.wallet.privateKey = wallet.privateKey; - console.log("wallet.privateKey: " + wallet.privateKey); - console.log("wallet.mnemonic: " + JSON.stringify(wallet.mnemonic)); - this.wallet.mnemonic.phrase = wallet.mnemonic.phrase; - this.wallet.mnemonic.path = wallet.mnemonic.path; - this.wallet.mnemonic.locale = wallet.mnemonic.locale; - this.wallet.newWallet = wallet; - // this.wallet.publicKey = wallet.publicKey; - // this.wallet.compressedPublicKey = ethers.utils.computePublicKey(wallet.publicKey, true); + const randomBytes = ethers.utils.randomBytes(this.wallet.randomBytesLength); + const m = ethers.utils.entropyToMnemonic(randomBytes); + console.log(moment().format("HH:mm:ss") + " newWallet - randomBytes[" + length + "]: " + JSON.stringify(m)); } catch (e) { console.log(moment().format("HH:mm:ss") + " newWallet ERROR: " + e.message); } + + // try { + // const wallet = new ethers.Wallet.createRandom(); + // console.table(wallet); + // this.wallet.address = wallet.address; + // this.wallet.privateKey = wallet.privateKey; + // console.log("wallet.privateKey: " + wallet.privateKey); + // console.log("wallet.mnemonic: " + JSON.stringify(wallet.mnemonic)); + // this.wallet.mnemonic.phrase = wallet.mnemonic.phrase; + // this.wallet.mnemonic.path = wallet.mnemonic.path; + // this.wallet.mnemonic.locale = wallet.mnemonic.locale; + // this.wallet.newWallet = wallet; + // // this.wallet.publicKey = wallet.publicKey; + // // this.wallet.compressedPublicKey = ethers.utils.computePublicKey(wallet.publicKey, true); + // } catch (e) { + // console.log(moment().format("HH:mm:ss") + " newWallet ERROR: " + e.message); + // } }, async downloadKeystore() { @@ -344,7 +367,7 @@ } catch (e) { console.log(moment().format("HH:mm:ss") + " recomputeWallet - keystorefile ERROR: " + e.message); } - } else if (this.wallet.tab == 2){ + } else if (this.wallet.tab == 2) { console.log(moment().format("HH:mm:ss") + " recomputeWallet - privatekey: " + JSON.stringify(this.wallet)); try { const wallet = new ethers.Wallet(this.wallet.privateKey); @@ -378,6 +401,20 @@ console.log(moment().format("HH:mm:ss") + " testIt - randomBytes[" + length + "]: " + JSON.stringify(m)); } + + // bytes length, mnemonic words + // 16, 12 + // 20, 15 + // 24, 18 + // 28, 21 + // 32, 24 + + // offline.html:378 18:35:10 testIt - randomBytes[16]: "crew ridge trash elbow tiny theme open exotic call giraffe tray drill" + // offline.html:378 18:35:10 testIt - randomBytes[20]: "curtain awkward stem improve meadow whisper knee enlist try worry guard devote behave cabbage top" + // offline.html:378 18:35:10 testIt - randomBytes[24]: "present drastic plastic bring section hamster cable elbow despair first dutch mystery modify kind thing swim clog art" + // offline.html:378 18:35:10 testIt - randomBytes[28]: "afraid path security exile cave rhythm autumn now digital glory cricket unusual meat drill bonus ring rain inhale fabric thunder wish" + // offline.html:378 18:35:10 testIt - randomBytes[32]: "comic salt ignore veteran web search window horn tackle act asset jaguar shoe position bundle balance jealous box ticket barrel also ceiling radar ball" + // const jsonText = '{"version":3,"id":"e14b94f9-cabc-445c-9b8a-ea090540d8db","address":"62325d923da56ab815367aa591c0a10cff1d0ddd","crypto":{"ciphertext":"4f19f96b36100b1b54d95f4106e38949cd56967dcba919d814ab962fed3b688b","cipherparams":{"iv":"befb0e2386402c71e06dd3d2cca4f828"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"67d0ff891bbbbe29eb98828bae566f5a31c131ff05f207b22f4ff2bcc7643bc6","n":8192,"r":8,"p":1},"mac":"7092eb22b1d4c58ff07ff913555fe2ca5a36040f51c4edfbccf1ddfb49216f70"}}'; // const password = ''; // const json = JSON.parse(jsonText);