paulmillr / noble-curves

Audited & minimal JS implementation of elliptic curve cryptography.
https://paulmillr.com/noble
MIT License
623 stars 56 forks source link

u coordinate expected 56 bytes, got 57 #66

Closed Icehunter closed 12 months ago

Icehunter commented 12 months ago

Here's an example in codesandbox:

https://codesandbox.io/s/morning-currying-59ptsd?file=/src/App.tsx

I've also tried this in node v18 and v20 with the same issue running with ts-node.

Perhaps I'm doing something incorrect?

My use case:

Users have pub/priv keys generated by this library -> convereted to hex -> encryped -> stored.

After that they use ECDH to save and exchange data.

Icehunter commented 12 months ago

It looks like the example was a little off, unless this is wrong but:

const priv = ed448.utils.randomPrivateKey();
const pub = x448.getPublicKey(priv);

x448.getSharedSecret(priv, pub);

That works, if using x448 to get the public and ed448 to get private.

paulmillr commented 12 months ago

ed448 and x448 keys are NOT interchangeable

const priv = x448.utils.randomPrivateKey();
const pub = x448.getPublicKey(priv);
x448.getSharedSecret(priv, pub);
x448.getPublicKey(priv);
Icehunter commented 12 months ago

Makes much more sense thank you!