@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.d.ts CHANGED
@@ -45,6 +45,7 @@ type SignatureAlgorithmFromKeyArgs = {
45
45
  };
46
46
  type SignatureAlgorithmFromKeyTypeArgs = {
47
47
  type: TKeyType;
48
+ algorithms?: string[];
48
49
  };
49
50
  type KeyTypeFromCryptographicSuiteArgs = {
50
51
  crv?: string;
@@ -138,6 +139,7 @@ declare const isRawCompressedPublicKey: (key: Uint8Array) => boolean;
138
139
  declare const toRawCompressedHexPublicKey: (rawPublicKey: Uint8Array, keyType: TKeyType) => string;
139
140
  declare const hexStringFromUint8Array: (value: Uint8Array) => string;
140
141
  declare const signatureAlgorithmFromKey: (args: SignatureAlgorithmFromKeyArgs) => Promise<JoseSignatureAlgorithm>;
142
+ declare function signatureAlgorithmToJoseAlgorithm(alg: string): JoseSignatureAlgorithm;
141
143
  declare const signatureAlgorithmFromKeyType: (args: SignatureAlgorithmFromKeyTypeArgs) => JoseSignatureAlgorithm;
142
144
  declare const keyTypeFromCryptographicSuite: (args: KeyTypeFromCryptographicSuiteArgs) => TKeyType;
143
145
  declare function removeNulls<T>(obj: T | any): any;
@@ -188,6 +190,11 @@ declare function joseToCoseKeyOperation(keyOp: JoseKeyOperation | JoseKeyOperati
188
190
  declare function coseToJoseKeyOperation(keyOp: ICoseKeyOperation): JoseKeyOperation;
189
191
  declare function joseToCoseCurve(curve: JoseCurve | JoseCurveString): ICoseCurve;
190
192
  declare function coseToJoseCurve(curve: ICoseCurve): JoseCurve;
193
+ declare function joseSignatureAlgToWebCrypto(alg: JoseSignatureAlgorithm | JoseSignatureAlgorithmString): {
194
+ name: string;
195
+ hash: string;
196
+ saltLength?: number;
197
+ };
191
198
 
192
199
  /**
193
200
  * Checks if the JWK is valid. It must contain all the required members.
@@ -237,4 +244,4 @@ declare const digestMethodParams: (hashAlgorithm: DigestAlgorithm) => {
237
244
  };
238
245
  declare const shaHasher: HasherSync;
239
246
 
240
- export { type DigestAlgorithm, ENC_KEY_ALGS, type HashAlgorithm, type IImportProvidedOrGeneratedKeyArgs, type IKeyOpts, JWK_JCS_PUB_NAME, JWK_JCS_PUB_PREFIX, JwkKeyUse, Key, type KeyTypeFromCryptographicSuiteArgs, type KeyVisibility, SIG_KEY_ALGS, type SignatureAlgorithmFromKeyArgs, type SignatureAlgorithmFromKeyTypeArgs, type TDigestMethod, type TKeyType, type X509Opts, asn1DerToRawPublicKey, base64ToBase64Url, calculateJwkThumbprint, calculateJwkThumbprintForKey, coseKeyToJwk, coseToJoseCurve, coseToJoseKeyOperation, coseToJoseKty, coseToJoseSignatureAlg, digestMethodParams, generatePrivateKeyHex, getKms, globalCrypto, hexStringFromUint8Array, importProvidedOrGeneratedKey, isAsn1Der, isHash, isHashString, isRawCompressedPublicKey, isSameHash, jcsCanonicalize, joseAlgorithmToDigest, joseToCoseCurve, joseToCoseKeyOperation, joseToCoseKty, joseToCoseSignatureAlg, jwkDetermineUse, jwkJcsDecode, jwkJcsEncode, jwkToCoseKey, jwkToRawHexKey, keyTypeFromCryptographicSuite, logger, minimalJwk, normalizeHashAlgorithm, padLeft, removeNulls, rsaJwkToRawHexKey, sanitizedJwk, shaHasher, signatureAlgorithmFromKey, signatureAlgorithmFromKeyType, toBase64url, toJwk, toJwkFromKey, toPkcs1, toPkcs1FromHex, toRawCompressedHexPublicKey, validateJwk, verifyRawSignature, x25519PublicHexFromPrivateHex };
247
+ export { type DigestAlgorithm, ENC_KEY_ALGS, type HashAlgorithm, type IImportProvidedOrGeneratedKeyArgs, type IKeyOpts, JWK_JCS_PUB_NAME, JWK_JCS_PUB_PREFIX, JwkKeyUse, Key, type KeyTypeFromCryptographicSuiteArgs, type KeyVisibility, SIG_KEY_ALGS, type SignatureAlgorithmFromKeyArgs, type SignatureAlgorithmFromKeyTypeArgs, type TDigestMethod, type TKeyType, type X509Opts, asn1DerToRawPublicKey, base64ToBase64Url, calculateJwkThumbprint, calculateJwkThumbprintForKey, coseKeyToJwk, coseToJoseCurve, coseToJoseKeyOperation, coseToJoseKty, coseToJoseSignatureAlg, digestMethodParams, generatePrivateKeyHex, getKms, globalCrypto, hexStringFromUint8Array, importProvidedOrGeneratedKey, isAsn1Der, isHash, isHashString, isRawCompressedPublicKey, isSameHash, jcsCanonicalize, joseAlgorithmToDigest, joseSignatureAlgToWebCrypto, joseToCoseCurve, joseToCoseKeyOperation, joseToCoseKty, joseToCoseSignatureAlg, jwkDetermineUse, jwkJcsDecode, jwkJcsEncode, jwkToCoseKey, jwkToRawHexKey, keyTypeFromCryptographicSuite, logger, minimalJwk, normalizeHashAlgorithm, padLeft, removeNulls, rsaJwkToRawHexKey, sanitizedJwk, shaHasher, signatureAlgorithmFromKey, signatureAlgorithmFromKeyType, signatureAlgorithmToJoseAlgorithm, toBase64url, toJwk, toJwkFromKey, toPkcs1, toPkcs1FromHex, toRawCompressedHexPublicKey, validateJwk, verifyRawSignature, x25519PublicHexFromPrivateHex };
package/dist/index.js CHANGED
@@ -868,11 +868,45 @@ var hexStringFromUint8Array = /* @__PURE__ */ __name((value) => toString2(value,
868
868
  var signatureAlgorithmFromKey = /* @__PURE__ */ __name(async (args) => {
869
869
  const { key } = args;
870
870
  return signatureAlgorithmFromKeyType({
871
- type: key.type
871
+ type: key.type,
872
+ algorithms: key.meta?.algorithms
872
873
  });
873
874
  }, "signatureAlgorithmFromKey");
875
+ function signatureAlgorithmToJoseAlgorithm(alg) {
876
+ switch (alg) {
877
+ case "RSA_SHA256":
878
+ return JoseSignatureAlgorithm.RS256;
879
+ case "RSA_SHA384":
880
+ return JoseSignatureAlgorithm.RS384;
881
+ case "RSA_SHA512":
882
+ return JoseSignatureAlgorithm.RS512;
883
+ case "RSA_SSA_PSS_SHA256_MGF1":
884
+ return JoseSignatureAlgorithm.PS256;
885
+ case "RSA_SSA_PSS_SHA384_MGF1":
886
+ return JoseSignatureAlgorithm.PS384;
887
+ case "RSA_SSA_PSS_SHA512_MGF1":
888
+ return JoseSignatureAlgorithm.PS512;
889
+ case "ECDSA_SHA256":
890
+ return JoseSignatureAlgorithm.ES256;
891
+ case "ECDSA_SHA384":
892
+ return JoseSignatureAlgorithm.ES384;
893
+ case "ECDSA_SHA512":
894
+ return JoseSignatureAlgorithm.ES512;
895
+ case "ES256K":
896
+ return JoseSignatureAlgorithm.ES256K;
897
+ case "ED25519":
898
+ case "EdDSA":
899
+ return JoseSignatureAlgorithm.EdDSA;
900
+ default:
901
+ return alg;
902
+ }
903
+ }
904
+ __name(signatureAlgorithmToJoseAlgorithm, "signatureAlgorithmToJoseAlgorithm");
874
905
  var signatureAlgorithmFromKeyType = /* @__PURE__ */ __name((args) => {
875
- const { type } = args;
906
+ const { type, algorithms } = args;
907
+ if (algorithms && algorithms.length > 0) {
908
+ return signatureAlgorithmToJoseAlgorithm(algorithms[0]);
909
+ }
876
910
  switch (type) {
877
911
  case "Ed25519":
878
912
  case "X25519":
@@ -886,7 +920,7 @@ var signatureAlgorithmFromKeyType = /* @__PURE__ */ __name((args) => {
886
920
  case "Secp256k1":
887
921
  return JoseSignatureAlgorithm.ES256K;
888
922
  case "RSA":
889
- return JoseSignatureAlgorithm.PS256;
923
+ return JoseSignatureAlgorithm.RS256;
890
924
  default:
891
925
  throw new Error(`Key type '${type}' not supported`);
892
926
  }
@@ -1138,7 +1172,8 @@ function toPkcs1FromHex(publicKeyHex) {
1138
1172
  }
1139
1173
  __name(toPkcs1FromHex, "toPkcs1FromHex");
1140
1174
  function joseAlgorithmToDigest(alg) {
1141
- switch (alg.toUpperCase().replace("-", "")) {
1175
+ const normalized = alg.toUpperCase().replace(/-/g, "");
1176
+ switch (normalized) {
1142
1177
  case "RS256":
1143
1178
  case "ES256":
1144
1179
  case "ES256K":
@@ -1155,10 +1190,11 @@ function joseAlgorithmToDigest(alg) {
1155
1190
  case "PS512":
1156
1191
  case "HS512":
1157
1192
  return "SHA-512";
1158
- case "EdDSA":
1193
+ case "EDDSA":
1194
+ case "ED25519":
1159
1195
  return "SHA-512";
1160
1196
  default:
1161
- return "SHA-256";
1197
+ throw new Error(`Unsupported JOSE algorithm: ${alg}. Cannot determine digest algorithm.`);
1162
1198
  }
1163
1199
  }
1164
1200
  __name(joseAlgorithmToDigest, "joseAlgorithmToDigest");
@@ -1175,16 +1211,18 @@ function isHashString(input) {
1175
1211
  if (length !== 32 && length !== 48 && length !== 64) {
1176
1212
  return false;
1177
1213
  }
1214
+ let printableCount = 0;
1178
1215
  for (let i = 0; i < length; i++) {
1179
1216
  const byte = input[i];
1180
1217
  if (byte === void 0) {
1181
1218
  return false;
1182
1219
  }
1183
- if (!(byte >= 48 && byte <= 57 || byte >= 65 && byte <= 70 || byte >= 97 && byte <= 102)) {
1184
- return false;
1220
+ if (byte >= 32 && byte <= 126) {
1221
+ printableCount++;
1185
1222
  }
1186
1223
  }
1187
- return true;
1224
+ const printableRatio = printableCount / length;
1225
+ return printableRatio < 0.9;
1188
1226
  }
1189
1227
  __name(isHashString, "isHashString");
1190
1228
  function normalizeHashAlgorithm(alg) {
@@ -1450,6 +1488,100 @@ function coseToJoseCurve(curve) {
1450
1488
  }
1451
1489
  }
1452
1490
  __name(coseToJoseCurve, "coseToJoseCurve");
1491
+ function joseSignatureAlgToWebCrypto(alg) {
1492
+ switch (alg) {
1493
+ case JoseSignatureAlgorithm2.RS256:
1494
+ case "RS256":
1495
+ return {
1496
+ name: "RSASSA-PKCS1-v1_5",
1497
+ hash: "SHA-256"
1498
+ };
1499
+ case JoseSignatureAlgorithm2.RS384:
1500
+ case "RS384":
1501
+ return {
1502
+ name: "RSASSA-PKCS1-v1_5",
1503
+ hash: "SHA-384"
1504
+ };
1505
+ case JoseSignatureAlgorithm2.RS512:
1506
+ case "RS512":
1507
+ return {
1508
+ name: "RSASSA-PKCS1-v1_5",
1509
+ hash: "SHA-512"
1510
+ };
1511
+ case JoseSignatureAlgorithm2.PS256:
1512
+ case "PS256":
1513
+ return {
1514
+ name: "RSA-PSS",
1515
+ hash: "SHA-256",
1516
+ saltLength: 32
1517
+ };
1518
+ case JoseSignatureAlgorithm2.PS384:
1519
+ case "PS384":
1520
+ return {
1521
+ name: "RSA-PSS",
1522
+ hash: "SHA-384",
1523
+ saltLength: 48
1524
+ };
1525
+ case JoseSignatureAlgorithm2.PS512:
1526
+ case "PS512":
1527
+ return {
1528
+ name: "RSA-PSS",
1529
+ hash: "SHA-512",
1530
+ saltLength: 64
1531
+ };
1532
+ case JoseSignatureAlgorithm2.ES256:
1533
+ case "ES256":
1534
+ return {
1535
+ name: "ECDSA",
1536
+ hash: "SHA-256"
1537
+ };
1538
+ case JoseSignatureAlgorithm2.ES384:
1539
+ case "ES384":
1540
+ return {
1541
+ name: "ECDSA",
1542
+ hash: "SHA-384"
1543
+ };
1544
+ case JoseSignatureAlgorithm2.ES512:
1545
+ case "ES512":
1546
+ return {
1547
+ name: "ECDSA",
1548
+ hash: "SHA-512"
1549
+ };
1550
+ case JoseSignatureAlgorithm2.ES256K:
1551
+ case "ES256K":
1552
+ return {
1553
+ name: "ECDSA",
1554
+ hash: "SHA-256"
1555
+ };
1556
+ case JoseSignatureAlgorithm2.EdDSA:
1557
+ case "EdDSA":
1558
+ return {
1559
+ name: "Ed25519",
1560
+ hash: ""
1561
+ };
1562
+ case JoseSignatureAlgorithm2.HS256:
1563
+ case "HS256":
1564
+ return {
1565
+ name: "HMAC",
1566
+ hash: "SHA-256"
1567
+ };
1568
+ case JoseSignatureAlgorithm2.HS384:
1569
+ case "HS384":
1570
+ return {
1571
+ name: "HMAC",
1572
+ hash: "SHA-384"
1573
+ };
1574
+ case JoseSignatureAlgorithm2.HS512:
1575
+ case "HS512":
1576
+ return {
1577
+ name: "HMAC",
1578
+ hash: "SHA-512"
1579
+ };
1580
+ default:
1581
+ throw Error(`Signature algorithm ${alg} not supported in Web Crypto API`);
1582
+ }
1583
+ }
1584
+ __name(joseSignatureAlgToWebCrypto, "joseSignatureAlgToWebCrypto");
1453
1585
  export {
1454
1586
  ENC_KEY_ALGS,
1455
1587
  JWK_JCS_PUB_NAME,
@@ -1479,6 +1611,7 @@ export {
1479
1611
  isSameHash,
1480
1612
  jcsCanonicalize,
1481
1613
  joseAlgorithmToDigest,
1614
+ joseSignatureAlgToWebCrypto,
1482
1615
  joseToCoseCurve,
1483
1616
  joseToCoseKeyOperation,
1484
1617
  joseToCoseKty,
@@ -1499,6 +1632,7 @@ export {
1499
1632
  shaHasher,
1500
1633
  signatureAlgorithmFromKey,
1501
1634
  signatureAlgorithmFromKeyType,
1635
+ signatureAlgorithmToJoseAlgorithm,
1502
1636
  toBase64url,
1503
1637
  toJwk,
1504
1638
  toJwkFromKey,