From b70f7e0852f0df187a070a4b518adf853860216e Mon Sep 17 00:00:00 2001 From: Yan Chen <48968912+chenyan-dfinity@users.noreply.github.com> Date: Tue, 6 Jun 2023 12:24:55 -0700 Subject: [PATCH] use mops to replace vessel, add custom domain (#173) * use mops to replace vessel * fix * fix * fix * custom domain and use binding from dfx generate --- .github/workflows/backend.yml | 13 +- .github/workflows/frontend.yml | 7 +- .gitignore | 2 +- README.md | 21 +- craco.config.js | 4 - dfx.json | 13 +- mops.toml | 4 + package-lock.json | 244 ++++++++--------- package-set.dhall | 34 --- package.json | 2 +- public/.ic-assets.json | 7 + public/.well-known/ic-domains | 2 + service/pool/tests/actor_class/dfx.json | 2 +- service/wasm-utils/build.sh | 3 +- src/config/actor.js | 10 +- src/config/generateAliases.js | 22 -- src/config/jest.config.js | 11 - src/declarations/backend/backend.did | 128 +++++++++ src/declarations/backend/backend.did.d.ts | 112 ++++++++ src/declarations/backend/backend.did.js | 159 +++++++++++ src/declarations/backend/index.d.ts | 50 ++++ src/declarations/backend/index.js | 42 +++ src/declarations/react_app/index.d.ts | 50 ++++ src/declarations/react_app/index.js | 42 +++ src/declarations/react_app/react_app.did | 228 ++++++++++++++++ src/declarations/react_app/react_app.did.d.ts | 206 +++++++++++++++ src/declarations/react_app/react_app.did.js | 247 ++++++++++++++++++ src/declarations/saved/index.d.ts | 50 ++++ src/declarations/saved/index.js | 42 +++ src/declarations/saved/saved.did | 42 +++ src/declarations/saved/saved.did.d.ts | 39 +++ src/declarations/saved/saved.did.js | 35 +++ src/declarations/wasm-utils/index.d.ts | 50 ++++ src/declarations/wasm-utils/index.js | 42 +++ src/declarations/wasm-utils/wasm-utils.did | 5 + .../wasm-utils/wasm-utils.did.d.ts | 15 ++ src/declarations/wasm-utils/wasm-utils.did.js | 14 + vessel.dhall | 4 - 38 files changed, 1765 insertions(+), 238 deletions(-) create mode 100644 mops.toml delete mode 100644 package-set.dhall create mode 100644 public/.ic-assets.json create mode 100644 public/.well-known/ic-domains delete mode 100644 src/config/generateAliases.js delete mode 100644 src/config/jest.config.js create mode 100644 src/declarations/backend/backend.did create mode 100644 src/declarations/backend/backend.did.d.ts create mode 100644 src/declarations/backend/backend.did.js create mode 100644 src/declarations/backend/index.d.ts create mode 100644 src/declarations/backend/index.js create mode 100644 src/declarations/react_app/index.d.ts create mode 100644 src/declarations/react_app/index.js create mode 100644 src/declarations/react_app/react_app.did create mode 100644 src/declarations/react_app/react_app.did.d.ts create mode 100644 src/declarations/react_app/react_app.did.js create mode 100644 src/declarations/saved/index.d.ts create mode 100644 src/declarations/saved/index.js create mode 100644 src/declarations/saved/saved.did create mode 100644 src/declarations/saved/saved.did.d.ts create mode 100644 src/declarations/saved/saved.did.js create mode 100644 src/declarations/wasm-utils/index.d.ts create mode 100644 src/declarations/wasm-utils/index.js create mode 100644 src/declarations/wasm-utils/wasm-utils.did create mode 100644 src/declarations/wasm-utils/wasm-utils.did.d.ts create mode 100644 src/declarations/wasm-utils/wasm-utils.did.js delete mode 100644 vessel.dhall diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 5fcf223a..268fbe34 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -14,9 +14,8 @@ jobs: strategy: fail-fast: false env: - DFX_VERSION: 0.14.0 - VESSEL_VERSION: v0.6.4 - IC_REPL_VERSION: 0.3.18 + DFX_VERSION: 0.14.1 + IC_REPL_VERSION: 0.4.0 MOC_VERSION: 0.9.1 steps: - uses: actions/checkout@v2 @@ -37,16 +36,16 @@ jobs: ~/.cargo/git service/wasm-utils/target key: cargo-${{ hashFiles('**/Cargo.lock') }} + - uses: actions/setup-node@v3 + with: + node-version: 18 - name: Install dfx run: | echo y | DFX_VERSION=$DFX_VERSION bash -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" wget https://github.com/chenyan2002/ic-repl/releases/download/$IC_REPL_VERSION/ic-repl-linux64 cp ./ic-repl-linux64 /usr/local/bin/ic-repl chmod a+x /usr/local/bin/ic-repl - wget https://github.com/dfinity/vessel/releases/download/$VESSEL_VERSION/vessel-linux64 - cp ./vessel-linux64 /usr/local/bin/vessel - chmod a+x /usr/local/bin/vessel - sudo apt-get install -y binaryen + npm i -g ic-mops dfx cache install cd $(dfx cache show) wget https://github.com/dfinity/motoko/releases/download/$MOC_VERSION/motoko-linux64-$MOC_VERSION.tar.gz diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index d4d23052..73be690b 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -21,8 +21,7 @@ jobs: - 14 - 16 env: - DFX_VERSION: 0.14.0 - VESSEL_VERSION: v0.6.4 + DFX_VERSION: 0.14.1 SKIP_WASM: true MOC_VERSION: 0.9.1 steps: @@ -36,9 +35,7 @@ jobs: - name: Install dfx run: | echo y | DFX_VERSION=$DFX_VERSION bash -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" - wget https://github.com/dfinity/vessel/releases/download/$VESSEL_VERSION/vessel-linux64 - cp ./vessel-linux64 /usr/local/bin/vessel - chmod a+x /usr/local/bin/vessel + npm i -g ic-mops dfx cache install cd $(dfx cache show) wget https://github.com/dfinity/motoko/releases/download/$MOC_VERSION/motoko-linux64-$MOC_VERSION.tar.gz diff --git a/.gitignore b/.gitignore index cb641e53..8fa347c3 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,7 @@ yarn-debug.log* yarn-error.log* .eslintcache -.vessel +.mops /service/wasm-utils/*.old.did diff --git a/README.md b/README.md index 1cc3f073..f45b57b7 100644 --- a/README.md +++ b/README.md @@ -26,31 +26,20 @@ We plan on adding many more features to make playground a full-featured web IDE - [Install Internet Computer SDK](https://sdk.dfinity.org/docs/quickstart/local-quickstart.html) - [Install npm](https://nodejs.org/en/download/) -- [Install Vessel](https://github.com/dfinity/vessel/releases) - - Download the latest release to your `/usr/local/bin` folder - - Rename from `vessel-{platform}` to `vessel` - - Run `chmod +x /usr/local/bin/vessel` +- [Install mops](https://mops.one/docs/install) + ``` + npm i -g ic-mops + ``` - [Install Rust](https://www.rust-lang.org/tools/install) - Add wasm32 target to Rust ``` rustup target add wasm32-unknown-unknown ``` -- Install binaryen - - ``` - apt install binaryen - ``` - - or - - ``` - brew install binaryen - ``` ### To run the Motoko Playground locally, proceed as follows after cloning the respository: ```sh -npm install # Install `npm` and `vessel` dependencies +npm install # Install `npm` dependencies npm start # Run the local development server ``` diff --git a/craco.config.js b/craco.config.js index bc515f0e..ce9ffa54 100644 --- a/craco.config.js +++ b/craco.config.js @@ -1,9 +1,6 @@ const { addBeforeLoader, loaderByName } = require("@craco/craco"); -const generateAliases = require("./src/config/generateAliases"); const webpack = require("webpack"); -const aliases = generateAliases(); - let canisterEnv; function initCanisterIds() { @@ -36,7 +33,6 @@ function initCanisterIds() { initCanisterIds(); const overrideWebpackConfig = ({ webpackConfig }) => { - webpackConfig.resolve.alias = { ...webpackConfig.resolve.alias, ...aliases }; webpackConfig.resolve.plugins = webpackConfig.resolve.plugins.filter( (plugin) => // Removes ModuleScopePlugin so `dfx-generated/` aliases work correctly diff --git a/dfx.json b/dfx.json index 58d409c0..88dc176d 100644 --- a/dfx.json +++ b/dfx.json @@ -3,17 +3,20 @@ "wasm-utils": { "type": "custom", "candid": "service/wasm-utils/wasm-utils.did", - "wasm": "service/wasm-utils/target/wasm32-unknown-unknown/release/wasm_opt.wasm", - "build": ["sh -c 'cd service/wasm-utils && ./build.sh'"] + "wasm": "service/wasm-utils/target/wasm32-unknown-unknown/release/wasm_utils.wasm", + "build": ["sh -c 'cd service/wasm-utils && ./build.sh'"], + "optimize": "cycles" }, "backend": { "dependencies": ["wasm-utils"], "main": "service/pool/Main.mo", - "type": "motoko" + "type": "motoko", + "optimize": "cycles" }, "saved": { "main": "service/saved/Saved.mo", - "type": "motoko" + "type": "motoko", + "optimize": "cycles" }, "react_app": { "dependencies": ["backend", "saved"], @@ -27,7 +30,7 @@ "defaults": { "build": { "output": "build", - "packtool": "vessel sources" + "packtool": "mops sources" } } } diff --git a/mops.toml b/mops.toml new file mode 100644 index 00000000..8693cd47 --- /dev/null +++ b/mops.toml @@ -0,0 +1,4 @@ +[dependencies] +base = "0.9.1" +splay = "0.1.0" + diff --git a/package-lock.json b/package-lock.json index f62255ed..7007e822 100644 --- a/package-lock.json +++ b/package-lock.json @@ -70,30 +70,30 @@ } }, "node_modules/@babel/compat-data": { - "version": "7.21.7", - "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.21.7.tgz", - "integrity": "sha512-KYMqFYTaenzMK4yUtf4EW9wc4N9ef80FsbMtkwool5zpwl4YrT1SdWYSTRcT94KO4hannogdS+LxY7L+arP3gA==", + "version": "7.22.3", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.22.3.tgz", + "integrity": "sha512-aNtko9OPOwVESUFp3MZfD8Uzxl7JzSeJpd7npIoxCasU37PFbAQRpKglkaKwlHOyeJdrREpo8TW8ldrkYWwvIQ==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/core": { - "version": "7.21.8", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.21.8.tgz", - "integrity": "sha512-YeM22Sondbo523Sz0+CirSPnbj9bG3P0CdHcBZdqUuaeOaYEFbOLoGU7lebvGP6P5J/WE9wOn7u7C4J9HvS1xQ==", + "version": "7.22.1", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.22.1.tgz", + "integrity": "sha512-Hkqu7J4ynysSXxmAahpN1jjRwVJ+NdpraFLIWflgjpVob3KNyK3/tIUc7Q7szed8WMp0JNa7Qtd1E9Oo22F9gA==", "dev": true, "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.21.4", - "@babel/generator": "^7.21.5", - "@babel/helper-compilation-targets": "^7.21.5", - "@babel/helper-module-transforms": "^7.21.5", - "@babel/helpers": "^7.21.5", - "@babel/parser": "^7.21.8", - "@babel/template": "^7.20.7", - "@babel/traverse": "^7.21.5", - "@babel/types": "^7.21.5", + "@babel/generator": "^7.22.0", + "@babel/helper-compilation-targets": "^7.22.1", + "@babel/helper-module-transforms": "^7.22.1", + "@babel/helpers": "^7.22.0", + "@babel/parser": "^7.22.0", + "@babel/template": "^7.21.9", + "@babel/traverse": "^7.22.1", + "@babel/types": "^7.22.0", "convert-source-map": "^1.7.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -129,11 +129,11 @@ } }, "node_modules/@babel/generator": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.21.5.tgz", - "integrity": "sha512-SrKK/sRv8GesIW1bDagf9cCG38IOMYZusoe1dfg0D8aiUe3Amvoj1QtjTPAWcfrZFvIwlleLb0gxzQidL9w14w==", + "version": "7.22.3", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.22.3.tgz", + "integrity": "sha512-C17MW4wlk//ES/CJDL51kPNwl+qiBQyN7b9SKyVp11BLGFeSPoVaHrv+MNt8jwQFhQWowW88z1eeBx3pFz9v8A==", "dependencies": { - "@babel/types": "^7.21.5", + "@babel/types": "^7.22.3", "@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" @@ -177,12 +177,12 @@ } }, "node_modules/@babel/helper-compilation-targets": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.21.5.tgz", - "integrity": "sha512-1RkbFGUKex4lvsB9yhIfWltJM5cZKUftB2eNajaDv3dCMEp49iBG0K14uH8NnX9IPux2+mK7JGEOB0jn48/J6w==", + "version": "7.22.1", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.22.1.tgz", + "integrity": "sha512-Rqx13UM3yVB5q0D/KwQ8+SPfX/+Rnsy1Lw1k/UwOC4KC6qrzIQoY3lYnBu5EHKBlEHHcj0M0W8ltPSkD8rqfsQ==", "dev": true, "dependencies": { - "@babel/compat-data": "^7.21.5", + "@babel/compat-data": "^7.22.0", "@babel/helper-validator-option": "^7.21.0", "browserslist": "^4.21.3", "lru-cache": "^5.1.1", @@ -279,9 +279,9 @@ } }, "node_modules/@babel/helper-environment-visitor": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.21.5.tgz", - "integrity": "sha512-IYl4gZ3ETsWocUWgsFZLM5i1BYx9SoemminVEXadgLBa9TdeorzgLKm8wWLA6J1N/kT3Kch8XIk1laNzYoHKvQ==", + "version": "7.22.1", + "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.1.tgz", + "integrity": "sha512-Z2tgopurB/kTbidvzeBrc2To3PUP/9i5MUe+fU6QJCQDyPwSH2oRapkLw3KGECDYSjhQZCNxEvNvZlLw8JjGwA==", "engines": { "node": ">=6.9.0" } @@ -342,19 +342,19 @@ } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.21.5.tgz", - "integrity": "sha512-bI2Z9zBGY2q5yMHoBvJ2a9iX3ZOAzJPm7Q8Yz6YeoUjU/Cvhmi2G4QyTNyPBqqXSgTjUxRg3L0xV45HvkNWWBw==", + "version": "7.22.1", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.22.1.tgz", + "integrity": "sha512-dxAe9E7ySDGbQdCVOY/4+UcD8M9ZFqZcZhSPsPacvCG4M+9lwtDDQfI2EoaSvmf7W/8yCBkGU0m7Pvt1ru3UZw==", "dev": true, "dependencies": { - "@babel/helper-environment-visitor": "^7.21.5", + "@babel/helper-environment-visitor": "^7.22.1", "@babel/helper-module-imports": "^7.21.4", "@babel/helper-simple-access": "^7.21.5", "@babel/helper-split-export-declaration": "^7.18.6", "@babel/helper-validator-identifier": "^7.19.1", - "@babel/template": "^7.20.7", - "@babel/traverse": "^7.21.5", - "@babel/types": "^7.21.5" + "@babel/template": "^7.21.9", + "@babel/traverse": "^7.22.1", + "@babel/types": "^7.22.0" }, "engines": { "node": ">=6.9.0" @@ -479,14 +479,14 @@ } }, "node_modules/@babel/helpers": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.21.5.tgz", - "integrity": "sha512-BSY+JSlHxOmGsPTydUkPf1MdMQ3M81x5xGCOVgWM3G8XH77sJ292Y2oqcp0CbbgxhqBuI46iUz1tT7hqP7EfgA==", + "version": "7.22.3", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.22.3.tgz", + "integrity": "sha512-jBJ7jWblbgr7r6wYZHMdIqKc73ycaTcCaWRq4/2LpuPHcx7xMlZvpGQkOYc9HeSjn6rcx15CPlgVcBtZ4WZJ2w==", "dev": true, "dependencies": { - "@babel/template": "^7.20.7", - "@babel/traverse": "^7.21.5", - "@babel/types": "^7.21.5" + "@babel/template": "^7.21.9", + "@babel/traverse": "^7.22.1", + "@babel/types": "^7.22.3" }, "engines": { "node": ">=6.9.0" @@ -544,9 +544,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.21.8", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.21.8.tgz", - "integrity": "sha512-6zavDGdzG3gUqAdWvlLFfk+36RilI+Pwyuuh7HItyeScCWP3k6i8vKclAQ0bM/0y/Kz/xiwvxhMv9MgTJP5gmA==", + "version": "7.22.4", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.22.4.tgz", + "integrity": "sha512-VLLsx06XkEYqBtE5YGPwfSGwfrjnyPP5oiGty3S8pQLFDFLaS8VwWSIxkTXpcvr5zeYLE6+MBNl2npl/YnfofA==", "bin": { "parser": "bin/babel-parser.js" }, @@ -1679,31 +1679,31 @@ } }, "node_modules/@babel/template": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.20.7.tgz", - "integrity": "sha512-8SegXApWe6VoNw0r9JHpSteLKTpTiLZ4rMlGIm9JQ18KiCtyQiAMEazujAHrUS5flrcqYZa75ukev3P6QmUwUw==", + "version": "7.21.9", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.21.9.tgz", + "integrity": "sha512-MK0X5k8NKOuWRamiEfc3KEJiHMTkGZNUjzMipqCGDDc6ijRl/B7RGSKVGncu4Ro/HdyzzY6cmoXuKI2Gffk7vQ==", "dependencies": { - "@babel/code-frame": "^7.18.6", - "@babel/parser": "^7.20.7", - "@babel/types": "^7.20.7" + "@babel/code-frame": "^7.21.4", + "@babel/parser": "^7.21.9", + "@babel/types": "^7.21.5" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/traverse": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.21.5.tgz", - "integrity": "sha512-AhQoI3YjWi6u/y/ntv7k48mcrCXmus0t79J9qPNlk/lAsFlCiJ047RmbfMOawySTHtywXhbXgpx/8nXMYd+oFw==", + "version": "7.22.4", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.22.4.tgz", + "integrity": "sha512-Tn1pDsjIcI+JcLKq1AVlZEr4226gpuAQTsLMorsYg9tuS/kG7nuwwJ4AB8jfQuEgb/COBwR/DqJxmoiYFu5/rQ==", "dependencies": { "@babel/code-frame": "^7.21.4", - "@babel/generator": "^7.21.5", - "@babel/helper-environment-visitor": "^7.21.5", + "@babel/generator": "^7.22.3", + "@babel/helper-environment-visitor": "^7.22.1", "@babel/helper-function-name": "^7.21.0", "@babel/helper-hoist-variables": "^7.18.6", "@babel/helper-split-export-declaration": "^7.18.6", - "@babel/parser": "^7.21.5", - "@babel/types": "^7.21.5", + "@babel/parser": "^7.22.4", + "@babel/types": "^7.22.4", "debug": "^4.1.0", "globals": "^11.1.0" }, @@ -1712,9 +1712,9 @@ } }, "node_modules/@babel/types": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.21.5.tgz", - "integrity": "sha512-m4AfNvVF2mVC/F7fDEdH2El3HzUg9It/XsCxZiOTTA3m3qYfcSVSbTfM6Q9xG+hYDniZssYhlXKKUMD5m8tF4Q==", + "version": "7.22.4", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.22.4.tgz", + "integrity": "sha512-Tx9x3UBHTTsMSW85WB2kphxYQVvrZ/t1FxD88IpSgIjiUJlCm9z+xWIDwyo1vffTwSqteqyznB8ZE9vYYk16zA==", "dependencies": { "@babel/helper-string-parser": "^7.21.5", "@babel/helper-validator-identifier": "^7.19.1", @@ -5672,9 +5672,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001435", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001435.tgz", - "integrity": "sha512-kdCkUTjR+v4YAJelyiDTqiu82BDr4W4CP5sgTA0ZBmqn30XfS2ZghPLMowik9TPhS+psWJiUNxsqLyurDbmutA==", + "version": "1.0.30001495", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001495.tgz", + "integrity": "sha512-F6x5IEuigtUfU5ZMQK2jsy5JqUUlEFRVZq8bO2a+ysq5K7jD6PPc9YXZj78xDNS3uNchesp1Jw47YXEqr+Viyg==", "dev": true, "funding": [ { @@ -5684,6 +5684,10 @@ { "type": "tidelift", "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" } ] }, @@ -21640,27 +21644,27 @@ } }, "@babel/compat-data": { - "version": "7.21.7", - "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.21.7.tgz", - "integrity": "sha512-KYMqFYTaenzMK4yUtf4EW9wc4N9ef80FsbMtkwool5zpwl4YrT1SdWYSTRcT94KO4hannogdS+LxY7L+arP3gA==", + "version": "7.22.3", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.22.3.tgz", + "integrity": "sha512-aNtko9OPOwVESUFp3MZfD8Uzxl7JzSeJpd7npIoxCasU37PFbAQRpKglkaKwlHOyeJdrREpo8TW8ldrkYWwvIQ==", "dev": true }, "@babel/core": { - "version": "7.21.8", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.21.8.tgz", - "integrity": "sha512-YeM22Sondbo523Sz0+CirSPnbj9bG3P0CdHcBZdqUuaeOaYEFbOLoGU7lebvGP6P5J/WE9wOn7u7C4J9HvS1xQ==", + "version": "7.22.1", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.22.1.tgz", + "integrity": "sha512-Hkqu7J4ynysSXxmAahpN1jjRwVJ+NdpraFLIWflgjpVob3KNyK3/tIUc7Q7szed8WMp0JNa7Qtd1E9Oo22F9gA==", "dev": true, "requires": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.21.4", - "@babel/generator": "^7.21.5", - "@babel/helper-compilation-targets": "^7.21.5", - "@babel/helper-module-transforms": "^7.21.5", - "@babel/helpers": "^7.21.5", - "@babel/parser": "^7.21.8", - "@babel/template": "^7.20.7", - "@babel/traverse": "^7.21.5", - "@babel/types": "^7.21.5", + "@babel/generator": "^7.22.0", + "@babel/helper-compilation-targets": "^7.22.1", + "@babel/helper-module-transforms": "^7.22.1", + "@babel/helpers": "^7.22.0", + "@babel/parser": "^7.22.0", + "@babel/template": "^7.21.9", + "@babel/traverse": "^7.22.1", + "@babel/types": "^7.22.0", "convert-source-map": "^1.7.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -21681,11 +21685,11 @@ } }, "@babel/generator": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.21.5.tgz", - "integrity": "sha512-SrKK/sRv8GesIW1bDagf9cCG38IOMYZusoe1dfg0D8aiUe3Amvoj1QtjTPAWcfrZFvIwlleLb0gxzQidL9w14w==", + "version": "7.22.3", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.22.3.tgz", + "integrity": "sha512-C17MW4wlk//ES/CJDL51kPNwl+qiBQyN7b9SKyVp11BLGFeSPoVaHrv+MNt8jwQFhQWowW88z1eeBx3pFz9v8A==", "requires": { - "@babel/types": "^7.21.5", + "@babel/types": "^7.22.3", "@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" @@ -21716,12 +21720,12 @@ } }, "@babel/helper-compilation-targets": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.21.5.tgz", - "integrity": "sha512-1RkbFGUKex4lvsB9yhIfWltJM5cZKUftB2eNajaDv3dCMEp49iBG0K14uH8NnX9IPux2+mK7JGEOB0jn48/J6w==", + "version": "7.22.1", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.22.1.tgz", + "integrity": "sha512-Rqx13UM3yVB5q0D/KwQ8+SPfX/+Rnsy1Lw1k/UwOC4KC6qrzIQoY3lYnBu5EHKBlEHHcj0M0W8ltPSkD8rqfsQ==", "dev": true, "requires": { - "@babel/compat-data": "^7.21.5", + "@babel/compat-data": "^7.22.0", "@babel/helper-validator-option": "^7.21.0", "browserslist": "^4.21.3", "lru-cache": "^5.1.1", @@ -21790,9 +21794,9 @@ } }, "@babel/helper-environment-visitor": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.21.5.tgz", - "integrity": "sha512-IYl4gZ3ETsWocUWgsFZLM5i1BYx9SoemminVEXadgLBa9TdeorzgLKm8wWLA6J1N/kT3Kch8XIk1laNzYoHKvQ==" + "version": "7.22.1", + "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.1.tgz", + "integrity": "sha512-Z2tgopurB/kTbidvzeBrc2To3PUP/9i5MUe+fU6QJCQDyPwSH2oRapkLw3KGECDYSjhQZCNxEvNvZlLw8JjGwA==" }, "@babel/helper-explode-assignable-expression": { "version": "7.14.5", @@ -21832,19 +21836,19 @@ } }, "@babel/helper-module-transforms": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.21.5.tgz", - "integrity": "sha512-bI2Z9zBGY2q5yMHoBvJ2a9iX3ZOAzJPm7Q8Yz6YeoUjU/Cvhmi2G4QyTNyPBqqXSgTjUxRg3L0xV45HvkNWWBw==", + "version": "7.22.1", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.22.1.tgz", + "integrity": "sha512-dxAe9E7ySDGbQdCVOY/4+UcD8M9ZFqZcZhSPsPacvCG4M+9lwtDDQfI2EoaSvmf7W/8yCBkGU0m7Pvt1ru3UZw==", "dev": true, "requires": { - "@babel/helper-environment-visitor": "^7.21.5", + "@babel/helper-environment-visitor": "^7.22.1", "@babel/helper-module-imports": "^7.21.4", "@babel/helper-simple-access": "^7.21.5", "@babel/helper-split-export-declaration": "^7.18.6", "@babel/helper-validator-identifier": "^7.19.1", - "@babel/template": "^7.20.7", - "@babel/traverse": "^7.21.5", - "@babel/types": "^7.21.5" + "@babel/template": "^7.21.9", + "@babel/traverse": "^7.22.1", + "@babel/types": "^7.22.0" } }, "@babel/helper-optimise-call-expression": { @@ -21926,14 +21930,14 @@ } }, "@babel/helpers": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.21.5.tgz", - "integrity": "sha512-BSY+JSlHxOmGsPTydUkPf1MdMQ3M81x5xGCOVgWM3G8XH77sJ292Y2oqcp0CbbgxhqBuI46iUz1tT7hqP7EfgA==", + "version": "7.22.3", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.22.3.tgz", + "integrity": "sha512-jBJ7jWblbgr7r6wYZHMdIqKc73ycaTcCaWRq4/2LpuPHcx7xMlZvpGQkOYc9HeSjn6rcx15CPlgVcBtZ4WZJ2w==", "dev": true, "requires": { - "@babel/template": "^7.20.7", - "@babel/traverse": "^7.21.5", - "@babel/types": "^7.21.5" + "@babel/template": "^7.21.9", + "@babel/traverse": "^7.22.1", + "@babel/types": "^7.22.3" } }, "@babel/highlight": { @@ -21970,9 +21974,9 @@ } }, "@babel/parser": { - "version": "7.21.8", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.21.8.tgz", - "integrity": "sha512-6zavDGdzG3gUqAdWvlLFfk+36RilI+Pwyuuh7HItyeScCWP3k6i8vKclAQ0bM/0y/Kz/xiwvxhMv9MgTJP5gmA==" + "version": "7.22.4", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.22.4.tgz", + "integrity": "sha512-VLLsx06XkEYqBtE5YGPwfSGwfrjnyPP5oiGty3S8pQLFDFLaS8VwWSIxkTXpcvr5zeYLE6+MBNl2npl/YnfofA==" }, "@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": { "version": "7.14.5", @@ -22628,36 +22632,36 @@ } }, "@babel/template": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.20.7.tgz", - "integrity": "sha512-8SegXApWe6VoNw0r9JHpSteLKTpTiLZ4rMlGIm9JQ18KiCtyQiAMEazujAHrUS5flrcqYZa75ukev3P6QmUwUw==", + "version": "7.21.9", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.21.9.tgz", + "integrity": "sha512-MK0X5k8NKOuWRamiEfc3KEJiHMTkGZNUjzMipqCGDDc6ijRl/B7RGSKVGncu4Ro/HdyzzY6cmoXuKI2Gffk7vQ==", "requires": { - "@babel/code-frame": "^7.18.6", - "@babel/parser": "^7.20.7", - "@babel/types": "^7.20.7" + "@babel/code-frame": "^7.21.4", + "@babel/parser": "^7.21.9", + "@babel/types": "^7.21.5" } }, "@babel/traverse": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.21.5.tgz", - "integrity": "sha512-AhQoI3YjWi6u/y/ntv7k48mcrCXmus0t79J9qPNlk/lAsFlCiJ047RmbfMOawySTHtywXhbXgpx/8nXMYd+oFw==", + "version": "7.22.4", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.22.4.tgz", + "integrity": "sha512-Tn1pDsjIcI+JcLKq1AVlZEr4226gpuAQTsLMorsYg9tuS/kG7nuwwJ4AB8jfQuEgb/COBwR/DqJxmoiYFu5/rQ==", "requires": { "@babel/code-frame": "^7.21.4", - "@babel/generator": "^7.21.5", - "@babel/helper-environment-visitor": "^7.21.5", + "@babel/generator": "^7.22.3", + "@babel/helper-environment-visitor": "^7.22.1", "@babel/helper-function-name": "^7.21.0", "@babel/helper-hoist-variables": "^7.18.6", "@babel/helper-split-export-declaration": "^7.18.6", - "@babel/parser": "^7.21.5", - "@babel/types": "^7.21.5", + "@babel/parser": "^7.22.4", + "@babel/types": "^7.22.4", "debug": "^4.1.0", "globals": "^11.1.0" } }, "@babel/types": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.21.5.tgz", - "integrity": "sha512-m4AfNvVF2mVC/F7fDEdH2El3HzUg9It/XsCxZiOTTA3m3qYfcSVSbTfM6Q9xG+hYDniZssYhlXKKUMD5m8tF4Q==", + "version": "7.22.4", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.22.4.tgz", + "integrity": "sha512-Tx9x3UBHTTsMSW85WB2kphxYQVvrZ/t1FxD88IpSgIjiUJlCm9z+xWIDwyo1vffTwSqteqyznB8ZE9vYYk16zA==", "requires": { "@babel/helper-string-parser": "^7.21.5", "@babel/helper-validator-identifier": "^7.19.1", @@ -25441,9 +25445,9 @@ } }, "caniuse-lite": { - "version": "1.0.30001435", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001435.tgz", - "integrity": "sha512-kdCkUTjR+v4YAJelyiDTqiu82BDr4W4CP5sgTA0ZBmqn30XfS2ZghPLMowik9TPhS+psWJiUNxsqLyurDbmutA==", + "version": "1.0.30001495", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001495.tgz", + "integrity": "sha512-F6x5IEuigtUfU5ZMQK2jsy5JqUUlEFRVZq8bO2a+ysq5K7jD6PPc9YXZj78xDNS3uNchesp1Jw47YXEqr+Viyg==", "dev": true }, "capture-exit": { diff --git a/package-set.dhall b/package-set.dhall deleted file mode 100644 index 28899328..00000000 --- a/package-set.dhall +++ /dev/null @@ -1,34 +0,0 @@ -let upstream = - https://github.com/dfinity/vessel-package-set/releases/download/mo-0.6.18-20220107/package-set.dhall - sha256:af8b8dbe762468ce9b002fb0c62e65e1a3ee0d003e793c4404a16f8531a71b59 - -let Package = - { name : Text, version : Text, repo : Text, dependencies : List Text } - -let - -- This is where you can add your own packages to the package-set - additions = - [ { name = "base" - , repo = "https://github.com/dfinity/motoko-base" - , version = "master" - , dependencies = [] : List Text - } - ] - : List Package - -let - {- This is where you can override existing packages in the package-set - - For example, if you wanted to use version `v2.0.0` of the foo library: - let overrides = [ - { name = "foo" - , version = "v2.0.0" - , repo = "https://github.com/bar/foo" - , dependencies = [] : List Text - } - ] - -} - overrides = - [] : List Package - -in upstream # additions # overrides diff --git a/package.json b/package.json index eedea854..c39b7a77 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "prestart": "dfx start --background; [ -f .dfx/local/canister_ids.json ] || dfx deploy", "predeploy": "npm run prestart", "prepare": "husky install", - "postinstall": "vessel install" + "postinstall": "mops install" }, "eslintConfig": { "extends": [ diff --git a/public/.ic-assets.json b/public/.ic-assets.json new file mode 100644 index 00000000..3d24b417 --- /dev/null +++ b/public/.ic-assets.json @@ -0,0 +1,7 @@ +[ + { + "match": ".well-known", + "ignore": false + } +] + diff --git a/public/.well-known/ic-domains b/public/.well-known/ic-domains new file mode 100644 index 00000000..8551e44c --- /dev/null +++ b/public/.well-known/ic-domains @@ -0,0 +1,2 @@ +play.motoko.org + diff --git a/service/pool/tests/actor_class/dfx.json b/service/pool/tests/actor_class/dfx.json index 62240cf1..bc68dbd8 100644 --- a/service/pool/tests/actor_class/dfx.json +++ b/service/pool/tests/actor_class/dfx.json @@ -11,7 +11,7 @@ }, "defaults": { "build": { - "packtool": "vessel sources" + "packtool": "mops sources" } } } diff --git a/service/wasm-utils/build.sh b/service/wasm-utils/build.sh index 83f362c7..7a4da000 100755 --- a/service/wasm-utils/build.sh +++ b/service/wasm-utils/build.sh @@ -5,9 +5,8 @@ set -e if [ "$SKIP_WASM" == "true" ]; then mkdir -p target/wasm32-unknown-unknown/release - echo -n -e '\x00\x61\x73\x6d\x01\x00\x00\x00' > target/wasm32-unknown-unknown/release/wasm_opt.wasm + echo -n -e '\x00\x61\x73\x6d\x01\x00\x00\x00' > target/wasm32-unknown-unknown/release/wasm_utils.wasm echo "skip" else cargo build --target wasm32-unknown-unknown --release --package wasm-utils - wasm-opt --strip-debug target/wasm32-unknown-unknown/release/wasm_utils.wasm -o target/wasm32-unknown-unknown/release/wasm_opt.wasm fi diff --git a/src/config/actor.js b/src/config/actor.js index 9fb9befa..549c2f50 100644 --- a/src/config/actor.js +++ b/src/config/actor.js @@ -1,11 +1,11 @@ import { Actor, HttpAgent, ActorSubclass } from "@dfinity/agent"; import { Principal } from "@dfinity/principal"; import { IDL } from "@dfinity/candid"; -import { idlFactory, canisterId } from "dfx-generated/backend"; +import { idlFactory, canisterId } from "../declarations/backend"; import { idlFactory as savedIdlFactory, canisterId as savedCanisterId, -} from "dfx-generated/saved"; +} from "../declarations/saved"; import { idlFactory as didjs_idl } from "../didjs.did"; @@ -16,17 +16,17 @@ const local = hostname === "127.0.0.1" || hostname.endsWith("localhost"); export const agent = new HttpAgent({ // Prefer calling local replica directly instead of CRA proxy - host: local ? `http://localhost:${LOCAL_PORT}` : undefined, + host: local ? `http://localhost:${LOCAL_PORT}` : "https://icp-api.io", }); if (local) { agent.fetchRootKey(); } /** - * @type {import("@dfinity/agent").ActorSubclass} + * @type {import("@dfinity/agent").ActorSubclass} */ export const backend = Actor.createActor(idlFactory, { agent, canisterId }); /** - * @type {import("@dfinity/agent").ActorSubclass} + * @type {import("@dfinity/agent").ActorSubclass} */ export const saved = Actor.createActor(savedIdlFactory, { agent, diff --git a/src/config/generateAliases.js b/src/config/generateAliases.js deleted file mode 100644 index 3b063b1c..00000000 --- a/src/config/generateAliases.js +++ /dev/null @@ -1,22 +0,0 @@ -const path = require("path"); - -const dfxJson = require(`${process.cwd()}/dfx.json`); -const { DFX_NETWORK = "local" } = process.env; - -function generateAliases() { - return Object.entries(dfxJson.canisters).reduce((result, [name]) => { - const outputRoot = path.join( - process.cwd(), - ".dfx", - DFX_NETWORK, - "canisters", - name - ); - return { - ...result, - ["dfx-generated/" + name]: path.join(outputRoot), - }; - }, {}); -} - -module.exports = generateAliases; diff --git a/src/config/jest.config.js b/src/config/jest.config.js deleted file mode 100644 index 6a80b451..00000000 --- a/src/config/jest.config.js +++ /dev/null @@ -1,11 +0,0 @@ -const { aliases } = require("./generateAliases"); - -const moduleNameMapper = Object.entries(aliases).reduce( - (result, [key, value]) => { - result[`^${key}$`] = value; - return result; - }, - {} -); - -module.exports = { moduleNameMapper }; diff --git a/src/declarations/backend/backend.did b/src/declarations/backend/backend.did new file mode 100644 index 00000000..2e5c4b5b --- /dev/null +++ b/src/declarations/backend/backend.did @@ -0,0 +1,128 @@ +type wasm_module = blob; +type definite_canister_settings = + record { + compute_allocation: nat; + controllers: vec principal; + freezing_threshold: nat; + memory_allocation: nat; + }; +type canister_settings = + record { + compute_allocation: opt nat; + controllers: opt vec principal; + freezing_threshold: opt nat; + memory_allocation: opt nat; + }; +type canister_id = principal; +type Stats = + record { + cycles_used: nat; + error_mismatch: nat; + error_out_of_capacity: nat; + error_total_wait_time: nat; + num_of_canisters: nat; + num_of_installs: nat; + }; +type Self = + service { + GCCanisters: () -> () oneway; + balance: () -> (nat) query; + callForward: (CanisterInfo, text, blob) -> (blob); + canister_status: (record {canister_id: canister_id;}) -> + (record { + cycles: nat; + memory_size: nat; + module_hash: opt blob; + settings: definite_canister_settings; + status: variant { + running; + stopped; + stopping; + }; + }); + create_canister: (record {settings: opt canister_settings;}) -> + (record {canister_id: canister_id;}); + delete_canister: (record {canister_id: canister_id;}) -> (); + dump: () -> (vec CanisterInfo) query; + getCanisterId: (Nonce) -> (CanisterInfo); + getInitParams: () -> (InitParams) query; + getStats: () -> (Stats) query; + getSubtree: (CanisterInfo) -> + (vec record { + principal; + vec CanisterInfo; + }) query; + http_request: (HttpRequest) -> (HttpResponse) query; + installCode: (CanisterInfo, InstallArgs, bool) -> (CanisterInfo); + install_code: + (record { + arg: blob; + canister_id: canister_id; + mode: variant { + install; + reinstall; + upgrade; + }; + wasm_module: wasm_module; + }) -> (); + removeCode: (CanisterInfo) -> (); + resetStats: () -> (); + start_canister: (record {canister_id: canister_id;}) -> (); + stop_canister: (record {canister_id: canister_id;}) -> (); + uninstall_code: (record {canister_id: canister_id;}) -> (); + update_settings: + (record { + canister_id: canister_id; + settings: canister_settings; + }) -> (); + wallet_receive: () -> (); + }; +type Nonce = + record { + nonce: nat; + timestamp: int; + }; +type InstallArgs = + record { + arg: blob; + canister_id: principal; + mode: variant { + install; + reinstall; + upgrade; + }; + wasm_module: blob; + }; +type InitParams = + record { + canister_time_to_live: nat; + cycles_per_canister: nat; + max_family_tree_size: nat; + max_num_canisters: nat; + nonce_time_to_live: nat; + }; +type HttpResponse = + record { + body: blob; + headers: vec record { + text; + text; + }; + status_code: nat16; + }; +type HttpRequest = + record { + body: blob; + headers: vec record { + text; + text; + }; + method: text; + url: text; + }; +type CanisterInfo = + record { + id: principal; + timestamp: int; + }; +service : (opt InitParams) -> Self diff --git a/src/declarations/backend/backend.did.d.ts b/src/declarations/backend/backend.did.d.ts new file mode 100644 index 00000000..d7f50a92 --- /dev/null +++ b/src/declarations/backend/backend.did.d.ts @@ -0,0 +1,112 @@ +import type { Principal } from "@dfinity/principal"; +import type { ActorMethod } from "@dfinity/agent"; + +export interface CanisterInfo { + id: Principal; + timestamp: bigint; +} +export interface HttpRequest { + url: string; + method: string; + body: Uint8Array | number[]; + headers: Array<[string, string]>; +} +export interface HttpResponse { + body: Uint8Array | number[]; + headers: Array<[string, string]>; + status_code: number; +} +export interface InitParams { + max_num_canisters: bigint; + canister_time_to_live: bigint; + cycles_per_canister: bigint; + nonce_time_to_live: bigint; + max_family_tree_size: bigint; +} +export interface InstallArgs { + arg: Uint8Array | number[]; + wasm_module: Uint8Array | number[]; + mode: { reinstall: null } | { upgrade: null } | { install: null }; + canister_id: Principal; +} +export interface Nonce { + nonce: bigint; + timestamp: bigint; +} +export interface Self { + GCCanisters: ActorMethod<[], undefined>; + balance: ActorMethod<[], bigint>; + callForward: ActorMethod< + [CanisterInfo, string, Uint8Array | number[]], + Uint8Array | number[] + >; + canister_status: ActorMethod< + [{ canister_id: canister_id }], + { + status: { stopped: null } | { stopping: null } | { running: null }; + memory_size: bigint; + cycles: bigint; + settings: definite_canister_settings; + module_hash: [] | [Uint8Array | number[]]; + } + >; + create_canister: ActorMethod< + [{ settings: [] | [canister_settings] }], + { canister_id: canister_id } + >; + delete_canister: ActorMethod<[{ canister_id: canister_id }], undefined>; + dump: ActorMethod<[], Array>; + getCanisterId: ActorMethod<[Nonce], CanisterInfo>; + getInitParams: ActorMethod<[], InitParams>; + getStats: ActorMethod<[], Stats>; + getSubtree: ActorMethod< + [CanisterInfo], + Array<[Principal, Array]> + >; + http_request: ActorMethod<[HttpRequest], HttpResponse>; + installCode: ActorMethod<[CanisterInfo, InstallArgs, boolean], CanisterInfo>; + install_code: ActorMethod< + [ + { + arg: Uint8Array | number[]; + wasm_module: wasm_module; + mode: { reinstall: null } | { upgrade: null } | { install: null }; + canister_id: canister_id; + } + ], + undefined + >; + removeCode: ActorMethod<[CanisterInfo], undefined>; + resetStats: ActorMethod<[], undefined>; + start_canister: ActorMethod<[{ canister_id: canister_id }], undefined>; + stop_canister: ActorMethod<[{ canister_id: canister_id }], undefined>; + uninstall_code: ActorMethod<[{ canister_id: canister_id }], undefined>; + update_settings: ActorMethod< + [{ canister_id: canister_id; settings: canister_settings }], + undefined + >; + wallet_receive: ActorMethod<[], undefined>; +} +export interface Stats { + num_of_installs: bigint; + num_of_canisters: bigint; + error_mismatch: bigint; + error_out_of_capacity: bigint; + cycles_used: bigint; + error_total_wait_time: bigint; +} +export type canister_id = Principal; +export interface canister_settings { + freezing_threshold: [] | [bigint]; + controllers: [] | [Array]; + memory_allocation: [] | [bigint]; + compute_allocation: [] | [bigint]; +} +export interface definite_canister_settings { + freezing_threshold: bigint; + controllers: Array; + memory_allocation: bigint; + compute_allocation: bigint; +} +export type wasm_module = Uint8Array | number[]; +export interface _SERVICE extends Self {} diff --git a/src/declarations/backend/backend.did.js b/src/declarations/backend/backend.did.js new file mode 100644 index 00000000..2f3a5cf4 --- /dev/null +++ b/src/declarations/backend/backend.did.js @@ -0,0 +1,159 @@ +export const idlFactory = ({ IDL }) => { + const InitParams = IDL.Record({ + max_num_canisters: IDL.Nat, + canister_time_to_live: IDL.Nat, + cycles_per_canister: IDL.Nat, + nonce_time_to_live: IDL.Nat, + max_family_tree_size: IDL.Nat, + }); + const CanisterInfo = IDL.Record({ + id: IDL.Principal, + timestamp: IDL.Int, + }); + const canister_id = IDL.Principal; + const definite_canister_settings = IDL.Record({ + freezing_threshold: IDL.Nat, + controllers: IDL.Vec(IDL.Principal), + memory_allocation: IDL.Nat, + compute_allocation: IDL.Nat, + }); + const canister_settings = IDL.Record({ + freezing_threshold: IDL.Opt(IDL.Nat), + controllers: IDL.Opt(IDL.Vec(IDL.Principal)), + memory_allocation: IDL.Opt(IDL.Nat), + compute_allocation: IDL.Opt(IDL.Nat), + }); + const Nonce = IDL.Record({ nonce: IDL.Nat, timestamp: IDL.Int }); + const Stats = IDL.Record({ + num_of_installs: IDL.Nat, + num_of_canisters: IDL.Nat, + error_mismatch: IDL.Nat, + error_out_of_capacity: IDL.Nat, + cycles_used: IDL.Nat, + error_total_wait_time: IDL.Nat, + }); + const HttpRequest = IDL.Record({ + url: IDL.Text, + method: IDL.Text, + body: IDL.Vec(IDL.Nat8), + headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + }); + const HttpResponse = IDL.Record({ + body: IDL.Vec(IDL.Nat8), + headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + status_code: IDL.Nat16, + }); + const InstallArgs = IDL.Record({ + arg: IDL.Vec(IDL.Nat8), + wasm_module: IDL.Vec(IDL.Nat8), + mode: IDL.Variant({ + reinstall: IDL.Null, + upgrade: IDL.Null, + install: IDL.Null, + }), + canister_id: IDL.Principal, + }); + const wasm_module = IDL.Vec(IDL.Nat8); + const Self = IDL.Service({ + GCCanisters: IDL.Func([], [], ["oneway"]), + balance: IDL.Func([], [IDL.Nat], ["query"]), + callForward: IDL.Func( + [CanisterInfo, IDL.Text, IDL.Vec(IDL.Nat8)], + [IDL.Vec(IDL.Nat8)], + [] + ), + canister_status: IDL.Func( + [IDL.Record({ canister_id: canister_id })], + [ + IDL.Record({ + status: IDL.Variant({ + stopped: IDL.Null, + stopping: IDL.Null, + running: IDL.Null, + }), + memory_size: IDL.Nat, + cycles: IDL.Nat, + settings: definite_canister_settings, + module_hash: IDL.Opt(IDL.Vec(IDL.Nat8)), + }), + ], + [] + ), + create_canister: IDL.Func( + [IDL.Record({ settings: IDL.Opt(canister_settings) })], + [IDL.Record({ canister_id: canister_id })], + [] + ), + delete_canister: IDL.Func( + [IDL.Record({ canister_id: canister_id })], + [], + [] + ), + dump: IDL.Func([], [IDL.Vec(CanisterInfo)], ["query"]), + getCanisterId: IDL.Func([Nonce], [CanisterInfo], []), + getInitParams: IDL.Func([], [InitParams], ["query"]), + getStats: IDL.Func([], [Stats], ["query"]), + getSubtree: IDL.Func( + [CanisterInfo], + [IDL.Vec(IDL.Tuple(IDL.Principal, IDL.Vec(CanisterInfo)))], + ["query"] + ), + http_request: IDL.Func([HttpRequest], [HttpResponse], ["query"]), + installCode: IDL.Func( + [CanisterInfo, InstallArgs, IDL.Bool], + [CanisterInfo], + [] + ), + install_code: IDL.Func( + [ + IDL.Record({ + arg: IDL.Vec(IDL.Nat8), + wasm_module: wasm_module, + mode: IDL.Variant({ + reinstall: IDL.Null, + upgrade: IDL.Null, + install: IDL.Null, + }), + canister_id: canister_id, + }), + ], + [], + [] + ), + removeCode: IDL.Func([CanisterInfo], [], []), + resetStats: IDL.Func([], [], []), + start_canister: IDL.Func( + [IDL.Record({ canister_id: canister_id })], + [], + [] + ), + stop_canister: IDL.Func([IDL.Record({ canister_id: canister_id })], [], []), + uninstall_code: IDL.Func( + [IDL.Record({ canister_id: canister_id })], + [], + [] + ), + update_settings: IDL.Func( + [ + IDL.Record({ + canister_id: canister_id, + settings: canister_settings, + }), + ], + [], + [] + ), + wallet_receive: IDL.Func([], [], []), + }); + return Self; +}; +export const init = ({ IDL }) => { + const InitParams = IDL.Record({ + max_num_canisters: IDL.Nat, + canister_time_to_live: IDL.Nat, + cycles_per_canister: IDL.Nat, + nonce_time_to_live: IDL.Nat, + max_family_tree_size: IDL.Nat, + }); + return [IDL.Opt(InitParams)]; +}; diff --git a/src/declarations/backend/index.d.ts b/src/declarations/backend/index.d.ts new file mode 100644 index 00000000..733c06c5 --- /dev/null +++ b/src/declarations/backend/index.d.ts @@ -0,0 +1,50 @@ +import type { + ActorSubclass, + HttpAgentOptions, + ActorConfig, + Agent, +} from "@dfinity/agent"; +import type { Principal } from "@dfinity/principal"; +import type { IDL } from "@dfinity/candid"; + +import { _SERVICE } from "./backend.did"; + +export declare const idlFactory: IDL.InterfaceFactory; +export declare const canisterId: string; + +export declare interface CreateActorOptions { + /** + * @see {@link Agent} + */ + agent?: Agent; + /** + * @see {@link HttpAgentOptions} + */ + agentOptions?: HttpAgentOptions; + /** + * @see {@link ActorConfig} + */ + actorOptions?: ActorConfig; +} + +/** + * Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister. + * @constructs {@link ActorSubClass} + * @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to + * @param {CreateActorOptions} options - see {@link CreateActorOptions} + * @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions + * @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent + * @see {@link HttpAgentOptions} + * @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor + * @see {@link ActorConfig} + */ +export declare const createActor: ( + canisterId: string | Principal, + options?: CreateActorOptions +) => ActorSubclass<_SERVICE>; + +/** + * Intialized Actor using default settings, ready to talk to a canister using its candid interface + * @constructs {@link ActorSubClass} + */ +export declare const backend: ActorSubclass<_SERVICE>; diff --git a/src/declarations/backend/index.js b/src/declarations/backend/index.js new file mode 100644 index 00000000..d07ab457 --- /dev/null +++ b/src/declarations/backend/index.js @@ -0,0 +1,42 @@ +import { Actor, HttpAgent } from "@dfinity/agent"; + +// Imports and re-exports candid interface +import { idlFactory } from "./backend.did.js"; +export { idlFactory } from "./backend.did.js"; + +/* CANISTER_ID is replaced by webpack based on node environment + * Note: canister environment variable will be standardized as + * process.env.CANISTER_ID_ + * beginning in dfx 0.15.0 + */ +export const canisterId = + process.env.CANISTER_ID_BACKEND || process.env.BACKEND_CANISTER_ID; + +export const createActor = (canisterId, options = {}) => { + const agent = options.agent || new HttpAgent({ ...options.agentOptions }); + + if (options.agent && options.agentOptions) { + console.warn( + "Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent." + ); + } + + // Fetch root key for certificate validation during development + if (process.env.DFX_NETWORK !== "ic") { + agent.fetchRootKey().catch((err) => { + console.warn( + "Unable to fetch root key. Check to ensure that your local replica is running" + ); + console.error(err); + }); + } + + // Creates an actor with using the candid interface and the HttpAgent + return Actor.createActor(idlFactory, { + agent, + canisterId, + ...options.actorOptions, + }); +}; + +export const backend = createActor(canisterId); diff --git a/src/declarations/react_app/index.d.ts b/src/declarations/react_app/index.d.ts new file mode 100644 index 00000000..50975856 --- /dev/null +++ b/src/declarations/react_app/index.d.ts @@ -0,0 +1,50 @@ +import type { + ActorSubclass, + HttpAgentOptions, + ActorConfig, + Agent, +} from "@dfinity/agent"; +import type { Principal } from "@dfinity/principal"; +import type { IDL } from "@dfinity/candid"; + +import { _SERVICE } from "./react_app.did"; + +export declare const idlFactory: IDL.InterfaceFactory; +export declare const canisterId: string; + +export declare interface CreateActorOptions { + /** + * @see {@link Agent} + */ + agent?: Agent; + /** + * @see {@link HttpAgentOptions} + */ + agentOptions?: HttpAgentOptions; + /** + * @see {@link ActorConfig} + */ + actorOptions?: ActorConfig; +} + +/** + * Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister. + * @constructs {@link ActorSubClass} + * @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to + * @param {CreateActorOptions} options - see {@link CreateActorOptions} + * @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions + * @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent + * @see {@link HttpAgentOptions} + * @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor + * @see {@link ActorConfig} + */ +export declare const createActor: ( + canisterId: string | Principal, + options?: CreateActorOptions +) => ActorSubclass<_SERVICE>; + +/** + * Intialized Actor using default settings, ready to talk to a canister using its candid interface + * @constructs {@link ActorSubClass} + */ +export declare const react_app: ActorSubclass<_SERVICE>; diff --git a/src/declarations/react_app/index.js b/src/declarations/react_app/index.js new file mode 100644 index 00000000..72c7d4ca --- /dev/null +++ b/src/declarations/react_app/index.js @@ -0,0 +1,42 @@ +import { Actor, HttpAgent } from "@dfinity/agent"; + +// Imports and re-exports candid interface +import { idlFactory } from "./react_app.did.js"; +export { idlFactory } from "./react_app.did.js"; + +/* CANISTER_ID is replaced by webpack based on node environment + * Note: canister environment variable will be standardized as + * process.env.CANISTER_ID_ + * beginning in dfx 0.15.0 + */ +export const canisterId = + process.env.CANISTER_ID_REACT_APP || process.env.REACT_APP_CANISTER_ID; + +export const createActor = (canisterId, options = {}) => { + const agent = options.agent || new HttpAgent({ ...options.agentOptions }); + + if (options.agent && options.agentOptions) { + console.warn( + "Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent." + ); + } + + // Fetch root key for certificate validation during development + if (process.env.DFX_NETWORK !== "ic") { + agent.fetchRootKey().catch((err) => { + console.warn( + "Unable to fetch root key. Check to ensure that your local replica is running" + ); + console.error(err); + }); + } + + // Creates an actor with using the candid interface and the HttpAgent + return Actor.createActor(idlFactory, { + agent, + canisterId, + ...options.actorOptions, + }); +}; + +export const react_app = createActor(canisterId); diff --git a/src/declarations/react_app/react_app.did b/src/declarations/react_app/react_app.did new file mode 100644 index 00000000..508bda65 --- /dev/null +++ b/src/declarations/react_app/react_app.did @@ -0,0 +1,228 @@ +type BatchId = nat; +type ChunkId = nat; +type Key = text; +type Time = int; + +type CreateAssetArguments = record { + key: Key; + content_type: text; + max_age: opt nat64; + headers: opt vec HeaderField; + enable_aliasing: opt bool; + allow_raw_access: opt bool; +}; + +// Add or change content for an asset, by content encoding +type SetAssetContentArguments = record { + key: Key; + content_encoding: text; + chunk_ids: vec ChunkId; + sha256: opt blob; +}; + +// Remove content for an asset, by content encoding +type UnsetAssetContentArguments = record { + key: Key; + content_encoding: text; +}; + +// Delete an asset +type DeleteAssetArguments = record { + key: Key; +}; + +// Reset everything +type ClearArguments = record {}; + +type BatchOperationKind = variant { + CreateAsset: CreateAssetArguments; + SetAssetContent: SetAssetContentArguments; + + SetAssetProperties: SetAssetPropertiesArguments; + + UnsetAssetContent: UnsetAssetContentArguments; + DeleteAsset: DeleteAssetArguments; + + Clear: ClearArguments; +}; + +type CommitBatchArguments = record { + batch_id: BatchId; + operations: vec BatchOperationKind +}; + +type CommitProposedBatchArguments = record { + batch_id: BatchId; + evidence: blob; +}; + +type ComputeEvidenceArguments = record { + batch_id: BatchId; + max_iterations: opt nat16 +}; + +type DeleteBatchArguments = record { + batch_id: BatchId; +}; + +type HeaderField = record { text; text; }; + +type HttpRequest = record { + method: text; + url: text; + headers: vec HeaderField; + body: blob; + certificate_version: opt nat16; +}; + +type HttpResponse = record { + status_code: nat16; + headers: vec HeaderField; + body: blob; + streaming_strategy: opt StreamingStrategy; +}; + +type StreamingCallbackHttpResponse = record { + body: blob; + token: opt StreamingCallbackToken; +}; + +type StreamingCallbackToken = record { + key: Key; + content_encoding: text; + index: nat; + sha256: opt blob; +}; + +type StreamingStrategy = variant { + Callback: record { + callback: func (StreamingCallbackToken) -> (opt StreamingCallbackHttpResponse) query; + token: StreamingCallbackToken; + }; +}; + +type SetAssetPropertiesArguments = record { + key: Key; + max_age: opt opt nat64; + headers: opt opt vec HeaderField; + allow_raw_access: opt opt bool; + is_aliased: opt opt bool; +}; + +type Permission = variant { + Commit; + ManagePermissions; + Prepare; +}; + +type GrantPermission = record { + to_principal: principal; + permission: Permission; +}; +type RevokePermission = record { + of_principal: principal; + permission: Permission; +}; +type ListPermitted = record { permission: Permission }; + +type ValidationResult = variant { Ok : text; Err : text }; + +service: { + api_version: () -> (nat16) query; + + get: (record { + key: Key; + accept_encodings: vec text; + }) -> (record { + content: blob; // may be the entirety of the content, or just chunk index 0 + content_type: text; + content_encoding: text; + sha256: opt blob; // sha256 of entire asset encoding, calculated by dfx and passed in SetAssetContentArguments + total_length: nat; // all chunks except last have size == content.size() + }) query; + + // if get() returned chunks > 1, call this to retrieve them. + // chunks may or may not be split up at the same boundaries as presented to create_chunk(). + get_chunk: (record { + key: Key; + content_encoding: text; + index: nat; + sha256: opt blob; // sha256 of entire asset encoding, calculated by dfx and passed in SetAssetContentArguments + }) -> (record { content: blob }) query; + + list : (record {}) -> (vec record { + key: Key; + content_type: text; + encodings: vec record { + content_encoding: text; + sha256: opt blob; // sha256 of entire asset encoding, calculated by dfx and passed in SetAssetContentArguments + length: nat; // Size of this encoding's blob. Calculated when uploading assets. + modified: Time; + }; + }) query; + + certified_tree : (record {}) -> (record { + certificate: blob; + tree: blob; + }) query; + + create_batch : (record {}) -> (record { batch_id: BatchId }); + + create_chunk: (record { batch_id: BatchId; content: blob }) -> (record { chunk_id: ChunkId }); + + // Perform all operations successfully, or reject + commit_batch: (CommitBatchArguments) -> (); + + // Save the batch operations for later commit + propose_commit_batch: (CommitBatchArguments) -> (); + + // Given a batch already proposed, perform all operations successfully, or reject + commit_proposed_batch: (CommitProposedBatchArguments) -> (); + + // Compute a hash over the CommitBatchArguments. Call until it returns Some(evidence). + compute_evidence: (ComputeEvidenceArguments) -> (opt blob); + + // Delete a batch that has been created, or proposed for commit, but not yet committed + delete_batch: (DeleteBatchArguments) -> (); + + create_asset: (CreateAssetArguments) -> (); + set_asset_content: (SetAssetContentArguments) -> (); + unset_asset_content: (UnsetAssetContentArguments) -> (); + + delete_asset: (DeleteAssetArguments) -> (); + + clear: (ClearArguments) -> (); + + // Single call to create an asset with content for a single content encoding that + // fits within the message ingress limit. + store: (record { + key: Key; + content_type: text; + content_encoding: text; + content: blob; + sha256: opt blob + }) -> (); + + http_request: (request: HttpRequest) -> (HttpResponse) query; + http_request_streaming_callback: (token: StreamingCallbackToken) -> (opt StreamingCallbackHttpResponse) query; + + authorize: (principal) -> (); + deauthorize: (principal) -> (); + list_authorized: () -> (vec principal) query; + grant_permission: (GrantPermission) -> (); + revoke_permission: (RevokePermission) -> (); + list_permitted: (ListPermitted) -> (vec principal) query; + take_ownership: () -> (); + + get_asset_properties : (key: Key) -> (record { + max_age: opt nat64; + headers: opt vec HeaderField; + allow_raw_access: opt bool; + is_aliased: opt bool; } ) query; + set_asset_properties: (SetAssetPropertiesArguments) -> (); + + validate_grant_permission: (GrantPermission) -> (ValidationResult); + validate_revoke_permission: (RevokePermission) -> (ValidationResult); + validate_take_ownership: () -> (ValidationResult); + validate_commit_proposed_batch: (CommitProposedBatchArguments) -> (ValidationResult); +} diff --git a/src/declarations/react_app/react_app.did.d.ts b/src/declarations/react_app/react_app.did.d.ts new file mode 100644 index 00000000..f818b563 --- /dev/null +++ b/src/declarations/react_app/react_app.did.d.ts @@ -0,0 +1,206 @@ +import type { Principal } from "@dfinity/principal"; +import type { ActorMethod } from "@dfinity/agent"; + +export type BatchId = bigint; +export type BatchOperationKind = + | { + SetAssetProperties: SetAssetPropertiesArguments; + } + | { CreateAsset: CreateAssetArguments } + | { UnsetAssetContent: UnsetAssetContentArguments } + | { DeleteAsset: DeleteAssetArguments } + | { SetAssetContent: SetAssetContentArguments } + | { Clear: ClearArguments }; +export type ChunkId = bigint; +export type ClearArguments = {}; +export interface CommitBatchArguments { + batch_id: BatchId; + operations: Array; +} +export interface CommitProposedBatchArguments { + batch_id: BatchId; + evidence: Uint8Array | number[]; +} +export interface ComputeEvidenceArguments { + batch_id: BatchId; + max_iterations: [] | [number]; +} +export interface CreateAssetArguments { + key: Key; + content_type: string; + headers: [] | [Array]; + allow_raw_access: [] | [boolean]; + max_age: [] | [bigint]; + enable_aliasing: [] | [boolean]; +} +export interface DeleteAssetArguments { + key: Key; +} +export interface DeleteBatchArguments { + batch_id: BatchId; +} +export interface GrantPermission { + permission: Permission; + to_principal: Principal; +} +export type HeaderField = [string, string]; +export interface HttpRequest { + url: string; + method: string; + body: Uint8Array | number[]; + headers: Array; + certificate_version: [] | [number]; +} +export interface HttpResponse { + body: Uint8Array | number[]; + headers: Array; + streaming_strategy: [] | [StreamingStrategy]; + status_code: number; +} +export type Key = string; +export interface ListPermitted { + permission: Permission; +} +export type Permission = + | { Prepare: null } + | { ManagePermissions: null } + | { Commit: null }; +export interface RevokePermission { + permission: Permission; + of_principal: Principal; +} +export interface SetAssetContentArguments { + key: Key; + sha256: [] | [Uint8Array | number[]]; + chunk_ids: Array; + content_encoding: string; +} +export interface SetAssetPropertiesArguments { + key: Key; + headers: [] | [[] | [Array]]; + is_aliased: [] | [[] | [boolean]]; + allow_raw_access: [] | [[] | [boolean]]; + max_age: [] | [[] | [bigint]]; +} +export interface StreamingCallbackHttpResponse { + token: [] | [StreamingCallbackToken]; + body: Uint8Array | number[]; +} +export interface StreamingCallbackToken { + key: Key; + sha256: [] | [Uint8Array | number[]]; + index: bigint; + content_encoding: string; +} +export type StreamingStrategy = { + Callback: { + token: StreamingCallbackToken; + callback: [Principal, string]; + }; +}; +export type Time = bigint; +export interface UnsetAssetContentArguments { + key: Key; + content_encoding: string; +} +export type ValidationResult = { Ok: string } | { Err: string }; +export interface _SERVICE { + api_version: ActorMethod<[], number>; + authorize: ActorMethod<[Principal], undefined>; + certified_tree: ActorMethod< + [{}], + { certificate: Uint8Array | number[]; tree: Uint8Array | number[] } + >; + clear: ActorMethod<[ClearArguments], undefined>; + commit_batch: ActorMethod<[CommitBatchArguments], undefined>; + commit_proposed_batch: ActorMethod<[CommitProposedBatchArguments], undefined>; + compute_evidence: ActorMethod< + [ComputeEvidenceArguments], + [] | [Uint8Array | number[]] + >; + create_asset: ActorMethod<[CreateAssetArguments], undefined>; + create_batch: ActorMethod<[{}], { batch_id: BatchId }>; + create_chunk: ActorMethod< + [{ content: Uint8Array | number[]; batch_id: BatchId }], + { chunk_id: ChunkId } + >; + deauthorize: ActorMethod<[Principal], undefined>; + delete_asset: ActorMethod<[DeleteAssetArguments], undefined>; + delete_batch: ActorMethod<[DeleteBatchArguments], undefined>; + get: ActorMethod< + [{ key: Key; accept_encodings: Array }], + { + content: Uint8Array | number[]; + sha256: [] | [Uint8Array | number[]]; + content_type: string; + content_encoding: string; + total_length: bigint; + } + >; + get_asset_properties: ActorMethod< + [Key], + { + headers: [] | [Array]; + is_aliased: [] | [boolean]; + allow_raw_access: [] | [boolean]; + max_age: [] | [bigint]; + } + >; + get_chunk: ActorMethod< + [ + { + key: Key; + sha256: [] | [Uint8Array | number[]]; + index: bigint; + content_encoding: string; + } + ], + { content: Uint8Array | number[] } + >; + grant_permission: ActorMethod<[GrantPermission], undefined>; + http_request: ActorMethod<[HttpRequest], HttpResponse>; + http_request_streaming_callback: ActorMethod< + [StreamingCallbackToken], + [] | [StreamingCallbackHttpResponse] + >; + list: ActorMethod< + [{}], + Array<{ + key: Key; + encodings: Array<{ + modified: Time; + sha256: [] | [Uint8Array | number[]]; + length: bigint; + content_encoding: string; + }>; + content_type: string; + }> + >; + list_authorized: ActorMethod<[], Array>; + list_permitted: ActorMethod<[ListPermitted], Array>; + propose_commit_batch: ActorMethod<[CommitBatchArguments], undefined>; + revoke_permission: ActorMethod<[RevokePermission], undefined>; + set_asset_content: ActorMethod<[SetAssetContentArguments], undefined>; + set_asset_properties: ActorMethod<[SetAssetPropertiesArguments], undefined>; + store: ActorMethod< + [ + { + key: Key; + content: Uint8Array | number[]; + sha256: [] | [Uint8Array | number[]]; + content_type: string; + content_encoding: string; + } + ], + undefined + >; + take_ownership: ActorMethod<[], undefined>; + unset_asset_content: ActorMethod<[UnsetAssetContentArguments], undefined>; + validate_commit_proposed_batch: ActorMethod< + [CommitProposedBatchArguments], + ValidationResult + >; + validate_grant_permission: ActorMethod<[GrantPermission], ValidationResult>; + validate_revoke_permission: ActorMethod<[RevokePermission], ValidationResult>; + validate_take_ownership: ActorMethod<[], ValidationResult>; +} diff --git a/src/declarations/react_app/react_app.did.js b/src/declarations/react_app/react_app.did.js new file mode 100644 index 00000000..f285d95d --- /dev/null +++ b/src/declarations/react_app/react_app.did.js @@ -0,0 +1,247 @@ +export const idlFactory = ({ IDL }) => { + const ClearArguments = IDL.Record({}); + const BatchId = IDL.Nat; + const Key = IDL.Text; + const HeaderField = IDL.Tuple(IDL.Text, IDL.Text); + const SetAssetPropertiesArguments = IDL.Record({ + key: Key, + headers: IDL.Opt(IDL.Opt(IDL.Vec(HeaderField))), + is_aliased: IDL.Opt(IDL.Opt(IDL.Bool)), + allow_raw_access: IDL.Opt(IDL.Opt(IDL.Bool)), + max_age: IDL.Opt(IDL.Opt(IDL.Nat64)), + }); + const CreateAssetArguments = IDL.Record({ + key: Key, + content_type: IDL.Text, + headers: IDL.Opt(IDL.Vec(HeaderField)), + allow_raw_access: IDL.Opt(IDL.Bool), + max_age: IDL.Opt(IDL.Nat64), + enable_aliasing: IDL.Opt(IDL.Bool), + }); + const UnsetAssetContentArguments = IDL.Record({ + key: Key, + content_encoding: IDL.Text, + }); + const DeleteAssetArguments = IDL.Record({ key: Key }); + const ChunkId = IDL.Nat; + const SetAssetContentArguments = IDL.Record({ + key: Key, + sha256: IDL.Opt(IDL.Vec(IDL.Nat8)), + chunk_ids: IDL.Vec(ChunkId), + content_encoding: IDL.Text, + }); + const BatchOperationKind = IDL.Variant({ + SetAssetProperties: SetAssetPropertiesArguments, + CreateAsset: CreateAssetArguments, + UnsetAssetContent: UnsetAssetContentArguments, + DeleteAsset: DeleteAssetArguments, + SetAssetContent: SetAssetContentArguments, + Clear: ClearArguments, + }); + const CommitBatchArguments = IDL.Record({ + batch_id: BatchId, + operations: IDL.Vec(BatchOperationKind), + }); + const CommitProposedBatchArguments = IDL.Record({ + batch_id: BatchId, + evidence: IDL.Vec(IDL.Nat8), + }); + const ComputeEvidenceArguments = IDL.Record({ + batch_id: BatchId, + max_iterations: IDL.Opt(IDL.Nat16), + }); + const DeleteBatchArguments = IDL.Record({ batch_id: BatchId }); + const Permission = IDL.Variant({ + Prepare: IDL.Null, + ManagePermissions: IDL.Null, + Commit: IDL.Null, + }); + const GrantPermission = IDL.Record({ + permission: Permission, + to_principal: IDL.Principal, + }); + const HttpRequest = IDL.Record({ + url: IDL.Text, + method: IDL.Text, + body: IDL.Vec(IDL.Nat8), + headers: IDL.Vec(HeaderField), + certificate_version: IDL.Opt(IDL.Nat16), + }); + const StreamingCallbackToken = IDL.Record({ + key: Key, + sha256: IDL.Opt(IDL.Vec(IDL.Nat8)), + index: IDL.Nat, + content_encoding: IDL.Text, + }); + const StreamingCallbackHttpResponse = IDL.Record({ + token: IDL.Opt(StreamingCallbackToken), + body: IDL.Vec(IDL.Nat8), + }); + const StreamingStrategy = IDL.Variant({ + Callback: IDL.Record({ + token: StreamingCallbackToken, + callback: IDL.Func( + [StreamingCallbackToken], + [IDL.Opt(StreamingCallbackHttpResponse)], + ["query"] + ), + }), + }); + const HttpResponse = IDL.Record({ + body: IDL.Vec(IDL.Nat8), + headers: IDL.Vec(HeaderField), + streaming_strategy: IDL.Opt(StreamingStrategy), + status_code: IDL.Nat16, + }); + const Time = IDL.Int; + const ListPermitted = IDL.Record({ permission: Permission }); + const RevokePermission = IDL.Record({ + permission: Permission, + of_principal: IDL.Principal, + }); + const ValidationResult = IDL.Variant({ Ok: IDL.Text, Err: IDL.Text }); + return IDL.Service({ + api_version: IDL.Func([], [IDL.Nat16], ["query"]), + authorize: IDL.Func([IDL.Principal], [], []), + certified_tree: IDL.Func( + [IDL.Record({})], + [ + IDL.Record({ + certificate: IDL.Vec(IDL.Nat8), + tree: IDL.Vec(IDL.Nat8), + }), + ], + ["query"] + ), + clear: IDL.Func([ClearArguments], [], []), + commit_batch: IDL.Func([CommitBatchArguments], [], []), + commit_proposed_batch: IDL.Func([CommitProposedBatchArguments], [], []), + compute_evidence: IDL.Func( + [ComputeEvidenceArguments], + [IDL.Opt(IDL.Vec(IDL.Nat8))], + [] + ), + create_asset: IDL.Func([CreateAssetArguments], [], []), + create_batch: IDL.Func( + [IDL.Record({})], + [IDL.Record({ batch_id: BatchId })], + [] + ), + create_chunk: IDL.Func( + [IDL.Record({ content: IDL.Vec(IDL.Nat8), batch_id: BatchId })], + [IDL.Record({ chunk_id: ChunkId })], + [] + ), + deauthorize: IDL.Func([IDL.Principal], [], []), + delete_asset: IDL.Func([DeleteAssetArguments], [], []), + delete_batch: IDL.Func([DeleteBatchArguments], [], []), + get: IDL.Func( + [IDL.Record({ key: Key, accept_encodings: IDL.Vec(IDL.Text) })], + [ + IDL.Record({ + content: IDL.Vec(IDL.Nat8), + sha256: IDL.Opt(IDL.Vec(IDL.Nat8)), + content_type: IDL.Text, + content_encoding: IDL.Text, + total_length: IDL.Nat, + }), + ], + ["query"] + ), + get_asset_properties: IDL.Func( + [Key], + [ + IDL.Record({ + headers: IDL.Opt(IDL.Vec(HeaderField)), + is_aliased: IDL.Opt(IDL.Bool), + allow_raw_access: IDL.Opt(IDL.Bool), + max_age: IDL.Opt(IDL.Nat64), + }), + ], + ["query"] + ), + get_chunk: IDL.Func( + [ + IDL.Record({ + key: Key, + sha256: IDL.Opt(IDL.Vec(IDL.Nat8)), + index: IDL.Nat, + content_encoding: IDL.Text, + }), + ], + [IDL.Record({ content: IDL.Vec(IDL.Nat8) })], + ["query"] + ), + grant_permission: IDL.Func([GrantPermission], [], []), + http_request: IDL.Func([HttpRequest], [HttpResponse], ["query"]), + http_request_streaming_callback: IDL.Func( + [StreamingCallbackToken], + [IDL.Opt(StreamingCallbackHttpResponse)], + ["query"] + ), + list: IDL.Func( + [IDL.Record({})], + [ + IDL.Vec( + IDL.Record({ + key: Key, + encodings: IDL.Vec( + IDL.Record({ + modified: Time, + sha256: IDL.Opt(IDL.Vec(IDL.Nat8)), + length: IDL.Nat, + content_encoding: IDL.Text, + }) + ), + content_type: IDL.Text, + }) + ), + ], + ["query"] + ), + list_authorized: IDL.Func([], [IDL.Vec(IDL.Principal)], ["query"]), + list_permitted: IDL.Func( + [ListPermitted], + [IDL.Vec(IDL.Principal)], + ["query"] + ), + propose_commit_batch: IDL.Func([CommitBatchArguments], [], []), + revoke_permission: IDL.Func([RevokePermission], [], []), + set_asset_content: IDL.Func([SetAssetContentArguments], [], []), + set_asset_properties: IDL.Func([SetAssetPropertiesArguments], [], []), + store: IDL.Func( + [ + IDL.Record({ + key: Key, + content: IDL.Vec(IDL.Nat8), + sha256: IDL.Opt(IDL.Vec(IDL.Nat8)), + content_type: IDL.Text, + content_encoding: IDL.Text, + }), + ], + [], + [] + ), + take_ownership: IDL.Func([], [], []), + unset_asset_content: IDL.Func([UnsetAssetContentArguments], [], []), + validate_commit_proposed_batch: IDL.Func( + [CommitProposedBatchArguments], + [ValidationResult], + [] + ), + validate_grant_permission: IDL.Func( + [GrantPermission], + [ValidationResult], + [] + ), + validate_revoke_permission: IDL.Func( + [RevokePermission], + [ValidationResult], + [] + ), + validate_take_ownership: IDL.Func([], [ValidationResult], []), + }); +}; +export const init = ({ IDL }) => { + return []; +}; diff --git a/src/declarations/saved/index.d.ts b/src/declarations/saved/index.d.ts new file mode 100644 index 00000000..10b6d08c --- /dev/null +++ b/src/declarations/saved/index.d.ts @@ -0,0 +1,50 @@ +import type { + ActorSubclass, + HttpAgentOptions, + ActorConfig, + Agent, +} from "@dfinity/agent"; +import type { Principal } from "@dfinity/principal"; +import type { IDL } from "@dfinity/candid"; + +import { _SERVICE } from "./saved.did"; + +export declare const idlFactory: IDL.InterfaceFactory; +export declare const canisterId: string; + +export declare interface CreateActorOptions { + /** + * @see {@link Agent} + */ + agent?: Agent; + /** + * @see {@link HttpAgentOptions} + */ + agentOptions?: HttpAgentOptions; + /** + * @see {@link ActorConfig} + */ + actorOptions?: ActorConfig; +} + +/** + * Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister. + * @constructs {@link ActorSubClass} + * @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to + * @param {CreateActorOptions} options - see {@link CreateActorOptions} + * @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions + * @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent + * @see {@link HttpAgentOptions} + * @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor + * @see {@link ActorConfig} + */ +export declare const createActor: ( + canisterId: string | Principal, + options?: CreateActorOptions +) => ActorSubclass<_SERVICE>; + +/** + * Intialized Actor using default settings, ready to talk to a canister using its candid interface + * @constructs {@link ActorSubClass} + */ +export declare const saved: ActorSubclass<_SERVICE>; diff --git a/src/declarations/saved/index.js b/src/declarations/saved/index.js new file mode 100644 index 00000000..9ddbcd44 --- /dev/null +++ b/src/declarations/saved/index.js @@ -0,0 +1,42 @@ +import { Actor, HttpAgent } from "@dfinity/agent"; + +// Imports and re-exports candid interface +import { idlFactory } from "./saved.did.js"; +export { idlFactory } from "./saved.did.js"; + +/* CANISTER_ID is replaced by webpack based on node environment + * Note: canister environment variable will be standardized as + * process.env.CANISTER_ID_ + * beginning in dfx 0.15.0 + */ +export const canisterId = + process.env.CANISTER_ID_SAVED || process.env.SAVED_CANISTER_ID; + +export const createActor = (canisterId, options = {}) => { + const agent = options.agent || new HttpAgent({ ...options.agentOptions }); + + if (options.agent && options.agentOptions) { + console.warn( + "Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent." + ); + } + + // Fetch root key for certificate validation during development + if (process.env.DFX_NETWORK !== "ic") { + agent.fetchRootKey().catch((err) => { + console.warn( + "Unable to fetch root key. Check to ensure that your local replica is running" + ); + console.error(err); + }); + } + + // Creates an actor with using the candid interface and the HttpAgent + return Actor.createActor(idlFactory, { + agent, + canisterId, + ...options.actorOptions, + }); +}; + +export const saved = createActor(canisterId); diff --git a/src/declarations/saved/saved.did b/src/declarations/saved/saved.did new file mode 100644 index 00000000..7a09bf76 --- /dev/null +++ b/src/declarations/saved/saved.did @@ -0,0 +1,42 @@ +type Time = int; +type StatResult = + record { + byte_size: nat; + num_projects: nat; + }; +type SavedProject = + record { + project: Project; + timestamp: Time; + }; +type Project = + record { + canisters: opt vec CanisterInfo; + files: vec NamedFile; + packages: opt vec PackageInfo; + }; +type PackageInfo = + record { + dir: opt text; + homepage: opt text; + name: text; + repo: text; + version: text; + }; +type NamedFile = + record { + content: text; + name: text; + }; +type HashId = nat; +type CanisterInfo = + record { + candid: text; + id: principal; + name: text; + }; +service : { + getProject: (HashId) -> (opt SavedProject) query; + getStats: () -> (StatResult) query; + putProject: (Project) -> (HashId); +} diff --git a/src/declarations/saved/saved.did.d.ts b/src/declarations/saved/saved.did.d.ts new file mode 100644 index 00000000..35779c7f --- /dev/null +++ b/src/declarations/saved/saved.did.d.ts @@ -0,0 +1,39 @@ +import type { Principal } from "@dfinity/principal"; +import type { ActorMethod } from "@dfinity/agent"; + +export interface CanisterInfo { + id: Principal; + name: string; + candid: string; +} +export type HashId = bigint; +export interface NamedFile { + content: string; + name: string; +} +export interface PackageInfo { + dir: [] | [string]; + name: string; + homepage: [] | [string]; + repo: string; + version: string; +} +export interface Project { + files: Array; + packages: [] | [Array]; + canisters: [] | [Array]; +} +export interface SavedProject { + timestamp: Time; + project: Project; +} +export interface StatResult { + byte_size: bigint; + num_projects: bigint; +} +export type Time = bigint; +export interface _SERVICE { + getProject: ActorMethod<[HashId], [] | [SavedProject]>; + getStats: ActorMethod<[], StatResult>; + putProject: ActorMethod<[Project], HashId>; +} diff --git a/src/declarations/saved/saved.did.js b/src/declarations/saved/saved.did.js new file mode 100644 index 00000000..23603879 --- /dev/null +++ b/src/declarations/saved/saved.did.js @@ -0,0 +1,35 @@ +export const idlFactory = ({ IDL }) => { + const HashId = IDL.Nat; + const Time = IDL.Int; + const NamedFile = IDL.Record({ content: IDL.Text, name: IDL.Text }); + const PackageInfo = IDL.Record({ + dir: IDL.Opt(IDL.Text), + name: IDL.Text, + homepage: IDL.Opt(IDL.Text), + repo: IDL.Text, + version: IDL.Text, + }); + const CanisterInfo = IDL.Record({ + id: IDL.Principal, + name: IDL.Text, + candid: IDL.Text, + }); + const Project = IDL.Record({ + files: IDL.Vec(NamedFile), + packages: IDL.Opt(IDL.Vec(PackageInfo)), + canisters: IDL.Opt(IDL.Vec(CanisterInfo)), + }); + const SavedProject = IDL.Record({ timestamp: Time, project: Project }); + const StatResult = IDL.Record({ + byte_size: IDL.Nat, + num_projects: IDL.Nat, + }); + return IDL.Service({ + getProject: IDL.Func([HashId], [IDL.Opt(SavedProject)], ["query"]), + getStats: IDL.Func([], [StatResult], ["query"]), + putProject: IDL.Func([Project], [HashId], []), + }); +}; +export const init = ({ IDL }) => { + return []; +}; diff --git a/src/declarations/wasm-utils/index.d.ts b/src/declarations/wasm-utils/index.d.ts new file mode 100644 index 00000000..5de01b1e --- /dev/null +++ b/src/declarations/wasm-utils/index.d.ts @@ -0,0 +1,50 @@ +import type { + ActorSubclass, + HttpAgentOptions, + ActorConfig, + Agent, +} from "@dfinity/agent"; +import type { Principal } from "@dfinity/principal"; +import type { IDL } from "@dfinity/candid"; + +import { _SERVICE } from "./wasm-utils.did"; + +export declare const idlFactory: IDL.InterfaceFactory; +export declare const canisterId: string; + +export declare interface CreateActorOptions { + /** + * @see {@link Agent} + */ + agent?: Agent; + /** + * @see {@link HttpAgentOptions} + */ + agentOptions?: HttpAgentOptions; + /** + * @see {@link ActorConfig} + */ + actorOptions?: ActorConfig; +} + +/** + * Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister. + * @constructs {@link ActorSubClass} + * @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to + * @param {CreateActorOptions} options - see {@link CreateActorOptions} + * @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions + * @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent + * @see {@link HttpAgentOptions} + * @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor + * @see {@link ActorConfig} + */ +export declare const createActor: ( + canisterId: string | Principal, + options?: CreateActorOptions +) => ActorSubclass<_SERVICE>; + +/** + * Intialized Actor using default settings, ready to talk to a canister using its candid interface + * @constructs {@link ActorSubClass} + */ +export declare const wasm_utils: ActorSubclass<_SERVICE>; diff --git a/src/declarations/wasm-utils/index.js b/src/declarations/wasm-utils/index.js new file mode 100644 index 00000000..c3559527 --- /dev/null +++ b/src/declarations/wasm-utils/index.js @@ -0,0 +1,42 @@ +import { Actor, HttpAgent } from "@dfinity/agent"; + +// Imports and re-exports candid interface +import { idlFactory } from "./wasm-utils.did.js"; +export { idlFactory } from "./wasm-utils.did.js"; + +/* CANISTER_ID is replaced by webpack based on node environment + * Note: canister environment variable will be standardized as + * process.env.CANISTER_ID_ + * beginning in dfx 0.15.0 + */ +export const canisterId = + process.env.CANISTER_ID_WASM - UTILS || process.env.WASM - UTILS_CANISTER_ID; + +export const createActor = (canisterId, options = {}) => { + const agent = options.agent || new HttpAgent({ ...options.agentOptions }); + + if (options.agent && options.agentOptions) { + console.warn( + "Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent." + ); + } + + // Fetch root key for certificate validation during development + if (process.env.DFX_NETWORK !== "ic") { + agent.fetchRootKey().catch((err) => { + console.warn( + "Unable to fetch root key. Check to ensure that your local replica is running" + ); + console.error(err); + }); + } + + // Creates an actor with using the candid interface and the HttpAgent + return Actor.createActor(idlFactory, { + agent, + canisterId, + ...options.actorOptions, + }); +}; + +export const wasm_utils = createActor(canisterId); diff --git a/src/declarations/wasm-utils/wasm-utils.did b/src/declarations/wasm-utils/wasm-utils.did new file mode 100644 index 00000000..35463025 --- /dev/null +++ b/src/declarations/wasm-utils/wasm-utils.did @@ -0,0 +1,5 @@ +type Config = record { profiling: bool; remove_cycles_add: bool; limit_stable_memory_page: opt nat32; backend_canister_id: opt principal}; + +service : { + transform : (blob, Config) -> (blob); +} diff --git a/src/declarations/wasm-utils/wasm-utils.did.d.ts b/src/declarations/wasm-utils/wasm-utils.did.d.ts new file mode 100644 index 00000000..a2c43c5d --- /dev/null +++ b/src/declarations/wasm-utils/wasm-utils.did.d.ts @@ -0,0 +1,15 @@ +import type { Principal } from "@dfinity/principal"; +import type { ActorMethod } from "@dfinity/agent"; + +export interface Config { + backend_canister_id: [] | [Principal]; + remove_cycles_add: boolean; + profiling: boolean; + limit_stable_memory_page: [] | [number]; +} +export interface _SERVICE { + transform: ActorMethod< + [Uint8Array | number[], Config], + Uint8Array | number[] + >; +} diff --git a/src/declarations/wasm-utils/wasm-utils.did.js b/src/declarations/wasm-utils/wasm-utils.did.js new file mode 100644 index 00000000..b2eff185 --- /dev/null +++ b/src/declarations/wasm-utils/wasm-utils.did.js @@ -0,0 +1,14 @@ +export const idlFactory = ({ IDL }) => { + const Config = IDL.Record({ + backend_canister_id: IDL.Opt(IDL.Principal), + remove_cycles_add: IDL.Bool, + profiling: IDL.Bool, + limit_stable_memory_page: IDL.Opt(IDL.Nat32), + }); + return IDL.Service({ + transform: IDL.Func([IDL.Vec(IDL.Nat8), Config], [IDL.Vec(IDL.Nat8)], []), + }); +}; +export const init = ({ IDL }) => { + return []; +}; diff --git a/vessel.dhall b/vessel.dhall deleted file mode 100644 index 526d9343..00000000 --- a/vessel.dhall +++ /dev/null @@ -1,4 +0,0 @@ -{ - dependencies = [ "base", "splay" ], - compiler = None Text -}