Skip to content

Instantly share code, notes, and snippets.

@dahlia
Last active June 2, 2024 13:17
Show Gist options
  • Save dahlia/7a182572e01a327ec25417739d6960c0 to your computer and use it in GitHub Desktop.
Save dahlia/7a182572e01a327ec25417739d6960c0 to your computer and use it in GitHub Desktop.
Ed25519 signing/verification using Web Cryptography API (tested on Node.js, Bun, and Deno)
const keyPair = await crypto.subtle.generateKey(
"Ed25519",
true,
["sign", "verify"],
);
console.debug(keyPair);
const msg = new TextEncoder().encode("Hello, World!");
const sig = await crypto.subtle.sign(
"Ed25519",
keyPair.privateKey,
msg,
);
console.debug(sig);
const isValid = await crypto.subtle.verify(
"Ed25519",
keyPair.publicKey,
sig,
msg,
);
console.debug(isValid);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment