1
var sign = function sign(message, secretKey) {
  return ed25519.ed25519.sign(message, secretKey.slice(0, 32));
};

This is what the official @solana/web3.js library does to sign a transaction. Is this because ed25519 is limited to 32-bytes or even other blockchains are using only half of the private key? What are the benefits of having a 64-bytes private key if only half of it is necessary to sign any transaction?

1 Answer 1

3

Without getting too into the weeds, Ed25519 signing uses both the public key and the private key.

The 64 bytes you see in the Keypair class of @solana/web3.js is actually the Ed25519 key-pair. The first half is the seed used to derive the private scalar and the second half is the actual public key itself.

In fact, if you convert the second half of the key-pair bytes into a base58 string, you'll get your Solana address!

@solana/web3.js doesn't need to pass both keys to the ed25519 library since that library uses the seed to derive both the private scalar and the public key.

https://github.com/paulmillr/noble-curves/blob/7f851873f97e55b7e4e46457c268f61400887ba3/src/abstract/edwards.ts#L448

As far as your specific question as to why they're included together in the first place, this was likely a design choice made by engineers for a few possible reasons, including:

  • compatibility with libraries who expect the 64-byte format
  • increased performance (don't need to compute the public key from the seed)
  • possibly others

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.