WebCryptoP256
Utility functions for NIST P256 ECDSA cryptography using the Web Crypto API
Examples
Below are some examples demonstrating common usages of the WebCryptoP256
module:
Creating Key Pairs
Key pairs can be created using WebCryptoP256.createKeyPair
:
import { WebCryptoP256 } from 'ox'
const { publicKey, privateKey } = await WebCryptoP256.createKeyPair()
{ privateKey: CryptoKey {}, publicKey: { x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n, y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n, prefix: 4, }, }
Signing Payloads
Payloads can be signed using WebCryptoP256.sign
:
import { WebCryptoP256 } from 'ox'
const { privateKey } = await WebCryptoP256.createKeyPair()
const signature = await WebCryptoP256.sign({
payload: '0xdeadbeef',
privateKey,
})
{ r: 151231...4423n, s: 516123...5512n, }
Verifying Signatures
Signatures can be verified using WebCryptoP256.verify
:
import { WebCryptoP256 } from 'ox'
const { privateKey, publicKey } = await WebCryptoP256.createKeyPair()
const signature = await WebCryptoP256.sign({ payload: '0xdeadbeef', privateKey })
const verified = await WebCryptoP256.verify({
payload: '0xdeadbeef',
publicKey,
signature,
})
true
Functions
Name | Description |
---|---|
WebCryptoP256.createKeyPair | Generates an ECDSA P256 key pair that includes: |
WebCryptoP256.sign | Signs a payload with the provided CryptoKey private key and returns a P256 signature. |
WebCryptoP256.verify | Verifies a payload was signed by the provided public key. |