@sphereon/ssi-sdk-ext.key-utils 0.36.1-feature.SSISDK.82.and.SSISDK.70.35 → 0.36.1-feature.SSISDK.89.metadata.persistence.103

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 CHANGED
@@ -59,6 +59,7 @@ __export(index_exports, {
59
59
  isSameHash: () => isSameHash,
60
60
  jcsCanonicalize: () => jcsCanonicalize,
61
61
  joseAlgorithmToDigest: () => joseAlgorithmToDigest,
62
+ joseSignatureAlgToWebCrypto: () => joseSignatureAlgToWebCrypto,
62
63
  joseToCoseCurve: () => joseToCoseCurve,
63
64
  joseToCoseKeyOperation: () => joseToCoseKeyOperation,
64
65
  joseToCoseKty: () => joseToCoseKty,
@@ -79,6 +80,7 @@ __export(index_exports, {
79
80
  shaHasher: () => shaHasher,
80
81
  signatureAlgorithmFromKey: () => signatureAlgorithmFromKey,
81
82
  signatureAlgorithmFromKeyType: () => signatureAlgorithmFromKeyType,
83
+ signatureAlgorithmToJoseAlgorithm: () => signatureAlgorithmToJoseAlgorithm,
82
84
  toBase64url: () => toBase64url,
83
85
  toJwk: () => toJwk,
84
86
  toJwkFromKey: () => toJwkFromKey,
@@ -958,11 +960,45 @@ var hexStringFromUint8Array = /* @__PURE__ */ __name((value) => toString2(value,
958
960
  var signatureAlgorithmFromKey = /* @__PURE__ */ __name(async (args) => {
959
961
  const { key } = args;
960
962
  return signatureAlgorithmFromKeyType({
961
- type: key.type
963
+ type: key.type,
964
+ algorithms: key.meta?.algorithms
962
965
  });
963
966
  }, "signatureAlgorithmFromKey");
967
+ function signatureAlgorithmToJoseAlgorithm(alg) {
968
+ switch (alg) {
969
+ case "RSA_SHA256":
970
+ return import_ssi_types.JoseSignatureAlgorithm.RS256;
971
+ case "RSA_SHA384":
972
+ return import_ssi_types.JoseSignatureAlgorithm.RS384;
973
+ case "RSA_SHA512":
974
+ return import_ssi_types.JoseSignatureAlgorithm.RS512;
975
+ case "RSA_SSA_PSS_SHA256_MGF1":
976
+ return import_ssi_types.JoseSignatureAlgorithm.PS256;
977
+ case "RSA_SSA_PSS_SHA384_MGF1":
978
+ return import_ssi_types.JoseSignatureAlgorithm.PS384;
979
+ case "RSA_SSA_PSS_SHA512_MGF1":
980
+ return import_ssi_types.JoseSignatureAlgorithm.PS512;
981
+ case "ECDSA_SHA256":
982
+ return import_ssi_types.JoseSignatureAlgorithm.ES256;
983
+ case "ECDSA_SHA384":
984
+ return import_ssi_types.JoseSignatureAlgorithm.ES384;
985
+ case "ECDSA_SHA512":
986
+ return import_ssi_types.JoseSignatureAlgorithm.ES512;
987
+ case "ES256K":
988
+ return import_ssi_types.JoseSignatureAlgorithm.ES256K;
989
+ case "ED25519":
990
+ case "EdDSA":
991
+ return import_ssi_types.JoseSignatureAlgorithm.EdDSA;
992
+ default:
993
+ return alg;
994
+ }
995
+ }
996
+ __name(signatureAlgorithmToJoseAlgorithm, "signatureAlgorithmToJoseAlgorithm");
964
997
  var signatureAlgorithmFromKeyType = /* @__PURE__ */ __name((args) => {
965
- const { type } = args;
998
+ const { type, algorithms } = args;
999
+ if (algorithms && algorithms.length > 0) {
1000
+ return signatureAlgorithmToJoseAlgorithm(algorithms[0]);
1001
+ }
966
1002
  switch (type) {
967
1003
  case "Ed25519":
968
1004
  case "X25519":
@@ -976,7 +1012,7 @@ var signatureAlgorithmFromKeyType = /* @__PURE__ */ __name((args) => {
976
1012
  case "Secp256k1":
977
1013
  return import_ssi_types.JoseSignatureAlgorithm.ES256K;
978
1014
  case "RSA":
979
- return import_ssi_types.JoseSignatureAlgorithm.PS256;
1015
+ return import_ssi_types.JoseSignatureAlgorithm.RS256;
980
1016
  default:
981
1017
  throw new Error(`Key type '${type}' not supported`);
982
1018
  }
@@ -1228,7 +1264,8 @@ function toPkcs1FromHex(publicKeyHex) {
1228
1264
  }
1229
1265
  __name(toPkcs1FromHex, "toPkcs1FromHex");
1230
1266
  function joseAlgorithmToDigest(alg) {
1231
- switch (alg.toUpperCase().replace("-", "")) {
1267
+ const normalized = alg.toUpperCase().replace(/-/g, "");
1268
+ switch (normalized) {
1232
1269
  case "RS256":
1233
1270
  case "ES256":
1234
1271
  case "ES256K":
@@ -1245,10 +1282,11 @@ function joseAlgorithmToDigest(alg) {
1245
1282
  case "PS512":
1246
1283
  case "HS512":
1247
1284
  return "SHA-512";
1248
- case "EdDSA":
1285
+ case "EDDSA":
1286
+ case "ED25519":
1249
1287
  return "SHA-512";
1250
1288
  default:
1251
- return "SHA-256";
1289
+ throw new Error(`Unsupported JOSE algorithm: ${alg}. Cannot determine digest algorithm.`);
1252
1290
  }
1253
1291
  }
1254
1292
  __name(joseAlgorithmToDigest, "joseAlgorithmToDigest");
@@ -1265,16 +1303,18 @@ function isHashString(input) {
1265
1303
  if (length !== 32 && length !== 48 && length !== 64) {
1266
1304
  return false;
1267
1305
  }
1306
+ let printableCount = 0;
1268
1307
  for (let i = 0; i < length; i++) {
1269
1308
  const byte = input[i];
1270
1309
  if (byte === void 0) {
1271
1310
  return false;
1272
1311
  }
1273
- if (!(byte >= 48 && byte <= 57 || byte >= 65 && byte <= 70 || byte >= 97 && byte <= 102)) {
1274
- return false;
1312
+ if (byte >= 32 && byte <= 126) {
1313
+ printableCount++;
1275
1314
  }
1276
1315
  }
1277
- return true;
1316
+ const printableRatio = printableCount / length;
1317
+ return printableRatio < 0.9;
1278
1318
  }
1279
1319
  __name(isHashString, "isHashString");
1280
1320
  function normalizeHashAlgorithm(alg) {
@@ -1540,4 +1580,98 @@ function coseToJoseCurve(curve) {
1540
1580
  }
1541
1581
  }
1542
1582
  __name(coseToJoseCurve, "coseToJoseCurve");
1583
+ function joseSignatureAlgToWebCrypto(alg) {
1584
+ switch (alg) {
1585
+ case import_ssi_types2.JoseSignatureAlgorithm.RS256:
1586
+ case "RS256":
1587
+ return {
1588
+ name: "RSASSA-PKCS1-v1_5",
1589
+ hash: "SHA-256"
1590
+ };
1591
+ case import_ssi_types2.JoseSignatureAlgorithm.RS384:
1592
+ case "RS384":
1593
+ return {
1594
+ name: "RSASSA-PKCS1-v1_5",
1595
+ hash: "SHA-384"
1596
+ };
1597
+ case import_ssi_types2.JoseSignatureAlgorithm.RS512:
1598
+ case "RS512":
1599
+ return {
1600
+ name: "RSASSA-PKCS1-v1_5",
1601
+ hash: "SHA-512"
1602
+ };
1603
+ case import_ssi_types2.JoseSignatureAlgorithm.PS256:
1604
+ case "PS256":
1605
+ return {
1606
+ name: "RSA-PSS",
1607
+ hash: "SHA-256",
1608
+ saltLength: 32
1609
+ };
1610
+ case import_ssi_types2.JoseSignatureAlgorithm.PS384:
1611
+ case "PS384":
1612
+ return {
1613
+ name: "RSA-PSS",
1614
+ hash: "SHA-384",
1615
+ saltLength: 48
1616
+ };
1617
+ case import_ssi_types2.JoseSignatureAlgorithm.PS512:
1618
+ case "PS512":
1619
+ return {
1620
+ name: "RSA-PSS",
1621
+ hash: "SHA-512",
1622
+ saltLength: 64
1623
+ };
1624
+ case import_ssi_types2.JoseSignatureAlgorithm.ES256:
1625
+ case "ES256":
1626
+ return {
1627
+ name: "ECDSA",
1628
+ hash: "SHA-256"
1629
+ };
1630
+ case import_ssi_types2.JoseSignatureAlgorithm.ES384:
1631
+ case "ES384":
1632
+ return {
1633
+ name: "ECDSA",
1634
+ hash: "SHA-384"
1635
+ };
1636
+ case import_ssi_types2.JoseSignatureAlgorithm.ES512:
1637
+ case "ES512":
1638
+ return {
1639
+ name: "ECDSA",
1640
+ hash: "SHA-512"
1641
+ };
1642
+ case import_ssi_types2.JoseSignatureAlgorithm.ES256K:
1643
+ case "ES256K":
1644
+ return {
1645
+ name: "ECDSA",
1646
+ hash: "SHA-256"
1647
+ };
1648
+ case import_ssi_types2.JoseSignatureAlgorithm.EdDSA:
1649
+ case "EdDSA":
1650
+ return {
1651
+ name: "Ed25519",
1652
+ hash: ""
1653
+ };
1654
+ case import_ssi_types2.JoseSignatureAlgorithm.HS256:
1655
+ case "HS256":
1656
+ return {
1657
+ name: "HMAC",
1658
+ hash: "SHA-256"
1659
+ };
1660
+ case import_ssi_types2.JoseSignatureAlgorithm.HS384:
1661
+ case "HS384":
1662
+ return {
1663
+ name: "HMAC",
1664
+ hash: "SHA-384"
1665
+ };
1666
+ case import_ssi_types2.JoseSignatureAlgorithm.HS512:
1667
+ case "HS512":
1668
+ return {
1669
+ name: "HMAC",
1670
+ hash: "SHA-512"
1671
+ };
1672
+ default:
1673
+ throw Error(`Signature algorithm ${alg} not supported in Web Crypto API`);
1674
+ }
1675
+ }
1676
+ __name(joseSignatureAlgToWebCrypto, "joseSignatureAlgToWebCrypto");
1543
1677
  //# sourceMappingURL=index.cjs.map