Skip to content

Commit

Permalink
test: openid4vp x509 (#1984)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Auer <martin.auer97@gmail.com>
  • Loading branch information
auer-martin committed Aug 5, 2024
1 parent fa62b74 commit 3ef3f10
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
25 changes: 19 additions & 6 deletions packages/openid4vc/tests/openid4vc.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
W3cCredentialSubject,
w3cDate,
W3cIssuer,
X509Module,
KeyType,
Jwt,
Jwk,
} from '@credo-ts/core'
Expand Down Expand Up @@ -57,6 +59,7 @@ describe('OpenId4Vc', () => {
let issuer: AgentType<{
openId4VcIssuer: OpenId4VcIssuerModule
tenants: TenantsModule<{ openId4VcIssuer: OpenId4VcIssuerModule }>
x509: X509Module
}>
let issuer1: TenantType
let issuer2: TenantType
Expand All @@ -80,6 +83,7 @@ describe('OpenId4Vc', () => {
issuer = (await createAgentFromModules(
'issuer',
{
x509: new X509Module(),
openId4VcIssuer: new OpenId4VcIssuerModule({
baseUrl: issuanceBaseUrl,
endpoints: {
Expand Down Expand Up @@ -130,6 +134,7 @@ describe('OpenId4Vc', () => {
openId4VcHolder: new OpenId4VcHolderModule(),
askar: new AskarModule(askarModuleConfig),
tenants: new TenantsModule(),
x509: new X509Module(),
},
'96213c3d7fc8d4d6754c7a0fd969598e'
)) as unknown as typeof holder
Expand Down Expand Up @@ -703,10 +708,7 @@ describe('OpenId4Vc', () => {
const openIdVerifier = await verifier.agent.modules.openId4VcVerifier.createVerifier()

const signedSdJwtVc = await issuer.agent.sdJwtVc.sign({
holder: {
method: 'did',
didUrl: holder.kid,
},
holder: { method: 'did', didUrl: holder.kid },
issuer: {
method: 'did',
didUrl: issuer.kid,
Expand All @@ -722,8 +724,17 @@ describe('OpenId4Vc', () => {
},
})

const certificate = await verifier.agent.x509.createSelfSignedCertificate({
key: await verifier.agent.wallet.createKey({ keyType: KeyType.Ed25519 }),
extensions: [[{ type: 'dns', value: 'example.com' }]],
})

const rawCertificate = certificate.toString('base64')
await holder.agent.sdJwtVc.store(signedSdJwtVc.compact)

await holder.agent.x509.addTrustedCertificate(rawCertificate)
await verifier.agent.x509.addTrustedCertificate(rawCertificate)

const presentationDefinition = {
id: 'OpenBadgeCredential',
input_descriptors: [
Expand Down Expand Up @@ -756,9 +767,11 @@ describe('OpenId4Vc', () => {
const { authorizationRequest, verificationSession } =
await verifier.agent.modules.openId4VcVerifier.createAuthorizationRequest({
verifierId: openIdVerifier.verifierId,

requestSigner: {
method: 'did',
didUrl: verifier.kid,
method: 'x5c',
x5c: [rawCertificate],
issuer: 'https://example.com/hakuna/matadata',
},
presentationExchange: {
definition: presentationDefinition,
Expand Down
4 changes: 2 additions & 2 deletions packages/openid4vc/tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
OpenId4VcVerificationSessionState,
OpenId4VcVerificationSessionStateChangedEvent,
} from '../src'
import type { BaseEvent, ModulesMap } from '@credo-ts/core'
import type { BaseEvent, ModulesMap, X509Module } from '@credo-ts/core'
import type { TenantsModule } from '@credo-ts/tenants'
import type { Observable } from 'rxjs'

Expand Down Expand Up @@ -44,7 +44,7 @@ export async function createAgentFromModules<MM extends ModulesMap>(label: strin
export type AgentType<MM extends ModulesMap> = Awaited<ReturnType<typeof createAgentFromModules<MM>>>

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type AgentWithTenantsModule = Agent<{ tenants: TenantsModule<any> }>
type AgentWithTenantsModule = Agent<{ tenants: TenantsModule<any>; x509: X509Module }>

export async function createTenantForAgent(
// FIXME: we need to make some improvements on the agent typing. It'a quite hard
Expand Down

0 comments on commit 3ef3f10

Please sign in to comment.