create-leo-app 0.7.2 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +3 -3
  2. package/dist/index.mjs +38 -38
  3. package/package.json +14 -8
  4. package/template-extension/README.md +4 -0
  5. package/template-extension/package.json +15 -0
  6. package/template-extension/rollup.config.js +21 -0
  7. package/template-extension/src/offscreen.js +1 -0
  8. package/template-extension/src/service_worker.js +20 -0
  9. package/template-extension/src/worker.js +34 -0
  10. package/template-extension/static/manifest.json +16 -0
  11. package/template-extension/static/offscreen.html +9 -0
  12. package/template-nextjs-ts/README.md +19 -0
  13. package/template-nextjs-ts/_gitignore +35 -0
  14. package/template-nextjs-ts/next-env.d.ts +5 -0
  15. package/template-nextjs-ts/next.config.js +32 -0
  16. package/template-nextjs-ts/package.json +24 -0
  17. package/template-nextjs-ts/public/aleo.svg +8 -0
  18. package/template-nextjs-ts/public/next.svg +1 -0
  19. package/template-nextjs-ts/src/app/favicon.ico +0 -0
  20. package/template-nextjs-ts/src/app/globals.css +126 -0
  21. package/template-nextjs-ts/src/app/layout.tsx +22 -0
  22. package/template-nextjs-ts/src/app/page.module.css +160 -0
  23. package/template-nextjs-ts/src/app/page.tsx +94 -0
  24. package/template-nextjs-ts/src/app/worker.ts +47 -0
  25. package/template-nextjs-ts/tsconfig.json +27 -0
  26. package/template-node/README.md +5 -0
  27. package/template-node/_gitignore +24 -0
  28. package/template-node/package.json +12 -0
  29. package/template-node-ts/README.md +5 -0
  30. package/template-node-ts/_gitignore +24 -0
  31. package/template-node-ts/package.json +19 -0
  32. package/template-node-ts/rollup.config.js +19 -0
  33. package/template-node-ts/src/index.ts +65 -0
  34. package/template-node-ts/tsconfig.json +15 -0
  35. package/template-offline-public-transaction-ts/README.md +52 -0
  36. package/template-offline-public-transaction-ts/_gitignore +24 -0
  37. package/template-offline-public-transaction-ts/package.json +19 -0
  38. package/template-offline-public-transaction-ts/rollup.config.js +19 -0
  39. package/template-offline-public-transaction-ts/src/helpers.ts +70 -0
  40. package/template-offline-public-transaction-ts/src/index.ts +171 -0
  41. package/template-offline-public-transaction-ts/tsconfig.json +15 -0
  42. package/template-react-leo/.babelrc +6 -0
  43. package/template-react-leo/.eslintrc.cjs +20 -0
  44. package/template-react-leo/README.md +85 -0
  45. package/template-react-leo/_gitignore +24 -0
  46. package/template-react-leo/_headers +3 -0
  47. package/template-react-leo/helloworld/.env.example +2 -0
  48. package/template-react-leo/helloworld/README.md +13 -0
  49. package/template-react-leo/helloworld/build/main.aleo +7 -0
  50. package/template-react-leo/helloworld/build/program.json +6 -0
  51. package/template-react-leo/helloworld/inputs/helloworld.in +4 -0
  52. package/template-react-leo/helloworld/program.json +6 -0
  53. package/template-react-leo/helloworld/src/main.leo +7 -0
  54. package/template-react-leo/index.html +88 -0
  55. package/template-react-leo/install.sh +30 -0
  56. package/template-react-leo/package.json +44 -0
  57. package/template-react-leo/public/favicon.ico +0 -0
  58. package/template-react-leo/src/App.css +42 -0
  59. package/template-react-leo/src/App.jsx +103 -0
  60. package/template-react-leo/src/assets/aleo.svg +5 -0
  61. package/template-react-leo/src/assets/react.svg +1 -0
  62. package/template-react-leo/src/index.css +69 -0
  63. package/template-react-leo/src/main.jsx +10 -0
  64. package/template-react-leo/src/workers/AleoWorker.js +20 -0
  65. package/template-react-leo/src/workers/worker.js +72 -0
  66. package/template-react-leo/vite.config.js +17 -0
  67. package/template-react-leo/webpack.config.js +102 -0
  68. package/template-react-managed-worker/.babelrc +6 -0
  69. package/template-react-managed-worker/.eslintrc.cjs +20 -0
  70. package/template-react-managed-worker/README.md +6 -0
  71. package/template-react-managed-worker/_gitignore +24 -0
  72. package/template-react-managed-worker/index.html +88 -0
  73. package/template-react-managed-worker/package.json +41 -0
  74. package/template-react-managed-worker/public/favicon.ico +0 -0
  75. package/template-react-managed-worker/src/App.css +42 -0
  76. package/template-react-managed-worker/src/App.jsx +78 -0
  77. package/template-react-managed-worker/src/assets/aleo.png +0 -0
  78. package/template-react-managed-worker/src/assets/react.svg +1 -0
  79. package/template-react-managed-worker/src/index.css +69 -0
  80. package/template-react-managed-worker/src/main.jsx +10 -0
  81. package/template-react-managed-worker/vite.config.js +21 -0
  82. package/template-react-managed-worker/webpack.config.js +90 -0
  83. package/template-react-ts/.babelrc +7 -0
  84. package/template-react-ts/.eslintrc.cjs +20 -0
  85. package/template-react-ts/README.md +85 -0
  86. package/template-react-ts/_gitignore +24 -0
  87. package/template-react-ts/_headers +3 -0
  88. package/template-react-ts/helloworld/.env.example +2 -0
  89. package/template-react-ts/helloworld/README.md +13 -0
  90. package/template-react-ts/helloworld/build/main.aleo +7 -0
  91. package/template-react-ts/helloworld/build/program.json +6 -0
  92. package/template-react-ts/helloworld/inputs/helloworld.in +4 -0
  93. package/template-react-ts/helloworld/program.json +6 -0
  94. package/template-react-ts/helloworld/src/main.leo +7 -0
  95. package/template-react-ts/index.html +88 -0
  96. package/template-react-ts/install.sh +30 -0
  97. package/template-react-ts/package.json +49 -0
  98. package/template-react-ts/public/favicon.ico +0 -0
  99. package/template-react-ts/src/App.css +42 -0
  100. package/template-react-ts/src/App.tsx +103 -0
  101. package/template-react-ts/src/assets/aleo.svg +5 -0
  102. package/template-react-ts/src/assets/react.svg +1 -0
  103. package/template-react-ts/src/custom.d.ts +16 -0
  104. package/template-react-ts/src/index.css +69 -0
  105. package/template-react-ts/src/main.tsx +10 -0
  106. package/template-react-ts/src/workers/AleoWorker.ts +21 -0
  107. package/template-react-ts/src/workers/worker.ts +73 -0
  108. package/template-react-ts/tsconfig.json +16 -0
  109. package/template-react-ts/vite.config.ts +17 -0
  110. package/template-react-ts/webpack.config.ts +112 -0
  111. package/template-vanilla/_gitignore +24 -0
  112. package/template-vanilla/_headers +3 -0
  113. package/template-vanilla/index.html +13 -0
  114. package/template-vanilla/javascript.svg +1 -0
  115. package/template-vanilla/main.js +48 -0
  116. package/template-vanilla/package.json +16 -0
  117. package/template-vanilla/public/aleo.svg +76 -0
  118. package/template-vanilla/public/vite.svg +1 -0
  119. package/template-vanilla/style.css +97 -0
  120. package/template-vanilla/vite.config.js +14 -0
  121. package/template-vanilla/worker.js +95 -0
