-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
DNM: Adding ability to derive solona address #3692
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to function fine. I left a few comments below.
It would be pretty easy to modify bitcore-mnemonic/lib
to get a ed25519 seed instead of a secp256k1 (Just a one-line change). Otherwise, it would require importing another lib to convert a mnemonic to a seed. 👎
I started going down the path of making bitcore-lib
fully SLIP-10 compliant (deriving ed25519 keys) and it's fairly substantial - doable but well beyond the scope of this PR, especially because it would require a move away from the elliptic
lib (which is probably a good idea anyway).
} | ||
|
||
deriveAddressWithPath(network: string, xpubKey: string, path: string) { | ||
throw new Error('Cannot derive solona addresses from just xpubkey, need to use derivePrivateKeyWithPath'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a hack around changing the fn signature in derivation/index.ts
is to do something like
if (true) {
throw ...
} else {
return '';
}
} | ||
|
||
addressFromPublicKeyBuffer(pubKey: Buffer): string { | ||
return Base58.fromBuffer(pubKey).toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplify to return new web3.PublicKey(pubKey).toString();
|
||
derivePrivateKey(network, xPriv, addressIndex, isChange) { | ||
const changeNum = isChange ? 1 : 0; | ||
const path = `m/${changeNum}'/${addressIndex}'`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like Solana/Phantom has the account index in the first position. (REF: https://help.phantom.app/hc/en-us/articles/12988493966227-What-derivation-paths-does-Phantom-wallet-support)
const path = `m/${addressIndex}'/${changeNum}'`;
Just wanted to see what it'd take to be able to derive the SOL address from what is already in this lib
I ref'd this blog post for an example of address derivation
https://www.abiraja.com/blog/from-seed-phrase-to-solana-address
These docs were useful too
https://solanacookbook.com/references/keypairs-and-wallets.html#how-to-generate-a-mnemonic-phrase