@sphereon/ssi-sdk-ext.key-utils 0.36.1-feature.SSISDK.70.integrate.digidentity.56 → 0.36.1-feature.SSISDK.78.41
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 +23 -133
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -13
- package/dist/index.d.ts +5 -13
- package/dist/index.js +23 -133
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/digest-methods.ts +11 -13
- package/src/functions.ts +9 -133
- package/src/types/key-util-types.ts +0 -3
package/dist/index.cjs
CHANGED
|
@@ -52,12 +52,8 @@ __export(index_exports, {
|
|
|
52
52
|
hexStringFromUint8Array: () => hexStringFromUint8Array,
|
|
53
53
|
importProvidedOrGeneratedKey: () => importProvidedOrGeneratedKey,
|
|
54
54
|
isAsn1Der: () => isAsn1Der,
|
|
55
|
-
isHash: () => isHash,
|
|
56
|
-
isHashString: () => isHashString,
|
|
57
55
|
isRawCompressedPublicKey: () => isRawCompressedPublicKey,
|
|
58
|
-
isSameHash: () => isSameHash,
|
|
59
56
|
jcsCanonicalize: () => jcsCanonicalize,
|
|
60
|
-
joseAlgorithmToDigest: () => joseAlgorithmToDigest,
|
|
61
57
|
joseToCoseCurve: () => joseToCoseCurve,
|
|
62
58
|
joseToCoseKeyOperation: () => joseToCoseKeyOperation,
|
|
63
59
|
joseToCoseKty: () => joseToCoseKty,
|
|
@@ -70,7 +66,6 @@ __export(index_exports, {
|
|
|
70
66
|
keyTypeFromCryptographicSuite: () => keyTypeFromCryptographicSuite,
|
|
71
67
|
logger: () => logger,
|
|
72
68
|
minimalJwk: () => minimalJwk,
|
|
73
|
-
normalizeHashAlgorithm: () => normalizeHashAlgorithm,
|
|
74
69
|
padLeft: () => padLeft,
|
|
75
70
|
removeNulls: () => removeNulls,
|
|
76
71
|
rsaJwkToRawHexKey: () => rsaJwkToRawHexKey,
|
|
@@ -78,7 +73,6 @@ __export(index_exports, {
|
|
|
78
73
|
shaHasher: () => shaHasher,
|
|
79
74
|
signatureAlgorithmFromKey: () => signatureAlgorithmFromKey,
|
|
80
75
|
signatureAlgorithmFromKeyType: () => signatureAlgorithmFromKeyType,
|
|
81
|
-
signatureAlgorithmToJoseAlgorithm: () => signatureAlgorithmToJoseAlgorithm,
|
|
82
76
|
toBase64url: () => toBase64url,
|
|
83
77
|
toJwk: () => toJwk,
|
|
84
78
|
toJwkFromKey: () => toJwkFromKey,
|
|
@@ -114,25 +108,24 @@ var import_sha512 = require("@noble/hashes/sha512");
|
|
|
114
108
|
var u8a = __toESM(require("uint8arrays"), 1);
|
|
115
109
|
var { fromString, toString, SupportedEncodings } = u8a;
|
|
116
110
|
var digestMethodParams = /* @__PURE__ */ __name((hashAlgorithm) => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
};
|
|
111
|
+
if (hashAlgorithm === "SHA-256") {
|
|
112
|
+
return {
|
|
113
|
+
hashAlgorithm: "SHA-256",
|
|
114
|
+
digestMethod: sha256DigestMethod,
|
|
115
|
+
hash: import_sha256.sha256
|
|
116
|
+
};
|
|
117
|
+
} else if (hashAlgorithm === "SHA-384") {
|
|
118
|
+
return {
|
|
119
|
+
hashAlgorithm: "SHA-384",
|
|
120
|
+
digestMethod: sha384DigestMethod,
|
|
121
|
+
hash: import_sha512.sha384
|
|
122
|
+
};
|
|
123
|
+
} else {
|
|
124
|
+
return {
|
|
125
|
+
hashAlgorithm: "SHA-512",
|
|
126
|
+
digestMethod: sha512DigestMethod,
|
|
127
|
+
hash: import_sha512.sha512
|
|
128
|
+
};
|
|
136
129
|
}
|
|
137
130
|
}, "digestMethodParams");
|
|
138
131
|
var shaHasher = /* @__PURE__ */ __name((input, alg) => {
|
|
@@ -456,7 +449,7 @@ var assertJwkClaimPresent = /* @__PURE__ */ __name((value, description) => {
|
|
|
456
449
|
}, "assertJwkClaimPresent");
|
|
457
450
|
var toBase64url = /* @__PURE__ */ __name((input) => toString2(fromString2(input), "base64url"), "toBase64url");
|
|
458
451
|
var calculateJwkThumbprint = /* @__PURE__ */ __name((args) => {
|
|
459
|
-
const digestAlgorithm =
|
|
452
|
+
const { digestAlgorithm = "sha256" } = args;
|
|
460
453
|
const jwk = sanitizedJwk(args.jwk);
|
|
461
454
|
let components;
|
|
462
455
|
switch (jwk.kty) {
|
|
@@ -500,7 +493,7 @@ var calculateJwkThumbprint = /* @__PURE__ */ __name((args) => {
|
|
|
500
493
|
throw new Error('"kty" (Key Type) Parameter missing or unsupported');
|
|
501
494
|
}
|
|
502
495
|
const data = JSON.stringify(components);
|
|
503
|
-
return digestMethodParams(
|
|
496
|
+
return digestAlgorithm === "sha512" ? digestMethodParams("SHA-512").digestMethod(data, "base64url") : digestMethodParams("SHA-256").digestMethod(data, "base64url");
|
|
504
497
|
}, "calculateJwkThumbprint");
|
|
505
498
|
var toJwkFromKey = /* @__PURE__ */ __name((key, opts) => {
|
|
506
499
|
const isPrivateKey = "privateKeyHex" in key;
|
|
@@ -958,45 +951,11 @@ var hexStringFromUint8Array = /* @__PURE__ */ __name((value) => toString2(value,
|
|
|
958
951
|
var signatureAlgorithmFromKey = /* @__PURE__ */ __name(async (args) => {
|
|
959
952
|
const { key } = args;
|
|
960
953
|
return signatureAlgorithmFromKeyType({
|
|
961
|
-
type: key.type
|
|
962
|
-
algorithms: key.meta?.algorithms
|
|
954
|
+
type: key.type
|
|
963
955
|
});
|
|
964
956
|
}, "signatureAlgorithmFromKey");
|
|
965
|
-
function signatureAlgorithmToJoseAlgorithm(alg) {
|
|
966
|
-
switch (alg) {
|
|
967
|
-
case "RSA_SHA256":
|
|
968
|
-
return import_ssi_types.JoseSignatureAlgorithm.RS256;
|
|
969
|
-
case "RSA_SHA384":
|
|
970
|
-
return import_ssi_types.JoseSignatureAlgorithm.RS384;
|
|
971
|
-
case "RSA_SHA512":
|
|
972
|
-
return import_ssi_types.JoseSignatureAlgorithm.RS512;
|
|
973
|
-
case "RSA_SSA_PSS_SHA256_MGF1":
|
|
974
|
-
return import_ssi_types.JoseSignatureAlgorithm.PS256;
|
|
975
|
-
case "RSA_SSA_PSS_SHA384_MGF1":
|
|
976
|
-
return import_ssi_types.JoseSignatureAlgorithm.PS384;
|
|
977
|
-
case "RSA_SSA_PSS_SHA512_MGF1":
|
|
978
|
-
return import_ssi_types.JoseSignatureAlgorithm.PS512;
|
|
979
|
-
case "ECDSA_SHA256":
|
|
980
|
-
return import_ssi_types.JoseSignatureAlgorithm.ES256;
|
|
981
|
-
case "ECDSA_SHA384":
|
|
982
|
-
return import_ssi_types.JoseSignatureAlgorithm.ES384;
|
|
983
|
-
case "ECDSA_SHA512":
|
|
984
|
-
return import_ssi_types.JoseSignatureAlgorithm.ES512;
|
|
985
|
-
case "ES256K":
|
|
986
|
-
return import_ssi_types.JoseSignatureAlgorithm.ES256K;
|
|
987
|
-
case "ED25519":
|
|
988
|
-
case "EdDSA":
|
|
989
|
-
return import_ssi_types.JoseSignatureAlgorithm.EdDSA;
|
|
990
|
-
default:
|
|
991
|
-
return alg;
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
__name(signatureAlgorithmToJoseAlgorithm, "signatureAlgorithmToJoseAlgorithm");
|
|
995
957
|
var signatureAlgorithmFromKeyType = /* @__PURE__ */ __name((args) => {
|
|
996
|
-
const { type
|
|
997
|
-
if (algorithms && algorithms.length > 0) {
|
|
998
|
-
return signatureAlgorithmToJoseAlgorithm(algorithms[0]);
|
|
999
|
-
}
|
|
958
|
+
const { type } = args;
|
|
1000
959
|
switch (type) {
|
|
1001
960
|
case "Ed25519":
|
|
1002
961
|
case "X25519":
|
|
@@ -1010,7 +969,7 @@ var signatureAlgorithmFromKeyType = /* @__PURE__ */ __name((args) => {
|
|
|
1010
969
|
case "Secp256k1":
|
|
1011
970
|
return import_ssi_types.JoseSignatureAlgorithm.ES256K;
|
|
1012
971
|
case "RSA":
|
|
1013
|
-
return import_ssi_types.JoseSignatureAlgorithm.
|
|
972
|
+
return import_ssi_types.JoseSignatureAlgorithm.PS256;
|
|
1014
973
|
default:
|
|
1015
974
|
throw new Error(`Key type '${type}' not supported`);
|
|
1016
975
|
}
|
|
@@ -1261,75 +1220,6 @@ function toPkcs1FromHex(publicKeyHex) {
|
|
|
1261
1220
|
return toString2(pkcs1, "hex");
|
|
1262
1221
|
}
|
|
1263
1222
|
__name(toPkcs1FromHex, "toPkcs1FromHex");
|
|
1264
|
-
function joseAlgorithmToDigest(alg) {
|
|
1265
|
-
const normalized = alg.toUpperCase().replace(/-/g, "");
|
|
1266
|
-
switch (normalized) {
|
|
1267
|
-
case "RS256":
|
|
1268
|
-
case "ES256":
|
|
1269
|
-
case "ES256K":
|
|
1270
|
-
case "PS256":
|
|
1271
|
-
case "HS256":
|
|
1272
|
-
return "SHA-256";
|
|
1273
|
-
case "RS384":
|
|
1274
|
-
case "ES384":
|
|
1275
|
-
case "PS384":
|
|
1276
|
-
case "HS384":
|
|
1277
|
-
return "SHA-384";
|
|
1278
|
-
case "RS512":
|
|
1279
|
-
case "ES512":
|
|
1280
|
-
case "PS512":
|
|
1281
|
-
case "HS512":
|
|
1282
|
-
return "SHA-512";
|
|
1283
|
-
case "EDDSA":
|
|
1284
|
-
case "ED25519":
|
|
1285
|
-
return "SHA-512";
|
|
1286
|
-
default:
|
|
1287
|
-
throw new Error(`Unsupported JOSE algorithm: ${alg}. Cannot determine digest algorithm.`);
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
__name(joseAlgorithmToDigest, "joseAlgorithmToDigest");
|
|
1291
|
-
function isHash(input) {
|
|
1292
|
-
const length = input.length;
|
|
1293
|
-
if (length !== 64 && length !== 96 && length !== 128) {
|
|
1294
|
-
return false;
|
|
1295
|
-
}
|
|
1296
|
-
return input.match(/^([0-9A-Fa-f])+$/g) !== null;
|
|
1297
|
-
}
|
|
1298
|
-
__name(isHash, "isHash");
|
|
1299
|
-
function isHashString(input) {
|
|
1300
|
-
const length = input.length;
|
|
1301
|
-
if (length !== 32 && length !== 48 && length !== 64) {
|
|
1302
|
-
return false;
|
|
1303
|
-
}
|
|
1304
|
-
let printableCount = 0;
|
|
1305
|
-
for (let i = 0; i < length; i++) {
|
|
1306
|
-
const byte = input[i];
|
|
1307
|
-
if (byte === void 0) {
|
|
1308
|
-
return false;
|
|
1309
|
-
}
|
|
1310
|
-
if (byte >= 32 && byte <= 126) {
|
|
1311
|
-
printableCount++;
|
|
1312
|
-
}
|
|
1313
|
-
}
|
|
1314
|
-
const printableRatio = printableCount / length;
|
|
1315
|
-
return printableRatio < 0.9;
|
|
1316
|
-
}
|
|
1317
|
-
__name(isHashString, "isHashString");
|
|
1318
|
-
function normalizeHashAlgorithm(alg) {
|
|
1319
|
-
if (!alg) {
|
|
1320
|
-
return "SHA-256";
|
|
1321
|
-
}
|
|
1322
|
-
const upper = alg.toUpperCase();
|
|
1323
|
-
if (upper.includes("256")) return "SHA-256";
|
|
1324
|
-
if (upper.includes("384")) return "SHA-384";
|
|
1325
|
-
if (upper.includes("512")) return "SHA-512";
|
|
1326
|
-
throw new Error(`Invalid hash algorithm: ${alg}`);
|
|
1327
|
-
}
|
|
1328
|
-
__name(normalizeHashAlgorithm, "normalizeHashAlgorithm");
|
|
1329
|
-
function isSameHash(left, right) {
|
|
1330
|
-
return normalizeHashAlgorithm(left) === normalizeHashAlgorithm(right);
|
|
1331
|
-
}
|
|
1332
|
-
__name(isSameHash, "isSameHash");
|
|
1333
1223
|
|
|
1334
1224
|
// src/conversion.ts
|
|
1335
1225
|
var import_ssi_types2 = require("@sphereon/ssi-types");
|