Skip to content

Commit

Permalink
Merge pull request #92 from blockchain-certificates/fix/update-esm-di…
Browse files Browse the repository at this point in the history
…stri

fix(ESM): expose entry points for esm and cjs
  • Loading branch information
lemoustachiste authored May 24, 2024
2 parents 447a57d + f92ffe9 commit 8ffcf83
Show file tree
Hide file tree
Showing 26 changed files with 5,125 additions and 15,648 deletions.
12 changes: 0 additions & 12 deletions jest.config.js

This file was deleted.

20,608 changes: 5,055 additions & 15,553 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"name": "jsonld-signatures-merkleproof2019",
"version": "0.0.0-dev",
"description": "A jsonld signature implementation to support MerkleProof2019 verification in Verifiable Credential context",
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
"exports": {
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"typings": "lib/index.d.ts",
"dependencies": {
"@blockcerts/explorer-lookup": "^1.5.1",
"@blockcerts/schemas": "^3.6.2",
"@blockcerts/explorer-lookup": "^1.5.2",
"@blockcerts/schemas": "^3.6.4",
"@trust/keyto": "^1.0.1",
"@vaultie/lds-merkle-proof-2019": "^0.0.12",
"bitcoinjs-lib": "^6.0.2",
Expand All @@ -27,7 +29,6 @@
"@digitalbazaar/vc": "^6.2.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@types/jest": "^29.5.8",
"@types/node": "^20.9.0",
"@types/sinon": "^17.0.1",
"@typescript-eslint/eslint-plugin": "^6.10.0",
Expand All @@ -41,24 +42,23 @@
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-standard": "^5.0.0",
"husky": "^8.0.3",
"jest": "^29.7.0",
"node-eval": "^2.0.0",
"node-fetch": "^3.2.10",
"rimraf": "^5.0.5",
"rollup": "^4.3.0",
"semantic-release": "^22.0.7",
"sinon": "^17.0.1",
"ts-jest": "^29.1.1",
"tslib": "^2.6.2",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"vitest": "^1.6.0"
},
"scripts": {
"compile": "npm run clean:build && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && npm run dts:bundle",
"dts:bundle": "dts-bundle-generator -o ./lib/index.d.ts --project tsconfig.json --no-banner src/index.ts",
"clean:build": "rimraf lib",
"lint": "eslint . --ext .ts",
"test": "jest",
"test:watch": "jest --watch",
"test": "vitest run",
"test:watch": "vitest",
"semantic-release": "semantic-release",
"prepare": "husky install"
},
Expand Down
24 changes: 13 additions & 11 deletions tests/MerkleProof2019.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, it, expect, beforeEach, afterEach, beforeAll, afterAll, vi } from 'vitest';
import sinon from 'sinon';
import * as explorerLookup from '@blockcerts/explorer-lookup';
import type * as explorerLookup from '@blockcerts/explorer-lookup';
import { LDMerkleProof2019, type MerkleProof2019Options, type MerkleProof2019VerificationResult } from '../src';
import decodedProof, { assertionTransactionId } from './assertions/proof';
import { BLOCKCHAINS } from '@blockcerts/explorer-lookup';
Expand Down Expand Up @@ -30,14 +31,10 @@ describe('MerkleProof2019 test suite', function () {
describe('given a MerkleProof2019 signed document is passed', function () {
let instance;

beforeEach(function () {
beforeAll(function () {
instance = new LDMerkleProof2019({ document: blockcertsV3Fixture });
});

afterEach(function () {
instance = null;
});

it('registers the type of the proof', function () {
expect(instance.type).toBe('MerkleProof2019');
});
Expand Down Expand Up @@ -76,14 +73,19 @@ describe('MerkleProof2019 test suite', function () {
describe('when the process is successful', function () {
let result: MerkleProof2019VerificationResult;

beforeEach(async function () {
sinon.stub(explorerLookup, 'lookForTx').resolves(fixtureTransactionData);
beforeAll(async function () {
vi.mock('@blockcerts/explorer-lookup', async (importOriginal) => {
const explorerLookup = await importOriginal();
return {
...explorerLookup,
lookForTx: () => fixtureTransactionData
};
});
result = await instance.verifyProof();
});

afterEach(function () {
sinon.restore();
result = null;
afterAll(function () {
vi.restoreAllMocks();
});

it('should retrieve the transaction id', function () {
Expand Down
28 changes: 0 additions & 28 deletions tests/contract/helpers/precompileEsmModuleToCjs.ts

This file was deleted.

15 changes: 2 additions & 13 deletions tests/contract/vc.js.contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { describe, it, expect } from 'vitest';
import { preloadedContexts } from '@blockcerts/schemas';
import jsonld from 'jsonld';
import { Headers } from 'node-fetch';
import { LDMerkleProof2019 } from '../../src';
import blockcertsDocument from '../fixtures/testnet-v3-did';
import * as vcjs from '@digitalbazaar/vc';
// import { vaultiePresentation } from '../fixtures/vaultie-authenticity-report';
import didDocument from '../fixtures/did:ion:EiA_Z6LQILbB2zj_eVrqfQ2xDm4HNqeJUw5Kj2Z7bFOOeQ.json';
import precompileEsmModuleToCjs from './helpers/precompileEsmModuleToCjs';

function generateDocumentLoader (): any {
preloadedContexts[blockcertsDocument.issuer.id] = didDocument;
Expand All @@ -23,17 +23,6 @@ function generateDocumentLoader (): any {
}

describe('Contract test suite', function () {
let vcjs;

beforeAll(async function () {
// jest requirement to prevent ESM issues
vcjs = await precompileEsmModuleToCjs('node_modules/@digitalbazaar/vc/lib/index.js', {
globalThis: {
Headers
}
});
}, 60000);

describe('vc.js compatibility', function () {
it('should verify a MerkleProof2019 signed document', async function () {
const suite = [new LDMerkleProof2019({
Expand Down
1 change: 1 addition & 0 deletions tests/helpers/getChain.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { BLOCKCHAINS } from '@blockcerts/explorer-lookup';
import getChain from '../../src/helpers/getChain';
import { type DecodedProof } from '../../src/models/Proof';
Expand Down
1 change: 1 addition & 0 deletions tests/helpers/getTransactionId.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import getTransactionId from '../../src/helpers/getTransactionId';
import decodedProof, { assertionTransactionId } from '../assertions/proof';

Expand Down
1 change: 1 addition & 0 deletions tests/helpers/isMockChain.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import isMockChain from '../../src/helpers/isMockChain';
import { BLOCKCHAINS } from '@blockcerts/explorer-lookup';

Expand Down
1 change: 1 addition & 0 deletions tests/inspectors/compareIssuingAddress.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { compareIssuingAddress } from '../../src/inspectors';

describe('compareIssuingAddress inspector test suite', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/inspectors/computeLocalHash.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import sinon from 'sinon';
import jsonld from 'jsonld';
import JsonLdError from 'jsonld/lib/JsonLdError';
Expand Down
5 changes: 5 additions & 0 deletions tests/inspectors/deriveIssuingAddressFromPublicKey.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import type { IDidDocumentPublicKey } from '@decentralized-identity/did-common-typescript';
import didDocument from '../fixtures/did:ion:EiA_Z6LQILbB2zj_eVrqfQ2xDm4HNqeJUw5Kj2Z7bFOOeQ.json';
import { BLOCKCHAINS } from '@blockcerts/explorer-lookup';
Expand All @@ -10,6 +11,10 @@ describe('deriveIssuingAddressFromPublicKey test suite', function () {
publicKey = Object.assign({}, didDocument.verificationMethod[0]);
});

afterEach(function () {
publicKey = null;
});

describe('given the argument chain was Bitcoin', function () {
it('should return the address of Bitcoin Mainnet', function () {
const address = deriveIssuingAddressFromPublicKey(publicKey, BLOCKCHAINS.bitcoin);
Expand Down
1 change: 1 addition & 0 deletions tests/inspectors/ensureHashesEqual.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import ensureHashesEqual from '../../src/inspectors/ensureHashesEqual';

describe('Inspectors test suite', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/inspectors/ensureMerkleRootEqual.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import ensureMerkleRootEqual from '../../src/inspectors/ensureMerkleRootEqual';

describe('Inspectors test suite', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/inspectors/isTransactionIdValid.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import isTransactionIdValid from '../../src/inspectors/isTransactionIdValid';

describe('Inspectors test suite', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/utils/data.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { toUTF8Data } from '../../src/utils/data';

describe('toUTF8Data method', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/utils/date.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { dateToUnixTimestamp, timestampToDateObject } from '../../src/utils/date';

describe('dateToUnixTimestamp method', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/utils/ensureExplorerAPIValidity.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { type ExplorerAPI, type TransactionData } from '@blockcerts/explorer-lookup';
import ensureExplorerAPIValidity from '../../src/utils/ensureExplorerAPIValidity';

Expand Down
1 change: 1 addition & 0 deletions tests/utils/prependHashPrefix.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { prependHashPrefix } from '../../src/utils/prependHashPrefix';

describe('explorers utils cleanupRemoteHash test suite', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/utils/string.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { capitalize, startsWith } from '../../src/utils/string';

describe('startsWith method', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/utils/stripHashPrefix.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { stripHashPrefix } from '../../src/utils/stripHashPrefix';

describe('explorers utils cleanupRemoteHash test suite', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/utils/url.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { safelyAppendUrlParameter } from '../../src/utils/url';

describe('safelyAppendUrlParameter method', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/verification/data-integrity-proof-support.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import fixture from '../fixtures/mocknet-vc-v2-data-integrity-proof.json';
import { LDMerkleProof2019 } from '../../src';

Expand Down
20 changes: 13 additions & 7 deletions tests/verification/ethereum-sepolia-v3.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { describe, it, expect, vi } from 'vitest';
import fixture from '../fixtures/ethereum-sepolia-v3';
import { LDMerkleProof2019 } from '../../src';
import sinon from 'sinon';
import * as explorerLookup from '@blockcerts/explorer-lookup';

describe('Given the anchoring chain is Ethereum Sepolia', function () {
describe('when the certificate is valid', function () {
it('should verify successfully', async function () {
sinon.stub(explorerLookup, 'lookForTx').resolves({
remoteHash: 'b2c64ed78cccda992431c265a1d0bb657e8cefd14b1ef15ceadcc697c566994f',
issuingAddress: '0x40cf9b7db6fcc742ad0a76b8588c7f8de2b54a60',
time: '2022-11-02T02:33:24.000Z',
revokedAddresses: []
vi.mock('@blockcerts/explorer-lookup', async (importOriginal) => {
const explorerLookup = await importOriginal();
return {
...explorerLookup,
lookForTx: () => ({
remoteHash: 'b2c64ed78cccda992431c265a1d0bb657e8cefd14b1ef15ceadcc697c566994f',
issuingAddress: '0x40cf9b7db6fcc742ad0a76b8588c7f8de2b54a60',
time: '2022-11-02T02:33:24.000Z',
revokedAddresses: []
})
};
});
const instance = new LDMerkleProof2019({ document: fixture });
const result = await instance.verifyProof();
Expand All @@ -19,6 +24,7 @@ describe('Given the anchoring chain is Ethereum Sepolia', function () {
verificationMethod: null,
error: ''
});
vi.restoreAllMocks();
});
});
});
24 changes: 10 additions & 14 deletions tests/verification/failing-altered-document.test.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
import sinon from 'sinon';
import * as explorerLookup from '@blockcerts/explorer-lookup';
import { describe, it, expect, vi } from 'vitest';
import alteredBlockcertsV3Fixture from '../fixtures/altered-blockcerts-v3';
import { LDMerkleProof2019, type MerkleProof2019VerificationResult } from '../../src';
import fixtureTransactionData from '../fixtures/transactionData';

describe('when the process fails', function () {
let instance;

beforeEach(function () {
instance = new LDMerkleProof2019({ document: alteredBlockcertsV3Fixture });
sinon.stub(explorerLookup, 'lookForTx').resolves(fixtureTransactionData);
});

afterEach(function () {
instance = null;
sinon.restore();
});

describe('given the local hash does not match the remote hash', function () {
it('should return the error', async function () {
vi.mock('@blockcerts/explorer-lookup', async (importOriginal) => {
const explorerLookup = await importOriginal();
return {
...explorerLookup,
lookForTx: () => fixtureTransactionData
};
});
const instance = new LDMerkleProof2019({ document: alteredBlockcertsV3Fixture });
const result: MerkleProof2019VerificationResult = await instance.verifyProof();
expect(result).toEqual({
verified: false,
verificationMethod: null,
error: 'Computed hash does not match remote hash'
});
vi.restoreAllMocks();
});
});
});
1 change: 1 addition & 0 deletions tests/verification/mocknet-v3.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import fixture from '../fixtures/mocknet-v3';
import { LDMerkleProof2019 } from '../../src';

Expand Down

0 comments on commit 8ffcf83

Please sign in to comment.