EVM Key derivation
Starting from Nostr private and public keys, is it possible to derive equivalent EVM keys?
It's easy to use the Nostr private key as the seed to generate an EVM priv/pubkey pair, but given someone's Nostr pubkey, is it possible to derive the same pubkey that the other party would derive from their private key?
Nostr private keys are converted into pubkeys using BIP340
/// Produces the public key from a private key
///
/// Takes privateKey, a 32-bytes hex-encoded string, i.e. 64 characters.
/// Returns a public key as also 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");
}
Currently I can do this using the following dart code:
EthPrivateKey getEthCredentials(String nostrPrivateKey) {
return EthPrivateKey.fromHex(hex.encode(hex.decode(nostrPrivateKey)));
}
EthereumAddress getEthAddressFromPublicKey(String bip340PublicKey) {
final ecCurve = ECCurve_secp256k1();
Uint8List publicKeyBytes = Uint8List.fromList(hex.decode(bip340PublicKey));
// Ensure the public key is in the correct format
if (publicKeyBytes.length == 32) {
// Add the 0x02 prefix for compressed public key
publicKeyBytes = Uint8List.fromList([0x02] + publicKeyBytes);
} else if (publicKeyBytes.length == 64) {
// Add the 0x04 prefix for uncompressed public key
publicKeyBytes = Uint8List.fromList([0x04] + publicKeyBytes);
}
// Decode the public key
final ecPoint = ecCurve.curve.decodePoint(publicKeyBytes);
final uncompressedPublicKey =
ecPoint!.getEncoded(false).sublist(1); // Remove the prefix byte
// Generate Ethereum address from the uncompressed public key
return EthereumAddress.fromPublicKey(uncompressedPublicKey);
}
But this doesn't allow me to derive new addresses, so these would be single-use addresses.
from Recent Questions - Bitcoin Stack Exchange https://ift.tt/PUfhF9I
via IFTTT