Skip to content

Commit

Permalink
fix(credential-ld): external context handling with the `fetchRemoteCo…
Browse files Browse the repository at this point in the history
…ntexts` option (#1149)
  • Loading branch information
simonas-notcat authored Mar 17, 2023
1 parent 8bc375a commit 4a63f40
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
32 changes: 32 additions & 0 deletions __tests__/shared/verifiableDataLD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,38 @@ export default (testContext: {
expect(verifiableCredential).toEqual(verifiableCredential2)
})

it('should create verifiable credential with external context', async () => {
const credential = await agent.createVerifiableCredential({
credential: {
issuer: { id: pkhIdentifier.did },
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://veramo.io/contexts/discord-kudos/v1'
],
type: ['VerifiableCredential', 'DiscordKudos'],
issuanceDate: new Date().toISOString(),
credentialSubject: {
id: pkhIdentifier.did,
kudos: 'Thank you',
},
},
proofFormat: 'lds',
fetchRemoteContexts: true,
})

// Check credential:
expect(credential).toHaveProperty('proof')
expect(credential).toHaveProperty('proof.jws')
expect(credential['type']).toEqual(['VerifiableCredential', 'DiscordKudos'])

const result = await agent.verifyCredential({
credential,
fetchRemoteContexts: true
})
expect(result.verified).toBe(true)

})

describe('credential verification policies', () => {
it('can verify credential at a particular time', async () => {
const issuanceDate = '2019-08-19T09:15:20.000Z' // 1566206120
Expand Down
8 changes: 4 additions & 4 deletions packages/credential-ld/src/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
IVerifyPresentationLDArgs,
} from './types.js'

const debug = Debug('veramo:w3c:action-handler')
const debug = Debug('veramo:credential-ld:action-handler')

/**
* A Veramo plugin that implements the {@link ICredentialIssuerLD} methods.
Expand Down Expand Up @@ -176,7 +176,7 @@ export class CredentialIssuerLD implements IAgentPlugin {
identifier.did,
signingKey,
verificationMethodId,
{ ...args.options, now },
{ ...args, now },
context,
)
} catch (error) {
Expand All @@ -200,7 +200,7 @@ export class CredentialIssuerLD implements IAgentPlugin {
return this.ldCredentialModule.verifyCredential(
credential,
args.fetchRemoteContexts || false,
{ ...args.options, now },
{ ...args, now },
context,
)
}
Expand All @@ -220,7 +220,7 @@ export class CredentialIssuerLD implements IAgentPlugin {
args.challenge,
args.domain,
args.fetchRemoteContexts || false,
{ ...args.options, now },
{ ...args, now },
context,
)
}
Expand Down

0 comments on commit 4a63f40

Please sign in to comment.