All files / features/identity / keys crypto.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24              3x                   1x 1x     1x    
/**
 * Cryptographic operations for Ed25519 keys
 *
 * Key generation uses @noble/curves (runs locally in JS).
 * KID derivation uses the tc-crypto WASM module (shared with the Rust backend).
 */
 
import { ed25519 } from '@noble/curves/ed25519.js';
import type { CryptoModule } from '@/providers/CryptoProvider';
import type { KeyPair } from './types';
 
/**
 * Generate a new Ed25519 key pair
 *
 * @param crypto - The WASM crypto module from useCryptoRequired()
 * @returns KeyPair with public/private keys and derived KID
 */
export function generateKeyPair(crypto: CryptoModule): KeyPair {
  const { secretKey, publicKey } = ed25519.keygen();
  const kid = crypto.derive_kid(publicKey);
 
  return { publicKey, privateKey: secretKey, kid };
}