@sphereon/ssi-sdk-ext.key-utils 0.36.1-feature.SSISDK.82.and.SSISDK.70.35 → 0.36.1-next.11

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
@@ -20,7 +20,6 @@ declare enum JwkKeyUse {
20
20
  declare const SIG_KEY_ALGS: string[];
21
21
  declare const ENC_KEY_ALGS: string[];
22
22
  type KeyVisibility = 'public' | 'private';
23
- type DigestAlgorithm = 'SHA-256' | 'sha256' | 'SHA-384' | 'sha384' | 'SHA-512' | 'sha512';
24
23
  interface X509Opts {
25
24
  cn?: string;
26
25
  privateKeyPEM?: string;
@@ -87,7 +86,7 @@ declare const toBase64url: (input: string) => string;
87
86
  */
88
87
  declare const calculateJwkThumbprint: (args: {
89
88
  jwk: JWK;
90
- digestAlgorithm?: DigestAlgorithm;
89
+ digestAlgorithm?: "sha256" | "sha512";
91
90
  }) => string;
92
91
  declare const toJwkFromKey: (key: IKey | MinimalImportableKey | ManagedKeyInfo, opts?: {
93
92
  use?: JwkKeyUse;
@@ -143,7 +142,6 @@ declare const keyTypeFromCryptographicSuite: (args: KeyTypeFromCryptographicSuit
143
142
  declare function removeNulls<T>(obj: T | any): any;
144
143
  declare const globalCrypto: (setGlobal: boolean, suppliedCrypto?: Crypto) => Crypto;
145
144
  declare const sanitizedJwk: (input: JWK | JsonWebKey) => JWK;
146
- declare const base64ToBase64Url: (input: string) => string;
147
145
  /**
148
146
  *
149
147
  */
@@ -171,12 +169,6 @@ declare function toPkcs1(derBytes: Uint8Array): Uint8Array;
171
169
  * @returns DER‐encoded PKCS#1 RSAPublicKey in hex
172
170
  */
173
171
  declare function toPkcs1FromHex(publicKeyHex: string): any;
174
- declare function joseAlgorithmToDigest(alg: string): DigestAlgorithm;
175
- declare function isHash(input: string): boolean;
176
- declare function isHashString(input: Uint8Array): boolean;
177
- type HashAlgorithm = 'SHA-256' | 'sha256' | 'SHA-384' | 'sha384' | 'SHA-512' | 'sha512';
178
- declare function normalizeHashAlgorithm(alg?: HashAlgorithm): 'SHA-256' | 'SHA-384' | 'SHA-512';
179
- declare function isSameHash(left: HashAlgorithm, right: HashAlgorithm): boolean;
180
172
 
181
173
  declare function coseKeyToJwk(coseKey: ICoseKeyJson): JWK;
182
174
  declare function jwkToCoseKey(jwk: JWK): ICoseKeyJson;
@@ -229,12 +221,13 @@ declare function jwkJcsDecode(bytes: ByteView<JsonWebKey$1>): JsonWebKey$1;
229
221
  declare function jcsCanonicalize(object: any): string;
230
222
 
231
223
  declare const SupportedEncodings: any;
224
+ type HashAlgorithm = 'SHA-256' | 'SHA-384' | 'SHA-512';
232
225
  type TDigestMethod = (input: string, encoding?: typeof SupportedEncodings) => string;
233
- declare const digestMethodParams: (hashAlgorithm: DigestAlgorithm) => {
234
- hashAlgorithm: DigestAlgorithm;
226
+ declare const digestMethodParams: (hashAlgorithm: HashAlgorithm) => {
227
+ hashAlgorithm: HashAlgorithm;
235
228
  digestMethod: TDigestMethod;
236
229
  hash: (data: Uint8Array) => Uint8Array;
237
230
  };
238
231
  declare const shaHasher: HasherSync;
239
232
 
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 };
233
+ export { 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, calculateJwkThumbprint, calculateJwkThumbprintForKey, coseKeyToJwk, coseToJoseCurve, coseToJoseKeyOperation, coseToJoseKty, coseToJoseSignatureAlg, digestMethodParams, generatePrivateKeyHex, getKms, globalCrypto, hexStringFromUint8Array, importProvidedOrGeneratedKey, isAsn1Der, isRawCompressedPublicKey, jcsCanonicalize, joseToCoseCurve, joseToCoseKeyOperation, joseToCoseKty, joseToCoseSignatureAlg, jwkDetermineUse, jwkJcsDecode, jwkJcsEncode, jwkToCoseKey, jwkToRawHexKey, keyTypeFromCryptographicSuite, logger, minimalJwk, padLeft, removeNulls, rsaJwkToRawHexKey, sanitizedJwk, shaHasher, signatureAlgorithmFromKey, signatureAlgorithmFromKeyType, toBase64url, toJwk, toJwkFromKey, toPkcs1, toPkcs1FromHex, toRawCompressedHexPublicKey, validateJwk, verifyRawSignature, x25519PublicHexFromPrivateHex };
package/dist/index.js CHANGED
@@ -24,25 +24,24 @@ import { sha384, sha512 } from "@noble/hashes/sha512";
24
24
  import * as u8a from "uint8arrays";
25
25
  var { fromString, toString, SupportedEncodings } = u8a;
26
26
  var digestMethodParams = /* @__PURE__ */ __name((hashAlgorithm) => {
27
- switch (normalizeHashAlgorithm(hashAlgorithm)) {
28
- case "SHA-256":
29
- return {
30
- hashAlgorithm: "SHA-256",
31
- digestMethod: sha256DigestMethod,
32
- hash: sha256
33
- };
34
- case "SHA-384":
35
- return {
36
- hashAlgorithm: "SHA-384",
37
- digestMethod: sha384DigestMethod,
38
- hash: sha384
39
- };
40
- case "SHA-512":
41
- return {
42
- hashAlgorithm: "SHA-512",
43
- digestMethod: sha512DigestMethod,
44
- hash: sha512
45
- };
27
+ if (hashAlgorithm === "SHA-256") {
28
+ return {
29
+ hashAlgorithm: "SHA-256",
30
+ digestMethod: sha256DigestMethod,
31
+ hash: sha256
32
+ };
33
+ } else if (hashAlgorithm === "SHA-384") {
34
+ return {
35
+ hashAlgorithm: "SHA-384",
36
+ digestMethod: sha384DigestMethod,
37
+ hash: sha384
38
+ };
39
+ } else {
40
+ return {
41
+ hashAlgorithm: "SHA-512",
42
+ digestMethod: sha512DigestMethod,
43
+ hash: sha512
44
+ };
46
45
  }
47
46
  }, "digestMethodParams");
48
47
  var shaHasher = /* @__PURE__ */ __name((input, alg) => {
@@ -366,7 +365,7 @@ var assertJwkClaimPresent = /* @__PURE__ */ __name((value, description) => {
366
365
  }, "assertJwkClaimPresent");
367
366
  var toBase64url = /* @__PURE__ */ __name((input) => toString2(fromString2(input), "base64url"), "toBase64url");
368
367
  var calculateJwkThumbprint = /* @__PURE__ */ __name((args) => {
369
- const digestAlgorithm = normalizeHashAlgorithm(args.digestAlgorithm ?? "SHA-256");
368
+ const { digestAlgorithm = "sha256" } = args;
370
369
  const jwk = sanitizedJwk(args.jwk);
371
370
  let components;
372
371
  switch (jwk.kty) {
@@ -410,7 +409,7 @@ var calculateJwkThumbprint = /* @__PURE__ */ __name((args) => {
410
409
  throw new Error('"kty" (Key Type) Parameter missing or unsupported');
411
410
  }
412
411
  const data = JSON.stringify(components);
413
- return digestMethodParams(digestAlgorithm).digestMethod(data, "base64url");
412
+ return digestAlgorithm === "sha512" ? digestMethodParams("SHA-512").digestMethod(data, "base64url") : digestMethodParams("SHA-256").digestMethod(data, "base64url");
414
413
  }, "calculateJwkThumbprint");
415
414
  var toJwkFromKey = /* @__PURE__ */ __name((key, opts) => {
416
415
  const isPrivateKey = "privateKeyHex" in key;
@@ -1137,71 +1136,6 @@ function toPkcs1FromHex(publicKeyHex) {
1137
1136
  return toString2(pkcs1, "hex");
1138
1137
  }
1139
1138
  __name(toPkcs1FromHex, "toPkcs1FromHex");
1140
- function joseAlgorithmToDigest(alg) {
1141
- switch (alg.toUpperCase().replace("-", "")) {
1142
- case "RS256":
1143
- case "ES256":
1144
- case "ES256K":
1145
- case "PS256":
1146
- case "HS256":
1147
- return "SHA-256";
1148
- case "RS384":
1149
- case "ES384":
1150
- case "PS384":
1151
- case "HS384":
1152
- return "SHA-384";
1153
- case "RS512":
1154
- case "ES512":
1155
- case "PS512":
1156
- case "HS512":
1157
- return "SHA-512";
1158
- case "EdDSA":
1159
- return "SHA-512";
1160
- default:
1161
- return "SHA-256";
1162
- }
1163
- }
1164
- __name(joseAlgorithmToDigest, "joseAlgorithmToDigest");
1165
- function isHash(input) {
1166
- const length = input.length;
1167
- if (length !== 64 && length !== 96 && length !== 128) {
1168
- return false;
1169
- }
1170
- return input.match(/^([0-9A-Fa-f])+$/g) !== null;
1171
- }
1172
- __name(isHash, "isHash");
1173
- function isHashString(input) {
1174
- const length = input.length;
1175
- if (length !== 32 && length !== 48 && length !== 64) {
1176
- return false;
1177
- }
1178
- for (let i = 0; i < length; i++) {
1179
- const byte = input[i];
1180
- if (byte === void 0) {
1181
- return false;
1182
- }
1183
- if (!(byte >= 48 && byte <= 57 || byte >= 65 && byte <= 70 || byte >= 97 && byte <= 102)) {
1184
- return false;
1185
- }
1186
- }
1187
- return true;
1188
- }
1189
- __name(isHashString, "isHashString");
1190
- function normalizeHashAlgorithm(alg) {
1191
- if (!alg) {
1192
- return "SHA-256";
1193
- }
1194
- const upper = alg.toUpperCase();
1195
- if (upper.includes("256")) return "SHA-256";
1196
- if (upper.includes("384")) return "SHA-384";
1197
- if (upper.includes("512")) return "SHA-512";
1198
- throw new Error(`Invalid hash algorithm: ${alg}`);
1199
- }
1200
- __name(normalizeHashAlgorithm, "normalizeHashAlgorithm");
1201
- function isSameHash(left, right) {
1202
- return normalizeHashAlgorithm(left) === normalizeHashAlgorithm(right);
1203
- }
1204
- __name(isSameHash, "isSameHash");
1205
1139
 
1206
1140
  // src/conversion.ts
1207
1141
  import { ICoseCurve, ICoseKeyOperation, ICoseKeyType, ICoseSignatureAlgorithm, JoseCurve as JoseCurve2, JoseKeyOperation, JoseSignatureAlgorithm as JoseSignatureAlgorithm2, JwkKeyType as JwkKeyType2 } from "@sphereon/ssi-types";
@@ -1458,7 +1392,6 @@ export {
1458
1392
  Key,
1459
1393
  SIG_KEY_ALGS,
1460
1394
  asn1DerToRawPublicKey,
1461
- base64ToBase64Url,
1462
1395
  calculateJwkThumbprint,
1463
1396
  calculateJwkThumbprintForKey,
1464
1397
  coseKeyToJwk,
@@ -1473,12 +1406,8 @@ export {
1473
1406
  hexStringFromUint8Array,
1474
1407
  importProvidedOrGeneratedKey,
1475
1408
  isAsn1Der,
1476
- isHash,
1477
- isHashString,
1478
1409
  isRawCompressedPublicKey,
1479
- isSameHash,
1480
1410
  jcsCanonicalize,
1481
- joseAlgorithmToDigest,
1482
1411
  joseToCoseCurve,
1483
1412
  joseToCoseKeyOperation,
1484
1413
  joseToCoseKty,
@@ -1491,7 +1420,6 @@ export {
1491
1420
  keyTypeFromCryptographicSuite,
1492
1421
  logger,
1493
1422
  minimalJwk,
1494
- normalizeHashAlgorithm,
1495
1423
  padLeft,
1496
1424
  removeNulls,
1497
1425
  rsaJwkToRawHexKey,