Converting between Ed25519 key and peerID #2379
-
What is the easiest and simplest way to obtain these in js-libp2p? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
A PeerId is a multihash of a protobuf struct that contains the key In the case of RSA For Ed25519 and Secp256k1 keys So for
To turn a string into a
|
Beta Was this translation helpful? Give feedback.
A PeerId is a multihash of a protobuf struct that contains the key
Type
and aData
field.In the case of RSA
Data
is the public key encoded as PKIX/X.509 in ASN1 DER format and the multihash is the sha256 hash of the serialized protobuf bytes.For Ed25519 and Secp256k1 keys
Data
is the raw public key bytes and the multihash is the identity hash, that is the multihash digest contains the actual serialized protobuf struct.So for
Ed25519
keys we can recreate the multihash with: