diff --git a/packages/ssi-types/package.json b/packages/ssi-types/package.json index 53e8a30fe..71d3473c0 100644 --- a/packages/ssi-types/package.json +++ b/packages/ssi-types/package.json @@ -9,7 +9,7 @@ "build:clean": "tsc --build --clean && tsc --build" }, "dependencies": { - "@sd-jwt/decode": "^0.2.0", + "@sd-jwt/decode": "0.3.2-next.108", "jwt-decode": "^3.1.2" }, "devDependencies": { diff --git a/packages/ssi-types/src/types/sd-jwt-vc.ts b/packages/ssi-types/src/types/sd-jwt-vc.ts index 62aaa592b..1b9b89194 100644 --- a/packages/ssi-types/src/types/sd-jwt-vc.ts +++ b/packages/ssi-types/src/types/sd-jwt-vc.ts @@ -1,5 +1,5 @@ import { OriginalType, WrappedVerifiableCredential, WrappedVerifiablePresentation } from './vc' -import { decodeSdJwtVc as _decodeSdJwtVc } from '@sd-jwt/decode' +import { decodeSdJwtSync, decodeSdJwt, getClaims, getClaimsSync } from '@sd-jwt/decode' type JsonValue = string | number | boolean | { [x: string]: JsonValue | undefined } | Array @@ -189,7 +189,12 @@ export type AsyncHasher = (data: string, alg: string) => Promise * this method hides the actual implementation of SD-JWT (which is currently based on @sd-jwt/core) */ export function decodeSdJwtVc(compactSdJwtVc: CompactSdJwtVc, hasher: Hasher): SdJwtDecodedVerifiableCredential { - const { signedPayload, decodedPayload, disclosures } = _decodeSdJwtVc(compactSdJwtVc, hasher) + const { jwt, disclosures } = decodeSdJwtSync(compactSdJwtVc, hasher) + + const signedPayload = jwt.payload as SdJwtSignedVerifiableCredentialPayload + const decodedPayload = getClaimsSync(signedPayload, disclosures, hasher) + + const { _sd_alg } = signedPayload return { compactSdJwtVc, @@ -198,11 +203,11 @@ export function decodeSdJwtVc(compactSdJwtVc: CompactSdJwtVc, hasher: Hasher): S const decoded = d.key ? [d.salt, d.key, d.value] : [d.salt, d.value] return { decoded: decoded as SdJwtDecodedDisclosure, - digest: d.digest, - encoded: d.encoded, + digest: d.digestSync({ hasher, alg: _sd_alg ?? 'sha-256' }), + encoded: d.encode(), } satisfies SdJwtDisclosure }), - signedPayload: signedPayload as SdJwtDecodedVerifiableCredentialPayload, + signedPayload: signedPayload as SdJwtSignedVerifiableCredentialPayload, } } @@ -214,19 +219,26 @@ export function decodeSdJwtVc(compactSdJwtVc: CompactSdJwtVc, hasher: Hasher): S * this method hides the actual implementation of SD-JWT (which is currently based on @sd-jwt/core) */ export async function decodeSdJwtVcAsync(compactSdJwtVc: CompactSdJwtVc, hasher: AsyncHasher): Promise { - const { signedPayload, decodedPayload, disclosures } = await _decodeSdJwtVc(compactSdJwtVc, hasher) + const { jwt, disclosures } = await decodeSdJwt(compactSdJwtVc, hasher) + + const signedPayload = jwt.payload as SdJwtSignedVerifiableCredentialPayload + const decodedPayload = await getClaims(signedPayload, disclosures, hasher) + + const { _sd_alg } = signedPayload return { compactSdJwtVc, decodedPayload: decodedPayload as SdJwtDecodedVerifiableCredentialPayload, - disclosures: disclosures.map((d) => { - const decoded = d.key ? [d.salt, d.key, d.value] : [d.salt, d.value] - return { - decoded: decoded as SdJwtDecodedDisclosure, - digest: d.digest, - encoded: d.encoded, - } satisfies SdJwtDisclosure - }), - signedPayload: signedPayload as SdJwtDecodedVerifiableCredentialPayload, + disclosures: await Promise.all( + disclosures.map(async (d) => { + const decoded = d.key ? [d.salt, d.key, d.value] : [d.salt, d.value] + return { + decoded: decoded as SdJwtDecodedDisclosure, + digest: await d.digest({ hasher, alg: _sd_alg ?? 'sha-256' }), + encoded: d.encode(), + } satisfies SdJwtDisclosure + }) + ), + signedPayload: signedPayload as SdJwtSignedVerifiableCredentialPayload, } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5c3e9aef5..f8145475c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1640,8 +1640,8 @@ importers: packages/ssi-types: dependencies: '@sd-jwt/decode': - specifier: ^0.2.0 - version: 0.2.0 + specifier: 0.3.2-next.108 + version: 0.3.2-next.108 jwt-decode: specifier: ^3.1.2 version: 3.1.2 @@ -6970,37 +6970,32 @@ packages: '@noble/hashes': 1.2.0 '@scure/base': 1.1.5 - /@sd-jwt/decode@0.2.0: - resolution: {integrity: sha512-nmiZN3SQ4ApapEu+rS1h/YAkDIq3exgN7swSCsEkrxSEwnBSbXtISIY/sv+EmwnehF1rcKbivHfHNxOWYtlxvg==} - dependencies: - '@sd-jwt/types': 0.2.0 - '@sd-jwt/utils': 0.2.0 - dev: false - /@sd-jwt/decode@0.3.0: resolution: {integrity: sha512-jCN1g3VzopiUxUtBZWq0Ojfzbg+wYkE1/gV86Xq7/gV8aNacCJo7Su5a3pYtoYg/rnH7ou1kwpD6vteQFkvXMQ==} dependencies: '@sd-jwt/types': 0.3.0 '@sd-jwt/utils': 0.3.0 + /@sd-jwt/decode@0.3.2-next.108: + resolution: {integrity: sha512-CRHbJrGYC+aHF3rdQ0loUvnavD5jU8U7AEoCVg7tAxf013+UQr/6kgllNODtt82AvsV1uMo1tUp+4svrE2Wtvg==} + engines: {node: '>=16'} + dependencies: + '@sd-jwt/types': 0.3.2-next.108 + '@sd-jwt/utils': 0.3.2-next.108 + dev: false + /@sd-jwt/present@0.3.0: resolution: {integrity: sha512-dICPhH5hqOLXmuJMdTaA47ZMpCDkTzbWUQXsIgw0vma7Aj9Bc6ySNevPwlsUx4K8XBjPgYWwBM9tKdrs3tsCvQ==} dependencies: '@sd-jwt/types': 0.3.0 '@sd-jwt/utils': 0.3.0 - /@sd-jwt/types@0.2.0: - resolution: {integrity: sha512-16WFRcL/maG0/JxN9UCSx07/vJ2SDbGscv9gDLmFLgJzhJcGPer41XfI6aDfVARYP430wHFixChfY/n7qC1L/Q==} - dev: false - /@sd-jwt/types@0.3.0: resolution: {integrity: sha512-JbpZICZ+nWPiKPKw+Veg5tf0Oftit4EzxhLJyvcd0u4R6IulNZvi6LCoUL7b2IT1H86eYPd/qB1KvSh43ByZOA==} - /@sd-jwt/utils@0.2.0: - resolution: {integrity: sha512-oHCfRYVHCb5RNwdq3eHAt7P9d7TsEaSM1TTux+xl1I9PeQGLtZETnto9Gchtzn8FlTrMdVsLlcuAcK6Viwj1Qw==} - dependencies: - '@sd-jwt/types': 0.2.0 - buffer: 6.0.3 + /@sd-jwt/types@0.3.2-next.108: + resolution: {integrity: sha512-xXPdajKdqwilPmi150+Thwwz8FJqpSWyw2qQU17rhfb8qHAYl30Qrf0pnk86SxvAOEELXGuBDTwl/44SwKecfg==} + engines: {node: '>=16'} dev: false /@sd-jwt/utils@0.3.0: @@ -7009,6 +7004,14 @@ packages: '@sd-jwt/types': 0.3.0 buffer: 6.0.3 + /@sd-jwt/utils@0.3.2-next.108: + resolution: {integrity: sha512-eMq1MYSjXzPOPlMt3QCqq+8v9WzNu2yrJMH7ej6zLu9ELLM3Z37ZVEFpEW1bcWlLun8zpV91af1fPx1Hz9rhYg==} + engines: {node: '>=16'} + dependencies: + '@sd-jwt/types': 0.3.2-next.108 + js-base64: 3.7.7 + dev: false + /@segment/loosely-validate-event@2.0.0: resolution: {integrity: sha512-ZMCSfztDBqwotkl848ODgVcAmN4OItEWDCkshcKz0/W6gGSQayuuCtWV/MlodFivAZD793d6UgANd6wCXUfrIw==} dependencies: @@ -15705,6 +15708,10 @@ packages: resolution: {integrity: sha512-oW3PCnvyrcm1HMvGTzqjxxfnEs9EoFOFWi2HsEGhlFVOXxTE3K9GKWVMFoFw06yPUqwpvEWic1BmtUZBI/tIjw==} dev: true + /js-base64@3.7.7: + resolution: {integrity: sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw==} + dev: false + /js-sha256@0.9.0: resolution: {integrity: sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==} dev: true