create-leo-app 0.0.13

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 (126) hide show
  1. package/README.md +36 -0
  2. package/dist/index.mjs +52 -0
  3. package/index.js +3 -0
  4. package/package.json +34 -0
  5. package/template-extension/.gitignore +2 -0
  6. package/template-extension/README.md +4 -0
  7. package/template-extension/package.json +15 -0
  8. package/template-extension/rollup.config.js +21 -0
  9. package/template-extension/src/offscreen.js +1 -0
  10. package/template-extension/src/service_worker.js +20 -0
  11. package/template-extension/src/worker.js +34 -0
  12. package/template-extension/static/manifest.json +16 -0
  13. package/template-extension/static/offscreen.html +9 -0
  14. package/template-nextjs-ts/README.md +19 -0
  15. package/template-nextjs-ts/_gitignore +35 -0
  16. package/template-nextjs-ts/next-env.d.ts +5 -0
  17. package/template-nextjs-ts/next.config.js +32 -0
  18. package/template-nextjs-ts/package.json +24 -0
  19. package/template-nextjs-ts/public/aleo.svg +8 -0
  20. package/template-nextjs-ts/public/next.svg +1 -0
  21. package/template-nextjs-ts/src/app/favicon.ico +0 -0
  22. package/template-nextjs-ts/src/app/globals.css +126 -0
  23. package/template-nextjs-ts/src/app/layout.tsx +22 -0
  24. package/template-nextjs-ts/src/app/page.module.css +160 -0
  25. package/template-nextjs-ts/src/app/page.tsx +94 -0
  26. package/template-nextjs-ts/src/app/worker.ts +47 -0
  27. package/template-nextjs-ts/tsconfig.json +27 -0
  28. package/template-node/README.md +5 -0
  29. package/template-node/_gitignore +24 -0
  30. package/template-node/index.js +59 -0
  31. package/template-node/package.json +12 -0
  32. package/template-node-ts/README.md +5 -0
  33. package/template-node-ts/_gitignore +24 -0
  34. package/template-node-ts/package.json +19 -0
  35. package/template-node-ts/rollup.config.js +19 -0
  36. package/template-node-ts/src/index.ts +66 -0
  37. package/template-node-ts/tsconfig.json +15 -0
  38. package/template-offline-public-transaction-ts/README.md +52 -0
  39. package/template-offline-public-transaction-ts/_gitignore +24 -0
  40. package/template-offline-public-transaction-ts/package.json +19 -0
  41. package/template-offline-public-transaction-ts/rollup.config.js +19 -0
  42. package/template-offline-public-transaction-ts/src/helpers.ts +70 -0
  43. package/template-offline-public-transaction-ts/src/index.ts +171 -0
  44. package/template-offline-public-transaction-ts/tsconfig.json +15 -0
  45. package/template-react-leo/.babelrc +6 -0
  46. package/template-react-leo/.eslintrc.cjs +20 -0
  47. package/template-react-leo/README.md +90 -0
  48. package/template-react-leo/_gitignore +24 -0
  49. package/template-react-leo/_headers +3 -0
  50. package/template-react-leo/helloworld/.env.example +2 -0
  51. package/template-react-leo/helloworld/.gitignore +5 -0
  52. package/template-react-leo/helloworld/README.md +13 -0
  53. package/template-react-leo/helloworld/build/main.aleo +7 -0
  54. package/template-react-leo/helloworld/build/program.json +6 -0
  55. package/template-react-leo/helloworld/inputs/helloworld.in +4 -0
  56. package/template-react-leo/helloworld/program.json +6 -0
  57. package/template-react-leo/helloworld/src/main.leo +7 -0
  58. package/template-react-leo/index.html +88 -0
  59. package/template-react-leo/install.sh +30 -0
  60. package/template-react-leo/package.json +44 -0
  61. package/template-react-leo/public/favicon.ico +0 -0
  62. package/template-react-leo/src/App.css +42 -0
  63. package/template-react-leo/src/App.jsx +103 -0
  64. package/template-react-leo/src/assets/aleo.svg +5 -0
  65. package/template-react-leo/src/assets/react.svg +1 -0
  66. package/template-react-leo/src/index.css +69 -0
  67. package/template-react-leo/src/main.jsx +10 -0
  68. package/template-react-leo/src/workers/AleoWorker.js +20 -0
  69. package/template-react-leo/src/workers/worker.js +72 -0
  70. package/template-react-leo/vite.config.js +16 -0
  71. package/template-react-leo/webpack.config.js +102 -0
  72. package/template-react-managed-worker/.babelrc +6 -0
  73. package/template-react-managed-worker/.eslintrc.cjs +20 -0
  74. package/template-react-managed-worker/README.md +8 -0
  75. package/template-react-managed-worker/_gitignore +24 -0
  76. package/template-react-managed-worker/index.html +88 -0
  77. package/template-react-managed-worker/package.json +41 -0
  78. package/template-react-managed-worker/public/favicon.ico +0 -0
  79. package/template-react-managed-worker/src/App.css +42 -0
  80. package/template-react-managed-worker/src/App.jsx +78 -0
  81. package/template-react-managed-worker/src/assets/aleo.png +0 -0
  82. package/template-react-managed-worker/src/assets/react.svg +1 -0
  83. package/template-react-managed-worker/src/index.css +69 -0
  84. package/template-react-managed-worker/src/main.jsx +10 -0
  85. package/template-react-managed-worker/vite.config.js +20 -0
  86. package/template-react-managed-worker/webpack.config.js +90 -0
  87. package/template-react-ts/.babelrc +7 -0
  88. package/template-react-ts/.eslintrc.cjs +20 -0
  89. package/template-react-ts/README.md +90 -0
  90. package/template-react-ts/_gitignore +24 -0
  91. package/template-react-ts/_headers +3 -0
  92. package/template-react-ts/helloworld/.env.example +2 -0
  93. package/template-react-ts/helloworld/.gitignore +5 -0
  94. package/template-react-ts/helloworld/README.md +13 -0
  95. package/template-react-ts/helloworld/build/main.aleo +7 -0
  96. package/template-react-ts/helloworld/build/program.json +6 -0
  97. package/template-react-ts/helloworld/inputs/helloworld.in +4 -0
  98. package/template-react-ts/helloworld/program.json +6 -0
  99. package/template-react-ts/helloworld/src/main.leo +7 -0
  100. package/template-react-ts/index.html +88 -0
  101. package/template-react-ts/install.sh +30 -0
  102. package/template-react-ts/package.json +49 -0
  103. package/template-react-ts/public/favicon.ico +0 -0
  104. package/template-react-ts/src/App.css +42 -0
  105. package/template-react-ts/src/App.tsx +103 -0
  106. package/template-react-ts/src/assets/aleo.svg +5 -0
  107. package/template-react-ts/src/assets/react.svg +1 -0
  108. package/template-react-ts/src/custom.d.ts +16 -0
  109. package/template-react-ts/src/index.css +69 -0
  110. package/template-react-ts/src/main.tsx +10 -0
  111. package/template-react-ts/src/workers/AleoWorker.ts +21 -0
  112. package/template-react-ts/src/workers/worker.ts +73 -0
  113. package/template-react-ts/tsconfig.json +16 -0
  114. package/template-react-ts/vite.config.ts +16 -0
  115. package/template-react-ts/webpack.config.ts +112 -0
  116. package/template-vanilla/_gitignore +24 -0
  117. package/template-vanilla/_headers +3 -0
  118. package/template-vanilla/index.html +13 -0
  119. package/template-vanilla/javascript.svg +1 -0
  120. package/template-vanilla/main.js +48 -0
  121. package/template-vanilla/package.json +16 -0
  122. package/template-vanilla/public/aleo.svg +76 -0
  123. package/template-vanilla/public/vite.svg +1 -0
  124. package/template-vanilla/style.css +97 -0
  125. package/template-vanilla/vite.config.js +12 -0
  126. package/template-vanilla/worker.js +95 -0
