diff --git a/package.json b/package.json index c4d33034..c12fd304 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,10 @@ "private": true, "dependencies": { "@cef-ebsi/key-did-resolver": "^1.1.0", - "@sd-jwt/core": "^0.2.1", + "@sd-jwt/core": "^0.7.2", + "@sd-jwt/crypto-browser": "^0.7.2", + "@sd-jwt/sd-jwt-vc": "^0.7.2", + "@sd-jwt/utils": "^0.7.2", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", diff --git a/src/functions/SdJwtUtils.ts b/src/functions/SdJwtUtils.ts new file mode 100644 index 00000000..cc8050f8 --- /dev/null +++ b/src/functions/SdJwtUtils.ts @@ -0,0 +1,14 @@ +import { SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc'; +import { digest } from '@sd-jwt/crypto-browser'; + +export const getSDJwtVcInstanceWithHasher = () => { + return new SDJwtVcInstance({ + hasher: digest, + hashAlg: 'SHA-256' + }); +} + +export const getClaims = async (credential: string) => { + const sdJwt = getSDJwtVcInstanceWithHasher(); + return await sdJwt.getClaims(credential); +} diff --git a/src/functions/parseSdJwtCredential.ts b/src/functions/parseSdJwtCredential.ts index c92e3977..59b951d6 100644 --- a/src/functions/parseSdJwtCredential.ts +++ b/src/functions/parseSdJwtCredential.ts @@ -1,32 +1,15 @@ -import { - HasherAlgorithm, - HasherAndAlgorithm, - SdJwt, -} from '@sd-jwt/core' +import { getClaims } from './SdJwtUtils'; export enum CredentialFormat { VC_SD_JWT = "vc+sd-jwt", JWT_VC_JSON = "jwt_vc_json" } -const encoder = new TextEncoder(); - -// Encoding the string into a Uint8Array -const hasherAndAlgorithm: HasherAndAlgorithm = { - hasher: (input: string) => { - return crypto.subtle.digest('SHA-256', encoder.encode(input)).then((v) => new Uint8Array(v)); - }, - algorithm: HasherAlgorithm.Sha256 -} - export const parseSdJwtCredential = async (credential: string | object): Promise<{ beautifiedForm: any; } | { error: string }> => { try { if (typeof credential == 'string') { // is JWT if (credential.includes('~')) { // is SD-JWT - const parsed = await SdJwt.fromCompact, any>(credential) - .withHasher(hasherAndAlgorithm) - .getPrettyClaims() - .then((payload) => payload); + const parsed = await getClaims(credential); return { beautifiedForm: parsed } diff --git a/src/lib/services/OpenID4VPRelyingParty.ts b/src/lib/services/OpenID4VPRelyingParty.ts index 3cea8da0..38d384d0 100644 --- a/src/lib/services/OpenID4VPRelyingParty.ts +++ b/src/lib/services/OpenID4VPRelyingParty.ts @@ -1,7 +1,8 @@ import { HandleAuthorizationRequestError, IOpenID4VPRelyingParty } from "../interfaces/IOpenID4VPRelyingParty"; import { StorableCredential } from "../types/StorableCredential"; import { Verify } from "../utils/Verify"; -import { HasherAlgorithm, HasherAndAlgorithm, SdJwt } from "@sd-jwt/core"; +// TODO: Fix +// import { HasherAlgorithm, HasherAndAlgorithm, SdJwt } from "@sd-jwt/core"; import { VerifiableCredentialFormat } from "../schemas/vc"; import { generateRandomIdentifier } from "../utils/generateRandomIdentifier"; import { base64url, EncryptJWT, importJWK, importX509, jwtVerify } from "jose"; @@ -195,10 +196,10 @@ export class OpenID4VPRelyingParty implements IOpenID4VPRelyingParty { return new Uint8Array(hashBuffer); } - const hasherAndAlgorithm: HasherAndAlgorithm = { - hasher: async (input: string) => hashSHA256(input), - algorithm: HasherAlgorithm.Sha256 - } + // const hasherAndAlgorithm: HasherAndAlgorithm = { + // hasher: async (input: string) => hashSHA256(input), + // algorithm: HasherAlgorithm.Sha256 + // } /** * @@ -278,10 +279,12 @@ export class OpenID4VPRelyingParty implements IOpenID4VPRelyingParty { .map((field) => field.path) .reduce((accumulator, currentValue) => [...accumulator, ...currentValue]); let presentationFrame = generatePresentationFrameForPaths(allPaths); - const sdJwt = SdJwt.fromCompact, any>( - vcEntity.credential - ).withHasher(hasherAndAlgorithm); - const presentation = await sdJwt.present(presentationFrame); + // TODO: Fix + // const sdJwt = SdJwt.fromCompact, any>( + // vcEntity.credential + // ).withHasher(hasherAndAlgorithm); + // const presentation = await sdJwt.present(presentationFrame); + const presentation = undefined; const { vpjwt } = await this.signJwtPresentationKeystoreFn(nonce, client_id, [presentation]); selectedVCs.push(presentation); generatedVPs.push(vpjwt); diff --git a/src/services/keystore.ts b/src/services/keystore.ts index 64eaf411..212a3f7e 100644 --- a/src/services/keystore.ts +++ b/src/services/keystore.ts @@ -9,7 +9,8 @@ import * as didUtil from "@cef-ebsi/key-did-resolver/dist/util.js"; import * as config from '../config'; import type { DidKeyVersion } from '../config'; import { byteArrayEquals, filterObject, jsonParseTaggedBinary, jsonStringifyTaggedBinary, toBase64Url } from "../util"; -import { SdJwt } from "@sd-jwt/core"; +// import { SdJwt } from "@sd-jwt/core"; +// TODO: Fix... const keyDidResolver = KeyDidResolver.getResolver(); @@ -1095,7 +1096,9 @@ async function createDid(publicKey: CryptoKey, didKeyVersion: DidKeyVersion): Pr } export async function signJwtPresentation([privateData, mainKey]: [PrivateData, CryptoKey], nonce: string, audience: string, verifiableCredentials: any[]): Promise<{ vpjwt: string }> { - const inputJwt = SdJwt.fromCompact(verifiableCredentials[0]); + // const inputJwt = SdJwt.fromCompact(verifiableCredentials[0]); + // TODO: Fix + const inputJwt = undefined; const { cnf } = inputJwt.payload as { cnf?: { jwk?: JWK } }; if (!cnf?.jwk) { diff --git a/yarn.lock b/yarn.lock index 76cfc2f9..f258c18b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2446,44 +2446,68 @@ resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.10.3.tgz#391d528054f758f81e53210f1a1eebcf1a8b1d20" integrity sha512-qC/xYId4NMebE6w/V33Fh9gWxLgURiNYgVNObbJl2LZv0GUUItCcCqC5axQSwRaAgaxl2mELq1rMzlswaQ0Zxg== -"@sd-jwt/core@^0.2.1": - version "0.2.1" - resolved "https://registry.npmjs.org/@sd-jwt/core/-/core-0.2.1.tgz" - integrity sha512-8auyt3mfzgAK+IP9mNc3kSONdo5x2Y8ypNj5gHKP7N81nVeyI+DHethoPQv84JVcqYYcNwHwyrc2Z5k7rg2lFQ== - dependencies: - "@sd-jwt/decode" "0.2.1" - "@sd-jwt/present" "0.2.1" - "@sd-jwt/types" "0.2.1" - "@sd-jwt/utils" "0.2.1" - -"@sd-jwt/decode@0.2.1": - version "0.2.1" - resolved "https://registry.npmjs.org/@sd-jwt/decode/-/decode-0.2.1.tgz" - integrity sha512-rs55WB3llrMObxN8jeMl06km/h0WivO9jSWNubO9JUIdlfrVhssU38xoXakvQeSDjAJkUUhfZcvmC2vNo1X6Wg== - dependencies: - "@sd-jwt/types" "0.2.1" - "@sd-jwt/utils" "0.2.1" - -"@sd-jwt/present@0.2.1": - version "0.2.1" - resolved "https://registry.npmjs.org/@sd-jwt/present/-/present-0.2.1.tgz" - integrity sha512-yWIAR2C/q1jNUwzAeUlUcf3WCTEcSSGo9pltHW5AXptELjyaWGSmC5p6o9ucDXHvBnicfPONhe5OdUCSpiCntw== - dependencies: - "@sd-jwt/types" "0.2.1" - "@sd-jwt/utils" "0.2.1" - -"@sd-jwt/types@0.2.1": - version "0.2.1" - resolved "https://registry.npmjs.org/@sd-jwt/types/-/types-0.2.1.tgz" - integrity sha512-nbNik/cq6UIMsN144FcgPZQzaqIsjEEj307j3ZSFORkQBR4Tsmcj54aswTuNh0Z0z/4aSbfw14vOKBZvRWyVLQ== - -"@sd-jwt/utils@0.2.1": - version "0.2.1" - resolved "https://registry.npmjs.org/@sd-jwt/utils/-/utils-0.2.1.tgz" - integrity sha512-9eRrge44dhE3fenawR/RZGxP5iuW9DtgdOVANu/JK5PEl80r0fDsMwm/gDjuv8OgLDCmQ6uSaVte1lYaTG71bQ== - dependencies: - "@sd-jwt/types" "0.2.1" - buffer "*" +"@sd-jwt/core@0.7.2", "@sd-jwt/core@^0.7.2": + version "0.7.2" + resolved "https://registry.yarnpkg.com/@sd-jwt/core/-/core-0.7.2.tgz#cfbcd853d507e2c31bf66ea5b2c1748291924ec3" + integrity sha512-vix1GplUFc1A9H42r/yXkg7cKYthggyqZEwlFdsBbn4xdZNE+AHVF4N7kPa1pPxipwN3UIHd4XnQ5MJV15mhsQ== + dependencies: + "@sd-jwt/decode" "0.7.2" + "@sd-jwt/present" "0.7.2" + "@sd-jwt/types" "0.7.2" + "@sd-jwt/utils" "0.7.2" + +"@sd-jwt/crypto-browser@^0.7.2": + version "0.7.2" + resolved "https://registry.yarnpkg.com/@sd-jwt/crypto-browser/-/crypto-browser-0.7.2.tgz#85dd1523757d3628d7dfebc49aab37940ed807ca" + integrity sha512-3EsFaVxgzWw/MguUKjMnW66kBv3NjErgdrf0wniyIAfKCi/njlJ+Zxlj9BW2Dmekiqdh2rH1JOPnCM3CZU9XUw== + +"@sd-jwt/decode@0.7.2": + version "0.7.2" + resolved "https://registry.yarnpkg.com/@sd-jwt/decode/-/decode-0.7.2.tgz#a0dd90d82c0b8b5e68adb22257a3db4b72de8529" + integrity sha512-dan2LSvK63SKwb62031G4r7TE4TaiI0EK1KbPXqS+LCXNkNDUHqhtYp9uOpj+grXceCsMtMa2f8VnUfsjmwHHg== + dependencies: + "@sd-jwt/types" "0.7.2" + "@sd-jwt/utils" "0.7.2" + +"@sd-jwt/jwt-status-list@0.7.2": + version "0.7.2" + resolved "https://registry.yarnpkg.com/@sd-jwt/jwt-status-list/-/jwt-status-list-0.7.2.tgz#13cd1b4abbcb08217a44efb59f0fd2a134fe398a" + integrity sha512-o/Mg/Zg21poFsPXuxtPD9sdXq2b/0L+rb9gxU2k1rp1aT+DWmqD0k8v0Ttr2tlMc8l1xXQNA8FLXbL1AdLRmbQ== + dependencies: + "@sd-jwt/types" "0.7.2" + base64url "^3.0.1" + pako "^2.1.0" + +"@sd-jwt/present@0.7.2": + version "0.7.2" + resolved "https://registry.yarnpkg.com/@sd-jwt/present/-/present-0.7.2.tgz#23e521cda6adf6ce9f73fcda64502ea7c45f61c3" + integrity sha512-mQV85u2+mLLy2VZ9Wx2zpaB6yTDnbhCfWkP7eeCrzJQHBKAAHko8GrylEFmLKewFIcajS/r4lT/zHOsCkp5pZw== + dependencies: + "@sd-jwt/decode" "0.7.2" + "@sd-jwt/types" "0.7.2" + "@sd-jwt/utils" "0.7.2" + +"@sd-jwt/sd-jwt-vc@^0.7.2": + version "0.7.2" + resolved "https://registry.yarnpkg.com/@sd-jwt/sd-jwt-vc/-/sd-jwt-vc-0.7.2.tgz#565a4fcebfe97915a995fd26b0e3cb1fdd56ff6a" + integrity sha512-rryYmnoJHRSNqHcrs0Atta+bfJzU2yT7mYumR2D4lTfxJKWZd0OHHFq57uZSEm/wXPI6uytUJXYbEboCqLUAtw== + dependencies: + "@sd-jwt/core" "0.7.2" + "@sd-jwt/jwt-status-list" "0.7.2" + "@sd-jwt/utils" "0.7.2" + +"@sd-jwt/types@0.7.2": + version "0.7.2" + resolved "https://registry.yarnpkg.com/@sd-jwt/types/-/types-0.7.2.tgz#29b5bf923eaed041b1375624afd7ce522f954f66" + integrity sha512-1NRKowiW0ZiB9SGLApLPBH4Xk8gDQJ+nA9NdZ+uy6MmJKLEwjuJxO7yTvRIv/jX/0/Ebh339S7Kq4RD2AiFuRg== + +"@sd-jwt/utils@0.7.2", "@sd-jwt/utils@^0.7.2": + version "0.7.2" + resolved "https://registry.yarnpkg.com/@sd-jwt/utils/-/utils-0.7.2.tgz#4309fa2f5ebe214947de4fb07a1e06a70c29710b" + integrity sha512-aMPY7uHRMgyI5PlDvEiIc+eBFGC1EM8OCQRiEjJ8HGN0pajWMYj0qwSw7pS90A49/DsYU1a5Zpvb7nyjgGH0Yg== + dependencies: + "@sd-jwt/types" "0.7.2" + js-base64 "^3.7.6" "@sinclair/typebox@^0.24.1": version "0.24.51" @@ -3908,10 +3932,10 @@ balanced-match@^1.0.0: resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz" integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== -base64-js@^1.3.1: - version "1.5.1" - resolved "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz" - integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== +base64url@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/base64url/-/base64url-3.0.1.tgz#6399d572e2bc3f90a9a8b22d5dbb0a32d33f788d" + integrity sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A== batch@0.6.1: version "0.6.1" @@ -4029,14 +4053,6 @@ buffer-from@^1.0.0: resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz" integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== -buffer@*: - version "6.0.3" - resolved "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz" - integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA== - dependencies: - base64-js "^1.3.1" - ieee754 "^1.2.1" - builtin-modules@^3.1.0: version "3.3.0" resolved "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz" @@ -6445,11 +6461,6 @@ identity-obj-proxy@^3.0.0: dependencies: harmony-reflect "^1.4.6" -ieee754@^1.2.1: - version "1.2.1" - resolved "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz" - integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== - ignore@^5.2.0: version "5.3.1" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.1.tgz#5073e554cd42c5b33b394375f538b8593e34d4ef" @@ -7421,6 +7432,11 @@ jose@^4.14.4: resolved "https://registry.yarnpkg.com/jose/-/jose-4.15.9.tgz#9b68eda29e9a0614c042fa29387196c7dd800100" integrity sha512-1vUQX+IdDMVPj4k8kOxgUqlcK518yluMuGZwqlr44FS1ppZB/5GWh4rZG89erpOBOJjU/OBsnCVFfapsRz6nEA== +js-base64@^3.7.6: + version "3.7.7" + resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.7.tgz#e51b84bf78fbf5702b9541e2cb7bfcb893b43e79" + integrity sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw== + js-cookie@^3.0.5: version "3.0.5" resolved "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz" @@ -8367,6 +8383,11 @@ package-json-from-dist@^1.0.0: resolved "https://registry.yarnpkg.com/package-json-from-dist/-/package-json-from-dist-1.0.0.tgz#e501cd3094b278495eb4258d4c9f6d5ac3019f00" integrity sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw== +pako@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/pako/-/pako-2.1.0.tgz#266cc37f98c7d883545d11335c00fbd4062c9a86" + integrity sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug== + param-case@^3.0.4: version "3.0.4" resolved "https://registry.npmjs.org/param-case/-/param-case-3.0.4.tgz"