publicKey property

Future<String> get publicKey

Returns a Future that resolves to the public key of this node as a base64 encoded protobuf.

Implementation

Future<String> get publicKey async {
  try {
    if (!_container.isRegistered(SecurityManager)) return '';
    final key = await _container.get<SecurityManager>().getPrivateKey('self');
    if (key != null) {
      final keyBytes = key.publicKeyBytes;
      if (keyBytes.isEmpty) return '';

      final protoBytes = <int>[
        0x08, 0x02, // Type: Secp256k1
        0x12, keyBytes.length, // Data tag + length
        ...keyBytes,
      ];

      return base64.encode(protoBytes);
    }
    return '';
  } catch (e) {
    _logger.warning('Failed to get public key: $e');
    return '';
  }
}