personal key – EVM Key derivation

Ranging from Nostr personal and public keys, is it potential to derive equal EVM keys?

It is easy to make use of the Nostr personal key because the seed to generate an EVM priv/pubkey pair, however given somebody’s Nostr pubkey, is it potential to derive the identical pubkey that the opposite social gathering would derive from their personal key?

Nostr personal keys are transformed into pubkeys utilizing BIP340

/// Produces the general public key from a non-public key
///
/// Takes privateKey, a 32-bytes hex-encoded string, i.e. 64 characters.
/// Returns a public key as additionally 32-bytes hex-encoded.
String getPublicKey(String privateKey) {
  var d0 = BigInt.parse(privateKey, radix: 16);
  ECPoint P = (secp256k1.G * d0)!;
  return P.x!.toBigInteger()!.toRadixString(16).padLeft(64, "0");
}

At the moment I can do that utilizing the next dart code:

EthPrivateKey getEthCredentials(String nostrPrivateKey) {
  return EthPrivateKey.fromHex(hex.encode(hex.decode(nostrPrivateKey)));
}

EthereumAddress getEthAddressFromPublicKey(String bip340PublicKey) {
  last ecCurve = ECCurve_secp256k1();
  Uint8List publicKeyBytes = Uint8List.fromList(hex.decode(bip340PublicKey));

  // Guarantee the general public secret's within the appropriate format
  if (publicKeyBytes.size == 32) {
    // Add the 0x02 prefix for compressed public key
    publicKeyBytes = Uint8List.fromList([0x02] + publicKeyBytes);
  } else if (publicKeyBytes.size == 64) {
    // Add the 0x04 prefix for uncompressed public key
    publicKeyBytes = Uint8List.fromList([0x04] + publicKeyBytes);
  }

  // Decode the general public key
  last ecPoint = ecCurve.curve.decodePoint(publicKeyBytes);
  last uncompressedPublicKey =
      ecPoint!.getEncoded(false).sublist(1); // Take away the prefix byte

  // Generate Ethereum tackle from the uncompressed public key
  return EthereumAddress.fromPublicKey(uncompressedPublicKey);
}

However this does not permit me to derive new addresses, so these could be single-use addresses.

Leave a Reply

Your email address will not be published. Required fields are marked *