verifyPeerBinding static method

bool verifyPeerBinding(
  1. String peerId,
  2. Uint8List publicKeyBytes
)

Verifies that publicKeyBytes cryptographically derives to peerId.

Returns true if and only if publicKeyBytes is a valid 32-byte Ed25519 key whose SHA-256 digest matches the peer ID.

Implementation

static bool verifyPeerBinding(String peerId, Uint8List publicKeyBytes) {
  if (publicKeyBytes.length != 32) return false;
  try {
    final derived = PeerId.fromPublicKey(
      publicKeyBytes,
      type: 'Ed25519',
    ).toBase58();
    return derived == peerId;
  } catch (_) {
    return false;
  }
}