diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4134d047c..ea75ce1b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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/npm-audit-action@v2.4.4 with: diff --git a/index.cjs b/index.cjs index 4d26afbfd..e05551d6a 100644 --- a/index.cjs +++ b/index.cjs @@ -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 +}; diff --git a/integration-tests/node/assertions.cjs b/integration-tests/node/assertions.cjs new file mode 100644 index 000000000..8b52a5973 --- /dev/null +++ b/integration-tests/node/assertions.cjs @@ -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 }; diff --git a/integration-tests/node/cjs/package-lock.json b/integration-tests/node/cjs/package-lock.json deleted file mode 100644 index 4a2ea6820..000000000 --- a/integration-tests/node/cjs/package-lock.json +++ /dev/null @@ -1,143 +0,0 @@ -{ - "name": "@identus-edge-agent-sdk/integration-tests-cjs", - "version": "0.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "@identus-edge-agent-sdk/integration-tests-cjs", - "version": "0.0.0", - "devDependencies": { - "sdk": "file:../../../" - }, - "engines": { - "node": ">=18" - } - }, - "../../..": { - "name": "@hyperledger/identus-edge-agent-sdk", - "version": "3.1.0", - "dev": true, - "hasInstallScript": true, - "license": "Apache-2.0", - "dependencies": { - "@hyperledger/identus-apollo": "^1.4.4", - "@noble/ciphers": "^0.6.0", - "@scure/bip32": "^1.3.0", - "@scure/bip39": "^1.1.1", - "@sd-jwt/sd-jwt-vc": "^0.7.1", - "@sinclair/typebox": "^0.32.31", - "@stablelib/base64": "^1.0.1", - "@stablelib/sha256": "^1.0.1", - "@stablelib/uuid": "^1.0.2", - "@stablelib/wipe": "^1.0.1", - "@stablelib/x25519": "^1.0.3", - "antlr4ts": "^0.5.0-alpha.4", - "assert": "^2.0.0", - "bn.js": "^5.2.1", - "buffer": "^6.0.3", - "did-jwt": "^8.0.4", - "did-resolver": "^4.1.0", - "elliptic": "^6.5.4", - "google-protobuf": "^3.21.2", - "hash.js": "1.1.7", - "isows": "^1.0.3", - "jose": "^4.15.5", - "jsonld": "^8.3.2", - "jsonwebtoken": "^9.0.0", - "multiformats": "^9.9.0", - "pako": "^2.1.0", - "patch-package": "^8.0.0", - "postinstall-postinstall": "^2.1.0", - "rxdb": "^14.17.1", - "rxjs": "^7.8.1", - "text-encoding": "^0.7.0", - "util": "^0.12.5", - "uuid": "^9.0.0" - }, - "devDependencies": { - "@babel/core": "^7.20.12", - "@babel/plugin-proposal-class-properties": "^7.16.0", - "@babel/plugin-proposal-decorators": "^7.21.0", - "@babel/plugin-transform-typescript": "^7.21.0", - "@babel/preset-env": "^7.20.2", - "@babel/preset-react": "^7.18.6", - "@babel/preset-typescript": "^7.21.0", - "@babel/traverse": "^7.23.2", - "@droppedcode/typedoc-plugin-relative-includes": "^1.0.5", - "@esbuild-plugins/node-resolve": "^0.2.2", - "@playwright/test": "^1.45.1", - "@pluto-encrypted/inmemory": "^1.12.3", - "@semantic-release/changelog": "^6.0.3", - "@semantic-release/commit-analyzer": "^9.0.2", - "@semantic-release/exec": "^6.0.3", - "@semantic-release/git": "^10.0.1", - "@semantic-release/release-notes-generator": "^10.0.3", - "@types/bn.js": "^5.1.3", - "@types/chai": "^4.3.4", - "@types/chai-as-promised": "^7.1.5", - "@types/elliptic": "^6.4.16", - "@types/google-protobuf": "^3.15.6", - "@types/jest": "^29.5.5", - "@types/jsonld": "^1.5.14", - "@types/node": "^18.14.2", - "@types/pako": "^2.0.3", - "@types/sinon": "^17.0.3", - "@types/sinon-chai": "^3.2.12", - "@types/uuid": "^9.0.1", - "@typescript-eslint/eslint-plugin": "^5.56.0", - "@typescript-eslint/parser": "^5.55.0", - "@vitest/browser": "^1.6.0", - "@vitest/coverage-istanbul": "^1.6.0", - "anoncreds-wasm": "./externals/generated/anoncreds-wasm", - "babel-plugin-transform-import-meta": "^2.2.0", - "babel-plugin-transform-typescript-metadata": "^0.3.2", - "chai": "^4.3.7", - "chai-as-promised": "^7.1.1", - "clean-webpack-plugin": "^4.0.0", - "copy-webpack-plugin": "^11.0.0", - "core-js": "^3.32.2", - "didcomm-wasm": "./externals/generated/didcomm-wasm", - "esbuild": "0.21.5", - "esbuild-plugin-wasm": "^1.1.0", - "esbuild-plugin-wasm-pack": "^1.1.0", - "eslint": "^8.36.0", - "eslint-config-react-app": "^7.0.1", - "eslint-config-standard-with-typescript": "^34.0.1", - "eslint-plugin-import": "^2.27.5", - "eslint-plugin-n": "^15.6.1", - "eslint-plugin-promise": "^6.1.1", - "eslint-plugin-react": "^7.32.2", - "eslint-plugin-unused-imports": "^2.0.0", - "get-func-name": "^3.0.0", - "husky": "^9.0.11", - "jest": "^29.5.0", - "jest-junit": "^16.0.0", - "jsdom": "^24.1.0", - "jwe-wasm": "./externals/generated/jwe-wasm", - "prettier": "^3.0.2", - "semantic-release": "^24.0.0", - "sinon": "^18.0.0", - "sinon-chai": "^3.7.0", - "typedoc": "^0.25.13", - "typedoc-plugin-external-module-map": "^1.3.2", - "typedoc-plugin-markdown": "^3.17.1", - "typedoc-plugin-rename-defaults": "^0.7.0", - "typescript": "^4.9.5", - "vite-plugin-swc-transform": "^1.0.1", - "vite-plugin-top-level-await": "^1.4.1", - "vite-plugin-wasm": "^3.3.0", - "vite-require": "^0.2.3", - "vitest": "^1.6.0", - "webdriverio": "^7.16.4" - }, - "optionalDependencies": { - "@rollup/rollup-linux-x64-gnu": "^4.24.0" - } - }, - "node_modules/sdk": { - "resolved": "../../..", - "link": true - } - } -} diff --git a/integration-tests/node/cjs/package.json b/integration-tests/node/cjs/package.json index 0d0548e5e..993ca0450 100644 --- a/integration-tests/node/cjs/package.json +++ b/integration-tests/node/cjs/package.json @@ -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:../../../" }, diff --git a/integration-tests/node/cjs/test.cjs b/integration-tests/node/cjs/test.cjs index 631274142..e0f5ec737 100644 --- a/integration-tests/node/cjs/test.cjs +++ b/integration-tests/node/cjs/test.cjs @@ -2,192 +2,8 @@ const { describe, test } = require('node:test'); const assert = require('node:assert'); const SDK = require("sdk"); +const assertions = require("../assertions.cjs"); describe('CommonJS Integration', () => { - 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"); - }); + assertions.runTests(describe, test, assert, SDK); }); diff --git a/integration-tests/node/esm/package-lock.json b/integration-tests/node/esm/package-lock.json deleted file mode 100644 index 3250eda2c..000000000 --- a/integration-tests/node/esm/package-lock.json +++ /dev/null @@ -1,143 +0,0 @@ -{ - "name": "@identus-edge-agent-sdk/integration-tests-esm", - "version": "0.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "@identus-edge-agent-sdk/integration-tests-esm", - "version": "0.0.0", - "devDependencies": { - "sdk": "file:../../../" - }, - "engines": { - "node": ">=18" - } - }, - "../../..": { - "name": "@hyperledger/identus-edge-agent-sdk", - "version": "3.1.0", - "dev": true, - "hasInstallScript": true, - "license": "Apache-2.0", - "dependencies": { - "@hyperledger/identus-apollo": "^1.4.4", - "@noble/ciphers": "^0.6.0", - "@scure/bip32": "^1.3.0", - "@scure/bip39": "^1.1.1", - "@sd-jwt/sd-jwt-vc": "^0.7.1", - "@sinclair/typebox": "^0.32.31", - "@stablelib/base64": "^1.0.1", - "@stablelib/sha256": "^1.0.1", - "@stablelib/uuid": "^1.0.2", - "@stablelib/wipe": "^1.0.1", - "@stablelib/x25519": "^1.0.3", - "antlr4ts": "^0.5.0-alpha.4", - "assert": "^2.0.0", - "bn.js": "^5.2.1", - "buffer": "^6.0.3", - "did-jwt": "^8.0.4", - "did-resolver": "^4.1.0", - "elliptic": "^6.5.4", - "google-protobuf": "^3.21.2", - "hash.js": "1.1.7", - "isows": "^1.0.3", - "jose": "^4.15.5", - "jsonld": "^8.3.2", - "jsonwebtoken": "^9.0.0", - "multiformats": "^9.9.0", - "pako": "^2.1.0", - "patch-package": "^8.0.0", - "postinstall-postinstall": "^2.1.0", - "rxdb": "^14.17.1", - "rxjs": "^7.8.1", - "text-encoding": "^0.7.0", - "util": "^0.12.5", - "uuid": "^9.0.0" - }, - "devDependencies": { - "@babel/core": "^7.20.12", - "@babel/plugin-proposal-class-properties": "^7.16.0", - "@babel/plugin-proposal-decorators": "^7.21.0", - "@babel/plugin-transform-typescript": "^7.21.0", - "@babel/preset-env": "^7.20.2", - "@babel/preset-react": "^7.18.6", - "@babel/preset-typescript": "^7.21.0", - "@babel/traverse": "^7.23.2", - "@droppedcode/typedoc-plugin-relative-includes": "^1.0.5", - "@esbuild-plugins/node-resolve": "^0.2.2", - "@playwright/test": "^1.45.1", - "@pluto-encrypted/inmemory": "^1.12.3", - "@semantic-release/changelog": "^6.0.3", - "@semantic-release/commit-analyzer": "^9.0.2", - "@semantic-release/exec": "^6.0.3", - "@semantic-release/git": "^10.0.1", - "@semantic-release/release-notes-generator": "^10.0.3", - "@types/bn.js": "^5.1.3", - "@types/chai": "^4.3.4", - "@types/chai-as-promised": "^7.1.5", - "@types/elliptic": "^6.4.16", - "@types/google-protobuf": "^3.15.6", - "@types/jest": "^29.5.5", - "@types/jsonld": "^1.5.14", - "@types/node": "^18.14.2", - "@types/pako": "^2.0.3", - "@types/sinon": "^17.0.3", - "@types/sinon-chai": "^3.2.12", - "@types/uuid": "^9.0.1", - "@typescript-eslint/eslint-plugin": "^5.56.0", - "@typescript-eslint/parser": "^5.55.0", - "@vitest/browser": "^1.6.0", - "@vitest/coverage-istanbul": "^1.6.0", - "anoncreds-wasm": "./externals/generated/anoncreds-wasm", - "babel-plugin-transform-import-meta": "^2.2.0", - "babel-plugin-transform-typescript-metadata": "^0.3.2", - "chai": "^4.3.7", - "chai-as-promised": "^7.1.1", - "clean-webpack-plugin": "^4.0.0", - "copy-webpack-plugin": "^11.0.0", - "core-js": "^3.32.2", - "didcomm-wasm": "./externals/generated/didcomm-wasm", - "esbuild": "0.21.5", - "esbuild-plugin-wasm": "^1.1.0", - "esbuild-plugin-wasm-pack": "^1.1.0", - "eslint": "^8.36.0", - "eslint-config-react-app": "^7.0.1", - "eslint-config-standard-with-typescript": "^34.0.1", - "eslint-plugin-import": "^2.27.5", - "eslint-plugin-n": "^15.6.1", - "eslint-plugin-promise": "^6.1.1", - "eslint-plugin-react": "^7.32.2", - "eslint-plugin-unused-imports": "^2.0.0", - "get-func-name": "^3.0.0", - "husky": "^9.0.11", - "jest": "^29.5.0", - "jest-junit": "^16.0.0", - "jsdom": "^24.1.0", - "jwe-wasm": "./externals/generated/jwe-wasm", - "prettier": "^3.0.2", - "semantic-release": "^24.0.0", - "sinon": "^18.0.0", - "sinon-chai": "^3.7.0", - "typedoc": "^0.25.13", - "typedoc-plugin-external-module-map": "^1.3.2", - "typedoc-plugin-markdown": "^3.17.1", - "typedoc-plugin-rename-defaults": "^0.7.0", - "typescript": "^4.9.5", - "vite-plugin-swc-transform": "^1.0.1", - "vite-plugin-top-level-await": "^1.4.1", - "vite-plugin-wasm": "^3.3.0", - "vite-require": "^0.2.3", - "vitest": "^1.6.0", - "webdriverio": "^7.16.4" - }, - "optionalDependencies": { - "@rollup/rollup-linux-x64-gnu": "^4.24.0" - } - }, - "node_modules/sdk": { - "resolved": "../../..", - "link": true - } - } -} diff --git a/integration-tests/node/esm/package.json b/integration-tests/node/esm/package.json index 5b7535826..959129774 100644 --- a/integration-tests/node/esm/package.json +++ b/integration-tests/node/esm/package.json @@ -3,6 +3,9 @@ "version": "0.0.0", "private": true, "type": "module", + "scripts": { + "test": "node ./test.mjs" + }, "devDependencies": { "sdk": "file:../../../" }, diff --git a/integration-tests/node/esm/test.mjs b/integration-tests/node/esm/test.mjs index 76b941a88..c1382d7b7 100644 --- a/integration-tests/node/esm/test.mjs +++ b/integration-tests/node/esm/test.mjs @@ -2,192 +2,8 @@ import { describe, test } from 'node:test'; import assert from 'node:assert'; import SDK from "sdk"; +import assertions from "../assertions.cjs"; -describe('CommonJS Integration', () => { - 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"); - }); +describe('ESM Integration', () => { + assertions.runTests(describe, test, assert, SDK); }); diff --git a/integration-tests/node/ts-cjs/package.json b/integration-tests/node/ts-cjs/package.json new file mode 100644 index 000000000..d75938788 --- /dev/null +++ b/integration-tests/node/ts-cjs/package.json @@ -0,0 +1,13 @@ +{ + "name": "@identus-edge-agent-sdk/integration-tests-ts-cjs", + "version": "0.0.0", + "private": true, + "type": "commonjs", + "scripts": { + "build": "npx tsc", + "test": "node ./build/ts-cjs/src/index.js" + }, + "dependencies": { + "sdk": "file:../../../" + } +} diff --git a/integration-tests/node/ts-cjs/src/index.ts b/integration-tests/node/ts-cjs/src/index.ts new file mode 100644 index 000000000..3cbfd5c5c --- /dev/null +++ b/integration-tests/node/ts-cjs/src/index.ts @@ -0,0 +1,13 @@ +import { describe, test } from 'node:test'; +import assert from 'node:assert'; +import SDK from "sdk"; +import * as SDKRoot from "sdk"; +import assertions = require("../../assertions.cjs"); + +describe("SDK default export", () => { + assertions.runTests(describe, test, assert, SDK); +}); + +describe("SDK root export", () => { + assertions.runTests(describe, test, assert, SDKRoot.default); +}); diff --git a/integration-tests/node/ts-cjs/tsconfig.json b/integration-tests/node/ts-cjs/tsconfig.json new file mode 100644 index 000000000..74b9e234b --- /dev/null +++ b/integration-tests/node/ts-cjs/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "module": "commonjs", /* Specify what module code is generated. */ + "outDir": "./build", /* Specify an output folder for all emitted files. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + "strict": true, /* Enable all strict type-checking options. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } +} diff --git a/integration-tests/node/ts-esm/package.json b/integration-tests/node/ts-esm/package.json new file mode 100644 index 000000000..e7073c7fb --- /dev/null +++ b/integration-tests/node/ts-esm/package.json @@ -0,0 +1,13 @@ +{ + "name": "@identus-edge-agent-sdk/integration-tests-ts-mjs", + "version": "0.0.0", + "private": true, + "type": "module", + "scripts": { + "build": "npx tsc", + "test": "node ./build/ts-esm/src/index.js" + }, + "dependencies": { + "sdk": "file:../../../" + } +} diff --git a/integration-tests/node/ts-esm/src/index.ts b/integration-tests/node/ts-esm/src/index.ts new file mode 100644 index 000000000..a6f8faf87 --- /dev/null +++ b/integration-tests/node/ts-esm/src/index.ts @@ -0,0 +1,19 @@ +import { describe, test } from 'node:test'; +import assert from 'node:assert'; +import SDK from "sdk"; +import * as SDKRoot from "sdk"; +import assertions = require("../../assertions.cjs"); + +describe("SDK default export", () => { + assertions.runTests(describe, test, assert, SDK); +}); + +describe("SDK root export", () => { + test("SDK root only has default export", () => { + const keys = Object.keys(SDKRoot); + assert(keys.length === 1); + assert(keys[0] === "default"); + }); + + assertions.runTests(describe, test, assert, SDKRoot.default); +}); diff --git a/integration-tests/node/ts-esm/tsconfig.json b/integration-tests/node/ts-esm/tsconfig.json new file mode 100644 index 000000000..4a92fc02c --- /dev/null +++ b/integration-tests/node/ts-esm/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "module": "NodeNext", /* Specify what module code is generated. */ + // "moduleResolution": "nodenext", + "outDir": "./build", /* Specify an output folder for all emitted files. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + "strict": true, /* Enable all strict type-checking options. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } +}