@sphereon/ssi-sdk-ext.jwt-service 0.28.1-feature.jose.vcdm.25 → 0.28.1-feature.jose.vcdm.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +45 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -8
- package/dist/index.js.map +1 -1
- package/package.json +13 -11
- package/src/functions/index.ts +25 -17
package/dist/index.js
CHANGED
|
@@ -37309,8 +37309,10 @@ var JwtService = class {
|
|
|
37309
37309
|
};
|
|
37310
37310
|
|
|
37311
37311
|
// src/functions/index.ts
|
|
37312
|
+
import { jwkTtoPublicKeyHex } from "@sphereon/ssi-sdk-ext.did-utils";
|
|
37312
37313
|
import { ensureManagedIdentifierResult, isManagedIdentifierDidResult, isManagedIdentifierX5cResult, resolveExternalJwkIdentifier } from "@sphereon/ssi-sdk-ext.identifier-resolution";
|
|
37313
|
-
import { verifyRawSignature } from "@sphereon/ssi-sdk-ext.key-utils";
|
|
37314
|
+
import { keyTypeFromCryptographicSuite, signatureAlgorithmFromKeyType, verifyRawSignature } from "@sphereon/ssi-sdk-ext.key-utils";
|
|
37315
|
+
import { contextHasPlugin } from "@sphereon/ssi-sdk.agent-config";
|
|
37314
37316
|
import { base64ToBytes as base64ToBytes2, bytesToBase64url as bytesToBase64url2, decodeJoseBlob, encodeJoseBlob } from "@veramo/utils";
|
|
37315
37317
|
import * as u8a3 from "uint8arrays";
|
|
37316
37318
|
var { fromString: fromString3 } = u8a3;
|
|
@@ -37383,10 +37385,14 @@ var createJwsJsonGeneral = /* @__PURE__ */ __name(async (args, context) => {
|
|
|
37383
37385
|
issuer,
|
|
37384
37386
|
mode
|
|
37385
37387
|
}, context);
|
|
37388
|
+
const alg = protectedHeader.alg ?? signatureAlgorithmFromKeyType({
|
|
37389
|
+
type: identifier.key.type
|
|
37390
|
+
});
|
|
37386
37391
|
const signature = await context.agent.keyManagerSign({
|
|
37387
37392
|
keyRef: identifier.kmsKeyRef,
|
|
37388
37393
|
data: `${b64.protectedHeader}.${b64.payload}`,
|
|
37389
|
-
encoding: void 0
|
|
37394
|
+
encoding: void 0,
|
|
37395
|
+
algorithm: alg
|
|
37390
37396
|
});
|
|
37391
37397
|
const jsonSignature = {
|
|
37392
37398
|
protected: b64.protectedHeader,
|
|
@@ -37402,6 +37408,9 @@ var createJwsJsonGeneral = /* @__PURE__ */ __name(async (args, context) => {
|
|
|
37402
37408
|
};
|
|
37403
37409
|
}, "createJwsJsonGeneral");
|
|
37404
37410
|
var checkAndUpdateJwsHeader = /* @__PURE__ */ __name(async ({ mode = "auto", identifier, header, noIdentifierInHeader = false }, context) => {
|
|
37411
|
+
header.alg = header.alg ?? signatureAlgorithmFromKeyType({
|
|
37412
|
+
type: identifier.key.type
|
|
37413
|
+
});
|
|
37405
37414
|
if (isIdentifierMode(mode, identifier.method, "did")) {
|
|
37406
37415
|
await checkAndUpdateDidHeader({
|
|
37407
37416
|
header,
|
|
@@ -37519,12 +37528,35 @@ var verifyJws = /* @__PURE__ */ __name(async (args, context) => {
|
|
|
37519
37528
|
let valid;
|
|
37520
37529
|
const data = fromString3(`${sigWithId.protected}.${jws.payload}`, "utf-8");
|
|
37521
37530
|
const jwkInfo = sigWithId.identifier.jwks[0];
|
|
37522
|
-
|
|
37523
|
-
|
|
37524
|
-
|
|
37525
|
-
|
|
37526
|
-
|
|
37527
|
-
|
|
37531
|
+
let signatureAlg = void 0;
|
|
37532
|
+
if (sigWithId.protected.startsWith(`ey`)) {
|
|
37533
|
+
const header = decodeJoseBlob(sigWithId.protected);
|
|
37534
|
+
signatureAlg = header.alg;
|
|
37535
|
+
}
|
|
37536
|
+
if (false) {
|
|
37537
|
+
const publicKeyHex = jwkTtoPublicKeyHex(jwkInfo.jwk);
|
|
37538
|
+
valid = await context.agent.keyManagerVerify({
|
|
37539
|
+
signature: sigWithId.signature,
|
|
37540
|
+
data,
|
|
37541
|
+
publicKeyHex,
|
|
37542
|
+
type: keyTypeFromCryptographicSuite({
|
|
37543
|
+
...jwkInfo.jwk.crv && {
|
|
37544
|
+
crv: jwkInfo.jwk.crv
|
|
37545
|
+
},
|
|
37546
|
+
alg: signatureAlg
|
|
37547
|
+
})
|
|
37548
|
+
});
|
|
37549
|
+
} else {
|
|
37550
|
+
const signature = base64ToBytes2(sigWithId.signature);
|
|
37551
|
+
valid = await verifyRawSignature({
|
|
37552
|
+
data,
|
|
37553
|
+
signature,
|
|
37554
|
+
key: jwkInfo.jwk,
|
|
37555
|
+
opts: {
|
|
37556
|
+
signatureAlg
|
|
37557
|
+
}
|
|
37558
|
+
});
|
|
37559
|
+
}
|
|
37528
37560
|
if (!valid) {
|
|
37529
37561
|
errorMessages.push(`Signature ${index} was not valid`);
|
|
37530
37562
|
}
|