Files
NapCatQQ/.pnpm-store/v3/files/62/08fab15b6f03232cf90c35ca35274d12eb6b67fc5f9a2edde6c6febbd8954b2a0a094bbeb67eb02700b56b0b999c591aaca5a7e2a68ae9cb67bebc94290e56
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

36 lines
1.5 KiB
Plaintext

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.verify = verify;
const cose_js_1 = require("../../cose.js");
const verifyEC2_js_1 = require("./verifyEC2.js");
const verifyRSA_js_1 = require("./verifyRSA.js");
const verifyOKP_js_1 = require("./verifyOKP.js");
const unwrapEC2Signature_js_1 = require("./unwrapEC2Signature.js");
/**
* Verify signatures with their public key. Supports EC2 and RSA public keys.
*/
function verify(opts) {
const { cosePublicKey, signature, data, shaHashOverride } = opts;
if ((0, cose_js_1.isCOSEPublicKeyEC2)(cosePublicKey)) {
const crv = cosePublicKey.get(cose_js_1.COSEKEYS.crv);
if (!(0, cose_js_1.isCOSECrv)(crv)) {
throw new Error(`unknown COSE curve ${crv}`);
}
const unwrappedSignature = (0, unwrapEC2Signature_js_1.unwrapEC2Signature)(signature, crv);
return (0, verifyEC2_js_1.verifyEC2)({
cosePublicKey,
signature: unwrappedSignature,
data,
shaHashOverride,
});
}
else if ((0, cose_js_1.isCOSEPublicKeyRSA)(cosePublicKey)) {
return (0, verifyRSA_js_1.verifyRSA)({ cosePublicKey, signature, data, shaHashOverride });
}
else if ((0, cose_js_1.isCOSEPublicKeyOKP)(cosePublicKey)) {
return (0, verifyOKP_js_1.verifyOKP)({ cosePublicKey, signature, data });
}
const kty = cosePublicKey.get(cose_js_1.COSEKEYS.kty);
throw new Error(`Signature verification with public key of kty ${kty} is not supported by this method`);
}