Skip to content

Commit

Permalink
fix: Incorrect verification method id returned when signing credentia…
Browse files Browse the repository at this point in the history
…ls in some cases
  • Loading branch information
nklomp committed Jan 13, 2023
1 parent 00892e2 commit c508507
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 228 deletions.
2 changes: 1 addition & 1 deletion packages/did-auth-siop-op-authenticator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +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
verifiedAuthorizationRequest: createAuthorizationResponse,
})
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ function getFileAsJson(path: string) {
let agent: any

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ 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'
)
const presentationSignProof = getFileAsJson('./packages/did-auth-siop-op-authenticator/__tests__/vc_vp_examples/psc/psc.json')

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
UrlEncodingFormat,
VerificationMode,
VerifiedAuthorizationRequest,
ParsedAuthorizationRequestURI
ParsedAuthorizationRequestURI,
} from '@sphereon/did-auth-siop'
import { mapIdentifierKeysToDoc } from '@veramo/utils'

Expand Down Expand Up @@ -348,10 +348,10 @@ export default (testContext: {

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'
'./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'
'./packages/did-auth-siop-op-authenticator/__tests__/vc_vp_examples/vp/vp_single.json'
)
vpSingle.presentation.presentation_submission!.id = expect.any(String)

Expand All @@ -365,11 +365,13 @@ export default (testContext: {
payload: {},
},
credentialFilter: {
where: [{
column: 'id',
value: ['https://example.com/credentials/1872']
}]
}
where: [
{
column: 'id',
value: ['https://example.com/credentials/1872'],
},
],
},
})

expect(result).toEqual({
Expand Down Expand Up @@ -434,7 +436,7 @@ 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'
'./packages/did-auth-siop-op-authenticator/__tests__/vc_vp_examples/pd/pd_multiple.json'
)

const result = await agent.sendSiopAuthorizationResponse({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class CredentialHandlerLDLocal implements IAgentPlugin {
verifyCredentialLDLocal: this.verifyCredentialLDLocal.bind(this),
}
private keyStore?: AbstractPrivateKeyStore

constructor(options: {
contextMaps: RecordLike<OrPromise<ContextDoc>>[]
suites: SphereonLdSignature[]
Expand Down Expand Up @@ -127,7 +128,7 @@ export class CredentialHandlerLDLocal implements IAgentPlugin {
...identifier.keys.find((k) => k.kid === keyRef),
privateKeyHex: k.privateKeyHex as string,
} as IKey
verificationMethod = `${identifier.did}#${identifier.did.substring(8)}`
verificationMethod = `${identifier.did}#${managedKey.kid ? managedKey.kid : k.alias}`
}
}
return { managedKey, verificationMethod }
Expand Down Expand Up @@ -183,8 +184,8 @@ export class CredentialHandlerLDLocal implements IAgentPlugin {
return await this.ldCredentialModule.signLDVerifiablePresentation(
presentation,
identifier.did,
managedKey || signingKey,
managedKey ? (verificationMethod as string) : verificationMethodId,
signingKey || managedKey,
verificationMethodId ? verificationMethodId : (verificationMethod as string),
args.challenge,
args.domain,
args.purpose,
Expand Down
15 changes: 9 additions & 6 deletions packages/vc-handler-ld-local/src/suites/JsonWebSignature2020.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ export class SphereonJsonWebSignature2020 extends SphereonLdSignature {
x: u8a.toString(u8a.fromString(key.publicKeyHex, 'hex'), 'base64url'),
}

const verificationKey = await JsonWebKey.from({
id: id,
type: this.getSupportedVerificationType(),
controller: controller,
publicKeyJwk,
}, {signer, verifier: false})
const verificationKey = await JsonWebKey.from(
{
id: id,
type: this.getSupportedVerificationType(),
controller: controller,
publicKeyJwk,
},
{ signer, verifier: false }
)

// verificationKey.signer = () => signer

Expand Down
Loading

0 comments on commit c508507

Please sign in to comment.