ed25519-keygen
Generate ed25519 keys deterministically for SSH, PGP (GPG) and TOR.
Does not use CLI utils, everything is done programmatically in pure JS.
Usage
npm install ed25519-keygen
The package exports four modules:
Use it in the following way:
import ssh from 'ed25519-keys/ssh';
import pgp from 'ed25519-keys/pgp';
import tor from 'ed25519-keys/tor';
import { randomBytes } from 'ed25519-keys/utils';
ssh(seed, username)
seed: Uint8Array
username: string
- Returns
{ fingerprint: string, privateKey: string, publicKey: string }
import ssh from 'ed25519-keys/ssh';
import { randomBytes } from 'ed25519-keygen/utils';
const sseed = randomBytes(32);
const skeys = await ssh(sseed, 'user@example.com');
console.log(skeys.fingerprint);
console.log(skeys.privateKey);
console.log(skeys.publicKey);
pgp(seed, user, password)
seed: Uint8Array
user: string
password: string
createdAt: number
- (default: 0) timestamp corresponding to key creation time- Returns
{ keyId: string, privateKey: string, publicKey: string }
Creates keys compatible with GPG. GPG is a commonly known utility that supports PGP protocol. Quirks:
- Generated private and public keys would have different representation,
however, their fingerprints would be the same. This is because AES encryption is used to
hide the keys, and AES requires different IV / salt.
- The function is slow (~725ms on Apple M1), because it uses S2K to derive keys.
- "warning: lower 3 bits of the secret key are not cleared"
happens even for keys generated with GnuPG 2.3.6, because check looks at item as Opaque MPI, when it is just MPI: see bugtracker URL.
import * as pgp from 'ed25519-keygen/pgp';
import { randomBytes } from 'ed25519-keygen/utils';
const pseed = randomBytes(32);
const pkeys = await pgp.getKeys(pseed, 'user@example.com', 'password');
console.log(pkeys.keyId);
console.log(pkeys.privateKey);
console.log(pkeys.publicKey);
console.log(await pgp.pubArmor.decode(keys.publicKey));
const privDecoded = await pgp.privArmor.decode(keys.privateKey);
console.log(privDecoded);
console.log({
ed25519: await pgp.decodeSecretKey('password', privDecoded[0].data),
cv25519: await pgp.decodeSecretKey('password', privDecoded[3].data),
});
tor(seed)
Generates TOR addresses.
seed: Uint8Array
- Returns
{ privateKey: string, publicKey: string }
import tor from 'ed25519-keygen/tor';
import { randomBytes } from 'ed25519-keygen/utils';
const tseed = randomBytes(32);
const tkeys = await tor(tseed);
console.log(tkeys.privateKey);
console.log(tkeys.publicKey);
randomBytes(length)
byteLength: number
default is 32
- Returns
Uint8Array
filled with cryptographically secure random bytes
License
MIT (c) Paul Miller (https://paulmillr.com), see LICENSE file.