extractPublicKey method

  1. @override
Future<PublicKey?> extractPublicKey()

Implementation

@override
Future<PublicKey?> extractPublicKey() async {
  try {
    final decoded = Multihash.decode(_multihash ?? Uint8List.fromList([]));
    // Only identity multihash contains the public key
    if (decoded.code != 0x00) { // 0x00 is the code for identity
      return null;
    }

    // Try to unmarshal the digest as a public key
    try {
      return await Ed25519PublicKey.unmarshal(Uint8List.fromList(decoded.digest));
    } catch (e) {
      return null;
    }
  } catch (e) {
    return null;
  }
}