Member-only story
Creating Ed25519 Signing Keys: Random or from a Passphrase
While Bitcoin and Ethereum use the secp256k1 curve and the ECDSA signature, there is a much better signature method. This is EdDSA, and when it uses Curve 25519, the signature is known as Ed25519:
With Ed25519, the private key is created from a 32-byte seed value. This could be a random value or could be generated from a passphrase and then converted into a 32-byte private key using PBKDF2, scrypt, crypt or Argon 2.
Random key
In the following, we will generate a random 32-byte seed value in JavaScript. Then, if Bob generates a private key of b (a 32-bit scalar value), the public key point is b⋅G, and where G is the base point. In Curve 25519, we only store the x-axis point, and so the public key will be a 32-byte (256-bit) value, as we can compute the y-axis value from the x-axis value. In this case, we will take a passphrase, and then take a SHA-512 hash, and then use the first 32 bytes of this hash for the seed. For a given string, we will have a fixed key pair.
We can generate a 32-byte random value with the function of:
function randomArray(length, max) {…