@sphereon/ssi-sdk-ext.key-utils 0.34.1-feature.SSISDK.26.RP.57 → 0.34.1-feature.SSISDK.44.finish.dcql.309
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 +69 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +70 -36
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/conversion.ts +38 -19
- package/src/functions.ts +49 -32
- package/src/types/key-util-types.ts +1 -0
package/dist/index.cjs
CHANGED
|
@@ -80,7 +80,8 @@ __export(index_exports, {
|
|
|
80
80
|
toPkcs1FromHex: () => toPkcs1FromHex,
|
|
81
81
|
toRawCompressedHexPublicKey: () => toRawCompressedHexPublicKey,
|
|
82
82
|
validateJwk: () => validateJwk,
|
|
83
|
-
verifyRawSignature: () => verifyRawSignature
|
|
83
|
+
verifyRawSignature: () => verifyRawSignature,
|
|
84
|
+
x25519PublicHexFromPrivateHex: () => x25519PublicHexFromPrivateHex
|
|
84
85
|
});
|
|
85
86
|
module.exports = __toCommonJS(index_exports);
|
|
86
87
|
|
|
@@ -276,17 +277,17 @@ __name(jcsCanonicalize, "jcsCanonicalize");
|
|
|
276
277
|
// src/types/key-util-types.ts
|
|
277
278
|
var JWK_JCS_PUB_NAME = "jwk_jcs-pub";
|
|
278
279
|
var JWK_JCS_PUB_PREFIX = 60241;
|
|
279
|
-
var Key = /* @__PURE__ */ function(Key2) {
|
|
280
|
+
var Key = /* @__PURE__ */ (function(Key2) {
|
|
280
281
|
Key2["Ed25519"] = "Ed25519";
|
|
281
282
|
Key2["Secp256k1"] = "Secp256k1";
|
|
282
283
|
Key2["Secp256r1"] = "Secp256r1";
|
|
283
284
|
return Key2;
|
|
284
|
-
}({});
|
|
285
|
-
var JwkKeyUse = /* @__PURE__ */ function(JwkKeyUse2) {
|
|
285
|
+
})({});
|
|
286
|
+
var JwkKeyUse = /* @__PURE__ */ (function(JwkKeyUse2) {
|
|
286
287
|
JwkKeyUse2["Encryption"] = "enc";
|
|
287
288
|
JwkKeyUse2["Signature"] = "sig";
|
|
288
289
|
return JwkKeyUse2;
|
|
289
|
-
}({});
|
|
290
|
+
})({});
|
|
290
291
|
var SIG_KEY_ALGS = [
|
|
291
292
|
"ES256",
|
|
292
293
|
"ES384",
|
|
@@ -379,14 +380,19 @@ var keyMetaAlgorithmsFromKeyType = /* @__PURE__ */ __name((type) => {
|
|
|
379
380
|
async function importProvidedOrGeneratedKey(args, context) {
|
|
380
381
|
const type = args.options?.type ?? args.options?.key?.type ?? args.options?.keyType ?? "Secp256r1";
|
|
381
382
|
const key = args?.options?.key;
|
|
382
|
-
if (
|
|
383
|
+
if (key) {
|
|
383
384
|
key.meta = {
|
|
384
|
-
|
|
385
|
-
x509: {
|
|
386
|
-
...args.options.x509,
|
|
387
|
-
...key.meta?.x509
|
|
388
|
-
}
|
|
385
|
+
providerName: args.providerName
|
|
389
386
|
};
|
|
387
|
+
if (args.options?.x509) {
|
|
388
|
+
key.meta = {
|
|
389
|
+
...key.meta,
|
|
390
|
+
x509: {
|
|
391
|
+
...args.options.x509,
|
|
392
|
+
...key.meta?.x509
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
}
|
|
390
396
|
}
|
|
391
397
|
if (args.options && args.options?.use === JwkKeyUse.Encryption && !ENC_KEY_ALGS.includes(type)) {
|
|
392
398
|
throw new Error(`${type} keys are not valid for encryption`);
|
|
@@ -633,6 +639,15 @@ function octJwkToRawHexKey(jwk) {
|
|
|
633
639
|
return toString2(key, "hex");
|
|
634
640
|
}
|
|
635
641
|
__name(octJwkToRawHexKey, "octJwkToRawHexKey");
|
|
642
|
+
function x25519PublicHexFromPrivateHex(privateKeyHex) {
|
|
643
|
+
if (!/^[0-9a-fA-F]{64}$/.test(privateKeyHex)) {
|
|
644
|
+
throw new Error("Private key must be 32-byte hex (64 chars)");
|
|
645
|
+
}
|
|
646
|
+
const priv = Uint8Array.from(Buffer.from(privateKeyHex, "hex"));
|
|
647
|
+
const pub = import_ed25519.x25519.getPublicKey(priv);
|
|
648
|
+
return Buffer.from(pub).toString("hex");
|
|
649
|
+
}
|
|
650
|
+
__name(x25519PublicHexFromPrivateHex, "x25519PublicHexFromPrivateHex");
|
|
636
651
|
var jwkDetermineUse = /* @__PURE__ */ __name((type, suppliedUse) => {
|
|
637
652
|
return suppliedUse ? suppliedUse : SIG_KEY_ALGS.includes(type) ? JwkKeyUse.Signature : ENC_KEY_ALGS.includes(type) ? JwkKeyUse.Encryption : void 0;
|
|
638
653
|
}, "jwkDetermineUse");
|
|
@@ -669,8 +684,8 @@ var toSecp256k1Jwk = /* @__PURE__ */ __name((keyHex, opts) => {
|
|
|
669
684
|
},
|
|
670
685
|
kty: import_ssi_types.JwkKeyType.EC,
|
|
671
686
|
crv: import_ssi_types.JoseCurve.secp256k1,
|
|
672
|
-
x: (0, import_ssi_sdk_ext.hexToBase64)(pubPoint.getX().toString("hex"), "base64url"),
|
|
673
|
-
y: (0, import_ssi_sdk_ext.hexToBase64)(pubPoint.getY().toString("hex"), "base64url"),
|
|
687
|
+
x: (0, import_ssi_sdk_ext.hexToBase64)(pubPoint.getX().toString("hex").padStart(64, "0"), "base64url"),
|
|
688
|
+
y: (0, import_ssi_sdk_ext.hexToBase64)(pubPoint.getY().toString("hex").padStart(64, "0"), "base64url"),
|
|
674
689
|
...opts?.isPrivateKey && {
|
|
675
690
|
d: (0, import_ssi_sdk_ext.hexToBase64)(keyPair.getPrivate("hex"), "base64url")
|
|
676
691
|
}
|
|
@@ -701,8 +716,8 @@ var toSecp256r1Jwk = /* @__PURE__ */ __name((keyHex, opts) => {
|
|
|
701
716
|
},
|
|
702
717
|
kty: import_ssi_types.JwkKeyType.EC,
|
|
703
718
|
crv: import_ssi_types.JoseCurve.P_256,
|
|
704
|
-
x: (0, import_ssi_sdk_ext.hexToBase64)(pubPoint.getX().toString("hex"), "base64url"),
|
|
705
|
-
y: (0, import_ssi_sdk_ext.hexToBase64)(pubPoint.getY().toString("hex"), "base64url"),
|
|
719
|
+
x: (0, import_ssi_sdk_ext.hexToBase64)(pubPoint.getX().toString("hex").padStart(64, "0"), "base64url"),
|
|
720
|
+
y: (0, import_ssi_sdk_ext.hexToBase64)(pubPoint.getY().toString("hex").padStart(64, "0"), "base64url"),
|
|
706
721
|
...opts?.isPrivateKey && {
|
|
707
722
|
d: (0, import_ssi_sdk_ext.hexToBase64)(keyPair.getPrivate("hex"), "base64url")
|
|
708
723
|
}
|
|
@@ -1103,7 +1118,7 @@ async function verifyRawSignature({ data, signature, key: inputKey, opts }) {
|
|
|
1103
1118
|
return import_bls12_381.bls12_381.verify(signature, data, fromString2(publicKeyHex, "hex"));
|
|
1104
1119
|
case "RSA": {
|
|
1105
1120
|
const signatureAlgorithm = opts?.signatureAlg ?? jwk.alg ?? import_ssi_types.JoseSignatureAlgorithm.PS256;
|
|
1106
|
-
const hashAlg = signatureAlgorithm ===
|
|
1121
|
+
const hashAlg = signatureAlgorithm === import_ssi_types.JoseSignatureAlgorithm.RS512 || signatureAlgorithm === import_ssi_types.JoseSignatureAlgorithm.PS512 ? import_sha2.sha512 : signatureAlgorithm === import_ssi_types.JoseSignatureAlgorithm.RS384 || signatureAlgorithm === import_ssi_types.JoseSignatureAlgorithm.PS384 ? import_sha2.sha384 : import_sha2.sha256;
|
|
1107
1122
|
switch (signatureAlgorithm) {
|
|
1108
1123
|
case import_ssi_types.JoseSignatureAlgorithm.RS256:
|
|
1109
1124
|
return rsa.PKCS1_SHA256.verify({
|
|
@@ -1312,27 +1327,38 @@ function coseToJoseSignatureAlg(coseAlg) {
|
|
|
1312
1327
|
__name(coseToJoseSignatureAlg, "coseToJoseSignatureAlg");
|
|
1313
1328
|
function joseToCoseSignatureAlg(joseAlg) {
|
|
1314
1329
|
switch (joseAlg) {
|
|
1315
|
-
case
|
|
1330
|
+
case import_ssi_types2.JoseSignatureAlgorithm.ES256K:
|
|
1331
|
+
case "ES256K":
|
|
1316
1332
|
return import_ssi_types2.ICoseSignatureAlgorithm.ES256K;
|
|
1317
|
-
case
|
|
1333
|
+
case import_ssi_types2.JoseSignatureAlgorithm.ES256:
|
|
1334
|
+
case "ES256":
|
|
1318
1335
|
return import_ssi_types2.ICoseSignatureAlgorithm.ES256;
|
|
1319
|
-
case
|
|
1336
|
+
case import_ssi_types2.JoseSignatureAlgorithm.ES384:
|
|
1337
|
+
case "ES384":
|
|
1320
1338
|
return import_ssi_types2.ICoseSignatureAlgorithm.ES384;
|
|
1321
|
-
case
|
|
1339
|
+
case import_ssi_types2.JoseSignatureAlgorithm.ES512:
|
|
1340
|
+
case "ES512":
|
|
1322
1341
|
return import_ssi_types2.ICoseSignatureAlgorithm.ES512;
|
|
1323
|
-
case
|
|
1342
|
+
case import_ssi_types2.JoseSignatureAlgorithm.PS256:
|
|
1343
|
+
case "PS256":
|
|
1324
1344
|
return import_ssi_types2.ICoseSignatureAlgorithm.PS256;
|
|
1325
|
-
case
|
|
1345
|
+
case import_ssi_types2.JoseSignatureAlgorithm.PS384:
|
|
1346
|
+
case "PS384":
|
|
1326
1347
|
return import_ssi_types2.ICoseSignatureAlgorithm.PS384;
|
|
1327
|
-
case
|
|
1348
|
+
case import_ssi_types2.JoseSignatureAlgorithm.PS512:
|
|
1349
|
+
case "PS512":
|
|
1328
1350
|
return import_ssi_types2.ICoseSignatureAlgorithm.PS512;
|
|
1329
|
-
case
|
|
1351
|
+
case import_ssi_types2.JoseSignatureAlgorithm.HS256:
|
|
1352
|
+
case "HS256":
|
|
1330
1353
|
return import_ssi_types2.ICoseSignatureAlgorithm.HS256;
|
|
1331
|
-
case
|
|
1354
|
+
case import_ssi_types2.JoseSignatureAlgorithm.HS384:
|
|
1355
|
+
case "HS384":
|
|
1332
1356
|
return import_ssi_types2.ICoseSignatureAlgorithm.HS384;
|
|
1333
|
-
case
|
|
1357
|
+
case import_ssi_types2.JoseSignatureAlgorithm.HS512:
|
|
1358
|
+
case "HS512":
|
|
1334
1359
|
return import_ssi_types2.ICoseSignatureAlgorithm.HS512;
|
|
1335
|
-
case
|
|
1360
|
+
case import_ssi_types2.JoseSignatureAlgorithm.EdDSA:
|
|
1361
|
+
case "EdDSA":
|
|
1336
1362
|
return import_ssi_types2.ICoseSignatureAlgorithm.EdDSA;
|
|
1337
1363
|
default:
|
|
1338
1364
|
throw Error(`Signature algorithm ${joseAlg} not supported in Cose`);
|
|
@@ -1341,21 +1367,29 @@ function joseToCoseSignatureAlg(joseAlg) {
|
|
|
1341
1367
|
__name(joseToCoseSignatureAlg, "joseToCoseSignatureAlg");
|
|
1342
1368
|
function joseToCoseKeyOperation(keyOp) {
|
|
1343
1369
|
switch (keyOp) {
|
|
1344
|
-
case
|
|
1370
|
+
case import_ssi_types2.JoseKeyOperation.SIGN:
|
|
1371
|
+
case "sign":
|
|
1345
1372
|
return import_ssi_types2.ICoseKeyOperation.SIGN;
|
|
1346
|
-
case
|
|
1373
|
+
case import_ssi_types2.JoseKeyOperation.VERIFY:
|
|
1374
|
+
case "verify":
|
|
1347
1375
|
return import_ssi_types2.ICoseKeyOperation.VERIFY;
|
|
1348
|
-
case
|
|
1376
|
+
case import_ssi_types2.JoseKeyOperation.ENCRYPT:
|
|
1377
|
+
case "encrypt":
|
|
1349
1378
|
return import_ssi_types2.ICoseKeyOperation.ENCRYPT;
|
|
1350
|
-
case
|
|
1379
|
+
case import_ssi_types2.JoseKeyOperation.DECRYPT:
|
|
1380
|
+
case "decrypt":
|
|
1351
1381
|
return import_ssi_types2.ICoseKeyOperation.DECRYPT;
|
|
1352
|
-
case
|
|
1382
|
+
case import_ssi_types2.JoseKeyOperation.WRAP_KEY:
|
|
1383
|
+
case "wrapKey":
|
|
1353
1384
|
return import_ssi_types2.ICoseKeyOperation.WRAP_KEY;
|
|
1354
|
-
case
|
|
1385
|
+
case import_ssi_types2.JoseKeyOperation.UNWRAP_KEY:
|
|
1386
|
+
case "unwrapKey":
|
|
1355
1387
|
return import_ssi_types2.ICoseKeyOperation.UNWRAP_KEY;
|
|
1356
|
-
case
|
|
1388
|
+
case import_ssi_types2.JoseKeyOperation.DERIVE_KEY:
|
|
1389
|
+
case "deriveKey":
|
|
1357
1390
|
return import_ssi_types2.ICoseKeyOperation.DERIVE_KEY;
|
|
1358
|
-
case
|
|
1391
|
+
case import_ssi_types2.JoseKeyOperation.DERIVE_BITS:
|
|
1392
|
+
case "deriveBits":
|
|
1359
1393
|
return import_ssi_types2.ICoseKeyOperation.DERIVE_BITS;
|
|
1360
1394
|
default:
|
|
1361
1395
|
throw Error(`Key operation ${keyOp} not supported in Cose`);
|