@sphereon/ssi-sdk-ext.key-utils 0.36.1-feature.SSISDK.70.integrate.digidentity.10 → 0.36.1-feature.SSISDK.70.integrate.digidentity.56
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 +48 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +48 -9
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/functions.ts +66 -10
- package/src/types/key-util-types.ts +1 -0
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.
|
|
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
|
-
|
|
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 "
|
|
1193
|
+
case "EDDSA":
|
|
1194
|
+
case "ED25519":
|
|
1159
1195
|
return "SHA-512";
|
|
1160
1196
|
default:
|
|
1161
|
-
|
|
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 (
|
|
1184
|
-
|
|
1220
|
+
if (byte >= 32 && byte <= 126) {
|
|
1221
|
+
printableCount++;
|
|
1185
1222
|
}
|
|
1186
1223
|
}
|
|
1187
|
-
|
|
1224
|
+
const printableRatio = printableCount / length;
|
|
1225
|
+
return printableRatio < 0.9;
|
|
1188
1226
|
}
|
|
1189
1227
|
__name(isHashString, "isHashString");
|
|
1190
1228
|
function normalizeHashAlgorithm(alg) {
|
|
@@ -1498,6 +1536,7 @@ export {
|
|
|
1498
1536
|
shaHasher,
|
|
1499
1537
|
signatureAlgorithmFromKey,
|
|
1500
1538
|
signatureAlgorithmFromKeyType,
|
|
1539
|
+
signatureAlgorithmToJoseAlgorithm,
|
|
1501
1540
|
toBase64url,
|
|
1502
1541
|
toJwk,
|
|
1503
1542
|
toJwkFromKey,
|