Skip to content

Commit

Permalink
mnemonic lengths wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bokkypoobah committed Apr 17, 2024
1 parent 677d733 commit cc804c2
Showing 1 changed file with 54 additions and 17 deletions.
71 changes: 54 additions & 17 deletions docs/offline.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@

<b-card bg-variant="light" no-body class="p-0 m-1">
<b-tabs card align="left" no-body v-model="wallet.tab" active-tab-class="m-0 p-0">
<b-tab v-for="t in tabs" :key="'dyn-tabx-' + t.name" @click="updateURL(t.name);" :title="t.text" title-item-class="p-0" title-link-class="mt-2 px-2">
<b-tab v-for="t in tabs" :key="'dyn-tabx-' + t.name" @click="updateURL(t.name);" :title="t.text" title-item-class="p-0" title-link-class="mt-2 px-3">
</b-tab>
</b-tabs>
<b-card-text class="m-0 p-2">

<b-form-group v-if="wallet.tab == 3" label="New Wallet:" label-for="wallet-new" label-size="sm" label-cols-sm="2" label-align-sm="right" class="mx-0 my-1 p-0">
<b-form-group v-if="wallet.tab == 3" label="Number of words:" label-for="wallet-numberofwords" label-size="sm" label-cols-sm="2" label-align-sm="right" class="mx-0 my-1 p-0">
<b-form-select size="sm" id="wallet-numberofwords" v-model="wallet.randomBytesLength" @change="recomputeWallet();" :options="randomBytesLengthMnemonicWordsOptions" class="w-25"></b-form-select>
</b-form-group>

<b-form-group v-if="wallet.tab == 3" label="" label-for="wallet-new" label-size="sm" label-cols-sm="2" label-align-sm="right" class="mx-0 my-1 p-0">
<b-button size="sm" id="wallet-new" @click="newWallet()" variant="warning">Generate</b-button>
</b-form-group>

Expand Down Expand Up @@ -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,
Expand All @@ -225,6 +229,7 @@
keystoreFilePassword: null,
keystoreFileContent: null,
privateKey: null,
randomBytesLength: 16, // 12 words
newWallet: null,

publicKey: null,
Expand Down Expand Up @@ -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: [
Expand All @@ -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 ---
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cc804c2

Please sign in to comment.