Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature for Extended Private Key utility function #478

Open
2 tasks done
Eligioo opened this issue Feb 12, 2019 · 2 comments
Open
2 tasks done

Feature for Extended Private Key utility function #478

Eligioo opened this issue Feb 12, 2019 · 2 comments

Comments

@Eligioo
Copy link
Member

Eligioo commented Feb 12, 2019

New issue checklist

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\''  ]
*/
@jeffesquivels
Copy link
Member

I'm closing this stalled issue, but please feel free to reopen it if you still want to build this utility :-)

@sisou
Copy link
Member

sisou commented Sep 28, 2022

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.

@sisou sisou reopened this Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants