UNPKG

@nfen/webcrypto-ts

Version:
100 lines 3.59 kB
/** * Code related to ECDSA * @module */ import * as params from "../params.js"; import { EcdsaPrivCryptoKey, EcdsaProxiedCryptoKeyPair, EcdsaProxiedPrivCryptoKey, EcdsaProxiedPubCryptoKey, EcdsaPubCryptoKey } from "./shared.js"; /** * Generate a new ECDSA keypair * @example * ```ts * const keyPair = await ECDSA.generateKey(); * ``` * @example * ```ts * const keyPair = await ECDSA.generateKey({ namedCurve: "P-256" }, false); * ``` * @example * ```ts * const keyPair = await ECDSA.generateKey({ namedCurve: "P-256" }, true, ['sign', 'verify']); * ``` */ export declare const generateKey: (algorithm?: Omit<params.EnforcedEcKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]) => Promise<EcdsaProxiedCryptoKeyPair>; /** * Generate a new ECDSA keypair * @alias generateKey * @example * ```ts * const keyPair = await ECDSA.generateKeyPair(); * ``` * @example * ```ts * const keyPair = await ECDSA.generateKeyPair({ namedCurve: "P-256" }, false); * ``` * @example * ```ts * const keyPair = await ECDSA.generateKeyPair({ namedCurve: "P-256" }, true, ['sign', 'verify']); * ``` */ export declare const generateKeyPair: (algorithm?: Omit<params.EnforcedEcKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]) => Promise<EcdsaProxiedCryptoKeyPair>; /** * Import an ECDSA public or private key * @example * ```ts * const pubKey = await ECDSA.importKey("jwk", pubKeyJwk, { namedCurve: "P-521" }, true, ['verify']); * ``` * @example * ```ts * const privKey = await ECDSA.importKey("jwk", privKeyJwk, { namedCurve: "P-521" }, true, ['sign']); * ``` */ export declare const importKey: (format: KeyFormat, key: BufferSource | JsonWebKey, algorithm?: Omit<params.EnforcedEcKeyImportParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]) => Promise<EcdsaProxiedPubCryptoKey | EcdsaProxiedPrivCryptoKey>; /** * Export an ECDSA public or private key * @example * ```ts * const pubKeyJwk = await ECDSA.exportKey("jwk", keyPair.publicKey.self); * ``` * @example * ```ts * const privKeyJwk = await ECDSA.exportKey("jwk", keyPair.privateKey.self); * ``` * @example * ```ts * const pubKeyJwk = await keyPair.publicKey.exportKey("jwk"); * ``` * @example * ```ts * const privKeyJwk = await keyPair.privateKey.exportKey("jwk"); * ``` */ export declare const exportKey: (format: KeyFormat, key: EcdsaPubCryptoKey | EcdsaPrivCryptoKey) => Promise<ArrayBuffer | JsonWebKey>; /** * Sign a given payload * @example * ```ts * const message = new TextEncoder().encode("a message"); * const signature = await ECDSA.sign({hash: "SHA-512"}, keyPair.privateKey.self, message); * ``` * @example * ```ts * const message = new TextEncoder().encode("a message"); * const signature = await keyPair.privateKey.sign({hash: "SHA-512"}, message); * ``` */ export declare function sign(algorithm: Omit<params.EnforcedEcdsaParams, "name">, key: EcdsaPrivCryptoKey, data: BufferSource): Promise<ArrayBuffer>; /** * Verify a given signature * @example * ```ts * const message = new TextEncoder().encode("a message"); * const isVerified = await ECDSA.verify({hash: "SHA-512"}, keyPair.publicKey.self, signature, message); * ``` * @example * ```ts * const message = new TextEncoder().encode("a message"); * const isVerified = await keyPair.publicKey.verify({hash: "SHA-512"}, signature, message); * ``` */ export declare function verify(algorithm: Omit<params.EnforcedEcdsaParams, "name">, key: EcdsaPubCryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>; //# sourceMappingURL=ecdsa.d.ts.map