Created
May 5, 2020 10:56
-
-
Save gjgd/8117bb3b2b3f1cbb79c170e5125b27bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const jsigs = require('jsonld-signatures'); | |
const vcjs = require('vc-js'); | |
const jsonld = require('jsonld'); | |
jest.setTimeout(10 * 1000); | |
const documentLoader = async url => { | |
if (url.split('#')[0] === 'did:web:vc.transmute.world') { | |
return { | |
contextUrl: null, | |
document: { | |
'@context': 'https://w3id.org/did/v0.11', | |
id: 'did:web:vc.transmute.world', | |
publicKey: [ | |
{ | |
id: | |
'did:web:vc.transmute.world#z6MksHh7qHWvybLg5QTPPdG2DgEjjduBDArV9EF9mRiRzMBN', | |
type: 'Ed25519VerificationKey2018', | |
controller: 'did:web:vc.transmute.world', | |
publicKeyBase58: 'DqS5F3GVe3rCxucgi4JBNagjv4dKoHc8TDLDw9kR58Pz', | |
}, | |
], | |
assertionMethod: [ | |
'did:web:vc.transmute.world#z6MksHh7qHWvybLg5QTPPdG2DgEjjduBDArV9EF9mRiRzMBN', | |
], | |
}, | |
documentUrl: url, | |
}; | |
} | |
const res = await jsonld.documentLoader(url); | |
return res; | |
}; | |
const { Ed25519Signature2018 } = jsigs.suites; | |
const credential = { | |
'@context': ['https://www.w3.org/2018/credentials/v1'], | |
id: 'http://example.com/credentials/123', | |
type: ['VerifiableCredential'], | |
issuer: 'did:web:vc.transmute.world', | |
issuanceDate: '2020-03-09T18:19:10.033Z', | |
credentialSubject: {}, | |
proof: { | |
type: 'Ed25519Signature2018', | |
created: '2019-12-11T03:50:55Z', | |
verificationMethod: | |
'did:web:vc.transmute.world#z6MksHh7qHWvybLg5QTPPdG2DgEjjduBDArV9EF9mRiRzMBN', | |
proofPurpose: 'assertionMethod', | |
jws: | |
'eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..PwEA-MOurqiHra5DdL4JdSksnVKVffzG77fBCRNLUTEoTzSuKwTmNcleULTDpjodVTWcRg2GWTaHTrIxqvuYDg', | |
}, | |
}; | |
describe('Show bug', () => { | |
it('should verify the correct signature', async () => { | |
const suite = new Ed25519Signature2018(); | |
const result = await vcjs.verifyCredential({ | |
credential, | |
suite, | |
documentLoader, | |
}); | |
expect(result.verified).toBeTruthy(); | |
}); | |
it('should not verify the wrong signature', async () => { | |
const suite = new Ed25519Signature2018(); | |
credential.proof.jws += 'somenoiseattheendofthesignature'; | |
const result = await vcjs.verifyCredential({ | |
credential, | |
suite, | |
documentLoader, | |
}); | |
expect(result.verified).toBeFalsy(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment