Skip to content

Commit c9682be

Browse files
berendsliedrechtTimoGlastra
authored andcommitted
fix presentation (#8)
Signed-off-by: Berend Sliedrecht <sliedrecht@berend.io>
1 parent 6755c8e commit c9682be

10 files changed

+133
-329
lines changed

agent/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "agent",
33
"dependencies": {
4-
"@credo-ts/askar": "^0.5.9",
5-
"@credo-ts/core": "^0.5.9",
6-
"@credo-ts/node": "^0.5.9",
7-
"@credo-ts/openid4vc": "^0.5.9",
4+
"@credo-ts/askar": "0.5.10-alpha-20240801095850",
5+
"@credo-ts/core": "0.5.10-alpha-20240801095850",
6+
"@credo-ts/node": "0.5.10-alpha-20240801095850",
7+
"@credo-ts/openid4vc": "0.5.10-alpha-20240801095850",
88
"@hyperledger/aries-askar-nodejs": "^0.2.3",
99
"cors": "^2.8.5",
1010
"dotenv": "^16.4.5",

agent/src/endpoints.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,14 @@ apiRouter.post('/offers/receive', async (request: Request, response: Response) =
9999
},
100100
})
101101

102+
for (const credential of credentials) {
103+
if ('compact' in credential.credential) {
104+
await agent.sdJwtVc.store(credential.credential.compact as string)
105+
}
106+
}
107+
102108
return response.json({
103-
credentials: credentials.map((credential) => JSON.stringify(credential.credential.payload)),
109+
credentials: credentials.map((credential) => credential.credential.payload),
104110
})
105111
})
106112

@@ -227,7 +233,7 @@ apiRouter.post('/requests/receive', async (request: Request, response: Response)
227233
return response.status(serverResponse.status).json(submittedResponse)
228234
})
229235

230-
apiRouter.use((error: Error, request: Request, response: Response, next: NextFunction) => {
236+
apiRouter.use((error: Error, _request: Request, response: Response, _next: NextFunction) => {
231237
console.error('Unhandled error', error)
232238
return response.status(500).json({
233239
error: error.message,

agent/src/keyMethods/setup.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export async function setupX509Certificate() {
3030
}
3131
}
3232

33+
console.log('======= X.509 Certificate ===========')
34+
console.log(x509Certificate)
35+
3336
const x509 = agent.dependencyManager.resolve(X509Api)
3437
await x509.addTrustedCertificate(x509Certificate)
3538
}

app/components/ReceiveTab.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,28 @@ import { Button } from '@/components/ui/button'
33
import { Card } from '@/components/ui/card'
44
import { Label } from '@/components/ui/label'
55
import { type FormEvent, useState } from 'react'
6-
import { receiveOffer } from '../lib/api'
6+
import { receiveOffer, receiveRequest } from '../lib/api'
77

88
export function ReceiveTab() {
9-
const [receiveCredentialOfferUri, setReceiveCredentialOfferUri] = useState<string>()
9+
const [receiveCredentialOfferOrPresentationUri, setReceiveCredentialOfferUri] = useState<string>()
1010
const [receivedCredentials, setReceivedCredentials] = useState()
11+
const [receivedPresentation, setReceivedPresentation] = useState()
1112

1213
async function onSubmitReceiveOffer(e: FormEvent) {
1314
e.preventDefault()
14-
if (!receiveCredentialOfferUri) return
15-
16-
setReceivedCredentials(await receiveOffer(receiveCredentialOfferUri))
15+
if (!receiveCredentialOfferOrPresentationUri) return
16+
if (receiveCredentialOfferOrPresentationUri.startsWith('openid-credential-offer://')) {
17+
setReceivedCredentials(await receiveOffer(receiveCredentialOfferOrPresentationUri))
18+
} else {
19+
setReceivedPresentation(await receiveRequest(receiveCredentialOfferOrPresentationUri))
20+
}
1721
}
1822

1923
return (
2024
<Card className="p-6">
2125
<form className="space-y-4" onSubmit={onSubmitReceiveOffer}>
2226
<div className="space-y-2">
23-
<Label htmlFor="credential-offer-uri">Credential Offer URI</Label>
27+
<Label htmlFor="credential-offer-uri">Credential Offer or SIOP URI</Label>
2428
<textarea
2529
className="w-full h-20 p-2 rounded-md bg-white border border-gray-300"
2630
id="credential-offer-uri"
@@ -31,6 +35,8 @@ export function ReceiveTab() {
3135
<div className="flex justify-center items-center bg-gray-200 min-h-64 w-full rounded-md">
3236
{receivedCredentials ? (
3337
<HighLight code={JSON.stringify(receivedCredentials, null, 2)} language="json" />
38+
) : receivedPresentation ? (
39+
<HighLight code={JSON.stringify(receivedPresentation, null, 2)} language="json" />
3440
) : (
3541
<p className="text-gray-500">JSON content of the credential will be displayed here</p>
3642
)}

app/components/VerifyTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function VerifyTab() {
6161
limit_disclosure: 'preferred',
6262
fields: [
6363
{
64-
path: ['$.given_name', '$.family_name', '$.address'],
64+
path: ['$.given_name'],
6565
},
6666
],
6767
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"pnpm": {
1111
"patchedDependencies": {
1212
"@sphereon/did-auth-siop@0.15.1-next.4": "patches/@sphereon__did-auth-siop@0.15.1-next.4.patch",
13-
"@credo-ts/openid4vc@0.5.9": "patches/@credo-ts__openid4vc@0.5.9.patch"
13+
"@credo-ts/openid4vc@0.5.10-alpha-20240801095850": "patches/@credo-ts__openid4vc@0.5.10-alpha-20240801095850.patch"
1414
}
1515
}
1616
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
diff --git a/build/shared/utils.js b/build/shared/utils.js
2+
index 36037ab98cf59f64b56d107aef9b2eb02b491c60..7eccc2ab99d396366299138df8d99376ca35696c 100644
3+
--- a/build/shared/utils.js
4+
+++ b/build/shared/utils.js
5+
@@ -64,9 +64,10 @@ function getCreateJwtCallback(agentContext) {
6+
return jws;
7+
}
8+
else if (jwtIssuer.method === 'jwk') {
9+
- const key = (0, core_1.getJwkFromJson)(jwtIssuer.jwk).key;
10+
+ const jwk = core_1.getJwkFromJson(jwtIssuer.jwk);
11+
+ const key = jwk.key;
12+
const jws = await jwsService.createJwsCompact(agentContext, {
13+
- protectedHeaderOptions: jwt.header,
14+
+ protectedHeaderOptions: Object.assign(jwt.header, { jwk, alg: jwtIssuer.alg }),
15+
payload: core_1.JwtPayload.fromJson(jwt.payload),
16+
key,
17+
});
18+
@@ -75,7 +76,7 @@ function getCreateJwtCallback(agentContext) {
19+
else if (jwtIssuer.method === 'x5c') {
20+
const key = core_1.X509Service.getLeafCertificate(agentContext, { certificateChain: jwtIssuer.x5c }).publicKey;
21+
const jws = await jwsService.createJwsCompact(agentContext, {
22+
- protectedHeaderOptions: jwt.header,
23+
+ protectedHeaderOptions: Object.assign(jwt.header, { jwk: undefined, alg: jwtIssuer.alg }),
24+
payload: core_1.JwtPayload.fromJson(jwt.payload),
25+
key,
26+
});
27+
@@ -102,17 +103,19 @@ async function openIdTokenIssuerToJwtIssuer(agentContext, openId4VcTokenIssuer)
28+
const leafCertificate = core_1.X509Service.getLeafCertificate(agentContext, {
29+
certificateChain: openId4VcTokenIssuer.x5c,
30+
});
31+
+ const jwk = (0, core_1.getJwkFromKey)(leafCertificate.publicKey);
32+
+ const alg = jwk.supportedSignatureAlgorithms[0]
33+
if (!issuer.startsWith('https://')) {
34+
throw new core_1.CredoError('The X509 certificate issuer must be a HTTPS URI.');
35+
}
36+
if ((_b = leafCertificate.sanUriNames) === null || _b === void 0 ? void 0 : _b.includes(issuer)) {
37+
- return Object.assign(Object.assign({}, openId4VcTokenIssuer), { clientIdScheme: 'x509_san_uri' });
38+
+ return Object.assign(Object.assign({}, openId4VcTokenIssuer), { clientIdScheme: 'x509_san_uri', alg });
39+
}
40+
else {
41+
if (!((_c = leafCertificate.sanDnsNames) === null || _c === void 0 ? void 0 : _c.includes((0, core_1.getDomainFromUrl)(issuer)))) {
42+
throw new Error(`The 'iss' claim in the payload does not match a 'SAN-URI' or 'SAN-DNS' name in the x5c certificate.`);
43+
}
44+
- return Object.assign(Object.assign({}, openId4VcTokenIssuer), { clientIdScheme: 'x509_san_dns' });
45+
+ return Object.assign(Object.assign({}, openId4VcTokenIssuer), { clientIdScheme: 'x509_san_dns', alg });
46+
}
47+
}
48+
return openId4VcTokenIssuer;

0 commit comments

Comments
 (0)