Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/siop-verifier' into feat…
Browse files Browse the repository at this point in the history
…ure/siop-verifier
  • Loading branch information
nklomp committed Apr 24, 2023
2 parents ec7d0b6 + e9f30f1 commit aba0fe8
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 117 deletions.
5 changes: 1 addition & 4 deletions packages/qr-code-generator/__tests__/shared/fixtures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,13 @@ export const openid4vciCreateElementByValue: CreateElementArgs<QRType.OpenID4VCI

export const openid4vciCreateValueValid: CreateValueArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme> = {
data: openid4vciDataValid,
onGenerate: (result: ValueResult<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>) => {
console.log(result, null, 2)
},
onGenerate: (result: ValueResult<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>) => {},
}

export const openid4vciCreateElementValid: CreateElementArgs<QRType.OpenID4VCI, OpenID4VCIDataWithScheme> = {
data: openid4vciDataValid,
renderingProps,
onGenerate: (result: ValueResult<QRType.OpenID4VCI, OpenID4VCIDataWithScheme>) => {
render(<div data-testid="test-div-openid4vci">{result.data.object.credentialOfferUri}</div>)
console.log(result.value)
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type ConfiguredAgent = TAgent<IDidAuthSiopOpAuthenticator & IDataStore>

const didMethod = 'ethr'
const did = 'did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a'
// @ts-ignore
const identifier = {
did,
provider: '',
Expand Down Expand Up @@ -75,7 +76,6 @@ const authKeys = [
},
]

console.log(identifier)
const sessionId = 'sessionId'
const otherSessionId = 'other_sessionId'
const redirectUrl = 'http://example/ext/get-auth-request-url'
Expand Down
1 change: 0 additions & 1 deletion packages/siopv2-oid4vp-rp-auth/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export function getPresentationVerificationCallback(didOpts: IDIDOptions, contex
fetchRemoteContexts: true,
domain: getDID(didOpts.identifierOpts),
})
console.log(`VP verification result: ${JSON.stringify(result, null, 2)}`)
return { verified: result.verified }
}

Expand Down
7 changes: 5 additions & 2 deletions packages/siopv2-oid4vp-rp-rest-api/__tests__/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { ISIOPv2RP, SIOPv2RP } from '@sphereon/ssi-sdk-siopv2-oid4vp-rp-auth'
import { IPresentationExchange, PresentationExchange } from '@sphereon/ssi-sdk-presentation-exchange'
import { CheckLinkedDomain } from '@sphereon/did-auth-siop'
import { entraAndSphereonCompatibleDef, entraVerifiedIdPresentation } from './presentationDefinitions'
import Debug from 'debug'

const debug = Debug('ssi-sdk-siopv2-oid4vp-rp-rest-api')

export const DIF_UNIRESOLVER_RESOLVE_URL = 'https://dev.uniresolver.io/1.0/identifiers'
export const APP_ID = 'sphereon:rp-demo'
Expand Down Expand Up @@ -197,9 +200,9 @@ agent
},
})
.then((value) => {
console.log(`IDENTIFIER: ${value.did}`)
debug(`IDENTIFIER: ${value.did}`)
})
.catch((reason) => {
console.log(`WHOOPSIE: ${reason}`)
debug(`error on creation: ${reason}`)
})
export default agent
172 changes: 86 additions & 86 deletions packages/siopv2-oid4vp-rp-rest-api/src/SIOPv2RPRestAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ export class SIOPv2RPRestAPI {

private removeAuthRequestStateWebappEndpoint() {
this.express.delete(
this._opts?.webappDeleteAuthRequestPath ?? '/webapp/definitions/:definitionId/auth-requests/:correlationId',
async (request, response) => {
const correlationId: string = request.params.correlationId
const definitionId: string = request.params.definitionId
if (!correlationId || !definitionId) {
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`)
return SIOPv2RPRestAPI.sendErrorResponse(response, 404, 'No authorization request could be found')
this._opts?.webappDeleteAuthRequestPath ?? '/webapp/definitions/:definitionId/auth-requests/:correlationId',
async (request, response) => {
const correlationId: string = request.params.correlationId
const definitionId: string = request.params.definitionId
if (!correlationId || !definitionId) {
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`)
return SIOPv2RPRestAPI.sendErrorResponse(response, 404, 'No authorization request could be found')
}
response.statusCode = 200
return response.send(this.agent.siopDeleteAuthState({ definitionId, correlationId }))
}
response.statusCode = 200
return response.send(this.agent.siopDeleteAuthState({ definitionId, correlationId }))
}
)
}

