Public keys as JWK
JWK serialisation for public keys.
Signatures
Section titled “Signatures”exportPublicKeyAsJwk(key: CryptoKey): Promise<JsonWebKey>importPublicKeyFromJwk(jwk: JsonWebKey, algorithm: 'ECDH' | 'ECDSA'): Promise<CryptoKey>Example
Section titled “Example”import { exportPublicKeyAsJwk, importPublicKeyFromJwk } from '@consealdev/conseal'
// Export for server registryconst jwk = await exportPublicKeyAsJwk(myPublicKey)await fetch('/keys/me', { method: 'PUT', body: JSON.stringify(jwk) })
// Import a recipient's public keyconst data = await fetch('/keys/alice').then(r => r.json())const aliceKey = await importPublicKeyFromJwk(data, 'ECDH')- Only export public keys. Never call this on a private key.
- Pass
'ECDH'for keys used withsealMessage,'ECDSA'for keys used withverify.