create-leo-app 0.9.3 → 0.9.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-leo-app",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "type": "module",
5
5
  "license": "GPL-3.0",
6
6
  "collaborators": [
@@ -7,7 +7,7 @@
7
7
  "build": "rimraf static/js && rollup --config"
8
8
  },
9
9
  "devDependencies": {
10
- "@provablehq/sdk": "^0.9.3",
10
+ "@provablehq/sdk": "^0.9.5",
11
11
  "@web/rollup-plugin-import-meta-assets": "^2.2.1",
12
12
  "rimraf": "^6.0.1",
13
13
  "rollup": "^4.32.0"
@@ -9,7 +9,7 @@
9
9
  "lint": "next lint"
10
10
  },
11
11
  "dependencies": {
12
- "@provablehq/sdk": "^0.9.3",
12
+ "@provablehq/sdk": "^0.9.5",
13
13
  "next": "15.2.3",
14
14
  "react": "^19.0.0",
15
15
  "react-dom": "^19.0.0",
@@ -46,7 +46,7 @@ async function localProgramExecution(program, programName, aleoFunction, inputs)
46
46
  console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());
47
47
 
48
48
  // Verify the execution using the verifying key that was generated earlier.
49
- if (programManager.verifyExecution(executionResponse)) {
49
+ if (programManager.verifyExecution(executionResponse, 9_000_000)) {
50
50
  console.log("hello_hello/hello execution verified!");
51
51
  } else {
52
52
  throw("Execution failed verification!");
@@ -7,6 +7,6 @@
7
7
  "dev": "node index.js"
8
8
  },
9
9
  "dependencies": {
10
- "@provablehq/sdk": "^0.9.3"
10
+ "@provablehq/sdk": "^0.9.5"
11
11
  }
12
12
  }
@@ -8,7 +8,7 @@
8
8
  "dev": "npm run build && node dist/index.js"
9
9
  },
10
10
  "dependencies": {
11
- "@provablehq/sdk": "^0.9.3"
11
+ "@provablehq/sdk": "^0.9.5"
12
12
  },
13
13
  "devDependencies": {
14
14
  "rimraf": "^6.0.1",
@@ -52,7 +52,7 @@ async function localProgramExecution(program, programName, aleoFunction, inputs)
52
52
  console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());
53
53
 
54
54
  // Verify the execution using the verifying key that was generated earlier.
55
- if (programManager.verifyExecution(executionResponse)) {
55
+ if (programManager.verifyExecution(executionResponse, 9_000_000)) {
56
56
  console.log("hello_hello/hello execution verified!");
57
57
  } else {
58
58
  throw("Execution failed verification!");
@@ -8,7 +8,7 @@
8
8
  "dev": "npm run build && node dist/index.js"
9
9
  },
10
10
  "dependencies": {
11
- "@provablehq/sdk": "^0.9.3"
11
+ "@provablehq/sdk": "^0.9.5"
12
12
  },
13
13
  "devDependencies": {
14
14
  "rimraf": "^6.0.1",
@@ -12,7 +12,7 @@
12
12
  "install-leo": "./install.sh"
13
13
  },
14
14
  "dependencies": {
15
- "@provablehq/sdk": "^0.9.3",
15
+ "@provablehq/sdk": "^0.9.5",
16
16
  "comlink": "^4.4.2",
17
17
  "react": "^19.0.0",
18
18
  "react-dom": "^19.0.0"
@@ -11,7 +11,7 @@
11
11
  "preview": "vite preview"
12
12
  },
13
13
  "dependencies": {
14
- "@provablehq/sdk": "^0.9.3",
14
+ "@provablehq/sdk": "^0.9.5",
15
15
  "react": "^19.0.0",
16
16
  "react-dom": "^19.0.0"
17
17
  },
@@ -12,7 +12,7 @@
12
12
  "install-leo": "./install.sh"
13
13
  },
14
14
  "dependencies": {
15
- "@provablehq/sdk": "^0.9.3",
15
+ "@provablehq/sdk": "^0.9.5",
16
16
  "comlink": "^4.4.2",
17
17
  "react": "^19.0.0",
18
18
  "react-dom": "^19.0.0"
@@ -9,7 +9,7 @@
9
9
  "preview": "vite preview"
10
10
  },
11
11
  "devDependencies": {
12
- "@provablehq/sdk": "^0.9.3",
12
+ "@provablehq/sdk": "^0.9.5",
13
13
  "tslib": "^2.8.1",
14
14
  "vite": "^6.1.2"
15
15
  }
