Skip to content
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
4 changes: 1 addition & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
defaults: &defaults
working_directory: ~/repo
docker:
- image: circleci/node:12.19.0
- image: cimg/node:lts

workflows:
version: 2
Expand Down Expand Up @@ -56,7 +56,6 @@ jobs:
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}-{{checksum "package-lock.json"}}
- run: sudo npm install -g npm@6.14.13
- run: npm ci
- save_cache:
paths:
Expand All @@ -82,7 +81,6 @@ jobs:
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}-{{checksum "package-lock.json"}}
- run: sudo npm install -g npm@6.14.13
- run: |
sh ./.circleci/install_hub.sh
mkdir -p ~/.config/ && echo -e "github.com:\n- user: civictechuser\n oauth_token: $GITHUB_API_KEY\n protocol: https\n" > ~/.config/hub
Expand Down
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "airbnb-base",
"extends": [
"airbnb-base",
"plugin:prettier/recommended"
],
"env": {
"browser": true,
"commonjs": true,
Expand Down
13 changes: 6 additions & 7 deletions AUDIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ Whenever you whitelist a specific advisory it is required to refer it to here an

### Advisories

| # | Level | Module | Title | Explanation |
|------|-------|---------|------|-------------|
| 565 | Moderate | npm>ssri | Regular Expression Denial of Service | dev dependency only |
| 786 | Low | babel-cli > chokidar > anymatch > micromatch > braces | Regular Expression Denial of Service | dev dependency only |
| 1500 | Low | babel-minify>yargs-parser | Prototype Pollution | dev dependency only |
| 1654 | Moderate | npm>libnpx>y18n | Regular Expression Denial of Service | dev dependency only |
| 1677 | Moderate | npm>hosted-git-info | Regular Expression Denial of Service | dev dependency only |
| # | Level | Module | Title | Explanation |
|---------------------|----------|--------------|-----------------------------|---------------------------------------------------------------------------------------------------------------------------------|
| GHSA-2j2x-2gpw-g8fm | critical | flat | Prototype Pollution | Flat is on an old version. The new version is an ESM and can be used once the bundler is updated to support ESM rather than CJS |
| GHSA-p8p7-x288-28g6 | moderate | request | Server-Side Request Forgery | Request is deprecated and should be replaced with Axios or Fetch |
| GHSA-72xf-g2v4-qvf3 | moderate | tough-cookie | Prototype Pollution | Used in 'request', which is deprecated and should be replaced with Axios or Fetch |
| GHSA-p9pc-299p-vxgp | moderate | yargs-parser | Prototype Pollution | Used in dev dependencies only |
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,19 @@ const ccc = new CCC({

```

If you are not sure how to get those informations, see the tutorial down below.
If you are not sure how to get this information, see the tutorial down below.

## NOTE

This library requires a DID resolver to be passed in as follows:

```js
const resolver = async (did) => {
const document = // retrieve from the blockchain or other source
return document;
}
VC.setResolver(resolver);
```

## Features

Expand Down
114 changes: 74 additions & 40 deletions __integrations__/credentials/VerifiableCredential.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const uuidv4 = require('uuid/v4');
const { Claim } = require('../../src/claim/Claim');
const VC = require('../../src/creds/VerifiableCredential');
const { schemaLoader, CVCSchemaLoader } = require('../../src');
const { v4: uuidv4 } = require("uuid");
const { Claim } = require("../../src/claim/Claim");
const VC = require("../../src/creds/VerifiableCredential");
const { schemaLoader, CVCSchemaLoader } = require("../../src");

const credentialSubject = 'did:sol:J2vss1hB3kgEfQMSSdvvjwRm3JdyFWp7S7dbX5mudS4V';
const credentialSubject =
"did:sol:J2vss1hB3kgEfQMSSdvvjwRm3JdyFWp7S7dbX5mudS4V";

jest.setTimeout(200000);

describe('Integration Tests for Verifiable Credentials', () => {
describe("Integration Tests for Verifiable Credentials", () => {
beforeAll(() => {
schemaLoader.addLoader(new CVCSchemaLoader());
});
Expand All @@ -16,50 +17,83 @@ describe('Integration Tests for Verifiable Credentials', () => {
schemaLoader.reset();
});

it('should request an anchor for Credential and return an temporary attestation', async (done) => {
const name = await Claim.create('claim-cvc:Identity.name-v1',
{ givenNames: 'Joao', otherNames: 'Barbosa', familyNames: 'Santos' });
it("should request an anchor for Credential and return an temporary attestation", async () => {
const name = await Claim.create("claim-cvc:Identity.name-v1", {
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) => {
expect(updated.proof.anchor.type).toBe('temporary');
expect(updated.proof.anchor.value).not.toBeDefined();
expect(updated.proof.anchor).toBeDefined();
expect(updated.proof.anchor.schema).toBe('dummy-20180201');
done();
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],
);
const updated = await cred.requestAnchor();
expect(updated.proof.anchor.type).toBe("temporary");
expect(updated.proof.anchor.value).not.toBeDefined();
expect(updated.proof.anchor).toBeDefined();
expect(updated.proof.anchor.schema).toBe("dummy-20180201");
});

it('should refresh an temporary anchoring with an permanent one', async (done) => {
const name = await Claim.create('claim-cvc:Identity.name-v1',
{ givenNames: 'Joao', otherNames: 'Barbosa', familyNames: 'Santos' });
it("should refresh an temporary anchoring with an permanent one", async () => {
const name = await Claim.create("claim-cvc:Identity.name-v1", {
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) => {
expect(updated.proof.anchor).toBeDefined();
return updated.updateAnchor().then((newUpdated) => {
expect(newUpdated.proof.anchor.type).toBe('permanent');
expect(newUpdated.proof.anchor).toBeDefined();
expect(newUpdated.proof.anchor.value).toBeDefined();
done();
});
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],
);
const updated = await cred.requestAnchor();
expect(updated.proof.anchor).toBeDefined();
const newUpdated = await updated.updateAnchor();
expect(newUpdated.proof.anchor.type).toBe("permanent");
expect(newUpdated.proof.anchor).toBeDefined();
expect(newUpdated.proof.anchor.value).toBeDefined();
});
it('should revoke the permanent anchor and succed verification', async (done) => {
const name = await Claim.create('claim-cvc:Identity.name-v1',
{ 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]);
it("should revoke the permanent anchor and succeed verification", async () => {
const name = await Claim.create("claim-cvc:Identity.name-v1", {
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();
if (validation) {
const isRevoked = await cred.revokeAttestation();
expect(isRevoked).toBeTruthy();
}
done();
expect(validation).toBeTruthy();
const isRevoked = await cred.revokeAttestation();
expect(isRevoked).toBeTruthy();
});
});
Loading