@provablehq/sdk 0.6.12 → 0.7.0
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 +16 -16
- package/dist/{account.d.ts → mainnet/account.d.ts} +3 -3
- package/dist/{index.d.ts → mainnet/browser.d.ts} +5 -4
- package/dist/mainnet/browser.js +3127 -0
- package/dist/mainnet/browser.js.map +1 -0
- package/dist/{function-key-provider.d.ts → mainnet/function-key-provider.d.ts} +57 -57
- package/dist/{network-client.d.ts → mainnet/network-client.d.ts} +26 -26
- package/dist/{node-polyfill.d.ts → mainnet/node-polyfill.d.ts} +1 -0
- package/dist/{node-polyfill.js → mainnet/node-polyfill.js} +1 -0
- package/dist/mainnet/node-polyfill.js.map +1 -0
- package/dist/mainnet/node.d.ts +2 -0
- package/dist/{node.js → mainnet/node.js} +3 -2
- package/dist/{node.js.map → mainnet/node.js.map} +1 -1
- package/dist/{offline-key-provider.d.ts → mainnet/offline-key-provider.d.ts} +22 -22
- package/dist/mainnet/polyfill/shared.d.ts +1 -0
- package/dist/{program-manager.d.ts → mainnet/program-manager.d.ts} +59 -59
- package/dist/{record-provider.d.ts → mainnet/record-provider.d.ts} +22 -22
- package/dist/{utils.d.ts → mainnet/utils.d.ts} +1 -0
- package/dist/{worker.d.ts → mainnet/worker.d.ts} +2 -1
- package/dist/mainnet/worker.js +78 -0
- package/dist/mainnet/worker.js.map +1 -0
- package/dist/testnet/account.d.ts +137 -0
- package/dist/testnet/browser.d.ts +53 -0
- package/dist/{index.js → testnet/browser.js} +197 -186
- package/dist/testnet/browser.js.map +1 -0
- package/dist/testnet/function-key-provider.d.ts +348 -0
- package/dist/testnet/managed-worker.d.ts +3 -0
- package/dist/testnet/models/block.d.ts +21 -0
- package/dist/testnet/models/confirmed_transaction.d.ts +6 -0
- package/dist/testnet/models/execution.d.ts +5 -0
- package/dist/testnet/models/input.d.ts +10 -0
- package/dist/testnet/models/output.d.ts +6 -0
- package/dist/testnet/models/transactionModel.d.ts +6 -0
- package/dist/testnet/models/transition.d.ts +13 -0
- package/dist/testnet/network-client.d.ts +267 -0
- package/dist/testnet/node-polyfill.d.ts +5 -0
- package/dist/testnet/node-polyfill.js +303 -0
- package/dist/testnet/node-polyfill.js.map +1 -0
- package/dist/testnet/node.d.ts +2 -0
- package/dist/testnet/node.js +12 -0
- package/dist/testnet/node.js.map +1 -0
- package/dist/testnet/offline-key-provider.d.ts +347 -0
- package/dist/testnet/polyfill/crypto.d.ts +1 -0
- package/dist/testnet/polyfill/fetch.d.ts +1 -0
- package/dist/testnet/polyfill/shared.d.ts +1 -0
- package/dist/testnet/polyfill/worker.d.ts +1 -0
- package/dist/testnet/polyfill/xmlhttprequest.d.ts +1 -0
- package/dist/testnet/program-manager.d.ts +636 -0
- package/dist/testnet/record-provider.d.ts +236 -0
- package/dist/testnet/utils.d.ts +3 -0
- package/dist/testnet/worker.d.ts +9 -0
- package/dist/testnet/worker.js +78 -0
- package/dist/testnet/worker.js.map +1 -0
- package/package.json +23 -13
- package/dist/index.js.map +0 -1
- package/dist/node-polyfill.js.map +0 -1
- package/dist/node.d.ts +0 -2
- package/dist/worker.js +0 -74
- package/dist/worker.js.map +0 -1
- /package/dist/{managed-worker.d.ts → mainnet/managed-worker.d.ts} +0 -0
- /package/dist/{models → mainnet/models}/block.d.ts +0 -0
- /package/dist/{models → mainnet/models}/confirmed_transaction.d.ts +0 -0
- /package/dist/{models → mainnet/models}/execution.d.ts +0 -0
- /package/dist/{models → mainnet/models}/input.d.ts +0 -0
- /package/dist/{models → mainnet/models}/output.d.ts +0 -0
- /package/dist/{models → mainnet/models}/transactionModel.d.ts +0 -0
- /package/dist/{models → mainnet/models}/transition.d.ts +0 -0
- /package/dist/{polyfill → mainnet/polyfill}/crypto.d.ts +0 -0
- /package/dist/{polyfill → mainnet/polyfill}/fetch.d.ts +0 -0
- /package/dist/{polyfill → mainnet/polyfill}/worker.d.ts +0 -0
- /package/dist/{polyfill → mainnet/polyfill}/xmlhttprequest.d.ts +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RecordPlaintext } from "./
|
|
1
|
+
import { RecordPlaintext } from "./browser";
|
|
2
2
|
import { Account } from "./account";
|
|
3
3
|
import { AleoNetworkClient } from "./network-client";
|
|
4
4
|
/**
|
|
@@ -23,7 +23,7 @@ interface RecordProvider {
|
|
|
23
23
|
* @param {boolean} unspent Whether or not the record is unspent
|
|
24
24
|
* @param {string[]} nonces Nonces of records already found so they are not found again
|
|
25
25
|
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
26
|
-
* @returns {Promise<RecordPlaintext
|
|
26
|
+
* @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* // A class implementing record provider can be used to find a record with a given number of microcredits
|
|
@@ -35,10 +35,10 @@ interface RecordProvider {
|
|
|
35
35
|
*
|
|
36
36
|
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
37
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.
|
|
38
|
+
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
39
39
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
40
40
|
*/
|
|
41
|
-
findCreditsRecord(microcredits: number, unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext
|
|
41
|
+
findCreditsRecord(microcredits: number, unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext>;
|
|
42
42
|
/**
|
|
43
43
|
* Find a list of credit.aleo records with a given number of microcredits from the chosen provider
|
|
44
44
|
*
|
|
@@ -46,7 +46,7 @@ interface RecordProvider {
|
|
|
46
46
|
* @param {boolean} unspent Whether or not the record is unspent
|
|
47
47
|
* @param {string[]} nonces Nonces of records already found so that they are not found again
|
|
48
48
|
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
49
|
-
* @returns {Promise<RecordPlaintext[]
|
|
49
|
+
* @returns {Promise<RecordPlaintext[]>} A list of records with a value greater or equal to the amounts specified if such records exist, otherwise an error
|
|
50
50
|
*
|
|
51
51
|
* @example
|
|
52
52
|
* // A class implementing record provider can be used to find a record with a given number of microcredits
|
|
@@ -60,16 +60,16 @@ interface RecordProvider {
|
|
|
60
60
|
*
|
|
61
61
|
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
62
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.
|
|
63
|
+
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
64
64
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
65
65
|
*/
|
|
66
|
-
findCreditsRecords(microcreditAmounts: number[], unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]
|
|
66
|
+
findCreditsRecords(microcreditAmounts: number[], unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]>;
|
|
67
67
|
/**
|
|
68
68
|
* Find an arbitrary record
|
|
69
69
|
* @param {boolean} unspent Whether or not the record is unspent
|
|
70
70
|
* @param {string[]} nonces Nonces of records already found so that they are not found again
|
|
71
71
|
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
72
|
-
* @returns {Promise<RecordPlaintext
|
|
72
|
+
* @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
|
|
73
73
|
*
|
|
74
74
|
* @example
|
|
75
75
|
* // The RecordSearchParams interface can be used to create parameters for custom record searches which can then
|
|
@@ -95,14 +95,14 @@ interface RecordProvider {
|
|
|
95
95
|
*
|
|
96
96
|
* const record = await recordProvider.findRecord(true, [], params);
|
|
97
97
|
*/
|
|
98
|
-
findRecord(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext
|
|
98
|
+
findRecord(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext>;
|
|
99
99
|
/**
|
|
100
100
|
* Find multiple records from arbitrary programs
|
|
101
101
|
*
|
|
102
102
|
* @param {boolean} unspent Whether or not the record is unspent
|
|
103
103
|
* @param {string[]} nonces Nonces of records already found so that they are not found again
|
|
104
104
|
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
105
|
-
* @returns {Promise<RecordPlaintext
|
|
105
|
+
* @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
|
|
106
106
|
*
|
|
107
107
|
* // The RecordSearchParams interface can be used to create parameters for custom record searches which can then
|
|
108
108
|
* // be passed to the record provider. An example of how this would be done for the credits.aleo program is shown
|
|
@@ -128,7 +128,7 @@ interface RecordProvider {
|
|
|
128
128
|
* const params = new CustomRecordSearch(0, 100, 5000, 2, "credits.aleo", "credits");
|
|
129
129
|
* const records = await recordProvider.findRecord(true, [], params);
|
|
130
130
|
*/
|
|
131
|
-
findRecords(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]
|
|
131
|
+
findRecords(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]>;
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
134
134
|
* A record provider implementation that uses the official Aleo API to find records for usage in program execution and
|
|
@@ -151,11 +151,11 @@ declare class NetworkRecordProvider implements RecordProvider {
|
|
|
151
151
|
* @param {boolean} unspent Whether or not the record is unspent
|
|
152
152
|
* @param {string[]} nonces Nonces of records already found so that they are not found again
|
|
153
153
|
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
154
|
-
* @returns {Promise<RecordPlaintext
|
|
154
|
+
* @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
|
|
155
155
|
*
|
|
156
156
|
* @example
|
|
157
157
|
* // Create a new NetworkRecordProvider
|
|
158
|
-
* const networkClient = new AleoNetworkClient("https://api.explorer.
|
|
158
|
+
* const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
|
|
159
159
|
* const keyProvider = new AleoKeyProvider();
|
|
160
160
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
161
161
|
*
|
|
@@ -168,11 +168,11 @@ declare class NetworkRecordProvider implements RecordProvider {
|
|
|
168
168
|
*
|
|
169
169
|
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
170
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.
|
|
171
|
+
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
172
172
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
173
173
|
*
|
|
174
174
|
* */
|
|
175
|
-
findCreditsRecords(microcredits: number[], unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]
|
|
175
|
+
findCreditsRecords(microcredits: number[], unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]>;
|
|
176
176
|
/**
|
|
177
177
|
* Find a credit record with a given number of microcredits by via the official Aleo API
|
|
178
178
|
*
|
|
@@ -180,11 +180,11 @@ declare class NetworkRecordProvider implements RecordProvider {
|
|
|
180
180
|
* @param {boolean} unspent Whether or not the record is unspent
|
|
181
181
|
* @param {string[]} nonces Nonces of records already found so that they are not found again
|
|
182
182
|
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
183
|
-
* @returns {Promise<RecordPlaintext
|
|
183
|
+
* @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
|
|
184
184
|
*
|
|
185
185
|
* @example
|
|
186
186
|
* // Create a new NetworkRecordProvider
|
|
187
|
-
* const networkClient = new AleoNetworkClient("https://api.explorer.
|
|
187
|
+
* const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
|
|
188
188
|
* const keyProvider = new AleoKeyProvider();
|
|
189
189
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
190
190
|
*
|
|
@@ -197,18 +197,18 @@ declare class NetworkRecordProvider implements RecordProvider {
|
|
|
197
197
|
*
|
|
198
198
|
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
199
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.
|
|
200
|
+
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
201
201
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
202
202
|
*/
|
|
203
|
-
findCreditsRecord(microcredits: number, unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext
|
|
203
|
+
findCreditsRecord(microcredits: number, unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext>;
|
|
204
204
|
/**
|
|
205
205
|
* Find an arbitrary record. WARNING: This function is not implemented yet and will throw an error.
|
|
206
206
|
*/
|
|
207
|
-
findRecord(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext
|
|
207
|
+
findRecord(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext>;
|
|
208
208
|
/**
|
|
209
209
|
* Find multiple arbitrary records. WARNING: This function is not implemented yet and will throw an error.
|
|
210
210
|
*/
|
|
211
|
-
findRecords(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]
|
|
211
|
+
findRecords(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]>;
|
|
212
212
|
}
|
|
213
213
|
/**
|
|
214
214
|
* BlockHeightSearch is a RecordSearchParams implementation that allows for searching for records within a given
|
|
@@ -219,7 +219,7 @@ declare class NetworkRecordProvider implements RecordProvider {
|
|
|
219
219
|
* const params = new BlockHeightSearch(89995, 99995);
|
|
220
220
|
*
|
|
221
221
|
* // Create a new NetworkRecordProvider
|
|
222
|
-
* const networkClient = new AleoNetworkClient("https://api.explorer.
|
|
222
|
+
* const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
|
|
223
223
|
* const keyProvider = new AleoKeyProvider();
|
|
224
224
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
225
225
|
*
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import 'core-js/proposals/json-parse-with-source.js';
|
|
2
|
+
import { ProgramManager, AleoKeyProvider, AleoKeyProviderParams } from './browser.js';
|
|
3
|
+
import { expose } from 'comlink';
|
|
4
|
+
import { initThreadPool, PrivateKey, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
|
|
5
|
+
|
|
6
|
+
await initThreadPool();
|
|
7
|
+
const defaultHost = "https://api.explorer.provable.com/v1";
|
|
8
|
+
const keyProvider = new AleoKeyProvider();
|
|
9
|
+
const programManager = new ProgramManager(defaultHost, keyProvider, undefined);
|
|
10
|
+
keyProvider.useCache(true);
|
|
11
|
+
let lastLocalProgram = "";
|
|
12
|
+
async function run(localProgram, aleoFunction, inputs, privateKey, proveExecution = false) {
|
|
13
|
+
console.log("Web worker: Executing function locally...");
|
|
14
|
+
const startTime = performance.now();
|
|
15
|
+
// Ensure the program is valid and that it contains the function specified
|
|
16
|
+
let program;
|
|
17
|
+
try {
|
|
18
|
+
program = programManager.createProgramFromSource(localProgram);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
throw new Error("Error creating program from source");
|
|
22
|
+
}
|
|
23
|
+
const program_id = program.id();
|
|
24
|
+
if (!program.hasFunction(aleoFunction)) {
|
|
25
|
+
throw new Error(`Program ${program_id} does not contain function ${aleoFunction}`);
|
|
26
|
+
}
|
|
27
|
+
const cacheKey = `${program_id}:${aleoFunction}`;
|
|
28
|
+
// Get the program imports
|
|
29
|
+
let imports;
|
|
30
|
+
try {
|
|
31
|
+
imports = await programManager.networkClient.getProgramImports(localProgram);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
throw new Error("Error getting program imports");
|
|
35
|
+
}
|
|
36
|
+
// Get the proving and verifying keys for the function
|
|
37
|
+
if (lastLocalProgram !== localProgram) {
|
|
38
|
+
const keys = await programManager.synthesizeKeys(localProgram, aleoFunction, inputs, PrivateKey.from_string(privateKey));
|
|
39
|
+
programManager.keyProvider.cacheKeys(cacheKey, keys);
|
|
40
|
+
lastLocalProgram = localProgram;
|
|
41
|
+
}
|
|
42
|
+
// Pass the cache key to the execute function
|
|
43
|
+
const keyParams = new AleoKeyProviderParams({
|
|
44
|
+
cacheKey: cacheKey,
|
|
45
|
+
});
|
|
46
|
+
// Execute the function locally
|
|
47
|
+
const response = await programManager.run(localProgram, aleoFunction, inputs, proveExecution, imports, keyParams, undefined, undefined, PrivateKey.from_string(privateKey));
|
|
48
|
+
// Return the outputs to the main thread
|
|
49
|
+
console.log(`Web worker: Local execution completed in ${performance.now() - startTime} ms`);
|
|
50
|
+
const outputs = response.getOutputs();
|
|
51
|
+
const execution = response.getExecution();
|
|
52
|
+
let executionString = "";
|
|
53
|
+
let keys;
|
|
54
|
+
try {
|
|
55
|
+
keys = keyProvider.getKeys(cacheKey);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
throw new Error("Could not get verifying key");
|
|
59
|
+
}
|
|
60
|
+
const verifyingKey = keys[1];
|
|
61
|
+
if (execution) {
|
|
62
|
+
verifyFunctionExecution(execution, verifyingKey, program, "hello");
|
|
63
|
+
executionString = execution.toString();
|
|
64
|
+
console.log("Execution verified successfully: " + execution);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
executionString = "";
|
|
68
|
+
}
|
|
69
|
+
console.log(`Function execution response: ${outputs}`);
|
|
70
|
+
return { outputs: outputs, execution: executionString };
|
|
71
|
+
}
|
|
72
|
+
async function getPrivateKey() {
|
|
73
|
+
const privateKey = new PrivateKey();
|
|
74
|
+
return privateKey.to_string();
|
|
75
|
+
}
|
|
76
|
+
const workerAPI = { run, getPrivateKey };
|
|
77
|
+
expose(workerAPI);
|
|
78
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sources":["../../src/worker.ts"],"sourcesContent":["import \"./polyfill/shared\";\nimport {initThreadPool, ProgramManager, PrivateKey, verifyFunctionExecution, FunctionKeyPair} from \"./browser\";\nimport { AleoKeyProvider, AleoKeyProviderParams} from \"./function-key-provider\";\nimport { expose } from \"comlink\";\n\nawait initThreadPool();\n\nconst defaultHost = \"https://api.explorer.provable.com/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 run: (\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 run(\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 // Ensure the program is valid and that it contains the function specified\n let program;\n\n try {\n program = programManager.createProgramFromSource(localProgram);\n } catch (e) {\n throw new Error(\"Error creating program from source\");\n }\n\n const program_id = program.id();\n if (!program.hasFunction(aleoFunction)) {\n throw new Error(`Program ${program_id} does not contain function ${aleoFunction}`);\n }\n const cacheKey = `${program_id}:${aleoFunction}`;\n\n\n // Get the program imports\n let imports;\n\n try {\n imports = await programManager.networkClient.getProgramImports(\n localProgram\n );\n } catch (e) {\n throw new Error(\"Error getting program imports\");\n }\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 let keys;\n\n try {\n keys = keyProvider.getKeys(cacheKey);\n } catch (e) {\n throw new Error(\"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}\n\nasync function getPrivateKey() {\n const privateKey = new PrivateKey();\n return privateKey.to_string();\n}\n\nconst workerAPI = { run, getPrivateKey };\nexpose(workerAPI);\n"],"names":[],"mappings":";;;;;AAKA,MAAM,cAAc,EAAE,CAAC;AAEvB,MAAM,WAAW,GAAG,sCAAsC,CAAC;AAC3D,MAAM,WAAW,GAAG,IAAI,eAAe,EAAE,CAAC;AAC1C,MAAM,cAAc,GAAG,IAAI,cAAc,CACrC,WAAW,EACX,WAAW,EACX,SAAS,CACZ,CAAC;AAEF,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAE3B,IAAI,gBAAgB,GAAW,EAAE,CAAC;AAYlC,eAAe,GAAG,CACd,YAAoB,EACpB,YAAoB,EACpB,MAAgB,EAChB,UAAkB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C;AAED,eAAe,aAAa,GAAA;AACxB,IAAA,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;AACpC,IAAA,OAAO,UAAU,CAAC,SAAS,EAAE,CAAC;AAClC,CAAC;AAED,MAAM,SAAS,GAAG,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC;AACzC,MAAM,CAAC,SAAS,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Address, PrivateKey, Signature, ViewKey, PrivateKeyCiphertext, RecordCiphertext } from "./browser";
|
|
2
|
+
interface AccountParam {
|
|
3
|
+
privateKey?: string;
|
|
4
|
+
seed?: Uint8Array;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Key Management class. Enables the creation of a new Aleo Account, importation of an existing account from
|
|
8
|
+
* an existing private key or seed, and message signing and verification functionality.
|
|
9
|
+
*
|
|
10
|
+
* An Aleo Account is generated from a randomly generated seed (number) from which an account private key, view key,
|
|
11
|
+
* and a public account address are derived. The private key lies at the root of an Aleo account. It is a highly
|
|
12
|
+
* sensitive secret and should be protected as it allows for creation of Aleo Program executions and arbitrary value
|
|
13
|
+
* transfers. The View Key allows for decryption of a user's activity on the blockchain. The Address is the public
|
|
14
|
+
* address to which other users of Aleo can send Aleo credits and other records to. This class should only be used
|
|
15
|
+
* environments where the safety of the underlying key material can be assured.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Create a new account
|
|
19
|
+
* const myRandomAccount = new Account();
|
|
20
|
+
*
|
|
21
|
+
* // Create an account from a randomly generated seed
|
|
22
|
+
* const seed = new Uint8Array([94, 91, 52, 251, 240, 230, 226, 35, 117, 253, 224, 210, 175, 13, 205, 120, 155, 214, 7, 169, 66, 62, 206, 50, 188, 40, 29, 122, 40, 250, 54, 18]);
|
|
23
|
+
* const mySeededAccount = new Account({seed: seed});
|
|
24
|
+
*
|
|
25
|
+
* // Create an account from an existing private key
|
|
26
|
+
* const myExistingAccount = new Account({privateKey: 'myExistingPrivateKey'})
|
|
27
|
+
*
|
|
28
|
+
* // Sign a message
|
|
29
|
+
* const hello_world = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
|
|
30
|
+
* const signature = myRandomAccount.sign(hello_world)
|
|
31
|
+
*
|
|
32
|
+
* // Verify a signature
|
|
33
|
+
* myRandomAccount.verify(hello_world, signature)
|
|
34
|
+
*/
|
|
35
|
+
export declare class Account {
|
|
36
|
+
_privateKey: PrivateKey;
|
|
37
|
+
_viewKey: ViewKey;
|
|
38
|
+
_address: Address;
|
|
39
|
+
constructor(params?: AccountParam);
|
|
40
|
+
/**
|
|
41
|
+
* Attempts to create an account from a private key ciphertext
|
|
42
|
+
* @param {PrivateKeyCiphertext | string} ciphertext
|
|
43
|
+
* @param {string} password
|
|
44
|
+
* @returns {PrivateKey}
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const ciphertext = PrivateKey.newEncrypted("password");
|
|
48
|
+
* const account = Account.fromCiphertext(ciphertext, "password");
|
|
49
|
+
*/
|
|
50
|
+
static fromCiphertext(ciphertext: PrivateKeyCiphertext | string, password: string): Account;
|
|
51
|
+
private privateKeyFromParams;
|
|
52
|
+
privateKey(): PrivateKey;
|
|
53
|
+
viewKey(): ViewKey;
|
|
54
|
+
address(): Address;
|
|
55
|
+
toString(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Encrypt the account's private key with a password
|
|
58
|
+
* @param {string} ciphertext
|
|
59
|
+
* @returns {PrivateKeyCiphertext}
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* const account = new Account();
|
|
63
|
+
* const ciphertext = account.encryptAccount("password");
|
|
64
|
+
*/
|
|
65
|
+
encryptAccount(password: string): PrivateKeyCiphertext;
|
|
66
|
+
/**
|
|
67
|
+
* Decrypts a Record in ciphertext form into plaintext
|
|
68
|
+
* @param {string} ciphertext
|
|
69
|
+
* @returns {Record}
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* const account = new Account();
|
|
73
|
+
* const record = account.decryptRecord("record1ciphertext");
|
|
74
|
+
*/
|
|
75
|
+
decryptRecord(ciphertext: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Decrypts an array of Records in ciphertext form into plaintext
|
|
78
|
+
* @param {string[]} ciphertexts
|
|
79
|
+
* @returns {Record[]}
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* const account = new Account();
|
|
83
|
+
* const record = account.decryptRecords(["record1ciphertext", "record2ciphertext"]);
|
|
84
|
+
*/
|
|
85
|
+
decryptRecords(ciphertexts: string[]): string[];
|
|
86
|
+
/**
|
|
87
|
+
* Determines whether the account owns a ciphertext record
|
|
88
|
+
* @param {RecordCipherText | string} ciphertext
|
|
89
|
+
* @returns {boolean}
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* // Create a connection to the Aleo network and an account
|
|
93
|
+
* const connection = new AleoNetworkClient("https://api.explorer.provable.com/v1");
|
|
94
|
+
* const account = Account.fromCiphertext("ciphertext", "password");
|
|
95
|
+
*
|
|
96
|
+
* // Get a record from the network
|
|
97
|
+
* const record = connection.getBlock(1234);
|
|
98
|
+
* const recordCipherText = record.transactions[0].execution.transitions[0].id;
|
|
99
|
+
*
|
|
100
|
+
* // Check if the account owns the record
|
|
101
|
+
* if account.ownsRecord(recordCipherText) {
|
|
102
|
+
* // Then one can do something like:
|
|
103
|
+
* // Decrypt the record and check if it's spent
|
|
104
|
+
* // Store the record in a local database
|
|
105
|
+
* // Etc.
|
|
106
|
+
* }
|
|
107
|
+
*/
|
|
108
|
+
ownsRecordCiphertext(ciphertext: RecordCiphertext | string): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Signs a message with the account's private key.
|
|
111
|
+
* Returns a Signature.
|
|
112
|
+
*
|
|
113
|
+
* @param {Uint8Array} message
|
|
114
|
+
* @returns {Signature}
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* const account = new Account();
|
|
118
|
+
* const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
|
|
119
|
+
* account.sign(message);
|
|
120
|
+
*/
|
|
121
|
+
sign(message: Uint8Array): Signature;
|
|
122
|
+
/**
|
|
123
|
+
* Verifies the Signature on a message.
|
|
124
|
+
*
|
|
125
|
+
* @param {Uint8Array} message
|
|
126
|
+
* @param {Signature} signature
|
|
127
|
+
* @returns {boolean}
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* const account = new Account();
|
|
131
|
+
* const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
|
|
132
|
+
* const signature = account.sign(message);
|
|
133
|
+
* account.verify(message, signature);
|
|
134
|
+
*/
|
|
135
|
+
verify(message: Uint8Array, signature: Signature): boolean;
|
|
136
|
+
}
|
|
137
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import "./polyfill/shared";
|
|
2
|
+
import { VerifyingKey } from "@provablehq/wasm/testnet.js";
|
|
3
|
+
declare const KEY_STORE: string;
|
|
4
|
+
interface Key {
|
|
5
|
+
name: string;
|
|
6
|
+
locator: string;
|
|
7
|
+
prover: string;
|
|
8
|
+
verifier: string;
|
|
9
|
+
verifyingKey: () => VerifyingKey;
|
|
10
|
+
}
|
|
11
|
+
declare const CREDITS_PROGRAM_KEYS: {
|
|
12
|
+
bond_public: Key;
|
|
13
|
+
bond_validator: Key;
|
|
14
|
+
claim_unbond_public: Key;
|
|
15
|
+
fee_private: Key;
|
|
16
|
+
fee_public: Key;
|
|
17
|
+
inclusion: Key;
|
|
18
|
+
join: Key;
|
|
19
|
+
set_validator_state: Key;
|
|
20
|
+
split: Key;
|
|
21
|
+
transfer_private: Key;
|
|
22
|
+
transfer_private_to_public: Key;
|
|
23
|
+
transfer_public: Key;
|
|
24
|
+
transfer_public_as_signer: Key;
|
|
25
|
+
transfer_public_to_private: Key;
|
|
26
|
+
unbond_public: Key;
|
|
27
|
+
getKey: (key: string) => Key;
|
|
28
|
+
};
|
|
29
|
+
declare const PRIVATE_TRANSFER_TYPES: Set<string>;
|
|
30
|
+
declare const VALID_TRANSFER_TYPES: Set<string>;
|
|
31
|
+
declare const PRIVATE_TRANSFER: Set<string>;
|
|
32
|
+
declare const PRIVATE_TO_PUBLIC_TRANSFER: Set<string>;
|
|
33
|
+
declare const PUBLIC_TRANSFER: Set<string>;
|
|
34
|
+
declare const PUBLIC_TRANSFER_AS_SIGNER: Set<string>;
|
|
35
|
+
declare const PUBLIC_TO_PRIVATE_TRANSFER: Set<string>;
|
|
36
|
+
declare function logAndThrow(message: string): never;
|
|
37
|
+
import { Account } from "./account";
|
|
38
|
+
import { AleoNetworkClient, ProgramImports } from "./network-client";
|
|
39
|
+
import { Block } from "./models/block";
|
|
40
|
+
import { Execution } from "./models/execution";
|
|
41
|
+
import { Input } from "./models/input";
|
|
42
|
+
import { Output } from "./models/output";
|
|
43
|
+
import { TransactionModel } from "./models/transactionModel";
|
|
44
|
+
import { Transition } from "./models/transition";
|
|
45
|
+
import { AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, CachedKeyPair, FunctionKeyPair, FunctionKeyProvider, KeySearchParams } from "./function-key-provider";
|
|
46
|
+
import { OfflineKeyProvider, OfflineSearchParams } from "./offline-key-provider";
|
|
47
|
+
import { BlockHeightSearch, NetworkRecordProvider, RecordProvider, RecordSearchParams } from "./record-provider";
|
|
48
|
+
declare function initializeWasm(): Promise<void>;
|
|
49
|
+
export { createAleoWorker } from "./managed-worker";
|
|
50
|
+
export { ProgramManager } from "./program-manager";
|
|
51
|
+
export { Address, Execution as FunctionExecution, ExecutionResponse, Field, OfflineQuery, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, RecordCiphertext, RecordPlaintext, Signature, Transaction, VerifyingKey, ViewKey, initThreadPool, verifyFunctionExecution, } from "@provablehq/wasm/testnet.js";
|
|
52
|
+
export { initializeWasm };
|
|
53
|
+
export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, AleoNetworkClient, Block, BlockHeightSearch, CachedKeyPair, Execution, FunctionKeyPair, FunctionKeyProvider, Input, Key, KeySearchParams, NetworkRecordProvider, ProgramImports, OfflineKeyProvider, OfflineSearchParams, Output, RecordProvider, RecordSearchParams, TransactionModel, Transition, CREDITS_PROGRAM_KEYS, KEY_STORE, PRIVATE_TRANSFER, PRIVATE_TO_PUBLIC_TRANSFER, PRIVATE_TRANSFER_TYPES, PUBLIC_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER, PUBLIC_TO_PRIVATE_TRANSFER, VALID_TRANSFER_TYPES, logAndThrow, };
|