@@ -1,195 +0,0 @@
1
- import { CREDITS_PROGRAM_KEYS, initThreadPool, Account, ProgramManager, ProvingKey, OfflineKeyProvider, OfflineQuery, OfflineSearchParams } from '@provablehq/sdk';
2
- import { promises, 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 promises.mkdir(dirPath, { recursive: true });
11
- const filePath = path.join(dirPath, `${fileName}.prover`);
12
- try {
13
- await promises.access(filePath);
14
- return filePath;
15
- }
16
- catch (_a) {
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
- async function preDownloadTransferKeys() {
25
- const keyPaths = {};
26
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
27
- const keysDirPath = path.join(__dirname, "keys");
28
- await promises.mkdir(keysDirPath, { recursive: true });
29
- for (const keyData of [CREDITS_PROGRAM_KEYS.transfer_public, CREDITS_PROGRAM_KEYS.fee_public, CREDITS_PROGRAM_KEYS.transfer_public_as_signer]) {
30
- try {
31
- keyPaths[keyData.locator] = await downloadAndSaveKey(keyData, keysDirPath);
32
- }
33
- catch (error) {
34
- throw (`Failed to download ${keyData.locator} - ${error}`);
35
- }
36
- }
37
- return keyPaths;
38
- }
39
- async function preDownloadBondingKeys() {
40
- const keyPaths = {};
41
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
42
- const keysDirPath = path.join(__dirname, "keys");
43
- await promises.mkdir(keysDirPath, { recursive: true });
44
- 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]) {
45
- try {
46
- keyPaths[keyData.locator] = await downloadAndSaveKey(keyData, keysDirPath);
47
- }
48
- catch (error) {
49
- throw (`Failed to download ${keyData.locator} - ${error}`);
50
- }
51
- }
52
- return keyPaths;
53
- }
54
- async function getLocalKey(filePath) {
55
- try {
56
- console.log("Reading key file:", filePath);
57
- const buffer = await promises.readFile(filePath);
58
- return new Uint8Array(buffer);
59
- }
60
- catch (error) {
61
- console.error("Error reading file:", error);
62
- throw error;
63
- }
64
- }
65
-
66
- await initThreadPool();
67
- /// Build transfer public transaction without connection to the internet
68
- async function buildTransferPublicTxOffline(recipientAddress, amount, latestStateRoot, keyPaths) {
69
- // Create an offline program manager
70
- const programManager = new ProgramManager();
71
- // Create a temporary account for the execution of the program
72
- const account = new Account();
73
- programManager.setAccount(account);
74
- // Create the proving keys from the key bytes on the offline machine
75
- console.log("Creating proving keys from local key files");
76
- const feePublicKeyBytes = await getLocalKey(keyPaths[CREDITS_PROGRAM_KEYS.fee_public.locator]);
77
- const feePublicProvingKey = ProvingKey.fromBytes(feePublicKeyBytes);
78
- const transferPublicProvingKey = ProvingKey.fromBytes(await getLocalKey(keyPaths[CREDITS_PROGRAM_KEYS.transfer_public.locator]));
79
- // Create an offline key provider
80
- console.log("Creating offline key provider");
81
- const offlineKeyProvider = new OfflineKeyProvider();
82
- // Insert the proving keys into the offline key provider. The key provider will automatically insert the verifying
83
- // keys into the key manager.
84
- console.log("Inserting proving keys into key provider");
85
- offlineKeyProvider.insertFeePublicKeys(feePublicProvingKey);
86
- try {
87
- offlineKeyProvider.insertTransferPublicKeys(transferPublicProvingKey);
88
- console.log("Successfully inserted proving key");
89
- }
90
- catch (err) {
91
- console.error("Failed to insert proving key:", err);
92
- }
93
- // Create an offline query to complete the inclusion proof
94
- let offlineQuery;
95
- const blockHeight = 0;
96
- // TODO this is a placeholder block height for now, which offlineQuery now requires
97
- try {
98
- const offlineQuery = new OfflineQuery(blockHeight, latestStateRoot);
99
- console.log("Successfully created OfflineQuery", offlineQuery);
100
- }
101
- catch (err) {
102
- console.error("Failed to create OfflineQuery:", err);
103
- }
104
- // Insert the key provider into the program manager
105
- programManager.setKeyProvider(offlineKeyProvider);
106
- // Build tne transfer_public transaction offline
107
- console.log("Building transfer transaction offline");
108
- return programManager.buildTransferPublicAsSignerTransaction(amount, recipientAddress.to_string(), 0.28, undefined, offlineQuery);
109
- }
110
- /// Build bonding and unbonding transactions without connection to the internet
111
- async function buildBondingTxOffline(validatorAddress, withdrawalAddress, amount, latestStateRoot, keyPaths) {
112
- // Create an offline program manager
113
- const programManager = new ProgramManager();
114
- // Create a temporary account for the execution of the program
115
- const account = new Account();
116
- programManager.setAccount(account);
117
- // Create the proving keys from the key bytes on the offline machine
118
- console.log("Creating proving keys from local key files");
119
- const feePublicKeyBytes = await getLocalKey(keyPaths[CREDITS_PROGRAM_KEYS.fee_public.locator]);
120
- const bondPublicKeyBytes = await getLocalKey(keyPaths[CREDITS_PROGRAM_KEYS.bond_public.locator]);
121
- const unbondPublicKeyBytes = await getLocalKey(keyPaths[CREDITS_PROGRAM_KEYS.unbond_public.locator]);
122
- const claimUnbondPublicKeyBytes = await getLocalKey(keyPaths[CREDITS_PROGRAM_KEYS.claim_unbond_public.locator]);
123
- const feePublicProvingKey = ProvingKey.fromBytes(feePublicKeyBytes);
124
- const bondPublicProvingKey = ProvingKey.fromBytes(bondPublicKeyBytes);
125
- const unBondPublicProvingKey = ProvingKey.fromBytes(unbondPublicKeyBytes);
126
- const claimUnbondPublicProvingKey = ProvingKey.fromBytes(claimUnbondPublicKeyBytes);
127
- // Create an offline key provider to fetch keys without connection to the internet
128
- console.log("Creating offline key provider");
129
- const offlineKeyProvider = new OfflineKeyProvider();
130
- // Insert the proving keys into the offline key provider
131
- console.log("Inserting proving keys into key provider");
132
- offlineKeyProvider.insertFeePublicKeys(feePublicProvingKey);
133
- offlineKeyProvider.insertBondPublicKeys(bondPublicProvingKey);
134
- offlineKeyProvider.insertUnbondPublicKeys(unBondPublicProvingKey);
135
- offlineKeyProvider.insertClaimUnbondPublicKeys(claimUnbondPublicProvingKey);
136
- // Insert the key provider into the program manager
137
- programManager.setKeyProvider(offlineKeyProvider);
138
- // Build the bonding transactions offline
139
- console.log("Building a bond_public execution transaction offline");
140
- const bondPublicOptions = {
141
- keySearchParams: OfflineSearchParams.bondPublicKeyParams(),
142
- offlineQuery: new OfflineQuery(0, latestStateRoot)
143
- };
144
- const bondTx = await programManager.buildBondPublicTransaction(validatorAddress.to_string(), withdrawalAddress.to_string(), amount, bondPublicOptions);
145
- console.log("\nbond_public transaction built!\n");
146
- const unbondPublicOptions = {
147
- keySearchParams: OfflineSearchParams.unbondPublicKeyParams(),
148
- offlineQuery: new OfflineQuery(0, latestStateRoot)
149
- };
150
- const unBondTx = await programManager.buildUnbondPublicTransaction(stakerAddress.to_string(), amount, unbondPublicOptions);
151
- console.log("\nunbond_public transaction built!\n");
152
- console.log("Building a claim_unbond_public transaction offline");
153
- const claimUnbondPublicOptions = {
154
- keySearchParams: OfflineSearchParams.claimUnbondPublicKeyParams(),
155
- offlineQuery: new OfflineQuery(0, latestStateRoot)
156
- };
157
- const claimUnbondTx = await programManager.buildClaimUnbondPublicTransaction(stakerAddress.to_string(), claimUnbondPublicOptions);
158
- console.log("\nclaim_unbond_public transaction built!\n");
159
- return [bondTx, unBondTx, claimUnbondTx];
160
- }
161
- // -------------------ONLINE COMPONENT---------------------
162
- // (Do this part on an internet connected machine)
163
- // Download the needed keys for the functions we want to execute offline
164
- const transferKeyPaths = await preDownloadTransferKeys();
165
- const bondingKeyPaths = await preDownloadBondingKeys();
166
- //---------------------------------------------------------
167
- // ------------------OFFLINE COMPONENT---------------------
168
- // (Do this part on an offline machine)
169
- // Get the latest state root from an online machine and enter it into an offline machine
170
- const latestStateRoot = "sr1p93gpsezrjzdhcd2wujznx5s07k8qa39t6vfcej35zew8vn2jyrs46te8q";
171
- // Build a transfer_public transaction
172
- const stakerAddress = new Account().address();
173
- const validatorAddress = new Account().address();
174
- const withdrawalAddress = new Account().address();
175
- const transferTx = await buildTransferPublicTxOffline(stakerAddress, 10000, latestStateRoot, transferKeyPaths);
176
- console.log("Transfer transaction built offline!");
177
- console.log(`\n---------------transfer_public transaction---------------\n${transferTx}`);
178
- console.log(`---------------------------------------------------------`);
179
- // Build bonding & unbonding transactions
180
- const bondTransactions = await buildBondingTxOffline(validatorAddress, withdrawalAddress, 100, latestStateRoot, bondingKeyPaths);
181
- console.log("Bonding transactions built offline!");
182
- console.log(`\n-----------------bond_public transaction-----------------\n${bondTransactions[0]}`);
183
- console.log(`---------------------------------------------------------`);
184
- console.log(`\n----------------unbond_public transaction:---------------\n${bondTransactions[1]}`);
185
- console.log(`---------------------------------------------------------`);
186
- console.log(`\n-----------------claim_unbond_public transaction:---------------\n${bondTransactions[2]}`);
187
- console.log(`---------------------------------------------------------`);
188
- //---------------------------------------------------------
189
- // -------------------ONLINE COMPONENT---------------------
190
- // (Do this part on an internet connected machine)
191
- // ONLINE COMPONENT (Uncomment this part to send the transaction to the Aleo Network on an internet connected machine)
192
- // Submit the transaction to the network
193
- // const transferTxId = await networkClient.submitTransaction(transferTx);
194
- //---------------------------------------------------------
195
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}