A WebCrypto polyfill for Node.js that provides comprehensive cryptographic operations using standard Web Crypto API
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Next-generation cryptographic algorithms including EdDSA signatures and Curve25519 key agreement (requires Node.js ≥14).
Modern signature algorithm using Edwards curves for enhanced security and performance.
/**
* EdDSA key generation parameters
*/
interface EdDsaKeyGenParams extends Algorithm {
name: "EdDSA";
namedCurve: "Ed25519" | "Ed448";
}
/**
* EdDSA signing/verification parameters
*/
interface EdDsaParams extends Algorithm {
name: "EdDSA";
}Usage Example:
// Generate Ed25519 key pair
const keyPair = await crypto.subtle.generateKey(
{ name: "EdDSA", namedCurve: "Ed25519" },
true,
["sign", "verify"]
);
// Sign with EdDSA
const data = new TextEncoder().encode("Message for EdDSA signature");
const signature = await crypto.subtle.sign(
{ name: "EdDSA" },
keyPair.privateKey,
data
);
// Verify EdDSA signature
const isValid = await crypto.subtle.verify(
{ name: "EdDSA" },
keyPair.publicKey,
signature,
data
);Modern key agreement using Curve25519 and Curve448 for secure key exchange.
/**
* ECDH-ES key generation parameters
*/
interface EcdhEsKeyGenParams extends Algorithm {
name: "ECDH-ES";
namedCurve: "X25519" | "X448";
}
/**
* ECDH-ES key derivation parameters
*/
interface EcdhEsKeyDeriveParams extends Algorithm {
name: "ECDH-ES";
public: CryptoKey; // Other party's public key
}Usage Example:
// Generate X25519 key pairs
const aliceKeys = await crypto.subtle.generateKey(
{ name: "ECDH-ES", namedCurve: "X25519" },
false,
["deriveKey", "deriveBits"]
);
const bobKeys = await crypto.subtle.generateKey(
{ name: "ECDH-ES", namedCurve: "X25519" },
false,
["deriveKey", "deriveBits"]
);
// Derive shared secret
const sharedKey = await crypto.subtle.deriveKey(
{ name: "ECDH-ES", public: bobKeys.publicKey },
aliceKeys.privateKey,
{ name: "AES-GCM", length: 256 },
false,
["encrypt", "decrypt"]
);
// Alternative: derive raw bits
const sharedBits = await crypto.subtle.deriveBits(
{ name: "ECDH-ES", public: bobKeys.publicKey },
aliceKeys.privateKey,
256
);Specialized Ed25519 implementation with enhanced features.
/**
* Ed25519 key generation parameters
*/
interface Ed25519KeyGenParams extends Algorithm {
name: "Ed25519";
}
/**
* Ed25519 signing/verification parameters
*/
interface Ed25519Params extends Algorithm {
name: "Ed25519";
}Specialized X25519 key agreement implementation.
/**
* X25519 key generation parameters
*/
interface X25519KeyGenParams extends Algorithm {
name: "X25519";
}
/**
* X25519 key derivation parameters
*/
interface X25519KeyDeriveParams extends Algorithm {
name: "X25519";
public: CryptoKey; // Other party's public key
}class EdPrivateKey extends AsymmetricKey {
public algorithm: EdKeyAlgorithm;
public type: "private";
public usages: KeyUsage[];
public extractable: boolean;
}
class EdPublicKey extends AsymmetricKey {
public algorithm: EdKeyAlgorithm;
public type: "public";
public usages: KeyUsage[];
public extractable: boolean;
}
interface EdKeyAlgorithm extends KeyAlgorithm {
name: "EdDSA" | "ECDH-ES";
namedCurve: "Ed25519" | "Ed448" | "X25519" | "X448";
}class Ed25519PrivateKey extends Ed25519CryptoKey {
public algorithm: Ed25519KeyAlgorithm;
public type: "private";
public usages: KeyUsage[];
public extractable: boolean;
}
class Ed25519PublicKey extends Ed25519CryptoKey {
public algorithm: Ed25519KeyAlgorithm;
public type: "public";
public usages: KeyUsage[];
public extractable: boolean;
}
class Ed25519CryptoKey extends AsymmetricKey {
public algorithm: Ed25519KeyAlgorithm;
}
interface Ed25519KeyAlgorithm extends KeyAlgorithm {
name: "Ed25519" | "X25519";
namedCurve: "Ed25519" | "X25519";
}Modern cryptographic keys support multiple import/export formats:
Ed25519/Ed448 Keys:
X25519/X448 Keys:
Usage Example:
// Export Ed25519 public key as raw bytes
const publicKeyBytes = await crypto.subtle.exportKey(
"raw",
keyPair.publicKey
);
// Import Ed25519 public key from raw bytes
const importedPublicKey = await crypto.subtle.importKey(
"raw",
publicKeyBytes,
{ name: "EdDSA", namedCurve: "Ed25519" },
true,
["verify"]
);
// Export private key as PKCS#8
const privateKeyPkcs8 = await crypto.subtle.exportKey(
"pkcs8",
keyPair.privateKey
);Modern cryptography features require:
Modern cryptographic algorithms provide several advantages:
Install with Tessl CLI
npx tessl i tessl/npm-peculiar--webcrypto