4 |
5 | ## MISCELLANEOUS EXAMPLES OF GAME TECH
6 |
7 | Useful game infra examples to help game developers collaborate and kickstart their development on ICP. Includes examples for a chat system, pseudo real-time multiplayer simulation, storing JSON configurations in a canister, and a batch transfer tool for transferring large amounts of tokens and NFTs to numerous principal ids at once.
--------------------------------------------------------------------------------
/login-webpage/src/login-webpage/src/alt_index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Login Page
7 |
8 |
9 |
10 |
11 |
12 |
13 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/candid-with-auth/.dfx/ic/canisters/didjs/service.did.d.ts:
--------------------------------------------------------------------------------
1 | import type { Principal } from '@dfinity/principal';
2 | import type { ActorMethod } from '@dfinity/agent';
3 | import type { IDL } from '@dfinity/candid';
4 |
5 | export interface _SERVICE {
6 | 'binding' : ActorMethod<[string, string], [] | [string]>,
7 | 'did_to_js' : ActorMethod<[string], [] | [string]>,
8 | 'subtype' : ActorMethod<
9 | [string, string],
10 | { 'Ok' : null } |
11 | { 'Err' : string }
12 | >,
13 | }
14 | export declare const idlFactory: IDL.InterfaceFactory;
15 | export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[];
16 |
--------------------------------------------------------------------------------
/candid-with-auth/.dfx/stag/canisters/didjs/service.did.d.ts:
--------------------------------------------------------------------------------
1 | import type { Principal } from '@dfinity/principal';
2 | import type { ActorMethod } from '@dfinity/agent';
3 | import type { IDL } from '@dfinity/candid';
4 |
5 | export interface _SERVICE {
6 | 'binding' : ActorMethod<[string, string], [] | [string]>,
7 | 'did_to_js' : ActorMethod<[string], [] | [string]>,
8 | 'subtype' : ActorMethod<
9 | [string, string],
10 | { 'Ok' : null } |
11 | { 'Err' : string }
12 | >,
13 | }
14 | export declare const idlFactory: IDL.InterfaceFactory;
15 | export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[];
16 |
--------------------------------------------------------------------------------
/candid-with-auth/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "allowJs": false,
4 | "baseUrl": "./",
5 | "composite": true,
6 | "esModuleInterop": true,
7 | "forceConsistentCasingInFileNames": true,
8 | "incremental": true,
9 | "lib": [
10 | "dom",
11 | "es2017"
12 | ],
13 | "module": "commonjs",
14 | "outDir": "ts-out/",
15 | "sourceMap": true,
16 | "strict": true,
17 | "target": "ES2017",
18 | "resolveJsonModule": true,
19 | },
20 | "include": [
21 | "src/**/*.ts",
22 | "src/**/*.css",
23 | "src/**/*.json"
24 | ],
25 | "exclude": [
26 | "**/*.test.ts"
27 | ],
28 | }
--------------------------------------------------------------------------------
/chat/src/chat_frontend/src/index.js:
--------------------------------------------------------------------------------
1 | import { chat_backend } from "../../declarations/chat_backend";
2 |
3 | document.querySelector("form").addEventListener("submit", async (e) => {
4 | e.preventDefault();
5 | const button = e.target.querySelector("button");
6 |
7 | const name = document.getElementById("name").value.toString();
8 |
9 | button.setAttribute("disabled", true);
10 |
11 | // Interact with foo actor, calling the greet method
12 | const greeting = await chat_backend.greet(name);
13 |
14 | button.removeAttribute("disabled");
15 |
16 | document.getElementById("greeting").innerText = greeting;
17 |
18 | return false;
19 | });
20 |
--------------------------------------------------------------------------------
/topup/src/topup_frontend/src/index.js:
--------------------------------------------------------------------------------
1 | import { topup_backend } from "../../declarations/topup_backend";
2 |
3 | document.querySelector("form").addEventListener("submit", async (e) => {
4 | e.preventDefault();
5 | const button = e.target.querySelector("button");
6 |
7 | const name = document.getElementById("name").value.toString();
8 |
9 | button.setAttribute("disabled", true);
10 |
11 | // Interact with foo actor, calling the greet method
12 | const greeting = await topup_backend.greet(name);
13 |
14 | button.removeAttribute("disabled");
15 |
16 | document.getElementById("greeting").innerText = greeting;
17 |
18 | return false;
19 | });
20 |
--------------------------------------------------------------------------------
/chat/dfx.json:
--------------------------------------------------------------------------------
1 | {
2 | "canisters": {
3 | "chat_backend": {
4 | "main": "src/chat_backend/main.mo",
5 | "type": "motoko"
6 | },
7 | "chat_frontend": {
8 | "dependencies": [
9 | "chat_backend"
10 | ],
11 | "frontend": {
12 | "entrypoint": "src/chat_frontend/src/index.html"
13 | },
14 | "source": [
15 | "src/chat_frontend/assets",
16 | "dist/chat_frontend/"
17 | ],
18 | "type": "assets"
19 | }
20 | },
21 | "defaults": {
22 | "build": {
23 | "args": "",
24 | "packtool": ""
25 | }
26 | },
27 | "output_env_file": ".env",
28 | "version": 1
29 | }
--------------------------------------------------------------------------------
/sns-metrics/src/metrics_frontend/src/index.js:
--------------------------------------------------------------------------------
1 | import { metrics_backend } from "../../declarations/metrics_backend";
2 |
3 | document.querySelector("form").addEventListener("submit", async (e) => {
4 | e.preventDefault();
5 | const button = e.target.querySelector("button");
6 |
7 | const name = document.getElementById("name").value.toString();
8 |
9 | button.setAttribute("disabled", true);
10 |
11 | // Interact with foo actor, calling the greet method
12 | const greeting = await metrics_backend.greet(name);
13 |
14 | button.removeAttribute("disabled");
15 |
16 | document.getElementById("greeting").innerText = greeting;
17 |
18 | return false;
19 | });
20 |
--------------------------------------------------------------------------------
/candid-with-auth/dfx.json:
--------------------------------------------------------------------------------
1 | {
2 | "canisters": {
3 | "didjs": {
4 | "type": "custom",
5 | "candid": "src/didjs/didjs.did",
6 | "wasm": "target/wasm32-unknown-unknown/release/didjs_opt.wasm",
7 | "build": [
8 | "npm run build",
9 | "cargo build --target wasm32-unknown-unknown --release --package didjs",
10 | "wasm-opt --strip-debug -Oz target/wasm32-unknown-unknown/release/didjs.wasm -o target/wasm32-unknown-unknown/release/didjs_opt.wasm"
11 | ]
12 | }
13 | },
14 | "networks": {
15 | "stag": {
16 | "providers": ["https://icp0.io"],
17 | "type": "persistent"
18 | }
19 | },
20 | "version": 1
21 | }
--------------------------------------------------------------------------------
/multiplayer/src/multiplayer_frontend/src/index.js:
--------------------------------------------------------------------------------
1 | import { multiplayer_backend } from "../../declarations/multiplayer_backend";
2 |
3 | document.querySelector("form").addEventListener("submit", async (e) => {
4 | e.preventDefault();
5 | const button = e.target.querySelector("button");
6 |
7 | const name = document.getElementById("name").value.toString();
8 |
9 | button.setAttribute("disabled", true);
10 |
11 | // Interact with foo actor, calling the greet method
12 | const greeting = await multiplayer_backend.greet(name);
13 |
14 | button.removeAttribute("disabled");
15 |
16 | document.getElementById("greeting").innerText = greeting;
17 |
18 | return false;
19 | });
20 |
--------------------------------------------------------------------------------
/sns-metrics/dfx.json:
--------------------------------------------------------------------------------
1 | {
2 | "canisters": {
3 | "metrics_backend": {
4 | "main": "src/metrics_backend/main.mo",
5 | "type": "motoko"
6 | },
7 | "metrics_frontend": {
8 | "dependencies": [
9 | "metrics_backend"
10 | ],
11 | "frontend": {
12 | "entrypoint": "src/metrics_frontend/src/index.html"
13 | },
14 | "source": [
15 | "src/metrics_frontend/assets",
16 | "dist/metrics_frontend/"
17 | ],
18 | "type": "assets"
19 | }
20 | },
21 | "defaults": {
22 | "build": {
23 | "args": "",
24 | "packtool": ""
25 | }
26 | },
27 | "output_env_file": ".env",
28 | "version": 1
29 | }
--------------------------------------------------------------------------------
/remote-configs/src/remote_configs_frontend/src/index.js:
--------------------------------------------------------------------------------
1 | import { remote_configs_backend } from "../../declarations/remote_configs_backend";
2 |
3 | document.querySelector("form").addEventListener("submit", async (e) => {
4 | e.preventDefault();
5 | const button = e.target.querySelector("button");
6 |
7 | const name = document.getElementById("name").value.toString();
8 |
9 | button.setAttribute("disabled", true);
10 |
11 | // Interact with foo actor, calling the greet method
12 | const greeting = await remote_configs_backend.greet(name);
13 |
14 | button.removeAttribute("disabled");
15 |
16 | document.getElementById("greeting").innerText = greeting;
17 |
18 | return false;
19 | });
20 |
--------------------------------------------------------------------------------
/login-webpage/dfx.json:
--------------------------------------------------------------------------------
1 | {
2 | "canisters": {
3 | "login-webpage": {
4 | "frontend": {
5 | "entrypoint": "src/login-webpage/src/index.html"
6 | },
7 | "source": [
8 | "src/login-webpage/assets",
9 | "dist/login-webpage/"
10 | ],
11 | "type": "assets"
12 | }
13 | },
14 | "defaults": {
15 | "build": {
16 | "args": "",
17 | "packtool": ""
18 | }
19 | },
20 | "networks": {
21 | "stag": {
22 | "providers": [
23 | "https://icp0.io"
24 | ],
25 | "type": "persistent"
26 | },
27 | "test": {
28 | "providers": [
29 | "https://icp0.io"
30 | ],
31 | "type": "persistent"
32 | }
33 | },
34 | "version": 1
35 | }
--------------------------------------------------------------------------------
/multiplayer/dfx.json:
--------------------------------------------------------------------------------
1 | {
2 | "canisters": {
3 | "multiplayer_backend": {
4 | "main": "src/multiplayer_backend/main.mo",
5 | "type": "motoko"
6 | },
7 | "multiplayer_frontend": {
8 | "dependencies": [
9 | "multiplayer_backend"
10 | ],
11 | "frontend": {
12 | "entrypoint": "src/multiplayer_frontend/src/index.html"
13 | },
14 | "source": [
15 | "src/multiplayer_frontend/assets",
16 | "dist/multiplayer_frontend/"
17 | ],
18 | "type": "assets"
19 | }
20 | },
21 | "defaults": {
22 | "build": {
23 | "args": "",
24 | "packtool": ""
25 | }
26 | },
27 | "output_env_file": ".env",
28 | "version": 1
29 | }
--------------------------------------------------------------------------------
/chat/src/chat_frontend/assets/main.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: sans-serif;
3 | font-size: 1.5rem;
4 | }
5 |
6 | img {
7 | max-width: 50vw;
8 | max-height: 25vw;
9 | display: block;
10 | margin: auto;
11 | }
12 |
13 | form {
14 | display: flex;
15 | justify-content: center;
16 | gap: 0.5em;
17 | flex-flow: row wrap;
18 | max-width: 40vw;
19 | margin: auto;
20 | align-items: baseline;
21 | }
22 |
23 | button[type="submit"] {
24 | padding: 5px 20px;
25 | margin: 10px auto;
26 | float: right;
27 | }
28 |
29 | #greeting {
30 | margin: 10px auto;
31 | padding: 10px 60px;
32 | border: 1px solid #222;
33 | }
34 |
35 | #greeting:empty {
36 | display: none;
37 | }
38 |
--------------------------------------------------------------------------------
/topup/src/topup_frontend/assets/main.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: sans-serif;
3 | font-size: 1.5rem;
4 | }
5 |
6 | img {
7 | max-width: 50vw;
8 | max-height: 25vw;
9 | display: block;
10 | margin: auto;
11 | }
12 |
13 | form {
14 | display: flex;
15 | justify-content: center;
16 | gap: 0.5em;
17 | flex-flow: row wrap;
18 | max-width: 40vw;
19 | margin: auto;
20 | align-items: baseline;
21 | }
22 |
23 | button[type="submit"] {
24 | padding: 5px 20px;
25 | margin: 10px auto;
26 | float: right;
27 | }
28 |
29 | #greeting {
30 | margin: 10px auto;
31 | padding: 10px 60px;
32 | border: 1px solid #222;
33 | }
34 |
35 | #greeting:empty {
36 | display: none;
37 | }
38 |
--------------------------------------------------------------------------------
/sns-metrics/src/metrics_frontend/assets/main.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: sans-serif;
3 | font-size: 1.5rem;
4 | }
5 |
6 | img {
7 | max-width: 50vw;
8 | max-height: 25vw;
9 | display: block;
10 | margin: auto;
11 | }
12 |
13 | form {
14 | display: flex;
15 | justify-content: center;
16 | gap: 0.5em;
17 | flex-flow: row wrap;
18 | max-width: 40vw;
19 | margin: auto;
20 | align-items: baseline;
21 | }
22 |
23 | button[type="submit"] {
24 | padding: 5px 20px;
25 | margin: 10px auto;
26 | float: right;
27 | }
28 |
29 | #greeting {
30 | margin: 10px auto;
31 | padding: 10px 60px;
32 | border: 1px solid #222;
33 | }
34 |
35 | #greeting:empty {
36 | display: none;
37 | }
38 |
--------------------------------------------------------------------------------
/candid-with-auth/dist/didjs/index.js.LICENSE.txt:
--------------------------------------------------------------------------------
1 | /*!
2 | * The buffer module from node.js, for the browser.
3 | *
4 | * @author Feross Aboukhadijeh
5 | * @license MIT
6 | */
7 |
8 | /*! Bundled license information:
9 |
10 | ieee754/index.js:
11 | (*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh *)
12 |
13 | buffer/index.js:
14 | (*!
15 | * The buffer module from node.js, for the browser.
16 | *
17 | * @author Feross Aboukhadijeh
18 | * @license MIT
19 | *)
20 | */
21 |
22 | /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */
23 |
24 | /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
25 |
--------------------------------------------------------------------------------
/multiplayer/src/multiplayer_frontend/assets/main.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: sans-serif;
3 | font-size: 1.5rem;
4 | }
5 |
6 | img {
7 | max-width: 50vw;
8 | max-height: 25vw;
9 | display: block;
10 | margin: auto;
11 | }
12 |
13 | form {
14 | display: flex;
15 | justify-content: center;
16 | gap: 0.5em;
17 | flex-flow: row wrap;
18 | max-width: 40vw;
19 | margin: auto;
20 | align-items: baseline;
21 | }
22 |
23 | button[type="submit"] {
24 | padding: 5px 20px;
25 | margin: 10px auto;
26 | float: right;
27 | }
28 |
29 | #greeting {
30 | margin: 10px auto;
31 | padding: 10px 60px;
32 | border: 1px solid #222;
33 | }
34 |
35 | #greeting:empty {
36 | display: none;
37 | }
38 |
--------------------------------------------------------------------------------
/remote-configs/src/remote_configs_frontend/assets/main.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: sans-serif;
3 | font-size: 1.5rem;
4 | }
5 |
6 | img {
7 | max-width: 50vw;
8 | max-height: 25vw;
9 | display: block;
10 | margin: auto;
11 | }
12 |
13 | form {
14 | display: flex;
15 | justify-content: center;
16 | gap: 0.5em;
17 | flex-flow: row wrap;
18 | max-width: 40vw;
19 | margin: auto;
20 | align-items: baseline;
21 | }
22 |
23 | button[type="submit"] {
24 | padding: 5px 20px;
25 | margin: 10px auto;
26 | float: right;
27 | }
28 |
29 | #greeting {
30 | margin: 10px auto;
31 | padding: 10px 60px;
32 | border: 1px solid #222;
33 | }
34 |
35 | #greeting:empty {
36 | display: none;
37 | }
38 |
--------------------------------------------------------------------------------
/batch-transfer-tool/src/batch_transfer_tool_frontend/assets/main.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: sans-serif;
3 | font-size: 1.5rem;
4 | }
5 |
6 | img {
7 | max-width: 50vw;
8 | max-height: 25vw;
9 | display: block;
10 | margin: auto;
11 | }
12 |
13 | form {
14 | display: flex;
15 | justify-content: center;
16 | gap: 0.5em;
17 | flex-flow: row wrap;
18 | max-width: 40vw;
19 | margin: auto;
20 | align-items: baseline;
21 | }
22 |
23 | button[type="submit"] {
24 | padding: 5px 20px;
25 | margin: 10px auto;
26 | float: right;
27 | }
28 |
29 | #greeting {
30 | margin: 10px auto;
31 | padding: 10px 60px;
32 | border: 1px solid #222;
33 | }
34 |
35 | #greeting:empty {
36 | display: none;
37 | }
38 |
--------------------------------------------------------------------------------
/batch-transfer-tool/dfx.json:
--------------------------------------------------------------------------------
1 | {
2 | "canisters": {
3 | "batch_transfer_tool_backend": {
4 | "main": "src/batch_transfer_tool_backend/main.mo",
5 | "type": "motoko"
6 | },
7 | "batch_transfer_tool_frontend": {
8 | "dependencies": [
9 | "batch_transfer_tool_backend"
10 | ],
11 | "frontend": {
12 | "entrypoint": "src/batch_transfer_tool_frontend/src/index.html"
13 | },
14 | "source": [
15 | "src/batch_transfer_tool_frontend/assets",
16 | "dist/batch_transfer_tool_frontend/"
17 | ],
18 | "type": "assets"
19 | }
20 | },
21 | "defaults": {
22 | "build": {
23 | "args": "",
24 | "packtool": ""
25 | }
26 | },
27 | "output_env_file": ".env",
28 | "version": 1
29 | }
--------------------------------------------------------------------------------
/chat/src/chat_frontend/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | chat
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/topup/src/topup_frontend/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | topup
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/sns-metrics/src/metrics_frontend/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | metrics
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/multiplayer/src/multiplayer_frontend/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | multiplayer
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/remote-configs/src/remote_configs_frontend/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | remote_configs
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/remote-configs/src/remote_configs_backend/utils/List.mo:
--------------------------------------------------------------------------------
1 | import Iter "mo:base/Iter";
2 | import List "mo:base/List";
3 |
4 | module {
5 | private type List = List.List;
6 |
7 | public func fromText(t : Text) : List {
8 | fromIter(t.chars());
9 | };
10 |
11 | public func fromIter(i : Iter.Iter) : List {
12 | switch (i.next()) {
13 | case (null) { null; };
14 | case (? v) { ?(v, fromIter(i)); };
15 | };
16 | };
17 |
18 | public class toIter(xs : List) : Iter.Iter {
19 | var list = xs;
20 | public func next() : ?T {
21 | switch (list) {
22 | case (null) { null; };
23 | case (? ys) {
24 | let (x, xs) = ys;
25 | list := xs;
26 | ?x;
27 | };
28 | };
29 | };
30 | };
31 | }
--------------------------------------------------------------------------------
/candid-with-auth/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ui",
3 | "version": "0.1.0",
4 | "description": "",
5 | "keywords": [],
6 | "scripts": {
7 | "build": "webpack"
8 | },
9 | "devDependencies": {
10 | "@dfinity/agent": "^1.0.1",
11 | "@dfinity/auth-client": "^1.0.1",
12 | "@dfinity/candid": "^1.0.1",
13 | "@dfinity/identity": "^1.0.1",
14 | "@dfinity/ledger-icp": "^2.2.1",
15 | "@dfinity/nns": "^4.0.1",
16 | "@dfinity/principal": "^1.0.1",
17 | "@nfid/embed": "^0.10.3",
18 | "@types/react": "^18.3.1",
19 | "buffer": "6.0.3",
20 | "copy-webpack-plugin": "^11.0.0",
21 | "css-loader": "^6.8.1",
22 | "html-webpack-plugin": "^5.5.3",
23 | "style-loader": "^3.3.3",
24 | "terser-webpack-plugin": "^5.3.9",
25 | "ts-loader": "9.4.4",
26 | "tsconfig-paths-webpack-plugin": "^4.1.0",
27 | "typescript": "^5.2.2",
28 | "webpack": "5.88.2",
29 | "webpack-cli": "5.1.4"
30 | },
31 | "dependencies": {
32 | "react": "^18.3.1"
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/candid-with-auth/README.md:
--------------------------------------------------------------------------------
1 | # Candid UI
2 |
3 | This canister generates a front-end UI for any canister running on the Internet Computer.
4 |
5 | The backend `didjs` is build with the [Rust CDK](https://github.com/dfinity/cdk-rs) and the [Candid](../../rust/) crate to convert did file into JavaScript.
6 | The frontend `ui` fetches the Candid interface from the running canister (currently only canisters built by Motoko expose the Candid interface) and renders the UI based on the interface signature.
7 |
8 | ## Build
9 |
10 | You need `dfx`, `cargo`, `npm` and `wasm-opt` for building the canister.
11 |
12 | ```bash
13 | cd ui/
14 | npm install
15 | dfx start --background
16 | dfx canister create --all
17 | dfx build
18 | dfx canister install --all
19 | ```
20 |
21 | ## Usage
22 |
23 | Open the `ui` canister in a browser and supply the id parameter in the URL to render a specific canister,
24 | e.g., `localhost:8000/?canisterId=ui-canister-id&id=target-canister-id` for local dev,
25 | or `ui-canister-id.ic0.app/?id=target-canister-id` for the main network.
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 BoomDAO
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/remote-configs/src/remote_configs_backend/utils/Parser.mo:
--------------------------------------------------------------------------------
1 | import List "mo:base/List";
2 |
3 | module Parser {
4 | private type List = List.List;
5 | public type Parser = List -> ?(A, List);
6 |
7 | // Succeeds without consuming any of the input, and returns the single result x.
8 | public func result(a : A) : Parser {
9 | func (xs : List) { ?(a, xs); };
10 | };
11 |
12 | // Always fails, regardless of the input.
13 | public func zero() : Parser {
14 | func (_ : List) { null; };
15 | };
16 |
17 | // Successfully consumes the first item if the input is non-empty, and fails otherwise.
18 | public func item() : Parser {
19 | func (xs : List) {
20 | switch(xs) {
21 | case (null) { null; };
22 | case (? (x, xs)) {
23 | ?(x, xs);
24 | };
25 | };
26 | };
27 | };
28 |
29 | // Delays the recursion.
30 | public func delay(
31 | function : () -> Parser,
32 | ) : Parser {
33 | func (xs : List) { function()(xs); };
34 | };
35 | };
--------------------------------------------------------------------------------
/chat/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "chat_frontend",
3 | "version": "0.1.0",
4 | "description": "Internet Computer starter application",
5 | "keywords": ["Internet Computer", "Motoko", "JavaScript", "Canister"],
6 | "scripts": {
7 | "build": "webpack",
8 | "prebuild": "npm run generate",
9 | "start": "webpack serve --mode development --env development",
10 | "prestart": "npm run generate",
11 | "generate": "dfx generate chat_backend"
12 | },
13 | "devDependencies": {
14 | "@dfinity/agent": "0.15.6",
15 | "@dfinity/candid": "0.15.6",
16 | "@dfinity/principal": "0.15.6",
17 | "assert": "2.0.0",
18 | "buffer": "6.0.3",
19 | "copy-webpack-plugin": "^11.0.0",
20 | "events": "3.3.0",
21 | "html-webpack-plugin": "5.5.0",
22 | "process": "0.11.10",
23 | "stream-browserify": "3.0.0",
24 | "terser-webpack-plugin": "^5.3.3",
25 | "util": "0.12.4",
26 | "webpack": "^5.73.0",
27 | "webpack-cli": "^4.10.0",
28 | "webpack-dev-server": "^4.8.1"
29 | },
30 | "engines": {
31 | "node": "^12 || ^14 || ^16 || ^18"
32 | },
33 | "browserslist": [
34 | "last 2 chrome version",
35 | "last 2 firefox version",
36 | "last 2 safari version",
37 | "last 2 edge version"
38 | ]
39 | }
40 |
--------------------------------------------------------------------------------
/topup/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "topup_frontend",
3 | "version": "0.1.0",
4 | "description": "Internet Computer starter application",
5 | "keywords": ["Internet Computer", "Motoko", "JavaScript", "Canister"],
6 | "scripts": {
7 | "build": "webpack",
8 | "prebuild": "npm run generate",
9 | "start": "webpack serve --mode development --env development",
10 | "prestart": "npm run generate",
11 | "generate": "dfx generate topup_backend"
12 | },
13 | "devDependencies": {
14 | "@dfinity/agent": "0.17.0",
15 | "@dfinity/candid": "0.17.0",
16 | "@dfinity/principal": "0.17.0",
17 | "assert": "2.0.0",
18 | "buffer": "6.0.3",
19 | "copy-webpack-plugin": "^11.0.0",
20 | "events": "3.3.0",
21 | "html-webpack-plugin": "5.5.0",
22 | "process": "0.11.10",
23 | "stream-browserify": "3.0.0",
24 | "terser-webpack-plugin": "^5.3.3",
25 | "util": "0.12.4",
26 | "webpack": "^5.73.0",
27 | "webpack-cli": "^4.10.0",
28 | "webpack-dev-server": "^4.8.1"
29 | },
30 | "engines": {
31 | "node": "^12 || ^14 || ^16 || ^18"
32 | },
33 | "browserslist": [
34 | "last 2 chrome version",
35 | "last 2 firefox version",
36 | "last 2 safari version",
37 | "last 2 edge version"
38 | ]
39 | }
40 |
--------------------------------------------------------------------------------
/multiplayer/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "multiplayer_frontend",
3 | "version": "0.1.0",
4 | "description": "Internet Computer starter application",
5 | "keywords": ["Internet Computer", "Motoko", "JavaScript", "Canister"],
6 | "scripts": {
7 | "build": "webpack",
8 | "prebuild": "npm run generate",
9 | "start": "webpack serve --mode development --env development",
10 | "prestart": "npm run generate",
11 | "generate": "dfx generate multiplayer_backend"
12 | },
13 | "devDependencies": {
14 | "@dfinity/agent": "0.15.6",
15 | "@dfinity/candid": "0.15.6",
16 | "@dfinity/principal": "0.15.6",
17 | "assert": "2.0.0",
18 | "buffer": "6.0.3",
19 | "copy-webpack-plugin": "^11.0.0",
20 | "events": "3.3.0",
21 | "html-webpack-plugin": "5.5.0",
22 | "process": "0.11.10",
23 | "stream-browserify": "3.0.0",
24 | "terser-webpack-plugin": "^5.3.3",
25 | "util": "0.12.4",
26 | "webpack": "^5.73.0",
27 | "webpack-cli": "^4.10.0",
28 | "webpack-dev-server": "^4.8.1"
29 | },
30 | "engines": {
31 | "node": "^12 || ^14 || ^16 || ^18"
32 | },
33 | "browserslist": [
34 | "last 2 chrome version",
35 | "last 2 firefox version",
36 | "last 2 safari version",
37 | "last 2 edge version"
38 | ]
39 | }
40 |
--------------------------------------------------------------------------------
/remote-configs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "remote_configs_frontend",
3 | "version": "0.1.0",
4 | "description": "Internet Computer starter application",
5 | "keywords": ["Internet Computer", "Motoko", "JavaScript", "Canister"],
6 | "scripts": {
7 | "build": "webpack",
8 | "prebuild": "npm run generate",
9 | "start": "webpack serve --mode development --env development",
10 | "prestart": "npm run generate",
11 | "generate": "dfx generate remote_configs_backend"
12 | },
13 | "devDependencies": {
14 | "@dfinity/agent": "0.15.6",
15 | "@dfinity/candid": "0.15.6",
16 | "@dfinity/principal": "0.15.6",
17 | "assert": "2.0.0",
18 | "buffer": "6.0.3",
19 | "copy-webpack-plugin": "^11.0.0",
20 | "events": "3.3.0",
21 | "html-webpack-plugin": "5.5.0",
22 | "process": "0.11.10",
23 | "stream-browserify": "3.0.0",
24 | "terser-webpack-plugin": "^5.3.3",
25 | "util": "0.12.4",
26 | "webpack": "^5.73.0",
27 | "webpack-cli": "^4.10.0",
28 | "webpack-dev-server": "^4.8.1"
29 | },
30 | "engines": {
31 | "node": "^12 || ^14 || ^16 || ^18"
32 | },
33 | "browserslist": [
34 | "last 2 chrome version",
35 | "last 2 firefox version",
36 | "last 2 safari version",
37 | "last 2 edge version"
38 | ]
39 | }
40 |
--------------------------------------------------------------------------------
/login-webpage/src/login-webpage/assets/main.css:
--------------------------------------------------------------------------------
1 | @import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@300&display=swap');
2 | body {
3 | display: flex;
4 | justify-content: center;
5 | align-items: center;
6 | height: 100vh;
7 | font-family: 'Open Sans', sans-serif;
8 | }
9 |
10 | main {
11 | display: flex;
12 | flex-direction: column;
13 | align-items: center;
14 | gap: 20px;
15 | }
16 |
17 | button[type="submit"] {
18 | padding: 1vw;
19 | background-color: white;
20 | color: black;
21 | border: 0.13vw solid black; /* Thicker border */
22 | cursor: pointer;
23 | font-size: 2vw; /* Font size relative to viewport width */
24 | border-radius: 0.5vw;
25 | transition: 0.3s;
26 | font-family: 'Open Sans', sans-serif;
27 | font-weight: 300;
28 | width: 40vw; /* Width of the button relative to viewport width */
29 | height: 20vh; /* Width of the button relative to viewport width */
30 | text-align: center;
31 | }
32 |
33 | button[type="submit"]:hover {
34 | background-color: #f3f3f3;
35 | box-shadow: 0 0.8vw 1.6vw 0 rgba(0,0,0,0.2);
36 | }
37 |
38 | .button-icon {
39 | width: 5vw; /* Icon size relative to viewport width */
40 | height: 5vw; /* Icon size relative to viewport width */
41 | margin-right: 0.5vw;
42 | vertical-align: middle;
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/sns-metrics/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "metrics_frontend",
3 | "version": "0.2.0",
4 | "description": "Internet Computer starter application",
5 | "keywords": [
6 | "Internet Computer",
7 | "Motoko",
8 | "JavaScript",
9 | "Canister"
10 | ],
11 | "scripts": {
12 | "build": "webpack",
13 | "prebuild": "dfx generate",
14 | "start": "webpack serve --mode development --env development",
15 | "deploy:local": "dfx deploy --network=local",
16 | "deploy:ic": "dfx deploy --network=ic",
17 | "generate": "dfx generate metrics_backend"
18 | },
19 | "dependencies": {
20 | "@dfinity/agent": "^0.19.3",
21 | "@dfinity/candid": "^0.19.3",
22 | "@dfinity/principal": "^0.19.3"
23 | },
24 | "devDependencies": {
25 | "assert": "2.0.0",
26 | "buffer": "6.0.3",
27 | "copy-webpack-plugin": "^11.0.0",
28 | "dotenv": "^16.0.3",
29 | "events": "3.3.0",
30 | "html-webpack-plugin": "5.5.0",
31 | "process": "0.11.10",
32 | "stream-browserify": "3.0.0",
33 | "terser-webpack-plugin": "^5.3.3",
34 | "util": "0.12.4",
35 | "webpack": "^5.73.0",
36 | "webpack-cli": "^4.10.0",
37 | "webpack-dev-server": "^4.8.1"
38 | },
39 | "engines": {
40 | "node": "^12 || ^14 || ^16 || ^18"
41 | },
42 | "browserslist": [
43 | "last 2 chrome version",
44 | "last 2 firefox version",
45 | "last 2 safari version",
46 | "last 2 edge version"
47 | ]
48 | }
49 |
--------------------------------------------------------------------------------
/login-webpage/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "login-webpage",
3 | "version": "0.1.0",
4 | "description": "login-webpage",
5 | "keywords": [
6 | "Internet Computer",
7 | "Motoko",
8 | "JavaScript",
9 | "Canister"
10 | ],
11 | "scripts": {
12 | "build": "webpack",
13 | "start": "webpack serve --mode development --env development"
14 | },
15 | "devDependencies": {
16 | "@babel/core": "^7.26.0",
17 | "@babel/preset-env": "^7.26.0",
18 | "@babel/preset-react": "^7.26.3",
19 | "assert": "2.0.0",
20 | "babel-loader": "^9.2.1",
21 | "buffer": "6.0.3",
22 | "copy-webpack-plugin": "^11.0.0",
23 | "css-loader": "^7.1.2",
24 | "events": "3.3.0",
25 | "html-webpack-plugin": "5.5.0",
26 | "process": "0.11.10",
27 | "stream-browserify": "3.0.0",
28 | "style-loader": "^4.0.0",
29 | "terser-webpack-plugin": "^5.3.3",
30 | "ts-loader": "^9.4.2",
31 | "typescript": "^4.9.5",
32 | "util": "^0.12.4",
33 | "webpack": "^5.73.0",
34 | "webpack-cli": "^4.10.0",
35 | "webpack-dev-server": "^4.8.1"
36 | },
37 | "engines": {
38 | "node": "^12 || ^14 || ^16 || ^18"
39 | },
40 | "browserslist": [
41 | "last 2 chrome version",
42 | "last 2 firefox version",
43 | "last 2 safari version",
44 | "last 2 edge version"
45 | ],
46 | "dependencies": {
47 | "@dfinity/agent": "^2.2.0",
48 | "@dfinity/auth-client": "^2.2.0",
49 | "@dfinity/candid": "^2.2.0",
50 | "@dfinity/identity": "^2.2.0",
51 | "@dfinity/ledger-icp": "^2.6.5",
52 | "@dfinity/principal": "^2.2.0",
53 | "@dfinity/utils": "^2.8.0",
54 | "@nfid/embed": "^0.10.3",
55 | "@nfid/identitykit": "^1.0.7"
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/batch-transfer-tool/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "batch_transfer_tool_frontend",
3 | "version": "0.1.0",
4 | "description": "Internet Computer starter application",
5 | "keywords": [
6 | "Internet Computer",
7 | "Motoko",
8 | "JavaScript",
9 | "Canister"
10 | ],
11 | "scripts": {
12 | "build": "webpack",
13 | "prebuild": "npm run generate",
14 | "start": "webpack serve --mode development --env development",
15 | "prestart": "npm run generate",
16 | "generate": ""
17 | },
18 | "devDependencies": {
19 | "@dfinity/agent": "^0.15.1",
20 | "@dfinity/auth-client": "^0.15.1",
21 | "@dfinity/authentication": "^0.14.1",
22 | "@dfinity/candid": "^0.15.1",
23 | "@dfinity/identity": "^0.15.1",
24 | "@dfinity/nns": "^0.10.0",
25 | "@dfinity/principal": "^0.15.1",
26 | "assert": "2.0.0",
27 | "buffer": "6.0.3",
28 | "copy-webpack-plugin": "^11.0.0",
29 | "events": "3.3.0",
30 | "html-webpack-plugin": "5.5.0",
31 | "process": "0.11.10",
32 | "stream-browserify": "3.0.0",
33 | "terser-webpack-plugin": "^5.3.3",
34 | "ts-loader": "^9.4.2",
35 | "typescript": "^4.9.3",
36 | "util": "0.12.4",
37 | "webpack": "^5.73.0",
38 | "webpack-cli": "^4.10.0",
39 | "webpack-dev-server": "^4.8.1"
40 | },
41 | "engines": {
42 | "node": "^12 || ^14 || ^16 || ^18"
43 | },
44 | "browserslist": [
45 | "last 2 chrome version",
46 | "last 2 firefox version",
47 | "last 2 safari version",
48 | "last 2 edge version"
49 | ],
50 | "dependencies": {
51 | "@psychedelic/dab-js": "^1.6.0-alpha.2",
52 | "@psychedelic/plug-connect": "^0.2.0",
53 | "buffer-crc32": "^0.2.13",
54 | "crypto-js": "^4.1.1",
55 | "react": "^18.2.0",
56 | "react-dom": "^18.2.0",
57 | "react-loader-spinner": "^5.3.4"
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/login-webpage/src/login-webpage/assets/.ic-assets.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "match": ".ic-assets.json",
4 | "headers": {
5 | "Access-Control-Allow-Origin": "*"
6 | },
7 | "ignore": false
8 | },
9 | {
10 | "match": ".well-known",
11 | "headers": {
12 | "Access-Control-Allow-Origin": "https://nfid.one"
13 | },
14 | "ignore": false
15 | },
16 | {
17 | "match": ".well-known/ii-alternative-origins",
18 | "headers": {
19 | "Access-Control-Allow-Origin": "https://nfid.one",
20 | "Content-Type": "application/json"
21 | },
22 | "ignore": false
23 | },
24 | {
25 | "match": "**/*",
26 | "headers": {
27 |
28 | "Permissions-Policy": "accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), window-placement=(), vertical-scroll=()",
29 | "X-Frame-Options": "ALLOW-FROM https://nfid.one/",
30 | "Referrer-Policy": "same-origin",
31 | "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
32 | "X-Content-Type-Options": "nosniff",
33 | "X-XSS-Protection": "1; mode=block"
34 | },
35 | "allow_raw_access": true
36 | }
37 | ]
38 |
--------------------------------------------------------------------------------
/utilities/world.types.mo:
--------------------------------------------------------------------------------
1 | import A "mo:base/AssocList";
2 | import Array "mo:base/Array";
3 | import Blob "mo:base/Blob";
4 | import Bool "mo:base/Bool";
5 | import Buffer "mo:base/Buffer";
6 | import Cycles "mo:base/ExperimentalCycles";
7 | import Char "mo:base/Char";
8 | import Error "mo:base/Error";
9 | import Float "mo:base/Float";
10 | import HashMap "mo:base/HashMap";
11 | import Hash "mo:base/Hash";
12 | import Map "mo:base/HashMap";
13 | import Int "mo:base/Int";
14 | import Int16 "mo:base/Int16";
15 | import Int8 "mo:base/Int8";
16 | import Iter "mo:base/Iter";
17 | import L "mo:base/List";
18 | import Nat "mo:base/Nat";
19 | import Nat8 "mo:base/Nat8";
20 | import Nat32 "mo:base/Nat32";
21 | import Nat64 "mo:base/Nat64";
22 | import Option "mo:base/Option";
23 | import Prelude "mo:base/Prelude";
24 | import Prim "mo:prim";
25 | import Principal "mo:base/Principal";
26 | import Result "mo:base/Result";
27 | import Text "mo:base/Text";
28 | import Time "mo:base/Time";
29 | import Trie "mo:base/Trie";
30 | import Trie2D "mo:base/Trie";
31 |
32 | module {
33 | public type userId = Text;
34 | public type worldId = Text;
35 | public type groupId = Text;
36 | public type entityId = Text;
37 | public type actionId = Text;
38 | public type nodeId = Text;
39 |
40 | public type Entity = {
41 | eid : Text;
42 | gid : Text;
43 | wid : Text;
44 | attribute : ?Text;
45 | quantity : ?Float;
46 | expiration : ?Nat;
47 | };
48 | public type Action = {
49 | intervalStartTs : Nat;
50 | actionCount : Nat;
51 | };
52 | public type EntityPermission = {
53 | #spendQuantityCap: { intervalDuration: Nat; capPerInterval: Float; };
54 | #receiveQuantityCap : { intervalDuration: Nat; capPerInterval: Float; };
55 | #renewExpirationCap : { intervalDuration: Nat; capPerInterval: Nat; };
56 | #reduceExpirationCap : { intervalDuration: Nat; capPerInterval: Nat; };
57 | };
58 | };
59 |
--------------------------------------------------------------------------------
/candid-with-auth/.dfx/ic/canisters/didjs/index.js:
--------------------------------------------------------------------------------
1 | import { Actor, HttpAgent } from "@dfinity/agent";
2 |
3 | // Imports and re-exports candid interface
4 | import { idlFactory } from './didjs.did.js';
5 | export { idlFactory } from './didjs.did.js';
6 | // CANISTER_ID is replaced by webpack based on node environment
7 | export const canisterId = process.env.CANISTER_ID_DIDJS;
8 |
9 | /**
10 | * @deprecated since dfx 0.11.1
11 | * Do not import from `.dfx`, instead switch to using `dfx generate` to generate your JS interface.
12 | * @param {string | import("@dfinity/principal").Principal} canisterId Canister ID of Agent
13 | * @param {{agentOptions?: import("@dfinity/agent").HttpAgentOptions; actorOptions?: import("@dfinity/agent").ActorConfig} | { agent?: import("@dfinity/agent").Agent; actorOptions?: import("@dfinity/agent").ActorConfig }} [options]
14 | * @return {import("@dfinity/agent").ActorSubclass}
15 | */
16 | export const createActor = (canisterId, options = {}) => {
17 | console.warn(`Deprecation warning: you are currently importing code from .dfx. Going forward, refactor to use the dfx generate command for JavaScript bindings.
18 |
19 | See https://internetcomputer.org/docs/current/developer-docs/updates/release-notes/ for migration instructions`);
20 | const agent = options.agent || new HttpAgent({ ...options.agentOptions });
21 |
22 | // Fetch root key for certificate validation during development
23 | if (process.env.DFX_NETWORK !== "ic") {
24 | agent.fetchRootKey().catch(err => {
25 | console.warn("Unable to fetch root key. Check to ensure that your local replica is running");
26 | console.error(err);
27 | });
28 | }
29 |
30 | // Creates an actor with using the candid interface and the HttpAgent
31 | return Actor.createActor(idlFactory, {
32 | agent,
33 | canisterId,
34 | ...(options ? options.actorOptions : {}),
35 | });
36 | };
37 |
38 | /**
39 | * A ready-to-use agent for the didjs canister
40 | * @type {import("@dfinity/agent").ActorSubclass}
41 | */
42 | export const didjs = createActor(canisterId);
43 |
--------------------------------------------------------------------------------
/candid-with-auth/.dfx/local/canisters/didjs/index.js:
--------------------------------------------------------------------------------
1 | import { Actor, HttpAgent } from "@dfinity/agent";
2 |
3 | // Imports and re-exports candid interface
4 | import { idlFactory } from './didjs.did.js';
5 | export { idlFactory } from './didjs.did.js';
6 | // CANISTER_ID is replaced by webpack based on node environment
7 | export const canisterId = process.env.DIDJS_CANISTER_ID;
8 |
9 | /**
10 | * @deprecated since dfx 0.11.1
11 | * Do not import from `.dfx`, instead switch to using `dfx generate` to generate your JS interface.
12 | * @param {string | import("@dfinity/principal").Principal} canisterId Canister ID of Agent
13 | * @param {{agentOptions?: import("@dfinity/agent").HttpAgentOptions; actorOptions?: import("@dfinity/agent").ActorConfig} | { agent?: import("@dfinity/agent").Agent; actorOptions?: import("@dfinity/agent").ActorConfig }} [options]
14 | * @return {import("@dfinity/agent").ActorSubclass}
15 | */
16 | export const createActor = (canisterId, options = {}) => {
17 | console.warn(`Deprecation warning: you are currently importing code from .dfx. Going forward, refactor to use the dfx generate command for JavaScript bindings.
18 |
19 | See https://internetcomputer.org/docs/current/developer-docs/updates/release-notes/ for migration instructions`);
20 | const agent = options.agent || new HttpAgent({ ...options.agentOptions });
21 |
22 | // Fetch root key for certificate validation during development
23 | if (process.env.DFX_NETWORK !== "ic") {
24 | agent.fetchRootKey().catch(err => {
25 | console.warn("Unable to fetch root key. Check to ensure that your local replica is running");
26 | console.error(err);
27 | });
28 | }
29 |
30 | // Creates an actor with using the candid interface and the HttpAgent
31 | return Actor.createActor(idlFactory, {
32 | agent,
33 | canisterId,
34 | ...(options ? options.actorOptions : {}),
35 | });
36 | };
37 |
38 | /**
39 | * A ready-to-use agent for the didjs canister
40 | * @type {import("@dfinity/agent").ActorSubclass}
41 | */
42 | export const didjs = createActor(canisterId);
43 |
--------------------------------------------------------------------------------
/candid-with-auth/.dfx/stag/canisters/didjs/index.js:
--------------------------------------------------------------------------------
1 | import { Actor, HttpAgent } from "@dfinity/agent";
2 |
3 | // Imports and re-exports candid interface
4 | import { idlFactory } from './didjs.did.js';
5 | export { idlFactory } from './didjs.did.js';
6 | // CANISTER_ID is replaced by webpack based on node environment
7 | export const canisterId = process.env.CANISTER_ID_DIDJS;
8 |
9 | /**
10 | * @deprecated since dfx 0.11.1
11 | * Do not import from `.dfx`, instead switch to using `dfx generate` to generate your JS interface.
12 | * @param {string | import("@dfinity/principal").Principal} canisterId Canister ID of Agent
13 | * @param {{agentOptions?: import("@dfinity/agent").HttpAgentOptions; actorOptions?: import("@dfinity/agent").ActorConfig} | { agent?: import("@dfinity/agent").Agent; actorOptions?: import("@dfinity/agent").ActorConfig }} [options]
14 | * @return {import("@dfinity/agent").ActorSubclass}
15 | */
16 | export const createActor = (canisterId, options = {}) => {
17 | console.warn(`Deprecation warning: you are currently importing code from .dfx. Going forward, refactor to use the dfx generate command for JavaScript bindings.
18 |
19 | See https://internetcomputer.org/docs/current/developer-docs/updates/release-notes/ for migration instructions`);
20 | const agent = options.agent || new HttpAgent({ ...options.agentOptions });
21 |
22 | // Fetch root key for certificate validation during development
23 | if (process.env.DFX_NETWORK !== "ic") {
24 | agent.fetchRootKey().catch(err => {
25 | console.warn("Unable to fetch root key. Check to ensure that your local replica is running");
26 | console.error(err);
27 | });
28 | }
29 |
30 | // Creates an actor with using the candid interface and the HttpAgent
31 | return Actor.createActor(idlFactory, {
32 | agent,
33 | canisterId,
34 | ...(options ? options.actorOptions : {}),
35 | });
36 | };
37 |
38 | /**
39 | * A ready-to-use agent for the didjs canister
40 | * @type {import("@dfinity/agent").ActorSubclass}
41 | */
42 | export const didjs = createActor(canisterId);
43 |
--------------------------------------------------------------------------------
/chat/README.md:
--------------------------------------------------------------------------------
1 | # chat
2 |
3 | Welcome to your new chat project and to the internet computer development community. By default, creating a new project adds this README and some template files to your project directory. You can edit these template files to customize your project and to include your own code to speed up the development cycle.
4 |
5 | To get started, you might want to explore the project directory structure and the default configuration file. Working with this project in your development environment will not affect any production deployment or identity tokens.
6 |
7 | To learn more before you start working with chat, see the following documentation available online:
8 |
9 | - [Quick Start](https://internetcomputer.org/docs/current/developer-docs/quickstart/hello10mins)
10 | - [SDK Developer Tools](https://internetcomputer.org/docs/current/developer-docs/build/install-upgrade-remove)
11 | - [Motoko Programming Language Guide](https://internetcomputer.org/docs/current/developer-docs/build/cdks/motoko-dfinity/motoko/)
12 | - [Motoko Language Quick Reference](https://internetcomputer.org/docs/current/references/motoko-ref/)
13 | - [JavaScript API Reference](https://erxue-5aaaa-aaaab-qaagq-cai.raw.ic0.app)
14 |
15 | If you want to start working on your project right away, you might want to try the following commands:
16 |
17 | ```bash
18 | cd chat/
19 | dfx help
20 | dfx canister --help
21 | ```
22 |
23 | ## Running the project locally
24 |
25 | If you want to test your project locally, you can use the following commands:
26 |
27 | ```bash
28 | # Starts the replica, running in the background
29 | dfx start --background
30 |
31 | # Deploys your canisters to the replica and generates your candid interface
32 | dfx deploy
33 | ```
34 |
35 | Once the job completes, your application will be available at `http://localhost:4943?canisterId={asset_canister_id}`.
36 |
37 | Additionally, if you are making frontend changes, you can start a development server with
38 |
39 | ```bash
40 | npm start
41 | ```
42 |
43 | Which will start a server at `http://localhost:8080`, proxying API requests to the replica at port 4943.
44 |
45 | ### Note on frontend environment variables
46 |
47 | If you are hosting frontend code somewhere without using DFX, you may need to make one of the following adjustments to ensure your project does not fetch the root key in production:
48 |
49 | - set`NODE_ENV` to `production` if you are using Webpack
50 | - use your own preferred method to replace `process.env.NODE_ENV` in the autogenerated declarations
51 | - Write your own `createActor` constructor
52 |
--------------------------------------------------------------------------------
/topup/README.md:
--------------------------------------------------------------------------------
1 | # topup
2 |
3 | Welcome to your new topup project and to the internet computer development community. By default, creating a new project adds this README and some template files to your project directory. You can edit these template files to customize your project and to include your own code to speed up the development cycle.
4 |
5 | To get started, you might want to explore the project directory structure and the default configuration file. Working with this project in your development environment will not affect any production deployment or identity tokens.
6 |
7 | To learn more before you start working with topup, see the following documentation available online:
8 |
9 | - [Quick Start](https://internetcomputer.org/docs/current/developer-docs/quickstart/hello10mins)
10 | - [SDK Developer Tools](https://internetcomputer.org/docs/current/developer-docs/build/install-upgrade-remove)
11 | - [Motoko Programming Language Guide](https://internetcomputer.org/docs/current/developer-docs/build/cdks/motoko-dfinity/motoko/)
12 | - [Motoko Language Quick Reference](https://internetcomputer.org/docs/current/references/motoko-ref/)
13 | - [JavaScript API Reference](https://erxue-5aaaa-aaaab-qaagq-cai.raw.ic0.app)
14 |
15 | If you want to start working on your project right away, you might want to try the following commands:
16 |
17 | ```bash
18 | cd topup/
19 | dfx help
20 | dfx canister --help
21 | ```
22 |
23 | ## Running the project locally
24 |
25 | If you want to test your project locally, you can use the following commands:
26 |
27 | ```bash
28 | # Starts the replica, running in the background
29 | dfx start --background
30 |
31 | # Deploys your canisters to the replica and generates your candid interface
32 | dfx deploy
33 | ```
34 |
35 | Once the job completes, your application will be available at `http://localhost:4943?canisterId={asset_canister_id}`.
36 |
37 | Additionally, if you are making frontend changes, you can start a development server with
38 |
39 | ```bash
40 | npm start
41 | ```
42 |
43 | Which will start a server at `http://localhost:8080`, proxying API requests to the replica at port 4943.
44 |
45 | ### Note on frontend environment variables
46 |
47 | If you are hosting frontend code somewhere without using DFX, you may need to make one of the following adjustments to ensure your project does not fetch the root key in production:
48 |
49 | - set`NODE_ENV` to `production` if you are using Webpack
50 | - use your own preferred method to replace `process.env.NODE_ENV` in the autogenerated declarations
51 | - Write your own `createActor` constructor
52 |
--------------------------------------------------------------------------------
/multiplayer/README.md:
--------------------------------------------------------------------------------
1 | # multiplayer
2 |
3 | Welcome to your new multiplayer project and to the internet computer development community. By default, creating a new project adds this README and some template files to your project directory. You can edit these template files to customize your project and to include your own code to speed up the development cycle.
4 |
5 | To get started, you might want to explore the project directory structure and the default configuration file. Working with this project in your development environment will not affect any production deployment or identity tokens.
6 |
7 | To learn more before you start working with multiplayer, see the following documentation available online:
8 |
9 | - [Quick Start](https://internetcomputer.org/docs/current/developer-docs/quickstart/hello10mins)
10 | - [SDK Developer Tools](https://internetcomputer.org/docs/current/developer-docs/build/install-upgrade-remove)
11 | - [Motoko Programming Language Guide](https://internetcomputer.org/docs/current/developer-docs/build/cdks/motoko-dfinity/motoko/)
12 | - [Motoko Language Quick Reference](https://internetcomputer.org/docs/current/references/motoko-ref/)
13 | - [JavaScript API Reference](https://erxue-5aaaa-aaaab-qaagq-cai.raw.ic0.app)
14 |
15 | If you want to start working on your project right away, you might want to try the following commands:
16 |
17 | ```bash
18 | cd multiplayer/
19 | dfx help
20 | dfx canister --help
21 | ```
22 |
23 | ## Running the project locally
24 |
25 | If you want to test your project locally, you can use the following commands:
26 |
27 | ```bash
28 | # Starts the replica, running in the background
29 | dfx start --background
30 |
31 | # Deploys your canisters to the replica and generates your candid interface
32 | dfx deploy
33 | ```
34 |
35 | Once the job completes, your application will be available at `http://localhost:4943?canisterId={asset_canister_id}`.
36 |
37 | Additionally, if you are making frontend changes, you can start a development server with
38 |
39 | ```bash
40 | npm start
41 | ```
42 |
43 | Which will start a server at `http://localhost:8080`, proxying API requests to the replica at port 4943.
44 |
45 | ### Note on frontend environment variables
46 |
47 | If you are hosting frontend code somewhere without using DFX, you may need to make one of the following adjustments to ensure your project does not fetch the root key in production:
48 |
49 | - set`NODE_ENV` to `production` if you are using Webpack
50 | - use your own preferred method to replace `process.env.NODE_ENV` in the autogenerated declarations
51 | - Write your own `createActor` constructor
52 |
--------------------------------------------------------------------------------
/remote-configs/README.md:
--------------------------------------------------------------------------------
1 | # remote_configs
2 |
3 | Welcome to your new remote_configs project and to the internet computer development community. By default, creating a new project adds this README and some template files to your project directory. You can edit these template files to customize your project and to include your own code to speed up the development cycle.
4 |
5 | To get started, you might want to explore the project directory structure and the default configuration file. Working with this project in your development environment will not affect any production deployment or identity tokens.
6 |
7 | To learn more before you start working with remote_configs, see the following documentation available online:
8 |
9 | - [Quick Start](https://internetcomputer.org/docs/current/developer-docs/quickstart/hello10mins)
10 | - [SDK Developer Tools](https://internetcomputer.org/docs/current/developer-docs/build/install-upgrade-remove)
11 | - [Motoko Programming Language Guide](https://internetcomputer.org/docs/current/developer-docs/build/cdks/motoko-dfinity/motoko/)
12 | - [Motoko Language Quick Reference](https://internetcomputer.org/docs/current/references/motoko-ref/)
13 | - [JavaScript API Reference](https://erxue-5aaaa-aaaab-qaagq-cai.raw.ic0.app)
14 |
15 | If you want to start working on your project right away, you might want to try the following commands:
16 |
17 | ```bash
18 | cd remote_configs/
19 | dfx help
20 | dfx canister --help
21 | ```
22 |
23 | ## Running the project locally
24 |
25 | If you want to test your project locally, you can use the following commands:
26 |
27 | ```bash
28 | # Starts the replica, running in the background
29 | dfx start --background
30 |
31 | # Deploys your canisters to the replica and generates your candid interface
32 | dfx deploy
33 | ```
34 |
35 | Once the job completes, your application will be available at `http://localhost:4943?canisterId={asset_canister_id}`.
36 |
37 | Additionally, if you are making frontend changes, you can start a development server with
38 |
39 | ```bash
40 | npm start
41 | ```
42 |
43 | Which will start a server at `http://localhost:8080`, proxying API requests to the replica at port 4943.
44 |
45 | ### Note on frontend environment variables
46 |
47 | If you are hosting frontend code somewhere without using DFX, you may need to make one of the following adjustments to ensure your project does not fetch the root key in production:
48 |
49 | - set`NODE_ENV` to `production` if you are using Webpack
50 | - use your own preferred method to replace `process.env.NODE_ENV` in the autogenerated declarations
51 | - Write your own `createActor` constructor
52 |
--------------------------------------------------------------------------------
/batch-transfer-tool/README.md:
--------------------------------------------------------------------------------
1 | # batch-transfer-tool
2 |
3 | Welcome to your new batch_transfer_tool project and to the internet computer development community. By default, creating a new project adds this README and some template files to your project directory. You can edit these template files to customize your project and to include your own code to speed up the development cycle.
4 |
5 | To get started, you might want to explore the project directory structure and the default configuration file. Working with this project in your development environment will not affect any production deployment or identity tokens.
6 |
7 | To learn more before you start working with batch_transfer_tool, see the following documentation available online:
8 |
9 | - [Quick Start](https://internetcomputer.org/docs/current/developer-docs/quickstart/hello10mins)
10 | - [SDK Developer Tools](https://internetcomputer.org/docs/current/developer-docs/build/install-upgrade-remove)
11 | - [Motoko Programming Language Guide](https://internetcomputer.org/docs/current/developer-docs/build/cdks/motoko-dfinity/motoko/)
12 | - [Motoko Language Quick Reference](https://internetcomputer.org/docs/current/references/motoko-ref/)
13 | - [JavaScript API Reference](https://erxue-5aaaa-aaaab-qaagq-cai.raw.ic0.app)
14 |
15 | If you want to start working on your project right away, you might want to try the following commands:
16 |
17 | ```bash
18 | cd batch_transfer_tool/
19 | dfx help
20 | dfx canister --help
21 | ```
22 |
23 | ## Running the project locally
24 |
25 | If you want to test your project locally, you can use the following commands:
26 |
27 | ```bash
28 | # Starts the replica, running in the background
29 | dfx start --background
30 |
31 | # Deploys your canisters to the replica and generates your candid interface
32 | dfx deploy
33 | ```
34 |
35 | Once the job completes, your application will be available at `http://localhost:4943?canisterId={asset_canister_id}`.
36 |
37 | Additionally, if you are making frontend changes, you can start a development server with
38 |
39 | ```bash
40 | npm start
41 | ```
42 |
43 | Which will start a server at `http://localhost:8080`, proxying API requests to the replica at port 4943.
44 |
45 | ### Note on frontend environment variables
46 |
47 | If you are hosting frontend code somewhere without using DFX, you may need to make one of the following adjustments to ensure your project does not fetch the root key in production:
48 |
49 | - set`NODE_ENV` to `production` if you are using Webpack
50 | - use your own preferred method to replace `process.env.NODE_ENV` in the autogenerated declarations
51 | - Write your own `createActor` constructor
52 |
--------------------------------------------------------------------------------
/login-webpage/src/login-webpage/src/alt_index.js:
--------------------------------------------------------------------------------
1 | import { AuthClient } from "@dfinity/auth-client";
2 | import { HttpAgent } from "@dfinity/agent";
3 | import { MyStorage } from "./MyStorage";
4 |
5 | let identity = null;
6 | let storage = new MyStorage();
7 |
8 | function toggleElements(isDisabled, isHidden) {
9 | const click = document.getElementById("click");
10 |
11 | click.disabled = isDisabled;
12 | click.hidden = isHidden;
13 | }
14 |
15 | async function handleButtonClick(e) {
16 | e.preventDefault();
17 |
18 | toggleElements(true, true);
19 |
20 | await GetIdentity();
21 |
22 | toggleElements(false, false);
23 |
24 | return false;
25 | }
26 |
27 | document.getElementById("click").addEventListener("click", handleButtonClick);
28 |
29 |
30 | // open web socket
31 | const webSocket = new WebSocket('ws://localhost:8080/Data');
32 |
33 | webSocket.addEventListener('open', () => {
34 | console.log('WebSocket connection established.');
35 | });
36 |
37 | function sendWebsocketMessage(message) {
38 | webSocket.send(message);
39 | }
40 |
41 | export async function GetIdentity() {
42 | try {
43 | // NFID
44 | const APPLICATION_NAME = "BOOM DAO";
45 | const APPLICATION_LOGO_URL = "https://i.postimg.cc/L4f471FF/logo.png";
46 | const AUTH_PATH =
47 | "/authenticate/?applicationName=" + APPLICATION_NAME + "&applicationLogo=" + APPLICATION_LOGO_URL + "#authorize";
48 | const NFID_AUTH_URL = "https://nfid.one" + AUTH_PATH;
49 |
50 | if (identity == null) {
51 | const authClient = await AuthClient.create({
52 | storage: storage,
53 | keyType: 'Ed25519',
54 | });
55 |
56 | await new Promise((resolve, reject) => {
57 | authClient.login({
58 | identityProvider: NFID_AUTH_URL,
59 | windowOpenerFeatures:
60 | `left=${window.screen.width / 2 - 525 / 2}, ` +
61 | `top=${window.screen.height / 2 - 705 / 2},` +
62 | `toolbar=0,location=0,menubar=0,width=525,height=705`,
63 | derivationOrigin: "https://7p3gx-jaaaa-aaaal-acbda-cai.ic0.app",
64 | onSuccess: resolve,
65 | onError: reject,
66 | });
67 | });
68 |
69 | identity = authClient.getIdentity();
70 | }
71 |
72 | console.log("referrer=" + document.referrer);
73 |
74 | if (window.parent != null && document.referrer !== '' && document.referrer != null) {
75 | window.parent.postMessage(JSON.stringify(identity), document.referrer);
76 | return;
77 | }
78 |
79 | let websocketMessage = {type : "identityJson", content : JSON.stringify(identity)}
80 | sendWebsocketMessage(JSON.stringify(websocketMessage));
81 | window.close();
82 |
83 | } catch (e) {
84 | console.error(e);
85 |
86 | toggleElements(true, true);
87 | }
88 | }
--------------------------------------------------------------------------------
/sns-metrics/README.md:
--------------------------------------------------------------------------------
1 | # metrics
2 |
3 | Welcome to your new metrics project and to the internet computer development community. By default, creating a new project adds this README and some template files to your project directory. You can edit these template files to customize your project and to include your own code to speed up the development cycle.
4 |
5 | To get started, you might want to explore the project directory structure and the default configuration file. Working with this project in your development environment will not affect any production deployment or identity tokens.
6 |
7 | To learn more before you start working with metrics, see the following documentation available online:
8 |
9 | - [Quick Start](https://internetcomputer.org/docs/current/developer-docs/quickstart/hello10mins)
10 | - [SDK Developer Tools](https://internetcomputer.org/docs/current/developer-docs/build/install-upgrade-remove)
11 | - [Motoko Programming Language Guide](https://internetcomputer.org/docs/current/developer-docs/build/cdks/motoko-dfinity/motoko/)
12 | - [Motoko Language Quick Reference](https://internetcomputer.org/docs/current/references/motoko-ref/)
13 | - [JavaScript API Reference](https://erxue-5aaaa-aaaab-qaagq-cai.raw.icp0.io)
14 |
15 | If you want to start working on your project right away, you might want to try the following commands:
16 |
17 | ```bash
18 | cd metrics/
19 | dfx help
20 | dfx canister --help
21 | ```
22 |
23 | ## Running the project locally
24 |
25 | If you want to test your project locally, you can use the following commands:
26 |
27 | ```bash
28 | # Starts the replica, running in the background
29 | dfx start --background
30 |
31 | # Deploys your canisters to the replica and generates your candid interface
32 | dfx deploy
33 | ```
34 |
35 | Once the job completes, your application will be available at `http://localhost:4943?canisterId={asset_canister_id}`.
36 |
37 | If you have made changes to your backend canister, you can generate a new candid interface with
38 |
39 | ```bash
40 | npm run generate
41 | ```
42 |
43 | at any time. This is recommended before starting the frontend development server, and will be run automatically any time you run `dfx deploy`.
44 |
45 | If you are making frontend changes, you can start a development server with
46 |
47 | ```bash
48 | npm start
49 | ```
50 |
51 | Which will start a server at `http://localhost:8080`, proxying API requests to the replica at port 4943.
52 |
53 | ### Note on frontend environment variables
54 |
55 | If you are hosting frontend code somewhere without using DFX, you may need to make one of the following adjustments to ensure your project does not fetch the root key in production:
56 |
57 | - set`DFX_NETWORK` to `ic` if you are using Webpack
58 | - use your own preferred method to replace `process.env.DFX_NETWORK` in the autogenerated declarations
59 | - Setting `canisters -> {asset_canister_id} -> declarations -> env_override to a string` in `dfx.json` will replace `process.env.DFX_NETWORK` with the string in the autogenerated declarations
60 | - Write your own `createActor` constructor
61 |
--------------------------------------------------------------------------------
/candid-with-auth/src/external.ts:
--------------------------------------------------------------------------------
1 | interface ExternalConfig {
2 | candid?: string;
3 | }
4 |
5 | type MessageListener = (message: any) => void;
6 |
7 | const hasExternalConfig = new URLSearchParams(window.location.search).has(
8 | "external-config"
9 | );
10 |
11 | const messagePrefix = "CandidUI";
12 |
13 | // Starting with a hard-coded origin list for security
14 | const allowedExternalOrigins = [
15 | "localhost:4943", // Local
16 | "http://ryjl3-tyaaa-aaaaa-aaaba-cai.localhost:4943", // Motoko Playground (local)
17 | "https://m7sm4-2iaaa-aaaab-qabra-cai.raw.icp0.io", // Motoko Playground (mainnet)
18 | "https://m7sm4-2iaaa-aaaab-qabra-cai.icp0.io", // Motoko Playground (certified)
19 | "https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app", // Motoko Playground (legacy, mainnet)
20 | "https://m7sm4-2iaaa-aaaab-qabra-cai.ic0.app", // Motoko Playground (legacy, certified)
21 | "https://play.motoko.org", // Motoko Playground (custom domain)
22 | ];
23 |
24 | const messageListeners: MessageListener[] = [];
25 |
26 | export function addMessageListener(listener: MessageListener) {
27 | messageListeners.push(listener);
28 | }
29 |
30 | export function removeMessageListener(listener: MessageListener) {
31 | const index = messageListeners.indexOf(listener);
32 | if (index !== -1) {
33 | messageListeners.splice(index, 1);
34 | }
35 | }
36 |
37 | window.addEventListener("message", ({ origin, source, data }) => {
38 | if (typeof data === "string" && data.startsWith(messagePrefix)) {
39 | if (allowedExternalOrigins.includes(origin)) {
40 | const message = JSON.parse(data.substring(messagePrefix.length));
41 | console.log("Candid UI received message:", message);
42 | try {
43 | if (
44 | message?.acknowledge !== undefined &&
45 | !(source instanceof MessagePort)
46 | ) {
47 | source?.postMessage?.(
48 | `${messagePrefix}${JSON.stringify({
49 | type: "acknowledge",
50 | acknowledge: message.acknowledge,
51 | })}`,
52 | // origin
53 | );
54 | }
55 | } catch (err) {
56 | console.error("Unable to send message acknowledgement:", err);
57 | }
58 | messageListeners.forEach((listener) => listener(message));
59 | } else {
60 | console.warn(
61 | "Candid UI received message from unexpected origin:",
62 | origin
63 | );
64 | }
65 | }
66 | });
67 |
68 | /**
69 | * Use this global promise to safely access `external-config` data provided through `postMessage()`.
70 | */
71 | export const EXTERNAL_CONFIG_PROMISE: Promise = new Promise(
72 | (resolve) => {
73 | if (!hasExternalConfig) {
74 | return resolve({});
75 | }
76 | let resolved = false;
77 |
78 | // Listen for "config" messages
79 | addMessageListener((message) => {
80 | if (message?.type === "config") {
81 | resolved = true;
82 | return resolve({ ...message.config });
83 | }
84 | });
85 |
86 | setTimeout(() => {
87 | if (!resolved) {
88 | console.error("External config timeout");
89 | resolve({});
90 | }
91 | }, 3000);
92 | }
93 | );
94 |
--------------------------------------------------------------------------------
/sns-metrics/webpack.config.js:
--------------------------------------------------------------------------------
1 | require("dotenv").config();
2 | const path = require("path");
3 | const webpack = require("webpack");
4 | const HtmlWebpackPlugin = require("html-webpack-plugin");
5 | const TerserPlugin = require("terser-webpack-plugin");
6 | const CopyPlugin = require("copy-webpack-plugin");
7 |
8 | const isDevelopment = process.env.NODE_ENV !== "production";
9 |
10 | const frontendDirectory = "metrics_frontend";
11 |
12 | const frontend_entry = path.join("src", frontendDirectory, "src", "index.html");
13 |
14 | module.exports = {
15 | target: "web",
16 | mode: isDevelopment ? "development" : "production",
17 | entry: {
18 | // The frontend.entrypoint points to the HTML file for this build, so we need
19 | // to replace the extension to `.js`.
20 | index: path.join(__dirname, frontend_entry).replace(/\.html$/, ".js"),
21 | },
22 | devtool: isDevelopment ? "source-map" : false,
23 | optimization: {
24 | minimize: !isDevelopment,
25 | minimizer: [new TerserPlugin()],
26 | },
27 | resolve: {
28 | extensions: [".js", ".ts", ".jsx", ".tsx"],
29 | fallback: {
30 | assert: require.resolve("assert/"),
31 | buffer: require.resolve("buffer/"),
32 | events: require.resolve("events/"),
33 | stream: require.resolve("stream-browserify/"),
34 | util: require.resolve("util/"),
35 | },
36 | },
37 | output: {
38 | filename: "index.js",
39 | path: path.join(__dirname, "dist", frontendDirectory),
40 | },
41 |
42 | // Depending in the language or framework you are using for
43 | // front-end development, add module loaders to the default
44 | // webpack configuration. For example, if you are using React
45 | // modules and CSS as described in the "Adding a stylesheet"
46 | // tutorial, uncomment the following lines:
47 | // module: {
48 | // rules: [
49 | // { test: /\.(ts|tsx|jsx)$/, loader: "ts-loader" },
50 | // { test: /\.css$/, use: ['style-loader','css-loader'] }
51 | // ]
52 | // },
53 | plugins: [
54 | new HtmlWebpackPlugin({
55 | template: path.join(__dirname, frontend_entry),
56 | cache: false,
57 | }),
58 | new webpack.EnvironmentPlugin([
59 | ...Object.keys(process.env).filter((key) => {
60 | if (key.includes("CANISTER")) return true;
61 | if (key.includes("DFX")) return true;
62 | return false;
63 | }),
64 | ]),
65 | new webpack.ProvidePlugin({
66 | Buffer: [require.resolve("buffer/"), "Buffer"],
67 | process: require.resolve("process/browser"),
68 | }),
69 | new CopyPlugin({
70 | patterns: [
71 | {
72 | from: `src/${frontendDirectory}/src/.ic-assets.json*`,
73 | to: ".ic-assets.json5",
74 | noErrorOnMissing: true,
75 | },
76 | ],
77 | }),
78 | ],
79 | // proxy /api to port 4943 during development.
80 | // if you edit dfx.json to define a project-specific local network, change the port to match.
81 | devServer: {
82 | proxy: {
83 | "/api": {
84 | target: "http://127.0.0.1:4943",
85 | changeOrigin: true,
86 | pathRewrite: {
87 | "^/api": "/api",
88 | },
89 | },
90 | },
91 | static: path.resolve(__dirname, "src", frontendDirectory, "assets"),
92 | hot: true,
93 | watchFiles: [path.resolve(__dirname, "src", frontendDirectory)],
94 | liveReload: true,
95 | },
96 | };
97 |
--------------------------------------------------------------------------------
/remote-configs/src/remote_configs_backend/main.mo:
--------------------------------------------------------------------------------
1 | import A "mo:base/AssocList";
2 | import Array "mo:base/Array";
3 | import Blob "mo:base/Blob";
4 | import Bool "mo:base/Bool";
5 | import Buffer "mo:base/Buffer";
6 | import Cycles "mo:base/ExperimentalCycles";
7 | import Char "mo:base/Char";
8 | import Error "mo:base/Error";
9 | import Float "mo:base/Float";
10 | import HashMap "mo:base/HashMap";
11 | import Hash "mo:base/Hash";
12 | import Map "mo:base/HashMap";
13 | import Int "mo:base/Int";
14 | import Int16 "mo:base/Int16";
15 | import Int8 "mo:base/Int8";
16 | import Iter "mo:base/Iter";
17 | import L "mo:base/List";
18 | import Nat "mo:base/Nat";
19 | import Nat8 "mo:base/Nat8";
20 | import Nat32 "mo:base/Nat32";
21 | import Nat64 "mo:base/Nat64";
22 | import Option "mo:base/Option";
23 | import Prelude "mo:base/Prelude";
24 | import Prim "mo:prim";
25 | import Principal "mo:base/Principal";
26 | import Result "mo:base/Result";
27 | import Text "mo:base/Text";
28 | import Time "mo:base/Time";
29 | import Trie "mo:base/Trie";
30 | import Trie2D "mo:base/Trie";
31 |
32 | import JSON "./utils/Json";
33 | import Utils "./utils/Helpers";
34 |
35 | actor Configs {
36 | //stable memory
37 | private stable var remote_configs : Trie.Trie = Trie.empty(); //mapping of remote_config_name -> remote_config_json_data
38 |
39 | //CRUD
40 | public shared ({ caller }) func create_config(name : Text, json : Text) : async (Result.Result) {
41 | switch (JSON.parse(json)) {
42 | case (?j) {
43 | remote_configs := Trie.put(remote_configs, Utils.keyT(name), Text.equal, j).0;
44 | return #ok(json);
45 | };
46 | case _ {
47 | return #err("json parse error");
48 | };
49 | };
50 | };
51 |
52 | public query func get_config(name : Text) : async (Text) {
53 | switch (Trie.find(remote_configs, Utils.keyT(name), Text.equal)) {
54 | case (?j) {
55 | return JSON.show(j);
56 | };
57 | case _ {
58 | return "json not found";
59 | };
60 | };
61 | };
62 |
63 | public shared ({ caller }) func update_config(name : Text, json : Text) : async (Result.Result) {
64 | switch (Trie.find(remote_configs, Utils.keyT(name), Text.equal)) {
65 | case (?_) {
66 | switch (JSON.parse(json)) {
67 | case (?j) {
68 | remote_configs := Trie.put(remote_configs, Utils.keyT(name), Text.equal, j).0;
69 | return #ok(json);
70 | };
71 | case _ {
72 |
73 | return #err("json parse error");
74 | };
75 | };
76 | };
77 | case _ {
78 |
79 | return #err("config not found");
80 | };
81 | };
82 | };
83 |
84 | public shared ({ caller }) func delete_config(name : Text) : async (Result.Result) {
85 | switch (Trie.find(remote_configs, Utils.keyT(name), Text.equal)) {
86 | case (?_) {
87 | remote_configs := Trie.remove(remote_configs, Utils.keyT(name), Text.equal).0;
88 | return #ok("removed " #name);
89 | };
90 | case _ {
91 | return #err("config not found");
92 | };
93 | };
94 | };
95 |
96 | };
97 |
--------------------------------------------------------------------------------
/remote-configs/src/remote_configs_backend/utils/Helpers.mo:
--------------------------------------------------------------------------------
1 | import A "mo:base/AssocList";
2 | import Array "mo:base/Array";
3 | import Blob "mo:base/Blob";
4 | import Bool "mo:base/Bool";
5 | import Buffer "mo:base/Buffer";
6 | import Cycles "mo:base/ExperimentalCycles";
7 | import Char "mo:base/Char";
8 | import Error "mo:base/Error";
9 | import Float "mo:base/Float";
10 | import HashMap "mo:base/HashMap";
11 | import Hash "mo:base/Hash";
12 | import Map "mo:base/HashMap";
13 | import Int "mo:base/Int";
14 | import Int16 "mo:base/Int16";
15 | import Int8 "mo:base/Int8";
16 | import Iter "mo:base/Iter";
17 | import L "mo:base/List";
18 | import Nat "mo:base/Nat";
19 | import Nat8 "mo:base/Nat8";
20 | import Nat32 "mo:base/Nat32";
21 | import Nat64 "mo:base/Nat64";
22 | import Int64 "mo:base/Int64";
23 | import Option "mo:base/Option";
24 | import Prelude "mo:base/Prelude";
25 | import Prim "mo:prim";
26 | import Principal "mo:base/Principal";
27 | import Result "mo:base/Result";
28 | import Text "mo:base/Text";
29 | import Time "mo:base/Time";
30 | import Trie "mo:base/Trie";
31 | import Trie2D "mo:base/Trie";
32 |
33 | module {
34 | //util types
35 | //
36 | public type headerField = (Text, Text);
37 | public type HttpRequest = {
38 | body : Blob;
39 | headers : [headerField];
40 | method : Text;
41 | url : Text;
42 | };
43 | public type HttpResponse = {
44 | body : Blob;
45 | headers : [headerField];
46 | status_code : Nat16;
47 | };
48 |
49 | //utility functions
50 | //
51 | public func key(x : Nat32) : Trie.Key {
52 | return { hash = x; key = x };
53 | };
54 |
55 | public func keyT(x : Text) : Trie.Key {
56 | return { hash = Text.hash(x); key = x };
57 | };
58 |
59 | public func textToNat(txt : Text) : Nat {
60 | assert (txt.size() > 0);
61 | let chars = txt.chars();
62 |
63 | var num : Nat = 0;
64 | for (v in chars) {
65 | let charToNum = Nat32.toNat(Char.toNat32(v) -48);
66 | assert (charToNum >= 0 and charToNum <= 9);
67 | num := num * 10 + charToNum;
68 | };
69 |
70 | return num;
71 | };
72 |
73 | public func textToFloat(t : Text) : Float {
74 | var i : Float = 1;
75 | var f : Float = 0;
76 | var isDecimal : Bool = false;
77 | for (c in t.chars()) {
78 | if (Char.isDigit(c)) {
79 | let charToNat : Nat64 = Nat64.fromNat(Nat32.toNat(Char.toNat32(c) -48));
80 | let natToFloat : Float = Float.fromInt64(Int64.fromNat64(charToNat));
81 | if (isDecimal) {
82 | let n : Float = natToFloat / Float.pow(10, i);
83 | f := f + n;
84 | } else {
85 | f := f * 10 + natToFloat;
86 | };
87 | i := i + 1;
88 | } else {
89 | if (Char.equal(c, '.') or Char.equal(c, ',')) {
90 | f := f / Float.pow(10, i); // Force decimal
91 | f := f * Float.pow(10, i); // Correction
92 | isDecimal := true;
93 | i := 1;
94 | } else {};
95 | };
96 | };
97 |
98 | return f;
99 | };
100 |
101 | public func textToarray(text : Text) : async ([Nat8]) {
102 | var blob : Blob = Text.encodeUtf8(text);
103 | var array : [Nat8] = Blob.toArray(blob);
104 | return array;
105 | };
106 | };
--------------------------------------------------------------------------------
/batch-transfer-tool/src/batch_transfer_tool_frontend/components/utils.js:
--------------------------------------------------------------------------------
1 | import { Principal } from '@dfinity/principal';
2 |
3 | import CryptoJS from 'crypto-js';
4 | import crc32 from 'buffer-crc32';
5 |
6 |
7 | // Dfinity Account separator
8 | export const ACCOUNT_DOMAIN_SEPERATOR = '\x0Aaccount-id';
9 | // Subaccounts are arbitrary 32-byte values.
10 | export const SUB_ACCOUNT_ZERO = Buffer.alloc(32);
11 |
12 | export const wordToByteArray = (word, length) => {
13 | const byteArray = [];
14 | const xFF = 0xff;
15 | if (length > 0) byteArray.push(word >>> 24);
16 | if (length > 1) byteArray.push((word >>> 16) & xFF);
17 | if (length > 2) byteArray.push((word >>> 8) & xFF);
18 | if (length > 3) byteArray.push(word & xFF);
19 |
20 | return byteArray;
21 | };
22 |
23 | export const wordArrayToByteArray = (wordArray, length) => {
24 | if (
25 | wordArray.hasOwnProperty('sigBytes') &&
26 | wordArray.hasOwnProperty('words')
27 | ) {
28 | length = wordArray.sigBytes;
29 | wordArray = wordArray.words;
30 | }
31 |
32 | let result = [];
33 | let bytes;
34 | let i = 0;
35 | while (length > 0) {
36 | bytes = wordToByteArray(wordArray[i], Math.min(4, length));
37 | length -= bytes.length;
38 | result = [...result, bytes];
39 | i++;
40 | }
41 | return [].concat.apply([], result);
42 | };
43 |
44 | export const intToHex = (val) =>
45 | val < 0 ? (Number(val) >>> 0).toString(16) : Number(val).toString(16);
46 |
47 | // We generate a CRC32 checksum, and trnasform it into a hexString
48 | export const generateChecksum = (hash) => {
49 | const crc = crc32.unsigned(Buffer.from(hash));
50 | const hex = intToHex(crc);
51 | return hex.padStart(8, '0');
52 | };
53 |
54 |
55 | export const byteArrayToWordArray = (byteArray) => {
56 | const wordArray = [];
57 | let i;
58 | for (i = 0; i < byteArray.length; i += 1) {
59 | wordArray[(i / 4) | 0] |= byteArray[i] << (24 - 8 * i);
60 | }
61 | // eslint-disable-next-line
62 | const result = CryptoJS.lib.WordArray.create(
63 | wordArray,
64 | byteArray.length
65 | );
66 | return result;
67 | };
68 |
69 | export const to32bits = (num) => {
70 | const b = new ArrayBuffer(4);
71 | new DataView(b).setUint32(0, num);
72 | return Array.from(new Uint8Array(b));
73 | };
74 |
75 | export const getAccountId = (
76 | principal,
77 | subAccount
78 | ) => {
79 | const sha = CryptoJS.algo.SHA224.create();
80 | sha.update(ACCOUNT_DOMAIN_SEPERATOR); // Internally parsed with UTF-8, like go does
81 | sha.update(byteArrayToWordArray(principal.toUint8Array()));
82 | const subBuffer = Buffer.from(SUB_ACCOUNT_ZERO);
83 | if (subAccount) {
84 | subBuffer.writeUInt32BE(subAccount);
85 | }
86 | sha.update(byteArrayToWordArray(subBuffer));
87 | const hash = sha.finalize();
88 |
89 | /// While this is backed by an array of length 28, it's canonical representation
90 | /// is a hex string of length 64. The first 8 characters are the CRC-32 encoded
91 | /// hash of the following 56 characters of hex. Both, upper and lower case
92 | /// characters are valid in the input string and can even be mixed.
93 | /// [ic/rs/rosetta-api/ledger_canister/src/account_identifier.rs]
94 | const byteArray = wordArrayToByteArray(hash, 28);
95 | const checksum = generateChecksum(byteArray);
96 | const val = checksum + hash.toString();
97 |
98 | return val;
99 | };
100 |
101 | export const getTokenIdentifier = (canister, index) => {
102 | const padding = Buffer.from('\x0Atid');
103 | const array = new Uint8Array([
104 | ...padding,
105 | ...Principal.fromText(canister).toUint8Array(),
106 | ...to32bits(index),
107 | ]);
108 | return Principal.fromUint8Array(array).toText();
109 | };
--------------------------------------------------------------------------------
/utilities/Utils.mo:
--------------------------------------------------------------------------------
1 | import A "mo:base/AssocList";
2 | import Array "mo:base/Array";
3 | import Blob "mo:base/Blob";
4 | import Bool "mo:base/Bool";
5 | import Buffer "mo:base/Buffer";
6 | import Cycles "mo:base/ExperimentalCycles";
7 | import Char "mo:base/Char";
8 | import Error "mo:base/Error";
9 | import Float "mo:base/Float";
10 | import HashMap "mo:base/HashMap";
11 | import Hash "mo:base/Hash";
12 | import Map "mo:base/HashMap";
13 | import Int "mo:base/Int";
14 | import Int16 "mo:base/Int16";
15 | import Int8 "mo:base/Int8";
16 | import Iter "mo:base/Iter";
17 | import L "mo:base/List";
18 | import Nat "mo:base/Nat";
19 | import Nat8 "mo:base/Nat8";
20 | import Nat32 "mo:base/Nat32";
21 | import Nat64 "mo:base/Nat64";
22 | import Int64 "mo:base/Int64";
23 | import Option "mo:base/Option";
24 | import Prelude "mo:base/Prelude";
25 | import Prim "mo:prim";
26 | import Principal "mo:base/Principal";
27 | import Result "mo:base/Result";
28 | import Text "mo:base/Text";
29 | import Time "mo:base/Time";
30 | import Trie "mo:base/Trie";
31 | import Trie2D "mo:base/Trie";
32 |
33 | module {
34 | //util types
35 | //
36 | public type headerField = (Text, Text);
37 | public type HttpRequest = {
38 | body : Blob;
39 | headers : [headerField];
40 | method : Text;
41 | url : Text;
42 | };
43 | public type HttpResponse = {
44 | body : Blob;
45 | headers : [headerField];
46 | status_code : Nat16;
47 | };
48 |
49 | //utility functions
50 | //
51 | public func key(x : Nat32) : Trie.Key {
52 | return { hash = x; key = x };
53 | };
54 |
55 | public func keyT(x : Text) : Trie.Key {
56 | return { hash = Text.hash(x); key = x };
57 | };
58 |
59 | public func textToNat(txt : Text) : Nat {
60 | assert (txt.size() > 0);
61 | let chars = txt.chars();
62 |
63 | var num : Nat = 0;
64 | for (v in chars) {
65 | let charToNum = Nat32.toNat(Char.toNat32(v) -48);
66 | assert (charToNum >= 0 and charToNum <= 9);
67 | num := num * 10 + charToNum;
68 | };
69 |
70 | return num;
71 | };
72 |
73 | public func textToFloat(t : Text) : Float {
74 | var i : Float = 1;
75 | var f : Float = 0;
76 | var isDecimal : Bool = false;
77 | for (c in t.chars()) {
78 | if (Char.isDigit(c)) {
79 | let charToNat : Nat64 = Nat64.fromNat(Nat32.toNat(Char.toNat32(c) -48));
80 | let natToFloat : Float = Float.fromInt64(Int64.fromNat64(charToNat));
81 | if (isDecimal) {
82 | let n : Float = natToFloat / Float.pow(10, i);
83 | f := f + n;
84 | } else {
85 | f := f * 10 + natToFloat;
86 | };
87 | i := i + 1;
88 | } else {
89 | if (Char.equal(c, '.') or Char.equal(c, ',')) {
90 | f := f / Float.pow(10, i); // Force decimal
91 | f := f * Float.pow(10, i); // Correction
92 | isDecimal := true;
93 | i := 1;
94 | } else {};
95 | };
96 | };
97 |
98 | return f;
99 | };
100 |
101 | public func textToarray(text : Text) : async ([Nat8]) {
102 | var blob : Blob = Text.encodeUtf8(text);
103 | var array : [Nat8] = Blob.toArray(blob);
104 | return array;
105 | };
106 |
107 | public func isResultError(result : Result.Result) : (Bool){
108 | switch(result){
109 | case(#err(msg)){
110 | return true;
111 | };
112 | case(#ok(msg)){
113 | return false;
114 | };
115 | };
116 | };
117 | };
--------------------------------------------------------------------------------
/candid-with-auth/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 | const TerserPlugin = require("terser-webpack-plugin");
3 | const dfxJson = require("./dfx.json");
4 | const HtmlWebpackPlugin = require('html-webpack-plugin');
5 | const CopyWebpackPlugin = require('copy-webpack-plugin');
6 | const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
7 | const webpack = require("webpack");
8 |
9 | // List of all aliases for canisters. This creates the module alias for
10 | // the `import ... from "@dfinity/ic/canisters/xyz"` where xyz is the name of a
11 | // canister.
12 | const aliases = Object.entries(dfxJson.canisters).reduce(
13 | (acc, [name, _value]) => {
14 | // Get the network name, or `local` by default.
15 | const networkName = process.env["DFX_NETWORK"] || "local";
16 | const outputRoot = path.join(
17 | __dirname,
18 | ".dfx",
19 | networkName,
20 | "canisters",
21 | name
22 | );
23 |
24 | return {
25 | ...acc,
26 | ["dfx-generated/" + name]: path.join(outputRoot),
27 | };
28 | },
29 | {}
30 | );
31 |
32 | /**
33 | * Generate a webpack configuration for a canister.
34 | */
35 | function generateWebpackConfigForCanister(name, info) {
36 | //if (typeof info.frontend !== "object") {
37 | // return;
38 | //}
39 |
40 | return {
41 | mode: "production",
42 | entry: {
43 | index: path.join(__dirname, "src/index.ts"),
44 | },
45 | target: 'web',
46 | devtool: "source-map",
47 | optimization: {
48 | minimize: true,
49 | minimizer: [new TerserPlugin()],
50 | },
51 | resolve: {
52 | plugins: [new TsconfigPathsPlugin({ configFile: './tsconfig.json' })],
53 | extensions: [".js", ".ts", ".jsx", ".tsx"],
54 | fallback: {
55 | //"assert": require.resolve("assert/"),
56 | "buffer": require.resolve("buffer/"),
57 | //"events": require.resolve("events/"),
58 | //"stream": require.resolve("stream-browserify/"),
59 | //"util": require.resolve("util/"),
60 | },
61 | alias: aliases,
62 | },
63 | output: {
64 | filename: "[name].js",
65 | path: path.join(__dirname, "dist", name),
66 | },
67 |
68 | // Depending in the language or framework you are using for
69 | // front-end development, add module loaders to the default
70 | // webpack configuration. For example, if you are using React
71 | // modules and CSS as described in the "Adding a stylesheet"
72 | // tutorial, uncomment the following lines:
73 | module: {
74 | rules: [
75 | { test: /\.css$/, use: ['style-loader','css-loader'] },
76 | { test: /\.(jsx|ts|tsx)$/,
77 | use: {
78 | loader: "ts-loader",
79 | options: {
80 | // eslint-disable-next-line no-undef
81 | configFile: path.join(__dirname, 'tsconfig.json'),
82 | projectReferences: true,
83 | }
84 | }
85 | }
86 | ]
87 | },
88 | plugins: [
89 | new HtmlWebpackPlugin({
90 | template: 'src/candid.html',
91 | filename: 'index.html',
92 | }),
93 | new CopyWebpackPlugin({
94 | patterns: [
95 | {
96 | from: 'src/favicon.ico',
97 | to: 'favicon.ico',
98 | },
99 | ]}),
100 | new webpack.ProvidePlugin({
101 | Buffer: [require.resolve('buffer/'), 'Buffer'],
102 | //process: require.resolve('process/browser'),
103 | }),
104 | ],
105 | };
106 | }
107 |
108 | // If you have additional webpack configurations you want to build
109 | // as part of this configuration, add them to the section below.
110 | module.exports = [
111 | ...Object.entries(dfxJson.canisters)
112 | .map(([name, info]) => {
113 | return generateWebpackConfigForCanister(name, info);
114 | })
115 | .filter((x) => !!x),
116 | ];
117 |
--------------------------------------------------------------------------------
/candid-with-auth/src/didjs/lib.rs:
--------------------------------------------------------------------------------
1 | use ic_cdk::export::candid::{
2 | candid_method, check_prog, export_service, types::subtype, types::Type, CandidType,
3 | Deserialize, IDLProg, TypeEnv,
4 | };
5 |
6 | #[derive(CandidType, Deserialize)]
7 | pub struct HeaderField(pub String, pub String);
8 |
9 | #[derive(CandidType, Deserialize)]
10 | pub struct HttpRequest {
11 | pub method: String,
12 | pub url: String,
13 | pub headers: Vec,
14 | #[serde(with = "serde_bytes")]
15 | pub body: Vec,
16 | }
17 |
18 | #[derive(CandidType, Deserialize)]
19 | pub struct HttpResponse {
20 | pub status_code: u16,
21 | pub headers: Vec,
22 | #[serde(with = "serde_bytes")]
23 | pub body: Vec,
24 | }
25 |
26 | #[ic_cdk_macros::query]
27 | #[candid_method(query)]
28 | fn did_to_js(prog: String) -> Option {
29 | let ast = prog.parse::().ok()?;
30 | let mut env = TypeEnv::new();
31 | let actor = check_prog(&mut env, &ast).ok()?;
32 | let res = ic_cdk::export::candid::bindings::javascript::compile(&env, &actor);
33 | Some(res)
34 | }
35 |
36 | #[ic_cdk_macros::query]
37 | #[candid_method(query)]
38 | fn binding(prog: String, lang: String) -> Option {
39 | use ic_cdk::export::candid::bindings;
40 | let ast = prog.parse::().ok()?;
41 | let mut env = TypeEnv::new();
42 | let actor = check_prog(&mut env, &ast).ok()?;
43 | let res = match lang.as_str() {
44 | "ts" => bindings::typescript::compile(&env, &actor),
45 | "mo" => bindings::motoko::compile(&env, &actor),
46 | "installed_did" => {
47 | let actor = if let Some(Type::Class(_, ty)) = actor {
48 | Some(*ty)
49 | } else {
50 | actor
51 | };
52 | bindings::candid::compile(&env, &actor)
53 | }
54 | _ => return None,
55 | };
56 | Some(res)
57 | }
58 |
59 | #[ic_cdk_macros::query]
60 | #[candid_method(query)]
61 | fn subtype(new: String, old: String) -> Result<(), String> {
62 | let new = new.parse::().unwrap();
63 | let old = old.parse::().unwrap();
64 | let mut new_env = TypeEnv::new();
65 | let mut old_env = TypeEnv::new();
66 | let new_actor = check_prog(&mut new_env, &new).unwrap().unwrap();
67 | let old_actor = check_prog(&mut old_env, &old).unwrap().unwrap();
68 | let mut gamma = std::collections::HashSet::new();
69 | let old_actor = new_env.merge_type(old_env, old_actor);
70 | subtype::subtype(&mut gamma, &new_env, &new_actor, &old_actor)
71 | .or_else(|e| Err(e.to_string()))
72 | }
73 |
74 | fn retrieve(path: &str) -> Option<&'static [u8]> {
75 | match path {
76 | "/index.html" | "/" => Some(include_bytes!("../../dist/didjs/index.html")),
77 | "/favicon.ico" => Some(include_bytes!("../../dist/didjs/favicon.ico")),
78 | "/index.js" => Some(include_bytes!("../../dist/didjs/index.js")),
79 | _ => None,
80 | }
81 | }
82 |
83 | fn get_path(url: &str) -> Option<&str> {
84 | url.split('?').next()
85 | }
86 |
87 | #[ic_cdk_macros::query]
88 | #[candid_method(query)]
89 | fn http_request(request: HttpRequest) -> HttpResponse {
90 | //TODO add /canister_id/ as endpoint when ICQC is available.
91 | let path = get_path(request.url.as_str()).unwrap_or("/");
92 | if let Some(bytes) = retrieve(path) {
93 | HttpResponse {
94 | status_code: 200,
95 | headers: vec![
96 | //HeaderField("Content-Encoding".to_string(), "gzip".to_string()),
97 | HeaderField("Content-Length".to_string(), format!("{}", bytes.len())),
98 | HeaderField("Cache-Control".to_string(), format!("max-age={}", 600)),
99 | ],
100 | body: bytes.to_vec(),
101 | }
102 | } else {
103 | HttpResponse {
104 | status_code: 404,
105 | headers: Vec::new(),
106 | body: path.as_bytes().to_vec(),
107 | }
108 | }
109 | }
110 |
111 | export_service!();
112 |
113 | #[ic_cdk_macros::query(name = "__get_candid_interface_tmp_hack")]
114 | fn export_candid() -> String {
115 | __export_service()
116 | }
117 |
--------------------------------------------------------------------------------
/chat/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 | const webpack = require("webpack");
3 | const HtmlWebpackPlugin = require("html-webpack-plugin");
4 | const TerserPlugin = require("terser-webpack-plugin");
5 | const CopyPlugin = require("copy-webpack-plugin");
6 |
7 | function initCanisterEnv() {
8 | let localCanisters, prodCanisters;
9 | try {
10 | localCanisters = require(path.resolve(
11 | ".dfx",
12 | "local",
13 | "canister_ids.json"
14 | ));
15 | } catch (error) {
16 | console.log("No local canister_ids.json found. Continuing production");
17 | }
18 | try {
19 | prodCanisters = require(path.resolve("canister_ids.json"));
20 | } catch (error) {
21 | console.log("No production canister_ids.json found. Continuing with local");
22 | }
23 |
24 | const network =
25 | process.env.DFX_NETWORK ||
26 | (process.env.NODE_ENV === "production" ? "ic" : "local");
27 |
28 | const canisterConfig = network === "local" ? localCanisters : prodCanisters;
29 |
30 | return Object.entries(canisterConfig).reduce((prev, current) => {
31 | const [canisterName, canisterDetails] = current;
32 | prev[canisterName.toUpperCase() + "_CANISTER_ID"] =
33 | canisterDetails[network];
34 | return prev;
35 | }, {});
36 | }
37 | const canisterEnvVariables = initCanisterEnv();
38 |
39 | const isDevelopment = process.env.NODE_ENV !== "production";
40 |
41 | const frontendDirectory = "chat_frontend";
42 |
43 | const frontend_entry = path.join("src", frontendDirectory, "src", "index.html");
44 |
45 | module.exports = {
46 | target: "web",
47 | mode: isDevelopment ? "development" : "production",
48 | entry: {
49 | // The frontend.entrypoint points to the HTML file for this build, so we need
50 | // to replace the extension to `.js`.
51 | index: path.join(__dirname, frontend_entry).replace(/\.html$/, ".js"),
52 | },
53 | devtool: isDevelopment ? "source-map" : false,
54 | optimization: {
55 | minimize: !isDevelopment,
56 | minimizer: [new TerserPlugin()],
57 | },
58 | resolve: {
59 | extensions: [".js", ".ts", ".jsx", ".tsx"],
60 | fallback: {
61 | assert: require.resolve("assert/"),
62 | buffer: require.resolve("buffer/"),
63 | events: require.resolve("events/"),
64 | stream: require.resolve("stream-browserify/"),
65 | util: require.resolve("util/"),
66 | },
67 | },
68 | output: {
69 | filename: "index.js",
70 | path: path.join(__dirname, "dist", frontendDirectory),
71 | },
72 |
73 | // Depending in the language or framework you are using for
74 | // front-end development, add module loaders to the default
75 | // webpack configuration. For example, if you are using React
76 | // modules and CSS as described in the "Adding a stylesheet"
77 | // tutorial, uncomment the following lines:
78 | // module: {
79 | // rules: [
80 | // { test: /\.(ts|tsx|jsx)$/, loader: "ts-loader" },
81 | // { test: /\.css$/, use: ['style-loader','css-loader'] }
82 | // ]
83 | // },
84 | plugins: [
85 | new HtmlWebpackPlugin({
86 | template: path.join(__dirname, frontend_entry),
87 | cache: false,
88 | }),
89 | new webpack.EnvironmentPlugin({
90 | NODE_ENV: "development",
91 | ...canisterEnvVariables,
92 | }),
93 | new webpack.ProvidePlugin({
94 | Buffer: [require.resolve("buffer/"), "Buffer"],
95 | process: require.resolve("process/browser"),
96 | }),
97 | new CopyPlugin({
98 | patterns: [
99 | {
100 | from: `src/${frontendDirectory}/src/.ic-assets.json*`,
101 | to: ".ic-assets.json5",
102 | noErrorOnMissing: true
103 | },
104 | ],
105 | }),
106 | ],
107 | // proxy /api to port 4943 during development.
108 | // if you edit dfx.json to define a project-specific local network, change the port to match.
109 | devServer: {
110 | proxy: {
111 | "/api": {
112 | target: "http://127.0.0.1:4943",
113 | changeOrigin: true,
114 | pathRewrite: {
115 | "^/api": "/api",
116 | },
117 | },
118 | },
119 | static: path.resolve(__dirname, "src", frontendDirectory, "assets"),
120 | hot: true,
121 | watchFiles: [path.resolve(__dirname, "src", frontendDirectory)],
122 | liveReload: true,
123 | },
124 | };
125 |
--------------------------------------------------------------------------------
/topup/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 | const webpack = require("webpack");
3 | const HtmlWebpackPlugin = require("html-webpack-plugin");
4 | const TerserPlugin = require("terser-webpack-plugin");
5 | const CopyPlugin = require("copy-webpack-plugin");
6 |
7 | function initCanisterEnv() {
8 | let localCanisters, prodCanisters;
9 | try {
10 | localCanisters = require(path.resolve(
11 | ".dfx",
12 | "local",
13 | "canister_ids.json"
14 | ));
15 | } catch (error) {
16 | console.log("No local canister_ids.json found. Continuing production");
17 | }
18 | try {
19 | prodCanisters = require(path.resolve("canister_ids.json"));
20 | } catch (error) {
21 | console.log("No production canister_ids.json found. Continuing with local");
22 | }
23 |
24 | const network =
25 | process.env.DFX_NETWORK ||
26 | (process.env.NODE_ENV === "production" ? "ic" : "local");
27 |
28 | const canisterConfig = network === "local" ? localCanisters : prodCanisters;
29 |
30 | return Object.entries(canisterConfig).reduce((prev, current) => {
31 | const [canisterName, canisterDetails] = current;
32 | prev[canisterName.toUpperCase() + "_CANISTER_ID"] =
33 | canisterDetails[network];
34 | return prev;
35 | }, {});
36 | }
37 | const canisterEnvVariables = initCanisterEnv();
38 |
39 | const isDevelopment = process.env.NODE_ENV !== "production";
40 |
41 | const frontendDirectory = "topup_frontend";
42 |
43 | const frontend_entry = path.join("src", frontendDirectory, "src", "index.html");
44 |
45 | module.exports = {
46 | target: "web",
47 | mode: isDevelopment ? "development" : "production",
48 | entry: {
49 | // The frontend.entrypoint points to the HTML file for this build, so we need
50 | // to replace the extension to `.js`.
51 | index: path.join(__dirname, frontend_entry).replace(/\.html$/, ".js"),
52 | },
53 | devtool: isDevelopment ? "source-map" : false,
54 | optimization: {
55 | minimize: !isDevelopment,
56 | minimizer: [new TerserPlugin()],
57 | },
58 | resolve: {
59 | extensions: [".js", ".ts", ".jsx", ".tsx"],
60 | fallback: {
61 | assert: require.resolve("assert/"),
62 | buffer: require.resolve("buffer/"),
63 | events: require.resolve("events/"),
64 | stream: require.resolve("stream-browserify/"),
65 | util: require.resolve("util/"),
66 | },
67 | },
68 | output: {
69 | filename: "index.js",
70 | path: path.join(__dirname, "dist", frontendDirectory),
71 | },
72 |
73 | // Depending in the language or framework you are using for
74 | // front-end development, add module loaders to the default
75 | // webpack configuration. For example, if you are using React
76 | // modules and CSS as described in the "Adding a stylesheet"
77 | // tutorial, uncomment the following lines:
78 | // module: {
79 | // rules: [
80 | // { test: /\.(ts|tsx|jsx)$/, loader: "ts-loader" },
81 | // { test: /\.css$/, use: ['style-loader','css-loader'] }
82 | // ]
83 | // },
84 | plugins: [
85 | new HtmlWebpackPlugin({
86 | template: path.join(__dirname, frontend_entry),
87 | cache: false,
88 | }),
89 | new webpack.EnvironmentPlugin({
90 | NODE_ENV: "development",
91 | ...canisterEnvVariables,
92 | }),
93 | new webpack.ProvidePlugin({
94 | Buffer: [require.resolve("buffer/"), "Buffer"],
95 | process: require.resolve("process/browser"),
96 | }),
97 | new CopyPlugin({
98 | patterns: [
99 | {
100 | from: `src/${frontendDirectory}/src/.ic-assets.json*`,
101 | to: ".ic-assets.json5",
102 | noErrorOnMissing: true
103 | },
104 | ],
105 | }),
106 | ],
107 | // proxy /api to port 4943 during development.
108 | // if you edit dfx.json to define a project-specific local network, change the port to match.
109 | devServer: {
110 | proxy: {
111 | "/api": {
112 | target: "http://127.0.0.1:4943",
113 | changeOrigin: true,
114 | pathRewrite: {
115 | "^/api": "/api",
116 | },
117 | },
118 | },
119 | static: path.resolve(__dirname, "src", frontendDirectory, "assets"),
120 | hot: true,
121 | watchFiles: [path.resolve(__dirname, "src", frontendDirectory)],
122 | liveReload: true,
123 | },
124 | };
125 |
--------------------------------------------------------------------------------
/batch-transfer-tool/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 | const webpack = require("webpack");
3 | const HtmlWebpackPlugin = require("html-webpack-plugin");
4 | const TerserPlugin = require("terser-webpack-plugin");
5 | const CopyPlugin = require("copy-webpack-plugin");
6 |
7 | function initCanisterEnv() {
8 | let localCanisters, prodCanisters;
9 | try {
10 | localCanisters = require(path.resolve(
11 | ".dfx",
12 | "local",
13 | "canister_ids.json"
14 | ));
15 | } catch (error) {
16 | console.log("No local canister_ids.json found. Continuing production");
17 | }
18 | try {
19 | prodCanisters = require(path.resolve("canister_ids.json"));
20 | } catch (error) {
21 | console.log("No production canister_ids.json found. Continuing with local");
22 | }
23 |
24 | const network =
25 | process.env.DFX_NETWORK ||
26 | (process.env.NODE_ENV === "production" ? "ic" : "local");
27 |
28 | const canisterConfig = network === "local" ? localCanisters : prodCanisters;
29 |
30 | return Object.entries(canisterConfig).reduce((prev, current) => {
31 | const [canisterName, canisterDetails] = current;
32 | prev[canisterName.toUpperCase() + "_CANISTER_ID"] =
33 | canisterDetails[network];
34 | return prev;
35 | }, {});
36 | }
37 | const canisterEnvVariables = initCanisterEnv();
38 |
39 | const isDevelopment = process.env.NODE_ENV !== "production";
40 |
41 | const frontendDirectory = "batch_transfer_tool_frontend";
42 |
43 | const frontend_entry = path.join("src", frontendDirectory, "src", "index.html");
44 |
45 | module.exports = {
46 | target: "web",
47 | mode: isDevelopment ? "development" : "production",
48 | entry: {
49 | // The frontend.entrypoint points to the HTML file for this build, so we need
50 | // to replace the extension to `.js`.
51 | index: path.join(__dirname, frontend_entry).replace(/\.html$/, ".jsx"),
52 | },
53 | devtool: isDevelopment ? "source-map" : false,
54 | optimization: {
55 | minimize: !isDevelopment,
56 | minimizer: [new TerserPlugin()],
57 | },
58 | resolve: {
59 | extensions: [".js", ".ts", ".jsx", ".tsx"],
60 | fallback: {
61 | assert: require.resolve("assert/"),
62 | buffer: require.resolve("buffer/"),
63 | events: require.resolve("events/"),
64 | stream: require.resolve("stream-browserify/"),
65 | util: require.resolve("util/"),
66 | },
67 | },
68 | output: {
69 | filename: "index.js",
70 | path: path.join(__dirname, "dist", frontendDirectory),
71 | },
72 |
73 | // Depending in the language or framework you are using for
74 | // front-end development, add module loaders to the default
75 | // webpack configuration. For example, if you are using React
76 | // modules and CSS as described in the "Adding a stylesheet"
77 | // tutorial, uncomment the following lines:
78 | module: {
79 | rules: [
80 | { test: /\.(ts|tsx|jsx)$/, loader: "ts-loader" },
81 | { test: /\.css$/, use: ['style-loader','css-loader'] }
82 | ]
83 | },
84 | plugins: [
85 | new HtmlWebpackPlugin({
86 | template: path.join(__dirname, frontend_entry),
87 | cache: false,
88 | }),
89 | new webpack.EnvironmentPlugin({
90 | NODE_ENV: "development",
91 | ...canisterEnvVariables,
92 | }),
93 | new webpack.ProvidePlugin({
94 | Buffer: [require.resolve("buffer/"), "Buffer"],
95 | process: require.resolve("process/browser"),
96 | }),
97 | new CopyPlugin({
98 | patterns: [
99 | {
100 | from: `src/${frontendDirectory}/src/.ic-assets.json*`,
101 | to: ".ic-assets.json5",
102 | noErrorOnMissing: true
103 | },
104 | ],
105 | }),
106 | ],
107 | // proxy /api to port 4943 during development.
108 | // if you edit dfx.json to define a project-specific local network, change the port to match.
109 | devServer: {
110 | proxy: {
111 | "/api": {
112 | target: "http://127.0.0.1:4943",
113 | changeOrigin: true,
114 | pathRewrite: {
115 | "^/api": "/api",
116 | },
117 | },
118 | },
119 | static: path.resolve(__dirname, "src", frontendDirectory, "assets"),
120 | hot: true,
121 | watchFiles: [path.resolve(__dirname, "src", frontendDirectory)],
122 | liveReload: true,
123 | },
124 | };
125 |
--------------------------------------------------------------------------------
/multiplayer/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 | const webpack = require("webpack");
3 | const HtmlWebpackPlugin = require("html-webpack-plugin");
4 | const TerserPlugin = require("terser-webpack-plugin");
5 | const CopyPlugin = require("copy-webpack-plugin");
6 |
7 | function initCanisterEnv() {
8 | let localCanisters, prodCanisters;
9 | try {
10 | localCanisters = require(path.resolve(
11 | ".dfx",
12 | "local",
13 | "canister_ids.json"
14 | ));
15 | } catch (error) {
16 | console.log("No local canister_ids.json found. Continuing production");
17 | }
18 | try {
19 | prodCanisters = require(path.resolve("canister_ids.json"));
20 | } catch (error) {
21 | console.log("No production canister_ids.json found. Continuing with local");
22 | }
23 |
24 | const network =
25 | process.env.DFX_NETWORK ||
26 | (process.env.NODE_ENV === "production" ? "ic" : "local");
27 |
28 | const canisterConfig = network === "local" ? localCanisters : prodCanisters;
29 |
30 | return Object.entries(canisterConfig).reduce((prev, current) => {
31 | const [canisterName, canisterDetails] = current;
32 | prev[canisterName.toUpperCase() + "_CANISTER_ID"] =
33 | canisterDetails[network];
34 | return prev;
35 | }, {});
36 | }
37 | const canisterEnvVariables = initCanisterEnv();
38 |
39 | const isDevelopment = process.env.NODE_ENV !== "production";
40 |
41 | const frontendDirectory = "multiplayer_frontend";
42 |
43 | const frontend_entry = path.join("src", frontendDirectory, "src", "index.html");
44 |
45 | module.exports = {
46 | target: "web",
47 | mode: isDevelopment ? "development" : "production",
48 | entry: {
49 | // The frontend.entrypoint points to the HTML file for this build, so we need
50 | // to replace the extension to `.js`.
51 | index: path.join(__dirname, frontend_entry).replace(/\.html$/, ".js"),
52 | },
53 | devtool: isDevelopment ? "source-map" : false,
54 | optimization: {
55 | minimize: !isDevelopment,
56 | minimizer: [new TerserPlugin()],
57 | },
58 | resolve: {
59 | extensions: [".js", ".ts", ".jsx", ".tsx"],
60 | fallback: {
61 | assert: require.resolve("assert/"),
62 | buffer: require.resolve("buffer/"),
63 | events: require.resolve("events/"),
64 | stream: require.resolve("stream-browserify/"),
65 | util: require.resolve("util/"),
66 | },
67 | },
68 | output: {
69 | filename: "index.js",
70 | path: path.join(__dirname, "dist", frontendDirectory),
71 | },
72 |
73 | // Depending in the language or framework you are using for
74 | // front-end development, add module loaders to the default
75 | // webpack configuration. For example, if you are using React
76 | // modules and CSS as described in the "Adding a stylesheet"
77 | // tutorial, uncomment the following lines:
78 | // module: {
79 | // rules: [
80 | // { test: /\.(ts|tsx|jsx)$/, loader: "ts-loader" },
81 | // { test: /\.css$/, use: ['style-loader','css-loader'] }
82 | // ]
83 | // },
84 | plugins: [
85 | new HtmlWebpackPlugin({
86 | template: path.join(__dirname, frontend_entry),
87 | cache: false,
88 | }),
89 | new webpack.EnvironmentPlugin({
90 | NODE_ENV: "development",
91 | ...canisterEnvVariables,
92 | }),
93 | new webpack.ProvidePlugin({
94 | Buffer: [require.resolve("buffer/"), "Buffer"],
95 | process: require.resolve("process/browser"),
96 | }),
97 | new CopyPlugin({
98 | patterns: [
99 | {
100 | from: `src/${frontendDirectory}/src/.ic-assets.json*`,
101 | to: ".ic-assets.json5",
102 | noErrorOnMissing: true
103 | },
104 | ],
105 | }),
106 | ],
107 | // proxy /api to port 4943 during development.
108 | // if you edit dfx.json to define a project-specific local network, change the port to match.
109 | devServer: {
110 | proxy: {
111 | "/api": {
112 | target: "http://127.0.0.1:4943",
113 | changeOrigin: true,
114 | pathRewrite: {
115 | "^/api": "/api",
116 | },
117 | },
118 | },
119 | static: path.resolve(__dirname, "src", frontendDirectory, "assets"),
120 | hot: true,
121 | watchFiles: [path.resolve(__dirname, "src", frontendDirectory)],
122 | liveReload: true,
123 | },
124 | };
125 |
--------------------------------------------------------------------------------
/remote-configs/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 | const webpack = require("webpack");
3 | const HtmlWebpackPlugin = require("html-webpack-plugin");
4 | const TerserPlugin = require("terser-webpack-plugin");
5 | const CopyPlugin = require("copy-webpack-plugin");
6 |
7 | function initCanisterEnv() {
8 | let localCanisters, prodCanisters;
9 | try {
10 | localCanisters = require(path.resolve(
11 | ".dfx",
12 | "local",
13 | "canister_ids.json"
14 | ));
15 | } catch (error) {
16 | console.log("No local canister_ids.json found. Continuing production");
17 | }
18 | try {
19 | prodCanisters = require(path.resolve("canister_ids.json"));
20 | } catch (error) {
21 | console.log("No production canister_ids.json found. Continuing with local");
22 | }
23 |
24 | const network =
25 | process.env.DFX_NETWORK ||
26 | (process.env.NODE_ENV === "production" ? "ic" : "local");
27 |
28 | const canisterConfig = network === "local" ? localCanisters : prodCanisters;
29 |
30 | return Object.entries(canisterConfig).reduce((prev, current) => {
31 | const [canisterName, canisterDetails] = current;
32 | prev[canisterName.toUpperCase() + "_CANISTER_ID"] =
33 | canisterDetails[network];
34 | return prev;
35 | }, {});
36 | }
37 | const canisterEnvVariables = initCanisterEnv();
38 |
39 | const isDevelopment = process.env.NODE_ENV !== "production";
40 |
41 | const frontendDirectory = "remote_configs_frontend";
42 |
43 | const frontend_entry = path.join("src", frontendDirectory, "src", "index.html");
44 |
45 | module.exports = {
46 | target: "web",
47 | mode: isDevelopment ? "development" : "production",
48 | entry: {
49 | // The frontend.entrypoint points to the HTML file for this build, so we need
50 | // to replace the extension to `.js`.
51 | index: path.join(__dirname, frontend_entry).replace(/\.html$/, ".js"),
52 | },
53 | devtool: isDevelopment ? "source-map" : false,
54 | optimization: {
55 | minimize: !isDevelopment,
56 | minimizer: [new TerserPlugin()],
57 | },
58 | resolve: {
59 | extensions: [".js", ".ts", ".jsx", ".tsx"],
60 | fallback: {
61 | assert: require.resolve("assert/"),
62 | buffer: require.resolve("buffer/"),
63 | events: require.resolve("events/"),
64 | stream: require.resolve("stream-browserify/"),
65 | util: require.resolve("util/"),
66 | },
67 | },
68 | output: {
69 | filename: "index.js",
70 | path: path.join(__dirname, "dist", frontendDirectory),
71 | },
72 |
73 | // Depending in the language or framework you are using for
74 | // front-end development, add module loaders to the default
75 | // webpack configuration. For example, if you are using React
76 | // modules and CSS as described in the "Adding a stylesheet"
77 | // tutorial, uncomment the following lines:
78 | // module: {
79 | // rules: [
80 | // { test: /\.(ts|tsx|jsx)$/, loader: "ts-loader" },
81 | // { test: /\.css$/, use: ['style-loader','css-loader'] }
82 | // ]
83 | // },
84 | plugins: [
85 | new HtmlWebpackPlugin({
86 | template: path.join(__dirname, frontend_entry),
87 | cache: false,
88 | }),
89 | new webpack.EnvironmentPlugin({
90 | NODE_ENV: "development",
91 | ...canisterEnvVariables,
92 | }),
93 | new webpack.ProvidePlugin({
94 | Buffer: [require.resolve("buffer/"), "Buffer"],
95 | process: require.resolve("process/browser"),
96 | }),
97 | new CopyPlugin({
98 | patterns: [
99 | {
100 | from: `src/${frontendDirectory}/src/.ic-assets.json*`,
101 | to: ".ic-assets.json5",
102 | noErrorOnMissing: true
103 | },
104 | ],
105 | }),
106 | ],
107 | // proxy /api to port 4943 during development.
108 | // if you edit dfx.json to define a project-specific local network, change the port to match.
109 | devServer: {
110 | proxy: {
111 | "/api": {
112 | target: "http://127.0.0.1:4943",
113 | changeOrigin: true,
114 | pathRewrite: {
115 | "^/api": "/api",
116 | },
117 | },
118 | },
119 | static: path.resolve(__dirname, "src", frontendDirectory, "assets"),
120 | hot: true,
121 | watchFiles: [path.resolve(__dirname, "src", frontendDirectory)],
122 | liveReload: true,
123 | },
124 | };
125 |
--------------------------------------------------------------------------------
/batch-transfer-tool/src/batch_transfer_tool_frontend/idls/icrc1.did:
--------------------------------------------------------------------------------
1 | export const icrc1IDL = ({ IDL }) => {
2 | const GetTransactionsRequest = IDL.Record({
3 | 'start' : IDL.Nat,
4 | 'length' : IDL.Nat,
5 | });
6 | const Account = IDL.Record({
7 | 'owner' : IDL.Principal,
8 | 'subaccount' : IDL.Opt(IDL.Vec(IDL.Nat8)),
9 | });
10 | const Burn = IDL.Record({
11 | 'from' : Account,
12 | 'memo' : IDL.Opt(IDL.Vec(IDL.Nat8)),
13 | 'created_at_time' : IDL.Opt(IDL.Nat64),
14 | 'amount' : IDL.Nat,
15 | });
16 | const Mint = IDL.Record({
17 | 'to' : Account,
18 | 'memo' : IDL.Opt(IDL.Vec(IDL.Nat8)),
19 | 'created_at_time' : IDL.Opt(IDL.Nat64),
20 | 'amount' : IDL.Nat,
21 | });
22 | const Transfer = IDL.Record({
23 | 'to' : Account,
24 | 'fee' : IDL.Opt(IDL.Nat),
25 | 'from' : Account,
26 | 'memo' : IDL.Opt(IDL.Vec(IDL.Nat8)),
27 | 'created_at_time' : IDL.Opt(IDL.Nat64),
28 | 'amount' : IDL.Nat,
29 | });
30 | const Transaction = IDL.Record({
31 | 'burn' : IDL.Opt(Burn),
32 | 'kind' : IDL.Text,
33 | 'mint' : IDL.Opt(Mint),
34 | 'timestamp' : IDL.Nat64,
35 | 'transfer' : IDL.Opt(Transfer),
36 | });
37 | const ArchivedTransactionRange = IDL.Record({
38 | 'callback' : IDL.Func(
39 | [GetTransactionsRequest],
40 | [IDL.Record({ 'transactions' : IDL.Vec(Transaction) })],
41 | ['query'],
42 | ),
43 | 'start' : IDL.Nat,
44 | 'length' : IDL.Nat,
45 | });
46 | const GetTransactionsResponse = IDL.Record({
47 | 'first_index' : IDL.Nat,
48 | 'log_length' : IDL.Nat,
49 | 'transactions' : IDL.Vec(Transaction),
50 | 'archived_transactions' : IDL.Vec(ArchivedTransactionRange),
51 | });
52 | const HttpRequest = IDL.Record({
53 | 'url' : IDL.Text,
54 | 'method' : IDL.Text,
55 | 'body' : IDL.Vec(IDL.Nat8),
56 | 'headers' : IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
57 | });
58 | const HttpResponse = IDL.Record({
59 | 'body' : IDL.Vec(IDL.Nat8),
60 | 'headers' : IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
61 | 'status_code' : IDL.Nat16,
62 | });
63 | const Value = IDL.Variant({
64 | 'Int' : IDL.Int,
65 | 'Nat' : IDL.Nat,
66 | 'Blob' : IDL.Vec(IDL.Nat8),
67 | 'Text' : IDL.Text,
68 | });
69 | const StandardRecord = IDL.Record({ 'url' : IDL.Text, 'name' : IDL.Text });
70 | const TransferArg = IDL.Record({
71 | 'to' : Account,
72 | 'fee' : IDL.Opt(IDL.Nat),
73 | 'memo' : IDL.Opt(IDL.Vec(IDL.Nat8)),
74 | 'from_subaccount' : IDL.Opt(IDL.Vec(IDL.Nat8)),
75 | 'created_at_time' : IDL.Opt(IDL.Nat64),
76 | 'amount' : IDL.Nat,
77 | });
78 | const TransferError = IDL.Variant({
79 | 'GenericError' : IDL.Record({
80 | 'message' : IDL.Text,
81 | 'error_code' : IDL.Nat,
82 | }),
83 | 'TemporarilyUnavailable' : IDL.Null,
84 | 'BadBurn' : IDL.Record({ 'min_burn_amount' : IDL.Nat }),
85 | 'Duplicate' : IDL.Record({ 'duplicate_of' : IDL.Nat }),
86 | 'BadFee' : IDL.Record({ 'expected_fee' : IDL.Nat }),
87 | 'CreatedInFuture' : IDL.Record({ 'ledger_time' : IDL.Nat64 }),
88 | 'TooOld' : IDL.Null,
89 | 'InsufficientFunds' : IDL.Record({ 'balance' : IDL.Nat }),
90 | });
91 | const Result = IDL.Variant({ 'Ok' : IDL.Nat, 'Err' : TransferError });
92 | return IDL.Service({
93 | 'get_transactions' : IDL.Func(
94 | [GetTransactionsRequest],
95 | [GetTransactionsResponse],
96 | ['query'],
97 | ),
98 | 'http_request' : IDL.Func([HttpRequest], [HttpResponse], ['query']),
99 | 'icrc1_balance_of' : IDL.Func([Account], [IDL.Nat], ['query']),
100 | 'icrc1_decimals' : IDL.Func([], [IDL.Nat8], ['query']),
101 | 'icrc1_fee' : IDL.Func([], [IDL.Nat], ['query']),
102 | 'icrc1_metadata' : IDL.Func(
103 | [],
104 | [IDL.Vec(IDL.Tuple(IDL.Text, Value))],
105 | ['query'],
106 | ),
107 | 'icrc1_minting_account' : IDL.Func([], [IDL.Opt(Account)], ['query']),
108 | 'icrc1_name' : IDL.Func([], [IDL.Text], ['query']),
109 | 'icrc1_supported_standards' : IDL.Func(
110 | [],
111 | [IDL.Vec(StandardRecord)],
112 | ['query'],
113 | ),
114 | 'icrc1_symbol' : IDL.Func([], [IDL.Text], ['query']),
115 | 'icrc1_total_supply' : IDL.Func([], [IDL.Nat], ['query']),
116 | 'icrc1_transfer' : IDL.Func([TransferArg], [Result], []),
117 | });
118 | };
--------------------------------------------------------------------------------
/login-webpage/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 | const webpack = require("webpack");
3 | const HtmlWebpackPlugin = require("html-webpack-plugin");
4 | const TerserPlugin = require("terser-webpack-plugin");
5 | const CopyPlugin = require("copy-webpack-plugin");
6 |
7 | function initCanisterEnv() {
8 | let localCanisters, prodCanisters;
9 | try {
10 | localCanisters = require(path.resolve(
11 | ".dfx",
12 | "local",
13 | "canister_ids.json"
14 | ));
15 | } catch (error) {
16 | console.log("No local canister_ids.json found. Continuing production");
17 | }
18 | try {
19 | prodCanisters = require(path.resolve("canister_ids.json"));
20 | } catch (error) {
21 | console.log("No production canister_ids.json found. Continuing with local");
22 | }
23 |
24 | const network =
25 | process.env.DFX_NETWORK ||
26 | (process.env.NODE_ENV === "production" ? "ic" : "local");
27 |
28 | const canisterConfig = network === "local" ? localCanisters : prodCanisters;
29 |
30 | return Object.entries(canisterConfig).reduce((prev, current) => {
31 | const [canisterName, canisterDetails] = current;
32 | prev[canisterName.toUpperCase() + "_CANISTER_ID"] =
33 | canisterDetails[network];
34 | return prev;
35 | }, {});
36 | }
37 | //const canisterEnvVariables = initCanisterEnv();
38 |
39 | const isDevelopment = process.env.NODE_ENV !== "production";
40 |
41 | const frontendDirectory = "login-webpage";
42 |
43 | const frontend_entry = path.join("src", frontendDirectory, "src", "index.html");
44 |
45 | module.exports = {
46 | target: "web",
47 | mode: isDevelopment ? "development" : "production",
48 | entry: {
49 | // The frontend.entrypoint points to the HTML file for this build, so we need
50 | // to replace the extension to `.js`.
51 | index: path.join(__dirname, frontend_entry).replace(/\.html$/, ".js"),
52 | },
53 | devtool: isDevelopment ? "source-map" : false,
54 | optimization: {
55 | minimize: !isDevelopment,
56 | minimizer: [new TerserPlugin()],
57 | },
58 | resolve: {
59 | extensions: [".js", ".ts", ".jsx", ".tsx"],
60 | fallback: {
61 | assert: require.resolve("assert/"),
62 | buffer: require.resolve("buffer/"),
63 | events: require.resolve("events/"),
64 | stream: require.resolve("stream-browserify/"),
65 | util: require.resolve("util/"),
66 | },
67 | },
68 | output: {
69 | filename: "index.js",
70 | path: path.join(__dirname, "dist", frontendDirectory),
71 | },
72 |
73 | // Depending in the language or framework you are using for
74 | // front-end development, add module loaders to the default
75 | // webpack configuration. For example, if you are using React
76 | // modules and CSS as described in the "Adding a stylesheet"
77 | // tutorial, uncomment the following lines:
78 | module: {
79 | rules: [
80 | { test: /\.(ts|tsx|jsx)$/, loader: "ts-loader" },
81 | { test: /\.css$/, use: ['style-loader', 'css-loader'] },
82 | {
83 | test: /\.jsx?$/,
84 | exclude: /node_modules/,
85 | use: {
86 | loader: 'babel-loader',
87 | options: {
88 | presets: ['@babel/preset-env', '@babel/preset-react']
89 | }
90 | }
91 | }
92 | ]
93 | },
94 | plugins: [
95 | new HtmlWebpackPlugin({
96 | template: path.join(__dirname, frontend_entry),
97 | cache: false,
98 | }),
99 | new webpack.EnvironmentPlugin({
100 | NODE_ENV: "development",
101 | // ...canisterEnvVariables,
102 | }),
103 | new webpack.ProvidePlugin({
104 | Buffer: [require.resolve("buffer/"), "Buffer"],
105 | process: require.resolve("process/browser"),
106 | }),
107 | new CopyPlugin({
108 | patterns: [
109 | {
110 | from: `src/${frontendDirectory}/src/.ic-assets.json*`,
111 | to: ".ic-assets.json5",
112 | noErrorOnMissing: true
113 | },
114 | ],
115 | }),
116 | ],
117 | // proxy /api to port 4943 during development.
118 | // if you edit dfx.json to define a project-specific local network, change the port to match.
119 | devServer: {
120 | proxy: {
121 | "/api": {
122 | target: "http://127.0.0.1:4943",
123 | changeOrigin: true,
124 | pathRewrite: {
125 | "^/api": "/api",
126 | },
127 | },
128 | },
129 | static: path.resolve(__dirname, "src", frontendDirectory, "assets"),
130 | hot: true,
131 | watchFiles: [path.resolve(__dirname, "src", frontendDirectory)],
132 | liveReload: true,
133 | },
134 | };
135 |
--------------------------------------------------------------------------------
/sns-metrics/src/metrics_backend/main.mo:
--------------------------------------------------------------------------------
1 | import A "mo:base/AssocList";
2 | import Array "mo:base/Array";
3 | import Blob "mo:base/Blob";
4 | import Bool "mo:base/Bool";
5 | import Buffer "mo:base/Buffer";
6 | import Cycles "mo:base/ExperimentalCycles";
7 | import Error "mo:base/Error";
8 | import Char "mo:base/Char";
9 | import Hash "mo:base/Hash";
10 | import HashMap "mo:base/HashMap";
11 | import Int "mo:base/Int";
12 | import Int16 "mo:base/Int16";
13 | import Int8 "mo:base/Int8";
14 | import Iter "mo:base/Iter";
15 | import List "mo:base/List";
16 | import Nat "mo:base/Nat";
17 | import Nat8 "mo:base/Nat8";
18 | import Nat32 "mo:base/Nat32";
19 | import Nat64 "mo:base/Nat64";
20 | import Option "mo:base/Option";
21 | import Prelude "mo:base/Prelude";
22 | import Principal "mo:base/Principal";
23 | import Result "mo:base/Result";
24 | import Text "mo:base/Text";
25 | import Time "mo:base/Time";
26 | import Trie "mo:base/Trie";
27 | import Trie2D "mo:base/Trie";
28 | import Float "mo:base/Float";
29 | import Int64 "mo:base/Int64";
30 |
31 | import Governance "governance.types";
32 |
33 | actor {
34 | let governance : Governance.Self = actor ("xomae-vyaaa-aaaaq-aabhq-cai");
35 |
36 | private stable var neuron_staking_details : {
37 | dissolving : Nat64;
38 | not_dissolving : Nat64;
39 | } = {
40 | dissolving = 0;
41 | not_dissolving = 0;
42 | };
43 |
44 | private stable var total_neurons = 0;
45 |
46 | private func textToFloat(t : Text) : Float {
47 | var i : Float = 1;
48 | var f : Float = 0;
49 | var isDecimal : Bool = false;
50 | for (c in t.chars()) {
51 | if (Char.isDigit(c)) {
52 | let charToNat : Nat64 = Nat64.fromNat(Nat32.toNat(Char.toNat32(c) -48));
53 | let natToFloat : Float = Float.fromInt64(Int64.fromNat64(charToNat));
54 | if (isDecimal) {
55 | let n : Float = natToFloat / Float.pow(10, i);
56 | f := f + n;
57 | } else {
58 | f := f * 10 + natToFloat;
59 | };
60 | i := i + 1;
61 | } else {
62 | if (Char.equal(c, '.') or Char.equal(c, ',')) {
63 | f := f / Float.pow(10, i); // Force decimal
64 | f := f * Float.pow(10, i); // Correction
65 | isDecimal := true;
66 | i := 1;
67 | } else {};
68 | };
69 | };
70 |
71 | return f;
72 | };
73 |
74 | public shared ({ caller }) func refresh_neurons_staking_details() : async ({
75 | dissolving : Nat64;
76 | not_dissolving : Nat64;
77 | }) {
78 | assert (caller != Principal.fromText("2vxsx-fae"));
79 | total_neurons := 0;
80 | var _dissolving : Nat = 0;
81 | var _not_dissolving : Nat = 0;
82 |
83 | var isPageLeft = true;
84 | var last_neuron : ?Governance.NeuronId = null;
85 |
86 | while (isPageLeft) {
87 | let neurons = await governance.list_neurons({
88 | of_principal = null;
89 | limit = 100;
90 | start_page_at = last_neuron;
91 | });
92 | for (i in neurons.neurons.vals()) {
93 | switch (i.dissolve_state) {
94 | case (?is_set) {
95 | switch (is_set) {
96 | case (#DissolveDelaySeconds _) {
97 | neuron_staking_details := {
98 | dissolving = neuron_staking_details.dissolving;
99 | not_dissolving = neuron_staking_details.not_dissolving + i.cached_neuron_stake_e8s;
100 | };
101 | };
102 | case (#WhenDissolvedTimestampSeconds _) {
103 | neuron_staking_details := {
104 | dissolving = neuron_staking_details.dissolving + i.cached_neuron_stake_e8s;
105 | not_dissolving = neuron_staking_details.not_dissolving;
106 | };
107 | };
108 | };
109 | };
110 | case _ {};
111 | };
112 | total_neurons := total_neurons + 1;
113 | };
114 | if (neurons.neurons.size() < 100) {
115 | isPageLeft := false;
116 | } else {
117 | last_neuron := neurons.neurons[99].id;
118 | };
119 | };
120 |
121 | return neuron_staking_details;
122 | };
123 |
124 | public query func get_neuron_staking_details() : async ({
125 | dissolving : Float;
126 | not_dissolving : Float;
127 | }) {
128 | let diss = Nat64.toText(neuron_staking_details.dissolving);
129 | let not_diss = Nat64.toText(neuron_staking_details.not_dissolving);
130 | return {
131 | dissolving = Float.div(textToFloat(diss), 100000000.0);
132 | not_dissolving = Float.div(textToFloat(not_diss), 100000000.0);
133 | };
134 | };
135 |
136 | // public query func cycleBalance() : async Nat {
137 | // Cycles.balance();
138 | // };
139 |
140 | public query func get_total_neurons() : async Nat { return total_neurons };
141 |
142 | };
143 |
--------------------------------------------------------------------------------
/candid-with-auth/dist/didjs/index.html:
--------------------------------------------------------------------------------
1 | World Candid UI
World ID:
User Principal ID:
User Account ID:
Configure Actions and Configs
Output Log
Methods
--------------------------------------------------------------------------------
/chat/src/chat_frontend/src/.ic-assets.json5:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "match": "**/*",
4 | "headers": {
5 | // Security: The Content Security Policy (CSP) given below aims at working with many apps rather than providing maximal security.
6 | // We recommend tightening the CSP for your specific application. Some recommendations are as follows:
7 | // - Use the CSP Evaluator (https://csp-evaluator.withgoogle.com/) to validate the CSP you define.
8 | // - Follow the “Strict CSP” recommendations (https://csp.withgoogle.com/docs/strict-csp.html). However, note that in the context of the IC,
9 | // nonces cannot be used because the response bodies must be static to work well with HTTP asset certification.
10 | // Thus, we recommend to include script hashes (in combination with strict-dynamic) in the CSP as described
11 | // in https://csp.withgoogle.com/docs/faq.html in section “What if my site is static and I can't add nonces to scripts?”.
12 | // See for example the II CSP (https://github.com/dfinity/internet-identity/blob/main/src/internet_identity/src/http.rs).
13 | // - It is recommended to tighten the connect-src directive. With the current CSP configuration the browser can
14 | // make requests to https://*.ic0.app, hence being able to call any canister via https://ic0.app/api/v2/canister/{canister-ID}.
15 | // This could potentially be used in combination with another vulnerability (e.g. XSS) to exfiltrate private data.
16 | // The developer can configure this policy to only allow requests to their specific canisters,
17 | // e.g: connect-src 'self' https://ic0.app/api/v2/canister/{my-canister-ID}, where {my-canister-ID} has the following format: aaaaa-aaaaa-aaaaa-aaaaa-aaa
18 | // - It is recommended to configure style-src, style-src-elem and font-src directives with the resources your canister is going to use
19 | // instead of using the wild card (*) option. Normally this will include 'self' but also other third party styles or fonts resources (e.g: https://fonts.googleapis.com or other CDNs)
20 |
21 | // Notes about the CSP below:
22 | // - script-src 'unsafe-eval' is currently required because agent-js uses a WebAssembly module for the validation of bls signatures.
23 | // There is currently no other way to allow execution of WebAssembly modules with CSP.
24 | // See: https://github.com/WebAssembly/content-security-policy/blob/main/proposals/CSP.md.
25 | // - We added img-src data: because data: images are used often.
26 | // - frame-ancestors: none mitigates clickjacking attacks. See https://owasp.org/www-community/attacks/Clickjacking.
27 | "Content-Security-Policy": "default-src 'self';script-src 'self' 'unsafe-eval';connect-src 'self' https://ic0.app https://*.ic0.app;img-src 'self' data:;style-src * 'unsafe-inline';style-src-elem * 'unsafe-inline';font-src *;object-src 'none';base-uri 'self';frame-ancestors 'none';form-action 'self';upgrade-insecure-requests;",
28 |
29 | // Security: The permissions policy disables all features for security reasons. If your site needs such permissions, activate them.
30 | // To configure permissions go here https://www.permissionspolicy.com/
31 | "Permissions-Policy": "accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), window-placement=(), vertical-scroll=()",
32 |
33 | // Security: Mitigates clickjacking attacks.
34 | // See: https://owasp.org/www-community/attacks/Clickjacking.
35 | "X-Frame-Options": "DENY",
36 |
37 | // Security: Avoids forwarding referrer information to other origins.
38 | // See: https://owasp.org/www-project-secure-headers/#referrer-policy.
39 | "Referrer-Policy": "same-origin",
40 |
41 | // Security: Tells the user’s browser that it must always use HTTPS with your site.
42 | // See: https://owasp.org/www-project-secure-headers/#http-strict-transport-security
43 | "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
44 |
45 | // Security: Prevents the browser from interpreting files as a different MIME type to what is specified in the Content-Type header.
46 | // See: https://owasp.org/www-project-secure-headers/#x-content-type-options
47 | "X-Content-Type-Options": "nosniff",
48 |
49 | // Security: Enables browser features to mitigate some of the XSS attacks. Note that it has to be in mode=block.
50 | // See: https://owasp.org/www-community/attacks/xss/
51 | "X-XSS-Protection": "1; mode=block"
52 | },
53 | // redirect all requests from .raw.ic0.app to .ic0.app (this redirection is the default)
54 | "allow_raw_access": false
55 | },
56 | ]
57 |
--------------------------------------------------------------------------------
/chat/src/chat_frontend/assets/.ic-assets.json5:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "match": "**/*",
4 | "headers": {
5 | // Security: The Content Security Policy (CSP) given below aims at working with many apps rather than providing maximal security.
6 | // We recommend tightening the CSP for your specific application. Some recommendations are as follows:
7 | // - Use the CSP Evaluator (https://csp-evaluator.withgoogle.com/) to validate the CSP you define.
8 | // - Follow the “Strict CSP” recommendations (https://csp.withgoogle.com/docs/strict-csp.html). However, note that in the context of the IC,
9 | // nonces cannot be used because the response bodies must be static to work well with HTTP asset certification.
10 | // Thus, we recommend to include script hashes (in combination with strict-dynamic) in the CSP as described
11 | // in https://csp.withgoogle.com/docs/faq.html in section “What if my site is static and I can't add nonces to scripts?”.
12 | // See for example the II CSP (https://github.com/dfinity/internet-identity/blob/main/src/internet_identity/src/http.rs).
13 | // - It is recommended to tighten the connect-src directive. With the current CSP configuration the browser can
14 | // make requests to https://*.ic0.app, hence being able to call any canister via https://ic0.app/api/v2/canister/{canister-ID}.
15 | // This could potentially be used in combination with another vulnerability (e.g. XSS) to exfiltrate private data.
16 | // The developer can configure this policy to only allow requests to their specific canisters,
17 | // e.g: connect-src 'self' https://ic0.app/api/v2/canister/{my-canister-ID}, where {my-canister-ID} has the following format: aaaaa-aaaaa-aaaaa-aaaaa-aaa
18 | // - It is recommended to configure style-src, style-src-elem and font-src directives with the resources your canister is going to use
19 | // instead of using the wild card (*) option. Normally this will include 'self' but also other third party styles or fonts resources (e.g: https://fonts.googleapis.com or other CDNs)
20 |
21 | // Notes about the CSP below:
22 | // - script-src 'unsafe-eval' is currently required because agent-js uses a WebAssembly module for the validation of bls signatures.
23 | // There is currently no other way to allow execution of WebAssembly modules with CSP.
24 | // See: https://github.com/WebAssembly/content-security-policy/blob/main/proposals/CSP.md.
25 | // - We added img-src data: because data: images are used often.
26 | // - frame-ancestors: none mitigates clickjacking attacks. See https://owasp.org/www-community/attacks/Clickjacking.
27 | "Content-Security-Policy": "default-src 'self';script-src 'self' 'unsafe-eval';connect-src 'self' https://ic0.app https://*.ic0.app;img-src 'self' data:;style-src * 'unsafe-inline';style-src-elem * 'unsafe-inline';font-src *;object-src 'none';base-uri 'self';frame-ancestors 'none';form-action 'self';upgrade-insecure-requests;",
28 |
29 | // Security: The permissions policy disables all features for security reasons. If your site needs such permissions, activate them.
30 | // To configure permissions go here https://www.permissionspolicy.com/
31 | "Permissions-Policy": "accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), window-placement=(), vertical-scroll=()",
32 |
33 | // Security: Mitigates clickjacking attacks.
34 | // See: https://owasp.org/www-community/attacks/Clickjacking.
35 | "X-Frame-Options": "DENY",
36 |
37 | // Security: Avoids forwarding referrer information to other origins.
38 | // See: https://owasp.org/www-project-secure-headers/#referrer-policy.
39 | "Referrer-Policy": "same-origin",
40 |
41 | // Security: Tells the user’s browser that it must always use HTTPS with your site.
42 | // See: https://owasp.org/www-project-secure-headers/#http-strict-transport-security
43 | "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
44 |
45 | // Security: Prevents the browser from interpreting files as a different MIME type to what is specified in the Content-Type header.
46 | // See: https://owasp.org/www-project-secure-headers/#x-content-type-options
47 | "X-Content-Type-Options": "nosniff",
48 |
49 | // Security: Enables browser features to mitigate some of the XSS attacks. Note that it has to be in mode=block.
50 | // See: https://owasp.org/www-community/attacks/xss/
51 | "X-XSS-Protection": "1; mode=block"
52 | },
53 | // redirect all requests from .raw.ic0.app to .ic0.app (this redirection is the default)
54 | "allow_raw_access": false
55 | },
56 | ]
57 |
--------------------------------------------------------------------------------
/topup/src/topup_frontend/assets/.ic-assets.json5:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "match": "**/*",
4 | "headers": {
5 | // Security: The Content Security Policy (CSP) given below aims at working with many apps rather than providing maximal security.
6 | // We recommend tightening the CSP for your specific application. Some recommendations are as follows:
7 | // - Use the CSP Evaluator (https://csp-evaluator.withgoogle.com/) to validate the CSP you define.
8 | // - Follow the “Strict CSP” recommendations (https://csp.withgoogle.com/docs/strict-csp.html). However, note that in the context of the IC,
9 | // nonces cannot be used because the response bodies must be static to work well with HTTP asset certification.
10 | // Thus, we recommend to include script hashes (in combination with strict-dynamic) in the CSP as described
11 | // in https://csp.withgoogle.com/docs/faq.html in section “What if my site is static and I can't add nonces to scripts?”.
12 | // See for example the II CSP (https://github.com/dfinity/internet-identity/blob/main/src/internet_identity/src/http.rs).
13 | // - It is recommended to tighten the connect-src directive. With the current CSP configuration the browser can
14 | // make requests to https://*.ic0.app, hence being able to call any canister via https://ic0.app/api/v2/canister/{canister-ID}.
15 | // This could potentially be used in combination with another vulnerability (e.g. XSS) to exfiltrate private data.
16 | // The developer can configure this policy to only allow requests to their specific canisters,
17 | // e.g: connect-src 'self' https://ic0.app/api/v2/canister/{my-canister-ID}, where {my-canister-ID} has the following format: aaaaa-aaaaa-aaaaa-aaaaa-aaa
18 | // - It is recommended to configure style-src, style-src-elem and font-src directives with the resources your canister is going to use
19 | // instead of using the wild card (*) option. Normally this will include 'self' but also other third party styles or fonts resources (e.g: https://fonts.googleapis.com or other CDNs)
20 |
21 | // Notes about the CSP below:
22 | // - script-src 'unsafe-eval' is currently required because agent-js uses a WebAssembly module for the validation of bls signatures.
23 | // There is currently no other way to allow execution of WebAssembly modules with CSP.
24 | // See: https://github.com/WebAssembly/content-security-policy/blob/main/proposals/CSP.md.
25 | // - We added img-src data: because data: images are used often.
26 | // - frame-ancestors: none mitigates clickjacking attacks. See https://owasp.org/www-community/attacks/Clickjacking.
27 | "Content-Security-Policy": "default-src 'self';script-src 'self' 'unsafe-eval';connect-src 'self' https://ic0.app https://*.ic0.app;img-src 'self' data:;style-src * 'unsafe-inline';style-src-elem * 'unsafe-inline';font-src *;object-src 'none';base-uri 'self';frame-ancestors 'none';form-action 'self';upgrade-insecure-requests;",
28 |
29 | // Security: The permissions policy disables all features for security reasons. If your site needs such permissions, activate them.
30 | // To configure permissions go here https://www.permissionspolicy.com/
31 | "Permissions-Policy": "accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), window-placement=(), vertical-scroll=()",
32 |
33 | // Security: Mitigates clickjacking attacks.
34 | // See: https://owasp.org/www-community/attacks/Clickjacking.
35 | "X-Frame-Options": "DENY",
36 |
37 | // Security: Avoids forwarding referrer information to other origins.
38 | // See: https://owasp.org/www-project-secure-headers/#referrer-policy.
39 | "Referrer-Policy": "same-origin",
40 |
41 | // Security: Tells the user’s browser that it must always use HTTPS with your site.
42 | // See: https://owasp.org/www-project-secure-headers/#http-strict-transport-security
43 | "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
44 |
45 | // Security: Prevents the browser from interpreting files as a different MIME type to what is specified in the Content-Type header.
46 | // See: https://owasp.org/www-project-secure-headers/#x-content-type-options
47 | "X-Content-Type-Options": "nosniff",
48 |
49 | // Security: Enables browser features to mitigate some of the XSS attacks. Note that it has to be in mode=block.
50 | // See: https://owasp.org/www-community/attacks/xss/
51 | "X-XSS-Protection": "1; mode=block"
52 | },
53 | // redirect all requests from .raw.ic0.app to .ic0.app (this redirection is the default)
54 | "allow_raw_access": false
55 | },
56 | ]
57 |
--------------------------------------------------------------------------------
/topup/src/topup_frontend/src/.ic-assets.json5:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "match": "**/*",
4 | "headers": {
5 | // Security: The Content Security Policy (CSP) given below aims at working with many apps rather than providing maximal security.
6 | // We recommend tightening the CSP for your specific application. Some recommendations are as follows:
7 | // - Use the CSP Evaluator (https://csp-evaluator.withgoogle.com/) to validate the CSP you define.
8 | // - Follow the “Strict CSP” recommendations (https://csp.withgoogle.com/docs/strict-csp.html). However, note that in the context of the IC,
9 | // nonces cannot be used because the response bodies must be static to work well with HTTP asset certification.
10 | // Thus, we recommend to include script hashes (in combination with strict-dynamic) in the CSP as described
11 | // in https://csp.withgoogle.com/docs/faq.html in section “What if my site is static and I can't add nonces to scripts?”.
12 | // See for example the II CSP (https://github.com/dfinity/internet-identity/blob/main/src/internet_identity/src/http.rs).
13 | // - It is recommended to tighten the connect-src directive. With the current CSP configuration the browser can
14 | // make requests to https://*.ic0.app, hence being able to call any canister via https://ic0.app/api/v2/canister/{canister-ID}.
15 | // This could potentially be used in combination with another vulnerability (e.g. XSS) to exfiltrate private data.
16 | // The developer can configure this policy to only allow requests to their specific canisters,
17 | // e.g: connect-src 'self' https://ic0.app/api/v2/canister/{my-canister-ID}, where {my-canister-ID} has the following format: aaaaa-aaaaa-aaaaa-aaaaa-aaa
18 | // - It is recommended to configure style-src, style-src-elem and font-src directives with the resources your canister is going to use
19 | // instead of using the wild card (*) option. Normally this will include 'self' but also other third party styles or fonts resources (e.g: https://fonts.googleapis.com or other CDNs)
20 |
21 | // Notes about the CSP below:
22 | // - script-src 'unsafe-eval' is currently required because agent-js uses a WebAssembly module for the validation of bls signatures.
23 | // There is currently no other way to allow execution of WebAssembly modules with CSP.
24 | // See: https://github.com/WebAssembly/content-security-policy/blob/main/proposals/CSP.md.
25 | // - We added img-src data: because data: images are used often.
26 | // - frame-ancestors: none mitigates clickjacking attacks. See https://owasp.org/www-community/attacks/Clickjacking.
27 | "Content-Security-Policy": "default-src 'self';script-src 'self' 'unsafe-eval';connect-src 'self' https://ic0.app https://*.ic0.app;img-src 'self' data:;style-src * 'unsafe-inline';style-src-elem * 'unsafe-inline';font-src *;object-src 'none';base-uri 'self';frame-ancestors 'none';form-action 'self';upgrade-insecure-requests;",
28 |
29 | // Security: The permissions policy disables all features for security reasons. If your site needs such permissions, activate them.
30 | // To configure permissions go here https://www.permissionspolicy.com/
31 | "Permissions-Policy": "accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), window-placement=(), vertical-scroll=()",
32 |
33 | // Security: Mitigates clickjacking attacks.
34 | // See: https://owasp.org/www-community/attacks/Clickjacking.
35 | "X-Frame-Options": "DENY",
36 |
37 | // Security: Avoids forwarding referrer information to other origins.
38 | // See: https://owasp.org/www-project-secure-headers/#referrer-policy.
39 | "Referrer-Policy": "same-origin",
40 |
41 | // Security: Tells the user’s browser that it must always use HTTPS with your site.
42 | // See: https://owasp.org/www-project-secure-headers/#http-strict-transport-security
43 | "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
44 |
45 | // Security: Prevents the browser from interpreting files as a different MIME type to what is specified in the Content-Type header.
46 | // See: https://owasp.org/www-project-secure-headers/#x-content-type-options
47 | "X-Content-Type-Options": "nosniff",
48 |
49 | // Security: Enables browser features to mitigate some of the XSS attacks. Note that it has to be in mode=block.
50 | // See: https://owasp.org/www-community/attacks/xss/
51 | "X-XSS-Protection": "1; mode=block"
52 | },
53 | // redirect all requests from .raw.ic0.app to .ic0.app (this redirection is the default)
54 | "allow_raw_access": false
55 | },
56 | ]
57 |
--------------------------------------------------------------------------------
/multiplayer/src/multiplayer_frontend/src/.ic-assets.json5:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "match": "**/*",
4 | "headers": {
5 | // Security: The Content Security Policy (CSP) given below aims at working with many apps rather than providing maximal security.
6 | // We recommend tightening the CSP for your specific application. Some recommendations are as follows:
7 | // - Use the CSP Evaluator (https://csp-evaluator.withgoogle.com/) to validate the CSP you define.
8 | // - Follow the “Strict CSP” recommendations (https://csp.withgoogle.com/docs/strict-csp.html). However, note that in the context of the IC,
9 | // nonces cannot be used because the response bodies must be static to work well with HTTP asset certification.
10 | // Thus, we recommend to include script hashes (in combination with strict-dynamic) in the CSP as described
11 | // in https://csp.withgoogle.com/docs/faq.html in section “What if my site is static and I can't add nonces to scripts?”.
12 | // See for example the II CSP (https://github.com/dfinity/internet-identity/blob/main/src/internet_identity/src/http.rs).
13 | // - It is recommended to tighten the connect-src directive. With the current CSP configuration the browser can
14 | // make requests to https://*.ic0.app, hence being able to call any canister via https://ic0.app/api/v2/canister/{canister-ID}.
15 | // This could potentially be used in combination with another vulnerability (e.g. XSS) to exfiltrate private data.
16 | // The developer can configure this policy to only allow requests to their specific canisters,
17 | // e.g: connect-src 'self' https://ic0.app/api/v2/canister/{my-canister-ID}, where {my-canister-ID} has the following format: aaaaa-aaaaa-aaaaa-aaaaa-aaa
18 | // - It is recommended to configure style-src, style-src-elem and font-src directives with the resources your canister is going to use
19 | // instead of using the wild card (*) option. Normally this will include 'self' but also other third party styles or fonts resources (e.g: https://fonts.googleapis.com or other CDNs)
20 |
21 | // Notes about the CSP below:
22 | // - script-src 'unsafe-eval' is currently required because agent-js uses a WebAssembly module for the validation of bls signatures.
23 | // There is currently no other way to allow execution of WebAssembly modules with CSP.
24 | // See: https://github.com/WebAssembly/content-security-policy/blob/main/proposals/CSP.md.
25 | // - We added img-src data: because data: images are used often.
26 | // - frame-ancestors: none mitigates clickjacking attacks. See https://owasp.org/www-community/attacks/Clickjacking.
27 | "Content-Security-Policy": "default-src 'self';script-src 'self' 'unsafe-eval';connect-src 'self' https://ic0.app https://*.ic0.app;img-src 'self' data:;style-src * 'unsafe-inline';style-src-elem * 'unsafe-inline';font-src *;object-src 'none';base-uri 'self';frame-ancestors 'none';form-action 'self';upgrade-insecure-requests;",
28 |
29 | // Security: The permissions policy disables all features for security reasons. If your site needs such permissions, activate them.
30 | // To configure permissions go here https://www.permissionspolicy.com/
31 | "Permissions-Policy": "accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), window-placement=(), vertical-scroll=()",
32 |
33 | // Security: Mitigates clickjacking attacks.
34 | // See: https://owasp.org/www-community/attacks/Clickjacking.
35 | "X-Frame-Options": "DENY",
36 |
37 | // Security: Avoids forwarding referrer information to other origins.
38 | // See: https://owasp.org/www-project-secure-headers/#referrer-policy.
39 | "Referrer-Policy": "same-origin",
40 |
41 | // Security: Tells the user’s browser that it must always use HTTPS with your site.
42 | // See: https://owasp.org/www-project-secure-headers/#http-strict-transport-security
43 | "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
44 |
45 | // Security: Prevents the browser from interpreting files as a different MIME type to what is specified in the Content-Type header.
46 | // See: https://owasp.org/www-project-secure-headers/#x-content-type-options
47 | "X-Content-Type-Options": "nosniff",
48 |
49 | // Security: Enables browser features to mitigate some of the XSS attacks. Note that it has to be in mode=block.
50 | // See: https://owasp.org/www-community/attacks/xss/
51 | "X-XSS-Protection": "1; mode=block"
52 | },
53 | // redirect all requests from .raw.ic0.app to .ic0.app (this redirection is the default)
54 | "allow_raw_access": false
55 | },
56 | ]
57 |
--------------------------------------------------------------------------------
/multiplayer/src/multiplayer_frontend/assets/.ic-assets.json5:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "match": "**/*",
4 | "headers": {
5 | // Security: The Content Security Policy (CSP) given below aims at working with many apps rather than providing maximal security.
6 | // We recommend tightening the CSP for your specific application. Some recommendations are as follows:
7 | // - Use the CSP Evaluator (https://csp-evaluator.withgoogle.com/) to validate the CSP you define.
8 | // - Follow the “Strict CSP” recommendations (https://csp.withgoogle.com/docs/strict-csp.html). However, note that in the context of the IC,
9 | // nonces cannot be used because the response bodies must be static to work well with HTTP asset certification.
10 | // Thus, we recommend to include script hashes (in combination with strict-dynamic) in the CSP as described
11 | // in https://csp.withgoogle.com/docs/faq.html in section “What if my site is static and I can't add nonces to scripts?”.
12 | // See for example the II CSP (https://github.com/dfinity/internet-identity/blob/main/src/internet_identity/src/http.rs).
13 | // - It is recommended to tighten the connect-src directive. With the current CSP configuration the browser can
14 | // make requests to https://*.ic0.app, hence being able to call any canister via https://ic0.app/api/v2/canister/{canister-ID}.
15 | // This could potentially be used in combination with another vulnerability (e.g. XSS) to exfiltrate private data.
16 | // The developer can configure this policy to only allow requests to their specific canisters,
17 | // e.g: connect-src 'self' https://ic0.app/api/v2/canister/{my-canister-ID}, where {my-canister-ID} has the following format: aaaaa-aaaaa-aaaaa-aaaaa-aaa
18 | // - It is recommended to configure style-src, style-src-elem and font-src directives with the resources your canister is going to use
19 | // instead of using the wild card (*) option. Normally this will include 'self' but also other third party styles or fonts resources (e.g: https://fonts.googleapis.com or other CDNs)
20 |
21 | // Notes about the CSP below:
22 | // - script-src 'unsafe-eval' is currently required because agent-js uses a WebAssembly module for the validation of bls signatures.
23 | // There is currently no other way to allow execution of WebAssembly modules with CSP.
24 | // See: https://github.com/WebAssembly/content-security-policy/blob/main/proposals/CSP.md.
25 | // - We added img-src data: because data: images are used often.
26 | // - frame-ancestors: none mitigates clickjacking attacks. See https://owasp.org/www-community/attacks/Clickjacking.
27 | "Content-Security-Policy": "default-src 'self';script-src 'self' 'unsafe-eval';connect-src 'self' https://ic0.app https://*.ic0.app;img-src 'self' data:;style-src * 'unsafe-inline';style-src-elem * 'unsafe-inline';font-src *;object-src 'none';base-uri 'self';frame-ancestors 'none';form-action 'self';upgrade-insecure-requests;",
28 |
29 | // Security: The permissions policy disables all features for security reasons. If your site needs such permissions, activate them.
30 | // To configure permissions go here https://www.permissionspolicy.com/
31 | "Permissions-Policy": "accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), window-placement=(), vertical-scroll=()",
32 |
33 | // Security: Mitigates clickjacking attacks.
34 | // See: https://owasp.org/www-community/attacks/Clickjacking.
35 | "X-Frame-Options": "DENY",
36 |
37 | // Security: Avoids forwarding referrer information to other origins.
38 | // See: https://owasp.org/www-project-secure-headers/#referrer-policy.
39 | "Referrer-Policy": "same-origin",
40 |
41 | // Security: Tells the user’s browser that it must always use HTTPS with your site.
42 | // See: https://owasp.org/www-project-secure-headers/#http-strict-transport-security
43 | "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
44 |
45 | // Security: Prevents the browser from interpreting files as a different MIME type to what is specified in the Content-Type header.
46 | // See: https://owasp.org/www-project-secure-headers/#x-content-type-options
47 | "X-Content-Type-Options": "nosniff",
48 |
49 | // Security: Enables browser features to mitigate some of the XSS attacks. Note that it has to be in mode=block.
50 | // See: https://owasp.org/www-community/attacks/xss/
51 | "X-XSS-Protection": "1; mode=block"
52 | },
53 | // redirect all requests from .raw.ic0.app to .ic0.app (this redirection is the default)
54 | "allow_raw_access": false
55 | },
56 | ]
57 |
--------------------------------------------------------------------------------
/remote-configs/src/remote_configs_frontend/src/.ic-assets.json5:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "match": "**/*",
4 | "headers": {
5 | // Security: The Content Security Policy (CSP) given below aims at working with many apps rather than providing maximal security.
6 | // We recommend tightening the CSP for your specific application. Some recommendations are as follows:
7 | // - Use the CSP Evaluator (https://csp-evaluator.withgoogle.com/) to validate the CSP you define.
8 | // - Follow the “Strict CSP” recommendations (https://csp.withgoogle.com/docs/strict-csp.html). However, note that in the context of the IC,
9 | // nonces cannot be used because the response bodies must be static to work well with HTTP asset certification.
10 | // Thus, we recommend to include script hashes (in combination with strict-dynamic) in the CSP as described
11 | // in https://csp.withgoogle.com/docs/faq.html in section “What if my site is static and I can't add nonces to scripts?”.
12 | // See for example the II CSP (https://github.com/dfinity/internet-identity/blob/main/src/internet_identity/src/http.rs).
13 | // - It is recommended to tighten the connect-src directive. With the current CSP configuration the browser can
14 | // make requests to https://*.ic0.app, hence being able to call any canister via https://ic0.app/api/v2/canister/{canister-ID}.
15 | // This could potentially be used in combination with another vulnerability (e.g. XSS) to exfiltrate private data.
16 | // The developer can configure this policy to only allow requests to their specific canisters,
17 | // e.g: connect-src 'self' https://ic0.app/api/v2/canister/{my-canister-ID}, where {my-canister-ID} has the following format: aaaaa-aaaaa-aaaaa-aaaaa-aaa
18 | // - It is recommended to configure style-src, style-src-elem and font-src directives with the resources your canister is going to use
19 | // instead of using the wild card (*) option. Normally this will include 'self' but also other third party styles or fonts resources (e.g: https://fonts.googleapis.com or other CDNs)
20 |
21 | // Notes about the CSP below:
22 | // - script-src 'unsafe-eval' is currently required because agent-js uses a WebAssembly module for the validation of bls signatures.
23 | // There is currently no other way to allow execution of WebAssembly modules with CSP.
24 | // See: https://github.com/WebAssembly/content-security-policy/blob/main/proposals/CSP.md.
25 | // - We added img-src data: because data: images are used often.
26 | // - frame-ancestors: none mitigates clickjacking attacks. See https://owasp.org/www-community/attacks/Clickjacking.
27 | "Content-Security-Policy": "default-src 'self';script-src 'self' 'unsafe-eval';connect-src 'self' https://ic0.app https://*.ic0.app;img-src 'self' data:;style-src * 'unsafe-inline';style-src-elem * 'unsafe-inline';font-src *;object-src 'none';base-uri 'self';frame-ancestors 'none';form-action 'self';upgrade-insecure-requests;",
28 |
29 | // Security: The permissions policy disables all features for security reasons. If your site needs such permissions, activate them.
30 | // To configure permissions go here https://www.permissionspolicy.com/
31 | "Permissions-Policy": "accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), window-placement=(), vertical-scroll=()",
32 |
33 | // Security: Mitigates clickjacking attacks.
34 | // See: https://owasp.org/www-community/attacks/Clickjacking.
35 | "X-Frame-Options": "DENY",
36 |
37 | // Security: Avoids forwarding referrer information to other origins.
38 | // See: https://owasp.org/www-project-secure-headers/#referrer-policy.
39 | "Referrer-Policy": "same-origin",
40 |
41 | // Security: Tells the user’s browser that it must always use HTTPS with your site.
42 | // See: https://owasp.org/www-project-secure-headers/#http-strict-transport-security
43 | "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
44 |
45 | // Security: Prevents the browser from interpreting files as a different MIME type to what is specified in the Content-Type header.
46 | // See: https://owasp.org/www-project-secure-headers/#x-content-type-options
47 | "X-Content-Type-Options": "nosniff",
48 |
49 | // Security: Enables browser features to mitigate some of the XSS attacks. Note that it has to be in mode=block.
50 | // See: https://owasp.org/www-community/attacks/xss/
51 | "X-XSS-Protection": "1; mode=block"
52 | },
53 | // redirect all requests from .raw.ic0.app to .ic0.app (this redirection is the default)
54 | "allow_raw_access": false
55 | },
56 | ]
57 |
--------------------------------------------------------------------------------
/remote-configs/src/remote_configs_frontend/assets/.ic-assets.json5:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "match": "**/*",
4 | "headers": {
5 | // Security: The Content Security Policy (CSP) given below aims at working with many apps rather than providing maximal security.
6 | // We recommend tightening the CSP for your specific application. Some recommendations are as follows:
7 | // - Use the CSP Evaluator (https://csp-evaluator.withgoogle.com/) to validate the CSP you define.
8 | // - Follow the “Strict CSP” recommendations (https://csp.withgoogle.com/docs/strict-csp.html). However, note that in the context of the IC,
9 | // nonces cannot be used because the response bodies must be static to work well with HTTP asset certification.
10 | // Thus, we recommend to include script hashes (in combination with strict-dynamic) in the CSP as described
11 | // in https://csp.withgoogle.com/docs/faq.html in section “What if my site is static and I can't add nonces to scripts?”.
12 | // See for example the II CSP (https://github.com/dfinity/internet-identity/blob/main/src/internet_identity/src/http.rs).
13 | // - It is recommended to tighten the connect-src directive. With the current CSP configuration the browser can
14 | // make requests to https://*.ic0.app, hence being able to call any canister via https://ic0.app/api/v2/canister/{canister-ID}.
15 | // This could potentially be used in combination with another vulnerability (e.g. XSS) to exfiltrate private data.
16 | // The developer can configure this policy to only allow requests to their specific canisters,
17 | // e.g: connect-src 'self' https://ic0.app/api/v2/canister/{my-canister-ID}, where {my-canister-ID} has the following format: aaaaa-aaaaa-aaaaa-aaaaa-aaa
18 | // - It is recommended to configure style-src, style-src-elem and font-src directives with the resources your canister is going to use
19 | // instead of using the wild card (*) option. Normally this will include 'self' but also other third party styles or fonts resources (e.g: https://fonts.googleapis.com or other CDNs)
20 |
21 | // Notes about the CSP below:
22 | // - script-src 'unsafe-eval' is currently required because agent-js uses a WebAssembly module for the validation of bls signatures.
23 | // There is currently no other way to allow execution of WebAssembly modules with CSP.
24 | // See: https://github.com/WebAssembly/content-security-policy/blob/main/proposals/CSP.md.
25 | // - We added img-src data: because data: images are used often.
26 | // - frame-ancestors: none mitigates clickjacking attacks. See https://owasp.org/www-community/attacks/Clickjacking.
27 | "Content-Security-Policy": "default-src 'self';script-src 'self' 'unsafe-eval';connect-src 'self' https://ic0.app https://*.ic0.app;img-src 'self' data:;style-src * 'unsafe-inline';style-src-elem * 'unsafe-inline';font-src *;object-src 'none';base-uri 'self';frame-ancestors 'none';form-action 'self';upgrade-insecure-requests;",
28 |
29 | // Security: The permissions policy disables all features for security reasons. If your site needs such permissions, activate them.
30 | // To configure permissions go here https://www.permissionspolicy.com/
31 | "Permissions-Policy": "accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), window-placement=(), vertical-scroll=()",
32 |
33 | // Security: Mitigates clickjacking attacks.
34 | // See: https://owasp.org/www-community/attacks/Clickjacking.
35 | "X-Frame-Options": "DENY",
36 |
37 | // Security: Avoids forwarding referrer information to other origins.
38 | // See: https://owasp.org/www-project-secure-headers/#referrer-policy.
39 | "Referrer-Policy": "same-origin",
40 |
41 | // Security: Tells the user’s browser that it must always use HTTPS with your site.
42 | // See: https://owasp.org/www-project-secure-headers/#http-strict-transport-security
43 | "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
44 |
45 | // Security: Prevents the browser from interpreting files as a different MIME type to what is specified in the Content-Type header.
46 | // See: https://owasp.org/www-project-secure-headers/#x-content-type-options
47 | "X-Content-Type-Options": "nosniff",
48 |
49 | // Security: Enables browser features to mitigate some of the XSS attacks. Note that it has to be in mode=block.
50 | // See: https://owasp.org/www-community/attacks/xss/
51 | "X-XSS-Protection": "1; mode=block"
52 | },
53 | // redirect all requests from .raw.ic0.app to .ic0.app (this redirection is the default)
54 | "allow_raw_access": false
55 | },
56 | ]
57 |
--------------------------------------------------------------------------------
/batch-transfer-tool/src/batch_transfer_tool_frontend/src/.ic-assets.json5:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "match": "**/*",
4 | "headers": {
5 | // Security: The Content Security Policy (CSP) given below aims at working with many apps rather than providing maximal security.
6 | // We recommend tightening the CSP for your specific application. Some recommendations are as follows:
7 | // - Use the CSP Evaluator (https://csp-evaluator.withgoogle.com/) to validate the CSP you define.
8 | // - Follow the “Strict CSP” recommendations (https://csp.withgoogle.com/docs/strict-csp.html). However, note that in the context of the IC,
9 | // nonces cannot be used because the response bodies must be static to work well with HTTP asset certification.
10 | // Thus, we recommend to include script hashes (in combination with strict-dynamic) in the CSP as described
11 | // in https://csp.withgoogle.com/docs/faq.html in section “What if my site is static and I can't add nonces to scripts?”.
12 | // See for example the II CSP (https://github.com/dfinity/internet-identity/blob/main/src/internet_identity/src/http.rs).
13 | // - It is recommended to tighten the connect-src directive. With the current CSP configuration the browser can
14 | // make requests to https://*.ic0.app, hence being able to call any canister via https://ic0.app/api/v2/canister/{canister-ID}.
15 | // This could potentially be used in combination with another vulnerability (e.g. XSS) to exfiltrate private data.
16 | // The developer can configure this policy to only allow requests to their specific canisters,
17 | // e.g: connect-src 'self' https://ic0.app/api/v2/canister/{my-canister-ID}, where {my-canister-ID} has the following format: aaaaa-aaaaa-aaaaa-aaaaa-aaa
18 | // - It is recommended to configure style-src, style-src-elem and font-src directives with the resources your canister is going to use
19 | // instead of using the wild card (*) option. Normally this will include 'self' but also other third party styles or fonts resources (e.g: https://fonts.googleapis.com or other CDNs)
20 |
21 | // Notes about the CSP below:
22 | // - script-src 'unsafe-eval' is currently required because agent-js uses a WebAssembly module for the validation of bls signatures.
23 | // There is currently no other way to allow execution of WebAssembly modules with CSP.
24 | // See: https://github.com/WebAssembly/content-security-policy/blob/main/proposals/CSP.md.
25 | // - We added img-src data: because data: images are used often.
26 | // - frame-ancestors: none mitigates clickjacking attacks. See https://owasp.org/www-community/attacks/Clickjacking.
27 | "Content-Security-Policy": "default-src 'self';script-src 'self' 'unsafe-eval';connect-src 'self' https://ic0.app https://*.ic0.app;img-src 'self' data:;style-src * 'unsafe-inline';style-src-elem * 'unsafe-inline';font-src *;object-src 'none';base-uri 'self';frame-ancestors 'none';form-action 'self';upgrade-insecure-requests;",
28 |
29 | // Security: The permissions policy disables all features for security reasons. If your site needs such permissions, activate them.
30 | // To configure permissions go here https://www.permissionspolicy.com/
31 | "Permissions-Policy": "accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), window-placement=(), vertical-scroll=()",
32 |
33 | // Security: Mitigates clickjacking attacks.
34 | // See: https://owasp.org/www-community/attacks/Clickjacking.
35 | "X-Frame-Options": "DENY",
36 |
37 | // Security: Avoids forwarding referrer information to other origins.
38 | // See: https://owasp.org/www-project-secure-headers/#referrer-policy.
39 | "Referrer-Policy": "same-origin",
40 |
41 | // Security: Tells the user’s browser that it must always use HTTPS with your site.
42 | // See: https://owasp.org/www-project-secure-headers/#http-strict-transport-security
43 | "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
44 |
45 | // Security: Prevents the browser from interpreting files as a different MIME type to what is specified in the Content-Type header.
46 | // See: https://owasp.org/www-project-secure-headers/#x-content-type-options
47 | "X-Content-Type-Options": "nosniff",
48 |
49 | // Security: Enables browser features to mitigate some of the XSS attacks. Note that it has to be in mode=block.
50 | // See: https://owasp.org/www-community/attacks/xss/
51 | "X-XSS-Protection": "1; mode=block"
52 | },
53 | // redirect all requests from .raw.ic0.app to .ic0.app (this redirection is the default)
54 | "allow_raw_access": false
55 | },
56 | ]
57 |
--------------------------------------------------------------------------------
/batch-transfer-tool/src/batch_transfer_tool_frontend/assets/.ic-assets.json5:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "match": "**/*",
4 | "headers": {
5 | // Security: The Content Security Policy (CSP) given below aims at working with many apps rather than providing maximal security.
6 | // We recommend tightening the CSP for your specific application. Some recommendations are as follows:
7 | // - Use the CSP Evaluator (https://csp-evaluator.withgoogle.com/) to validate the CSP you define.
8 | // - Follow the “Strict CSP” recommendations (https://csp.withgoogle.com/docs/strict-csp.html). However, note that in the context of the IC,
9 | // nonces cannot be used because the response bodies must be static to work well with HTTP asset certification.
10 | // Thus, we recommend to include script hashes (in combination with strict-dynamic) in the CSP as described
11 | // in https://csp.withgoogle.com/docs/faq.html in section “What if my site is static and I can't add nonces to scripts?”.
12 | // See for example the II CSP (https://github.com/dfinity/internet-identity/blob/main/src/internet_identity/src/http.rs).
13 | // - It is recommended to tighten the connect-src directive. With the current CSP configuration the browser can
14 | // make requests to https://*.ic0.app, hence being able to call any canister via https://ic0.app/api/v2/canister/{canister-ID}.
15 | // This could potentially be used in combination with another vulnerability (e.g. XSS) to exfiltrate private data.
16 | // The developer can configure this policy to only allow requests to their specific canisters,
17 | // e.g: connect-src 'self' https://ic0.app/api/v2/canister/{my-canister-ID}, where {my-canister-ID} has the following format: aaaaa-aaaaa-aaaaa-aaaaa-aaa
18 | // - It is recommended to configure style-src, style-src-elem and font-src directives with the resources your canister is going to use
19 | // instead of using the wild card (*) option. Normally this will include 'self' but also other third party styles or fonts resources (e.g: https://fonts.googleapis.com or other CDNs)
20 |
21 | // Notes about the CSP below:
22 | // - script-src 'unsafe-eval' is currently required because agent-js uses a WebAssembly module for the validation of bls signatures.
23 | // There is currently no other way to allow execution of WebAssembly modules with CSP.
24 | // See: https://github.com/WebAssembly/content-security-policy/blob/main/proposals/CSP.md.
25 | // - We added img-src data: because data: images are used often.
26 | // - frame-ancestors: none mitigates clickjacking attacks. See https://owasp.org/www-community/attacks/Clickjacking.
27 | "Content-Security-Policy": "default-src 'self';script-src 'self' 'unsafe-eval';connect-src 'self' https://ic0.app https://*.ic0.app;img-src 'self' data:;style-src * 'unsafe-inline';style-src-elem * 'unsafe-inline';font-src *;object-src 'none';base-uri 'self';frame-ancestors 'none';form-action 'self';upgrade-insecure-requests;",
28 |
29 | // Security: The permissions policy disables all features for security reasons. If your site needs such permissions, activate them.
30 | // To configure permissions go here https://www.permissionspolicy.com/
31 | "Permissions-Policy": "accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), window-placement=(), vertical-scroll=()",
32 |
33 | // Security: Mitigates clickjacking attacks.
34 | // See: https://owasp.org/www-community/attacks/Clickjacking.
35 | "X-Frame-Options": "DENY",
36 |
37 | // Security: Avoids forwarding referrer information to other origins.
38 | // See: https://owasp.org/www-project-secure-headers/#referrer-policy.
39 | "Referrer-Policy": "same-origin",
40 |
41 | // Security: Tells the user’s browser that it must always use HTTPS with your site.
42 | // See: https://owasp.org/www-project-secure-headers/#http-strict-transport-security
43 | "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
44 |
45 | // Security: Prevents the browser from interpreting files as a different MIME type to what is specified in the Content-Type header.
46 | // See: https://owasp.org/www-project-secure-headers/#x-content-type-options
47 | "X-Content-Type-Options": "nosniff",
48 |
49 | // Security: Enables browser features to mitigate some of the XSS attacks. Note that it has to be in mode=block.
50 | // See: https://owasp.org/www-community/attacks/xss/
51 | "X-XSS-Protection": "1; mode=block"
52 | },
53 | // redirect all requests from .raw.ic0.app to .ic0.app (this redirection is the default)
54 | "allow_raw_access": false
55 | },
56 | ]
57 |
--------------------------------------------------------------------------------
/sns-metrics/src/metrics_frontend/src/.ic-assets.json5:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "match": "**/*",
4 | "headers": {
5 | // Security: The Content Security Policy (CSP) given below aims at working with many apps rather than providing maximal security.
6 | // We recommend tightening the CSP for your specific application. Some recommendations are as follows:
7 | // - Use the CSP Evaluator (https://csp-evaluator.withgoogle.com/) to validate the CSP you define.
8 | // - Follow the “Strict CSP” recommendations (https://csp.withgoogle.com/docs/strict-csp.html). However, note that in the context of the IC,
9 | // nonces cannot be used because the response bodies must be static to work well with HTTP asset certification.
10 | // Thus, we recommend to include script hashes (in combination with strict-dynamic) in the CSP as described
11 | // in https://csp.withgoogle.com/docs/faq.html in section “What if my site is static and I can't add nonces to scripts?”.
12 | // See for example the II CSP (https://github.com/dfinity/internet-identity/blob/main/src/internet_identity/src/http.rs).
13 | // - It is recommended to tighten the connect-src directive. With the current CSP configuration the browser can
14 | // make requests to https://*.icp0.io, hence being able to call any canister via https://icp0.io/api/v2/canister/{canister-ID}.
15 | // This could potentially be used in combination with another vulnerability (e.g. XSS) to exfiltrate private data.
16 | // The developer can configure this policy to only allow requests to their specific canisters,
17 | // e.g: connect-src 'self' https://icp-api.io/api/v2/canister/{my-canister-ID}, where {my-canister-ID} has the following format: aaaaa-aaaaa-aaaaa-aaaaa-aaa
18 | // - It is recommended to configure style-src, style-src-elem and font-src directives with the resources your canister is going to use
19 | // instead of using the wild card (*) option. Normally this will include 'self' but also other third party styles or fonts resources (e.g: https://fonts.googleapis.com or other CDNs)
20 |
21 | // Notes about the CSP below:
22 | // - script-src 'unsafe-eval' is currently required because agent-js uses a WebAssembly module for the validation of bls signatures.
23 | // There is currently no other way to allow execution of WebAssembly modules with CSP.
24 | // See: https://github.com/WebAssembly/content-security-policy/blob/main/proposals/CSP.md.
25 | // - We added img-src data: because data: images are used often.
26 | // - frame-ancestors: none mitigates clickjacking attacks. See https://owasp.org/www-community/attacks/Clickjacking.
27 | "Content-Security-Policy": "default-src 'self';script-src 'self' 'unsafe-eval';connect-src 'self' https://icp0.io https://*.icp0.io https://icp-api.io;img-src 'self' data:;style-src * 'unsafe-inline';style-src-elem * 'unsafe-inline';font-src *;object-src 'none';base-uri 'self';frame-ancestors 'none';form-action 'self';upgrade-insecure-requests;",
28 |
29 | // Security: The permissions policy disables all features for security reasons. If your site needs such permissions, activate them.
30 | // To configure permissions go here https://www.permissionspolicy.com/
31 | "Permissions-Policy": "accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), window-placement=(), vertical-scroll=()",
32 |
33 | // Security: Mitigates clickjacking attacks.
34 | // See: https://owasp.org/www-community/attacks/Clickjacking.
35 | "X-Frame-Options": "DENY",
36 |
37 | // Security: Avoids forwarding referrer information to other origins.
38 | // See: https://owasp.org/www-project-secure-headers/#referrer-policy.
39 | "Referrer-Policy": "same-origin",
40 |
41 | // Security: Tells the user’s browser that it must always use HTTPS with your site.
42 | // See: https://owasp.org/www-project-secure-headers/#http-strict-transport-security
43 | "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
44 |
45 | // Security: Prevents the browser from interpreting files as a different MIME type to what is specified in the Content-Type header.
46 | // See: https://owasp.org/www-project-secure-headers/#x-content-type-options
47 | "X-Content-Type-Options": "nosniff",
48 |
49 | // Security: Enables browser features to mitigate some of the XSS attacks. Note that it has to be in mode=block.
50 | // See: https://owasp.org/www-community/attacks/xss/
51 | "X-XSS-Protection": "1; mode=block"
52 | },
53 | // Set the allow_raw_access field to false to redirect all requests from .raw.icp0.io to .icp0.io
54 | // The default behavior is to allow raw access.
55 | // "allow_raw_access": true
56 | },
57 | ]
58 |
--------------------------------------------------------------------------------