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,49 @@
1
+ {
2
+ "name": "aleo-react-typescript-starter",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "scripts": {
6
+ "dev": "vite",
7
+ "build": "webpack",
8
+ "dev-webpack": "webpack serve",
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.2",
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.22.15",
24
+ "@babel/preset-typescript": "^7.23.2",
25
+ "@types/react": "^18.2.15",
26
+ "@types/react-dom": "^18.2.7",
27
+ "@types/babel__generator": "^7.6.6",
28
+ "@types/node": "^20.8.7",
29
+ "@vitejs/plugin-react": "^4.0.4",
30
+ "babel-loader": "^8.2.3",
31
+ "copy-webpack-plugin": "^11.0.0",
32
+ "css-loader": "^6.6.0",
33
+ "eslint": "^8.45.0",
34
+ "eslint-plugin-react": "^7.32.2",
35
+ "eslint-plugin-react-hooks": "^4.6.0",
36
+ "eslint-plugin-react-refresh": "^0.4.3",
37
+ "file-loader": "^6.2.0",
38
+ "html-webpack-plugin": "^5.5.0",
39
+ "raw-loader": "^4.0.2",
40
+ "style-loader": "^3.3.1",
41
+ "svg-url-loader": "^8.0.0",
42
+ "ts-node": "^10.9.1",
43
+ "typescript": "^5.2.2",
44
+ "vite": "^4.4.12",
45
+ "webpack": "^5.76.0",
46
+ "webpack-cli": "^5.1.4",
47
+ "webpack-dev-server": "^4.15.1"
48
+ }
49
+ }
@@ -0,0 +1,42 @@
1
+ #root {
2
+ max-width: 1280px;
3
+ margin: 0 auto;
4
+ padding: 2rem;
5
+ text-align: center;
6
+ }
7
+
8
+ .logo {
9
+ height: 6em;
10
+ padding: 1.5em;
11
+ will-change: filter;
12
+ transition: filter 300ms;
13
+ }
14
+ .logo:hover {
15
+ filter: drop-shadow(0 0 2em #646cffaa);
16
+ }
17
+ .logo.react:hover {
18
+ filter: drop-shadow(0 0 2em #61dafbaa);
19
+ }
20
+
21
+ @keyframes logo-spin {
22
+ from {
23
+ transform: rotate(0deg);
24
+ }
25
+ to {
26
+ transform: rotate(360deg);
27
+ }
28
+ }
29
+
30
+ @media (prefers-reduced-motion: no-preference) {
31
+ a:nth-of-type(2) .logo {
32
+ animation: logo-spin infinite 20s linear;
33
+ }
34
+ }
35
+
36
+ .card {
37
+ padding: 2em;
38
+ }
39
+
40
+ .read-the-docs {
41
+ color: #888;
42
+ }
@@ -0,0 +1,103 @@
1
+ import { useState } from "react";
2
+ import reactLogo from "./assets/react.svg";
3
+ import aleoLogo from "./assets/aleo.svg";
4
+ import "./App.css";
5
+ import helloworld_program from "../helloworld/build/main.aleo?raw";
6
+ import { AleoWorker } from "./workers/AleoWorker";
7
+
8
+ const aleoWorker = AleoWorker();
9
+ function App() {
10
+ const [count, setCount] = useState(0);
11
+ const [account, setAccount] = useState(null);
12
+ const [executing, setExecuting] = useState(false);
13
+ const [deploying, setDeploying] = useState(false);
14
+
15
+ const generateAccount = async () => {
16
+ const key = await aleoWorker.getPrivateKey();
17
+ setAccount(await key.to_string());
18
+ };
19
+
20
+ async function execute() {
21
+ setExecuting(true);
22
+ const result = await aleoWorker.localProgramExecution(
23
+ helloworld_program,
24
+ "main",
25
+ ["5u32", "5u32"],
26
+ );
27
+ setExecuting(false);
28
+
29
+ alert(JSON.stringify(result));
30
+ }
31
+
32
+ async function deploy() {
33
+ setDeploying(true);
34
+ try {
35
+ const result = await aleoWorker.deployProgram(helloworld_program);
36
+ console.log("Transaction:")
37
+ console.log("https://explorer.hamp.app/transaction?id=" + result)
38
+ alert("Transaction ID: " + result);
39
+ } catch (e) {
40
+ console.log(e)
41
+ alert("Error with deployment, please check console for details");
42
+ }
43
+ setDeploying(false);
44
+ }
45
+
46
+ return (
47
+ <>
48
+ <div>
49
+ <a href="https://aleo.org" target="_blank">
50
+ <img src={aleoLogo} className="logo" alt="Aleo logo" />
51
+ </a>
52
+ <a href="https://react.dev" target="_blank">
53
+ <img src={reactLogo} className="logo react" alt="React logo" />
54
+ </a>
55
+ </div>
56
+ <h1>Aleo + React</h1>
57
+ <div className="card">
58
+ <button onClick={() => setCount((count) => count + 1)}>
59
+ count is {count}
60
+ </button>
61
+ <p>
62
+ <button onClick={generateAccount}>
63
+ {account
64
+ ? `Account private key is ${JSON.stringify(account)}`
65
+ : `Click to generate account`}
66
+ </button>
67
+ </p>
68
+ <p>
69
+ <button disabled={executing} onClick={execute}>
70
+ {executing
71
+ ? `Executing...check console for details...`
72
+ : `Execute helloworld.aleo`}
73
+ </button>
74
+ </p>
75
+ <p>
76
+ Edit <code>src/App.tsx</code> and save to test HMR
77
+ </p>
78
+ </div>
79
+
80
+ {/* Advanced Section */}
81
+ <div className="card">
82
+ <h2>Advanced Actions</h2>
83
+ <p>
84
+ Deployment on Aleo requires certain prerequisites like seeding your
85
+ wallet with credits and retrieving a fee record. Check README for more
86
+ details.
87
+ </p>
88
+ <p>
89
+ <button disabled={deploying} onClick={deploy}>
90
+ {deploying
91
+ ? `Deploying...check console for details...`
92
+ : `Deploy helloworld.aleo`}
93
+ </button>
94
+ </p>
95
+ </div>
96
+ <p className="read-the-docs">
97
+ Click on the Aleo and React logos to learn more
98
+ </p>
99
+ </>
100
+ );
101
+ }
102
+
103
+ export default App;
@@ -0,0 +1,5 @@
1
+ <svg width="76" height="80" viewBox="0 0 76 80" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M47.886 0H29.4601L13.4679 46.7704H23.2068L36.1609 8.61481H40.8513L53.8036 46.7704H23.2068L20.193 55.3852H56.7073L65.0811 80H75.1314L47.886 0Z" fill="#F5F5F5"/>
3
+ <path d="M2.10278 80H11.8174L20.193 55.3852L10.5213 55.3852L2.10278 80Z" fill="#F5F5F5"/>
4
+ <path d="M3.81482 46.7704L0.868164 55.3852H10.5213L13.4679 46.7704H3.81482Z" fill="#F5F5F5"/>
5
+ </svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
@@ -0,0 +1,16 @@
1
+ declare module '*.svg' {
2
+ const content: any;
3
+ export default content;
4
+ }
5
+
6
+ declare module '*.aleo' {
7
+ const content: string;
8
+ export default content;
9
+ }
10
+
11
+ declare module '*?raw' {
12
+ const content: string;
13
+ export default content;
14
+ }
15
+
16
+
@@ -0,0 +1,69 @@
1
+ :root {
2
+ font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3
+ line-height: 1.5;
4
+ font-weight: 400;
5
+
6
+ color-scheme: light dark;
7
+ color: rgba(255, 255, 255, 0.87);
8
+ background-color: #242424;
9
+
10
+ font-synthesis: none;
11
+ text-rendering: optimizeLegibility;
12
+ -webkit-font-smoothing: antialiased;
13
+ -moz-osx-font-smoothing: grayscale;
14
+ -webkit-text-size-adjust: 100%;
15
+ }
16
+
17
+ a {
18
+ font-weight: 500;
19
+ color: #646cff;
20
+ text-decoration: inherit;
21
+ }
22
+ a:hover {
23
+ color: #535bf2;
24
+ }
25
+
26
+ body {
27
+ margin: 0;
28
+ display: flex;
29
+ place-items: center;
30
+ min-width: 320px;
31
+ min-height: 100vh;
32
+ }
33
+
34
+ h1 {
35
+ font-size: 3.2em;
36
+ line-height: 1.1;
37
+ }
38
+
39
+ button {
40
+ border-radius: 8px;
41
+ border: 1px solid transparent;
42
+ padding: 0.6em 1.2em;
43
+ font-size: 1em;
44
+ font-weight: 500;
45
+ font-family: inherit;
46
+ background-color: #1a1a1a;
47
+ cursor: pointer;
48
+ transition: border-color 0.25s;
49
+ }
50
+ button:hover {
51
+ border-color: #646cff;
52
+ }
53
+ button:focus,
54
+ button:focus-visible {
55
+ outline: 4px auto -webkit-focus-ring-color;
56
+ }
57
+
58
+ @media (prefers-color-scheme: light) {
59
+ :root {
60
+ color: #213547;
61
+ background-color: #ffffff;
62
+ }
63
+ a:hover {
64
+ color: #747bff;
65
+ }
66
+ button {
67
+ background-color: #f9f9f9;
68
+ }
69
+ }
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ import ReactDOM from "react-dom/client";
3
+ import App from "./App";
4
+ import "./index.css";
5
+
6
+ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
7
+ <React.StrictMode>
8
+ <App />
9
+ </React.StrictMode>,
10
+ );
@@ -0,0 +1,21 @@
1
+ //@ts-nocheck
2
+ import { wrap } from "comlink";
3
+
4
+ let singletonWorker = null;
5
+
6
+ const AleoWorker = () => {
7
+ if (!singletonWorker) {
8
+ const worker = new Worker(new URL("worker", import.meta.url), {
9
+ type: "module",
10
+ });
11
+
12
+ worker.onerror = function(event) {
13
+ console.error("Error in worker: " + event?.message);
14
+ };
15
+
16
+ singletonWorker = wrap(worker);
17
+ }
18
+ return singletonWorker;
19
+ };
20
+
21
+ export { AleoWorker };
@@ -0,0 +1,73 @@
1
+ //@ts-nocheck
2
+ import {
3
+ Account,
4
+ ProgramManager,
5
+ PrivateKey,
6
+ initThreadPool,
7
+ AleoKeyProvider,
8
+ AleoNetworkClient,
9
+ NetworkRecordProvider,
10
+ } from "@provablehq/sdk";
11
+ import { expose, proxy } from "comlink";
12
+
13
+ await initThreadPool();
14
+
15
+ async function localProgramExecution(program, aleoFunction, inputs) {
16
+ const programManager = new ProgramManager();
17
+
18
+ // Create a temporary account for the execution of the program
19
+ const account = new Account();
20
+ programManager.setAccount(account);
21
+
22
+ const executionResponse = await programManager.run(
23
+ program,
24
+ aleoFunction,
25
+ inputs,
26
+ false,
27
+ );
28
+ return executionResponse.getOutputs();
29
+ }
30
+
31
+ async function getPrivateKey() {
32
+ const key = new PrivateKey();
33
+ return proxy(key);
34
+ }
35
+
36
+ async function deployProgram(program) {
37
+ const keyProvider = new AleoKeyProvider();
38
+ keyProvider.useCache(true);
39
+
40
+ // Create a record provider that will be used to find records and transaction data for Aleo programs
41
+ const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
42
+
43
+ // Use existing account with funds
44
+ const account = new Account({
45
+ privateKey: "user1PrivateKey",
46
+ });
47
+
48
+ const recordProvider = new NetworkRecordProvider(account, networkClient);
49
+
50
+ // Initialize a program manager to talk to the Aleo network with the configured key and record providers
51
+ const programManager = new ProgramManager(
52
+ "https://api.explorer.aleo.org/v1",
53
+ keyProvider,
54
+ recordProvider,
55
+ );
56
+
57
+ programManager.setAccount(account);
58
+
59
+ // Define a fee to pay to deploy the program
60
+ const fee = 1.9; // 1.9 Aleo credits
61
+
62
+ // Deploy the program to the Aleo network
63
+ const tx_id = await programManager.deploy(program, fee);
64
+
65
+ // Optional: Pass in fee record manually to avoid long scan times
66
+ // const feeRecord = "{ owner: aleo1xxx...xxx.private, microcredits: 2000000u64.private, _nonce: 123...789group.public}";
67
+ // const tx_id = await programManager.deploy(program, fee, undefined, feeRecord);
68
+
69
+ return tx_id;
70
+ }
71
+
72
+ const workerMethods = { localProgramExecution, getPrivateKey, deployProgram };
73
+ expose(workerMethods);
@@ -0,0 +1,16 @@
1
+ {
2
+ "include": ["src", "__tests__", "src/custom.d.ts"],
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "target": "ES2015",
6
+ "moduleResolution": "Bundler",
7
+ "strict": true,
8
+ "skipLibCheck": true,
9
+ "declaration": false,
10
+ "sourceMap": false,
11
+ "noUnusedLocals": true,
12
+ "esModuleInterop": true,
13
+ "allowSyntheticDefaultImports": true,
14
+ "jsx":"react-jsx",
15
+ }
16
+ }
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from "vite";
2
+ import react from "@vitejs/plugin-react";
3
+
4
+ // https://vitejs.dev/config/
5
+ export default defineConfig({
6
+ plugins: [react()],
7
+ optimizeDeps: {
8
+ exclude: ["@provablehq/wasm", "@provablehq/sdk"],
9
+ },
10
+ server: {
11
+ headers: {
12
+ "Cross-Origin-Opener-Policy": "same-origin",
13
+ "Cross-Origin-Embedder-Policy": "require-corp",
14
+ },
15
+ },
16
+ });
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env ts-node
2
+ import CopyPlugin from "copy-webpack-plugin";
3
+ import TerserPlugin from "terser-webpack-plugin";
4
+ import HtmlWebpackPlugin from "html-webpack-plugin";
5
+
6
+ import path from "path";
7
+
8
+ const appConfig = {
9
+ mode: "production",
10
+ entry: {
11
+ index: "./src/main.tsx",
12
+ },
13
+ output: {
14
+ path: path.resolve("dist"),
15
+ filename: "[name].bundle.js",
16
+ },
17
+ resolve: {
18
+ extensions: [".ts", ".tsx", ".js", ".wasm", ".jsx"],
19
+ },
20
+ devServer: {
21
+ port: 3000,
22
+ headers: {
23
+ "Cross-Origin-Opener-Policy": "same-origin",
24
+ "Cross-Origin-Embedder-Policy": "require-corp",
25
+ },
26
+ client: {
27
+ overlay: false,
28
+ },
29
+ },
30
+ module: {
31
+ rules: [
32
+ {
33
+ test: /\.(ts|tsx|js|jsx)$/,
34
+ //exclude: /node_modules/,
35
+ use: {
36
+ loader: "babel-loader",
37
+ // options: {
38
+ // presets: [
39
+ // '@babel/preset-env',
40
+ // '@babel/preset-react',
41
+ // '@babel/preset-typescript',
42
+ // ],
43
+ // },
44
+ },
45
+ },
46
+ {
47
+ test: /\.css$/,
48
+ use: ["style-loader", "css-loader"],
49
+ },
50
+ {
51
+ test: /\.(png|jpe?g|gif)$/i,
52
+ use: [
53
+ {
54
+ loader: "file-loader",
55
+ options: {
56
+ name: "[path][name].[ext]",
57
+ },
58
+ },
59
+ ],
60
+ },
61
+ {
62
+ test: /\.svg$/,
63
+ use: [
64
+ {
65
+ loader: "svg-url-loader",
66
+ options: {
67
+ limit: 8192,
68
+ noquotes: true,
69
+ },
70
+ },
71
+ ],
72
+ },
73
+ {
74
+ test: /\.aleo$/i,
75
+ use: 'raw-loader',
76
+ },
77
+ ],
78
+ },
79
+ plugins: [
80
+ new CopyPlugin({
81
+ patterns: [{ from: "public", to: "public" }, { from: "_headers", to: "." },
82
+ { from: 'src/assets', to: 'dist/assets' }
83
+ ],
84
+ }),
85
+ new HtmlWebpackPlugin({
86
+ template: "./index.html",
87
+ }),
88
+ ],
89
+ performance: {
90
+ hints: false,
91
+ maxAssetSize: 13 * 1024 * 1024, // 12 MiB
92
+ maxEntrypointSize: 13 * 1024 * 1024, // 12 MiB
93
+ },
94
+ optimization: {
95
+ minimize: true,
96
+ minimizer: [new TerserPlugin({
97
+ terserOptions: {
98
+ module: true,
99
+ }
100
+ })],
101
+ },
102
+ stats: {
103
+ warnings: false,
104
+ },
105
+ experiments: {
106
+ asyncWebAssembly: true,
107
+ topLevelAwait: true,
108
+ },
109
+ devtool: "source-map",
110
+ };
111
+
112
+ export default [appConfig];
@@ -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,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/aleo.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Leo App</title>
8
+ </head>
9
+ <body>
10
+ <div id="app"></div>
11
+ <script type="module" src="/main.js"></script>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="32" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path fill="#F7DF1E" d="M0 0h256v256H0V0Z"></path><path d="m67.312 213.932l19.59-11.856c3.78 6.701 7.218 12.371 15.465 12.371c7.905 0 12.89-3.092 12.89-15.12v-81.798h24.057v82.138c0 24.917-14.606 36.259-35.916 36.259c-19.245 0-30.416-9.967-36.087-21.996m85.07-2.576l19.588-11.341c5.157 8.421 11.859 14.607 23.715 14.607c9.969 0 16.325-4.984 16.325-11.858c0-8.248-6.53-11.17-17.528-15.98l-6.013-2.58c-17.357-7.387-28.87-16.667-28.87-36.257c0-18.044 13.747-31.792 35.228-31.792c15.294 0 26.292 5.328 34.196 19.247l-18.732 12.03c-4.125-7.389-8.591-10.31-15.465-10.31c-7.046 0-11.514 4.468-11.514 10.31c0 7.217 4.468 10.14 14.778 14.608l6.014 2.577c20.45 8.765 31.963 17.7 31.963 37.804c0 21.654-17.012 33.51-39.867 33.51c-22.339 0-36.774-10.654-43.819-24.574"></path></svg>
@@ -0,0 +1,48 @@
1
+ import "./style.css";
2
+ import javascriptLogo from "./javascript.svg";
3
+ import aleoLogo from "/aleo.svg";
4
+ import viteLogo from "/vite.svg";
5
+
6
+ const worker = new Worker("worker.js", {
7
+ type: "module",
8
+ });
9
+
10
+ worker.onmessage = function (e) {
11
+ console.log(e.data);
12
+ alert(e.data);
13
+ };
14
+
15
+ window.execute = () => {
16
+ worker.postMessage("execute");
17
+ };
18
+
19
+ window.key = () => {
20
+ worker.postMessage("key");
21
+ };
22
+
23
+ window.deploy = () => {
24
+ worker.postMessage("deploy");
25
+ };
26
+
27
+ document.querySelector("#app").innerHTML = `
28
+ <div>
29
+ <a href="https://vitejs.dev" target="_blank">
30
+ <img src="${viteLogo}" class="logo" alt="Vite logo" />
31
+ </a>
32
+ <a href="https://aleo.org/" target="_blank">
33
+ <img src="${aleoLogo}" class="logo" alt="Aleo logo" />
34
+ </a>
35
+ <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" target="_blank">
36
+ <img src="${javascriptLogo}" class="logo vanilla" alt="JavaScript logo" />
37
+ </a>
38
+ <h1>Hello Aleo!</h1>
39
+ <div class="card">
40
+ <button onclick="window.execute()">Call Execute Function</button>
41
+ <button onclick="window.key()">Get Private Key</button>
42
+ <button onclick="window.deploy()">Deploy HelloWorld Program</button>
43
+ </div>
44
+ <p class="read-the-docs">
45
+ Click on the Aleo logo to learn more
46
+ </p>
47
+ </div>
48
+ `;
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "aleo-starter",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "devDependencies": {
12
+ "@provablehq/sdk": "^0.6.0",
13
+ "tslib": "^2.6.2",
14
+ "vite": "^4.4.12"
15
+ }
16
+ }