@sphereon/ssi-sdk-ext.key-utils 0.36.1-feat.SSISDK.83.5 → 0.36.1-feature.SSISDK.82.and.SSISDK.70.35
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 +92 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -5
- package/dist/index.d.ts +12 -5
- package/dist/index.js +92 -20
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/digest-methods.ts +13 -11
- package/src/functions.ts +75 -7
- package/src/types/key-util-types.ts +2 -0
package/dist/index.cjs
CHANGED
|
@@ -38,6 +38,7 @@ __export(index_exports, {
|
|
|
38
38
|
Key: () => Key,
|
|
39
39
|
SIG_KEY_ALGS: () => SIG_KEY_ALGS,
|
|
40
40
|
asn1DerToRawPublicKey: () => asn1DerToRawPublicKey,
|
|
41
|
+
base64ToBase64Url: () => base64ToBase64Url,
|
|
41
42
|
calculateJwkThumbprint: () => calculateJwkThumbprint,
|
|
42
43
|
calculateJwkThumbprintForKey: () => calculateJwkThumbprintForKey,
|
|
43
44
|
coseKeyToJwk: () => coseKeyToJwk,
|
|
@@ -52,8 +53,12 @@ __export(index_exports, {
|
|
|
52
53
|
hexStringFromUint8Array: () => hexStringFromUint8Array,
|
|
53
54
|
importProvidedOrGeneratedKey: () => importProvidedOrGeneratedKey,
|
|
54
55
|
isAsn1Der: () => isAsn1Der,
|
|
56
|
+
isHash: () => isHash,
|
|
57
|
+
isHashString: () => isHashString,
|
|
55
58
|
isRawCompressedPublicKey: () => isRawCompressedPublicKey,
|
|
59
|
+
isSameHash: () => isSameHash,
|
|
56
60
|
jcsCanonicalize: () => jcsCanonicalize,
|
|
61
|
+
joseAlgorithmToDigest: () => joseAlgorithmToDigest,
|
|
57
62
|
joseToCoseCurve: () => joseToCoseCurve,
|
|
58
63
|
joseToCoseKeyOperation: () => joseToCoseKeyOperation,
|
|
59
64
|
joseToCoseKty: () => joseToCoseKty,
|
|
@@ -66,6 +71,7 @@ __export(index_exports, {
|
|
|
66
71
|
keyTypeFromCryptographicSuite: () => keyTypeFromCryptographicSuite,
|
|
67
72
|
logger: () => logger,
|
|
68
73
|
minimalJwk: () => minimalJwk,
|
|
74
|
+
normalizeHashAlgorithm: () => normalizeHashAlgorithm,
|
|
69
75
|
padLeft: () => padLeft,
|
|
70
76
|
removeNulls: () => removeNulls,
|
|
71
77
|
rsaJwkToRawHexKey: () => rsaJwkToRawHexKey,
|
|
@@ -108,24 +114,25 @@ var import_sha512 = require("@noble/hashes/sha512");
|
|
|
108
114
|
var u8a = __toESM(require("uint8arrays"), 1);
|
|
109
115
|
var { fromString, toString, SupportedEncodings } = u8a;
|
|
110
116
|
var digestMethodParams = /* @__PURE__ */ __name((hashAlgorithm) => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
117
|
+
switch (normalizeHashAlgorithm(hashAlgorithm)) {
|
|
118
|
+
case "SHA-256":
|
|
119
|
+
return {
|
|
120
|
+
hashAlgorithm: "SHA-256",
|
|
121
|
+
digestMethod: sha256DigestMethod,
|
|
122
|
+
hash: import_sha256.sha256
|
|
123
|
+
};
|
|
124
|
+
case "SHA-384":
|
|
125
|
+
return {
|
|
126
|
+
hashAlgorithm: "SHA-384",
|
|
127
|
+
digestMethod: sha384DigestMethod,
|
|
128
|
+
hash: import_sha512.sha384
|
|
129
|
+
};
|
|
130
|
+
case "SHA-512":
|
|
131
|
+
return {
|
|
132
|
+
hashAlgorithm: "SHA-512",
|
|
133
|
+
digestMethod: sha512DigestMethod,
|
|
134
|
+
hash: import_sha512.sha512
|
|
135
|
+
};
|
|
129
136
|
}
|
|
130
137
|
}, "digestMethodParams");
|
|
131
138
|
var shaHasher = /* @__PURE__ */ __name((input, alg) => {
|
|
@@ -449,7 +456,7 @@ var assertJwkClaimPresent = /* @__PURE__ */ __name((value, description) => {
|
|
|
449
456
|
}, "assertJwkClaimPresent");
|
|
450
457
|
var toBase64url = /* @__PURE__ */ __name((input) => toString2(fromString2(input), "base64url"), "toBase64url");
|
|
451
458
|
var calculateJwkThumbprint = /* @__PURE__ */ __name((args) => {
|
|
452
|
-
const
|
|
459
|
+
const digestAlgorithm = normalizeHashAlgorithm(args.digestAlgorithm ?? "SHA-256");
|
|
453
460
|
const jwk = sanitizedJwk(args.jwk);
|
|
454
461
|
let components;
|
|
455
462
|
switch (jwk.kty) {
|
|
@@ -493,7 +500,7 @@ var calculateJwkThumbprint = /* @__PURE__ */ __name((args) => {
|
|
|
493
500
|
throw new Error('"kty" (Key Type) Parameter missing or unsupported');
|
|
494
501
|
}
|
|
495
502
|
const data = JSON.stringify(components);
|
|
496
|
-
return
|
|
503
|
+
return digestMethodParams(digestAlgorithm).digestMethod(data, "base64url");
|
|
497
504
|
}, "calculateJwkThumbprint");
|
|
498
505
|
var toJwkFromKey = /* @__PURE__ */ __name((key, opts) => {
|
|
499
506
|
const isPrivateKey = "privateKeyHex" in key;
|
|
@@ -1220,6 +1227,71 @@ function toPkcs1FromHex(publicKeyHex) {
|
|
|
1220
1227
|
return toString2(pkcs1, "hex");
|
|
1221
1228
|
}
|
|
1222
1229
|
__name(toPkcs1FromHex, "toPkcs1FromHex");
|
|
1230
|
+
function joseAlgorithmToDigest(alg) {
|
|
1231
|
+
switch (alg.toUpperCase().replace("-", "")) {
|
|
1232
|
+
case "RS256":
|
|
1233
|
+
case "ES256":
|
|
1234
|
+
case "ES256K":
|
|
1235
|
+
case "PS256":
|
|
1236
|
+
case "HS256":
|
|
1237
|
+
return "SHA-256";
|
|
1238
|
+
case "RS384":
|
|
1239
|
+
case "ES384":
|
|
1240
|
+
case "PS384":
|
|
1241
|
+
case "HS384":
|
|
1242
|
+
return "SHA-384";
|
|
1243
|
+
case "RS512":
|
|
1244
|
+
case "ES512":
|
|
1245
|
+
case "PS512":
|
|
1246
|
+
case "HS512":
|
|
1247
|
+
return "SHA-512";
|
|
1248
|
+
case "EdDSA":
|
|
1249
|
+
return "SHA-512";
|
|
1250
|
+
default:
|
|
1251
|
+
return "SHA-256";
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
__name(joseAlgorithmToDigest, "joseAlgorithmToDigest");
|
|
1255
|
+
function isHash(input) {
|
|
1256
|
+
const length = input.length;
|
|
1257
|
+
if (length !== 64 && length !== 96 && length !== 128) {
|
|
1258
|
+
return false;
|
|
1259
|
+
}
|
|
1260
|
+
return input.match(/^([0-9A-Fa-f])+$/g) !== null;
|
|
1261
|
+
}
|
|
1262
|
+
__name(isHash, "isHash");
|
|
1263
|
+
function isHashString(input) {
|
|
1264
|
+
const length = input.length;
|
|
1265
|
+
if (length !== 32 && length !== 48 && length !== 64) {
|
|
1266
|
+
return false;
|
|
1267
|
+
}
|
|
1268
|
+
for (let i = 0; i < length; i++) {
|
|
1269
|
+
const byte = input[i];
|
|
1270
|
+
if (byte === void 0) {
|
|
1271
|
+
return false;
|
|
1272
|
+
}
|
|
1273
|
+
if (!(byte >= 48 && byte <= 57 || byte >= 65 && byte <= 70 || byte >= 97 && byte <= 102)) {
|
|
1274
|
+
return false;
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
return true;
|
|
1278
|
+
}
|
|
1279
|
+
__name(isHashString, "isHashString");
|
|
1280
|
+
function normalizeHashAlgorithm(alg) {
|
|
1281
|
+
if (!alg) {
|
|
1282
|
+
return "SHA-256";
|
|
1283
|
+
}
|
|
1284
|
+
const upper = alg.toUpperCase();
|
|
1285
|
+
if (upper.includes("256")) return "SHA-256";
|
|
1286
|
+
if (upper.includes("384")) return "SHA-384";
|
|
1287
|
+
if (upper.includes("512")) return "SHA-512";
|
|
1288
|
+
throw new Error(`Invalid hash algorithm: ${alg}`);
|
|
1289
|
+
}
|
|
1290
|
+
__name(normalizeHashAlgorithm, "normalizeHashAlgorithm");
|
|
1291
|
+
function isSameHash(left, right) {
|
|
1292
|
+
return normalizeHashAlgorithm(left) === normalizeHashAlgorithm(right);
|
|
1293
|
+
}
|
|
1294
|
+
__name(isSameHash, "isSameHash");
|
|
1223
1295
|
|
|
1224
1296
|
// src/conversion.ts
|
|
1225
1297
|
var import_ssi_types2 = require("@sphereon/ssi-types");
|