From e7d0f20346fd6baaec439adb718304ef07a88baa Mon Sep 17 00:00:00 2001 From: aydarng Date: Fri, 7 Feb 2025 21:23:32 +0100 Subject: [PATCH] vlei-verifier-workflows integration (#182) * vlei-verifier-workflows integration * Fix vlei-verifier-workflows version --- signify-ts-test/babel.config.js | 6 + signify-ts-test/jest.config.ts | 3 + signify-ts-test/package-lock.json | 425 +++-- signify-ts-test/package.json | 9 +- .../src/utils/generate-test-data.ts | 40 - .../src/utils/handle-json-config.ts | 85 - signify-ts-test/src/vlei-issuance.ts | 1458 ----------------- signify-ts-test/test/reg-pilot-api.test.ts | 15 +- signify-ts-test/test/report.test.ts | 12 +- .../test/run-workflow-bank-api.test.ts | 43 +- .../test/run-workflow-bank-issuance.test.ts | 43 +- signify-ts-test/test/run-workflow.test.ts | 48 +- signify-ts-test/test/utils/run-workflow.ts | 150 -- signify-ts-test/test/utils/test-data.ts | 13 +- .../test/utils/workflow-step-runners.ts | 122 ++ .../test/vlei-verification.test.ts | 19 +- 16 files changed, 494 insertions(+), 1997 deletions(-) create mode 100644 signify-ts-test/babel.config.js delete mode 100644 signify-ts-test/src/utils/generate-test-data.ts delete mode 100644 signify-ts-test/src/utils/handle-json-config.ts delete mode 100644 signify-ts-test/src/vlei-issuance.ts delete mode 100755 signify-ts-test/test/utils/run-workflow.ts create mode 100644 signify-ts-test/test/utils/workflow-step-runners.ts diff --git a/signify-ts-test/babel.config.js b/signify-ts-test/babel.config.js new file mode 100644 index 0000000..dd242dc --- /dev/null +++ b/signify-ts-test/babel.config.js @@ -0,0 +1,6 @@ +module.exports = { + presets: [ + ["@babel/preset-env", { targets: { node: "current" } }], + "@babel/preset-typescript", + ], +}; diff --git a/signify-ts-test/jest.config.ts b/signify-ts-test/jest.config.ts index 38bdf35..4e15299 100644 --- a/signify-ts-test/jest.config.ts +++ b/signify-ts-test/jest.config.ts @@ -4,6 +4,9 @@ const config: Config = { preset: "ts-jest", testMatch: ["/test/*.test.ts"], projects: ["/test"], + transform: { + "^.+\\.tsx?$": ["ts-jest", { useESM: true }], + }, }; export default config; diff --git a/signify-ts-test/package-lock.json b/signify-ts-test/package-lock.json index efb12f5..5268c9d 100644 --- a/signify-ts-test/package-lock.json +++ b/signify-ts-test/package-lock.json @@ -17,9 +17,12 @@ "libsodium-wrappers-sumo": "^0.7.9", "mathjs": "^12.4.0", "signify-ts": "github:weboftrust/signify-ts#main", - "structured-headers": "^0.5.0" + "structured-headers": "^0.5.0", + "vlei-verifier-workflows": "^0.0.2" }, "devDependencies": { + "@babel/preset-typescript": "^7.26.0", + "@jest/globals": "^29.7.0", "@mermaid-js/mermaid-cli": "^10.6.1", "@types/adm-zip": "^0.5.5", "@types/fs-extra": "^11.0.4", @@ -37,7 +40,7 @@ "jsdoc": "^4.0.2", "minami": "^1.2.3", "prettier": "^3.3.3", - "ts-jest": "^29.1.1", + "ts-jest": "^29.2.5", "ts-mockito": "^2.6.1", "ts-node": "^10.9.1", "typedoc": "^0.25.3", @@ -58,12 +61,14 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", - "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", + "version": "7.26.2", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz", + "integrity": "sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/highlight": "^7.24.7", + "@babel/helper-validator-identifier": "^7.25.9", + "js-tokens": "^4.0.0", "picocolors": "^1.0.0" }, "engines": { @@ -119,15 +124,30 @@ } }, "node_modules/@babel/generator": { - "version": "7.25.5", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.25.5.tgz", - "integrity": "sha512-abd43wyLfbWoxC6ahM8xTkqLpGB2iWBVyuKC9/srhFunCd1SDNrV1s72bBpK4hLj8KLzHBBcOblvLQZBNw9r3w==", + "version": "7.26.5", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.26.5.tgz", + "integrity": "sha512-2caSP6fN9I7HOe6nqhtft7V4g7/V/gfDsC3Ag4W7kEzzvRGKqiv0pu0HogPiZ3KaVSoNDhUws6IJjDjpfmYIXw==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/types": "^7.25.4", + "@babel/parser": "^7.26.5", + "@babel/types": "^7.26.5", "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.25", - "jsesc": "^2.5.1" + "jsesc": "^3.0.2" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-annotate-as-pure": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.25.9.tgz", + "integrity": "sha512-gv7320KBUFJz1RnylIg5WWYPRXKZ884AGkYpgpWW02TH66Dl+HaC1t1CKd0z3R4b6hdYEcmrNZHUmfCP+1u3/g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/types": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -158,29 +178,20 @@ "semver": "bin/semver.js" } }, - "node_modules/@babel/helper-module-imports": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.24.7.tgz", - "integrity": "sha512-8AyH3C+74cgCVVXow/myrynrAGv+nTVg5vKu2nZph9x7RcRwzmh0VFallJuFTZ9mx6u4eSdXZfcOzSqTUm0HCA==", - "dev": true, - "dependencies": { - "@babel/traverse": "^7.24.7", - "@babel/types": "^7.24.7" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/helper-module-transforms": { - "version": "7.25.2", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.25.2.tgz", - "integrity": "sha512-BjyRAbix6j/wv83ftcVJmBt72QtHI56C7JXZoG2xATiLpmoC7dpd8WnkikExHDVPpi/3qCmO6WY1EaXOluiecQ==", + "node_modules/@babel/helper-create-class-features-plugin": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.25.9.tgz", + "integrity": "sha512-UTZQMvt0d/rSz6KI+qdu7GQze5TIajwTS++GUozlw8VBJDEOAqSXwm1WvmYEZwqdqSGQshRocPDqrt4HBZB3fQ==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/helper-module-imports": "^7.24.7", - "@babel/helper-simple-access": "^7.24.7", - "@babel/helper-validator-identifier": "^7.24.7", - "@babel/traverse": "^7.25.2" + "@babel/helper-annotate-as-pure": "^7.25.9", + "@babel/helper-member-expression-to-functions": "^7.25.9", + "@babel/helper-optimise-call-expression": "^7.25.9", + "@babel/helper-replace-supers": "^7.25.9", + "@babel/helper-skip-transparent-expression-wrappers": "^7.25.9", + "@babel/traverse": "^7.25.9", + "semver": "^6.3.1" }, "engines": { "node": ">=6.9.0" @@ -189,146 +200,168 @@ "@babel/core": "^7.0.0" } }, - "node_modules/@babel/helper-plugin-utils": { - "version": "7.24.8", - "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.24.8.tgz", - "integrity": "sha512-FFWx5142D8h2Mgr/iPVGH5G7w6jDn4jUSpZTyDnQO0Yn7Ks2Kuz6Pci8H6MPCoUJegd/UZQ3tAvfLCxQSnWWwg==", + "node_modules/@babel/helper-create-class-features-plugin/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, - "engines": { - "node": ">=6.9.0" + "license": "ISC", + "bin": { + "semver": "bin/semver.js" } }, - "node_modules/@babel/helper-simple-access": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.24.7.tgz", - "integrity": "sha512-zBAIvbCMh5Ts+b86r/CjU+4XGYIs+R1j951gxI3KmmxBMhCg4oQMsv6ZXQ64XOm/cvzfU1FmoCyt6+owc5QMYg==", + "node_modules/@babel/helper-member-expression-to-functions": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.25.9.tgz", + "integrity": "sha512-wbfdZ9w5vk0C0oyHqAJbc62+vet5prjj01jjJ8sKn3j9h3MQQlflEdXYvuqRWjHnM12coDEqiC1IRCi0U/EKwQ==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/traverse": "^7.24.7", - "@babel/types": "^7.24.7" + "@babel/traverse": "^7.25.9", + "@babel/types": "^7.25.9" }, "engines": { "node": ">=6.9.0" } }, - "node_modules/@babel/helper-string-parser": { - "version": "7.24.8", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.8.tgz", - "integrity": "sha512-pO9KhhRcuUyGnJWwyEgnRJTSIZHiT+vMD0kPeD+so0l7mxkMT19g3pjY9GTnHySck/hDzq+dtW/4VgnMkippsQ==", + "node_modules/@babel/helper-module-imports": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.25.9.tgz", + "integrity": "sha512-tnUA4RsrmflIM6W6RFTLFSXITtl0wKjgpnLgXyowocVPrbYrLUXSBXDgTs8BlbmIzIdlBySRQjINYs2BAkiLtw==", "dev": true, + "license": "MIT", + "dependencies": { + "@babel/traverse": "^7.25.9", + "@babel/types": "^7.25.9" + }, "engines": { "node": ">=6.9.0" } }, - "node_modules/@babel/helper-validator-identifier": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.7.tgz", - "integrity": "sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w==", + "node_modules/@babel/helper-module-transforms": { + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.26.0.tgz", + "integrity": "sha512-xO+xu6B5K2czEnQye6BHA7DolFFmS3LB7stHZFaOLb1pAwO1HWLS8fXA+eh0A2yIvltPVmx3eNNDBJA2SLHXFw==", "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-module-imports": "^7.25.9", + "@babel/helper-validator-identifier": "^7.25.9", + "@babel/traverse": "^7.25.9" + }, "engines": { "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" } }, - "node_modules/@babel/helper-validator-option": { - "version": "7.24.8", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.24.8.tgz", - "integrity": "sha512-xb8t9tD1MHLungh/AIoWYN+gVHaB9kwlu8gffXGSt3FFEIT7RjS+xWbc2vUD1UTZdIpKj/ab3rdqJ7ufngyi2Q==", + "node_modules/@babel/helper-optimise-call-expression": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.25.9.tgz", + "integrity": "sha512-FIpuNaz5ow8VyrYcnXQTDRGvV6tTjkNtCK/RYNDXGSLlUD6cBuQTSw43CShGxjvfBTfcUA/r6UhUCbtYqkhcuQ==", "dev": true, + "license": "MIT", + "dependencies": { + "@babel/types": "^7.25.9" + }, "engines": { "node": ">=6.9.0" } }, - "node_modules/@babel/helpers": { - "version": "7.25.0", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.25.0.tgz", - "integrity": "sha512-MjgLZ42aCm0oGjJj8CtSM3DB8NOOf8h2l7DCTePJs29u+v7yO/RBX9nShlKMgFnRks/Q4tBAe7Hxnov9VkGwLw==", + "node_modules/@babel/helper-plugin-utils": { + "version": "7.26.5", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.26.5.tgz", + "integrity": "sha512-RS+jZcRdZdRFzMyr+wcsaqOmld1/EqTghfaBGQQd/WnRdzdlvSZ//kF7U8VQTxf1ynZ4cjUcYgjVGx13ewNPMg==", "dev": true, - "dependencies": { - "@babel/template": "^7.25.0", - "@babel/types": "^7.25.0" - }, + "license": "MIT", "engines": { "node": ">=6.9.0" } }, - "node_modules/@babel/highlight": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.7.tgz", - "integrity": "sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==", + "node_modules/@babel/helper-replace-supers": { + "version": "7.26.5", + "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.26.5.tgz", + "integrity": "sha512-bJ6iIVdYX1YooY2X7w1q6VITt+LnUILtNk7zT78ykuwStx8BauCzxvFqFaHjOpW1bVnSUM1PN1f0p5P21wHxvg==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/helper-validator-identifier": "^7.24.7", - "chalk": "^2.4.2", - "js-tokens": "^4.0.0", - "picocolors": "^1.0.0" + "@babel/helper-member-expression-to-functions": "^7.25.9", + "@babel/helper-optimise-call-expression": "^7.25.9", + "@babel/traverse": "^7.26.5" }, "engines": { "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" } }, - "node_modules/@babel/highlight/node_modules/ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "node_modules/@babel/helper-skip-transparent-expression-wrappers": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-skip-transparent-expression-wrappers/-/helper-skip-transparent-expression-wrappers-7.25.9.tgz", + "integrity": "sha512-K4Du3BFa3gvyhzgPcntrkDgZzQaq6uozzcpGbOO1OEJaI+EJdqWIMTLgFgQf6lrfiDFo5FU+BxKepI9RmZqahA==", "dev": true, + "license": "MIT", "dependencies": { - "color-convert": "^1.9.0" + "@babel/traverse": "^7.25.9", + "@babel/types": "^7.25.9" }, "engines": { - "node": ">=4" + "node": ">=6.9.0" } }, - "node_modules/@babel/highlight/node_modules/chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "node_modules/@babel/helper-string-parser": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.25.9.tgz", + "integrity": "sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA==", "dev": true, - "dependencies": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - }, + "license": "MIT", "engines": { - "node": ">=4" + "node": ">=6.9.0" } }, - "node_modules/@babel/highlight/node_modules/escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "node_modules/@babel/helper-validator-identifier": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.9.tgz", + "integrity": "sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==", "dev": true, + "license": "MIT", "engines": { - "node": ">=0.8.0" + "node": ">=6.9.0" } }, - "node_modules/@babel/highlight/node_modules/has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "node_modules/@babel/helper-validator-option": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.25.9.tgz", + "integrity": "sha512-e/zv1co8pp55dNdEcCynfj9X7nyUKUXoUEwfXqaZt0omVOmDe9oOTdKStH4GmAw6zxMFs50ZayuMfHDKlO7Tfw==", "dev": true, + "license": "MIT", "engines": { - "node": ">=4" + "node": ">=6.9.0" } }, - "node_modules/@babel/highlight/node_modules/supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "node_modules/@babel/helpers": { + "version": "7.25.0", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.25.0.tgz", + "integrity": "sha512-MjgLZ42aCm0oGjJj8CtSM3DB8NOOf8h2l7DCTePJs29u+v7yO/RBX9nShlKMgFnRks/Q4tBAe7Hxnov9VkGwLw==", "dev": true, "dependencies": { - "has-flag": "^3.0.0" + "@babel/template": "^7.25.0", + "@babel/types": "^7.25.0" }, "engines": { - "node": ">=4" + "node": ">=6.9.0" } }, "node_modules/@babel/parser": { - "version": "7.25.4", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.25.4.tgz", - "integrity": "sha512-nq+eWrOgdtu3jG5Os4TQP3x3cLA8hR8TvJNjD8vnPa20WGycimcparWnLK4jJhElTK6SDyuJo1weMKO/5LpmLA==", + "version": "7.26.7", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.26.7.tgz", + "integrity": "sha512-kEvgGGgEjRUutvdVvZhbn/BxVt+5VSpwXz1j3WYXQbXDo8KzFOPNG2GQbdAiNq8g6wn1yKk7C/qrke03a84V+w==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/types": "^7.25.4" + "@babel/types": "^7.26.7" }, "bin": { "parser": "bin/babel-parser.js" @@ -428,12 +461,13 @@ } }, "node_modules/@babel/plugin-syntax-jsx": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.24.7.tgz", - "integrity": "sha512-6ddciUPe/mpMnOKv/U+RSd2vvVy+Yw/JfBB0ZHYjEZt9NLHmCUylNYlsbqCCS1Bffjlb0fCwC9Vqz+sBz6PsiQ==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.25.9.tgz", + "integrity": "sha512-ld6oezHQMZsZfp6pWtbjaNDF2tiiCYYDqQszHt5VV437lewP9aSi2Of99CK0D0XB21k7FLgnLcmQKyKzynfeAA==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/helper-plugin-utils": "^7.24.7" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -545,12 +579,70 @@ } }, "node_modules/@babel/plugin-syntax-typescript": { - "version": "7.25.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.25.4.tgz", - "integrity": "sha512-uMOCoHVU52BsSWxPOMVv5qKRdeSlPuImUCB2dlPuBSU+W2/ROE7/Zg8F2Kepbk+8yBa68LlRKxO+xgEVWorsDg==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.25.9.tgz", + "integrity": "sha512-hjMgRy5hb8uJJjUcdWunWVcoi9bGpJp8p5Ol1229PoN6aytsLwNMgmdftO23wnCLMfVmTwZDWMPNq/D1SY60JQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-plugin-utils": "^7.25.9" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-modules-commonjs": { + "version": "7.26.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.26.3.tgz", + "integrity": "sha512-MgR55l4q9KddUDITEzEFYn5ZsGDXMSsU9E+kh7fjRXTIC3RHqfCo8RPRbyReYJh44HQ/yomFkqbOFohXvDCiIQ==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/helper-plugin-utils": "^7.24.8" + "@babel/helper-module-transforms": "^7.26.0", + "@babel/helper-plugin-utils": "^7.25.9" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-typescript": { + "version": "7.26.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.26.7.tgz", + "integrity": "sha512-5cJurntg+AT+cgelGP9Bt788DKiAw9gIMSMU2NJrLAilnj0m8WZWUNZPSLOmadYsujHutpgElO+50foX+ib/Wg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.25.9", + "@babel/helper-create-class-features-plugin": "^7.25.9", + "@babel/helper-plugin-utils": "^7.26.5", + "@babel/helper-skip-transparent-expression-wrappers": "^7.25.9", + "@babel/plugin-syntax-typescript": "^7.25.9" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/preset-typescript": { + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.26.0.tgz", + "integrity": "sha512-NMk1IGZ5I/oHhoXEElcm+xUnL/szL6xflkFZmoEU9xj1qSJXpiS7rsspYo92B4DRCDvZn2erT5LdsCeXAKNCkg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-validator-option": "^7.25.9", + "@babel/plugin-syntax-jsx": "^7.25.9", + "@babel/plugin-transform-modules-commonjs": "^7.25.9", + "@babel/plugin-transform-typescript": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -571,30 +663,32 @@ } }, "node_modules/@babel/template": { - "version": "7.25.0", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.25.0.tgz", - "integrity": "sha512-aOOgh1/5XzKvg1jvVz7AVrx2piJ2XBi227DHmbY6y+bM9H2FlN+IfecYu4Xl0cNiiVejlsCri89LUsbj8vJD9Q==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.25.9.tgz", + "integrity": "sha512-9DGttpmPvIxBb/2uwpVo3dqJ+O6RooAFOS+lB+xDqoE2PVCE8nfoHMdZLpfCQRLwvohzXISPZcgxt80xLfsuwg==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/code-frame": "^7.24.7", - "@babel/parser": "^7.25.0", - "@babel/types": "^7.25.0" + "@babel/code-frame": "^7.25.9", + "@babel/parser": "^7.25.9", + "@babel/types": "^7.25.9" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/traverse": { - "version": "7.25.4", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.25.4.tgz", - "integrity": "sha512-VJ4XsrD+nOvlXyLzmLzUs/0qjFS4sK30te5yEFlvbbUNEgKaVb2BHZUpAL+ttLPQAHNrsI3zZisbfha5Cvr8vg==", + "version": "7.26.7", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.26.7.tgz", + "integrity": "sha512-1x1sgeyRLC3r5fQOM0/xtQKsYjyxmFjaOrLJNtZ81inNjyJHGIolTULPiSc/2qe1/qfpFLisLQYFnnZl7QoedA==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/code-frame": "^7.24.7", - "@babel/generator": "^7.25.4", - "@babel/parser": "^7.25.4", - "@babel/template": "^7.25.0", - "@babel/types": "^7.25.4", + "@babel/code-frame": "^7.26.2", + "@babel/generator": "^7.26.5", + "@babel/parser": "^7.26.7", + "@babel/template": "^7.25.9", + "@babel/types": "^7.26.7", "debug": "^4.3.1", "globals": "^11.1.0" }, @@ -612,14 +706,14 @@ } }, "node_modules/@babel/types": { - "version": "7.25.4", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.25.4.tgz", - "integrity": "sha512-zQ1ijeeCXVEh+aNL0RlmkPkG8HUiDcU2pzQQFjtbntgAczRASFzj4H+6+bV+dy1ntKR14I/DypeuRG1uma98iQ==", + "version": "7.26.7", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.26.7.tgz", + "integrity": "sha512-t8kDRGrKXyp6+tjUh7hw2RLyclsW4TRoRvRHtSyAX9Bb5ldlFh+90YAYY6awRXrlB4G5G2izNeGySpATlFzmOg==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/helper-string-parser": "^7.24.8", - "@babel/helper-validator-identifier": "^7.24.7", - "to-fast-properties": "^2.0.0" + "@babel/helper-string-parser": "^7.25.9", + "@babel/helper-validator-identifier": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1541,6 +1635,7 @@ "resolved": "https://registry.npmjs.org/@jest/globals/-/globals-29.7.0.tgz", "integrity": "sha512-mpiz3dutLbkW2MNFubUGUEVLkTGiqW6yLVTA+JbP6fI6J5iL9Y0Nlg8k95pcF8ctKwCS7WVxteBs29hhfAotzQ==", "dev": true, + "license": "MIT", "dependencies": { "@jest/environment": "^29.7.0", "@jest/expect": "^29.7.0", @@ -3341,21 +3436,6 @@ "integrity": "sha512-lHl4d5/ONEbLlJvaJNtsF/Lz+WvB07u2ycqTYbdrq7UypDXailES4valYb2eWiJFxZlVmpGekfqoxQhzyFdT4Q==", "dev": true }, - "node_modules/color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "dependencies": { - "color-name": "1.1.3" - } - }, - "node_modules/color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", - "dev": true - }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -6926,7 +7006,8 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/js-yaml": { "version": "4.1.0", @@ -6994,15 +7075,16 @@ } }, "node_modules/jsesc": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", - "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz", + "integrity": "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==", "dev": true, + "license": "MIT", "bin": { "jsesc": "bin/jsesc" }, "engines": { - "node": ">=4" + "node": ">=6" } }, "node_modules/json-buffer": { @@ -9268,15 +9350,6 @@ "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==", "dev": true }, - "node_modules/to-fast-properties": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", - "integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==", - "dev": true, - "engines": { - "node": ">=4" - } - }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -9321,6 +9394,7 @@ "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.2.5.tgz", "integrity": "sha512-KD8zB2aAZrcKIdGk4OwpJggeLcH1FgrICqDSROWqlnJXGCXK4Mn6FcdK2B6670Xr73lHMG1kHw8R87A0ecZ+vA==", "dev": true, + "license": "MIT", "dependencies": { "bs-logger": "^0.2.6", "ejs": "^3.1.10", @@ -9689,6 +9763,27 @@ "node": ">=10.12.0" } }, + "node_modules/vlei-verifier-workflows": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/vlei-verifier-workflows/-/vlei-verifier-workflows-0.0.2.tgz", + "integrity": "sha512-BIe6pYJo+NrbnVf31v2tIyYgJTtjtTFfXMNtc6fmR8GJDvVQRzi49fjRwktJ61YCJRHLhUfDkoFDGgok2Pk+iA==", + "license": "MIT", + "dependencies": { + "@noble/hashes": "^1.3.2", + "adm-zip": "^0.5.14", + "axios": "^1.7.8", + "buffer": "^6.0.3", + "ecdsa-secp256r1": "^1.3.3", + "form-data": "^4.0.0", + "fs-extra": "^11.2.0", + "glob": "^11.0.0", + "jszip": "^3.10.1", + "libsodium-wrappers-sumo": "^0.7.9", + "mathjs": "^12.4.0", + "signify-ts": "github:weboftrust/signify-ts#main", + "structured-headers": "^0.5.0" + } + }, "node_modules/vscode-oniguruma": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/vscode-oniguruma/-/vscode-oniguruma-1.7.0.tgz", diff --git a/signify-ts-test/package.json b/signify-ts-test/package.json index 09fd0b4..73d3345 100644 --- a/signify-ts-test/package.json +++ b/signify-ts-test/package.json @@ -15,6 +15,7 @@ "dependencies": { "@noble/hashes": "^1.3.2", "adm-zip": "^0.5.14", + "axios": "^1.7.8", "buffer": "^6.0.3", "ecdsa-secp256r1": "^1.3.3", "form-data": "^4.0.0", @@ -23,11 +24,13 @@ "jszip": "^3.10.1", "libsodium-wrappers-sumo": "^0.7.9", "mathjs": "^12.4.0", - "axios": "^1.7.8", "signify-ts": "github:weboftrust/signify-ts#main", - "structured-headers": "^0.5.0" + "structured-headers": "^0.5.0", + "vlei-verifier-workflows": "^0.0.2" }, "devDependencies": { + "@babel/preset-typescript": "^7.26.0", + "@jest/globals": "^29.7.0", "@mermaid-js/mermaid-cli": "^10.6.1", "@types/adm-zip": "^0.5.5", "@types/fs-extra": "^11.0.4", @@ -45,7 +48,7 @@ "jsdoc": "^4.0.2", "minami": "^1.2.3", "prettier": "^3.3.3", - "ts-jest": "^29.1.1", + "ts-jest": "^29.2.5", "ts-mockito": "^2.6.1", "ts-node": "^10.9.1", "typedoc": "^0.25.3", diff --git a/signify-ts-test/src/utils/generate-test-data.ts b/signify-ts-test/src/utils/generate-test-data.ts deleted file mode 100644 index aa4c06d..0000000 --- a/signify-ts-test/src/utils/generate-test-data.ts +++ /dev/null @@ -1,40 +0,0 @@ -const testDataDir = "test_data"; -const fs = require("fs"); -const path = require("path"); - -export async function buildTestData( - testData: EcrTestData, - testName: string, - issueName: string, - fileNamePrefix: string = "", -): Promise { - let testDataDirPrefixed = path.join( - __dirname, - "../../test", - "data", - testDataDir, - testName, - ); - if (!fs.existsSync(testDataDirPrefixed)) { - fs.mkdirSync(testDataDirPrefixed); - } - testData.credential["issueName"] = issueName; - const testDataJson = JSON.stringify(testData); - const fileName = `${fileNamePrefix}${testData.lei}_${testData.aid}_${testData.engagementContextRole}.json`; - await fs.writeFile( - `${testDataDirPrefixed}/${fileName}`, - testDataJson, - "utf8", - (err: Error) => { - if (err) throw err; - }, - ); - return testDataDirPrefixed; -} - -export interface EcrTestData { - aid: string; - credential: any; - lei: string; - engagementContextRole: string; -} diff --git a/signify-ts-test/src/utils/handle-json-config.ts b/signify-ts-test/src/utils/handle-json-config.ts deleted file mode 100644 index 08191bb..0000000 --- a/signify-ts-test/src/utils/handle-json-config.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { boolean, identity } from "mathjs"; -import { SignifyClient } from "signify-ts"; - -export async function buildUserData(jsonConfig: any): Promise> { - let users: Array = new Array(); - const identifiers = structuredClone(jsonConfig.identifiers); - for (const key of Object.keys(identifiers)) { - if (identifiers[key]["agent"]) { - identifiers[key].agent = { - name: identifiers[key]["agent"], - secret: - jsonConfig.secrets[ - jsonConfig.agents[identifiers[key]["agent"]]["secret"] - ], - }; - } - } - for (const user of jsonConfig.users) { - let curUser: User = { - LE: user.LE, - identifiers: user.identifiers.map((key: any) => ({ - ...identifiers[key], - })), - alias: user.alias, - type: user.type, - }; - users.push(curUser); - } - return users; -} - -export async function buildCredentials( - jsonConfig: any, -): Promise> { - let credentials: Map = new Map< - string, - CredentialInfo - >(); - for (const key in jsonConfig.credentials) { - const cred = jsonConfig.credentials[key]; - let curCred: CredentialInfo = { - type: cred.type, - schema: cred.schema, - rules: cred.rules, - privacy: cred.privacy, - attributes: cred.attributes, - credSource: cred.credSource, - }; - credentials.set(key, curCred); - } - return credentials; -} - -export async function buildAidData(jsonConfig: any): Promise { - let users: Array = new Array(); - const identifiers = structuredClone(jsonConfig.identifiers); - for (const key of Object.keys(identifiers)) { - if (identifiers[key]["agent"]) { - identifiers[key].agent = { - name: identifiers[key]["agent"], - secret: - jsonConfig.secrets[ - jsonConfig.agents[identifiers[key]["agent"]]["secret"] - ], - }; - } - } - return identifiers; -} - -export interface User { - type: string; - LE: string; - alias: string; - identifiers: any; -} - -export interface CredentialInfo { - type: string; - schema: string; - rules?: string; - privacy: boolean; - attributes: any; - credSource?: any; -} diff --git a/signify-ts-test/src/vlei-issuance.ts b/signify-ts-test/src/vlei-issuance.ts deleted file mode 100644 index 9baf197..0000000 --- a/signify-ts-test/src/vlei-issuance.ts +++ /dev/null @@ -1,1458 +0,0 @@ -import { strict as assert } from "assert"; -import signify, { - Saider, - CredentialSubject, - CredentialData, - CreateIdentiferArgs, - randomNonce, - Salter, - HabState, - SignifyClient, - Dict, -} from "signify-ts"; -import { - resolveOobi, - waitOperation, - getOrCreateAID, - getOrCreateClients, - getOrCreateContact, - createTimestamp, - getIssuedCredential, - getReceivedCredential, - sendGrantMessage, - sendAdmitMessage, - getOrIssueCredential, - getOrCreateRegistry, - waitForCredential, - admitSinglesig, - waitAndMarkNotification, - assertOperations, - warnNotifications, - Aid, - sleep, - revokeCredential, -} from "../test/utils/test-util"; -import { - addEndRoleMultisig, - admitMultisig, - createAIDMultisig, - createRegistryMultisig, - delegateMultisig, - grantMultisig, - issueCredentialMultisig, - multisigRevoke, -} from "../test/utils/multisig-utils"; -import { boolean, sec } from "mathjs"; -import { retry } from "../test/utils/retry"; -import { - QVI_SCHEMA_URL, - LE_SCHEMA_URL, - ECR_AUTH_SCHEMA_URL, - ECR_SCHEMA_URL, - OOR_AUTH_SCHEMA_URL, - OOR_SCHEMA_URL, - CRED_RETRY_DEFAULTS, - witnessIds, - SCHEMAS, - RULES, -} from "./constants"; - -import { - User, - CredentialInfo, - buildUserData, - buildCredentials, -} from "./utils/handle-json-config"; -import fs from "fs"; -import path from "path"; -import { buildTestData, EcrTestData } from "./utils/generate-test-data"; -import { ApiUser } from "../test/utils/test-data"; - -export class VleiIssuance { - configPath: string = "config/"; - configJson: any; - users: Array = new Array(); - clients: Map> = new Map< - string, - Array - >(); - aids: Map> = new Map>(); - oobis: Map> = new Map>(); - - credentialsInfo: Map = new Map< - string, - CredentialInfo - >(); - registries: Map = new Map< - string, - { regk: string } - >(); - credentials: Map = new Map(); - schemas: any = SCHEMAS; - rules: any = RULES; - credentialData: Map = new Map(); - aidsInfo: Map = new Map(); - - kargsAID = - witnessIds.length > 0 ? { toad: witnessIds.length, wits: witnessIds } : {}; - - constructor(configJson: any) { - this.configJson = configJson; - } - - public async prepareClients() { - this.users = await buildUserData(this.configJson); - this.credentialsInfo = await buildCredentials(this.configJson); - - await this.createClients(); - await this.createAids(); - await this.fetchOobis(); - await this.createContacts(); - await this.resolveOobis([ - QVI_SCHEMA_URL, - LE_SCHEMA_URL, - ECR_AUTH_SCHEMA_URL, - ECR_SCHEMA_URL, - OOR_AUTH_SCHEMA_URL, - OOR_SCHEMA_URL, - ]); - await this.createMultisigAids(); - // await this.createMultisigDelegatedAids(); - } - - // Create clients dynamically for each user - protected async createClients() { - console.log("Creating Clients"); - for (const user of this.users) { - for (const identifier of user.identifiers) { - if (!identifier.agent) continue; - const client = await getOrCreateClients( - 1, - [identifier.agent.secret], - false, - ); - if (this.clients.has(identifier.agent)) { - this.clients.get(identifier.agent)?.push(client[0]); - } else { - this.clients.set(identifier.agent.name, [client[0]]); - } - } - } - } - - // Create AIDs for each client - protected async createAids() { - console.log("Creating AIDs"); - for (const user of this.users) { - for (const identifier of user.identifiers) { - let aid: any; - if (!identifier.identifiers) { - this.aidsInfo.set(identifier.name, identifier); - aid = await this.createAidSinglesig(identifier); - if (this.aids.has(identifier.name)) { - this.aids.get(identifier.name)?.push(aid); - } else { - this.aids.set(identifier.name, [aid]); - } - } - } - } - } - - protected async createMultisigAids() { - console.log("Creating Multisig AIDs"); - for (const user of this.users) { - for (const identifier of user.identifiers) { - let aid: any; - if (identifier.identifiers) { - this.aidsInfo.set(identifier.name, identifier); - aid = await this.createAidMultisig(identifier); - if (this.aids.has(identifier.name)) { - this.aids.get(identifier.name)?.push(aid); - } else { - this.aids.set(identifier.name, [aid]); - } - } - } - } - } - - protected async createMultisigDelegatedAids() { - console.log("Creating Delegated Multisig AIDs"); - for (const user of this.users) { - for (const identifier of user.identifiers) { - let aid: any; - if (identifier.identifiers && identifier.delegator) { - this.aidsInfo.set(identifier.name, identifier); - aid = await this.createDelegatedAidMultisig(identifier); - if (this.aids.has(identifier.name)) { - this.aids.get(identifier.name)?.push(aid); - } else { - this.aids.set(identifier.name, [aid]); - } - } - } - } - } - - // Fetch OOBIs for each client - protected async fetchOobis() { - console.log("Fetching OOBIs"); - for (const user of this.users) { - for (const identifier of user.identifiers) { - let client: any; - let oobi: any; - if (identifier.agent) { - client = this.clients.get(identifier.agent.name)![0]; - oobi = await client.oobis().get(identifier.name, "agent"); - } else { - client = this.clients.get( - this.aidsInfo.get(identifier.identifiers[0]).agent.name, - )![0]; - oobi = await client - .oobis() - .get(this.aidsInfo.get(identifier.identifiers[0]).name, "agent"); - } - if (oobi) { - if (this.oobis.has(identifier.name)) { - this.oobis.get(identifier.name)?.push(oobi); - } else { - this.oobis.set(identifier.name, [oobi]); - } - } - } - } - } - - // Create contacts between clients - protected async createContacts() { - console.log("Creating Contacts"); - const contactPromises: Promise[] = []; - for (const userA of this.users) { - for (const identifierA of userA.identifiers) { - for (const userB of this.users) { - for (const identifierB of userB.identifiers) { - if (identifierA.name !== identifierB.name) { - let client; - let oobi; - if (!identifierA.agent) { - client = this.clients.get( - this.aidsInfo.get(identifierA.identifiers[0]).agent.name, - )![0]; - } else { - client = this.clients.get(identifierA.agent.name)![0]; - } - if (!identifierB.agent) { - oobi = this.oobis.get( - this.aidsInfo.get(identifierB.identifiers[0]).name, - )?.[0].oobis[0]; - } else { - oobi = this.oobis.get(identifierB.name)?.[0].oobis[0]; - } - if (client && oobi) { - contactPromises.push( - getOrCreateContact(client, identifierB.name, oobi), - ); - } - } - } - } - } - } - await Promise.all(contactPromises); - } - - // Resolve OOBIs for each client and schema - protected async resolveOobis(schemaUrls: string[]) { - console.log("Resolving OOBIs"); - const resolveOobiPromises: Promise[] = []; - for (const [role, clientList] of this.clients) { - for (const client of clientList) { - schemaUrls.forEach(async (schemaUrl) => { - await resolveOobi(client, schemaUrl); - }); - } - } - } - - public async createRegistries() { - console.log("Creating Registries"); - for (const user of this.users) { - for (const identifier of user.identifiers) { - let registry; - if (identifier.identifiers) { - registry = await this.createRegistryMultisig( - this.aids.get(identifier.name)![0], - identifier, - ); - } else { - const client = this.clients.get(identifier.agent.name)![0]; - registry = await this.getOrCreateRegistry( - client, - this.aids.get(identifier.name)![0], - `${user.alias}Registry`, - ); - } - - this.registries.set(identifier.name, registry); - } - } - } - - private async getOrCreateRegistry( - client: SignifyClient, - aid: Aid, - registryName: string, - ) { - return await getOrCreateRegistry(client, aid, registryName); - } - - public async createAidSinglesig(aidInfo: any) { - const delegator = aidInfo.delegator; - let kargsSinglesigAID: CreateIdentiferArgs = { - toad: this.kargsAID.toad, - wits: this.kargsAID.wits, - }; - const client = this.clients.get(aidInfo.agent.name)![0]; - - if (delegator != null) { - kargsSinglesigAID.delpre = this.aids.get(delegator)![0].prefix; - const delegatorClient = this.clients.get( - this.aidsInfo.get(delegator).agent.name, - )![0]; - - const delegatorAid = this.aids.get(delegator)![0]; - // Resolve delegator's oobi - const oobi1 = await delegatorClient.oobis().get(delegator, "agent"); - await resolveOobi(client, oobi1.oobis[0], delegator); - - // Delegate client creates delegate AID - const icpResult2 = await client - .identifiers() - .create(aidInfo.name, { delpre: delegatorAid.prefix }); - const op2 = await icpResult2.op(); - const delegateAidPrefix = op2.name.split(".")[1]; - - console.log("Delegate's prefix:", delegateAidPrefix); - - // Client 1 approves delegation - const anchor = { - i: delegateAidPrefix, - s: "0", - d: delegateAidPrefix, - }; - - const result = await retry(async () => { - const apprDelRes = await delegatorClient - .delegations() - .approve(delegator, anchor); - await waitOperation(delegatorClient, await apprDelRes.op()); - console.log("Delegator approve delegation submitted"); - return apprDelRes; - }); - assert.equal( - JSON.stringify(result.serder.ked.a[0]), - JSON.stringify(anchor), - ); - - const op3 = await client.keyStates().query(delegatorAid.prefix, "1"); - await waitOperation(client, op3); - - // Delegate client checks approval - await waitOperation(client, op2); - const aid2 = await client.identifiers().get(aidInfo.name); - assert.equal(aid2.prefix, delegateAidPrefix); - console.log("Delegation approved for aid:", aid2.prefix); - - await assertOperations(delegatorClient, client); - const rpyResult2 = await client - .identifiers() - .addEndRole(aidInfo.name, "agent", client!.agent!.pre); - await waitOperation(client, await rpyResult2.op()); - return aid2; - } else { - const aid = await getOrCreateAID(client, aidInfo.name, kargsSinglesigAID); - return aid; - } - } - - public async createAidMultisig(aidInfo: any) { - let multisigAids: HabState[] = []; - const aidIdentifierNames: Array = aidInfo.identifiers; - - let issuerAids = - aidIdentifierNames.map( - (aidIdentifierName) => this.aids.get(aidIdentifierName)![0], - ) || []; - - try { - for (const aidIdentifierName of aidIdentifierNames) { - const client = this.clients.get( - this.aidsInfo.get(aidIdentifierName).agent.name, - )![0]; - multisigAids.push(await client.identifiers().get(aidInfo.name)); - } - const multisigAid = multisigAids[0]; - console.log(`${aidInfo.name} AID: ${multisigAid.prefix}`); - return multisigAid; - } catch { - multisigAids = []; - } - if (multisigAids.length == 0) { - const rstates = issuerAids.map((aid) => aid.state); - const states = rstates; - - let kargsMultisigAID: CreateIdentiferArgs = { - algo: signify.Algos.group, - isith: aidInfo.isith, - nsith: aidInfo.nsith, - toad: this.kargsAID.toad, - wits: this.kargsAID.wits, - states: states, - rstates: rstates, - }; - if (aidInfo.delegator != null) { - kargsMultisigAID.delpre = this.aids.get(aidInfo.delegator)![0].prefix; - } - let multisigOps: any[] = []; - for (let index = 0; index < issuerAids.length; index++) { - const aid = issuerAids[index]; - const kargsMultisigAIDClone = { ...kargsMultisigAID, mhab: aid }; - const otherAids = issuerAids.filter((aidTmp) => aid !== aidTmp); - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - - const op = await createAIDMultisig( - client, - aid, - otherAids, - aidInfo.name, - kargsMultisigAIDClone, - index === 0, // Set true for the first operation - ); - - multisigOps.push([client, op]); - } - if (aidInfo.delegator) { - // Approve delegation - const delegatorAidInfo = this.aidsInfo.get(aidInfo.delegator); - const delegatorAidIdentifierNames: Array = - delegatorAidInfo.identifiers; - let delegatorAids = - delegatorAidIdentifierNames.map( - (aidIdentifierName) => this.aids.get(aidIdentifierName)![0], - ) || []; - const teepre = multisigOps[0][1].name.split(".")[1]; - const anchor = { - i: teepre, - s: "0", - d: teepre, - }; - let delegatorClientInitiator; - const delegatorMultisigAid = this.aids.get(delegatorAidInfo.name)![0]; - let delegateOps = []; - for ( - let index = 0; - index < delegatorAidInfo.identifiers.length; - index++ - ) { - const curAidName = delegatorAidInfo.identifiers[index]; - const curAidInfo = this.aidsInfo.get(curAidName); - const aid = this.aids.get(curAidName)![0]; - const otherAids = delegatorAids.filter( - (aidTmp: any) => aid.prefix !== aidTmp.prefix, - ); - const delegatorClient = this.clients.get(curAidInfo.agent.name)![0]; - - const delApprOp = await delegateMultisig( - delegatorClient, - aid, - otherAids, - delegatorMultisigAid, - anchor, - index === 0, - ); - delegateOps.push([delegatorClient, delApprOp]); - if (index === 0) { - delegatorClientInitiator = delegatorClient; - } else { - await waitAndMarkNotification( - delegatorClientInitiator!, - "/multisig/ixn", - ); - } - } - for (const [client, op] of delegateOps) { - await waitOperation(client, op); - } - for (const identifier of delegatorAidInfo.identifiers) { - const curAidInfo = this.aidsInfo.get(identifier); - const delegatorClient = this.clients.get(curAidInfo.agent.name)![0]; - const queryOp1 = await delegatorClient - .keyStates() - .query(delegatorMultisigAid.prefix, "1"); - const kstor1 = await waitOperation(delegatorClient, queryOp1); - } - - for (const identifier of aidInfo.identifiers) { - const curAidInfo = this.aidsInfo.get(identifier); - const delegateeClient = this.clients.get(curAidInfo.agent.name)![0]; - const ksteetor1 = await delegateeClient - .keyStates() - .query(delegatorMultisigAid.prefix, "1"); - const teeTor1 = await waitOperation(delegateeClient, ksteetor1); - } - } - - // Wait for all multisig operations to complete - for (const [client, op] of multisigOps) { - await waitOperation(client, op); - } - - // Wait for multisig inception notifications for all clients - await waitAndMarkNotification( - this.clients.get(this.aidsInfo.get(issuerAids[0].name).agent.name)![0], - "/multisig/icp", - ); - // Retrieve the newly created AIDs for all clients - multisigAids = await Promise.all( - issuerAids.map(async (aid) => { - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return await client.identifiers().get(aidInfo.name); - }), - ); - - assert( - multisigAids.every((aid) => aid.prefix === multisigAids[0].prefix), - ); - assert(multisigAids.every((aid) => aid.name === multisigAids[0].name)); - const multisigAid = multisigAids[0]; - - // Skip if they have already been authorized. - let oobis: Array = await Promise.all( - issuerAids.map(async (aid) => { - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return await client.oobis().get(multisigAid.name, "agent"); - }), - ); - - if (oobis.some((oobi) => oobi.oobis.length == 0)) { - const timestamp = createTimestamp(); - - // Add endpoint role for all clients - const roleOps = await Promise.all( - issuerAids.map(async (aid, index) => { - const otherAids = issuerAids.filter((_, i) => i !== index); - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return await addEndRoleMultisig( - client, - multisigAid.name, - aid, - otherAids, - multisigAid, - timestamp, - index === 0, - ); - }), - ); - - // Wait for all role operations to complete for each client - for (let i = 0; i < roleOps.length; i++) { - for (let j = 0; j < roleOps[i].length; j++) { - const client = this.clients.get( - this.aidsInfo.get(issuerAids[i].name).agent.name, - )![0]; - await waitOperation(client, roleOps[i][j]); - } - } - - // Wait for role resolution notifications for all clients - // await waitAndMarkNotification(this.clients.get(this.aidsInfo.get(issuerAids[0].name).agent.name)![0], "/multisig/rpy"); - await Promise.all( - issuerAids.map((aid) => { - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return waitAndMarkNotification(client, "/multisig/rpy"); - }), - ); - - // Retrieve the OOBI again after the operation for all clients - oobis = await Promise.all( - issuerAids.map(async (aid) => { - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return await client.oobis().get(multisigAid.name, "agent"); - }), - ); - } - - // Ensure that all OOBIs are consistent across all clients - assert(oobis.every((oobi) => oobi.role === oobis[0].role)); - assert(oobis.every((oobi) => oobi.oobis[0] === oobis[0].oobis[0])); - - const oobi = oobis[0].oobis[0].split("/agent/")[0]; - const clients = Array.from(this.clients.values()).flat(); - - await Promise.all( - clients.map( - async (client) => - await getOrCreateContact(client, multisigAid.name, oobi), - ), - ); - console.log(`${aidInfo.name} AID: ${multisigAid.prefix}`); - return multisigAid; - } - } - - // Not used. Delegated AID creation is handled in createAidMultisig - public async createDelegatedAidMultisig(aidInfo: any) { - let multisigAids: HabState[] = []; - const delegatorAidInfo = this.aidsInfo.get(aidInfo.delegator); - const aidIdentifierNames: Array = aidInfo.identifiers; - const delegatorAidIdentifierNames: Array = - delegatorAidInfo.identifiers; - - let issuerAids = - aidIdentifierNames.map( - (aidIdentifierName) => this.aids.get(aidIdentifierName)![0], - ) || []; - - let delegatorAids = - delegatorAidIdentifierNames.map( - (aidIdentifierName) => this.aids.get(aidIdentifierName)![0], - ) || []; - - try { - for (const aidIdentifierName of aidIdentifierNames) { - const client = this.clients.get( - this.aidsInfo.get(aidIdentifierName).agent.name, - )![0]; - multisigAids.push(await client.identifiers().get(aidInfo.name)); - } - const multisigAid = multisigAids[0]; - console.log(`${aidInfo.name} AID: ${multisigAid.prefix}`); - await this.fetchOobis(); - await this.createContacts(); - return multisigAid; - } catch { - multisigAids = []; - } - if (multisigAids.length == 0) { - const rstates = issuerAids.map((aid) => aid.state); - const states = rstates; - - let kargsMultisigAID: CreateIdentiferArgs = { - algo: signify.Algos.group, - isith: aidInfo.isith, - nsith: aidInfo.nsith, - toad: this.kargsAID.toad, - wits: this.kargsAID.wits, - states: states, - rstates: rstates, - }; - if (aidInfo.delegator != null) { - kargsMultisigAID.delpre = this.aids.get(aidInfo.delegator)![0].prefix; - } - let multisigOps: any[] = []; - for (let index = 0; index < issuerAids.length; index++) { - const aid = issuerAids[index]; - const kargsMultisigAIDClone = { ...kargsMultisigAID, mhab: aid }; - const otherAids = issuerAids.filter((aidTmp) => aid !== aidTmp); - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - - const op = await createAIDMultisig( - client, - aid, - otherAids, - aidInfo.name, - kargsMultisigAIDClone, - index === 0, // Set true for the first operation - ); - - multisigOps.push([client, op]); - } - - // Wait for multisig inception notifications for all clients - await waitAndMarkNotification( - this.clients.get(this.aidsInfo.get(issuerAids[0].name).agent.name)![0], - "/multisig/icp", - ); - - // Approve delegation - const teepre = multisigOps[0][1].name.split(".")[1]; - const anchor = { - i: teepre, - s: "0", - d: teepre, - }; - let delegatorClientInitiator; - const delegatorMultisigAid = this.aids.get(delegatorAidInfo.name)![0]; - let delegateOps = []; - for ( - let index = 0; - index < delegatorAidInfo.identifiers.length; - index++ - ) { - const curAidName = delegatorAidInfo.identifiers[index]; - const curAidInfo = this.aidsInfo.get(curAidName); - const aid = this.aids.get(curAidName)![0]; - const otherAids = delegatorAids.filter( - (aidTmp: any) => aid.prefix !== aidTmp.prefix, - ); - const delegatorClient = this.clients.get(curAidInfo.agent.name)![0]; - - const delApprOp = await delegateMultisig( - delegatorClient, - aid, - otherAids, - delegatorMultisigAid, - anchor, - index === 0, - ); - delegateOps.push([delegatorClient, delApprOp]); - if (index === 0) { - delegatorClientInitiator = delegatorClient; - } else { - await waitAndMarkNotification( - delegatorClientInitiator!, - "/multisig/ixn", - ); - } - } - for (const [client, op] of delegateOps) { - await waitOperation(client, op); - } - - for (const identifier of delegatorAidInfo.identifiers) { - const curAidInfo = this.aidsInfo.get(identifier); - const delegatorClient = this.clients.get(curAidInfo.agent.name)![0]; - const queryOp1 = await delegatorClient - .keyStates() - .query(delegatorMultisigAid.prefix, "1"); - const kstor1 = await waitOperation(delegatorClient, queryOp1); - } - - for (const identifier of aidInfo.identifiers) { - const curAidInfo = this.aidsInfo.get(identifier); - const delegateeClient = this.clients.get(curAidInfo.agent.name)![0]; - const ksteetor1 = await delegateeClient - .keyStates() - .query(delegatorMultisigAid.prefix, "1"); - const teeTor1 = await waitOperation(delegateeClient, ksteetor1); - } - - for (const [client, op] of multisigOps) { - await waitOperation(client, op); - } - const curAidInfo = this.aidsInfo.get(aidInfo.identifiers[0]); - const delegateeClient = this.clients.get(curAidInfo.agent.name)![0]; - const multisigAid = await delegateeClient.identifiers().get(aidInfo.name); - console.log("Delegated multisig created!"); - - let oobis: Array = await Promise.all( - issuerAids.map(async (aid) => { - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return await client.oobis().get(multisigAid.name, "agent"); - }), - ); - - if (oobis.some((oobi) => oobi.oobis.length == 0)) { - const timestamp = createTimestamp(); - - // Add endpoint role for all clients - const roleOps = await Promise.all( - issuerAids.map(async (aid, index) => { - const otherAids = issuerAids.filter((_, i) => i !== index); - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return await addEndRoleMultisig( - client, - multisigAid.name, - aid, - otherAids, - multisigAid, - timestamp, - index === 0, - ); - }), - ); - - // Wait for all role operations to complete for each client - for (let i = 0; i < roleOps.length; i++) { - for (let j = 0; j < roleOps[i].length; j++) { - const client = this.clients.get( - this.aidsInfo.get(issuerAids[i].name).agent.name, - )![0]; - await waitOperation(client, roleOps[i][j]); - } - } - - // Wait for role resolution notifications for all clients - // await waitAndMarkNotification(this.clients.get(this.aidsInfo.get(issuerAids[0].name).agent.name)![0], "/multisig/rpy"); - await Promise.all( - issuerAids.map((aid) => { - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return waitAndMarkNotification(client, "/multisig/rpy"); - }), - ); - - // Retrieve the OOBI again after the operation for all clients - oobis = await Promise.all( - issuerAids.map(async (aid) => { - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return await client.oobis().get(multisigAid.name, "agent"); - }), - ); - } - // Ensure that all OOBIs are consistent across all clients - assert(oobis.every((oobi) => oobi.role === oobis[0].role)); - assert(oobis.every((oobi) => oobi.oobis[0] === oobis[0].oobis[0])); - - const oobi = oobis[0].oobis[0].split("/agent/")[0]; - const clients = Array.from(this.clients.values()).flat(); - - await Promise.all( - clients.map( - async (client) => - await getOrCreateContact(client, multisigAid.name, oobi), - ), - ); - return multisigAid; - } - } - - public async createRegistryMultisig(multisigAid: HabState, aidInfo: any) { - const registryIdentifierName = `${aidInfo.name}Registry`; - const aidIdentifierNames: Array = aidInfo.identifiers; - let registries: Array = new Array(); - let issuerAids = - aidIdentifierNames.map( - (aidIdentifierName) => this.aids.get(aidIdentifierName)![0], - ) || []; - // Check if the registries already exist - for (const aidIdentifierName of aidIdentifierNames) { - const client = this.clients.get( - this.aidsInfo.get(aidIdentifierName).agent.name, - )![0]; - let tmpRegistry = await client.registries().list(multisigAid.name); - tmpRegistry = tmpRegistry.filter( - (reg: { name: string }) => reg.name == `${aidInfo.name}Registry`, - ); - registries.push(tmpRegistry); - } - - // Check if registries exist - const allEmpty = registries.every((registry) => registry.length === 0); - - if (allEmpty) { - const nonce = randomNonce(); - const registryOps = issuerAids!.map((aid, index) => { - const otherAids = issuerAids!.filter((_, i) => i !== index); - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return createRegistryMultisig( - client, - aid, - otherAids, - multisigAid, - registryIdentifierName, - nonce, - index === 0, // Use true for the first operation, false for others - ); - }); - - // Await all registry creation operations - const createdOps = await Promise.all(registryOps); - - // Wait for all operations to complete across multiple clients - await Promise.all( - createdOps.map(async (op, index) => { - const client = this.clients.get( - this.aidsInfo.get(issuerAids![index].name).agent.name, - )![0]; - return await waitOperation(client, op); - }), - ); - - // Wait for multisig inception notification for each client - await waitAndMarkNotification( - this.clients.get(this.aidsInfo.get(issuerAids[0].name).agent.name)![0], - "/multisig/vcp", - ); - - // Recheck the registries for each client - const updatedRegistries = await Promise.all( - issuerAids.map((aid) => { - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return client.registries().list(multisigAid.name); - }), - ); - - // Update the `registries` array with the new values - registries.splice(0, registries.length, ...updatedRegistries); - - // Ensure that all registries match the first one - const firstRegistry = registries[0][0]; - registries.forEach((registry) => { - assert.equal(registry[0].regk, firstRegistry.regk); - assert.equal(registry[0].name, firstRegistry.name); - }); - - // Save the first registry and return it - this.registries.set(multisigAid.name, firstRegistry); - console.log(`${multisigAid.name} Registry created`); - return firstRegistry; - } else { - return registries[0][0]; - } - } - - public buildCredSource(credType: string, cred: any, o?: string) { - const credDict: { [key: string]: any } = { - n: cred.sad.d, - s: cred.sad.s, - }; - if (o != null) { - credDict["o"] = o; - } - const credSource = Saider.saidify({ - d: "", - [credType]: credDict, - })[1]; - return credSource; - } - - public async getOrIssueCredential( - credId: string, - credName: string, - attributes: any, - issuerAidKey: string, - issueeAidKey: string, - credSourceId?: string, - generateTestData: boolean = false, - testName: string = "default_test", - ): Promise { - const issuerAidInfo = this.aidsInfo.get(issuerAidKey)!; - if (issuerAidInfo.identifiers) { - return await this.getOrIssueCredentialMultiSig( - credId, - credName, - attributes, - issuerAidKey, - issueeAidKey, - credSourceId, - generateTestData, - testName, - ); - } else { - return await this.getOrIssueCredentialSingleSig( - credId, - credName, - attributes, - issuerAidKey, - issueeAidKey, - credSourceId, - generateTestData, - testName, - ); - } - } - - public async revokeCredential( - credId: string, - issuerAidKey: string, - issueeAidKey: string, - generateTestData: boolean = false, - testName: string = "default_test", - ) { - const issuerAidInfo = this.aidsInfo.get(issuerAidKey)!; - if (issuerAidInfo.identifiers) { - return await this.revokeCredentialMultiSig( - credId, - issuerAidKey, - issueeAidKey, - generateTestData, - testName, - ); - } else { - return await this.revokeCredentialSingleSig( - credId, - issuerAidKey, - issueeAidKey, - generateTestData, - testName, - ); - } - } - - public async getOrIssueCredentialSingleSig( - credId: string, - credName: string, - attributes: any, - issuerAidKey: string, - issueeAidKey: string, - credSourceId?: string, - generateTestData: boolean = false, - testName: string = "default_test", - ): Promise { - const credInfo: CredentialInfo = this.credentialsInfo.get(credName)!; - const issuerAID = this.aids.get(issuerAidKey)![0]; - const recipientAID = this.aids.get(issueeAidKey)![0]; - const issuerAIDInfo = this.aidsInfo.get(issuerAidKey)!; - const recipientAIDInfo = this.aidsInfo.get(issueeAidKey)!; - const issuerClient = this.clients.get(issuerAIDInfo.agent.name)![0]; - const recipientClient = this.clients.get(recipientAIDInfo.agent.name)![0]; - - const issuerRegistry = this.registries.get(issuerAIDInfo.name)!; - const schema = this.schemas[credInfo.schema]; - const rules = this.rules[credInfo.rules!]; - const privacy = credInfo.privacy; - let credSource = null; - if (credSourceId != null) { - const credType = credInfo.credSource["type"]; - const issuerCred = this.credentials.get(credSourceId); - const credO = credInfo.credSource["o"] || null; - credSource = this.buildCredSource(credType, issuerCred, credO); - } - if (attributes["AID"] != null) { - attributes.AID = this.aids.get(attributes["AID"])![0].prefix; - } - const credData = { ...credInfo.attributes, ...attributes }; - const cred = await getOrIssueCredential( - issuerClient, - issuerAID, - recipientAID, - issuerRegistry, - credData, - schema, - rules || undefined, - credSource || undefined, - boolean(privacy || false), - ); - - let credHolder = await getReceivedCredential(recipientClient, cred.sad.d); - - if (!credHolder) { - await sendGrantMessage(issuerClient, issuerAID, recipientAID, cred); - await sendAdmitMessage(recipientClient, recipientAID, issuerAID); - credHolder = await retry(async () => { - const cCred = await getReceivedCredential(recipientClient, cred.sad.d); - assert(cCred !== undefined); - return cCred; - }, CRED_RETRY_DEFAULTS); - } - - assert.equal(credHolder.sad.d, cred.sad.d); - assert.equal(credHolder.sad.s, schema); - assert.equal(credHolder.sad.i, issuerAID.prefix); - assert.equal(credHolder.sad.a.i, recipientAID.prefix); - assert.equal(credHolder.status.s, "0"); - assert(credHolder.atc !== undefined); - this.credentials.set(credId, cred); - const credCesr = await recipientClient.credentials().get(cred.sad.d, true); - if (generateTestData) { - let tmpCred = cred; - let testData: EcrTestData = { - aid: recipientAID.prefix, - lei: credData.LEI, - credential: { raw: tmpCred, cesr: credCesr }, - engagementContextRole: - credData.engagementContextRole || credData.officialRole, - }; - await buildTestData(testData, testName, issueeAidKey); - } - const response: ApiUser = { - roleClient: recipientClient, - ecrAid: recipientAID, - creds: [{ cred: cred, credCesr: credCesr }], - lei: credData.LEI, - uploadDig: "", - idAlias: issueeAidKey, - }; - return [response, credData.engagementContextRole]; - } - - public async getOrIssueCredentialMultiSig( - credId: string, - credName: string, - attributes: any, - issuerAidKey: string, - issueeAidKey: string, - credSourceId?: string, - generateTestData: boolean = false, - testName: string = "default_test", - ) { - const credInfo: CredentialInfo = this.credentialsInfo.get(credName)!; - const issuerAidInfo = this.aidsInfo.get(issuerAidKey)!; - const recipientAidInfo = this.aidsInfo.get(issueeAidKey)!; - const issuerAidIdentifierName = issuerAidInfo.name; - const recipientAidIdentifierName = recipientAidInfo.name; - const issuerAIDMultisig = this.aids.get(issuerAidKey)![0]; - const recipientAID = this.aids.get(issueeAidKey)![0]; - const credData = credInfo.attributes; - const schema = this.schemas[credInfo.schema]; - let rules = this.rules[credInfo.rules!]; - const privacy = credInfo.privacy; - const registryName = issuerAidInfo.name; - let issuerRegistry = this.registries.get(registryName)!; - const issuerAids = - issuerAidInfo.identifiers.map( - (identifier: any) => this.aids.get(identifier)![0], - ) || []; - let recepientAids = []; - - if (recipientAidInfo.identifiers) { - recepientAids = - recipientAidInfo.identifiers.map( - (identifier: any) => this.aids.get(identifier)![0], - ) || []; - } else { - recepientAids = [this.aids.get(recipientAidInfo.name)![0]]; - } - - let credSource = null; - if (credSourceId != null) { - const credType = credInfo.credSource["type"]; - const issuerCred = this.credentials.get(credSourceId); - const credO = credInfo.credSource["o"] || null; - credSource = this.buildCredSource(credType, issuerCred, credO); - credSource = credSource ? { e: credSource } : undefined; - } - rules = rules ? { r: rules } : undefined; - // Issuing a credential - let creds = await Promise.all( - issuerAids.map((aid: any, index: any) => - getIssuedCredential( - this.clients.get(this.aidsInfo.get(aid.name).agent.name)![0], - issuerAIDMultisig, - recipientAID, - schema, - ), - ), - ); - - if (creds.every((cred) => !cred)) { - if (attributes["AID"] != null) { - attributes.AID = this.aids.get(attributes["AID"])![0].prefix; - } - const credData = { ...credInfo.attributes, ...attributes }; - - const kargsSub = { - i: recipientAID.prefix, - dt: createTimestamp(), - u: privacy ? new Salter({}).qb64 : undefined, - ...credData, - }; - - const kargsIss = { - i: issuerAIDMultisig.prefix, - ri: issuerRegistry.regk, - s: schema, - a: kargsSub, - u: privacy ? new Salter({}).qb64 : undefined, - ...credSource!, - ...rules!, - }; - - const IssOps = await Promise.all( - issuerAids.map((aid: any, index: any) => - issueCredentialMultisig( - this.clients.get(this.aidsInfo.get(aid.name).agent.name)![0], - aid, - issuerAids.filter((_: any, i: any) => i !== index), - issuerAIDMultisig.name, - kargsIss, - index === 0, - ), - ), - ); - - await Promise.all( - issuerAids.map((aid: any, index: any) => { - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return waitOperation(client, IssOps[index]); - }), - ); - - await waitAndMarkNotification( - this.clients.get(this.aidsInfo.get(issuerAids[0].name).agent.name)![0], - "/multisig/iss", - ); - - creds = await Promise.all( - issuerAids.map((aid: any, index: any) => { - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return getIssuedCredential( - client, - issuerAIDMultisig, - recipientAID, - schema, - ); - }), - ); - sleep(1000); - const grantTime = createTimestamp(); - await Promise.all( - creds.map((cred, index) => { - const client = this.clients.get( - this.aidsInfo.get(issuerAids[index].name).agent.name, - )![0]; - return grantMultisig( - client, - issuerAids[index], - issuerAids.filter((_: any, i: any) => i !== index), - issuerAIDMultisig, - recipientAID, - cred, - grantTime, - index === 0, - ); - }), - ); - sleep(1000); - await waitAndMarkNotification( - this.clients.get(this.aidsInfo.get(issuerAids[0].name).agent.name)![0], - "/multisig/exn", - ); - } - const cred = creds[0]; - - // Exchange grant and admit messages. - // Check if the recipient is a singlesig AID - if (recipientAidInfo.identifiers) { - let credsReceived = await Promise.all( - recepientAids.map((aid: any) => { - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return getReceivedCredential(client, cred.sad.d); - }), - ); - - if (credsReceived.every((cred) => cred === undefined)) { - const admitTime = createTimestamp(); - - await Promise.all( - recepientAids.map((aid: any, index: any) => { - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return admitMultisig( - client, - aid, - recepientAids.filter((_: any, i: any) => i !== index), - recipientAID, - issuerAIDMultisig, - admitTime, - ); - }), - ); - sleep(2000); - for (const aid of issuerAids) { - await waitAndMarkNotification( - this.clients.get(this.aidsInfo.get(aid.name).agent.name)![0], - "/exn/ipex/admit", - ); - } - for (const aid of recepientAids) { - await waitAndMarkNotification( - this.clients.get(this.aidsInfo.get(aid.name).agent.name)![0], - "/multisig/exn", - ); - } - for (const aid of recepientAids) { - await waitAndMarkNotification( - this.clients.get(this.aidsInfo.get(aid.name).agent.name)![0], - "/exn/ipex/admit", - ); - } - sleep(1000); - credsReceived = await Promise.all( - recepientAids.map((aid: any) => { - const client = this.clients.get( - this.aidsInfo.get(aid.name).agent.name, - )![0]; - return waitForCredential(client, cred.sad.d); - }), - ); - - // Assert received credential details - for (const credReceived of credsReceived) { - assert.equal(cred.sad.d, credReceived.sad.d); - } - } - } else { - let credReceived = await getReceivedCredential( - this.clients.get( - this.aidsInfo.get(recepientAids[0]!.name).agent.name, - )![0], - cred.sad.d, - ); - if (!credReceived) { - await admitSinglesig( - this.clients.get( - this.aidsInfo.get(recepientAids[0]!.name).agent.name, - )![0], - this.aids.get(recepientAids[0]!.name)![0].name, - issuerAIDMultisig, - ); - sleep(2000); - for (const aid of issuerAids) { - await waitAndMarkNotification( - this.clients.get(this.aidsInfo.get(aid.name).agent.name)![0], - "/exn/ipex/admit", - ); - } - - credReceived = await waitForCredential( - this.clients.get( - this.aidsInfo.get(recepientAids[0]!.name).agent.name, - )![0], - cred.sad.d, - ); - } - assert.equal(cred.sad.d, credReceived.sad.d); - } - console.log( - `${issuerAIDMultisig.name} has issued a ${recipientAID.name} vLEI credential with SAID:`, - cred.sad.d, - ); - this.credentials.set(credId, cred); - return [cred, null]; - } - - public async revokeCredentialSingleSig( - credId: string, - issuerAidKey: string, - issueeAidKey: string, - generateTestData: boolean = false, - testName: string = "default_test", - ) { - const cred: any = this.credentials.get(credId)!; - const issuerAID = this.aids.get(issuerAidKey)![0]; - const recipientAID = this.aids.get(issueeAidKey)![0]; - const issuerAIDInfo = this.aidsInfo.get(issuerAidKey)!; - const recipientAIDInfo = this.aidsInfo.get(issueeAidKey)!; - const recipientClient = this.clients.get(recipientAIDInfo.agent.name)![0]; - const issuerClient = this.clients.get(issuerAIDInfo.agent.name)![0]; - - const revCred = await revokeCredential(issuerClient, issuerAID, cred.sad.d); - this.credentials.set(credId, revCred); - const credCesr = await issuerClient.credentials().get(revCred.sad.d, true); - if (generateTestData) { - let tmpCred = revCred; - let testData: EcrTestData = { - aid: recipientAID.prefix, - lei: revCred.sad.a.LEI, - credential: { raw: tmpCred, cesr: credCesr }, - engagementContextRole: - revCred.sad.a.engagementContextRole || revCred.sad.a.officialRole, - }; - await buildTestData(testData, testName, issueeAidKey, "revoked_"); - } - - const response: ApiUser = { - roleClient: recipientClient, - ecrAid: recipientAID, - creds: [{ cred: revCred, credCesr: credCesr }], - lei: revCred.sad.a.LEI, - uploadDig: "", - idAlias: issueeAidKey, - }; - return [response, revCred.sad.a.engagementContextRole]; - } - - public async revokeCredentialMultiSig( - credId: string, - issuerAidKey: string, - issueeAidKey: string, - generateTestData: boolean = false, - testName: string = "default_test", - ) { - const recipientAID = this.aids.get(issueeAidKey)![0]; - const cred: any = this.credentials.get(credId)!; - const issuerAidInfo = this.aidsInfo.get(issuerAidKey)!; - const issuerAIDMultisig = this.aids.get(issuerAidKey)![0]; - const issuerAids = - issuerAidInfo.identifiers.map( - (identifier: any) => this.aids.get(identifier)![0], - ) || []; - let revCred: any; - let issuerClient: any; - let revOps = []; - let i = 0; - const REVTIME = new Date().toISOString().replace("Z", "000+00:00"); - for (const issuerAid of issuerAids) { - const aidInfo = this.aidsInfo.get(issuerAid.name)!; - issuerClient = this.clients.get(aidInfo.agent.name)![0]; - if (i != 0) { - const msgSaid = await waitAndMarkNotification( - issuerClient, - "/multisig/rev", - ); - console.log( - `Multisig AID ${issuerAid.name} received exchange message to join the credential revocation event`, - ); - const res = await issuerClient.groups().getRequest(msgSaid); - } - const revResult = await issuerClient - .credentials() - .revoke(issuerAIDMultisig.name, cred.sad.d, REVTIME); - revOps.push([issuerClient, revResult.op]); - await multisigRevoke( - issuerClient, - issuerAid.name, - issuerAIDMultisig.name, - revResult.rev, - revResult.anc, - ); - i += 1; - } - - for (const [client, op] of revOps) { - await waitOperation(client, op); - } - revCred = await issuerClient.credentials().get(cred.sad.d); - this.credentials.set(credId, revCred); - if (generateTestData) { - let tmpCred = revCred; - const credCesr = await issuerClient - .credentials() - .get(revCred.sad.d, true); - let testData: EcrTestData = { - aid: recipientAID.prefix, - lei: revCred.sad.a.LEI, - credential: { raw: tmpCred, cesr: credCesr }, - engagementContextRole: - revCred.sad.a.engagementContextRole || revCred.sad.a.officialRole, - }; - await buildTestData(testData, testName, issueeAidKey, "revoked_"); - } - return [revCred, null]; - } -} diff --git a/signify-ts-test/test/reg-pilot-api.test.ts b/signify-ts-test/test/reg-pilot-api.test.ts index 7d4bb42..8662dd9 100644 --- a/signify-ts-test/test/reg-pilot-api.test.ts +++ b/signify-ts-test/test/reg-pilot-api.test.ts @@ -6,13 +6,8 @@ import { HabState, SignifyClient } from "signify-ts"; import { ApiAdapter } from "../src/api-adapter"; import { generateFileDigest } from "./utils/generate-digest"; import { resolveEnvironment, TestEnvironment } from "./utils/resolve-env"; -import { - ApiUser, - getApiTestData, - getConfig, - isEbaDataSubmitter, -} from "./utils/test-data"; -import { buildUserData } from "../src/utils/handle-json-config"; +import { ApiUser, getApiTestData, isEbaDataSubmitter } from "./utils/test-data"; +import { buildUserData, getConfig } from "vlei-verifier-workflows"; import { ECR_SCHEMA_SAID } from "../src/constants"; import { sleep } from "./utils/test-util"; @@ -33,8 +28,10 @@ beforeAll(async () => { if (require.main === module) { test("reg-pilot-api", async function run() { - const configFilePath = env.configuration; - const configJson = await getConfig(configFilePath, false); + const configFileName = env.configuration; + let dirPath = "../src/config/"; + const configFilePath = path.join(__dirname, dirPath) + configFileName; + const configJson = await getConfig(configFilePath); let users = await buildUserData(configJson); users = users.filter((user) => user.type === "ECR"); const apiUsers = await getApiTestData( diff --git a/signify-ts-test/test/report.test.ts b/signify-ts-test/test/report.test.ts index 521fbe4..4f86e3d 100644 --- a/signify-ts-test/test/report.test.ts +++ b/signify-ts-test/test/report.test.ts @@ -10,13 +10,13 @@ import { resolveEnvironment, TestEnvironment } from "./utils/resolve-env"; import { buildAidData, buildUserData, - User, -} from "../src/utils/handle-json-config"; + getConfig, +} from "vlei-verifier-workflows"; import { unknownPrefix } from "../src/constants"; import { sign } from "crypto"; import { boolean, re } from "mathjs"; -import { getConfig, getReportGenTestData } from "./utils/test-data"; +import { getReportGenTestData } from "./utils/test-data"; export const EXTERNAL_MAN_TYPE = "external_manifest"; export const SIMPLE_TYPE = "simple"; @@ -63,8 +63,10 @@ function deleteReportsDir(repDir: string): void { if (require.main === module) { test("report-generation-test", async function run() { env = resolveEnvironment(); - const configFilePath = env.configuration; - const configJson = await getConfig(configFilePath, false); + const configFileName = env.configuration; + let dirPath = "../src/config/"; + const configFilePath = path.join(__dirname, dirPath) + configFileName; + const configJson = await getConfig(configFilePath); let users = await buildUserData(configJson); users = users.filter((user) => user.type === "ECR"); for (const user of users) { diff --git a/signify-ts-test/test/run-workflow-bank-api.test.ts b/signify-ts-test/test/run-workflow-bank-api.test.ts index 23b04f8..f9286c4 100755 --- a/signify-ts-test/test/run-workflow-bank-api.test.ts +++ b/signify-ts-test/test/run-workflow-bank-api.test.ts @@ -1,9 +1,17 @@ import path from "path"; import { resolveEnvironment, TestEnvironment } from "./utils/resolve-env"; +import { strict as assert } from "assert"; -import { getConfig } from "./utils/test-data"; - -import { runWorkflow } from "./utils/run-workflow"; +import { + WorkflowRunner, + getConfig, + loadWorkflow, +} from "vlei-verifier-workflows"; +import { + ApiTestStepRunner, + GenerateReportStepRunner, + VleiVerificationTestStepRunner, +} from "./utils/workflow-step-runners"; const fs = require("fs"); const yaml = require("js-yaml"); @@ -18,25 +26,26 @@ beforeAll((done) => { env = resolveEnvironment(); }); -// Function to load and parse YAML file -function loadWorkflow(filePath: string) { - try { - const file = fs.readFileSync(filePath, "utf8"); - return yaml.load(file); - } catch (e) { - console.error("Error reading YAML file:", e); - return null; - } -} - test("api-verifier-bank-test-workflow", async function run() { // You need to set the BANK_NAME environment variable. Ex.: export BANK_NAME=Bank_2. const bankName = process.env.BANK_NAME; const workflowPath = "../src/workflows/bank-api-verifier-test-workflow.yaml"; const workflow = loadWorkflow(path.join(__dirname, `${workflowPath}`)); - const configFilePath = `${bankName}/config.json`; - const configJson = await getConfig(configFilePath, true); + const configFileName = `${bankName}/config.json`; + let dirPath = "./data/600-banks-test-data/"; + const configFilePath = path.join(__dirname, dirPath) + configFileName; + const configJson = await getConfig(configFilePath); + if (workflow && configJson) { - await runWorkflow(workflow, configJson); + const wr = new WorkflowRunner(workflow, configJson); + await wr.prepareClients(); + wr.registerRunner("generate_report", new GenerateReportStepRunner()); + wr.registerRunner("api_test", new ApiTestStepRunner()); + wr.registerRunner( + "vlei_verification_test", + new VleiVerificationTestStepRunner(), + ); + const workflowRunResult = await wr.runWorkflow(); + assert.equal(workflowRunResult, true); } }, 3600000); diff --git a/signify-ts-test/test/run-workflow-bank-issuance.test.ts b/signify-ts-test/test/run-workflow-bank-issuance.test.ts index 5e25dc9..2151696 100755 --- a/signify-ts-test/test/run-workflow-bank-issuance.test.ts +++ b/signify-ts-test/test/run-workflow-bank-issuance.test.ts @@ -1,7 +1,17 @@ import path from "path"; import { resolveEnvironment, TestEnvironment } from "./utils/resolve-env"; -import { getConfig } from "./utils/test-data"; -import { runWorkflow } from "./utils/run-workflow"; +import { strict as assert } from "assert"; + +import { + WorkflowRunner, + getConfig, + loadWorkflow, +} from "vlei-verifier-workflows"; +import { + ApiTestStepRunner, + GenerateReportStepRunner, + VleiVerificationTestStepRunner, +} from "./utils/workflow-step-runners"; const fs = require("fs"); const yaml = require("js-yaml"); @@ -16,17 +26,6 @@ beforeAll((done) => { env = resolveEnvironment(); }); -// Function to load and parse YAML file -function loadWorkflow(filePath: string) { - try { - const file = fs.readFileSync(filePath, "utf8"); - return yaml.load(file); - } catch (e) { - console.error("Error reading YAML file:", e); - return null; - } -} - test("vlei-issuance-reports-bank-test-workflow", async function run() { // You need to set the BANK_NAME environment variable. Ex.: export BANK_NAME=Bank_2. const bankName = process.env.BANK_NAME; @@ -38,9 +37,21 @@ test("vlei-issuance-reports-bank-test-workflow", async function run() { const workflow = loadWorkflow( path.join(__dirname, `${bankDirPath}`) + workflowName, ); - const configFilePath = `${bankName}/config.json`; - const configJson = await getConfig(configFilePath, true); + const configFileName = `${bankName}/config.json`; + let dirPath = "./data/600-banks-test-data/"; + const configFilePath = path.join(__dirname, dirPath) + configFileName; + const configJson = await getConfig(configFilePath); + if (workflow && configJson) { - await runWorkflow(workflow, configJson); + const wr = new WorkflowRunner(workflow, configJson); + await wr.prepareClients(); + wr.registerRunner("generate_report", new GenerateReportStepRunner()); + wr.registerRunner("api_test", new ApiTestStepRunner()); + wr.registerRunner( + "vlei_verification_test", + new VleiVerificationTestStepRunner(), + ); + const workflowRunResult = await wr.runWorkflow(); + assert.equal(workflowRunResult, true); } }, 3600000); diff --git a/signify-ts-test/test/run-workflow.test.ts b/signify-ts-test/test/run-workflow.test.ts index 089f9ce..de07830 100755 --- a/signify-ts-test/test/run-workflow.test.ts +++ b/signify-ts-test/test/run-workflow.test.ts @@ -1,18 +1,16 @@ -import { VleiIssuance } from "../src/vlei-issuance"; import path from "path"; -import { getOrCreateClients } from "./utils/test-util"; import { resolveEnvironment, TestEnvironment } from "./utils/resolve-env"; -import { buildAidData } from "../src/utils/handle-json-config"; -import { generate_reports } from "./report.test"; import { - ApiUser, - getApiTestData, + WorkflowRunner, getConfig, - getReportGenTestData, -} from "./utils/test-data"; -import { run_api_revocation_test, run_api_test } from "./reg-pilot-api.test"; -import { run_vlei_verification_test } from "./vlei-verification.test"; -import { runWorkflow } from "./utils/run-workflow"; + loadWorkflow, +} from "vlei-verifier-workflows"; +import { strict as assert } from "assert"; +import { + ApiTestStepRunner, + GenerateReportStepRunner, + VleiVerificationTestStepRunner, +} from "./utils/workflow-step-runners"; const fs = require("fs"); const yaml = require("js-yaml"); @@ -27,26 +25,26 @@ beforeAll((done) => { env = resolveEnvironment(); }); -// Function to load and parse YAML file -function loadWorkflow(filePath: string) { - try { - const file = fs.readFileSync(filePath, "utf8"); - return yaml.load(file); - } catch (e) { - console.error("Error reading YAML file:", e); - return null; - } -} - test.only("workflow", async function run() { const workflowsDir = "../src/workflows/"; const workflowFile = env.workflow; const workflow = loadWorkflow( path.join(__dirname, `${workflowsDir}${workflowFile}`), ); - const configFilePath = env.configuration; - const configJson = await getConfig(configFilePath, false); + const configFileName = env.configuration; + let dirPath = "../src/config/"; + const configFilePath = path.join(__dirname, dirPath) + configFileName; + const configJson = await getConfig(configFilePath); if (workflow && configJson) { - await runWorkflow(workflow, configJson); + const wr = new WorkflowRunner(workflow, configJson); + await wr.prepareClients(); + wr.registerRunner("generate_report", new GenerateReportStepRunner()); + wr.registerRunner("api_test", new ApiTestStepRunner()); + wr.registerRunner( + "vlei_verification_test", + new VleiVerificationTestStepRunner(), + ); + const workflowRunResult = await wr.runWorkflow(); + assert.equal(workflowRunResult, true); } }, 3600000); diff --git a/signify-ts-test/test/utils/run-workflow.ts b/signify-ts-test/test/utils/run-workflow.ts deleted file mode 100755 index baf825e..0000000 --- a/signify-ts-test/test/utils/run-workflow.ts +++ /dev/null @@ -1,150 +0,0 @@ -import { VleiIssuance } from "../../src/vlei-issuance"; -import path from "path"; -import { getOrCreateClients } from "./test-util"; -import { resolveEnvironment, TestEnvironment } from "./resolve-env"; -import { buildAidData } from "../../src/utils/handle-json-config"; -import { generate_reports } from "../report.test"; -import { - ApiUser, - getApiTestData, - getConfig, - getReportGenTestData, -} from "./test-data"; -import { - run_api_admin_test, - run_api_revocation_test, - run_api_test, - run_api_test_no_delegation, -} from "../reg-pilot-api.test"; -import { run_vlei_verification_test } from "../vlei-verification.test"; - -const fs = require("fs"); -const yaml = require("js-yaml"); - -// Function to load and parse YAML file -function loadWorkflow(filePath: string) { - try { - const file = fs.readFileSync(filePath, "utf8"); - return yaml.load(file); - } catch (e) { - console.error("Error reading YAML file:", e); - return null; - } -} - -export async function runWorkflow(workflow: any, configJson: any) { - let executedSteps = new Set(); - let creds: Map = new Map(); - let vi: VleiIssuance; - - for (const [k, v] of Object.entries(workflow.workflow.steps)) { - await executeStep(k, v); - } - - async function executeStep(stepName: string, step: any) { - let env = resolveEnvironment(); - if (step.type == "issue_credential") { - if (!vi) { - vi = new VleiIssuance(configJson); - await vi.prepareClients(); - await vi.createRegistries(); - } - console.log(`Executing: ${step.description}`); - const cred = await vi.getOrIssueCredential( - stepName, - step.credential, - step.attributes, - step.issuer_aid, - step.issuee_aid, - step.credential_source, - Boolean(step.generate_test_data), - step.test_name, - ); - if (cred[1]) creds.set(stepName, cred[0]); - } else if (step.type == "revoke_credential") { - console.log(`Executing: ${step.description}`); - const cred = await vi.revokeCredential( - step.credential, - step.issuer_aid, - step.issuee_aid, - Boolean(step.generate_test_data), - step.test_name, - ); - if (cred[1]) creds.set(stepName, cred[0]); - } else if (step.type == "generate_report") { - console.log(`Executing: ${step.description}`); - const testData = getReportGenTestData(); - const aidData = await buildAidData(configJson); - const clients = await getOrCreateClients( - 1, - [aidData[step.aid].agent.secret], - true, - ); - const roleClient = clients[0]; - const ecrAid = await roleClient.identifiers().get(step.aid); - const keeper = roleClient.manager!.get(ecrAid); - const failDirPrefixed = path.join( - __dirname, - "../data", - testData["failDir"], - ecrAid.prefix, - ); - const signedDirPrefixed = path.join( - __dirname, - "../data", - testData["signedDir"], - ecrAid.prefix, - ); - await generate_reports( - ecrAid, - keeper, - signedDirPrefixed, - failDirPrefixed, - testData["unsignedReports"], - testData["reportTypes"], - step.copy_folder, - ); - } else if (step.type == "api_test") { - console.log(`Executing: ${step.description}`); - const apiUsers = await getApiTestData(configJson, env, step.aids); - if (step.test_case == "api_test_revocation") { - const aidData = await buildAidData(configJson); - const clients = await getOrCreateClients( - 1, - [aidData[step.requestor_aid].agent.secret], - true, - ); - const roleClient = clients[clients.length - 1]; - const requestorAid = await roleClient - .identifiers() - .get(step.requestor_aid); - const requestorAidPrefix = requestorAid.prefix; - await run_api_revocation_test( - roleClient, - step.requestor_aid, - requestorAidPrefix, - creds, - configJson, - ); - } else if (step.test_case == "api_test_admin") { - const adminUser = await getApiTestData(configJson, env, [ - step.admin_aid, - ]); - await run_api_admin_test(apiUsers, configJson, adminUser[0]); - } else if (step.test_case == "api_test_no_delegation") { - await run_api_test_no_delegation(apiUsers, configJson); - } else if (step.test_case == "api_test") { - await run_api_test(apiUsers, configJson); - } else { - console.log(`invalid workflow API test case: ${step.test_case}`); - } - } else if (step.type == "vlei_verification_test") { - console.log(`Executing: ${step.description}`); - const apiUsers = await getApiTestData(configJson, env, step.aids); - await run_vlei_verification_test(apiUsers, configJson); - } else { - console.log(`invalid workflow step type: ${step.type}`); - } - executedSteps.add(step.id); - } -} diff --git a/signify-ts-test/test/utils/test-data.ts b/signify-ts-test/test/utils/test-data.ts index d1df57a..dfb5ca4 100644 --- a/signify-ts-test/test/utils/test-data.ts +++ b/signify-ts-test/test/utils/test-data.ts @@ -1,6 +1,6 @@ import path from "path"; import fs from "fs"; -import { buildAidData } from "../../src/utils/handle-json-config"; +import { buildAidData } from "vlei-verifier-workflows"; import { TestEnvironment } from "./resolve-env"; import { getOrCreateClients } from "./test-util"; import { ECR_SCHEMA_SAID } from "../../src/constants"; @@ -16,17 +16,6 @@ const origDir = "orig_reports"; const failDir = "fail_reports"; const signedDir = "signed_reports"; -export async function getConfig(configFilePath: string, bankTest = false) { - let dirPath = "../../src/config/"; - if (bankTest) { - dirPath = "../data/600-banks-test-data/"; - } - const configJson = JSON.parse( - fs.readFileSync(path.join(__dirname, dirPath) + configFilePath, "utf-8"), - ); - return configJson; -} - export async function getApiTestData( configJson: any, env: TestEnvironment, diff --git a/signify-ts-test/test/utils/workflow-step-runners.ts b/signify-ts-test/test/utils/workflow-step-runners.ts new file mode 100644 index 0000000..75c79e2 --- /dev/null +++ b/signify-ts-test/test/utils/workflow-step-runners.ts @@ -0,0 +1,122 @@ +import { generate_reports } from "../report.test"; +import { + StepRunner, + getOrCreateClients, + buildAidData, + VleiIssuance, +} from "vlei-verifier-workflows"; + +import { getReportGenTestData, getApiTestData } from "./test-data"; + +import { + run_api_admin_test, + run_api_revocation_test, + run_api_test, + run_api_test_no_delegation, +} from "../reg-pilot-api.test"; +import { run_vlei_verification_test } from "../vlei-verification.test"; +import { resolveEnvironment } from "./resolve-env"; + +import path from "path"; + +export class GenerateReportStepRunner extends StepRunner { + type: string = "generate_report"; + public async run( + vi: VleiIssuance, + stepName: string, + step: any, + configJson: any, + ): Promise { + const testData = getReportGenTestData(); + const aidData = await buildAidData(configJson); + const clients = await getOrCreateClients( + 1, + [aidData[step.aid].agent.secret], + true, + ); + const roleClient = clients[0]; + const ecrAid = await roleClient.identifiers().get(step.aid); + const keeper = roleClient.manager!.get(ecrAid); + const failDirPrefixed = path.join( + __dirname, + "../data", + testData["failDir"], + ecrAid.prefix, + ); + const signedDirPrefixed = path.join( + __dirname, + "../data", + testData["signedDir"], + ecrAid.prefix, + ); + const result = await generate_reports( + ecrAid, + keeper, + signedDirPrefixed, + failDirPrefixed, + testData["unsignedReports"], + testData["reportTypes"], + step.copy_folder, + ); + return result; + } +} + +export class ApiTestStepRunner extends StepRunner { + type: string = "api_test"; + public async run( + vi: VleiIssuance, + stepName: string, + step: any, + configJson: any, + ): Promise { + let env = resolveEnvironment(); + const apiUsers = await getApiTestData(configJson, env, step.aids); + let result; + if (step.test_case == "api_test_revocation") { + const aidData = await buildAidData(configJson); + const clients = await getOrCreateClients( + 1, + [aidData[step.requestor_aid].agent.secret], + true, + ); + const roleClient = clients[clients.length - 1]; + const requestorAid = await roleClient + .identifiers() + .get(step.requestor_aid); + const requestorAidPrefix = requestorAid.prefix; + result = await run_api_revocation_test( + roleClient, + step.requestor_aid, + requestorAidPrefix, + new Map(), // TODO: instead of new Map() must be map of creds. + configJson, + ); + } else if (step.test_case == "api_test_admin") { + const adminUser = await getApiTestData(configJson, env, [step.admin_aid]); + result = await run_api_admin_test(apiUsers, configJson, adminUser[0]); + } else if (step.test_case == "api_test_no_delegation") { + result = await run_api_test_no_delegation(apiUsers, configJson); + } else if (step.test_case == "api_test") { + result = await run_api_test(apiUsers, configJson); + } else { + console.log(`invalid workflow API test case: ${step.test_case}`); + } + return result; + } +} + +export class VleiVerificationTestStepRunner extends StepRunner { + type: string = "revoke_credential"; + public async run( + vi: VleiIssuance, + stepName: string, + step: any, + configJson: any = null, + ): Promise { + let env = resolveEnvironment(); + const apiUsers = await getApiTestData(configJson, env, step.aids); + const result = await run_vlei_verification_test(apiUsers, configJson); + return result; + } +} diff --git a/signify-ts-test/test/vlei-verification.test.ts b/signify-ts-test/test/vlei-verification.test.ts index 4e619f1..60267b1 100644 --- a/signify-ts-test/test/vlei-verification.test.ts +++ b/signify-ts-test/test/vlei-verification.test.ts @@ -1,16 +1,9 @@ import { strict as assert } from "assert"; import { resolveEnvironment, TestEnvironment } from "./utils/resolve-env"; -import { HabState, SignifyClient } from "signify-ts"; -import fs from "fs"; -import path from "path"; -import { - ApiUser, - getApiTestData, - getConfig, - isEbaDataSubmitter, -} from "./utils/test-data"; -import { buildUserData } from "../src/utils/handle-json-config"; +import { ApiUser, getApiTestData, isEbaDataSubmitter } from "./utils/test-data"; +import { buildUserData, getConfig } from "vlei-verifier-workflows"; import { ApiAdapter } from "../src/api-adapter"; +import path from "path"; const secretsJsonPath = "../src/config/"; const ECR_SCHEMA_SAID = "EEy9PkikFcANV1l7EHukCeXqrzT1hNZjGlUk7wuMO5jw"; @@ -31,8 +24,10 @@ beforeAll(async () => { // from the report test if (require.main === module) { test("vlei-verification", async function run() { - const configFilePath = env.configuration; - const configJson = await getConfig(configFilePath, false); + const configFileName = env.configuration; + let dirPath = "../src/config/"; + const configFilePath = path.join(__dirname, dirPath) + configFileName; + const configJson = await getConfig(configFilePath); let users = await buildUserData(configJson); users = users.filter((user) => user.type === "ECR"); const apiUsers = await getApiTestData(