@@ -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
+ "start": "npm run build && node dist/index.js"
9
+ },
10
+ "dependencies": {
11
+ "@provablehq/sdk": "^0.6.0"
12
+ },
13
+ "devDependencies": {
14
+ "rimraf": "^5.0.1",
15
+ "rollup": "^3.27.2",
16
+ "rollup-plugin-typescript2": "^0.36.0",
17
+ "typescript": "^5.2.2"
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<Error | 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<Error | 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,90 @@
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/testnet3/create-leo-app/template-react-leo)
4
+
5
+ This template provides a minimal setup to get React and Aleo working in Vite
6
+ with HMR and some ESLint rules.
7
+
8
+ This template includes a Leo program that is loaded by the web app located in
9
+ the `helloworld` directory.
10
+
11
+ Note: Webpack is currently used for production builds due to a
12
+ [bug](https://github.com/vitejs/vite/issues/13367) with Vite related to nested
13
+ workers.
14
+
15
+ ### Start in development mode
16
+
17
+ ```bash
18
+ npm run dev
19
+ ```
20
+
21
+ Your app should be running on http://localhost:5173/
22
+
23
+ ### Build Leo program
24
+
25
+ 1. Copy the `helloworld/.env.example` to `helloworld/.env` (this will be ignored
26
+ by Git):
27
+
28
+ ```bash
29
+ cd helloworld
30
+ cp .env.example .env
31
+ ```
32
+
33
+ 2. Replace `PRIVATE_KEY=user1PrivateKey` in the `.env` with your own key (you
34
+ can use an existing one or generate your own at https://provable.tools/account)
35
+
36
+ 3. Follow instructions to install Leo here: https://github.com/ProvableHQ/leo
37
+
38
+ 4. You can edit `helloworld/src/main.leo` and run `leo run` to compile and update the
39
+ Aleo instructions under `build` which are loaded by the web app.
40
+
41
+ ## Deploy program from web app
42
+
43
+ > [!WARNING]
44
+ > This is for demonstration purposes or local testing only, in production applications you
45
+ > should avoid building a public facing web app with private key information
46
+
47
+ Information on generating a private key, seeding a wallet with funds, and finding a spendable record can be found here
48
+ if you are unfamiliar: https://developer.aleo.org/testnet/getting_started/deploy_execute_demo
49
+
50
+ 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.
51
+
52
+ 1. In the `worker.js` file modify the privateKey to be an account with available
53
+ funds
54
+
55
+ ```js
56
+ // Use existing account with funds
57
+ const account = new Account({
58
+ privateKey: "user1PrivateKey",
59
+ });
60
+ ```
61
+
62
+ 2. (Optional) Provide a fee record manually (located in commented code within `worker.js`)
63
+
64
+ 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.
65
+
66
+ 3. Run the web app and hit the deploy button
67
+
68
+ ## Production deployment
69
+
70
+ ### Build
71
+
72
+ `npm run build`
73
+
74
+ Upload `dist` folder to your host of choice.
75
+
76
+ ### ⚠️ Header warnings
77
+
78
+ `DOMException: Failed to execute 'postMessage' on 'Worker': SharedArrayBuffer transfer requires self.crossOriginIsolated`
79
+
80
+ If you get a warning similar to this when deploying your application, you need
81
+ to make sure your web server is configured with the following headers:
82
+
83
+ ```
84
+ Cross-Origin-Opener-Policy: same-origin
85
+ Cross-Origin-Embedder-Policy: require-corp
86
+ ```
87
+
88
+ We've included a `_headers` file that works with some web hosts (e.g. Netlify)
89
+ but depending on your host / server setup you may need to configure the headers
90
+ 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
@@ -0,0 +1,5 @@
1
+ .env
2
+ *.avm
3
+ *.prover
4
+ *.verifier
5
+ outputs/
@@ -0,0 +1,13 @@
1
+ # helloworld.aleo
2
+
3
+ ## Build Guide
4
+
5
+ To compile this Aleo program, run:
6
+ ```bash
7
+ snarkvm build
8
+ ```
9
+
10
+ To execute this Aleo program, run:
11
+ ```bash
12
+ snarkvm run hello
13
+ ```
@@ -0,0 +1,7 @@
1
+ program helloworld.aleo;
2
+
3
+ function main:
4
+ input r0 as u32.public;
5
+ input r1 as u32.private;
6
+ add r0 r1 into r2;
7
+ output r2 as u32.private;
@@ -0,0 +1,6 @@
1
+ {
2
+ "program": "helloworld.aleo",
3
+ "version": "0.0.0",
4
+ "description": "",
5
+ "license": "MIT"
6
+ }
@@ -0,0 +1,4 @@
1
+ // The program input for helloworld/src/main.leo
2
+ [main]
3
+ public a: u32 = 1u32;
4
+ b: u32 = 2u32;
@@ -0,0 +1,6 @@
1
+ {
2
+ "program": "helloworld.aleo",
3
+ "version": "0.0.0",
4
+ "description": "",
5
+ "license": "MIT"
6
+ }
@@ -0,0 +1,7 @@
1
+ // The 'helloworld' program.
2
+ program helloworld.aleo {
3
+ transition main(public a: u32, b: u32) -> u32 {
4
+ let c: u32 = a + b;
5
+ return c;
6
+ }
7
+ }
@@ -0,0 +1,88 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" href="public/favicon.ico" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Aleo + React</title>
8
+ <style>
9
+ body {
10
+ background: #000000;
11
+ }
12
+ .spinner {
13
+ margin: 150px auto 50px auto;
14
+ width: 40px;
15
+ height: 40px;
16
+ position: relative;
17
+ text-align: center;
18
+
19
+ -webkit-animation: sk-rotate 2s infinite linear;
20
+ animation: sk-rotate 2s infinite linear;
21
+ }
22
+
23
+ .dot1,
24
+ .dot2 {
25
+ width: 60%;
26
+ height: 60%;
27
+ display: inline-block;
28
+ position: absolute;
29
+ top: 0;
30
+ background-color: #00C0F9;
31
+ border-radius: 100%;
32
+
33
+ -webkit-animation: sk-bounce 2s infinite ease-in-out;
34
+ animation: sk-bounce 2s infinite ease-in-out;
35
+ }
36
+
37
+ .dot2 {
38
+ top: auto;
39
+ bottom: 0;
40
+ -webkit-animation-delay: -1s;
41
+ animation-delay: -1s;
42
+ }
43
+
44
+ @-webkit-keyframes sk-rotate {
45
+ 100% {
46
+ -webkit-transform: rotate(360deg);
47
+ }
48
+ }
49
+ @keyframes sk-rotate {
50
+ 100% {
51
+ transform: rotate(360deg);
52
+ -webkit-transform: rotate(360deg);
53
+ }
54
+ }
55
+
56
+ @-webkit-keyframes sk-bounce {
57
+ 0%,
58
+ 100% {
59
+ -webkit-transform: scale(0);
60
+ }
61
+ 50% {
62
+ -webkit-transform: scale(1);
63
+ }
64
+ }
65
+
66
+ @keyframes sk-bounce {
67
+ 0%,
68
+ 100% {
69
+ transform: scale(0);
70
+ -webkit-transform: scale(0);
71
+ }
72
+ 50% {
73
+ transform: scale(1);
74
+ -webkit-transform: scale(1);
75
+ }
76
+ }
77
+ </style>
78
+ </head>
79
+ <body>
80
+ <div id="root">
81
+ <div class="spinner">
82
+ <div class="dot1"></div>
83
+ <div class="dot2"></div>
84
+ </div>
85
+ </div>
86
+ <script type="module" src="/src/main.jsx"></script>
87
+ </body>
88
+ </html>
@@ -0,0 +1,30 @@
1
+ #!/bin/bash
2
+
3
+ # script exists immediately if command fails
4
+ set -e
5
+
6
+ # check for dependencies
7
+ command -v git >/dev/null 2>&1 || { echo >&2 "git is required but it's not installed. Aborting."; exit 1; }
8
+ command -v cargo >/dev/null 2>&1 || { echo >&2 "cargo is required but it's not installed. Aborting."; exit 1; }
9
+
10
+ INSTALL_DIR="${INSTALL_DIR:-$HOME/.leo}"
11
+
12
+ # ask for confirmation
13
+ read -p "This script will install Leo into $INSTALL_DIR. Do you want to continue? (y/N) " choice
14
+ case "$choice" in
15
+ y|Y ) echo "Continuing installation...";;
16
+ * ) echo "Aborting."; exit;;
17
+ esac
18
+
19
+ # clone or update the repo
20
+ if [ -d "$INSTALL_DIR" ]; then
21
+ echo "Directory $INSTALL_DIR exists. Updating repository..."
22
+ git -C "$INSTALL_DIR" pull
23
+ else
24
+ echo "Cloning repository into $INSTALL_DIR..."
25
+ git clone https://github.com/ProvableHQ/leo "$INSTALL_DIR"
26
+ fi
27
+
28
+ # build and install
29
+ echo "Building and installing from source..."
30
+ cargo install --path "$INSTALL_DIR"
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "aleo-react-leo-starter",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "webpack --config webpack.config.js",
9
+ "build:vite": "vite build",
10
+ "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
11
+ "preview": "vite preview",
12
+ "install-leo": "./install.sh"
13
+ },
14
+ "dependencies": {
15
+ "@provablehq/sdk": "^0.6.0",
16
+ "comlink": "^4.4.1",
17
+ "react": "^18.2.0",
18
+ "react-dom": "^18.2.0"
19
+ },
20
+ "devDependencies": {
21
+ "@babel/core": "^7.17.2",
22
+ "@babel/preset-env": "^7.16.11",
23
+ "@babel/preset-react": "^7.16.7",
24
+ "@types/react": "^18.2.15",
25
+ "@types/react-dom": "^18.2.7",
26
+ "@vitejs/plugin-react": "^4.0.4",
27
+ "babel-loader": "^8.2.3",
28
+ "copy-webpack-plugin": "^11.0.0",
29
+ "css-loader": "^6.6.0",
30
+ "eslint": "^8.45.0",
31
+ "eslint-plugin-react": "^7.32.2",
32
+ "eslint-plugin-react-hooks": "^4.6.0",
33
+ "eslint-plugin-react-refresh": "^0.4.3",
34
+ "file-loader": "^6.2.0",
35
+ "html-webpack-plugin": "^5.5.0",
36
+ "raw-loader": "^4.0.2",
37
+ "style-loader": "^3.3.1",
38
+ "svg-url-loader": "^8.0.0",
39
+ "vite": "^4.4.12",
40
+ "webpack": "^5.76.0",
41
+ "webpack-cli": "^5.1.4",
42
+ "webpack-dev-server": "^4.15.1"
43
+ }
44
+ }