@provablehq/sdk 0.6.9
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/README.md +1172 -0
- package/dist/account.d.ts +137 -0
- package/dist/function-key-provider.d.ts +336 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +3049 -0
- package/dist/index.js.map +1 -0
- package/dist/managed-worker.d.ts +3 -0
- package/dist/models/block.d.ts +21 -0
- package/dist/models/confirmed_transaction.d.ts +6 -0
- package/dist/models/execution.d.ts +5 -0
- package/dist/models/input.d.ts +10 -0
- package/dist/models/output.d.ts +6 -0
- package/dist/models/transactionModel.d.ts +6 -0
- package/dist/models/transition.d.ts +13 -0
- package/dist/network-client.d.ts +267 -0
- package/dist/node-polyfill.d.ts +4 -0
- package/dist/node-polyfill.js +302 -0
- package/dist/node-polyfill.js.map +1 -0
- package/dist/node.d.ts +2 -0
- package/dist/node.js +11 -0
- package/dist/node.js.map +1 -0
- package/dist/offline-key-provider.d.ts +347 -0
- package/dist/polyfill/crypto.d.ts +1 -0
- package/dist/polyfill/fetch.d.ts +1 -0
- package/dist/polyfill/worker.d.ts +1 -0
- package/dist/polyfill/xmlhttprequest.d.ts +1 -0
- package/dist/program-manager.d.ts +639 -0
- package/dist/record-provider.d.ts +236 -0
- package/dist/utils.d.ts +2 -0
- package/dist/worker.d.ts +8 -0
- package/dist/worker.js +74 -0
- package/dist/worker.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { RecordPlaintext } from "./index";
|
|
2
|
+
import { Account } from "./account";
|
|
3
|
+
import { AleoNetworkClient } from "./network-client";
|
|
4
|
+
/**
|
|
5
|
+
* Interface for record search parameters. This allows for arbitrary search parameters to be passed to record provider
|
|
6
|
+
* implementations.
|
|
7
|
+
*/
|
|
8
|
+
interface RecordSearchParams {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Interface for a record provider. A record provider is used to find records for use in deployment and execution
|
|
13
|
+
* transactions on the Aleo Network. A default implementation is provided by the NetworkRecordProvider class. However,
|
|
14
|
+
* a custom implementation can be provided (say if records are synced locally to a database from the network) by
|
|
15
|
+
* implementing this interface.
|
|
16
|
+
*/
|
|
17
|
+
interface RecordProvider {
|
|
18
|
+
account: Account;
|
|
19
|
+
/**
|
|
20
|
+
* Find a credits.aleo record with a given number of microcredits from the chosen provider
|
|
21
|
+
*
|
|
22
|
+
* @param {number} microcredits The number of microcredits to search for
|
|
23
|
+
* @param {boolean} unspent Whether or not the record is unspent
|
|
24
|
+
* @param {string[]} nonces Nonces of records already found so they are not found again
|
|
25
|
+
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
26
|
+
* @returns {Promise<RecordPlaintext | Error>} The record if found, otherwise an error
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // A class implementing record provider can be used to find a record with a given number of microcredits
|
|
30
|
+
* const record = await recordProvider.findCreditsRecord(5000, true, []);
|
|
31
|
+
*
|
|
32
|
+
* // When a record is found but not yet used, its nonce should be added to the nonces array so that it is not
|
|
33
|
+
* // found again if a subsequent search is performed
|
|
34
|
+
* const record2 = await recordProvider.findCreditsRecord(5000, true, [record.nonce()]);
|
|
35
|
+
*
|
|
36
|
+
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
37
|
+
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
38
|
+
* const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
|
|
39
|
+
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
40
|
+
*/
|
|
41
|
+
findCreditsRecord(microcredits: number, unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext | Error>;
|
|
42
|
+
/**
|
|
43
|
+
* Find a list of credit.aleo records with a given number of microcredits from the chosen provider
|
|
44
|
+
*
|
|
45
|
+
* @param {number} microcreditAmounts A list of separate microcredit amounts to search for (e.g. [5000, 100000])
|
|
46
|
+
* @param {boolean} unspent Whether or not the record is unspent
|
|
47
|
+
* @param {string[]} nonces Nonces of records already found so that they are not found again
|
|
48
|
+
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
49
|
+
* @returns {Promise<RecordPlaintext[] | Error>} A list of records with a value greater or equal to the amounts specified if such records exist, otherwise an error
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // A class implementing record provider can be used to find a record with a given number of microcredits
|
|
53
|
+
* const records = await recordProvider.findCreditsRecords([5000, 5000], true, []);
|
|
54
|
+
*
|
|
55
|
+
* // When a record is found but not yet used, it's nonce should be added to the nonces array so that it is not
|
|
56
|
+
* // found again if a subsequent search is performed
|
|
57
|
+
* const nonces = [];
|
|
58
|
+
* records.forEach(record => { nonces.push(record.nonce()) });
|
|
59
|
+
* const records2 = await recordProvider.findCreditsRecord(5000, true, nonces);
|
|
60
|
+
*
|
|
61
|
+
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
62
|
+
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
63
|
+
* const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
|
|
64
|
+
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
65
|
+
*/
|
|
66
|
+
findCreditsRecords(microcreditAmounts: number[], unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[] | Error>;
|
|
67
|
+
/**
|
|
68
|
+
* Find an arbitrary record
|
|
69
|
+
* @param {boolean} unspent Whether or not the record is unspent
|
|
70
|
+
* @param {string[]} nonces Nonces of records already found so that they are not found again
|
|
71
|
+
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
72
|
+
* @returns {Promise<RecordPlaintext | Error>} The record if found, otherwise an error
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* // The RecordSearchParams interface can be used to create parameters for custom record searches which can then
|
|
76
|
+
* // be passed to the record provider. An example of how this would be done for the credits.aleo program is shown
|
|
77
|
+
* // below.
|
|
78
|
+
*
|
|
79
|
+
* class CustomRecordSearch implements RecordSearchParams {
|
|
80
|
+
* startHeight: number;
|
|
81
|
+
* endHeight: number;
|
|
82
|
+
* amount: number;
|
|
83
|
+
* program: string;
|
|
84
|
+
* recordName: string;
|
|
85
|
+
* constructor(startHeight: number, endHeight: number, credits: number, maxRecords: number, programName: string, recordName: string) {
|
|
86
|
+
* this.startHeight = startHeight;
|
|
87
|
+
* this.endHeight = endHeight;
|
|
88
|
+
* this.amount = amount;
|
|
89
|
+
* this.program = programName;
|
|
90
|
+
* this.recordName = recordName;
|
|
91
|
+
* }
|
|
92
|
+
* }
|
|
93
|
+
*
|
|
94
|
+
* const params = new CustomRecordSearch(0, 100, 5000, "credits.aleo", "credits");
|
|
95
|
+
*
|
|
96
|
+
* const record = await recordProvider.findRecord(true, [], params);
|
|
97
|
+
*/
|
|
98
|
+
findRecord(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext | Error>;
|
|
99
|
+
/**
|
|
100
|
+
* Find multiple records from arbitrary programs
|
|
101
|
+
*
|
|
102
|
+
* @param {boolean} unspent Whether or not the record is unspent
|
|
103
|
+
* @param {string[]} nonces Nonces of records already found so that they are not found again
|
|
104
|
+
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
105
|
+
* @returns {Promise<RecordPlaintext | Error>} The record if found, otherwise an error
|
|
106
|
+
*
|
|
107
|
+
* // The RecordSearchParams interface can be used to create parameters for custom record searches which can then
|
|
108
|
+
* // be passed to the record provider. An example of how this would be done for the credits.aleo program is shown
|
|
109
|
+
* // below.
|
|
110
|
+
*
|
|
111
|
+
* class CustomRecordSearch implements RecordSearchParams {
|
|
112
|
+
* startHeight: number;
|
|
113
|
+
* endHeight: number;
|
|
114
|
+
* amount: number;
|
|
115
|
+
* maxRecords: number;
|
|
116
|
+
* programName: string;
|
|
117
|
+
* recordName: string;
|
|
118
|
+
* constructor(startHeight: number, endHeight: number, credits: number, maxRecords: number, programName: string, recordName: string) {
|
|
119
|
+
* this.startHeight = startHeight;
|
|
120
|
+
* this.endHeight = endHeight;
|
|
121
|
+
* this.amount = amount;
|
|
122
|
+
* this.maxRecords = maxRecords;
|
|
123
|
+
* this.programName = programName;
|
|
124
|
+
* this.recordName = recordName;
|
|
125
|
+
* }
|
|
126
|
+
* }
|
|
127
|
+
*
|
|
128
|
+
* const params = new CustomRecordSearch(0, 100, 5000, 2, "credits.aleo", "credits");
|
|
129
|
+
* const records = await recordProvider.findRecord(true, [], params);
|
|
130
|
+
*/
|
|
131
|
+
findRecords(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[] | Error>;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* A record provider implementation that uses the official Aleo API to find records for usage in program execution and
|
|
135
|
+
* deployment, wallet functionality, and other use cases.
|
|
136
|
+
*/
|
|
137
|
+
declare class NetworkRecordProvider implements RecordProvider {
|
|
138
|
+
account: Account;
|
|
139
|
+
networkClient: AleoNetworkClient;
|
|
140
|
+
constructor(account: Account, networkClient: AleoNetworkClient);
|
|
141
|
+
/**
|
|
142
|
+
* Set the account used to search for records
|
|
143
|
+
*
|
|
144
|
+
* @param {Account} account The account to use for searching for records
|
|
145
|
+
*/
|
|
146
|
+
setAccount(account: Account): void;
|
|
147
|
+
/**
|
|
148
|
+
* Find a list of credit records with a given number of microcredits by via the official Aleo API
|
|
149
|
+
*
|
|
150
|
+
* @param {number[]} microcredits The number of microcredits to search for
|
|
151
|
+
* @param {boolean} unspent Whether or not the record is unspent
|
|
152
|
+
* @param {string[]} nonces Nonces of records already found so that they are not found again
|
|
153
|
+
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
154
|
+
* @returns {Promise<RecordPlaintext | Error>} The record if found, otherwise an error
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* // Create a new NetworkRecordProvider
|
|
158
|
+
* const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
|
|
159
|
+
* const keyProvider = new AleoKeyProvider();
|
|
160
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
161
|
+
*
|
|
162
|
+
* // The record provider can be used to find records with a given number of microcredits
|
|
163
|
+
* const record = await recordProvider.findCreditsRecord(5000, true, []);
|
|
164
|
+
*
|
|
165
|
+
* // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
|
|
166
|
+
* // found again if a subsequent search is performed
|
|
167
|
+
* const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
|
|
168
|
+
*
|
|
169
|
+
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
170
|
+
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
171
|
+
* const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
|
|
172
|
+
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
173
|
+
*
|
|
174
|
+
* */
|
|
175
|
+
findCreditsRecords(microcredits: number[], unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[] | Error>;
|
|
176
|
+
/**
|
|
177
|
+
* Find a credit record with a given number of microcredits by via the official Aleo API
|
|
178
|
+
*
|
|
179
|
+
* @param {number} microcredits The number of microcredits to search for
|
|
180
|
+
* @param {boolean} unspent Whether or not the record is unspent
|
|
181
|
+
* @param {string[]} nonces Nonces of records already found so that they are not found again
|
|
182
|
+
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
183
|
+
* @returns {Promise<RecordPlaintext | Error>} The record if found, otherwise an error
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* // Create a new NetworkRecordProvider
|
|
187
|
+
* const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
|
|
188
|
+
* const keyProvider = new AleoKeyProvider();
|
|
189
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
190
|
+
*
|
|
191
|
+
* // The record provider can be used to find records with a given number of microcredits
|
|
192
|
+
* const record = await recordProvider.findCreditsRecord(5000, true, []);
|
|
193
|
+
*
|
|
194
|
+
* // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
|
|
195
|
+
* // found again if a subsequent search is performed
|
|
196
|
+
* const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
|
|
197
|
+
*
|
|
198
|
+
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
199
|
+
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
200
|
+
* const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
|
|
201
|
+
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
202
|
+
*/
|
|
203
|
+
findCreditsRecord(microcredits: number, unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext | Error>;
|
|
204
|
+
/**
|
|
205
|
+
* Find an arbitrary record. WARNING: This function is not implemented yet and will throw an error.
|
|
206
|
+
*/
|
|
207
|
+
findRecord(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext | Error>;
|
|
208
|
+
/**
|
|
209
|
+
* Find multiple arbitrary records. WARNING: This function is not implemented yet and will throw an error.
|
|
210
|
+
*/
|
|
211
|
+
findRecords(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[] | Error>;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* BlockHeightSearch is a RecordSearchParams implementation that allows for searching for records within a given
|
|
215
|
+
* block height range.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* // Create a new BlockHeightSearch
|
|
219
|
+
* const params = new BlockHeightSearch(89995, 99995);
|
|
220
|
+
*
|
|
221
|
+
* // Create a new NetworkRecordProvider
|
|
222
|
+
* const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
|
|
223
|
+
* const keyProvider = new AleoKeyProvider();
|
|
224
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
225
|
+
*
|
|
226
|
+
* // The record provider can be used to find records with a given number of microcredits and the block height search
|
|
227
|
+
* // can be used to find records within a given block height range
|
|
228
|
+
* const record = await recordProvider.findCreditsRecord(5000, true, [], params);
|
|
229
|
+
*
|
|
230
|
+
*/
|
|
231
|
+
declare class BlockHeightSearch implements RecordSearchParams {
|
|
232
|
+
startHeight: number;
|
|
233
|
+
endHeight: number;
|
|
234
|
+
constructor(startHeight: number, endHeight: number);
|
|
235
|
+
}
|
|
236
|
+
export { BlockHeightSearch, NetworkRecordProvider, RecordProvider, RecordSearchParams };
|
package/dist/utils.d.ts
ADDED
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PrivateKey } from "./index";
|
|
2
|
+
export interface WorkerAPI {
|
|
3
|
+
executeOffline: (localProgram: string, aleoFunction: string, inputs: string[], privateKey: string) => Promise<{
|
|
4
|
+
outputs: any;
|
|
5
|
+
execution: string;
|
|
6
|
+
} | string>;
|
|
7
|
+
getPrivateKey: () => Promise<PrivateKey>;
|
|
8
|
+
}
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ProgramManager, AleoKeyProvider, AleoKeyProviderParams } from './index.js';
|
|
2
|
+
import { expose } from 'comlink';
|
|
3
|
+
import { initThreadPool, PrivateKey, verifyFunctionExecution } from '@provablehq/wasm';
|
|
4
|
+
|
|
5
|
+
await initThreadPool();
|
|
6
|
+
const defaultHost = "https://api.explorer.aleo.org/v1";
|
|
7
|
+
const keyProvider = new AleoKeyProvider();
|
|
8
|
+
const programManager = new ProgramManager(defaultHost, keyProvider, undefined);
|
|
9
|
+
keyProvider.useCache(true);
|
|
10
|
+
let lastLocalProgram = "";
|
|
11
|
+
async function executeOffline(localProgram, aleoFunction, inputs, privateKey, proveExecution = false) {
|
|
12
|
+
console.log("Web worker: Executing function locally...");
|
|
13
|
+
const startTime = performance.now();
|
|
14
|
+
try {
|
|
15
|
+
// Ensure the program is valid and that it contains the function specified
|
|
16
|
+
const program = programManager.createProgramFromSource(localProgram);
|
|
17
|
+
if (program instanceof Error) {
|
|
18
|
+
throw "Error creating program from source";
|
|
19
|
+
}
|
|
20
|
+
const program_id = program.id();
|
|
21
|
+
if (!program.hasFunction(aleoFunction)) {
|
|
22
|
+
throw `Program ${program_id} does not contain function ${aleoFunction}`;
|
|
23
|
+
}
|
|
24
|
+
const cacheKey = `${program_id}:${aleoFunction}`;
|
|
25
|
+
// Get the program imports
|
|
26
|
+
const imports = await programManager.networkClient.getProgramImports(localProgram);
|
|
27
|
+
if (imports instanceof Error) {
|
|
28
|
+
throw "Error getting program imports";
|
|
29
|
+
}
|
|
30
|
+
// Get the proving and verifying keys for the function
|
|
31
|
+
if (lastLocalProgram !== localProgram) {
|
|
32
|
+
const keys = await programManager.synthesizeKeys(localProgram, aleoFunction, inputs, PrivateKey.from_string(privateKey));
|
|
33
|
+
programManager.keyProvider.cacheKeys(cacheKey, keys);
|
|
34
|
+
lastLocalProgram = localProgram;
|
|
35
|
+
}
|
|
36
|
+
// Pass the cache key to the execute function
|
|
37
|
+
const keyParams = new AleoKeyProviderParams({
|
|
38
|
+
cacheKey: cacheKey,
|
|
39
|
+
});
|
|
40
|
+
// Execute the function locally
|
|
41
|
+
const response = await programManager.run(localProgram, aleoFunction, inputs, proveExecution, imports, keyParams, undefined, undefined, PrivateKey.from_string(privateKey));
|
|
42
|
+
// Return the outputs to the main thread
|
|
43
|
+
console.log(`Web worker: Local execution completed in ${performance.now() - startTime} ms`);
|
|
44
|
+
const outputs = response.getOutputs();
|
|
45
|
+
const execution = response.getExecution();
|
|
46
|
+
let executionString = "";
|
|
47
|
+
const keys = keyProvider.getKeys(cacheKey);
|
|
48
|
+
if (keys instanceof Error) {
|
|
49
|
+
throw "Could not get verifying key";
|
|
50
|
+
}
|
|
51
|
+
const verifyingKey = keys[1];
|
|
52
|
+
if (execution) {
|
|
53
|
+
verifyFunctionExecution(execution, verifyingKey, program, "hello");
|
|
54
|
+
executionString = execution.toString();
|
|
55
|
+
console.log("Execution verified successfully: " + execution);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
executionString = "";
|
|
59
|
+
}
|
|
60
|
+
console.log(`Function execution response: ${outputs}`);
|
|
61
|
+
return { outputs: outputs, execution: executionString };
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.error(error);
|
|
65
|
+
return error ? error.toString() : "Unknown error";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function getPrivateKey() {
|
|
69
|
+
const privateKey = new PrivateKey();
|
|
70
|
+
return privateKey.to_string();
|
|
71
|
+
}
|
|
72
|
+
const workerAPI = { executeOffline, getPrivateKey };
|
|
73
|
+
expose(workerAPI);
|
|
74
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sources":["../src/worker.ts"],"sourcesContent":["import {initThreadPool, ProgramManager, PrivateKey, verifyFunctionExecution, FunctionKeyPair} from \"./index\";\nimport { AleoKeyProvider, AleoKeyProviderParams} from \"./function-key-provider\";\nimport { expose } from \"comlink\";\n\nawait initThreadPool();\n\nconst defaultHost = \"https://api.explorer.aleo.org/v1\";\nconst keyProvider = new AleoKeyProvider();\nconst programManager = new ProgramManager(\n defaultHost,\n keyProvider,\n undefined\n);\n\nkeyProvider.useCache(true);\n\nlet lastLocalProgram: string = \"\";\n\nexport interface WorkerAPI {\n executeOffline: (\n localProgram: string,\n aleoFunction: string,\n inputs: string[],\n privateKey: string\n ) => Promise<{ outputs: any; execution: string } | string>;\n\n getPrivateKey: () => Promise<PrivateKey>;\n}\nasync function executeOffline(\n localProgram: string,\n aleoFunction: string,\n inputs: string[],\n privateKey: string,\n proveExecution = false\n) {\n console.log(\"Web worker: Executing function locally...\");\n const startTime = performance.now();\n\n try {\n // Ensure the program is valid and that it contains the function specified\n const program = programManager.createProgramFromSource(localProgram);\n if (program instanceof Error) {\n throw \"Error creating program from source\";\n }\n const program_id = program.id();\n if (!program.hasFunction(aleoFunction)) {\n throw `Program ${program_id} does not contain function ${aleoFunction}`;\n }\n const cacheKey = `${program_id}:${aleoFunction}`;\n\n // Get the program imports\n const imports = await programManager.networkClient.getProgramImports(\n localProgram\n );\n\n if (imports instanceof Error) {\n throw \"Error getting program imports\";\n }\n // Get the proving and verifying keys for the function\n if (lastLocalProgram !== localProgram) {\n const keys = <FunctionKeyPair>await programManager.synthesizeKeys(\n localProgram,\n aleoFunction,\n inputs,\n PrivateKey.from_string(privateKey)\n );\n programManager.keyProvider.cacheKeys(cacheKey, keys);\n lastLocalProgram = localProgram;\n }\n\n // Pass the cache key to the execute function\n const keyParams = new AleoKeyProviderParams({\n cacheKey: cacheKey,\n });\n\n // Execute the function locally\n const response = await programManager.run(\n localProgram,\n aleoFunction,\n inputs,\n proveExecution,\n imports,\n keyParams,\n undefined,\n undefined,\n PrivateKey.from_string(privateKey),\n );\n\n // Return the outputs to the main thread\n console.log(\n `Web worker: Local execution completed in ${\n performance.now() - startTime\n } ms`\n );\n const outputs = response.getOutputs();\n const execution = response.getExecution();\n let executionString = \"\";\n\n const keys = keyProvider.getKeys(cacheKey);\n\n if (keys instanceof Error) {\n throw \"Could not get verifying key\";\n }\n\n const verifyingKey = keys[1];\n\n if (execution) {\n verifyFunctionExecution(\n execution,\n verifyingKey,\n program,\n \"hello\"\n );\n executionString = execution.toString();\n console.log(\"Execution verified successfully: \" + execution);\n } else {\n executionString = \"\";\n }\n\n console.log(`Function execution response: ${outputs}`);\n\n return { outputs: outputs, execution: executionString };\n } catch (error) {\n console.error(error);\n return error ? error.toString() : \"Unknown error\";\n }\n}\n\nasync function getPrivateKey() {\n const privateKey = new PrivateKey();\n return privateKey.to_string();\n}\n\nconst workerAPI = { executeOffline, getPrivateKey };\nexpose(workerAPI);\n"],"names":[],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@provablehq/sdk",
|
|
3
|
+
"version": "0.6.9",
|
|
4
|
+
"description": "A Software Development Kit (SDK) for Zero-Knowledge Transactions",
|
|
5
|
+
"collaborators": [
|
|
6
|
+
"The Provable Team <hello@provable.com>"
|
|
7
|
+
],
|
|
8
|
+
"license": "GPL-3.0",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./dist/node.js",
|
|
11
|
+
"browser": "./dist/index.js",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"node": "./dist/node.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "rimraf dist && rollup -c rollup.config.js",
|
|
25
|
+
"prepublish": "yarn build",
|
|
26
|
+
"test": "node --no-warnings --experimental-vm-modules ../node_modules/jest/bin/jest.js --config jest-config.json --detectOpenHandles",
|
|
27
|
+
"integration": "node --no-warnings --experimental-vm-modules ../node_modules/jest/bin/jest.js --silent=false --runInBand --detectOpenHandles",
|
|
28
|
+
"clear_jest": "jest --clearCache"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/ProvableHQ/sdk.git"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"Aleo",
|
|
36
|
+
"Blockchain",
|
|
37
|
+
"Zero Knowledge",
|
|
38
|
+
"ZK"
|
|
39
|
+
],
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/ProvableHQ/sdk/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/ProvableHQ/sdk#readme",
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@provablehq/wasm": "^0.6.0",
|
|
46
|
+
"comlink": "^4.4.1",
|
|
47
|
+
"mime": "^3.0.0",
|
|
48
|
+
"sync-request": "^6.1.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@rollup/plugin-replace": "^5.0.5",
|
|
52
|
+
"@types/jest": "^29.5.5",
|
|
53
|
+
"@types/mime": "^3.0.1",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^5.41.0",
|
|
55
|
+
"@typescript-eslint/parser": "^5.41.0",
|
|
56
|
+
"better-docs": "^2.7.2",
|
|
57
|
+
"clean-jsdoc-theme": "^4.1.8",
|
|
58
|
+
"cpr": "^3.0.1",
|
|
59
|
+
"eslint": "^8.26.0",
|
|
60
|
+
"eslint-config-prettier": "^8.5.0",
|
|
61
|
+
"eslint-plugin-import": "^2.26.0",
|
|
62
|
+
"jest": "^29.7.0",
|
|
63
|
+
"jsdoc": "^3.6.11",
|
|
64
|
+
"prettier": "2.7.1",
|
|
65
|
+
"rimraf": "^5.0.1",
|
|
66
|
+
"rollup": "^3.27.2",
|
|
67
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
68
|
+
"ts-jest": "^29.1.1",
|
|
69
|
+
"typescript": "^5.2.2"
|
|
70
|
+
}
|
|
71
|
+
}
|