ed2curve-js icon indicating copy to clipboard operation
ed2curve-js copied to clipboard

Using 64 byte extended (expanded) secret keys

Open gitmachtl opened this issue 2 years ago • 2 comments

Hi,

first, awesome lib! 👍

I am running in troubles, because i need a function to convert ed25519 extended keys into a curve25519 one, so i can later do a DH on it. Theses extended keys are used on the cardano blockchain and i think follow the NaCl: https://cips.cardano.org/cips/cip16/ BIP32-Ed25519 extended keys (Ed25519 extended keys with BIP32-style derivation)

Do you see a chance to update the convertSecretKey function do also convert such extended keys?

Example keys:

PrvKey: 78d4bd66ecfe2f828ccb819ab85ed3afee813b06f70e6690a2ed527c1fc709516b7cc91a85aadee46927ee32e87e6fba60d4d9e4fe2527763bc57fe3eec8cbf9
PubKey: cd6d71f11cbd2f63326e5a50d7141a9443bd0f16f4b02f3f2f4d40acc5f83294

Best regards, Martin

gitmachtl avatar Dec 04 '22 10:12 gitmachtl

Hi,

I'm no expert, so I'm not sure if I am providing the right answer, but Ed25519 private keys are usually 64 bytes long, and they are usually encoded so that the first half (32bytes) is the secret key and the second half is the public key.

In the convertSecretKey function, it already processes only the first 32 bytes of the secret key, so it should work correctly. Are you asking about the 96 bytes extended keys that also contain the chain code in 32 bytes?

jose-gataca avatar Dec 13 '22 17:12 jose-gataca

Hi, yes normally. But extended ed25519 keys have real 64 bytes for the keypart. Can be extended further with a chaincode, but not a must. But most of the time yes, 64 byte secret key + 32 byte chaincode. or, 64 byte secret key + 32 byte public key + 32 byte chaincode.

gitmachtl avatar Dec 14 '22 13:12 gitmachtl