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

DNM: Adding ability to derive solona address #3692

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

micahriggan
Copy link
Contributor

@micahriggan micahriggan commented Jan 28, 2024

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

@micahriggan micahriggan changed the title Adding ability to derive solona address DNM: Adding ability to derive solona address Jan 28, 2024
Copy link
Collaborator

@kajoseph kajoseph left a 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');
Copy link
Collaborator

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();
Copy link
Collaborator

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}'`;
Copy link
Collaborator

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}'`;

leolambo added a commit to leolambo/bitcore that referenced this pull request Dec 10, 2024
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

Successfully merging this pull request may close these issues.

2 participants