Skip to content
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

fix: commonJs default export #339

Merged
merged 1 commit into from
Nov 26, 2024
Merged
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
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ jobs:
working-directory: integration-tests/node/esm
run: npm i && node test.mjs

- name: Test integration ts-cjs
working-directory: integration-tests/node/ts-cjs
run: npm i && npm run build && npm t

- name: Test integration ts-esm
working-directory: integration-tests/node/ts-esm
run: npm i && npm run build && npm t

- name: Npm audit
uses: oke-py/[email protected]
with:
Expand Down
7 changes: 6 additions & 1 deletion index.cjs
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
module.exports = require('./build/index.js')
const sdk = require('./build/index.js')
// patch default for builders expecting it downstream
module.exports = {
...sdk,
default: sdk.default ?? sdk
};
190 changes: 190 additions & 0 deletions integration-tests/node/assertions.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
const runTests = (describe, test, assert, SDK) => {
test('Top level exports', () => {
assert(typeof SDK === "object");

// modules
assert("Agent" in SDK);
assert("Apollo" in SDK);
assert("Castor" in SDK);
assert("Domain" in SDK);
assert("Mercury" in SDK);
assert("Pluto" in SDK);
assert("Pollux" in SDK);

// misc modules
assert("ApiImpl" in SDK);
assert("BasicMediatorHandler" in SDK);
assert("ConnectionsManager" in SDK);
assert("PublicMediatorStore" in SDK);

// credentials
assert("AnonCredsCredential" in SDK);
assert("AnonCredsCredentialProperties" in SDK);
assert("AnonCredsRecoveryId" in SDK);

assert("JWTCredential" in SDK);
assert("JWTVerifiableCredentialRecoveryId" in SDK);

assert("SDJWTCredential" in SDK);
assert("SDJWTVerifiableCredentialRecoveryId" in SDK);

// keys
assert("Ed25519KeyPair" in SDK);
assert("Ed25519PrivateKey" in SDK);
assert("Ed25519PublicKey" in SDK);
assert("Secp256k1KeyPair" in SDK);
assert("Secp256k1PrivateKey" in SDK);
assert("Secp256k1PublicKey" in SDK);
assert("X25519KeyPair" in SDK);
assert("X25519PrivateKey" in SDK);
assert("X25519PublicKey" in SDK);
assert("KeyProperties" in SDK);

// DIDComm
assert("ProtocolType" in SDK);
assert("BasicMessage" in SDK);
assert("DIDCommWrapper" in SDK);
assert("HandshakeRequest" in SDK);
assert("IssueCredential" in SDK);
assert("OfferCredential" in SDK);
assert("OutOfBandInvitation" in SDK);
assert("Presentation" in SDK);
assert("ProposePresentation" in SDK);
assert("RequestPresentation" in SDK);

// OIDC
assert("OIDC" in SDK);
assert("OIDCAgent" in SDK);

assert("ListenerKey" in SDK);

// ?? should be in Castor
assert("PeerDID" in SDK);
assert("PeerDIDService" in SDK);

// ?? should be in Pluto
assert("Store" in SDK);

// ?? shouldnt be exported
assert("isPresentationDefinitionRequestType" in SDK);
});

describe("Modules", () => {
describe("Apollo", () => {
test("instantiates", async () => {
const apollo = new SDK.Apollo();
assert(apollo instanceof SDK.Apollo);
assert(apollo.createRandomMnemonics instanceof Function);
assert(apollo.createSeed instanceof Function);
assert(apollo.createRandomSeed instanceof Function);
assert(apollo.createPrivateKey instanceof Function);
assert(apollo.createPublicKey instanceof Function);
});
});

describe("Castor", () => {
test("instantiates", async () => {
const apollo = new SDK.Apollo();
const castor = new SDK.Castor(apollo);
assert(castor instanceof SDK.Castor);
assert(castor.parseDID instanceof Function);
assert(castor.createPrismDID instanceof Function);
assert(castor.createPeerDID instanceof Function);
assert(castor.resolveDID instanceof Function);
assert(castor.verifySignature instanceof Function);
assert(castor.getEcnumbasis instanceof Function);
});
});

describe("Mercury", () => {
test("instantiates", async () => {
const apollo = new SDK.Apollo();
const castor = new SDK.Castor(apollo);
const httpManager = {};
const protocol = { unpack: () => 123 };
const mercury = new SDK.Mercury(castor, protocol, httpManager);
assert(mercury instanceof SDK.Mercury);
assert(mercury.packMessage instanceof Function);
assert(mercury.unpackMessage instanceof Function);
assert(mercury.sendMessage instanceof Function);
assert(mercury.sendMessageParseMessage instanceof Function);
});
});

describe("Pluto", () => {
test("instantiates", async () => {
const apollo = new SDK.Apollo();
const store = { insert: () => { } }
const pluto = new SDK.Pluto(store, apollo);
assert(pluto instanceof SDK.Pluto);
assert(pluto.backup instanceof Function);
assert(pluto.restore instanceof Function);
assert(pluto.storeDID instanceof Function);
assert(pluto.storeMessage instanceof Function);
assert(pluto.storeMediator instanceof Function);
assert(pluto.storeCredential instanceof Function);
});
});

describe("Pollux", () => {
test("instantiates", async () => {
const apollo = new SDK.Apollo();
const castor = new SDK.Castor(apollo);
const pollux = new SDK.Pollux(apollo, castor);
assert(pollux instanceof SDK.Pollux);
assert(pollux.revealCredentialFields instanceof Function);
assert(pollux.isCredentialRevoked instanceof Function);
assert(pollux.parseCredential instanceof Function);
assert(pollux.processCredentialOffer instanceof Function);
assert(pollux.createPresentationSubmission instanceof Function);
assert(pollux.verifyPresentationSubmission instanceof Function);
assert(pollux.createPresentationDefinitionRequest instanceof Function);
});
});
});

test("Agent starts", async () => {
const apollo = new SDK.Apollo();
const castor = new SDK.Castor(apollo);
const mockApi = {
request: async () => new SDK.Domain.ApiResponse(new Uint8Array(), 200)
};
const mockProtocol = {
packEncrypted: async () => "",
unpack: async () => new SDK.Domain.Message("{}", undefined, "TypeofMessage"),
};
const mercury = new SDK.Mercury(castor, mockProtocol, mockApi);
const seed = {
value: new Uint8Array([69, 191, 35, 232, 213, 102, 3, 93, 180, 106, 224, 144, 79, 171, 79, 223, 154, 217, 235, 232, 96, 30, 248, 92, 100, 38, 38, 42, 101, 53, 2, 247, 56, 111, 148, 220, 237, 122, 15, 120, 55, 82, 89, 150, 35, 45, 123, 135, 159, 140, 52, 127, 239, 148, 150, 109, 86, 145, 77, 109, 47, 60, 20, 16])
};
const store = {
query: () => ([]),
insert: () => { }
};
const pluto = new SDK.Pluto(store, apollo);
const did = SDK.Domain.DID.from("did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6Imh0dHA6Ly8xOTIuMTY4LjEuNDQ6ODA4MCIsImEiOlsiZGlkY29tbS92MiJdfX0.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6IndzOi8vMTkyLjE2OC4xLjQ0OjgwODAvd3MiLCJhIjpbImRpZGNvbW0vdjIiXX19");
const agent = SDK.Agent.initialize({
mediatorDID: did,
apollo,
castor,
pluto,
mercury,
seed,
});

// hack to avoid mediation startup
agent.connectionManager.cancellable = { cancel: () => { } };
agent.mediationHandler.mediator = {
hostDID: did,
mediatorDID: did,
routingDID: did,
};

await agent.start();
assert(agent.state === "running");
await agent.stop();
assert(agent.state === "stopped");
});
}

module.exports = { default: runTests, runTests };
143 changes: 0 additions & 143 deletions integration-tests/node/cjs/package-lock.json

This file was deleted.

4 changes: 4 additions & 0 deletions integration-tests/node/cjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"name": "@identus-edge-agent-sdk/integration-tests-cjs",
"version": "0.0.0",
"private": true,
"type": "commonjs",
"scripts": {
"test": "node ./test.cjs"
},
"devDependencies": {
"sdk": "file:../../../"
},
Expand Down
Loading
Loading