PeerId.fromPrivateKey constructor
PeerId.fromPrivateKey(
- PrivateKey privateKey
Creates a PeerId from a private key
Implementation
PeerId.fromPrivateKey(PrivateKey privateKey) {
final publicKey = privateKey.publicKey;
final keyBytes = publicKey.marshal();
// If key is small enough, use identity multihash
if (keyBytes.length <= _maxInlineKeyLength) {
final identityMultihash = Multihash.encode('identity', keyBytes);
_multihash = identityMultihash.toBytes();
return;
}
// Otherwise use SHA2-256
final sha256Multihash = Multihash.encode('sha2-256', keyBytes);
_multihash = sha256Multihash.toBytes();
}