Expand All @@ -115,16 +115,16 @@ export class SIOPv2RPRestAPI {
const correlationId: string = request.body.correlationId as string
const definitionId: string = request.body.definitionId as string
const requestState =
correlationId && definitionId
? await this.agent.siopGetAuthRequestState({
correlationId,
definitionId,
errorOnNotFound: false,
})
: undefined
correlationId && definitionId
? await this.agent.siopGetAuthRequestState({
correlationId,
definitionId,
errorOnNotFound: false,
})
: undefined
if (!requestState || !definitionId || !correlationId) {
console.log(
`No authentication request mapping could be found for the given URL. correlation: ${correlationId}, definitionId: ${definitionId}`
`No authentication request mapping could be found for the given URL. correlation: ${correlationId}, definitionId: ${definitionId}`
)
response.statusCode = 404

Expand Down Expand Up @@ -155,8 +155,8 @@ export class SIOPv2RPRestAPI {
definitionId,
lastUpdated: overallState.lastUpdated,
...(responseState && responseState.status === AuthorizationResponseStateStatus.VERIFIED
? { payload: await responseState.response.mergedPayloads() }
: {}),
? { payload: await responseState.response.mergedPayloads() }
: {}),
}
console.log(`Will send auth status: ${JSON.stringify(statusBody)}`)
if (overallState.status === AuthorizationRequestStateStatus.ERROR || overallState.status === AuthorizationResponseStateStatus.ERROR) {
Expand All @@ -170,19 +170,19 @@ export class SIOPv2RPRestAPI {

private createAuthRequestWebappEndpoint() {
this.express.post(
this._opts?.webappCreateAuthRequestPath || '/webapp/definitions/:definitionId/auth-requests',
(request: RequestWithAgent, response) => {
// if (!request.agent) throw Error('No agent configured')
const definitionId = request.params.definitionId
const state: string = uuid.uuid()
const correlationId = state
this._opts?.webappCreateAuthRequestPath || '/webapp/definitions/:definitionId/auth-requests',
(request: RequestWithAgent, response) => {
// if (!request.agent) throw Error('No agent configured')
const definitionId = request.params.definitionId
const state: string = uuid.uuid()
const correlationId = state

const requestByReferenceURI = uriWithBase(`/siop/definitions/${definitionId}/auth-requests/${correlationId}`, {
baseURI: this._opts?.siopBaseURI,
})
const redirectURI = uriWithBase(`/siop/definitions/${definitionId}/auth-responses/${correlationId}`, { baseURI: this._opts?.siopBaseURI })
const requestByReferenceURI = uriWithBase(`/siop/definitions/${definitionId}/auth-requests/${correlationId}`, {
baseURI: this._opts?.siopBaseURI,
})
const redirectURI = uriWithBase(`/siop/definitions/${definitionId}/auth-responses/${correlationId}`, { baseURI: this._opts?.siopBaseURI })

this.agent
this.agent
.siopCreateAuthRequestURI({
definitionId,
correlationId,
Expand All @@ -204,31 +204,31 @@ export class SIOPv2RPRestAPI {
console.error(e, e.stack)
return SIOPv2RPRestAPI.sendErrorResponse(response, 500, 'Could not create an authorization request URI: ' + e.message)
})
}
}
)
}

private verifyAuthResponseSIOPv2Endpoint() {
this.express.post(
this._opts?.siopVerifyAuthResponsePath ?? '/siop/definitions/:definitionId/auth-responses/:correlationId',
async (request, response) => {
const correlationId = request.params.correlationId
const definitionId = request.params.definitionId
if (!correlationId || !definitionId) {
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`)
return SIOPv2RPRestAPI.sendErrorResponse(response, 404, 'No authorization request could be found')
}
console.log('Authorization Response (siop-sessions')
console.log(JSON.stringify(request.body, null, 2))
const definition = await this.agent.pexStoreGetDefinition({ definitionId })
const authorizationResponse = typeof request.body === 'string' ? request.body : (request.body as AuthorizationResponsePayload)
console.log(`URI: ${JSON.stringify(authorizationResponse)}`)
if (!definition) {
response.statusCode = 404
response.statusMessage = `No definition ${definitionId}`
return response.send()
}
await this.agent
this._opts?.siopVerifyAuthResponsePath ?? '/siop/definitions/:definitionId/auth-responses/:correlationId',
async (request, response) => {
const correlationId = request.params.correlationId
const definitionId = request.params.definitionId
if (!correlationId || !definitionId) {
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`)
return SIOPv2RPRestAPI.sendErrorResponse(response, 404, 'No authorization request could be found')
}
console.log('Authorization Response (siop-sessions')
console.log(JSON.stringify(request.body, null, 2))
const definition = await this.agent.pexStoreGetDefinition({ definitionId })
const authorizationResponse = typeof request.body === 'string' ? request.body : (request.body as AuthorizationResponsePayload)
console.log(`URI: ${JSON.stringify(authorizationResponse)}`)
if (!definition) {
response.statusCode = 404
response.statusMessage = `No definition ${definitionId}`
return response.send()
}
await this.agent
.siopVerifyAuthResponse({
authorizationResponse,
correlationId,
Expand Down Expand Up @@ -263,50 +263,50 @@ export class SIOPv2RPRestAPI {
response.statusMessage = reason.message
return response.send()
})
}
}
)
}

private getAuthRequestSIOPv2Endpoint() {
this.express.get(
this._opts?.siopGetAuthRequestPath ?? '/siop/definitions/:definitionId/auth-requests/:correlationId',
async (request, response) => {
const correlationId = request.params.correlationId
const definitionId = request.params.definitionId
if (!correlationId || !definitionId) {
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`)
return SIOPv2RPRestAPI.sendErrorResponse(response, 404, 'No authorization request could be found')
}
const requestState = await this.agent.siopGetAuthRequestState({
correlationId,
definitionId,
errorOnNotFound: false,
})
if (!requestState) {
console.log(
`No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${definitionId}`
)
return SIOPv2RPRestAPI.sendErrorResponse(response, 404, `No authorization request could be found`)
}
const requestObject = await requestState.request?.requestObject?.toJwt()
console.log('JWT Request object:')
console.log(requestObject)

let error: string | undefined
try {
response.statusCode = 200
return response.send(requestObject)
} catch (e) {
error = typeof e === 'string' ? e : e instanceof Error ? e.message : undefined
} finally {
this.agent.siopUpdateAuthRequestState({
this._opts?.siopGetAuthRequestPath ?? '/siop/definitions/:definitionId/auth-requests/:correlationId',
async (request, response) => {
const correlationId = request.params.correlationId
const definitionId = request.params.definitionId
if (!correlationId || !definitionId) {
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`)
return SIOPv2RPRestAPI.sendErrorResponse(response, 404, 'No authorization request could be found')
}
const requestState = await this.agent.siopGetAuthRequestState({
correlationId,
definitionId,
state: AuthorizationRequestStateStatus.SENT,
error,
errorOnNotFound: false,
})
if (!requestState) {
console.log(
`No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${definitionId}`
)
return SIOPv2RPRestAPI.sendErrorResponse(response, 404, `No authorization request could be found`)
}
const requestObject = await requestState.request?.requestObject?.toJwt()
console.log('JWT Request object:')
console.log(requestObject)

let error: string | undefined
try {
response.statusCode = 200
return response.send(requestObject)
} catch (e) {
error = typeof e === 'string' ? e : e instanceof Error ? e.message : undefined
} finally {
this.agent.siopUpdateAuthRequestState({
correlationId,
definitionId,
state: AuthorizationRequestStateStatus.SENT,
error,
})
}
}
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const definitionId = '9449e2db-791f-407c-b086-c21cc677d2e0'
const baseUrl = 'https://ssi-backend.sphereon.com'

const agent = createAgent<IResolver & ISIOPv2OID4VPRPRestClient>({
plugins: [new SIOPv2OID4VPRPRestClient(baseUrl, definitionId)],
plugins: [new SIOPv2OID4VPRPRestClient({baseUrl, definitionId})],
})

describe('@sphereon/siopv2-oid4vp-rp-rest-client', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const definitionId = '9449e2db-791f-407c-b086-c21cc677d2e0'
const baseUrl = 'https://my-siop-endpoint'

const agent = createAgent<IResolver & ISIOPv2OID4VPRPRestClient>({
plugins: [new SIOPv2OID4VPRPRestClient(baseUrl, definitionId)],
plugins: [new SIOPv2OID4VPRPRestClient({baseUrl, definitionId})],
})
afterAll(() => {
nock.cleanAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export class SIOPv2OID4VPRPRestClient implements IAgentPlugin {
private readonly baseUrl?: string
private readonly definitionId?: string

constructor(baseUrl?: string, definitionId?: string) {
if (baseUrl) {
this.baseUrl = baseUrl
constructor(args?: { baseUrl?: string, definitionId?: string }) {
if (args?.baseUrl) {
this.baseUrl = args.baseUrl
}
if (definitionId) {
this.definitionId = definitionId
if (args?.definitionId) {
this.definitionId = args.definitionId
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ describe('credential-LD full flow', () => {
})

expect(verifiableCredential).toBeDefined()
// console.log(verifiableCredential)

const verifiedCredential = await agent.verifyCredentialLDLocal({
credential: verifiableCredential,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ let agent: any

const setup = async (): Promise<boolean> => {
const config = getConfig('packages/vc-handler-ld-local/agent.yml')
console.log(JSON.stringify(config.agent.$args[0], null, 1))
config.agent.$args[0].plugins[1].$args[0].contextMaps = [LdDefaultContexts]
config.agent.$args[0].plugins[1].$args[0].suites = [SphereonEd25519Signature2018, SphereonEd25519Signature2020, SphereonBbsBlsSignature2020]
const { localAgent } = createObjects(config, { localAgent: '/agent' })
Expand Down
5 changes: 1 addition & 4 deletions packages/vc-handler-ld-local/src/ld-credential-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ export class LdCredentialModule {

// result can include raw Error
debug(`Error verifying LD Verifiable Credential: ${JSON.stringify(result, null, 2)}`)
console.log(JSON.stringify(result, null, 2))
context.agent.emit(events.CREDENTIAL_VERIFY_FAILED, credential)
throw Error('Error verifying LD Verifiable Credential')
}
Expand All @@ -196,7 +195,6 @@ export class LdCredentialModule {
checkStatus?: Function
//AssertionProofPurpose()
): Promise<boolean> {
// console.log(JSON.stringify(presentation, null, 2))
let result
if (presentation.proof.type?.includes('BbsBlsSignature2020')) {
//Should never be null or undefined
Expand Down Expand Up @@ -246,8 +244,7 @@ export class LdCredentialModule {
// NOT verified.

// result can include raw Error
console.log(`Error verifying LD Verifiable Presentation`)
console.log(JSON.stringify(result, null, 2))
debug(`Error verifying LD Verifiable Presentation: ${JSON.stringify(result, null, 2)}`)
context.agent.emit(events.PRESENTATION_VERIFY_FAILED, presentation)
throw Error('Error verifying LD Verifiable Presentation')
}
Expand Down
3 changes: 0 additions & 3 deletions packages/vc-handler-ld-local/src/ld-document-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export class LdDocumentLoader {

getLoader(context: IAgentContext<IResolver>, attemptToFetchContexts = false) {
return extendContextLoader(async (url: string) => {
// console.log(`resolving context for: ${url}`)

// did resolution
if (url.toLowerCase().startsWith('did:')) {
let didDoc: DIDDocument | null
Expand Down Expand Up @@ -78,7 +76,6 @@ export class LdDocumentLoader {
// and LD suites to be fixed specifically within the Veramo LD Suites definition
this.ldSuiteLoader.getAllSignatureSuites().forEach((x) => x.preDidResolutionModification(url, didDoc as DIDDocument))

// console.log(`Returning from Documentloader: ${JSON.stringify(returnDocument)}`)
return {
contextUrl: null,
documentUrl: url,
Expand Down
Loading

0 comments on commit aba0fe8

Please sign in to comment.