getPublicKey method

Future<String> getPublicKey(
  1. String hdPath, [
  2. KeyType keyType = KeyType.secp256k1
])

Returns the public key as hex-String associated with hdPath.

Implementation

Future<String> getPublicKey(String hdPath,
    [KeyType keyType = KeyType.secp256k1]) async {
  if (keyType == KeyType.secp256k1) {
    var master = BIP32.fromSeed(_keyBox!.get('seed'));
    var key = master.derivePath(hdPath);
    return bytesToHex(key.publicKey);
  } else if (keyType == KeyType.ed25519) {
    var key = await ED25519_HD_KEY.derivePath(
        hdPath, _keyBox!.get('seed').toList());
    return bytesToHex(
        ed.public(ed.newKeyFromSeed(Uint8List.fromList(key.key))).bytes);
  } else if (keyType == KeyType.x25519) {
    var key = await ED25519_HD_KEY.derivePath(
        hdPath, _keyBox!.get('seed').toList());
    return bytesToHex(
        _edPrivateToXPublic(ed.newKeyFromSeed(Uint8List.fromList(key.key))));
  } else {
    throw Exception('Unknown KeyType');
  }
}