Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Jan 13, 2023
2 parents 94c0e73 + a0bd467 commit 5e5328b
Show file tree
Hide file tree
Showing 23 changed files with 582 additions and 329 deletions.
3 changes: 1 addition & 2 deletions packages/did-auth-siop-op-authenticator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ For more detailed information see: [Self Issued OpenID Provider v2 (SIOP)](https
const sessionId = 'example_session_id'
const authorizationRequestDetailsResponse = await agent.getSiopAuthorizationRequestDetails({
sessionId,
verifiedAuthorizationRequest: createAuthorizationResponse,
verifiableCredentials: [credential],
verifiedAuthorizationRequest: createAuthorizationResponse
})
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import * as fs from 'fs'
import { getConfig } from '@veramo/cli/build/setup'
import { createObjects } from '@veramo/cli/build/lib/objectCreator'
import didAuthSiopOpAuthenticatorAgentLogic from './shared/didAuthSiopOpAuthenticatorAgentLogic'
import { PresentationSignCallback } from '@sphereon/did-auth-siop'

jest.setTimeout(30000)

import didAuthSiopOpAuthenticatorAgentLogic from './shared/didAuthSiopOpAuthenticatorAgentLogic'
import { presentationSignCallback } from './shared/mockedData'
function getFile(path: string) {
return fs.readFileSync(path, 'utf-8')
}

function getFileAsJson(path: string) {
return JSON.parse(getFile(path))
}

let agent: any

const presentationSignCallback: PresentationSignCallback = async (args) => {
const presentationSignProof = getFileAsJson(
'./packages/did-auth-siop-op-authenticator/__tests__/vc_vp_examples/psc/psc.json'
)

return {
...args.presentation,
...presentationSignProof
}
}

const setup = async (): Promise<boolean> => {
const config = getConfig('packages/did-auth-siop-op-authenticator/agent.yml')
config.agent.$args[0].plugins[1].$args[0] = presentationSignCallback
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as fs from 'fs'
import 'cross-fetch/polyfill'
// @ts-ignore
import express from 'express'
import { IAgent, createAgent, IAgentOptions } from '@veramo/core'
import { IAgent, createAgent, IAgentOptions, IDataStore } from '@veramo/core'
import { AgentRestClient } from '@veramo/remote-client'
import { Server } from 'http'
import { AgentRouter, RequestWithAgentRouter } from '@veramo/remote-server'
Expand All @@ -12,17 +14,36 @@ import { getDidKeyResolver } from '@veramo/did-provider-key'
import { DIDResolverPlugin } from '@veramo/did-resolver'
import { getUniResolver } from '@sphereon/did-uni-client'
import didAuthSiopOpAuthenticatorAgentLogic from './shared/didAuthSiopOpAuthenticatorAgentLogic'
import { presentationSignCallback } from './shared/mockedData'
import { PresentationSignCallback } from '@sphereon/did-auth-siop'

jest.setTimeout(30000)

function getFile(path: string) {
return fs.readFileSync(path, 'utf-8')
}

function getFileAsJson(path: string) {
return JSON.parse(getFile(path))
}

const port = 3002
const basePath = '/agent'
let serverAgent: IAgent
let restServer: Server

const presentationSignCallback: PresentationSignCallback = async (args) => {
const presentationSignProof = getFileAsJson(
'./packages/did-auth-siop-op-authenticator/__tests__/vc_vp_examples/psc/psc.json'
)

return {
...args.presentation,
...presentationSignProof
}
}

const getAgent = (options?: IAgentOptions) =>
createAgent<IDidAuthSiopOpAuthenticator>({
createAgent<IDidAuthSiopOpAuthenticator & IDataStore>({
...options,
plugins: [
new DidAuthSiopOpAuthenticator(presentationSignCallback),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
import { TAgent } from '@veramo/core'
import { OP, AuthorizationRequest } from '@sphereon/did-auth-siop'
import { IDidAuthSiopOpAuthenticator, IGetSiopAuthorizationRequestDetailsArgs } from '../../src'
import * as fs from 'fs'
import { IDataStore, TAgent, VerifiableCredential } from '@veramo/core'
import { IAuthRequestDetails, IDidAuthSiopOpAuthenticator } from '../../src'
import { OP, AuthorizationRequest, VerifiablePresentationWithLocation } from '@sphereon/did-auth-siop'

import {
PresentationDefinitionWithLocation,
ResponseContext,
ResponseMode,
ResponseType,
SubjectIdentifierType,
UrlEncodingFormat,
VerificationMode,
VerifiedAuthorizationRequest,
ParsedAuthorizationRequestURI,
ParsedAuthorizationRequestURI
} from '@sphereon/did-auth-siop'
import { mapIdentifierKeysToDoc } from '@veramo/utils'
import { pdMultiple, pdSingle, vcs, vpMultiple, vpSingle } from './mockedData'

function getFile(path: string) {
return fs.readFileSync(path, 'utf-8')
}

function getFileAsJson(path: string) {
return JSON.parse(getFile(path))
}

const nock = require('nock')
jest.mock('@veramo/utils', () => ({
...jest.requireActual('@veramo/utils'),
mapIdentifierKeysToDoc: jest.fn(),
}))

type ConfiguredAgent = TAgent<IDidAuthSiopOpAuthenticator>
type ConfiguredAgent = TAgent<IDidAuthSiopOpAuthenticator & IDataStore>

const didMethod = 'ethr'
const did = 'did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a'
Expand Down Expand Up @@ -156,6 +165,16 @@ export default (testContext: {
await testContext.setup()
agent = testContext.getAgent()

const idCardCredential: VerifiableCredential = getFileAsJson(
'./packages/did-auth-siop-op-authenticator/__tests__/vc_vp_examples/vc/vc_idCardCredential.json'
)
await agent.dataStoreSaveVerifiableCredential({ verifiableCredential: idCardCredential })

const driverLicenseCredential: VerifiableCredential = getFileAsJson(
'./packages/did-auth-siop-op-authenticator/__tests__/vc_vp_examples/vc/vc_driverLicense.json'
)
await agent.dataStoreSaveVerifiableCredential({ verifiableCredential: driverLicenseCredential })

nock(redirectUrl).get(`?stateId=${stateId}`).times(5).reply(200, requestResultMockedText)

const mockedMapIdentifierKeysToDocMethod = mapIdentifierKeysToDoc as jest.Mock
Expand Down Expand Up @@ -298,52 +317,96 @@ export default (testContext: {
})

it('should get authentication details with single credential', async () => {
let authorizationRequestArgs: IGetSiopAuthorizationRequestDetailsArgs = {
const pd_single: PresentationDefinitionWithLocation = getFileAsJson(
'./packages/did-auth-siop-op-authenticator/__tests__/vc_vp_examples/pd/pd_single.json'
)
const vp_single: VerifiablePresentationWithLocation = getFileAsJson(
'./packages/did-auth-siop-op-authenticator/__tests__/vc_vp_examples/vp/vp_single.json'
)
vp_single.presentation.presentation_submission!.id = expect.any(String)

const result: IAuthRequestDetails = await agent.getSiopAuthorizationRequestDetails({
sessionId,
verifiedAuthorizationRequest: {
...createAuthorizationResponseMockedResult,
presentationDefinitions: pdSingle,
presentationDefinitions: [pd_single],
authorizationRequest: {} as AuthorizationRequest,
versions: [],
payload: {},
},
verifiableCredentials: vcs,
signingOptions: {
nonce: 'nonce202212272050',
domain: 'domain202212272051',
},
}
const result = await agent.getSiopAuthorizationRequestDetails(authorizationRequestArgs)
})

expect(result).toEqual({
id: 'did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a',
vpResponseOpts: [vp_single],
})
})

it('should get authentication details with getting specific credentials', async () => {
const pdSingle: PresentationDefinitionWithLocation = getFileAsJson(
'./packages/did-auth-siop-op-authenticator/__tests__/vc_vp_examples/pd/pd_single.json'
)
const vpSingle: VerifiablePresentationWithLocation = getFileAsJson(
'./packages/did-auth-siop-op-authenticator/__tests__/vc_vp_examples/vp/vp_single.json'
)
vpSingle.presentation.presentation_submission!.id = expect.any(String)

const result: IAuthRequestDetails = await agent.getSiopAuthorizationRequestDetails({
sessionId,
verifiedAuthorizationRequest: {
...createAuthorizationResponseMockedResult,
presentationDefinitions: [pdSingle],
authorizationRequest: {} as AuthorizationRequest,
versions: [],
payload: {},
},
credentialFilter: {
where: [{
column: 'id',
value: ['https://example.com/credentials/1872']
}]
}
})

expect(result).toEqual({
id: 'did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a',
vpResponseOpts: vpSingle,
alsoKnownAs: undefined,
vpResponseOpts: [vpSingle],
})
})

it('should get authentication details with multiple credentials', async () => {
let authorizationRequestArgs: IGetSiopAuthorizationRequestDetailsArgs = {
const pdMultiple: PresentationDefinitionWithLocation = getFileAsJson(
'./packages/did-auth-siop-op-authenticator/__tests__/vc_vp_examples/pd/pd_multiple.json'
)
const vpMultiple: VerifiablePresentationWithLocation = getFileAsJson(
'./packages/did-auth-siop-op-authenticator/__tests__/vc_vp_examples/vp/vp_multiple.json'
)
vpMultiple.presentation.presentation_submission!.id = expect.any(String)

const result: IAuthRequestDetails = await agent.getSiopAuthorizationRequestDetails({
sessionId,
verifiedAuthorizationRequest: {
...createAuthorizationResponseMockedResult,
presentationDefinitions: pdMultiple,
presentationDefinitions: [pdMultiple],
authorizationRequest: {} as AuthorizationRequest,
versions: [],
payload: {},
},
verifiableCredentials: vcs,
signingOptions: {
nonce: 'nonce202212272050',
domain: 'domain202212272051',
},
}

const result = await agent.getSiopAuthorizationRequestDetails(authorizationRequestArgs)
})

expect(result).toEqual({
alsoKnownAs: undefined,
id: 'did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a',
vpResponseOpts: vpMultiple,
vpResponseOpts: [vpMultiple],
})
})

Expand All @@ -370,11 +433,15 @@ export default (testContext: {
})

it('should send authentication response', async () => {
const pdMultiple: PresentationDefinitionWithLocation = getFileAsJson(
'./packages/did-auth-siop-op-authenticator/__tests__/vc_vp_examples/pd/pd_multiple.json'
)

const result = await agent.sendSiopAuthorizationResponse({
sessionId,
verifiedAuthorizationRequest: {
...createAuthorizationResponseMockedResult,
presentationDefinitions: pdMultiple,
presentationDefinitions: [pdMultiple],
authorizationRequest: {} as AuthorizationRequest,
versions: [],
authorizationRequestPayload: {},
Expand Down
Loading

0 comments on commit 5e5328b

Please sign in to comment.