diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d458cec5..4134d047c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,6 +53,14 @@ jobs: - name: Run coverage test run: npm run coverage + - name: Test integration node-cjs + working-directory: integration-tests/node/cjs + run: npm i && node test.cjs + + - name: Test integration node-esm + working-directory: integration-tests/node/esm + run: npm i && node test.mjs + - name: Npm audit uses: oke-py/npm-audit-action@v2.4.4 with: diff --git a/esbuild.config.mjs b/esbuild.config.mjs index e6be9e9c1..96e326565 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -47,30 +47,22 @@ const generic = { platform: 'neutral', splitting: false, resolveExtensions: ['.ts', '.js', '.wasm'], - inject: ['anoncreds-wasm', 'didcomm-wasm', 'jwe-wasm'], mainFields: ['module', 'main'], - banner: { - js: bufferShim, - }, + target: ['esnext'], define: { 'global.Buffer': 'Buffer', }, + banner: { + js: bufferShim, + }, external: ['buffer'] }; (async () => { await esbuild.build({ ...generic, - outfile: "build/index.mjs", - target: ['esnext'], - format: 'esm', - plugins - }) - await esbuild.build({ - ...generic, - entryPoints: ['./build/index.mjs'], - outfile: "build/index.cjs", - target: ['es6'], + outdir: "build", + inject: ['anoncreds-wasm', 'didcomm-wasm', 'jwe-wasm'], format: 'cjs', plugins }) diff --git a/index.cjs b/index.cjs index 15f1d2bdf..4d26afbfd 100644 --- a/index.cjs +++ b/index.cjs @@ -1 +1 @@ -module.exports = require('./build/index.cjs') +module.exports = require('./build/index.js') diff --git a/index.mjs b/index.mjs index 1ca200451..55f562ada 100644 --- a/index.mjs +++ b/index.mjs @@ -1,3 +1,3 @@ -import * as SDK from './build/index.mjs'; +import SDK from './build/index.js'; export default SDK \ No newline at end of file diff --git a/integration-tests/node/cjs/package-lock.json b/integration-tests/node/cjs/package-lock.json new file mode 100644 index 000000000..4a2ea6820 --- /dev/null +++ b/integration-tests/node/cjs/package-lock.json @@ -0,0 +1,143 @@ +{ + "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 new file mode 100644 index 000000000..0d0548e5e --- /dev/null +++ b/integration-tests/node/cjs/package.json @@ -0,0 +1,11 @@ +{ + "name": "@identus-edge-agent-sdk/integration-tests-cjs", + "version": "0.0.0", + "private": true, + "devDependencies": { + "sdk": "file:../../../" + }, + "engines": { + "node": ">=18" + } +} diff --git a/integration-tests/node/cjs/test.cjs b/integration-tests/node/cjs/test.cjs new file mode 100644 index 000000000..631274142 --- /dev/null +++ b/integration-tests/node/cjs/test.cjs @@ -0,0 +1,193 @@ +/* eslint-disable n/no-unsupported-features/node-builtins */ +const { describe, test } = require('node:test'); +const assert = require('node:assert'); +const SDK = require("sdk"); + +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"); + }); +}); diff --git a/integration-tests/node/esm/package-lock.json b/integration-tests/node/esm/package-lock.json new file mode 100644 index 000000000..3250eda2c --- /dev/null +++ b/integration-tests/node/esm/package-lock.json @@ -0,0 +1,143 @@ +{ + "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 new file mode 100644 index 000000000..5b7535826 --- /dev/null +++ b/integration-tests/node/esm/package.json @@ -0,0 +1,12 @@ +{ + "name": "@identus-edge-agent-sdk/integration-tests-esm", + "version": "0.0.0", + "private": true, + "type": "module", + "devDependencies": { + "sdk": "file:../../../" + }, + "engines": { + "node": ">=18" + } +} diff --git a/integration-tests/node/esm/test.mjs b/integration-tests/node/esm/test.mjs new file mode 100644 index 000000000..76b941a88 --- /dev/null +++ b/integration-tests/node/esm/test.mjs @@ -0,0 +1,193 @@ +/* eslint-disable n/no-unsupported-features/node-builtins */ +import { describe, test } from 'node:test'; +import assert from 'node:assert'; +import SDK from "sdk"; + +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"); + }); +});