-
Notifications
You must be signed in to change notification settings - Fork 459
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
Import compressed secp256k1 public key #2696
Comments
Thinking more about it... Its a little funky that we rely on the loose rule of byte length in *FromRaw fns. Would expect them to take a type param and look something like: export function publicKeyFromRaw (type: KeyType, buf: Uint8Array): PublicKey {
if (type === "Ed25519") {
return unmarshalEd25519PublicKey(buf)
} else if (type === "secp256k1") {
return unmarshalSecp256k1PublicKey(buf)
} else if (type === "RSA") {
return pkixToRSAPublicKey(buf)
}
throw new UnsupportedKeyTypeError()
} |
It does make me slightly nervous that we infer the key type by the length, all it would take is a new key type with the same length as one of the others to throw a spanner in the works. An optional hint might be the way to go, we can overload it to specify the return type too: export function publicKeyFromRaw (buf: Uint8Array, type: 'Ed25519'): Ed25519PublicKey
export function publicKeyFromRaw (buf: Uint8Array, type: 'secp256k1'): Secp256k1PublicKey
export function publicKeyFromRaw (buf: Uint8Array, type: 'RSA'): RSAPublicKey
export function publicKeyFromRaw (buf: Uint8Array): PublicKey
export function publicKeyFromRaw (buf: Uint8Array, type?: KeyType): PublicKey {
//... implementation here
}
export function privateKeyFromRaw (buf: Uint8Array, type: 'Ed25519'): Ed25519PrivateKey
export function privateFromRaw (buf: Uint8Array, type: 'secp256k1'): Secp256k1PrivateKey
export function privateFromRaw (buf: Uint8Array, type: 'RSA'): RSAPrivateKey
export function privateFromRaw (buf: Uint8Array): PrivateKey
export function privateFromRaw (buf: Uint8Array, type?: KeyType): PrivateKey {
//... implementation here
} |
A compressed secp256k1 public key is 33 bytes. I don't think 34 bytes is a thing anywhere.
But as it stands, the new
@libp2p/crypto
makes it very difficult turn this into aPublicKey
instance.leads to funny code
The text was updated successfully, but these errors were encountered: