Skip to content

Commit

Permalink
add sixt
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
  • Loading branch information
TimoGlastra committed Nov 20, 2024
1 parent f01a4ff commit ba3ac9c
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 21 deletions.
10 changes: 8 additions & 2 deletions agent/src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ const zCreatePresentationRequestBody = z.object({
})

apiRouter.post('/requests/create', async (request: Request, response: Response) => {
const verifier = await getVerifier()

const createPresentationRequestBody = zCreatePresentationRequestBody.parse(request.body)

const x509Certificate = getX509Certificate()
Expand All @@ -200,6 +198,14 @@ apiRouter.post('/requests/create', async (request: Request, response: Response)
})
}

const verifierId = verifiers.find((a) => a.presentationRequests.find((r) => r.id === definition.id))?.verifierId
if (!verifierId) {
return response.status(404).json({
error: 'Verifier not found',
})
}
const verifier = await getVerifier(verifierId)

const { authorizationRequest, verificationSession } =
await agent.modules.openId4VcVerifier.createAuthorizationRequest({
verifierId: verifier.verifierId,
Expand Down
3 changes: 2 additions & 1 deletion agent/src/issuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getX509Certificate } from './keyMethods'
import { DateOnly, oneYearInMilliseconds, serverStartupTimeInMilliseconds, tenDaysInMilliseconds } from './utils/date'
import { getVerifier } from './verifier'
import { pidSdJwtInputDescriptor } from './verifiers/util'
import { animoVerifier } from './verifiers/animo'

export async function createOrUpdateIssuer(options: OpenId4VciCreateIssuerOptions & { issuerId: string }) {
if (await doesIssuerExist(options.issuerId)) {
Expand Down Expand Up @@ -51,7 +52,7 @@ export function getIssuerIdForCredentialConfigurationId(credentialConfigurationI

export const getVerificationSessionForIssuanceSession: OpenId4VciGetVerificationSessionForIssuanceSessionAuthorization =
async ({ agentContext, scopes }) => {
const verifier = await getVerifier()
const verifier = await getVerifier(animoVerifier.verifierId)
const x509Certificate = getX509Certificate()
const verifierApi = agentContext.dependencyManager.resolve(OpenId4VcVerifierApi)

Expand Down
7 changes: 4 additions & 3 deletions agent/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { createOrUpdateIssuer } from './issuer'
import { issuers } from './issuers'
import { setupX509Certificate } from './keyMethods'
import { getProvider, oidcRouterPath, oidcUrl } from './oidcProvider/provider'
import { createVerifier, doesVerifierExist } from './verifier'
import { createOrUpdateVerifier } from './verifier'
import { verifiers } from './verifiers'

async function run() {
await agent.initialize()
Expand All @@ -28,8 +29,8 @@ async function run() {
})
}

if (!(await doesVerifierExist())) {
await createVerifier()
for (const verifier of verifiers) {
await createOrUpdateVerifier(verifier)
}

await setupX509Certificate()
Expand Down
28 changes: 21 additions & 7 deletions agent/src/verifier.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import type { OpenId4VcSiopCreateVerifierOptions } from '@credo-ts/openid4vc'
import { agent } from './agent'
import type { DifPresentationExchangeDefinitionV2 } from '@credo-ts/core'

const verifierId = 'c01ea0f3-34df-41d5-89d1-50ef3d181855'
export interface PlaygroundVerifierOptions {
verifierId: string
clientMetadata?: OpenId4VcSiopCreateVerifierOptions['clientMetadata']
presentationRequests: Array<DifPresentationExchangeDefinitionV2>
}

export async function createVerifier() {
return agent.modules.openId4VcVerifier.createVerifier({
verifierId,
})
export async function createOrUpdateVerifier(options: PlaygroundVerifierOptions) {
if (await doesVerifierExist(options.verifierId)) {
await agent.modules.openId4VcVerifier.updateVerifierMetadata({
verifierId: options.verifierId,
clientMetadata: options.clientMetadata,
})
} else {
return agent.modules.openId4VcVerifier.createVerifier({
clientMetadata: options.clientMetadata,
verifierId: options.verifierId,
})
}
}

export async function doesVerifierExist() {
export async function doesVerifierExist(verifierId: string) {
try {
await agent.modules.openId4VcVerifier.getVerifierByVerifierId(verifierId)
return true
Expand All @@ -17,6 +31,6 @@ export async function doesVerifierExist() {
}
}

export async function getVerifier() {
export async function getVerifier(verifierId: string) {
return agent.modules.openId4VcVerifier.getVerifierByVerifierId(verifierId)
}
12 changes: 8 additions & 4 deletions agent/src/verifiers/animo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import type { DifPresentationExchangeDefinitionV2 } from '@credo-ts/core'
import { pidMdocInputDescriptor, pidSdJwtInputDescriptor } from './util'
import type { PlaygroundVerifierOptions } from '../verifier'

export const animoVerifier = {
clientMetadata: {
logo_uri:
'https://camo.githubusercontent.com/e19cc0e590529e86cb0d39e2528d36284e5c2ac454cd038473c8bd71b2927720/68747470733a2f2f7265732e636c6f7564696e6172792e636f6d2f616e696d6f2d736f6c7574696f6e732f696d6167652f75706c6f61642f76313635363537383332302f616e696d6f2d6c6f676f2d6c696768742d6e6f2d746578745f6f6b396175792e737667',
client_name: 'Animo',
},
verifierId: 'd8662712-ee78-406c-a88c-df4ff1ed9468',
presentationRequests: [
{
id: '4db74328-9e94-49bb-97b7-bbfcb2d11a06',
Expand Down Expand Up @@ -64,6 +70,4 @@ export const animoVerifier = {
],
},
],
} as const satisfies {
presentationRequests: Array<DifPresentationExchangeDefinitionV2>
}
} as const satisfies PlaygroundVerifierOptions
12 changes: 8 additions & 4 deletions agent/src/verifiers/sixt.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import type { DifPresentationExchangeDefinitionV2 } from '@credo-ts/core'
import { mobileDriversLicenseMdoc, mobileDriversLicenseSdJwt } from '../issuers/infrastruktur'
import { mdocInputDescriptor, pidSdJwtInputDescriptor, sdJwtInputDescriptor } from './util'
import type { PlaygroundVerifierOptions } from '../verifier'
import { AGENT_HOST } from '../constants'

export const sixtVerifier = {
verifierId: 'c01ea0f3-34df-41d5-89d1-50ef3d181855',
clientMetadata: {
logo_uri: `${AGENT_HOST}/assets/verifiers/sixt/verifier.png`,
client_name: 'Sixt - Rent a Car',
},
presentationRequests: [
{
id: '1ad8ea6e-ec51-4e14-b316-dd76a6275480',
Expand Down Expand Up @@ -49,6 +55,4 @@ export const sixtVerifier = {
],
},
],
} as const satisfies {
presentationRequests: Array<DifPresentationExchangeDefinitionV2>
}
} as const satisfies PlaygroundVerifierOptions
Binary file added app/public/assets/verifiers/sixt/verifier.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ba3ac9c

Please sign in to comment.