Expand description

Code related to Ed25519

Functions

Export an Ed25519 public or private key

example
const pubKeyJwk = await Ed25519.exportKey("jwk", keyPair.publicKey.self);
example
const privKeyJwk = await Ed25519.exportKey("jwk", keyPair.privateKey.self);
example
const pubKeyJwk = await keyPair.publicKey.exportKey("jwk");
example
const privKeyJwk = await keyPair.privateKey.exportKey("jwk");

Parameters

Returns Promise<ArrayBuffer | JsonWebKey>

Generate a new Ed25519 keypair

example
const keyPair = await Ed25519.generateKey();
example
const keyPair = await Ed25519.generateKey(false);
example
const keyPair = await Ed25519.generateKey(true, ['sign', 'verify']);

Parameters

  • Optional extractable: boolean
  • Optional keyUsages: KeyUsage[]

Returns Promise<Ed25519ProxiedCryptoKeyPair>

Generate a new Ed25519 keypair

alias

generateKey

example
const keyPair = await Ed25519.generateKeyPair();
example
const keyPair = await Ed25519.generateKeyPair(false);
example
const keyPair = await Ed25519.generateKeyPair(true, ['sign', 'verify']);

Parameters

  • Optional extractable: boolean
  • Optional keyUsages: KeyUsage[]

Returns Promise<Ed25519ProxiedCryptoKeyPair>

Import an Ed25519 public or private key

example
const pubKey = await Ed25519.importKey("jwk", pubKeyJwk, true, ['verify']);
example
const privKey = await Ed25519.importKey("jwk", privKeyJwk, true, ['sign']);

Parameters

  • format: KeyFormat
  • key: BufferSource | JsonWebKey
  • Optional extractable: boolean
  • Optional keyUsages: KeyUsage[]

Returns Promise<Ed25519ProxiedPubCryptoKey | Ed25519ProxiedPrivCryptoKey>

Sign a given payload

example
const message = new TextEncoder().encode("a message");
const signature = await Ed25519.sign(keyPair.privateKey.self, message);
example
const message = new TextEncoder().encode("a message");
const signature = await keyPair.privateKey.sign(message);

Parameters

Returns Promise<ArrayBuffer>

Verify a given signature

example
const message = new TextEncoder().encode("a message");
const isVerified = await Ed25519.verify(keyPair.publicKey.self, signature, message);
example
const message = new TextEncoder().encode("a message");
const isVerified = await keyPair.publicKey.verify(signature, message);

Parameters

Returns Promise<boolean>