Hi all I'm trying to develop my own deterministic key hierarchy with BIP-44 , BIP-39 and BIP-32. The initial part of the project is done:

  1. I generated the seed phrase thanks to BIP-39;
  2. I created my master node and its private key thanks to BIP-32;
  3. Now I'm trying to use branch paths to make my hierarchy work on other blockchains (I've already created addresses for BTC,ETH,BNB and SOL).

If I run my code, importing a previously generated seed phrase, the addresses I generated earlier become visible again, so it works. Unfortunately, however, it only works with the first three cryptocurrencies and not with Solana.

I show you the code I used to generate the Solana key pair (I used the module tweetnacl-js on Node.js)

> const path = \m/44'/501'/0'/0/0`;
> const child =masterNode.derivePath(path);
> console.log("\n---------Solana---------\n" )  
> const keyPair =nacl.sign.keyPair.fromSecretKey(child.privateKey); 
> const publicKeySol = bs58.encode(keyPair.publicKey);
> bs58.encode(keyPair.secretKey); 
> console.log(${coin} address:${publicKeySol});

As you can see, i used the function fromSecretKey to derive the private key. I think this is the right one. From documentation of tweetnacl-js. When I run the code, it (rightly) gives me this error: "Error: bad secret key size"

Since the private key that the master node generates is 32 bytes and is a Buffer, while the fromSecretKey function, from Doc , says: "Returns a signing key pair with public key corresponding to the given 64-byte secret key. The secret key must have been generated by nacl.sign.keyPair or nacl.sign.keyPair.fromSeed."

Is there a way to convert the child's private key to the correct format? Is there another library that allows you to do this that I don't know about? What do you think? I'm on the right track?

Thank you all in advance <3

1 Answer 1


You're very close! Since you have the private key, you can derive the public key and create a normal keypair using fromSeed instead of fromSecretKey, as the docs say.

Here's the tweetnacl function in the docs: https://www.npmjs.com/package/tweetnacl#naclsignkeypairfromseedseed

  • but the seed I should pass to the function, can't be child.privateKey , or can I put it? Should i pass the general seed of the master node? I don't think this should be used as it is needed to have access to all accounts, am I wrong?
    – AlexCav
    Apr 11, 2023 at 9:45
  • You should put child.privateKey. Unless I've misunderstood, the whole point is that you've derived the child seed from the master, and now you want a usable private key for the child, correct?
    – Jon C
    Apr 12, 2023 at 10:18
  • Yes, it's correct, so i should use this one. Thank you.
    – AlexCav
    Apr 12, 2023 at 10:56
  • Can i contact you in private for other questions for develop a crypto wallet non custodial?
    – AlexCav
    Apr 12, 2023 at 10:58
  • Sorry, I think it's better to keep conversations out in the open, that way you can get answers from more people!
    – Jon C
    Apr 12, 2023 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.