-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement support for compressed public keys #41
Comments
Thanks for creating this issue. The specs for this are here https://github.com/status-im/specs/blob/master/docs/stable/2-account.md#public-key-serialization We actually support all This may be useful https://github.com/multiformats/js-multibase Public key types:
But I've been told that we'd only use |
Looks like the secret sauce are > s = 'zQ3shPyZJnxZK4Bwyx9QsaksNKDYTPmpwPvGSjMYVHoXHeEgB'
'zQ3shPyZJnxZK4Bwyx9QsaksNKDYTPmpwPvGSjMYVHoXHeEgB'
> b = multibase.decode(s)
<Buffer e7 01 02 26 1c 55 67 5e 55 ff 25 ed b5 0b 34 5c fb 3a 3f 35 f6 07 12 d2 51 cb aa ab 97 bd 50 05 4c 6e bc>
> secp256k1.publicKeyConvert(b.slice(2), compressed=false)
Uint8Array(65) [
4, 38, 28, 85, 103, 94, 85, 255, 37, 237, 181,
11, 52, 92, 251, 58, 63, 53, 246, 7, 18, 210,
81, 203, 170, 171, 151, 189, 80, 5, 76, 110, 188,
60, 212, 226, 34, 0, 198, 141, 175, 116, 147, 225,
248, 218, 106, 25, 10, 104, 166, 113, 226, 211, 151,
120, 9, 97, 36, 36, 199, 195, 136, 139, 198
] |
And the other way around: > k = "0x041c678bdeb6940df3e436cee76612ae6177f46e54e541fc024b572fafd9be89ba43612d6e26bba8f3961b5d379efe1fb031a718ea24936a83550086f4ba2c5c94"
'0x041c678bdeb6940df3e436cee76612ae6177f46e54e541fc024b572fafd9be89ba43612d6e26bba8f3961b5d379efe1fb031a718ea24936a83550086f4ba2c5c94'
> f = "f" + k.slice(2)
'f041c678bdeb6940df3e436cee76612ae6177f46e54e541fc024b572fafd9be89ba43612d6e26bba8f3961b5d379efe1fb031a718ea24936a83550086f4ba2c5c94'
> b = multibase.decode(f)
<Buffer 04 1c 67 8b de b6 94 0d f3 e4 36 ce e7 66 12 ae 61 77 f4 6e 54 e5 41 fc 02 4b 57 2f af d9 be 89 ba 43 61 2d 6e 26 bb a8 f3 96 1b 5d 37 9e fe 1f b0 31 ... 15 more bytes>
> c = secp256k1.publicKeyConvert(b)
Uint8Array(33) [
2, 28, 103, 139, 222, 182, 148, 13,
243, 228, 54, 206, 231, 102, 18, 174,
97, 119, 244, 110, 84, 229, 65, 252,
2, 75, 87, 47, 175, 217, 190, 137,
186
]
> secp256k1MultifactorID = Buffer.from([231, 1])
> d = Buffer.concat([secp256k1MultifactorID, c])
<Buffer e7 01 02 1c 67 8b de b6 94 0d f3 e4 36 ce e7 66 12 ae 61 77 f4 6e 54 e5 41 fc 02 4b 57 2f af d9 be 89 ba>
> multibase.encode('base58btc', d).toString()
'zQ3shPKfkQPeJdWMrXMtSfCFHhDR9gck99GsYt4Er3yvHxT2Z' |
This post was a good resource: status-im/status-go#1937 (comment) |
I'm please you found it helpful, I always try share the information I learn to make the learning curve of anyone else to be less steep than mine 😆 |
Based off of status-im/status-go#1937 the handler needs to be able to accept compressed public key.
@Samyoul which compressed formats do we need to support? Just multiformat base58 encoded?
The text was updated successfully, but these errors were encountered: