okx / go-wallet-sdk

Multi-chain golang signature sdk, supports bitcoin, ethereum, aptos, cosmos, etc.
MIT License
341 stars 111 forks source link

Solana Chain Derivation Path #25

Closed wgx731 closed 7 months ago

wgx731 commented 8 months ago

Hi OKX Team,

By following https://www.okx.com/web3/build/docs/build-dapp/private-key-wallet-go-sdk#supported-coins, the Solana chain derivation path should be m/44'/501'/0'/0/0, but during my test, using the same 12-word recovery phrase, the actual OKX wallet generated key is different from the key generated using the mentioned derivation path (https://github.com/okx/go-wallet-sdk/blob/main/crypto/bip32/bip32.go#L43 is used), also from https://www.exodus.com/support/article/1795-derivation-paths-in-exodus#other-derivation-paths mentions m/44'/501'/0'/0' is the derivation path, I tried it with no luck as well.

Could you please help update the documentation with the correct derivation path used for the Solana chain?

Thank you.

wgx731 commented 7 months ago

Hi all,

I have discovered the issue and here is the solution if you face the same issue. I was using https://github.com/tyler-smith/go-bip32 to generate the master key from mnemonic like for other evm chains, note on https://github.com/tyler-smith/go-bip32/blob/master/bip32.go#L61 Bitcoin seed is used as seed key for hmac.New whereas for solana ed25519 seed should be used. https://github.com/stellar/go/blob/master/exp/crypto/derivation/main.go#L43 can be used to find out the correct MasterKey and DeriveKey in this case or you can implement your own MasterKey function for bip32.

Cheers.