@@ -0,0 +1,24 @@
1
+ # Logs
2
+ logs
3
+ *.log
4
+ npm-debug.log*
5
+ yarn-debug.log*
6
+ yarn-error.log*
7
+ pnpm-debug.log*
8
+ lerna-debug.log*
9
+
10
+ node_modules
11
+ dist
12
+ dist-ssr
13
+ *.local
14
+
15
+ # Editor directories and files
16
+ .vscode/*
17
+ !.vscode/extensions.json
18
+ .idea
19
+ .DS_Store
20
+ *.suo
21
+ *.ntvs*
22
+ *.njsproj
23
+ *.sln
24
+ *.sw?
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "node-ts-starter",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "build": "rimraf dist/js && rollup --config",
8
+ "dev": "npm run build && node dist/index.js"
9
+ },
10
+ "dependencies": {
11
+ "@provablehq/sdk": "^0.8.0"
12
+ },
13
+ "devDependencies": {
14
+ "rimraf": "^6.0.1",
15
+ "rollup": "^4.32.0",
16
+ "rollup-plugin-typescript2": "^0.36.0",
17
+ "typescript": "^5.7.3"
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ import typescript from "rollup-plugin-typescript2";
2
+
3
+ export default {
4
+ input: {
5
+ index: "./src/index.ts",
6
+ },
7
+ output: {
8
+ dir: `dist`,
9
+ format: "es",
10
+ sourcemap: true,
11
+ },
12
+ external: ['@provablehq/sdk'],
13
+ plugins: [
14
+ typescript({
15
+ tsconfig: "tsconfig.json",
16
+ clean: true,
17
+ }),
18
+ ],
19
+ };
@@ -0,0 +1,65 @@
1
+ import {Account, initThreadPool, ProgramManager, AleoKeyProvider, AleoKeyProviderParams} from "@provablehq/sdk";
2
+
3
+ await initThreadPool();
4
+
5
+ const programName = "hello_hello.aleo"
6
+
7
+ const hello_hello_program =`
8
+ program ${programName};
9
+
10
+ function hello:
11
+ input r0 as u32.public;
12
+ input r1 as u32.private;
13
+ add r0 r1 into r2;
14
+ output r2 as u32.private;`
15
+
16
+ async function localProgramExecution(program, programName, aleoFunction, inputs) {
17
+ const programManager = new ProgramManager();
18
+
19
+ // Create a temporary account for the execution of the program
20
+ const account = new Account();
21
+ programManager.setAccount(account);
22
+
23
+ // Create a key provider in order to re-use the same key for each execution
24
+ const keyProvider = new AleoKeyProvider();
25
+ keyProvider.useCache(true);
26
+ programManager.setKeyProvider(keyProvider);
27
+
28
+ // Pre-synthesize the program keys and then cache them in memory using key provider
29
+ try {
30
+ const keyPair = await programManager.synthesizeKeys(hello_hello_program, aleoFunction, inputs);
31
+
32
+ programManager.keyProvider.cacheKeys(`${programName}:${aleoFunction}`, keyPair);
33
+
34
+ } catch (e) {
35
+ throw new Error(`Failed to synthesize keys: ${e.message}`);
36
+ }
37
+
38
+ // Specify parameters for the key provider to use search for program keys. In particular specify the cache key
39
+ // that was used to cache the keys in the previous step.
40
+ const keyProviderParams = new AleoKeyProviderParams({cacheKey: `${programName}:${aleoFunction}`});
41
+
42
+ // Execute once using the key provider params defined above. This will use the cached proving keys and make
43
+ // execution significantly faster.
44
+ let executionResponse = await programManager.run(
45
+ program,
46
+ aleoFunction,
47
+ inputs,
48
+ true,
49
+ undefined,
50
+ keyProviderParams,
51
+ );
52
+ console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());
53
+
54
+ // Verify the execution using the verifying key that was generated earlier.
55
+ if (programManager.verifyExecution(executionResponse)) {
56
+ console.log("hello_hello/hello execution verified!");
57
+ } else {
58
+ throw("Execution failed verification!");
59
+ }
60
+ }
61
+
62
+ const start = Date.now();
63
+ console.log("Starting execute!");
64
+ await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]);
65
+ console.log("Execute finished!", Date.now() - start);
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Basic Options */
4
+ "target": "es2017",
5
+ "module": "esnext",
6
+
7
+ /* Module Resolution Options */
8
+ "moduleResolution": "node",
9
+ "esModuleInterop": true,
10
+
11
+ /* Advanced Options */
12
+ "skipLibCheck": true,
13
+ "forceConsistentCasingInFileNames": true
14
+ }
15
+ }
@@ -0,0 +1,52 @@
1
+ # Offline Transaction Builder
2
+
3
+ ## 1. Overview
4
+ ### 1.1 Proving Keys for Zero Knowledge Function Execution
5
+ To achieve zero knowledge execution, all Aleo functions require a `ProvingKey` and `VerifyingKey` in order to build a
6
+ zero knowledge ZkSnark proof of execution. If a user does not possess these keys for a function, they are normally
7
+ downloaded from the internet when the function is called.
8
+
9
+ ### 1.2 Key Providers
10
+ They `KeyProvider` interface is designed to allow users to provide their own implementations for providing key material
11
+ to Aleo function executions.
12
+
13
+ ### 1.3 Building Transactions Offline
14
+
15
+ The `OfflineKeyProvider` enables Transaction Building without connection to the internet.
16
+
17
+ The `OfflineKeyProvider` and `OfflineSearchParams` are concrete implementations of the `KeyProvider` and `KeySearchParams`
18
+ interfaces. They are designed to fetch proving key material for Aleo functions from a local machine instead of contacting
19
+ the internet for it. This provides a way to build Aleo execution transactions without being connected to the internet.
20
+
21
+ This pathway is suitable for use-cases such as hardware wallets or air-gapped machines used
22
+ for building secure transactions.
23
+
24
+ ### 1.4 Assumptions
25
+
26
+ The key material in this example is assumed to be pre-downloaded onto the machine performing the
27
+ construction of the offline transaction.
28
+
29
+ ## 2. Usage
30
+
31
+ ### 2.1 Pre-Download the Keys
32
+ First run this command online to download the key material to disk:
33
+
34
+ `npm start`
35
+
36
+ Once this command is run, all proving keys for the `transfer_public`, `bond_public`, `unbond_public`, and
37
+ `claim_unbond_public` functions will be downloaded to the `./keys` folder. The machine can then be disconnected from
38
+ the internet and the `OfflineKeyProvider` will search this directory for the function proving keys when building the
39
+ transaction instead of connecting to the internet. Alternatively you can skip the online step entirely by adding the proving key creating this directory manually and
40
+ adding the key material yourself.
41
+
42
+ ### 2.2 Build the Transaction Offline
43
+
44
+ Once the key material is downloaded, turn off your internet connection and run the following command:
45
+
46
+ `npm start`
47
+
48
+ You should see the transactions being built and the resulting transaction IDs printed to the console.
49
+
50
+ ## 3. Notes
51
+
52
+ Node.js 20+ is recommended for best performance.
@@ -0,0 +1,24 @@
1
+ # Logs
2
+ logs
3
+ *.log
4
+ npm-debug.log*
5
+ yarn-debug.log*
6
+ yarn-error.log*
7
+ pnpm-debug.log*
8
+ lerna-debug.log*
9
+
10
+ node_modules
11
+ dist
12
+ dist-ssr
13
+ *.local
14
+
15
+ # Editor directories and files
16
+ .vscode/*
17
+ !.vscode/extensions.json
18
+ .idea
19
+ .DS_Store
20
+ *.suo
21
+ *.ntvs*
22
+ *.njsproj
23
+ *.sln
24
+ *.sw?
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "node-offline-transaction-example",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "build": "rimraf dist/js && rollup --config",
8
+ "dev": "npm run build && node dist/index.js"
9
+ },
10
+ "dependencies": {
11
+ "@provablehq/sdk": "^0.8.0"
12
+ },
13
+ "devDependencies": {
14
+ "rimraf": "^6.0.1",
15
+ "rollup": "^4.32.0",
16
+ "rollup-plugin-typescript2": "^0.36.0",
17
+ "typescript": "^5.7.3"
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ import typescript from "rollup-plugin-typescript2";
2
+
3
+ export default {
4
+ input: {
5
+ index: "./src/index.ts",
6
+ },
7
+ output: {
8
+ dir: `dist`,
9
+ format: "es",
10
+ sourcemap: true,
11
+ },
12
+ external: ['@provablehq/sdk'],
13
+ plugins: [
14
+ typescript({
15
+ tsconfig: "tsconfig.json",
16
+ clean: true,
17
+ }),
18
+ ],
19
+ };
@@ -0,0 +1,70 @@
1
+ import { CREDITS_PROGRAM_KEYS } from "@provablehq/sdk";
2
+ import { promises as fsPromises, writeFileSync } from "fs";
3
+ import path from "path";
4
+ import { fileURLToPath } from "url";
5
+
6
+ async function downloadAndSaveKey(keyData, keysDirPath) {
7
+ const locatorParts = keyData.locator.split('/');
8
+ const fileName = locatorParts.pop();
9
+ const dirPath = path.join(keysDirPath, ...locatorParts);
10
+ await fsPromises.mkdir(dirPath, { recursive: true });
11
+ const filePath = path.join(dirPath, `${fileName}.prover`);
12
+
13
+ try {
14
+ await fsPromises.access(filePath);
15
+ return filePath;
16
+ } catch {
17
+ const res = await fetch(keyData.prover);
18
+ const buffer = await res.arrayBuffer();
19
+ writeFileSync(filePath, new Uint8Array(buffer), { flag: 'wx' });
20
+ console.log(`Downloaded ${keyData.locator}.prover to ${filePath}`);
21
+ return filePath;
22
+ }
23
+ }
24
+
25
+ async function preDownloadTransferKeys() {
26
+ const keyPaths = {};
27
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
28
+ const keysDirPath = path.join(__dirname, "keys");
29
+ await fsPromises.mkdir(keysDirPath, { recursive: true });
30
+
31
+ for (const keyData of [CREDITS_PROGRAM_KEYS.transfer_public, CREDITS_PROGRAM_KEYS.fee_public]) {
32
+ try {
33
+ keyPaths[keyData.locator] = await downloadAndSaveKey(keyData, keysDirPath);
34
+ } catch (error) {
35
+ throw(`Failed to download ${keyData.locator} - ${error}`);
36
+ }
37
+ }
38
+
39
+ return keyPaths;
40
+ }
41
+
42
+ async function preDownloadBondingKeys() {
43
+ const keyPaths = {};
44
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
45
+ const keysDirPath = path.join(__dirname, "keys");
46
+ await fsPromises.mkdir(keysDirPath, { recursive: true });
47
+
48
+ for (const keyData of [CREDITS_PROGRAM_KEYS.bond_public, CREDITS_PROGRAM_KEYS.fee_public, CREDITS_PROGRAM_KEYS.unbond_public, CREDITS_PROGRAM_KEYS.claim_unbond_public]) {
49
+ try {
50
+ keyPaths[keyData.locator] = await downloadAndSaveKey(keyData, keysDirPath);
51
+ } catch (error) {
52
+ throw(`Failed to download ${keyData.locator} - ${error}`);
53
+ }
54
+ }
55
+
56
+ return keyPaths;
57
+ }
58
+
59
+ async function getLocalKey(filePath: string): Promise<Uint8Array> {
60
+ try {
61
+ console.log("Reading key file:", filePath);
62
+ const buffer = await fsPromises.readFile(filePath);
63
+ return new Uint8Array(buffer);
64
+ } catch (error) {
65
+ console.error("Error reading file:", error);
66
+ throw error;
67
+ }
68
+ }
69
+
70
+ export { downloadAndSaveKey, getLocalKey, preDownloadBondingKeys, preDownloadTransferKeys };
@@ -0,0 +1,171 @@
1
+ import {Account, Address, CREDITS_PROGRAM_KEYS, initThreadPool, ProgramManager, OfflineQuery, OfflineKeyProvider, OfflineSearchParams, ProvingKey, Transaction} from "@provablehq/sdk";
2
+ import { getLocalKey, preDownloadBondingKeys, preDownloadTransferKeys } from "./helpers";
3
+
4
+ await initThreadPool();
5
+
6
+ /// Build transfer public transaction without connection to the internet
7
+ async function buildTransferPublicTxOffline(recipientAddress: Address, amount: number, latestStateRoot: string, keyPaths: {}): Promise<Transaction> {
8
+ // Create an offline program manager
9
+ const programManager = new ProgramManager();
10
+
11
+ // Create a temporary account for the execution of the program
12
+ const account = new Account();
13
+ programManager.setAccount(account);
14
+
15
+ // Create the proving keys from the key bytes on the offline machine
16
+ console.log("Creating proving keys from local key files");
17
+ const feePublicKeyBytes = await getLocalKey(<string>keyPaths[CREDITS_PROGRAM_KEYS.fee_public.locator]);
18
+ const transferPublicAsSignerKeyBytes = await getLocalKey(<string>keyPaths[CREDITS_PROGRAM_KEYS.transfer_public_as_signer.locator]);
19
+ const feePublicProvingKey = ProvingKey.fromBytes(feePublicKeyBytes);
20
+ const transferPublicProvingKey = ProvingKey.fromBytes(transferPublicAsSignerKeyBytes);
21
+
22
+ // Create an offline key provider
23
+ console.log("Creating offline key provider");
24
+ const offlineKeyProvider = new OfflineKeyProvider();
25
+
26
+ // Insert the proving keys into the offline key provider. The key provider will automatically insert the verifying
27
+ // keys into the key manager.
28
+ console.log("Inserting proving keys into key provider");
29
+ offlineKeyProvider.insertFeePublicKeys(feePublicProvingKey);
30
+ offlineKeyProvider.insertTransferPublicKeys(transferPublicProvingKey);
31
+
32
+ // Create an offline query to complete the inclusion proof
33
+ const offlineQuery = new OfflineQuery(latestStateRoot);
34
+
35
+ // Insert the key provider into the program manager
36
+ programManager.setKeyProvider(offlineKeyProvider);
37
+
38
+ // Build tne transfer_public transaction offline
39
+ console.log("Building transfer transaction offline");
40
+ return programManager.buildTransferPublicAsSignerTransaction(
41
+ amount,
42
+ recipientAddress.to_string(),
43
+ 0.28,
44
+ undefined,
45
+ offlineQuery,
46
+ );
47
+ }
48
+
49
+ /// Build bonding and unbonding transactions without connection to the internet
50
+ async function buildBondingTxOffline(stakerAddress: Address, validatorAddress: Address, withdrawalAddress: Address, amount: number, latestStateRoot: string, keyPaths: {}): Promise<Transaction[]> {
51
+ // Create an offline program manager
52
+ const programManager = new ProgramManager();
53
+
54
+ // Create a temporary account for the execution of the program
55
+ const account = new Account();
56
+ programManager.setAccount(account);
57
+
58
+ // Create the proving keys from the key bytes on the offline machine
59
+ console.log("Creating proving keys from local key files");
60
+ const feePublicKeyBytes = await getLocalKey(<string>keyPaths[CREDITS_PROGRAM_KEYS.fee_public.locator]);
61
+ const bondPublicKeyBytes = await getLocalKey(<string>keyPaths[CREDITS_PROGRAM_KEYS.bond_public.locator]);
62
+ const unbondPublicKeyBytes = await getLocalKey(<string>keyPaths[CREDITS_PROGRAM_KEYS.unbond_public.locator]);
63
+ const claimUnbondPublicKeyBytes = await getLocalKey(<string>keyPaths[CREDITS_PROGRAM_KEYS.claim_unbond_public.locator]);
64
+ const feePublicProvingKey = ProvingKey.fromBytes(feePublicKeyBytes);
65
+ const bondPublicProvingKey = ProvingKey.fromBytes(bondPublicKeyBytes);
66
+ const unBondPublicProvingKey = ProvingKey.fromBytes(unbondPublicKeyBytes);
67
+ const claimUnbondPublicProvingKey = ProvingKey.fromBytes(claimUnbondPublicKeyBytes);
68
+
69
+ // Create an offline key provider to fetch keys without connection to the internet
70
+ console.log("Creating offline key provider");
71
+ const offlineKeyProvider = new OfflineKeyProvider();
72
+
73
+ // Insert the proving keys into the offline key provider. The key provider will automatically insert the verifying
74
+ // keys into the key manager.
75
+ console.log("Inserting proving keys into key provider");
76
+ offlineKeyProvider.insertFeePublicKeys(feePublicProvingKey);
77
+ offlineKeyProvider.insertBondPublicKeys(bondPublicProvingKey);
78
+ offlineKeyProvider.insertUnbondPublicKeys(unBondPublicProvingKey);
79
+ offlineKeyProvider.insertClaimUnbondPublicKeys(claimUnbondPublicProvingKey);
80
+
81
+ // Insert the key provider into the program manager
82
+ programManager.setKeyProvider(offlineKeyProvider);
83
+
84
+ // Build the bonding transactions offline
85
+ console.log("Building a bond_public execution transaction offline");
86
+ const bondPublicOptions = {
87
+ executionParams: {
88
+ keySearchParams: OfflineSearchParams.bondPublicKeyParams()
89
+ },
90
+ offlineParams: {
91
+ offlineQuery: new OfflineQuery(latestStateRoot)
92
+ }
93
+ }
94
+
95
+ const bondTx = <Transaction>await programManager.buildBondPublicTransaction(
96
+ stakerAddress.to_string(),
97
+ validatorAddress.to_string(),
98
+ withdrawalAddress.to_string(),
99
+ amount,
100
+ bondPublicOptions,
101
+ )
102
+ console.log("\nbond_public transaction built!\n");
103
+
104
+ console.log("Building an unbond_public execution transaction offline")
105
+ const unbondPublicOptions = {
106
+ executionParams: {
107
+ keySearchParams: OfflineSearchParams.unbondPublicKeyParams()
108
+ },
109
+ offlineParams: {
110
+ offlineQuery: new OfflineQuery(latestStateRoot)
111
+ }
112
+ }
113
+
114
+ const unBondTx = <Transaction>await programManager.buildUnbondPublicTransaction(stakerAddress.to_string(), amount, unbondPublicOptions);
115
+ console.log("\nunbond_public transaction built!\n");
116
+
117
+ console.log("Building a claim_unbond_public transaction offline")
118
+ // Build the claim unbonding transaction offline
119
+ const claimUnbondPublicOptions = {
120
+ executionParams: {
121
+ keySearchParams: OfflineSearchParams.claimUnbondPublicKeyParams()
122
+ },
123
+ offlineParams: {
124
+ offlineQuery: new OfflineQuery(latestStateRoot)
125
+ }
126
+ }
127
+
128
+ const claimUnbondTx = <Transaction>await programManager.buildClaimUnbondPublicTransaction(stakerAddress.to_string(), claimUnbondPublicOptions);
129
+ console.log("\nclaim_unbond_public transaction built!\n");
130
+ return [bondTx, unBondTx, claimUnbondTx];
131
+ }
132
+
133
+ // -------------------ONLINE COMPONENT---------------------
134
+ // (Do this part on an internet connected machine)
135
+
136
+ // Download the needed keys for the functions we want to execute offline
137
+ const transferKeyPaths = await preDownloadTransferKeys();
138
+ const bondingKeyPaths = await preDownloadBondingKeys();
139
+ //---------------------------------------------------------
140
+
141
+ // ------------------OFFLINE COMPONENT---------------------
142
+ // (Do this part on an offline machine)
143
+ // Get the latest state root from an online machine and enter it into an offline machine
144
+ const latestStateRoot = "sr1p93gpsezrjzdhcd2wujznx5s07k8qa39t6vfcej35zew8vn2jyrs46te8q";
145
+
146
+ // Build a transfer_public transaction
147
+ const stakerAddress = new Account().address();
148
+ const validatorAddress = new Account().address();
149
+ const withdrawalAddress = new Account().address();
150
+ const transferTx = await buildTransferPublicTxOffline(stakerAddress, 10000, latestStateRoot, transferKeyPaths);
151
+ console.log("Transfer transaction built offline!");
152
+ console.log(`\n---------------transfer_public transaction---------------\n${transferTx}`);
153
+ console.log(`---------------------------------------------------------`);
154
+
155
+ // Build bonding & unbonding transactions
156
+ const bondTransactions = await buildBondingTxOffline(stakerAddress, validatorAddress, withdrawalAddress, 100, latestStateRoot, bondingKeyPaths);
157
+ console.log("Bonding transactions built offline!");
158
+ console.log(`\n-----------------bond_public transaction-----------------\n${bondTransactions[0]}`);
159
+ console.log(`---------------------------------------------------------`);
160
+ console.log(`\n----------------unbond_public transaction:---------------\n${bondTransactions[1]}`);
161
+ console.log(`---------------------------------------------------------`);
162
+ console.log(`\n-----------------claim_unbond transaction:---------------\n${bondTransactions[2]}`);
163
+ console.log(`---------------------------------------------------------`);
164
+ //---------------------------------------------------------
165
+
166
+ // -------------------ONLINE COMPONENT---------------------
167
+ // (Do this part on an internet connected machine)
168
+ // ONLINE COMPONENT (Uncomment this part to send the transaction to the Aleo Network on an internet connected machine)
169
+ // Submit the transaction to the network
170
+ // const transferTxId = await networkClient.submitTransaction(transferTx);
171
+ //---------------------------------------------------------
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Basic Options */
4
+ "target": "es2017",
5
+ "module": "esnext",
6
+
7
+ /* Module Resolution Options */
8
+ "moduleResolution": "node",
9
+ "esModuleInterop": true,
10
+
11
+ /* Advanced Options */
12
+ "skipLibCheck": true,
13
+ "forceConsistentCasingInFileNames": true
14
+ }
15
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "presets": [
3
+ "@babel/preset-env",
4
+ ["@babel/preset-react", { "runtime": "automatic" }]
5
+ ]
6
+ }
@@ -0,0 +1,20 @@
1
+ module.exports = {
2
+ root: true,
3
+ env: { browser: true, es2020: true },
4
+ extends: [
5
+ 'eslint:recommended',
6
+ 'plugin:react/recommended',
7
+ 'plugin:react/jsx-runtime',
8
+ 'plugin:react-hooks/recommended',
9
+ ],
10
+ ignorePatterns: ['dist', '.eslintrc.cjs'],
11
+ parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
12
+ settings: { react: { version: '18.2' } },
13
+ plugins: ['react-refresh'],
14
+ rules: {
15
+ 'react-refresh/only-export-components': [
16
+ 'warn',
17
+ { allowConstantExport: true },
18
+ ],
19
+ },
20
+ }
@@ -0,0 +1,85 @@
1
+ # React + Aleo + Leo
2
+
3
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/fork/github/ProvableHQ/sdk/tree/mainnet/create-leo-app/template-react-leo)
4
+
5
+ This template provides a minimal setup to get React and Aleo working in Webpack or Vite with HMR and some ESLint rules.
6
+
7
+ This template includes a Leo program that is loaded by the web app located in
8
+ the `helloworld` directory.
9
+
10
+ ### Start in development mode
11
+
12
+ ```bash
13
+ npm run dev
14
+ ```
15
+
16
+ Your app should be running on http://localhost:5173/
17
+
18
+ ### Build Leo program
19
+
20
+ 1. Copy the `helloworld/.env.example` to `helloworld/.env` (this will be ignored
21
+ by Git):
22
+
23
+ ```bash
24
+ cd helloworld
25
+ cp .env.example .env
26
+ ```
27
+
28
+ 2. Replace `PRIVATE_KEY=user1PrivateKey` in the `.env` with your own key (you
29
+ can use an existing one or generate your own at https://provable.tools/account)
30
+
31
+ 3. Follow instructions to install Leo here: https://github.com/ProvableHQ/leo
32
+
33
+ 4. You can edit `helloworld/src/main.leo` and run `leo run` to compile and update the
34
+ Aleo instructions under `build` which are loaded by the web app.
35
+
36
+ ## Deploy program from web app
37
+
38
+ > [!WARNING]
39
+ > This is for demonstration purposes or local testing only, in production applications you
40
+ > should avoid building a public facing web app with private key information
41
+
42
+ Information on generating a private key, seeding a wallet with funds, and finding a spendable record can be found here
43
+ if you are unfamiliar: https://docs.leo-lang.org/testnet/getting_started/deploy_execute_demo
44
+
45
+ Aleo programs deployed require unique names, make sure to edit the program's name to something unique in `helloworld/src/main.leo`, `helloworld/program.json`, rename `helloworld/inputs/helloworld.in` and rebuild.
46
+
47
+ 1. In the `worker.js` file modify the privateKey to be an account with available
48
+ funds
49
+
50
+ ```js
51
+ // Use existing account with funds
52
+ const account = new Account({
53
+ privateKey: "user1PrivateKey",
54
+ });
55
+ ```
56
+
57
+ 2. (Optional) Provide a fee record manually (located in commented code within `worker.js`)
58
+
59
+ If you do not provide a manual fee record, the SDK will attempt to scan for a record starting at the latest block. A simple way to speed this up would be to make a public transaction to this account right before deploying.
60
+
61
+ 3. Run the web app and hit the deploy button
62
+
63
+ ## Production deployment
64
+
65
+ ### Build
66
+
67
+ `npm run build`
68
+
69
+ Upload `dist` folder to your host of choice.
70
+
71
+ ### ⚠️ Header warnings
72
+
73
+ `DOMException: Failed to execute 'postMessage' on 'Worker': SharedArrayBuffer transfer requires self.crossOriginIsolated`
74
+
75
+ If you get a warning similar to this when deploying your application, you need
76
+ to make sure your web server is configured with the following headers:
77
+
78
+ ```
79
+ Cross-Origin-Opener-Policy: same-origin
80
+ Cross-Origin-Embedder-Policy: require-corp
81
+ ```
82
+
83
+ We've included a `_headers` file that works with some web hosts (e.g. Netlify)
84
+ but depending on your host / server setup you may need to configure the headers
85
+ manually.
@@ -0,0 +1,24 @@
1
+ # Logs
2
+ logs
3
+ *.log
4
+ npm-debug.log*
5
+ yarn-debug.log*
6
+ yarn-error.log*
7
+ pnpm-debug.log*
8
+ lerna-debug.log*
9
+
10
+ node_modules
11
+ dist
12
+ dist-ssr
13
+ *.local
14
+
15
+ # Editor directories and files
16
+ .vscode/*
17
+ !.vscode/extensions.json
18
+ .idea
19
+ .DS_Store
20
+ *.suo
21
+ *.ntvs*
22
+ *.njsproj
23
+ *.sln
24
+ *.sw?
@@ -0,0 +1,3 @@
1
+ /*
2
+ Cross-Origin-Opener-Policy: same-origin
3
+ Cross-Origin-Embedder-Policy: require-corp
@@ -0,0 +1,2 @@
1
+ NETWORK=testnet
2
+ PRIVATE_KEY=user1PrivateKey