UNPKG

@datadayrepos/libsodium-wrapper

Version:

Typescript for accessing the libsodium.js for a small subset of functionalities.

36 lines (35 loc) 960 B
import { crypto_sign_keypair, sodiumReady, to_base64, } from './lib'; function createEd25519JWKS(publicKey, privateKey) { const jwkPair = { private: { alg: 'EdDSA', crv: 'Ed25519', d: privateKey, kid: '', kty: 'OKP', use: 'sig', x: publicKey, }, public: { alg: 'EdDSA', crv: 'Ed25519', kid: '', kty: 'OKP', use: 'sig', x: publicKey, }, }; return jwkPair; } export async function createEd25519KeyPair() { await sodiumReady; const keyPair = crypto_sign_keypair(); return { privateKey: to_base64(keyPair.privateKey), publicKey: to_base64(keyPair.publicKey), }; } export async function createEd25519JwkPair() { const keyPair = await createEd25519KeyPair(); return createEd25519JWKS(keyPair.publicKey, keyPair.privateKey); }