@sphereon/ssi-sdk-ext.key-utils 0.36.1-feature.integration.fides.88 → 0.36.1-next.102
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 +10 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/functions.ts +25 -7
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk-ext.key-utils",
|
|
3
3
|
"description": "Sphereon SSI-SDK plugin for key creation.",
|
|
4
|
-
"version": "0.36.1-
|
|
4
|
+
"version": "0.36.1-next.102+47fd4911",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@ethersproject/random": "^5.7.0",
|
|
26
26
|
"@noble/curves": "1.7.0",
|
|
27
27
|
"@noble/hashes": "1.6.1",
|
|
28
|
-
"@sphereon/ssi-sdk-ext.x509-utils": "0.36.1-
|
|
29
|
-
"@sphereon/ssi-types": "0.36.1-
|
|
28
|
+
"@sphereon/ssi-sdk-ext.x509-utils": "0.36.1-next.102+47fd4911",
|
|
29
|
+
"@sphereon/ssi-types": "0.36.1-next.102+47fd4911",
|
|
30
30
|
"@stablelib/ed25519": "^1.0.3",
|
|
31
31
|
"@trust/keyto": "^1.0.1",
|
|
32
32
|
"@veramo/core": "4.2.0",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"DID",
|
|
64
64
|
"Veramo"
|
|
65
65
|
],
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "47fd49119d1d2e1b424a76739ac71a864f150ec4"
|
|
67
67
|
}
|
package/src/functions.ts
CHANGED
|
@@ -1160,7 +1160,10 @@ export function toPkcs1FromHex(publicKeyHex: string) {
|
|
|
1160
1160
|
}
|
|
1161
1161
|
|
|
1162
1162
|
export function joseAlgorithmToDigest(alg: string): DigestAlgorithm {
|
|
1163
|
-
|
|
1163
|
+
// Normalize the algorithm string by converting to uppercase and removing hyphens
|
|
1164
|
+
const normalized = alg.toUpperCase().replace(/-/g, '')
|
|
1165
|
+
|
|
1166
|
+
switch (normalized) {
|
|
1164
1167
|
case 'RS256':
|
|
1165
1168
|
case 'ES256':
|
|
1166
1169
|
case 'ES256K':
|
|
@@ -1177,10 +1180,11 @@ export function joseAlgorithmToDigest(alg: string): DigestAlgorithm {
|
|
|
1177
1180
|
case 'PS512':
|
|
1178
1181
|
case 'HS512':
|
|
1179
1182
|
return 'SHA-512'
|
|
1180
|
-
case '
|
|
1183
|
+
case 'EDDSA':
|
|
1184
|
+
case 'ED25519':
|
|
1181
1185
|
return 'SHA-512'
|
|
1182
1186
|
default:
|
|
1183
|
-
|
|
1187
|
+
throw new Error(`Unsupported JOSE algorithm: ${alg}. Cannot determine digest algorithm.`)
|
|
1184
1188
|
}
|
|
1185
1189
|
}
|
|
1186
1190
|
|
|
@@ -1199,17 +1203,31 @@ export function isHashString(input: Uint8Array): boolean {
|
|
|
1199
1203
|
if (length !== 32 && length !== 48 && length !== 64) {
|
|
1200
1204
|
return false
|
|
1201
1205
|
}
|
|
1206
|
+
|
|
1207
|
+
// A hash digest is raw binary data (any byte values 0x00-0xFF are valid).
|
|
1208
|
+
// We should NOT check if bytes are ASCII hex characters, as that would only detect
|
|
1209
|
+
// hex-encoded strings, not actual binary hash digests.
|
|
1210
|
+
// Instead, we use a heuristic: if the data looks like it has high entropy
|
|
1211
|
+
// and is the right length, we assume it's already a hash.
|
|
1212
|
+
|
|
1213
|
+
// Simple heuristic: Check if data is all printable ASCII (which would indicate it's NOT a hash)
|
|
1214
|
+
// Printable ASCII is roughly 0x20-0x7E
|
|
1215
|
+
let printableCount = 0
|
|
1202
1216
|
for (let i = 0; i < length; i++) {
|
|
1203
1217
|
const byte = input[i]
|
|
1204
1218
|
if (byte === undefined) {
|
|
1205
1219
|
return false
|
|
1206
1220
|
}
|
|
1207
|
-
//
|
|
1208
|
-
if (
|
|
1209
|
-
|
|
1221
|
+
// Count printable ASCII characters
|
|
1222
|
+
if (byte >= 0x20 && byte <= 0x7e) {
|
|
1223
|
+
printableCount++
|
|
1210
1224
|
}
|
|
1211
1225
|
}
|
|
1212
|
-
|
|
1226
|
+
|
|
1227
|
+
// If more than 90% of bytes are printable ASCII, it's likely NOT a raw binary hash
|
|
1228
|
+
// Raw binary hashes should have a more uniform distribution across all byte values
|
|
1229
|
+
const printableRatio = printableCount / length
|
|
1230
|
+
return printableRatio < 0.9
|
|
1213
1231
|
}
|
|
1214
1232
|
|
|
1215
1233
|
export type HashAlgorithm = 'SHA-256' | 'sha256' | 'SHA-384' | 'sha384' | 'SHA-512' | 'sha512'
|