Skip to content

Commit

Permalink
fix: update jarm
Browse files Browse the repository at this point in the history
  • Loading branch information
auer-martin committed Sep 25, 2024
1 parent f457d69 commit 7b54fae
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
22 changes: 11 additions & 11 deletions packages/siop-oid4vp/lib/op/OP.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EventEmitter } from 'events'

import { JarmClientMetadataParams, sendJarmAuthResponse } from '@protokoll/jarm'
import { joseExtractJWKS } from '@protokoll/core'
import { JarmClientMetadataParams, sendJarmAuthRequest } from '@protokoll/jarm'
import { JwtIssuer, uuidv4 } from '@sphereon/oid4vc-common'
import { IIssuerId } from '@sphereon/ssi-types'

Expand Down Expand Up @@ -169,7 +170,7 @@ export class OP {
throw Error('No correlation Id provided')
}

const isJarmResponseMode = (responseMode: string): responseMode is 'direct_post.jwt' | 'query.jwt' | 'fragment.jwt' => {
const isJarmResponseMode = (responseMode: string): responseMode is 'jwt' | 'direct_post.jwt' | 'query.jwt' | 'fragment.jwt' => {
return responseMode === ResponseMode.DIRECT_POST_JWT || responseMode === ResponseMode.QUERY_JWT || responseMode === ResponseMode.FRAGMENT_JWT
}

Expand Down Expand Up @@ -204,17 +205,16 @@ export class OP {
throw new Error(`Sending an authorization response with response_mode '${responseMode}' requires providing an encryptJwtCallback`)
}

if (!clientMetadata.jwks) {
throw new Error('Currently the jarm response decryption key can only be extracted from the jwks client_metadata parameter')
}

const decJwk = clientMetadata.jwks.keys.find((key) => key.use === 'enc')
if (!decJwk) {
throw new Error('No decyption key found in the jwks client_metadata parameter')
// The client metadata will be parsed in the joseExtractJWKS function
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const jwks = await joseExtractJWKS(clientMetadata as any)
const dectyptionJwk = jwks.keys.find((key) => key.use === 'enc')
if (!dectyptionJwk) {
throw new Error('No decryption could be extracted from the client metadata')
}

const { jwe } = await this.createResponseOptions.encryptJwtCallback({
jwk: decJwk,
jwk: dectyptionJwk,
plaintext: JSON.stringify(response.payload),
})

Expand All @@ -227,7 +227,7 @@ export class OP {
responseType = 'vp_token'
}

return sendJarmAuthResponse({
return sendJarmAuthRequest({
authRequestParams: {
response_uri: responseUri,
response_mode: responseMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,14 @@ export const AuthorizationResponseOptsSchemaObj = {
}
}
},
"EncryptJwtCallback": {},
"EncryptJwtCallback": {
"properties": {
"isFunction": {
"type": "boolean",
"const": true
}
}
},
"JwtIssuer": {
"anyOf": [
{
Expand Down
3 changes: 2 additions & 1 deletion packages/siop-oid4vp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
},
"dependencies": {
"@astronautlabs/jsonpath": "^1.1.2",
"@protokoll/jarm": "^0.2.7",
"@protokoll/jarm": "^0.2.10",
"@protokoll/core": "^0.2.10",
"@sphereon/did-uni-client": "^0.6.2",
"@sphereon/oid4vc-common": "workspace:*",
"@sphereon/pex": "5.0.0-unstable.2",
Expand Down
21 changes: 12 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7b54fae

Please sign in to comment.