@sphereon/ssi-sdk-ext.key-utils 0.36.1-feature.SSISDK.70.integrate.digidentity.10 → 0.36.1-feature.SSISDK.70.integrate.digidentity.56
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 +48 -9
- 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 +48 -9
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/functions.ts +66 -10
- package/src/types/key-util-types.ts +1 -0
package/dist/index.cjs
CHANGED
|
@@ -78,6 +78,7 @@ __export(index_exports, {
|
|
|
78
78
|
shaHasher: () => shaHasher,
|
|
79
79
|
signatureAlgorithmFromKey: () => signatureAlgorithmFromKey,
|
|
80
80
|
signatureAlgorithmFromKeyType: () => signatureAlgorithmFromKeyType,
|
|
81
|
+
signatureAlgorithmToJoseAlgorithm: () => signatureAlgorithmToJoseAlgorithm,
|
|
81
82
|
toBase64url: () => toBase64url,
|
|
82
83
|
toJwk: () => toJwk,
|
|
83
84
|
toJwkFromKey: () => toJwkFromKey,
|
|
@@ -957,11 +958,45 @@ var hexStringFromUint8Array = /* @__PURE__ */ __name((value) => toString2(value,
|
|
|
957
958
|
var signatureAlgorithmFromKey = /* @__PURE__ */ __name(async (args) => {
|
|
958
959
|
const { key } = args;
|
|
959
960
|
return signatureAlgorithmFromKeyType({
|
|
960
|
-
type: key.type
|
|
961
|
+
type: key.type,
|
|
962
|
+
algorithms: key.meta?.algorithms
|
|
961
963
|
});
|
|
962
964
|
}, "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");
|
|
963
995
|
var signatureAlgorithmFromKeyType = /* @__PURE__ */ __name((args) => {
|
|
964
|
-
const { type } = args;
|
|
996
|
+
const { type, algorithms } = args;
|
|
997
|
+
if (algorithms && algorithms.length > 0) {
|
|
998
|
+
return signatureAlgorithmToJoseAlgorithm(algorithms[0]);
|
|
999
|
+
}
|
|
965
1000
|
switch (type) {
|
|
966
1001
|
case "Ed25519":
|
|
967
1002
|
case "X25519":
|
|
@@ -975,7 +1010,7 @@ var signatureAlgorithmFromKeyType = /* @__PURE__ */ __name((args) => {
|
|
|
975
1010
|
case "Secp256k1":
|
|
976
1011
|
return import_ssi_types.JoseSignatureAlgorithm.ES256K;
|
|
977
1012
|
case "RSA":
|
|
978
|
-
return import_ssi_types.JoseSignatureAlgorithm.
|
|
1013
|
+
return import_ssi_types.JoseSignatureAlgorithm.RS256;
|
|
979
1014
|
default:
|
|
980
1015
|
throw new Error(`Key type '${type}' not supported`);
|
|
981
1016
|
}
|
|
@@ -1227,7 +1262,8 @@ function toPkcs1FromHex(publicKeyHex) {
|
|
|
1227
1262
|
}
|
|
1228
1263
|
__name(toPkcs1FromHex, "toPkcs1FromHex");
|
|
1229
1264
|
function joseAlgorithmToDigest(alg) {
|
|
1230
|
-
|
|
1265
|
+
const normalized = alg.toUpperCase().replace(/-/g, "");
|
|
1266
|
+
switch (normalized) {
|
|
1231
1267
|
case "RS256":
|
|
1232
1268
|
case "ES256":
|
|
1233
1269
|
case "ES256K":
|
|
@@ -1244,10 +1280,11 @@ function joseAlgorithmToDigest(alg) {
|
|
|
1244
1280
|
case "PS512":
|
|
1245
1281
|
case "HS512":
|
|
1246
1282
|
return "SHA-512";
|
|
1247
|
-
case "
|
|
1283
|
+
case "EDDSA":
|
|
1284
|
+
case "ED25519":
|
|
1248
1285
|
return "SHA-512";
|
|
1249
1286
|
default:
|
|
1250
|
-
|
|
1287
|
+
throw new Error(`Unsupported JOSE algorithm: ${alg}. Cannot determine digest algorithm.`);
|
|
1251
1288
|
}
|
|
1252
1289
|
}
|
|
1253
1290
|
__name(joseAlgorithmToDigest, "joseAlgorithmToDigest");
|
|
@@ -1264,16 +1301,18 @@ function isHashString(input) {
|
|
|
1264
1301
|
if (length !== 32 && length !== 48 && length !== 64) {
|
|
1265
1302
|
return false;
|
|
1266
1303
|
}
|
|
1304
|
+
let printableCount = 0;
|
|
1267
1305
|
for (let i = 0; i < length; i++) {
|
|
1268
1306
|
const byte = input[i];
|
|
1269
1307
|
if (byte === void 0) {
|
|
1270
1308
|
return false;
|
|
1271
1309
|
}
|
|
1272
|
-
if (
|
|
1273
|
-
|
|
1310
|
+
if (byte >= 32 && byte <= 126) {
|
|
1311
|
+
printableCount++;
|
|
1274
1312
|
}
|
|
1275
1313
|
}
|
|
1276
|
-
|
|
1314
|
+
const printableRatio = printableCount / length;
|
|
1315
|
+
return printableRatio < 0.9;
|
|
1277
1316
|
}
|
|
1278
1317
|
__name(isHashString, "isHashString");
|
|
1279
1318
|
function normalizeHashAlgorithm(alg) {
|