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,22 @@
1
+ import './globals.css'
2
+ import type { Metadata } from 'next'
3
+ import { Inter } from 'next/font/google'
4
+
5
+ const inter = Inter({ subsets: ['latin'] })
6
+
7
+ export const metadata: Metadata = {
8
+ title: 'Create Next App',
9
+ description: 'Generated by create next app',
10
+ }
11
+
12
+ export default function RootLayout({
13
+ children,
14
+ }: {
15
+ children: React.ReactNode
16
+ }) {
17
+ return (
18
+ <html lang="en">
19
+ <body className={inter.className}>{children}</body>
20
+ </html>
21
+ )
22
+ }
@@ -0,0 +1,160 @@
1
+ .main {
2
+ display: flex;
3
+ flex-direction: column;
4
+ justify-content: space-between;
5
+ align-items: center;
6
+ padding: 15rem;
7
+ min-height: 100vh;
8
+ }
9
+
10
+ .description {
11
+ display: inherit;
12
+ justify-content: inherit;
13
+ align-items: inherit;
14
+ font-size: 0.85rem;
15
+ max-width: var(--max-width);
16
+ z-index: 2;
17
+ font-family: var(--font-mono);
18
+ }
19
+
20
+ .description a {
21
+ display: flex;
22
+ justify-content: center;
23
+ align-items: center;
24
+ gap: 0.5rem;
25
+ }
26
+
27
+ .description p {
28
+ position: relative;
29
+ margin: 0;
30
+ padding: 1rem;
31
+ background-color: rgba(var(--callout-rgb), 0.5);
32
+ border: 1px solid rgba(var(--callout-border-rgb), 0.3);
33
+ border-radius: var(--border-radius);
34
+ }
35
+
36
+ .code {
37
+ font-weight: 700;
38
+ font-family: var(--font-mono);
39
+ }
40
+
41
+ .center {
42
+ display: flex;
43
+ justify-content: center;
44
+ align-items: center;
45
+ position: relative;
46
+ padding: 4rem 0;
47
+ }
48
+
49
+ .center::before {
50
+ background: var(--secondary-glow);
51
+ border-radius: 50%;
52
+ width: 480px;
53
+ height: 360px;
54
+ margin-left: -400px;
55
+ }
56
+
57
+ .center::after {
58
+ background: var(--primary-glow);
59
+ width: 240px;
60
+ height: 180px;
61
+ z-index: -1;
62
+ }
63
+
64
+ .center::before,
65
+ .center::after {
66
+ content: '';
67
+ left: 50%;
68
+ position: absolute;
69
+ filter: blur(45px);
70
+ transform: translateZ(0);
71
+ }
72
+
73
+ .logo {
74
+ position: relative;
75
+ }
76
+
77
+ /* Mobile */
78
+ @media (max-width: 700px) {
79
+ .content {
80
+ padding: 4rem;
81
+ }
82
+
83
+ .center {
84
+ padding: 8rem 0 6rem;
85
+ }
86
+
87
+ .center::before {
88
+ transform: none;
89
+ height: 300px;
90
+ }
91
+
92
+ .description {
93
+ font-size: 0.8rem;
94
+ }
95
+
96
+ .description a {
97
+ padding: 1rem;
98
+ }
99
+
100
+ .description p,
101
+ .description div {
102
+ display: flex;
103
+ justify-content: center;
104
+ position: fixed;
105
+ width: 100%;
106
+ }
107
+
108
+ .description p {
109
+ align-items: center;
110
+ inset: 0 0 auto;
111
+ padding: 2rem 1rem 1.4rem;
112
+ border-radius: 0;
113
+ border: none;
114
+ border-bottom: 1px solid rgba(var(--callout-border-rgb), 0.25);
115
+ background: linear-gradient(
116
+ to bottom,
117
+ rgba(var(--background-start-rgb), 1),
118
+ rgba(var(--callout-rgb), 0.5)
119
+ );
120
+ background-clip: padding-box;
121
+ backdrop-filter: blur(24px);
122
+ }
123
+
124
+ .description div {
125
+ align-items: flex-end;
126
+ pointer-events: none;
127
+ inset: auto 0 0;
128
+ padding: 2rem;
129
+ height: 200px;
130
+ background: linear-gradient(
131
+ to bottom,
132
+ transparent 0%,
133
+ rgb(var(--background-end-rgb)) 40%
134
+ );
135
+ z-index: 1;
136
+ }
137
+ }
138
+
139
+ @media (prefers-color-scheme: dark) {
140
+ .logo {
141
+ filter: invert(1) drop-shadow(0 0 0.3rem #ffffff70);
142
+ }
143
+ }
144
+
145
+ @keyframes rotate {
146
+ from {
147
+ transform: rotate(360deg);
148
+ }
149
+ to {
150
+ transform: rotate(0deg);
151
+ }
152
+ }
153
+
154
+ .card {
155
+ text-align: center;
156
+ }
157
+
158
+ .card p {
159
+ padding: 1em;
160
+ }
@@ -0,0 +1,94 @@
1
+ "use client";
2
+
3
+ import Image from "next/image";
4
+ import styles from "./page.module.css";
5
+ import { useCallback, useEffect, useRef, useState } from "react";
6
+
7
+ export default function Home() {
8
+ const [account, setAccount] = useState(null);
9
+ const [executing, setExecuting] = useState(false);
10
+
11
+ const generateAccount = async () => {
12
+ workerRef.current?.postMessage("key");
13
+ };
14
+
15
+ async function execute() {
16
+ setExecuting(true);
17
+ workerRef.current?.postMessage("execute");
18
+ }
19
+
20
+ const workerRef = useRef<Worker>();
21
+
22
+ interface AleoWorkerMessageEvent {
23
+ type: string;
24
+ result: any;
25
+ }
26
+
27
+ useEffect(() => {
28
+ workerRef.current = new Worker(new URL("worker.ts", import.meta.url));
29
+ workerRef.current.onmessage = (
30
+ event: MessageEvent<AleoWorkerMessageEvent>
31
+ ) => {
32
+ if (event.data.type === "key") {
33
+ setAccount(event.data.result);
34
+ } else if (event.data.type === "execute") {
35
+ setExecuting(false);
36
+ }
37
+ alert(`WebWorker Response => ${event.data.result}`);
38
+ };
39
+ return () => {
40
+ workerRef.current?.terminate();
41
+ };
42
+ }, []);
43
+
44
+ const handleWork = useCallback(async () => {
45
+ workerRef.current?.postMessage("execute");
46
+ }, []);
47
+
48
+ return (
49
+ <main className={styles.main}>
50
+ <div className={styles.description}>
51
+ <p>
52
+ Get started by editing&nbsp;
53
+ <code className={styles.code}>src/app/page.tsx</code>
54
+ </p>
55
+ </div>
56
+
57
+ <div className={styles.center}>
58
+ <Image
59
+ className={styles.logo}
60
+ src="/next.svg"
61
+ alt="Next.js Logo"
62
+ width={180}
63
+ height={37}
64
+ priority
65
+ />
66
+ <Image
67
+ className={styles.logo}
68
+ src="/aleo.svg"
69
+ alt="Next.js Logo"
70
+ width={180}
71
+ height={45}
72
+ priority
73
+ />
74
+ </div>
75
+
76
+ <div className={styles.card}>
77
+ <p>
78
+ <button onClick={generateAccount}>
79
+ {account
80
+ ? `Account private key is ${JSON.stringify(account)}`
81
+ : `Click to generate account`}
82
+ </button>
83
+ </p>
84
+ <p>
85
+ <button disabled={executing} onClick={execute}>
86
+ {executing
87
+ ? `Executing...check console for details...`
88
+ : `Execute helloworld.aleo`}
89
+ </button>
90
+ </p>
91
+ </div>
92
+ </main>
93
+ );
94
+ }
@@ -0,0 +1,47 @@
1
+ import {
2
+ Account,
3
+ initThreadPool,
4
+ PrivateKey,
5
+ ProgramManager,
6
+ } from "@provablehq/sdk";
7
+
8
+ await initThreadPool();
9
+
10
+ const hello_hello_program =`
11
+ program hello_hello.aleo;
12
+
13
+ function hello:
14
+ input r0 as u32.public;
15
+ input r1 as u32.private;
16
+ add r0 r1 into r2;
17
+ output r2 as u32.private;`
18
+
19
+ async function localProgramExecution(program: string, aleoFunction: string, inputs: string[]) {
20
+ const programManager = new ProgramManager();
21
+
22
+ // Create a temporary account for the execution of the program
23
+ const account = new Account();
24
+ programManager.setAccount(account);
25
+
26
+ const executionResponse = await programManager.run(
27
+ program,
28
+ aleoFunction,
29
+ inputs,
30
+ false,
31
+ );
32
+ return executionResponse.getOutputs();
33
+ }
34
+
35
+ function getPrivateKey() {
36
+ return new PrivateKey().to_string();
37
+ }
38
+
39
+ onmessage = async function (e) {
40
+ if (e.data === "execute") {
41
+ const result = await localProgramExecution(hello_hello_program, "hello", ["5u32", "5u32"]);
42
+ postMessage({type: "execute", result: result});
43
+ } else if (e.data === "key") {
44
+ const result = getPrivateKey();
45
+ postMessage({type: "key", result: result});
46
+ }
47
+ };
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2017",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "esModuleInterop": true,
10
+ "module": "esnext",
11
+ "moduleResolution": "bundler",
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "jsx": "preserve",
15
+ "incremental": true,
16
+ "plugins": [
17
+ {
18
+ "name": "next"
19
+ }
20
+ ],
21
+ "paths": {
22
+ "@/*": ["./src/*"]
23
+ }
24
+ },
25
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
26
+ "exclude": ["node_modules"]
27
+ }
@@ -0,0 +1,5 @@
1
+ # Aleo + Node.js
2
+
3
+ `npm start`
4
+
5
+ Recommend Node.js 20+ 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,59 @@
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
+ const keyPair = await programManager.synthesizeKeys(hello_hello_program, aleoFunction, inputs);
30
+ programManager.keyProvider.cacheKeys(`${programName}:${aleoFunction}`, keyPair);
31
+
32
+ // Specify parameters for the key provider to use search for program keys. In particular specify the cache key
33
+ // that was used to cache the keys in the previous step.
34
+ const keyProviderParams = new AleoKeyProviderParams({cacheKey: `${programName}:${aleoFunction}`});
35
+
36
+ // Execute once using the key provider params defined above. This will use the cached proving keys and make
37
+ // execution significantly faster.
38
+ let executionResponse = await programManager.run(
39
+ program,
40
+ aleoFunction,
41
+ inputs,
42
+ true,
43
+ undefined,
44
+ keyProviderParams,
45
+ );
46
+ console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());
47
+
48
+ // Verify the execution using the verifying key that was generated earlier.
49
+ if (programManager.verifyExecution(executionResponse)) {
50
+ console.log("hello_hello/hello execution verified!");
51
+ } else {
52
+ throw("Execution failed verification!");
53
+ }
54
+ }
55
+
56
+ const start = Date.now();
57
+ console.log("Starting execute!");
58
+ await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]);
59
+ console.log("Execute finished!", Date.now() - start);
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "node-starter",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "start": "node index.js"
8
+ },
9
+ "dependencies": {
10
+ "@provablehq/sdk": "^0.6.0"
11
+ }
12
+ }
@@ -0,0 +1,5 @@
1
+ # Aleo + Node.js + TypeScript
2
+
3
+ `npm start`
4
+
5
+ Recommend Node.js 20+ 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-ts-starter",
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,66 @@
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
+ const keyPair = await programManager.synthesizeKeys(hello_hello_program, aleoFunction, inputs);
30
+
31
+ if (keyPair instanceof Error) {
32
+ throw new Error(`Failed to synthesize keys: ${keyPair.message}`);
33
+ } else {
34
+ programManager.keyProvider.cacheKeys(`${programName}:${aleoFunction}`, keyPair);
35
+ }
36
+
37
+ programManager.keyProvider.cacheKeys(`${programName}:${aleoFunction}`, keyPair);
38
+
39
+ // Specify parameters for the key provider to use search for program keys. In particular specify the cache key
40
+ // that was used to cache the keys in the previous step.
41
+ const keyProviderParams = new AleoKeyProviderParams({cacheKey: `${programName}:${aleoFunction}`});
42
+
43
+ // Execute once using the key provider params defined above. This will use the cached proving keys and make
44
+ // execution significantly faster.
45
+ let executionResponse = await programManager.run(
46
+ program,
47
+ aleoFunction,
48
+ inputs,
49
+ true,
50
+ undefined,
51
+ keyProviderParams,
52
+ );
53
+ console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());
54
+
55
+ // Verify the execution using the verifying key that was generated earlier.
56
+ if (programManager.verifyExecution(executionResponse)) {
57
+ console.log("hello_hello/hello execution verified!");
58
+ } else {
59
+ throw("Execution failed verification!");
60
+ }
61
+ }
62
+
63
+ const start = Date.now();
64
+ console.log("Starting execute!");
65
+ await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]);
66
+ 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?