Files
NapCatQQ/.pnpm-store/v3/files/4b/23f6d0cd725121eaabdcd0726753c7a79dfa3db7c247c82e358c6db1996a0befde82bbc92d624bd9d7fe143f60058fcffe69362ccac708b26c82fc324be26f
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.2 KiB
Plaintext

import { isoCrypto } from './iso/index.js';
import { decodeCredentialPublicKey } from './decodeCredentialPublicKey.js';
import { convertX509PublicKeyToCOSE } from './convertX509PublicKeyToCOSE.js';
/**
* Verify an authenticator's signature
*/
export function verifySignature(opts) {
const { signature, data, credentialPublicKey, x509Certificate, hashAlgorithm, } = opts;
if (!x509Certificate && !credentialPublicKey) {
throw new Error('Must declare either "leafCert" or "credentialPublicKey"');
}
if (x509Certificate && credentialPublicKey) {
throw new Error('Must not declare both "leafCert" and "credentialPublicKey"');
}
let cosePublicKey = new Map();
if (credentialPublicKey) {
cosePublicKey = decodeCredentialPublicKey(credentialPublicKey);
}
else if (x509Certificate) {
cosePublicKey = convertX509PublicKeyToCOSE(x509Certificate);
}
return _verifySignatureInternals.stubThis(isoCrypto.verify({
cosePublicKey,
signature,
data,
shaHashOverride: hashAlgorithm,
}));
}
/**
* Make it possible to stub the return value during testing
* @ignore Don't include this in docs output
*/
export const _verifySignatureInternals = {
stubThis: (value) => value,
};