@sphereon/ssi-sdk-ext.key-utils 0.36.1-feature.SSISDK.70.integrate.digidentity.56 → 0.36.1-feature.SSISDK.78.41
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 +23 -133
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -13
- package/dist/index.d.ts +5 -13
- package/dist/index.js +23 -133
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/digest-methods.ts +11 -13
- package/src/functions.ts +9 -133
- package/src/types/key-util-types.ts +0 -3
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;
|
|
@@ -45,7 +44,6 @@ type SignatureAlgorithmFromKeyArgs = {
|
|
|
45
44
|
};
|
|
46
45
|
type SignatureAlgorithmFromKeyTypeArgs = {
|
|
47
46
|
type: TKeyType;
|
|
48
|
-
algorithms?: string[];
|
|
49
47
|
};
|
|
50
48
|
type KeyTypeFromCryptographicSuiteArgs = {
|
|
51
49
|
crv?: string;
|
|
@@ -88,7 +86,7 @@ declare const toBase64url: (input: string) => string;
|
|
|
88
86
|
*/
|
|
89
87
|
declare const calculateJwkThumbprint: (args: {
|
|
90
88
|
jwk: JWK;
|
|
91
|
-
digestAlgorithm?:
|
|
89
|
+
digestAlgorithm?: "sha256" | "sha512";
|
|
92
90
|
}) => string;
|
|
93
91
|
declare const toJwkFromKey: (key: IKey | MinimalImportableKey | ManagedKeyInfo, opts?: {
|
|
94
92
|
use?: JwkKeyUse;
|
|
@@ -139,7 +137,6 @@ declare const isRawCompressedPublicKey: (key: Uint8Array) => boolean;
|
|
|
139
137
|
declare const toRawCompressedHexPublicKey: (rawPublicKey: Uint8Array, keyType: TKeyType) => string;
|
|
140
138
|
declare const hexStringFromUint8Array: (value: Uint8Array) => string;
|
|
141
139
|
declare const signatureAlgorithmFromKey: (args: SignatureAlgorithmFromKeyArgs) => Promise<JoseSignatureAlgorithm>;
|
|
142
|
-
declare function signatureAlgorithmToJoseAlgorithm(alg: string): JoseSignatureAlgorithm;
|
|
143
140
|
declare const signatureAlgorithmFromKeyType: (args: SignatureAlgorithmFromKeyTypeArgs) => JoseSignatureAlgorithm;
|
|
144
141
|
declare const keyTypeFromCryptographicSuite: (args: KeyTypeFromCryptographicSuiteArgs) => TKeyType;
|
|
145
142
|
declare function removeNulls<T>(obj: T | any): any;
|
|
@@ -172,12 +169,6 @@ declare function toPkcs1(derBytes: Uint8Array): Uint8Array;
|
|
|
172
169
|
* @returns DER‐encoded PKCS#1 RSAPublicKey in hex
|
|
173
170
|
*/
|
|
174
171
|
declare function toPkcs1FromHex(publicKeyHex: string): any;
|
|
175
|
-
declare function joseAlgorithmToDigest(alg: string): DigestAlgorithm;
|
|
176
|
-
declare function isHash(input: string): boolean;
|
|
177
|
-
declare function isHashString(input: Uint8Array): boolean;
|
|
178
|
-
type HashAlgorithm = 'SHA-256' | 'sha256' | 'SHA-384' | 'sha384' | 'SHA-512' | 'sha512';
|
|
179
|
-
declare function normalizeHashAlgorithm(alg?: HashAlgorithm): 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
180
|
-
declare function isSameHash(left: HashAlgorithm, right: HashAlgorithm): boolean;
|
|
181
172
|
|
|
182
173
|
declare function coseKeyToJwk(coseKey: ICoseKeyJson): JWK;
|
|
183
174
|
declare function jwkToCoseKey(jwk: JWK): ICoseKeyJson;
|
|
@@ -230,12 +221,13 @@ declare function jwkJcsDecode(bytes: ByteView<JsonWebKey$1>): JsonWebKey$1;
|
|
|
230
221
|
declare function jcsCanonicalize(object: any): string;
|
|
231
222
|
|
|
232
223
|
declare const SupportedEncodings: any;
|
|
224
|
+
type HashAlgorithm = 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
233
225
|
type TDigestMethod = (input: string, encoding?: typeof SupportedEncodings) => string;
|
|
234
|
-
declare const digestMethodParams: (hashAlgorithm:
|
|
235
|
-
hashAlgorithm:
|
|
226
|
+
declare const digestMethodParams: (hashAlgorithm: HashAlgorithm) => {
|
|
227
|
+
hashAlgorithm: HashAlgorithm;
|
|
236
228
|
digestMethod: TDigestMethod;
|
|
237
229
|
hash: (data: Uint8Array) => Uint8Array;
|
|
238
230
|
};
|
|
239
231
|
declare const shaHasher: HasherSync;
|
|
240
232
|
|
|
241
|
-
export {
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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 =
|
|
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(
|
|
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;
|
|
@@ -868,45 +867,11 @@ var hexStringFromUint8Array = /* @__PURE__ */ __name((value) => toString2(value,
|
|
|
868
867
|
var signatureAlgorithmFromKey = /* @__PURE__ */ __name(async (args) => {
|
|
869
868
|
const { key } = args;
|
|
870
869
|
return signatureAlgorithmFromKeyType({
|
|
871
|
-
type: key.type
|
|
872
|
-
algorithms: key.meta?.algorithms
|
|
870
|
+
type: key.type
|
|
873
871
|
});
|
|
874
872
|
}, "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");
|
|
905
873
|
var signatureAlgorithmFromKeyType = /* @__PURE__ */ __name((args) => {
|
|
906
|
-
const { type
|
|
907
|
-
if (algorithms && algorithms.length > 0) {
|
|
908
|
-
return signatureAlgorithmToJoseAlgorithm(algorithms[0]);
|
|
909
|
-
}
|
|
874
|
+
const { type } = args;
|
|
910
875
|
switch (type) {
|
|
911
876
|
case "Ed25519":
|
|
912
877
|
case "X25519":
|
|
@@ -920,7 +885,7 @@ var signatureAlgorithmFromKeyType = /* @__PURE__ */ __name((args) => {
|
|
|
920
885
|
case "Secp256k1":
|
|
921
886
|
return JoseSignatureAlgorithm.ES256K;
|
|
922
887
|
case "RSA":
|
|
923
|
-
return JoseSignatureAlgorithm.
|
|
888
|
+
return JoseSignatureAlgorithm.PS256;
|
|
924
889
|
default:
|
|
925
890
|
throw new Error(`Key type '${type}' not supported`);
|
|
926
891
|
}
|
|
@@ -1171,75 +1136,6 @@ function toPkcs1FromHex(publicKeyHex) {
|
|
|
1171
1136
|
return toString2(pkcs1, "hex");
|
|
1172
1137
|
}
|
|
1173
1138
|
__name(toPkcs1FromHex, "toPkcs1FromHex");
|
|
1174
|
-
function joseAlgorithmToDigest(alg) {
|
|
1175
|
-
const normalized = alg.toUpperCase().replace(/-/g, "");
|
|
1176
|
-
switch (normalized) {
|
|
1177
|
-
case "RS256":
|
|
1178
|
-
case "ES256":
|
|
1179
|
-
case "ES256K":
|
|
1180
|
-
case "PS256":
|
|
1181
|
-
case "HS256":
|
|
1182
|
-
return "SHA-256";
|
|
1183
|
-
case "RS384":
|
|
1184
|
-
case "ES384":
|
|
1185
|
-
case "PS384":
|
|
1186
|
-
case "HS384":
|
|
1187
|
-
return "SHA-384";
|
|
1188
|
-
case "RS512":
|
|
1189
|
-
case "ES512":
|
|
1190
|
-
case "PS512":
|
|
1191
|
-
case "HS512":
|
|
1192
|
-
return "SHA-512";
|
|
1193
|
-
case "EDDSA":
|
|
1194
|
-
case "ED25519":
|
|
1195
|
-
return "SHA-512";
|
|
1196
|
-
default:
|
|
1197
|
-
throw new Error(`Unsupported JOSE algorithm: ${alg}. Cannot determine digest algorithm.`);
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
__name(joseAlgorithmToDigest, "joseAlgorithmToDigest");
|
|
1201
|
-
function isHash(input) {
|
|
1202
|
-
const length = input.length;
|
|
1203
|
-
if (length !== 64 && length !== 96 && length !== 128) {
|
|
1204
|
-
return false;
|
|
1205
|
-
}
|
|
1206
|
-
return input.match(/^([0-9A-Fa-f])+$/g) !== null;
|
|
1207
|
-
}
|
|
1208
|
-
__name(isHash, "isHash");
|
|
1209
|
-
function isHashString(input) {
|
|
1210
|
-
const length = input.length;
|
|
1211
|
-
if (length !== 32 && length !== 48 && length !== 64) {
|
|
1212
|
-
return false;
|
|
1213
|
-
}
|
|
1214
|
-
let printableCount = 0;
|
|
1215
|
-
for (let i = 0; i < length; i++) {
|
|
1216
|
-
const byte = input[i];
|
|
1217
|
-
if (byte === void 0) {
|
|
1218
|
-
return false;
|
|
1219
|
-
}
|
|
1220
|
-
if (byte >= 32 && byte <= 126) {
|
|
1221
|
-
printableCount++;
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
const printableRatio = printableCount / length;
|
|
1225
|
-
return printableRatio < 0.9;
|
|
1226
|
-
}
|
|
1227
|
-
__name(isHashString, "isHashString");
|
|
1228
|
-
function normalizeHashAlgorithm(alg) {
|
|
1229
|
-
if (!alg) {
|
|
1230
|
-
return "SHA-256";
|
|
1231
|
-
}
|
|
1232
|
-
const upper = alg.toUpperCase();
|
|
1233
|
-
if (upper.includes("256")) return "SHA-256";
|
|
1234
|
-
if (upper.includes("384")) return "SHA-384";
|
|
1235
|
-
if (upper.includes("512")) return "SHA-512";
|
|
1236
|
-
throw new Error(`Invalid hash algorithm: ${alg}`);
|
|
1237
|
-
}
|
|
1238
|
-
__name(normalizeHashAlgorithm, "normalizeHashAlgorithm");
|
|
1239
|
-
function isSameHash(left, right) {
|
|
1240
|
-
return normalizeHashAlgorithm(left) === normalizeHashAlgorithm(right);
|
|
1241
|
-
}
|
|
1242
|
-
__name(isSameHash, "isSameHash");
|
|
1243
1139
|
|
|
1244
1140
|
// src/conversion.ts
|
|
1245
1141
|
import { ICoseCurve, ICoseKeyOperation, ICoseKeyType, ICoseSignatureAlgorithm, JoseCurve as JoseCurve2, JoseKeyOperation, JoseSignatureAlgorithm as JoseSignatureAlgorithm2, JwkKeyType as JwkKeyType2 } from "@sphereon/ssi-types";
|
|
@@ -1510,12 +1406,8 @@ export {
|
|
|
1510
1406
|
hexStringFromUint8Array,
|
|
1511
1407
|
importProvidedOrGeneratedKey,
|
|
1512
1408
|
isAsn1Der,
|
|
1513
|
-
isHash,
|
|
1514
|
-
isHashString,
|
|
1515
1409
|
isRawCompressedPublicKey,
|
|
1516
|
-
isSameHash,
|
|
1517
1410
|
jcsCanonicalize,
|
|
1518
|
-
joseAlgorithmToDigest,
|
|
1519
1411
|
joseToCoseCurve,
|
|
1520
1412
|
joseToCoseKeyOperation,
|
|
1521
1413
|
joseToCoseKty,
|
|
@@ -1528,7 +1420,6 @@ export {
|
|
|
1528
1420
|
keyTypeFromCryptographicSuite,
|
|
1529
1421
|
logger,
|
|
1530
1422
|
minimalJwk,
|
|
1531
|
-
normalizeHashAlgorithm,
|
|
1532
1423
|
padLeft,
|
|
1533
1424
|
removeNulls,
|
|
1534
1425
|
rsaJwkToRawHexKey,
|
|
@@ -1536,7 +1427,6 @@ export {
|
|
|
1536
1427
|
shaHasher,
|
|
1537
1428
|
signatureAlgorithmFromKey,
|
|
1538
1429
|
signatureAlgorithmFromKeyType,
|
|
1539
|
-
signatureAlgorithmToJoseAlgorithm,
|
|
1540
1430
|
toBase64url,
|
|
1541
1431
|
toJwk,
|
|
1542
1432
|
toJwkFromKey,
|