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