paulmillr / noble-secp256k1

Fastest 4KB JS implementation of secp256k1 signatures and ECDH
https://paulmillr.com/noble
MIT License
757 stars 114 forks source link

33bytes PK? (Migrating from curves => secp256k1) #113

Closed telamon closed 1 year ago

telamon commented 1 year ago

Hello I tried switching to this smaller repo from curves. But a test that used getPublickKey() failed:

operator: equal
    expected: |-
      "b618af96fde8ba61d43dde06583e7a897256c10c1d11c4b32dc15b76726593e6"
    actual:   |-
      "03b618af96fde8ba61d43dde06583e7a897256c10c1d11c4b32dc15b76726593e6"

32bytes produced by (@noble/curves).secp256k1.getPublicKey(sk) 33bytes produced by (@noble/secp256k1).get(publicKey(sk)

What's that first 03 byte? Can I discard it?

EDIT after reading source, first byte is the compression-id/ y-coord polarity parity; But what do i do with all existing 32byte keys? How was the y-coord polarity parity decompressed before?

paulmillr commented 1 year ago

not sure what are you talking about, they both are 33b.

> (await import('@noble/curves/secp256k1')).secp256k1.getPublicKey(new Uint8Array(32).fill(1))
Uint8Array(33) [
    3,  27, 132, 197,  86, 123,  18, 100,
   64, 153,  93,  62, 213, 170, 186,   5,
  101, 215,  30,  24,  52,  96,  72,  25,
  255, 156,  23, 245, 233, 213, 221,   7,
  143
]

> (await import('@noble/secp256k1')).getPublicKey(new Uint8Array(32).fill(1))
Uint8Array(33) [
    3,  27, 132, 197,  86, 123,  18, 100,
   64, 153,  93,  62, 213, 170, 186,   5,
  101, 215,  30,  24,  52,  96,  72,  25,
  255, 156,  23, 245, 233, 213, 221,   7,
  143
]
telamon commented 1 year ago

@paulmillr Sorry i was zoomed in, but that is weird... I can check which version of curves i migrated from but I am positive getPublickKey() used to return out 32byte keys (without the id byte). Closing the issue.

paulmillr commented 1 year ago

schnorr.getPublicKey returns 32 bytes

telamon commented 11 months ago

@paulmillr i finally figured it out.. In the first example I was using the schnorr scheme from @noble/curves which indeed are 32bytes. Hence my original description is wrong, should have been: (@noble/curves/secp256k1).schnorr.getPublicKey(sk) Apologies for the noise and thx for the help.