DNM: Adding ability to derive solona address#3692
Conversation
kajoseph
left a comment
There was a problem hiding this comment.
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.
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.
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.
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