@sphereon/ssi-sdk.sd-jwt 0.32.1-feature.IATAB2B.52.190 → 0.32.1-feature.MWALL.715.121
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/action-handler.d.ts.map +1 -1
- package/dist/action-handler.js +34 -4
- package/dist/action-handler.js.map +1 -1
- package/dist/defaultCallbacks.d.ts +2 -2
- package/dist/defaultCallbacks.d.ts.map +1 -1
- package/dist/defaultCallbacks.js.map +1 -1
- package/dist/types.d.ts +5 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +15 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +29 -4
- package/dist/utils.js.map +1 -1
- package/package.json +14 -14
- package/src/__tests__/resources/BoardingPassCredential-vct.json +264 -0
- package/src/__tests__/resources/LoyaltyProgram Account VC Schema V0.1 sd-jwt-schema.json +97 -0
- package/src/__tests__/resources/LoyaltyProgramAccountCredential-vct.json +152 -0
- package/src/__tests__/resources/boarding Pass VC Schema V1.0 sd-jwt.json +156 -0
- package/src/__tests__/resources/boardingpass-logo.png +0 -0
- package/src/__tests__/resources/boardingpass.svg +1 -0
- package/src/__tests__/resources/e-passport.svg +1 -0
- package/src/__tests__/resources/ePassport VC Schema V1.0.sd-jwt.json +303 -0
- package/src/__tests__/resources/ePassportCredential-vct.json +226 -0
- package/src/__tests__/resources/epassport-logo.png +0 -0
- package/src/__tests__/resources/loyaltyprogramaccount-icon.png +0 -0
- package/src/__tests__/resources/loyaltyprogramaccount.png +0 -0
- package/src/__tests__/resources/loyaltyprogramaccount.svg +1 -0
- package/src/__tests__/resources/travel-agency VC Employee v0.1 sd-jwt-schema.json +115 -0
- package/src/__tests__/resources/travel-agency-EmployeeAgencyCredential-vct.json +181 -0
- package/src/__tests__/resources/travel-agency-vc-employee-logo.png +0 -0
- package/src/__tests__/resources/travel-agency-vc-employee.svg +1 -0
- package/src/__tests__/sd-jwt-integrity.test.ts +100 -0
- package/src/__tests__/sd-jwt.test.ts +2 -3
- package/src/action-handler.ts +48 -14
- package/src/defaultCallbacks.ts +2 -3
- package/src/types.ts +5 -4
- package/src/utils.ts +48 -4
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SdJwtTypeMetadata } from '@sphereon/ssi-types'
|
|
2
2
|
import * as u8a from 'uint8arrays'
|
|
3
|
+
import { HasherSync } from '@sd-jwt/types/src/type'
|
|
4
|
+
import { Hasher } from '@sd-jwt/types'
|
|
3
5
|
|
|
4
6
|
// Helper function to fetch API with error handling
|
|
5
7
|
export async function fetchUrlWithErrorHandling(url: string): Promise<Response> {
|
|
@@ -10,9 +12,51 @@ export async function fetchUrlWithErrorHandling(url: string): Promise<Response>
|
|
|
10
12
|
return response
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
export type IntegrityAlg = 'sha256' | 'sha384' | 'sha512'
|
|
16
|
+
|
|
17
|
+
function extractHashAlgFromIntegrity(integrityValue?: string): IntegrityAlg | undefined {
|
|
18
|
+
const val = integrityValue?.toLowerCase().trim().split('-')[0]
|
|
19
|
+
if (val === 'sha256' || val === 'sha384' || val === 'sha512') {
|
|
20
|
+
return val as IntegrityAlg
|
|
21
|
+
}
|
|
22
|
+
return undefined
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function extractHashFromIntegrity(integrityValue?: string): string | undefined {
|
|
26
|
+
return integrityValue?.toLowerCase().trim().split('-')[1]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function validateIntegrity({
|
|
30
|
+
input,
|
|
31
|
+
integrityValue,
|
|
32
|
+
hasher,
|
|
33
|
+
}: {
|
|
34
|
+
input: any
|
|
35
|
+
integrityValue?: string
|
|
36
|
+
hasher: HasherSync | Hasher
|
|
37
|
+
}): Promise<boolean> {
|
|
38
|
+
if (!integrityValue) {
|
|
39
|
+
return true
|
|
40
|
+
}
|
|
41
|
+
const alg = extractHashAlgFromIntegrity(integrityValue)
|
|
42
|
+
if (!alg) {
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
45
|
+
const calculatedHash = await createIntegrity({ hasher, input, alg })
|
|
46
|
+
return calculatedHash == integrityValue
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function createIntegrity({
|
|
50
|
+
input,
|
|
51
|
+
hasher,
|
|
52
|
+
alg = 'sha256',
|
|
53
|
+
}: {
|
|
54
|
+
input: any
|
|
55
|
+
hasher: HasherSync | Hasher
|
|
56
|
+
alg?: IntegrityAlg
|
|
57
|
+
}): Promise<string> {
|
|
58
|
+
const calculatedHash = await hasher(typeof input === 'string' ? input : JSON.stringify(input), alg)
|
|
59
|
+
return `${alg}-${u8a.toString(calculatedHash, 'base64')}`
|
|
16
60
|
}
|
|
17
61
|
|
|
18
62
|
export function assertValidTypeMetadata(metadata: SdJwtTypeMetadata, vct: string): void {
|