Skip to content

Extract CVCMerkleProof from the VC creation #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 52 additions & 11 deletions __integrations__/credentials/VerifiableCredential.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
const uuidv4 = require('uuid/v4');
const { Claim } = require('claim/Claim');
const VC = require('creds/VerifiableCredential');
const { schemaLoader, CVCSchemaLoader } = require('index');
const didTestUtil = require("../../__test__/lib/util/did");

const solResolver = require('lib/did');
const {VerifiableCredential} = require('vc/VerifiableCredential')
const CvcMerkleProof = require('proof/CvcMerkleProof').default;
const {Ed25519SignerVerifier} = require("proof/CvcMerkleProof/Ed25519SignerVerifier");

const credentialSubject = 'did:sol:J2vss1hB3kgEfQMSSdvvjwRm3JdyFWp7S7dbX5mudS4V';


const cvcMerkleProof = new CvcMerkleProof(new Ed25519SignerVerifier(
solResolver,
`${didTestUtil.DID_CONTROLLER}#default`,
didTestUtil.keyPair(didTestUtil.DID_CONTROLLER)));

jest.setTimeout(200000);

describe('Integration Tests for Verifiable Credentials', () => {
Expand All @@ -21,8 +32,18 @@ describe('Integration Tests for Verifiable Credentials', () => {
{ givenNames: 'Joao', otherNames: 'Barbosa', familyNames: 'Santos' });

const dob = await Claim.create('claim-cvc:Identity.dateOfBirth-v1', { day: 20, month: 3, year: 1978 });
const cred = await VC.create('credential-cvc:Identity-v3', uuidv4(), null, credentialSubject, [name, dob]);
return cred.requestAnchor().then((updated) => {

const unsignedCred = await VerifiableCredential.create({
issuer: didTestUtil.DID_CONTROLLER,
identifier: 'credential-cvc:Identity-v3',
subject: credentialSubject,
claims: [name, dob],
expiry: null,
});
Comment on lines +36 to +42
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, if we're copying large blocks of boilerplate code over and over, we need to please refactor it into a single location.


const cred = await cvcMerkleProof.sign(unsignedCred);

return CvcMerkleProof.requestAnchor(cred).then((updated) => {
expect(updated.proof.anchor.type).toBe('temporary');
expect(updated.proof.anchor.value).not.toBeDefined();
expect(updated.proof.anchor).toBeDefined();
Expand All @@ -36,10 +57,20 @@ describe('Integration Tests for Verifiable Credentials', () => {
{ givenNames: 'Joao', otherNames: 'Barbosa', familyNames: 'Santos' });

const dob = await Claim.create('claim-cvc:Identity.dateOfBirth-v1', { day: 20, month: 3, year: 1978 });
const cred = await VC.create('credential-cvc:Identity-v3', uuidv4(), null, credentialSubject, [name, dob]);
return cred.requestAnchor().then((updated) => {

const unsignedCred = await VerifiableCredential.create({
issuer: didTestUtil.DID_CONTROLLER,
identifier: 'credential-cvc:Identity-v3',
subject: credentialSubject,
claims: [name, dob],
expiry: null,
});

const cred = await cvcMerkleProof.sign(unsignedCred);

return CvcMerkleProof.requestAnchor(cred).then((updated) => {
expect(updated.proof.anchor).toBeDefined();
return updated.updateAnchor().then((newUpdated) => {
return CvcMerkleProof.updateAnchor(updated).then((newUpdated) => {
expect(newUpdated.proof.anchor.type).toBe('permanent');
expect(newUpdated.proof.anchor).toBeDefined();
expect(newUpdated.proof.anchor.value).toBeDefined();
Expand All @@ -52,12 +83,22 @@ describe('Integration Tests for Verifiable Credentials', () => {
{ givenNames: 'Joao', otherNames: 'Barbosa', familyNames: 'Santos' });

const dob = await Claim.create('claim-cvc:Identity.dateOfBirth-v1', { day: 20, month: 3, year: 1978 });
const cred = await VC.create('credential-cvc:Identity-v3', uuidv4(), null, credentialSubject, [name, dob]);
await cred.requestAnchor();
await cred.updateAnchor();
const validation = await cred.verifyAttestation();

const unsignedCred = await VerifiableCredential.create({
issuer: didTestUtil.DID_CONTROLLER,
identifier: 'credential-cvc:Identity-v3',
subject: credentialSubject,
claims: [name, dob],
expiry: null,
});

const cred = await cvcMerkleProof.sign(unsignedCred);

await CvcMerkleProof.requestAnchor(cred);
await CvcMerkleProof.updateAnchor(cred);
const validation = await CvcMerkleProof.verifyAttestation(cred);
if (validation) {
const isRevoked = await cred.revokeAttestation();
const isRevoked = await CvcMerkleProof.revokeAttestation(cred);
expect(isRevoked).toBeTruthy();
}
done();
Expand Down
Loading