core-js
core-js copied to clipboard
Feature for Extended Private Key utility function
New issue checklist
- [x] I have read all of the
README
- [x] I have searched existing issues and this is not a duplicate.
Question or Feature Request
Right now the path for Extended PrivateKeys is a string. Which is not really suited for manipulation. I was thinking about a utility function that makes creating new paths easier. For example you could create an iteration and generate 20 wallets for an account fast. I was wondering if there is a demand for such a method.
I created a quick demo method to illustratie what I mean
let utility = pathArray => {
let result = new String();
if(pathArray.length === 5) {
result = pathArray.reduce((x, y) => `${x}/${y}'`)
}
else if(pathArray.length === 2) {
result = ['m', 44, 242].concat(pathArray).reduce((x, y) => `${x}/${y}'`)
}
if(!Nimiq.ExtendedPrivateKey.isValidPath(result)) {
throw new Error("The path is invalid.");
}
return result
}
let pathString = utility(['m', 44, 242, 0, 0]);
// pathString: m/44'/242'/0'/0'
let otherPathString = utility([1, 0]);
// otherPathString: m/44'/242'/1'/0'
let pathArray = Array.apply(null, {length: 5})
.map(Number.call, Number)
.map((_, i) => utility([0,i]))
/*
pathArray =
[ 'm/44\'/242\'/0\'/0\'',
'm/44\'/242\'/0\'/1\'',
'm/44\'/242\'/0\'/2\'',
'm/44\'/242\'/0\'/3\'',
'm/44\'/242\'/0\'/4\'' ]
*/
I'm closing this stalled issue, but please feel free to reopen it if you still want to build this utility :-)
I belive we will keep lots of core-js also for Albatross since everything around the protocol didn't change, or only minimally.
So I think this is something that should still be added to ExtendedPrivateKey.derivePath
, to also accept an array.