@sphereon/ssi-sdk-ext.key-utils 0.36.1-feature.SSISDK.44.finish.dcql.1 → 0.36.1-feature.SSISDK.70.integrate.digidentity.10
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 +91 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -5
- package/dist/index.d.ts +11 -5
- package/dist/index.js +91 -20
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/digest-methods.ts +13 -11
- package/src/functions.ts +74 -6
- package/src/types/key-util-types.ts +2 -0
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ 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';
|
|
23
24
|
interface X509Opts {
|
|
24
25
|
cn?: string;
|
|
25
26
|
privateKeyPEM?: string;
|
|
@@ -86,7 +87,7 @@ declare const toBase64url: (input: string) => string;
|
|
|
86
87
|
*/
|
|
87
88
|
declare const calculateJwkThumbprint: (args: {
|
|
88
89
|
jwk: JWK;
|
|
89
|
-
digestAlgorithm?:
|
|
90
|
+
digestAlgorithm?: DigestAlgorithm;
|
|
90
91
|
}) => string;
|
|
91
92
|
declare const toJwkFromKey: (key: IKey | MinimalImportableKey | ManagedKeyInfo, opts?: {
|
|
92
93
|
use?: JwkKeyUse;
|
|
@@ -169,6 +170,12 @@ declare function toPkcs1(derBytes: Uint8Array): Uint8Array;
|
|
|
169
170
|
* @returns DER‐encoded PKCS#1 RSAPublicKey in hex
|
|
170
171
|
*/
|
|
171
172
|
declare function toPkcs1FromHex(publicKeyHex: string): any;
|
|
173
|
+
declare function joseAlgorithmToDigest(alg: string): DigestAlgorithm;
|
|
174
|
+
declare function isHash(input: string): boolean;
|
|
175
|
+
declare function isHashString(input: Uint8Array): boolean;
|
|
176
|
+
type HashAlgorithm = 'SHA-256' | 'sha256' | 'SHA-384' | 'sha384' | 'SHA-512' | 'sha512';
|
|
177
|
+
declare function normalizeHashAlgorithm(alg?: HashAlgorithm): 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
178
|
+
declare function isSameHash(left: HashAlgorithm, right: HashAlgorithm): boolean;
|
|
172
179
|
|
|
173
180
|
declare function coseKeyToJwk(coseKey: ICoseKeyJson): JWK;
|
|
174
181
|
declare function jwkToCoseKey(jwk: JWK): ICoseKeyJson;
|
|
@@ -221,13 +228,12 @@ declare function jwkJcsDecode(bytes: ByteView<JsonWebKey$1>): JsonWebKey$1;
|
|
|
221
228
|
declare function jcsCanonicalize(object: any): string;
|
|
222
229
|
|
|
223
230
|
declare const SupportedEncodings: any;
|
|
224
|
-
type HashAlgorithm = 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
225
231
|
type TDigestMethod = (input: string, encoding?: typeof SupportedEncodings) => string;
|
|
226
|
-
declare const digestMethodParams: (hashAlgorithm:
|
|
227
|
-
hashAlgorithm:
|
|
232
|
+
declare const digestMethodParams: (hashAlgorithm: DigestAlgorithm) => {
|
|
233
|
+
hashAlgorithm: DigestAlgorithm;
|
|
228
234
|
digestMethod: TDigestMethod;
|
|
229
235
|
hash: (data: Uint8Array) => Uint8Array;
|
|
230
236
|
};
|
|
231
237
|
declare const shaHasher: HasherSync;
|
|
232
238
|
|
|
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 };
|
|
239
|
+
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, 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 };
|
package/dist/index.js
CHANGED
|
@@ -24,24 +24,25 @@ 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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
+
};
|
|
45
46
|
}
|
|
46
47
|
}, "digestMethodParams");
|
|
47
48
|
var shaHasher = /* @__PURE__ */ __name((input, alg) => {
|
|
@@ -365,7 +366,7 @@ var assertJwkClaimPresent = /* @__PURE__ */ __name((value, description) => {
|
|
|
365
366
|
}, "assertJwkClaimPresent");
|
|
366
367
|
var toBase64url = /* @__PURE__ */ __name((input) => toString2(fromString2(input), "base64url"), "toBase64url");
|
|
367
368
|
var calculateJwkThumbprint = /* @__PURE__ */ __name((args) => {
|
|
368
|
-
const
|
|
369
|
+
const digestAlgorithm = normalizeHashAlgorithm(args.digestAlgorithm ?? "SHA-256");
|
|
369
370
|
const jwk = sanitizedJwk(args.jwk);
|
|
370
371
|
let components;
|
|
371
372
|
switch (jwk.kty) {
|
|
@@ -409,7 +410,7 @@ var calculateJwkThumbprint = /* @__PURE__ */ __name((args) => {
|
|
|
409
410
|
throw new Error('"kty" (Key Type) Parameter missing or unsupported');
|
|
410
411
|
}
|
|
411
412
|
const data = JSON.stringify(components);
|
|
412
|
-
return
|
|
413
|
+
return digestMethodParams(digestAlgorithm).digestMethod(data, "base64url");
|
|
413
414
|
}, "calculateJwkThumbprint");
|
|
414
415
|
var toJwkFromKey = /* @__PURE__ */ __name((key, opts) => {
|
|
415
416
|
const isPrivateKey = "privateKeyHex" in key;
|
|
@@ -1136,6 +1137,71 @@ function toPkcs1FromHex(publicKeyHex) {
|
|
|
1136
1137
|
return toString2(pkcs1, "hex");
|
|
1137
1138
|
}
|
|
1138
1139
|
__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");
|
|
1139
1205
|
|
|
1140
1206
|
// src/conversion.ts
|
|
1141
1207
|
import { ICoseCurve, ICoseKeyOperation, ICoseKeyType, ICoseSignatureAlgorithm, JoseCurve as JoseCurve2, JoseKeyOperation, JoseSignatureAlgorithm as JoseSignatureAlgorithm2, JwkKeyType as JwkKeyType2 } from "@sphereon/ssi-types";
|
|
@@ -1406,8 +1472,12 @@ export {
|
|
|
1406
1472
|
hexStringFromUint8Array,
|
|
1407
1473
|
importProvidedOrGeneratedKey,
|
|
1408
1474
|
isAsn1Der,
|
|
1475
|
+
isHash,
|
|
1476
|
+
isHashString,
|
|
1409
1477
|
isRawCompressedPublicKey,
|
|
1478
|
+
isSameHash,
|
|
1410
1479
|
jcsCanonicalize,
|
|
1480
|
+
joseAlgorithmToDigest,
|
|
1411
1481
|
joseToCoseCurve,
|
|
1412
1482
|
joseToCoseKeyOperation,
|
|
1413
1483
|
joseToCoseKty,
|
|
@@ -1420,6 +1490,7 @@ export {
|
|
|
1420
1490
|
keyTypeFromCryptographicSuite,
|
|
1421
1491
|
logger,
|
|
1422
1492
|
minimalJwk,
|
|
1493
|
+
normalizeHashAlgorithm,
|
|
1423
1494
|
padLeft,
|
|
1424
1495
|
removeNulls,
|
|
1425
1496
|
rsaJwkToRawHexKey,
|