Expand description

Code related to ECDSA

Functions

Export an ECDSA public or private key

example
const pubKeyJwk = await ECDSA.exportKey("jwk", keyPair.publicKey.self);
example
const privKeyJwk = await ECDSA.exportKey("jwk", keyPair.privateKey.self);
example
const pubKeyJwk = await keyPair.publicKey.exportKey("jwk");
example
const privKeyJwk = await keyPair.privateKey.exportKey("jwk");

Parameters

Returns Promise<ArrayBuffer | JsonWebKey>

Generate a new ECDSA keypair

example
const keyPair = await ECDSA.generateKey();
example
const keyPair = await ECDSA.generateKey({ namedCurve: "P-256" }, false);
example
const keyPair = await ECDSA.generateKey({ namedCurve: "P-256" }, true, ['sign', 'verify']);

Parameters

  • algorithm: Omit<EnforcedEcKeyGenParams, "name"> = { namedCurve: Alg.Curve.P_521, }
  • Optional extractable: boolean
  • Optional keyUsages: KeyUsage[]

Returns Promise<EcdsaProxiedCryptoKeyPair>

Generate a new ECDSA keypair

alias

generateKey

example
const keyPair = await ECDSA.generateKeyPair();
example
const keyPair = await ECDSA.generateKeyPair({ namedCurve: "P-256" }, false);
example
const keyPair = await ECDSA.generateKeyPair({ namedCurve: "P-256" }, true, ['sign', 'verify']);

Parameters

  • algorithm: Omit<EnforcedEcKeyGenParams, "name"> = { namedCurve: Alg.Curve.P_521, }
  • Optional extractable: boolean
  • Optional keyUsages: KeyUsage[]

Returns Promise<EcdsaProxiedCryptoKeyPair>

Import an ECDSA public or private key

example
const pubKey = await ECDSA.importKey("jwk", pubKeyJwk, { namedCurve: "P-521" }, true, ['verify']);
example
const privKey = await ECDSA.importKey("jwk", privKeyJwk, { namedCurve: "P-521" }, true, ['sign']);

Parameters

  • format: KeyFormat
  • key: BufferSource | JsonWebKey
  • algorithm: Omit<EnforcedEcKeyImportParams, "name"> = { namedCurve: Alg.Curve.P_521, }
  • Optional extractable: boolean
  • Optional keyUsages: KeyUsage[]

Returns Promise<EcdsaProxiedPubCryptoKey | EcdsaProxiedPrivCryptoKey>

Sign a given payload

example
const message = new TextEncoder().encode("a message");
const signature = await ECDSA.sign({hash: "SHA-512"}, keyPair.privateKey.self, message);
example
const message = new TextEncoder().encode("a message");
const signature = await keyPair.privateKey.sign({hash: "SHA-512"}, message);

Parameters

Returns Promise<ArrayBuffer>

Verify a given signature

example
const message = new TextEncoder().encode("a message");
const isVerified = await ECDSA.verify({hash: "SHA-512"}, keyPair.publicKey.self, signature, message);
example
const message = new TextEncoder().encode("a message");
const isVerified = await keyPair.publicKey.verify({hash: "SHA-512"}, signature, message);

Parameters

Returns Promise<boolean>