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

25 lines
1009 B
Plaintext

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertCOSEtoPKCS = convertCOSEtoPKCS;
const index_js_1 = require("./iso/index.js");
const cose_js_1 = require("./cose.js");
/**
* Takes COSE-encoded public key and converts it to PKCS key
*/
function convertCOSEtoPKCS(cosePublicKey) {
// This is a little sloppy, I'm using COSEPublicKeyEC2 since it could have both x and y, but when
// there's no y it means it's probably better typed as COSEPublicKeyOKP. I'll leave this for now
// and revisit it later if it ever becomes an actual problem.
const struct = index_js_1.isoCBOR.decodeFirst(cosePublicKey);
const tag = Uint8Array.from([0x04]);
const x = struct.get(cose_js_1.COSEKEYS.x);
const y = struct.get(cose_js_1.COSEKEYS.y);
if (!x) {
throw new Error('COSE public key was missing x');
}
if (y) {
return index_js_1.isoUint8Array.concat([tag, x, y]);
}
return index_js_1.isoUint8Array.concat([tag, x]);
}