From 66f08477cfff2bf5d20b01a7c78805f0e39c2319 Mon Sep 17 00:00:00 2001 From: Pavlos Tzegiannakis Date: Mon, 23 Mar 2020 16:50:58 +0200 Subject: [PATCH] Fixes for ALGO, AION, NEM. Auto-increment account index in path correctly --- bip39-standalone.html | 30 ++++++++++-------------------- src/js/aionjs.js | 7 ++----- src/js/algorandjs.js | 7 ++----- src/js/index.js | 6 +++--- src/js/nemjs.js | 10 +++------- 5 files changed, 20 insertions(+), 40 deletions(-) diff --git a/bip39-standalone.html b/bip39-standalone.html index 4eec849..d9e4e9a 100644 --- a/bip39-standalone.html +++ b/bip39-standalone.html @@ -190825,16 +190825,12 @@

This project is 100% open-source code

var HDNode = require("./util/hdnode"); var nem = require("nem-sdk").default; -var counter = 0; - window.nemUtil = { - account: function account(mnemonic, passphrase) { + account: function account(mnemonic, passphrase,accountIndex) { var seed = bip39.mnemonicToSeed(mnemonic, passphrase); var root = HDNode.fromSeedBuffer(seed); - - var accountNumberInPath = counter.toString(); - counter++; - var nemCustomPath = "m/44'/43'/" + accountNumberInPath + "'/0'/0'"; + + var nemCustomPath = "m/44'/43'/" + accountIndex.toString() + "'/0'/0'"; var node = root.derivePath(nemCustomPath); /* Check this hard coded path */ var secretKey = nem.utils.convert.hex2ua_reversed(node.getPrivateKeyHex()); @@ -337969,7 +337965,6 @@

This project is 100% open-source code

var replaceDerive = function replaceDerive(val) { return val.replace("'", ''); }; -var counter = 0; var getMasterKeyFromSeed = function getMasterKeyFromSeed(seed) { var hmac = createHmac('sha512', ED25519_CURVE); @@ -338032,13 +338027,11 @@

This project is 100% open-source code

} window.algorandUtil = { - account: function account(mnemonic, passphrase) { + account: function account(mnemonic, passphrase, accountIndex) { var seed = bip39.mnemonicToSeed(mnemonic, passphrase); - var accountNumberInPath = counter.toString(); - counter++; - var algoPath = "m/44'/283'/" + accountNumberInPath + "'/0'/0'"; + var algoPath = "m/44'/283'/" + accountIndex.toString() + "'/0'/0'"; var childKeys = derivePath(algoPath, seed); @@ -379186,7 +379179,6 @@

This project is 100% open-source code

var replaceDerive = function replaceDerive(val) { return val.replace("'", ''); }; -var counter = 0; var getMasterKeyFromSeed = function getMasterKeyFromSeed(seed) { var hmac = createHmac('sha512', ED25519_CURVE); @@ -379248,13 +379240,11 @@

This project is 100% open-source code

} window.aionUtil = { - account: function account(mnemonic, passphrase) { + account: function account(mnemonic, passphrase, accountIndex) { var seed = bip39.mnemonicToSeed(mnemonic, passphrase); - var accountNumberInPath = counter.toString(); - counter++; - var algoPath = "m/44'/425'/" + accountNumberInPath + "'/0'/0'"; + var algoPath = "m/44'/425'/" + accountIndex.toString() + "'/0'/0'"; var childKeys = derivePath(algoPath, seed); @@ -386472,7 +386462,7 @@

This project is 100% open-source code

var phrase = DOM.phrase.val(); var passphrase = DOM.passphrase.val(); - var nemAccount = nemUtil.account(phrase,passphrase); + var nemAccount = nemUtil.account(phrase,passphrase,index); privkey = nemAccount.privKey; pubkey = nemAccount.publicKey; @@ -386483,7 +386473,7 @@

This project is 100% open-source code

var phrase = DOM.phrase.val(); var passphrase = DOM.passphrase.val(); - var algoAccount = algorandUtil.account(phrase,passphrase); + var algoAccount = algorandUtil.account(phrase,passphrase, index); privkey = algoAccount.privKey; pubkey = algoAccount.publicKey; @@ -386494,7 +386484,7 @@

This project is 100% open-source code

var phrase = DOM.phrase.val(); var passphrase = DOM.passphrase.val(); - var aionAccount = aionUtil.account(phrase,passphrase); + var aionAccount = aionUtil.account(phrase,passphrase, index); privkey = aionAccount.privKey; pubkey = aionAccount.publicKey; diff --git a/src/js/aionjs.js b/src/js/aionjs.js index 6fdc051..a6327e7 100644 --- a/src/js/aionjs.js +++ b/src/js/aionjs.js @@ -41120,7 +41120,6 @@ naclFactory.instantiate(function (nacl) { var replaceDerive = function replaceDerive(val) { return val.replace("'", ''); }; -var counter = 0; var getMasterKeyFromSeed = function getMasterKeyFromSeed(seed) { var hmac = createHmac('sha512', ED25519_CURVE); @@ -41182,13 +41181,11 @@ function fixAddressPrefix(address){ } window.aionUtil = { - account: function account(mnemonic, passphrase) { + account: function account(mnemonic, passphrase, accountIndex) { var seed = bip39.mnemonicToSeed(mnemonic, passphrase); - var accountNumberInPath = counter.toString(); - counter++; - var algoPath = "m/44'/425'/" + accountNumberInPath + "'/0'/0'"; + var algoPath = "m/44'/425'/" + accountIndex.toString() + "'/0'/0'"; var childKeys = derivePath(algoPath, seed); diff --git a/src/js/algorandjs.js b/src/js/algorandjs.js index 49d23cc..cc43414 100644 --- a/src/js/algorandjs.js +++ b/src/js/algorandjs.js @@ -41939,7 +41939,6 @@ naclFactory.instantiate(function (nacl) { var replaceDerive = function replaceDerive(val) { return val.replace("'", ''); }; -var counter = 0; var getMasterKeyFromSeed = function getMasterKeyFromSeed(seed) { var hmac = createHmac('sha512', ED25519_CURVE); @@ -42002,13 +42001,11 @@ function encode(address) { } window.algorandUtil = { - account: function account(mnemonic, passphrase) { + account: function account(mnemonic, passphrase, accountIndex) { var seed = bip39.mnemonicToSeed(mnemonic, passphrase); - var accountNumberInPath = counter.toString(); - counter++; - var algoPath = "m/44'/283'/" + accountNumberInPath + "'/0'/0'"; + var algoPath = "m/44'/283'/" + accountIndex.toString() + "'/0'/0'"; var childKeys = derivePath(algoPath, seed); diff --git a/src/js/index.js b/src/js/index.js index 6be1ddc..1fe3375 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -1011,7 +1011,7 @@ var phrase = DOM.phrase.val(); var passphrase = DOM.passphrase.val(); - var nemAccount = nemUtil.account(phrase,passphrase); + var nemAccount = nemUtil.account(phrase,passphrase,index); privkey = nemAccount.privKey; pubkey = nemAccount.publicKey; @@ -1022,7 +1022,7 @@ var phrase = DOM.phrase.val(); var passphrase = DOM.passphrase.val(); - var algoAccount = algorandUtil.account(phrase,passphrase); + var algoAccount = algorandUtil.account(phrase,passphrase, index); privkey = algoAccount.privKey; pubkey = algoAccount.publicKey; @@ -1033,7 +1033,7 @@ var phrase = DOM.phrase.val(); var passphrase = DOM.passphrase.val(); - var aionAccount = aionUtil.account(phrase,passphrase); + var aionAccount = aionUtil.account(phrase,passphrase, index); privkey = aionAccount.privKey; pubkey = aionAccount.publicKey; diff --git a/src/js/nemjs.js b/src/js/nemjs.js index 7117c62..6bd84c3 100644 --- a/src/js/nemjs.js +++ b/src/js/nemjs.js @@ -114058,16 +114058,12 @@ var bip39 = require("bip39"); var HDNode = require("./util/hdnode"); var nem = require("nem-sdk").default; -var counter = 0; - window.nemUtil = { - account: function account(mnemonic, passphrase) { + account: function account(mnemonic, passphrase,accountIndex) { var seed = bip39.mnemonicToSeed(mnemonic, passphrase); var root = HDNode.fromSeedBuffer(seed); - - var accountNumberInPath = counter.toString(); - counter++; - var nemCustomPath = "m/44'/43'/" + accountNumberInPath + "'/0'/0'"; + + var nemCustomPath = "m/44'/43'/" + accountIndex.toString() + "'/0'/0'"; var node = root.derivePath(nemCustomPath); /* Check this hard coded path */ var secretKey = nem.utils.convert.hex2ua_reversed(node.getPrivateKeyHex());