@provablehq/sdk 0.9.2 → 0.9.4-offline-rc
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/dist/mainnet/account.d.ts +36 -1
- package/dist/mainnet/browser.d.ts +5 -4
- package/dist/mainnet/browser.js +4415 -570
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/function-key-provider.d.ts +18 -0
- package/dist/mainnet/models/authorization.d.ts +6 -0
- package/dist/mainnet/models/inputID.d.ts +4 -0
- package/dist/mainnet/models/provingRequest.d.ts +6 -0
- package/dist/mainnet/models/provingResponse.d.ts +5 -0
- package/dist/mainnet/models/request.d.ts +14 -0
- package/dist/mainnet/network-client.d.ts +0 -14
- package/dist/mainnet/node-polyfill.js.map +1 -1
- package/dist/mainnet/node.js +2 -4
- package/dist/mainnet/node.js.map +1 -1
- package/dist/mainnet/offline-key-provider.d.ts +14 -0
- package/dist/mainnet/program-manager.d.ts +209 -6
- package/dist/mainnet/wasm.d.ts +1 -1
- package/dist/testnet/account.d.ts +36 -1
- package/dist/testnet/browser.d.ts +5 -4
- package/dist/testnet/browser.js +4415 -570
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/function-key-provider.d.ts +18 -0
- package/dist/testnet/models/authorization.d.ts +6 -0
- package/dist/testnet/models/inputID.d.ts +4 -0
- package/dist/testnet/models/provingRequest.d.ts +6 -0
- package/dist/testnet/models/provingResponse.d.ts +5 -0
- package/dist/testnet/models/request.d.ts +14 -0
- package/dist/testnet/network-client.d.ts +0 -14
- package/dist/testnet/node-polyfill.js.map +1 -1
- package/dist/testnet/node.js +2 -4
- package/dist/testnet/node.js.map +1 -1
- package/dist/testnet/offline-key-provider.d.ts +14 -0
- package/dist/testnet/program-manager.d.ts +209 -6
- package/dist/testnet/wasm.d.ts +1 -1
- package/package.json +2 -2
- package/dist/mainnet/managed-worker.d.ts +0 -3
- package/dist/mainnet/program-manager-B-18sj9m.js +0 -3458
- package/dist/mainnet/program-manager-B-18sj9m.js.map +0 -1
- package/dist/mainnet/worker.d.ts +0 -9
- package/dist/mainnet/worker.js +0 -78
- package/dist/mainnet/worker.js.map +0 -1
- package/dist/testnet/managed-worker.d.ts +0 -3
- package/dist/testnet/program-manager-BR5taTR7.js +0 -3458
- package/dist/testnet/program-manager-BR5taTR7.js.map +0 -1
- package/dist/testnet/worker.d.ts +0 -9
- package/dist/testnet/worker.js +0 -78
- package/dist/testnet/worker.js.map +0 -1
package/dist/mainnet/worker.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import "./polyfill/shared.js";
|
|
2
|
-
import { PrivateKey } from "./browser.js";
|
|
3
|
-
export interface WorkerAPI {
|
|
4
|
-
run: (localProgram: string, aleoFunction: string, inputs: string[], privateKey: string) => Promise<{
|
|
5
|
-
outputs: any;
|
|
6
|
-
execution: string;
|
|
7
|
-
} | string>;
|
|
8
|
-
getPrivateKey: () => Promise<PrivateKey>;
|
|
9
|
-
}
|
package/dist/mainnet/worker.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import 'core-js/proposals/json-parse-with-source.js';
|
|
2
|
-
import { initThreadPool, PrivateKey, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
|
|
3
|
-
import { P as ProgramManager, A as AleoKeyProvider, a as AleoKeyProviderParams } from './program-manager-B-18sj9m.js';
|
|
4
|
-
import { expose } from 'comlink';
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sources":["../../src/worker.ts"],"sourcesContent":["import \"./polyfill/shared.js\";\nimport {initThreadPool, ProgramManager, PrivateKey, verifyFunctionExecution, FunctionKeyPair} from \"./browser.js\";\nimport { AleoKeyProvider, AleoKeyProviderParams} from \"./function-key-provider.js\";\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;AAEtB,MAAM,WAAW,GAAG,sCAAsC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