From 75773449c21d32f5df060ed430cd44dfb86dfde4 Mon Sep 17 00:00:00 2001 From: Pierre Troger Date: Thu, 4 Apr 2024 16:57:01 -0400 Subject: [PATCH] wip on sdk, fixing package publishing --- package-lock.json | 483 +++++++++++++++++- package.json | 1 + packages/engine-request/package.json | 5 +- packages/engine-request/src/index.ts | 8 +- .../src/lib/builders/evaluation-request.ts | 61 ++- .../builders/request/organization-request.ts | 28 + .../lib/builders/request/request-builder.ts | 24 + .../lib/builders/request/wallet-request.ts | 220 ++++++++ packages/engine-request/src/lib/domain.ts | 24 + packages/engine-request/src/lib/narval-sdk.ts | 17 + packages/policy-engine-shared/.npmignore | 11 + packages/policy-engine-shared/.npmrc | 2 + packages/policy-engine-shared/package.json | 33 ++ packages/signature/src/lib/types.ts | 9 + 14 files changed, 909 insertions(+), 17 deletions(-) create mode 100644 packages/engine-request/src/lib/builders/request/organization-request.ts create mode 100644 packages/engine-request/src/lib/builders/request/request-builder.ts create mode 100644 packages/engine-request/src/lib/builders/request/wallet-request.ts create mode 100644 packages/engine-request/src/lib/narval-sdk.ts create mode 100644 packages/policy-engine-shared/.npmignore create mode 100644 packages/policy-engine-shared/.npmrc create mode 100644 packages/policy-engine-shared/package.json diff --git a/package-lock.json b/package-lock.json index 310650c8c..41b0eb653 100644 --- a/package-lock.json +++ b/package-lock.json @@ -73,6 +73,7 @@ "@faker-js/faker": "^8.4.0", "@nestjs/schematics": "^10.0.1", "@nestjs/testing": "^10.0.2", + "@nrwl/node": "^18.2.2", "@nx-plus/docusaurus": "^15.0.0-rc.0", "@nx/devkit": "17.1.3", "@nx/eslint": "18.1.3", @@ -7976,12 +7977,477 @@ } }, "node_modules/@nrwl/node": { - "version": "17.1.3", - "resolved": "https://registry.npmjs.org/@nrwl/node/-/node-17.1.3.tgz", - "integrity": "sha512-J/iIDuuLwM6NR0TIWEHXQmre9SdlkHbFtstae9nuTqATcZEBShBLYdR8I9piQT+QGMvwKIoWej5a3g21JBQhlg==", + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nrwl/node/-/node-18.2.2.tgz", + "integrity": "sha512-HA8Psc575XV1RsZIiyRWbhHID3HlYJc8pSrMWCAW5ycajdqYsGUtid4EQntUHwtHNEozud0mUpmdYTBJqehfWA==", "dev": true, "dependencies": { - "@nx/node": "17.1.3" + "@nx/node": "18.2.2" + } + }, + "node_modules/@nrwl/node/node_modules/@nrwl/devkit": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nrwl/devkit/-/devkit-18.2.2.tgz", + "integrity": "sha512-6RBr1aMzrpY0kk9L9buqT9H7Nv8+QujJPo4ASr6jp/5d5gPBsebeTn6qSvv1xJSB0GhB1ACOeq1nVkbwRQoQCw==", + "dev": true, + "dependencies": { + "@nx/devkit": "18.2.2" + } + }, + "node_modules/@nrwl/node/node_modules/@nrwl/jest": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nrwl/jest/-/jest-18.2.2.tgz", + "integrity": "sha512-+sjh1RYCE9wbHvdy01PhBZ7v4tgF1vupuzOy3xskBesW8p25B/ZjOEpZxiQpZvtU8aJ9r1OyncC5biKFLnkLAw==", + "dev": true, + "dependencies": { + "@nx/jest": "18.2.2" + } + }, + "node_modules/@nrwl/node/node_modules/@nrwl/js": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nrwl/js/-/js-18.2.2.tgz", + "integrity": "sha512-+COyT27frMSARYNPyFDL404nOgMmJQ0o5ap24hYond3TUuhYa5LKB0AQvEZZEz6Wb0Z/KdWRi44mw4+Gm+5Beg==", + "dev": true, + "dependencies": { + "@nx/js": "18.2.2" + } + }, + "node_modules/@nrwl/node/node_modules/@nrwl/tao": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nrwl/tao/-/tao-18.2.2.tgz", + "integrity": "sha512-tXjAbbw8Ir3cY/PQVHiC7q10jsU43r5kkEVwa2vzd1rfPtPFvj9WtgwISd+GstuppYtsbNi+UgTNmHX8dRKPYQ==", + "dev": true, + "dependencies": { + "nx": "18.2.2", + "tslib": "^2.3.0" + }, + "bin": { + "tao": "index.js" + } + }, + "node_modules/@nrwl/node/node_modules/@nrwl/workspace": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nrwl/workspace/-/workspace-18.2.2.tgz", + "integrity": "sha512-Vqd6S3IlLtIeSru84T+gX+AtMZYS7qgXTujo2ux0q2gc/AxtHp7etmiUqKuXV4Q9QqBqsxZZg+P6NWzyPJACDg==", + "dev": true, + "dependencies": { + "@nx/workspace": "18.2.2" + } + }, + "node_modules/@nrwl/node/node_modules/@nx/devkit": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/devkit/-/devkit-18.2.2.tgz", + "integrity": "sha512-Yz/uLYfy2QLeeCJecgKXuT4z0eGx/yBw3VxkgD0zSvpSIg8p1OGSK/rUQ47n/FibsLRdXa1Me5uE57rNt/FKvA==", + "dev": true, + "dependencies": { + "@nrwl/devkit": "18.2.2", + "ejs": "^3.1.7", + "enquirer": "~2.3.6", + "ignore": "^5.0.4", + "semver": "^7.5.3", + "tmp": "~0.2.1", + "tslib": "^2.3.0", + "yargs-parser": "21.1.1" + }, + "peerDependencies": { + "nx": ">= 16 <= 18" + } + }, + "node_modules/@nrwl/node/node_modules/@nx/eslint": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/eslint/-/eslint-18.2.2.tgz", + "integrity": "sha512-EHDhystP1y+8LtQfflvbHVrIdMTAoXp/xQrXiH/8U5ESbezBQUT7B75UOiWAzI+lBn9uwailMKhfEiIf4t5uRQ==", + "dev": true, + "dependencies": { + "@nx/devkit": "18.2.2", + "@nx/js": "18.2.2", + "@nx/linter": "18.2.2", + "eslint": "^8.0.0", + "tslib": "^2.3.0", + "typescript": "~5.4.2" + }, + "peerDependencies": { + "js-yaml": "4.1.0" + }, + "peerDependenciesMeta": { + "js-yaml": { + "optional": true + } + } + }, + "node_modules/@nrwl/node/node_modules/@nx/jest": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/jest/-/jest-18.2.2.tgz", + "integrity": "sha512-AEfA3IYCcQObYxKrnW5/Hu6l4Sp5wgEe/lXkYgcdOlcJkEg8DSYoS8M5soESAugka2H8CbvY6ZUXUacTjh1RIQ==", + "dev": true, + "dependencies": { + "@jest/reporters": "^29.4.1", + "@jest/test-result": "^29.4.1", + "@nrwl/jest": "18.2.2", + "@nx/devkit": "18.2.2", + "@nx/js": "18.2.2", + "@phenomnomnominal/tsquery": "~5.0.1", + "chalk": "^4.1.0", + "identity-obj-proxy": "3.0.0", + "jest-config": "^29.4.1", + "jest-resolve": "^29.4.1", + "jest-util": "^29.4.1", + "minimatch": "9.0.3", + "resolve.exports": "1.1.0", + "tslib": "^2.3.0", + "yargs-parser": "21.1.1" + } + }, + "node_modules/@nrwl/node/node_modules/@nx/js": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/js/-/js-18.2.2.tgz", + "integrity": "sha512-EQXlUW83w4D2//AXMW4AQUocBs4Nwfl15gPERahpzyTK6CKSOV3nKyORCTnVa5TgtugRXGluTbN3TxamSoWpug==", + "dev": true, + "dependencies": { + "@babel/core": "^7.23.2", + "@babel/plugin-proposal-decorators": "^7.22.7", + "@babel/plugin-transform-class-properties": "^7.22.5", + "@babel/plugin-transform-runtime": "^7.23.2", + "@babel/preset-env": "^7.23.2", + "@babel/preset-typescript": "^7.22.5", + "@babel/runtime": "^7.22.6", + "@nrwl/js": "18.2.2", + "@nx/devkit": "18.2.2", + "@nx/workspace": "18.2.2", + "@phenomnomnominal/tsquery": "~5.0.1", + "babel-plugin-const-enum": "^1.0.1", + "babel-plugin-macros": "^2.8.0", + "babel-plugin-transform-typescript-metadata": "^0.3.1", + "chalk": "^4.1.0", + "columnify": "^1.6.0", + "detect-port": "^1.5.1", + "fast-glob": "3.2.7", + "fs-extra": "^11.1.0", + "ignore": "^5.0.4", + "js-tokens": "^4.0.0", + "minimatch": "9.0.3", + "npm-package-arg": "11.0.1", + "npm-run-path": "^4.0.1", + "ora": "5.3.0", + "semver": "^7.5.3", + "source-map-support": "0.5.19", + "ts-node": "10.9.1", + "tsconfig-paths": "^4.1.2", + "tslib": "^2.3.0" + }, + "peerDependencies": { + "verdaccio": "^5.0.4" + }, + "peerDependenciesMeta": { + "verdaccio": { + "optional": true + } + } + }, + "node_modules/@nrwl/node/node_modules/@nx/linter": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/linter/-/linter-18.2.2.tgz", + "integrity": "sha512-uLgqXMhYyomPx0ruhSygPqa9Q7WtDWdwlfOs5Zgrv9xrL+wfSgVqu2sFbBp9fy1P+6BHreiAA0JAr5E/TLv1Ww==", + "dev": true, + "dependencies": { + "@nx/eslint": "18.2.2" + } + }, + "node_modules/@nrwl/node/node_modules/@nx/node": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/node/-/node-18.2.2.tgz", + "integrity": "sha512-nnsL2G6U4vtoIKi6SDOeGNkvNk0hBEDC0iWesJqt0OtF/eGNJbz9d0vtfM7byLe6lNjngHjBlpQd8QwkgWancQ==", + "dev": true, + "dependencies": { + "@nrwl/node": "18.2.2", + "@nx/devkit": "18.2.2", + "@nx/eslint": "18.2.2", + "@nx/jest": "18.2.2", + "@nx/js": "18.2.2", + "tslib": "^2.3.0" + } + }, + "node_modules/@nrwl/node/node_modules/@nx/nx-darwin-arm64": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/nx-darwin-arm64/-/nx-darwin-arm64-18.2.2.tgz", + "integrity": "sha512-mZ5X2rmtzmEGnt5ddpKlyQDGRd1wh0HSJtWvjruj6fYLNNpoosnXefI0PQLZUw13hf8OpJNo8J6xKfjIViSa8g==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nrwl/node/node_modules/@nx/nx-darwin-x64": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/nx-darwin-x64/-/nx-darwin-x64-18.2.2.tgz", + "integrity": "sha512-FeYvbr0OOIdn9xvuNZlLHQKwdAPN9KcWnmIysJTQZeanvUf6tifkhBUU1cXDduAkdut5iibnnA91JhcEj4x9yg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nrwl/node/node_modules/@nx/nx-freebsd-x64": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/nx-freebsd-x64/-/nx-freebsd-x64-18.2.2.tgz", + "integrity": "sha512-Owt/5jT8IG5I6eRbs8en+bHvi2St+k1Z1S1CLArlnfTzkTgVGz/R39HD4OouEVnr2dQPkfc7ms6+XkhlYx5NLg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nrwl/node/node_modules/@nx/nx-linux-arm-gnueabihf": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/nx-linux-arm-gnueabihf/-/nx-linux-arm-gnueabihf-18.2.2.tgz", + "integrity": "sha512-6D6ZC4EdBjAE0QgLYXuk7AC5r/LM+XUUOa5tFAV6fsAKn+GjVFsmP8dl/HEHfg+vx619+o+IrVrOA+h6ztmNJA==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nrwl/node/node_modules/@nx/nx-linux-arm64-gnu": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/nx-linux-arm64-gnu/-/nx-linux-arm64-gnu-18.2.2.tgz", + "integrity": "sha512-RHZ9nPZ4ivv9p+djO9WqoilMhjlR8/rj7P4sog5OpeRE5EWc65Rb7SFwjek1IovS2gbbK+3P2y8Q4G7lyvbe5w==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nrwl/node/node_modules/@nx/nx-linux-arm64-musl": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/nx-linux-arm64-musl/-/nx-linux-arm64-musl-18.2.2.tgz", + "integrity": "sha512-WginA4UHdrRhK40pDV8sv3Izho5aOzWf3iC8WVXi8r850mVbOE88JaWnO7TJ7zNWgiM32/OZeVyaYQ/Wv8pYjw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nrwl/node/node_modules/@nx/nx-linux-x64-gnu": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/nx-linux-x64-gnu/-/nx-linux-x64-gnu-18.2.2.tgz", + "integrity": "sha512-Fekq6TWZAN7T1Yi+IVAPQ3wUmsmtvu3WyvXiVBjVKh8C1H/PKPcNi+4kaG9Ys1BhBZhqiEfTgc44RF9xLM9IAQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nrwl/node/node_modules/@nx/nx-linux-x64-musl": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/nx-linux-x64-musl/-/nx-linux-x64-musl-18.2.2.tgz", + "integrity": "sha512-3Uk7x2/giczRCva7RsWd/KjgeYH9kOQFiqzE4heMrjBEuJQfACDlasjIrTRv9bwLrZ6otkBVeX/zmE9kBo3tOA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nrwl/node/node_modules/@nx/nx-win32-arm64-msvc": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/nx-win32-arm64-msvc/-/nx-win32-arm64-msvc-18.2.2.tgz", + "integrity": "sha512-y0d79+FYtSEI96KGAjIUrD7/xybAp7aSjqqesM0WP2+DIJBYkdjK6maTKxkB5gb3FBJyhfNYr4A1NqDnvbPtvA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nrwl/node/node_modules/@nx/nx-win32-x64-msvc": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/nx-win32-x64-msvc/-/nx-win32-x64-msvc-18.2.2.tgz", + "integrity": "sha512-17b7hh8VMGWHq0yQDxevLUM0K4ZoNUah3oYVbYe46tp1w7D4u44vDkOOE2SpV2E/alllcDES1etcVsYQSMTGig==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nrwl/node/node_modules/@nx/workspace": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@nx/workspace/-/workspace-18.2.2.tgz", + "integrity": "sha512-peZQmiibIVNoDYHgTvrd+2k14KfuquarnoDrNT4USpOz36B6usMGEOw8a2kZ+7TZ7xpCGOhDTr3jHYTg8NFBUg==", + "dev": true, + "dependencies": { + "@nrwl/workspace": "18.2.2", + "@nx/devkit": "18.2.2", + "chalk": "^4.1.0", + "enquirer": "~2.3.6", + "nx": "18.2.2", + "tslib": "^2.3.0", + "yargs-parser": "21.1.1" + } + }, + "node_modules/@nrwl/node/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@nrwl/node/node_modules/minimatch": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", + "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@nrwl/node/node_modules/nx": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/nx/-/nx-18.2.2.tgz", + "integrity": "sha512-ZEnN+2XV6QWI3q6N/I9byjSK2ErxAJJjKIWFQ45RW7+KCFbiwF0zeGnn5zruSHY7nbTrUf5C7MDA80eXam5DTg==", + "dev": true, + "hasInstallScript": true, + "dependencies": { + "@nrwl/tao": "18.2.2", + "@yarnpkg/lockfile": "^1.1.0", + "@yarnpkg/parsers": "3.0.0-rc.46", + "@zkochan/js-yaml": "0.0.6", + "axios": "^1.6.0", + "chalk": "^4.1.0", + "cli-cursor": "3.1.0", + "cli-spinners": "2.6.1", + "cliui": "^8.0.1", + "dotenv": "~16.3.1", + "dotenv-expand": "~10.0.0", + "enquirer": "~2.3.6", + "figures": "3.2.0", + "flat": "^5.0.2", + "fs-extra": "^11.1.0", + "ignore": "^5.0.4", + "jest-diff": "^29.4.1", + "js-yaml": "4.1.0", + "jsonc-parser": "3.2.0", + "lines-and-columns": "~2.0.3", + "minimatch": "9.0.3", + "node-machine-id": "1.1.12", + "npm-run-path": "^4.0.1", + "open": "^8.4.0", + "ora": "5.3.0", + "semver": "^7.5.3", + "string-width": "^4.2.3", + "strong-log-transformer": "^2.1.0", + "tar-stream": "~2.2.0", + "tmp": "~0.2.1", + "tsconfig-paths": "^4.1.2", + "tslib": "^2.3.0", + "yargs": "^17.6.2", + "yargs-parser": "21.1.1" + }, + "bin": { + "nx": "bin/nx.js", + "nx-cloud": "bin/nx-cloud.js" + }, + "optionalDependencies": { + "@nx/nx-darwin-arm64": "18.2.2", + "@nx/nx-darwin-x64": "18.2.2", + "@nx/nx-freebsd-x64": "18.2.2", + "@nx/nx-linux-arm-gnueabihf": "18.2.2", + "@nx/nx-linux-arm64-gnu": "18.2.2", + "@nx/nx-linux-arm64-musl": "18.2.2", + "@nx/nx-linux-x64-gnu": "18.2.2", + "@nx/nx-linux-x64-musl": "18.2.2", + "@nx/nx-win32-arm64-msvc": "18.2.2", + "@nx/nx-win32-x64-msvc": "18.2.2" + }, + "peerDependencies": { + "@swc-node/register": "^1.8.0", + "@swc/core": "^1.3.85" + }, + "peerDependenciesMeta": { + "@swc-node/register": { + "optional": true + }, + "@swc/core": { + "optional": true + } + } + }, + "node_modules/@nrwl/node/node_modules/typescript": { + "version": "5.4.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.4.tgz", + "integrity": "sha512-dGE2Vv8cpVvw28v8HCPqyb08EzbBURxDpuhJvTrusShUfGnhHBafDsLdS1EhhxyL6BJQE+2cT3dDPAv+MQ6oLw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" } }, "node_modules/@nrwl/nx-darwin-arm64": { @@ -10773,6 +11239,15 @@ "@nx/js": "17.1.3" } }, + "node_modules/@nx/node/node_modules/@nrwl/node": { + "version": "17.1.3", + "resolved": "https://registry.npmjs.org/@nrwl/node/-/node-17.1.3.tgz", + "integrity": "sha512-J/iIDuuLwM6NR0TIWEHXQmre9SdlkHbFtstae9nuTqATcZEBShBLYdR8I9piQT+QGMvwKIoWej5a3g21JBQhlg==", + "dev": true, + "dependencies": { + "@nx/node": "17.1.3" + } + }, "node_modules/@nx/node/node_modules/@nrwl/workspace": { "version": "17.1.3", "resolved": "https://registry.npmjs.org/@nrwl/workspace/-/workspace-17.1.3.tgz", diff --git a/package.json b/package.json index 2ec375c81..b48477449 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@faker-js/faker": "^8.4.0", "@nestjs/schematics": "^10.0.1", "@nestjs/testing": "^10.0.2", + "@nrwl/node": "^18.2.2", "@nx-plus/docusaurus": "^15.0.0-rc.0", "@nx/devkit": "17.1.3", "@nx/eslint": "18.1.3", diff --git a/packages/engine-request/package.json b/packages/engine-request/package.json index 6d8ef55c4..4d86bf995 100644 --- a/packages/engine-request/package.json +++ b/packages/engine-request/package.json @@ -4,6 +4,9 @@ "dependencies": { "tslib": "^2.3.0", "uuid": "^9.0.1", - "zod": "^3.22.4" + "zod": "^3.22.4", + "@narval-xyz/policy-engine-domain": "*", + "@narval-xyz/signature": "*", + "axios": "^1.6.7" } } diff --git a/packages/engine-request/src/index.ts b/packages/engine-request/src/index.ts index 766cc379f..7e41dd7e0 100644 --- a/packages/engine-request/src/index.ts +++ b/packages/engine-request/src/index.ts @@ -1,2 +1,6 @@ -export { buildRequest } from './lib/builders/request-builder' -export * from './lib/engine-request' +import EvaluationRequestBuilder from './lib/builders/evaluation-request' + +export { buildRequest } from './lib/builders/request/request-builder' +export { ClientConfig, Endpoints, NarvalSdkConfig, PolicyEngineConfig } from './lib/domain' +export { NarvalSdk } from './lib/narval-sdk' +export { EvaluationRequestBuilder } diff --git a/packages/engine-request/src/lib/builders/evaluation-request.ts b/packages/engine-request/src/lib/builders/evaluation-request.ts index f2d7ab9f1..d5f7d458c 100644 --- a/packages/engine-request/src/lib/builders/evaluation-request.ts +++ b/packages/engine-request/src/lib/builders/evaluation-request.ts @@ -1,22 +1,63 @@ -import { Feed, JwtString, Prices } from '@narval/policy-engine-shared' +import { EvaluationRequest, Feed, JwtString, Prices, Request } from '@narval/policy-engine-shared' +import { Jwk, Payload, SignConfig, hash, signJwt } from '@narval/signature' +import axios from 'axios' +import { Endpoints, NarvalSdkConfig } from '../domain' + +export type EvaluationRequestConfig = { + approvals?: JwtString[] + prices?: Prices + feeds?: Feed[] +} + +const buildPayloadFromRequest = (request: Request, jwk: Jwk, orgId: string): Payload => { + return { + requestHash: hash(request), + sub: jwk.kid, + iss: orgId, + iat: new Date().getTime() + } +} export default class EvaluationRequestBuilder { private approvals?: JwtString[] private prices?: Prices private feeds?: Feed[] - setApprovals(approvals: JwtString[]) { - this.approvals = approvals - return this + constructor(config?: EvaluationRequestConfig) { + this.approvals = config?.approvals + this.prices = config?.prices + this.feeds = config?.feeds } - setPrices(prices: Prices) { - this.prices = prices - return this + async sign( + request: Request, + opts: { + signConfig: SignConfig + jwk: Jwk + clientId: string + } + ): Promise { + const payload = buildPayloadFromRequest(request, opts.jwk, opts.clientId) + const { signer, opts: signingOpts } = opts.signConfig + const authentication = signer + ? await signJwt(payload, opts.jwk, signingOpts, signer) + : await signJwt(payload, opts.jwk, signingOpts) + return { + authentication, + request, + approvals: this.approvals, + prices: this.prices, + feeds: this.feeds + } } - setFeeds(feeds: Feed[]) { - this.feeds = feeds - return this + async send(request: EvaluationRequest, config: NarvalSdkConfig): Promise { + const response = await axios.post(`${config.engine.url}${Endpoints.engine.evaluations}`, request, { + headers: { + 'x-client-id': config.client.id, + 'x-client-secret': config.client.secret + } + }) + return response.data } } diff --git a/packages/engine-request/src/lib/builders/request/organization-request.ts b/packages/engine-request/src/lib/builders/request/organization-request.ts new file mode 100644 index 000000000..7a2dfb29f --- /dev/null +++ b/packages/engine-request/src/lib/builders/request/organization-request.ts @@ -0,0 +1,28 @@ +import { OrganizationAction } from '../../domain' + +export default class OrganizationBuilder { + private action: OrganizationAction | null = null + private nonce: string + + setAction(action: OrganizationAction) { + this.action = action + switch (action) { + case OrganizationAction.CREATE_ORGANIZATION: + return new CreateOrganizationBuilder() + } + } + + setNonce(nonce: string) { + this.nonce = nonce + return this + } +} + +class CreateOrganizationBuilder extends OrganizationBuilder { + private organizationId: string + + setOrganization(organizationId: string) { + this.organizationId = organizationId + return this + } +} diff --git a/packages/engine-request/src/lib/builders/request/request-builder.ts b/packages/engine-request/src/lib/builders/request/request-builder.ts new file mode 100644 index 000000000..5a1324cc7 --- /dev/null +++ b/packages/engine-request/src/lib/builders/request/request-builder.ts @@ -0,0 +1,24 @@ +import { Category } from '../../domain' +import OrganizationBuilder from './organization-request' +import WalletRequestBuilder from './wallet-request' + +/** + * Creates a request builder for either Wallet or Organization categories. + * @param category - The category of the request to build. Either 'wallet' or 'organization'. + * @returns A builder instance specific to the provided category, either WalletRequestBuilder or OrganizationBuilder. + * @example + * // For wallet-related requests + * const walletBuilder = buildRequest('wallet'); + * + * // For organization-related requests + * const organizationBuilder = buildRequest('organization'); + */ +export function buildRequest(category: 'wallet'): WalletRequestBuilder +export function buildRequest(category: 'organization'): OrganizationBuilder +export function buildRequest(category: Category): OrganizationBuilder | WalletRequestBuilder { + if (category === Category.WALLET) { + return new WalletRequestBuilder() + } else { + return new OrganizationBuilder() + } +} diff --git a/packages/engine-request/src/lib/builders/request/wallet-request.ts b/packages/engine-request/src/lib/builders/request/wallet-request.ts new file mode 100644 index 000000000..752443f37 --- /dev/null +++ b/packages/engine-request/src/lib/builders/request/wallet-request.ts @@ -0,0 +1,220 @@ +import { + Eip712TypedData, + SignMessageAction, + SignRawAction, + SignTransactionAction, + SignTypedDataAction, + TransactionRequest +} from '@narval/policy-engine-shared' +import { v4 } from 'uuid' +import { BuildResponse, WalletAction } from '../../domain' + +/** + * Builder class for creating wallet-related requests, such as signing transactions, raw data, messages, or typed data. + */ +export default class WalletRequestBuilder { + private action: WalletAction + private resourceId: string + private nonce: string + + /** + * Mandatory. Sets the action to be performed by the request. + * @param action - The specific wallet action to perform. + * @returns The builder instance specific to the action for method chaining. + * @example + * const request = buildRequest('wallet') + * .setAction('signTransaction') + * .setTransactionRequest(transactionRequest) + * @example + * const request = buildRequest('wallet') + * .setAction('signRaw') + * .setRawMessage(rawMessage) + */ + setAction(action: 'signTransaction'): SignTransactionBuilder + setAction(action: 'signRaw'): SignRawBuilder + setAction(action: 'signMessage'): SignMessageBuilder + setAction(action: 'signTypedData'): SignTypedDataBuilder + setAction(action: WalletAction) { + switch (action) { + case WalletAction.SIGN_TRANSACTION: + return new SignTransactionBuilder() + case WalletAction.SIGN_RAW: + return new SignRawBuilder() + case WalletAction.SIGN_MESSAGE: + return new SignMessageBuilder() + case WalletAction.SIGN_TYPED_DATA: + return new SignTypedDataBuilder() + default: + throw new Error(`Invalid action: ${action}`) + } + } + + /** + * Optional. Sets the unique identifier for the transaction nonce. + * @default v4() + * @optional + * @param nonce - The nonce value as a string. + * @returns The builder instance for method chaining. + */ + setNonce(nonce: string) { + this.nonce = nonce + return this + } + + protected getNonce() { + return this.nonce + } + + protected getResourceId() { + return this.resourceId + } + + /** + * Mandatory. Sets the resource identifier involved in the request, usually the wallet address. + * @param resourceId - The Ethereum wallet address as a string. + * @mandatory + * @returns The builder instance for method chaining. + */ + setResourceId(resourceId: string) { + this.resourceId = resourceId + return this + } +} + +class SignTransactionBuilder extends WalletRequestBuilder { + private transactionRequest: TransactionRequest + + setTransactionRequest(transactionRequest: TransactionRequest) { + this.transactionRequest = transactionRequest + return this + } + + /** + * Constructs and returns the final request object based on the previously provided configurations. + * @returns {BuildResponse} The final request object if all required configurations are valid, otherwise returns an error object. + */ + build(): BuildResponse { + const nonce = this.getNonce() || v4() + const request = { + action: WalletAction.SIGN_TRANSACTION, + nonce, + resourceId: this.getResourceId(), + transactionRequest: this.transactionRequest + } + const res = SignTransactionAction.safeParse(request) + return res.success + ? { + success: true, + request: res.data + } + : { + success: false, + error: res.error + } + } +} + +class SignRawBuilder extends WalletRequestBuilder { + private rawMessage: string + private alg: string + + setRawMessage(rawMessage: string) { + this.rawMessage = rawMessage + return this + } + + setAlg(alg: string) { + this.alg = alg + return this + } + + /** + * Constructs and returns the final request object based on the previously provided configurations. + * @returns {BuildResponse} The final request object if all required configurations are valid, otherwise returns an error object. + */ + build(): BuildResponse { + const nonce = this.getNonce() || v4() + const request = { + action: WalletAction.SIGN_RAW, + nonce, + resourceId: this.getResourceId(), + rawMessage: this.rawMessage + } + const res = SignRawAction.safeParse(request) + return res.success + ? { + success: true, + request: res.data + } + : { + success: false, + error: res.error + } + } +} + +class SignMessageBuilder extends WalletRequestBuilder { + private message: string + + setMessage(message: string) { + this.message = message + return this + } + + /** + * Constructs and returns the final request object based on the previously provided configurations. + * @returns {BuildResponse} The final request object if all required configurations are valid, otherwise returns an error object. + */ + build(): BuildResponse { + const nonce = this.getNonce() || v4() + const request = { + action: WalletAction.SIGN_MESSAGE, + nonce, + resourceId: this.getResourceId(), + message: this.message + } + const res = SignMessageAction.safeParse(request) + return res.success + ? { + success: true, + request: res.data + } + : { + success: false, + error: res.error + } + } +} + +class SignTypedDataBuilder extends WalletRequestBuilder { + private typedData: Eip712TypedData + + setTypedData(typedData: Eip712TypedData) { + this.typedData = typedData + return this + } + + /** + * Constructs and returns the final request object based on the previously provided configurations. + * @returns {BuildResponse} The final request object if all required configurations are valid, otherwise returns an error object. + */ + build(): BuildResponse { + const nonce = this.getNonce() || v4() + const request = { + action: WalletAction.SIGN_TYPED_DATA, + nonce, + resourceId: this.getResourceId(), + typedData: this.typedData + } + const res = SignTypedDataAction.safeParse(request) + return res.success + ? { + success: true, + request: res.data + } + : { + success: false, + error: res.error + } + } +} diff --git a/packages/engine-request/src/lib/domain.ts b/packages/engine-request/src/lib/domain.ts index b10002cc8..d4ef403d7 100644 --- a/packages/engine-request/src/lib/domain.ts +++ b/packages/engine-request/src/lib/domain.ts @@ -1,4 +1,5 @@ import { Action } from '@narval/policy-engine-shared' +import { Jwk, SignConfig } from '@narval/signature' import { ZodError } from 'zod' export const Category = { @@ -21,3 +22,26 @@ export const OrganizationAction = { export type OrganizationAction = (typeof OrganizationAction)[keyof typeof OrganizationAction] export type BuildResponse = { success: true; request: T } | { success: false; error: ZodError } + +export type PolicyEngineConfig = { + url: string +} + +export type ClientConfig = { + id: string + secret: string + credential?: Jwk + defaultSigning?: SignConfig +} + +export type NarvalSdkConfig = { + engine: PolicyEngineConfig + client: ClientConfig +} + +export const Endpoints = { + engine: { + evaluations: '/evaluations' + } +} as const +export type Endpoints = (typeof Endpoints)[keyof typeof Endpoints] diff --git a/packages/engine-request/src/lib/narval-sdk.ts b/packages/engine-request/src/lib/narval-sdk.ts new file mode 100644 index 000000000..7aa7e70c8 --- /dev/null +++ b/packages/engine-request/src/lib/narval-sdk.ts @@ -0,0 +1,17 @@ +import { Jwk } from '@narval/signature' +import EvaluationRequestBuilder from './builders/evaluation-request' +import { NarvalSdkConfig } from './domain' + +export class NarvalSdk { + private _config: NarvalSdkConfig + evaluationRequest: EvaluationRequestBuilder + + constructor(config: NarvalSdkConfig, evaluationRequest?: EvaluationRequestBuilder) { + this.evaluationRequest = evaluationRequest || new EvaluationRequestBuilder() + this._config = config + } + + set clientCredential(credential: Jwk) { + this._config.client.credential = credential + } +} diff --git a/packages/policy-engine-shared/.npmignore b/packages/policy-engine-shared/.npmignore new file mode 100644 index 000000000..ea29faba4 --- /dev/null +++ b/packages/policy-engine-shared/.npmignore @@ -0,0 +1,11 @@ +# Ignore configuration files +**/tsconfig*.json +**/jest.config.ts +**/project.json +**/*.md +**/Makefile + +# Ignore directories +**/node_modules/ +**/__tests__/ +**/__mocks__/ diff --git a/packages/policy-engine-shared/.npmrc b/packages/policy-engine-shared/.npmrc new file mode 100644 index 000000000..c881c976e --- /dev/null +++ b/packages/policy-engine-shared/.npmrc @@ -0,0 +1,2 @@ + +@narval-xyz:registry=https://npm.pkg.github.com diff --git a/packages/policy-engine-shared/package.json b/packages/policy-engine-shared/package.json new file mode 100644 index 000000000..9104a46bd --- /dev/null +++ b/packages/policy-engine-shared/package.json @@ -0,0 +1,33 @@ +{ + "name": "@narval-xyz/policy-engine-domain", + "version": "0.0.2", + "description": "Domain shared for policy engine", + "main": "../../dist/out-tsc/packages/policy-engine-shared/index.js", + "types": "../../dist/out-tsc/packages/policy-engine-shared/index.d.ts", + "scripts": { + "build": "nx build policy-engine-shared" + }, + "repository": { + "type": "git", + "url": "https://github.com/your-org/narval.git", + "directory": "packages/policy-engine-shared" + }, + "dependencies": { + "@narval-xyz/signature": "0.1.1", + "viem": "^2.7.16", + "zod": "^3.22.4", + "type-fest": "^4.14.0", + "lodash": "^4.17.21" + }, + "devDependencies": { + "@types/jest": "^29.5.12", + "@types/node": "^18.14.2", + "@types/lodash": "^4.14.202", + "@nx/eslint-plugin": "17.2.8", + "eslint-plugin-jest": "^27.9.0" + }, + "publishConfig": { + "registry": "https://npm.pkg.github.com", + "access": "restricted" + } +} diff --git a/packages/signature/src/lib/types.ts b/packages/signature/src/lib/types.ts index ed4c56147..84424ed1c 100644 --- a/packages/signature/src/lib/types.ts +++ b/packages/signature/src/lib/types.ts @@ -197,6 +197,15 @@ export const JwsdHeader = z.object({ }) export type JwsdHeader = z.infer +export const SignConfig = z.object({ + opts: z.object({ + alg: z.nativeEnum(SigningAlg) + }), + signer: z.function(z.tuple([z.string()]), z.promise(z.string())).optional() +}) + +export type SignConfig = z.infer + /** * Defines the payload of JWT. *