UNPKG

@peculiar/webcrypto

Version:
57 lines (56 loc) • 1.73 kB
/** * Copyright (c) 2019-2026, Peculiar Ventures * SPDX-License-Identifier: MIT */ import { getCryptoKey, setCryptoKey } from "../storage.js"; import { EcPrivateKey } from "./private_key.js"; import { EcPublicKey } from "./public_key.js"; import { EcCrypto } from "./crypto.js"; import * as core from "webcrypto-core"; // src/mechs/ec/ec_dsa.ts var EcdsaProvider = class extends core.EcdsaProvider { namedCurves = core.EcCurves.names; hashAlgorithms = [ "SHA-1", "SHA-256", "SHA-384", "SHA-512", "shake128", "shake256", "SHA3-256", "SHA3-384", "SHA3-512" ]; async onGenerateKey(algorithm, extractable, keyUsages) { const keys = await EcCrypto.generateKey({ ...algorithm, name: this.name }, extractable, keyUsages); return { privateKey: setCryptoKey(keys.privateKey), publicKey: setCryptoKey(keys.publicKey) }; } async onSign(algorithm, key, data) { return EcCrypto.sign(algorithm, getCryptoKey(key), new Uint8Array(data)); } async onVerify(algorithm, key, signature, data) { return EcCrypto.verify(algorithm, getCryptoKey(key), new Uint8Array(signature), new Uint8Array(data)); } async onExportKey(format, key) { return EcCrypto.exportKey(format, getCryptoKey(key)); } async onImportKey(format, keyData, algorithm, extractable, keyUsages) { const key = await EcCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages); return setCryptoKey(key); } checkCryptoKey(key, keyUsage) { super.checkCryptoKey(key, keyUsage); const internalKey = getCryptoKey(key); if (!(internalKey instanceof EcPrivateKey || internalKey instanceof EcPublicKey)) throw new TypeError("key: Is not EC CryptoKey"); } }; export { EcdsaProvider };