@provablehq/sdk 0.9.12 → 0.9.14
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/browser.js +743 -142
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/constants.d.ts +1 -0
- package/dist/mainnet/integrations/sealance/merkle-tree.d.ts +83 -12
- package/dist/mainnet/network-client.d.ts +29 -2
- package/dist/mainnet/node-polyfill.js.map +1 -1
- package/dist/mainnet/program-manager.d.ts +165 -0
- package/dist/testnet/browser.js +743 -142
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/constants.d.ts +1 -0
- package/dist/testnet/integrations/sealance/merkle-tree.d.ts +83 -12
- package/dist/testnet/network-client.d.ts +29 -2
- package/dist/testnet/node-polyfill.js.map +1 -1
- package/dist/testnet/program-manager.d.ts +165 -0
- package/package.json +2 -2
|
@@ -37,3 +37,4 @@ export declare const RECORD_DOMAIN = "RecordScannerV0";
|
|
|
37
37
|
* Zero address on Aleo blockchain that corresponds to field element 0. Used as padding in Merkle trees and as a sentinel value.
|
|
38
38
|
*/
|
|
39
39
|
export declare const ZERO_ADDRESS = "aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc";
|
|
40
|
+
export declare const FIVE_MINUTES: number;
|
|
@@ -18,6 +18,7 @@ import { Field } from "../../wasm.js";
|
|
|
18
18
|
* const proof_left = sealance.getSiblingPath(tree, leftIdx, 15);
|
|
19
19
|
* const proof_right = sealance.getSiblingPath(tree, rightIdx, 15);
|
|
20
20
|
* const exclusion_proof = [proof_left, proof_right];
|
|
21
|
+
* const formatted_proof = sealance.formatMerkleProof(exclusion_proof);
|
|
21
22
|
* ```
|
|
22
23
|
*/
|
|
23
24
|
declare class SealanceMerkleTree {
|
|
@@ -35,8 +36,9 @@ declare class SealanceMerkleTree {
|
|
|
35
36
|
*
|
|
36
37
|
* @example
|
|
37
38
|
* ```typescript
|
|
39
|
+
* const sealance = new SealanceMerkleTree();
|
|
38
40
|
* const address = "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px";
|
|
39
|
-
* const fieldValue = convertAddressToField(address);
|
|
41
|
+
* const fieldValue = sealance.convertAddressToField(address);
|
|
40
42
|
* console.log(fieldValue); // 123456789...n
|
|
41
43
|
* ```
|
|
42
44
|
*/
|
|
@@ -59,13 +61,33 @@ declare class SealanceMerkleTree {
|
|
|
59
61
|
*
|
|
60
62
|
* @example
|
|
61
63
|
* ```typescript
|
|
64
|
+
* const sealance = new SealanceMerkleTree();
|
|
62
65
|
* const leaves = ["0field", "1field", "2field", "3field"];
|
|
63
|
-
* const tree = buildTree(leaves);
|
|
66
|
+
* const tree = sealance.buildTree(leaves);
|
|
64
67
|
* const root = tree[tree.length - 1]; // Get the Merkle root
|
|
65
68
|
* ```
|
|
66
69
|
*/
|
|
67
70
|
buildTree(leaves: string[]): bigint[];
|
|
68
71
|
/**
|
|
72
|
+
* Converts an array of decimal string representations of U256 numbers to an array of BigInts.
|
|
73
|
+
*
|
|
74
|
+
* @param tree - Array of decimal string representations of U256 numbers.
|
|
75
|
+
* @returns Array of BigInts.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const treeStrings = ["0","4328470178059738374782465505490977516512210899136548187530607227309847251692","1741259420362056497457198439964202806733137875365061915996980524089960046336"];
|
|
80
|
+
* const sealance = new SealanceMerkleTree();
|
|
81
|
+
* const treeBigInts = sealance.convertTreeToBigInt(treeStrings);
|
|
82
|
+
* console.log(treeBigInts); // [
|
|
83
|
+
* 0,
|
|
84
|
+
* 4328470178059738374782465505490977516512210899136548187530607227309847251692,
|
|
85
|
+
* 1741259420362056497457198439964202806733137875365061915996980524089960046336
|
|
86
|
+
* ]
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
convertTreeToBigInt(tree: string[]): bigint[];
|
|
90
|
+
/**
|
|
69
91
|
* Converts Aleo addresses to field elements, sorts them, pads with zero fields, and returns an array. This prepares addresses for Merkle tree construction.
|
|
70
92
|
*
|
|
71
93
|
* @param addresses - Array of Aleo addresses.
|
|
@@ -76,11 +98,18 @@ declare class SealanceMerkleTree {
|
|
|
76
98
|
* @example
|
|
77
99
|
* ```typescript
|
|
78
100
|
* const addresses = [
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
* const
|
|
101
|
+
* "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
|
|
102
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
103
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
104
|
+
* ];
|
|
105
|
+
* const sealance = new SealanceMerkleTree();
|
|
106
|
+
* const leaves = sealance.generateLeaves(addresses, 15);
|
|
107
|
+
* console.log(leaves); // [
|
|
108
|
+
* "0field",
|
|
109
|
+
* "1295133970529764960316948294624974168921228814652993007266766481909235735940field",
|
|
110
|
+
* "1295133970529764960316948294624974168921228814652993007266766481909235735940field",
|
|
111
|
+
* "3501665755452795161867664882580888971213780722176652848275908626939553697821field"
|
|
112
|
+
* ]
|
|
84
113
|
* ```
|
|
85
114
|
*/
|
|
86
115
|
generateLeaves(addresses: string[], maxTreeDepth?: number): string[];
|
|
@@ -93,8 +122,15 @@ declare class SealanceMerkleTree {
|
|
|
93
122
|
*
|
|
94
123
|
* @example
|
|
95
124
|
* ```typescript
|
|
96
|
-
* const
|
|
97
|
-
|
|
125
|
+
* const addresses = [
|
|
126
|
+
* "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
|
|
127
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
128
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
129
|
+
* ];
|
|
130
|
+
* const sealance = new SealanceMerkleTree();
|
|
131
|
+
* const leaves = sealance.generateLeaves(addresses);
|
|
132
|
+
* const tree = sealance.buildTree(leaves);
|
|
133
|
+
* const [leftIdx, rightIdx] = sealance.getLeafIndices(tree, "aleo1...");
|
|
98
134
|
* ```
|
|
99
135
|
*/
|
|
100
136
|
getLeafIndices(merkleTree: bigint[], address: string): [number, number];
|
|
@@ -108,14 +144,49 @@ declare class SealanceMerkleTree {
|
|
|
108
144
|
*
|
|
109
145
|
* @example
|
|
110
146
|
* ```typescript
|
|
111
|
-
* const
|
|
112
|
-
*
|
|
113
|
-
*
|
|
147
|
+
* const addresses = [
|
|
148
|
+
* "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
|
|
149
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
150
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
151
|
+
* ];
|
|
152
|
+
* const sealance = new SealanceMerkleTree();
|
|
153
|
+
* const leaves = sealance.generateLeaves(addresses);
|
|
154
|
+
* const tree = sealance.buildTree(leaves);
|
|
155
|
+
* const [leftIdx, rightIdx] = sealance.getLeafIndices(tree, "aleo1...");
|
|
156
|
+
* const proof = sealance.getSiblingPath(tree, leftIdx, 15);
|
|
157
|
+
* // proof = { siblings: [0n, 1n, ...], leaf_index: leftIdx }
|
|
114
158
|
* ```
|
|
115
159
|
*/
|
|
116
160
|
getSiblingPath(tree: bigint[], leafIndex: number, depth: number): {
|
|
117
161
|
siblings: bigint[];
|
|
118
162
|
leaf_index: number;
|
|
119
163
|
};
|
|
164
|
+
/**
|
|
165
|
+
* Generates a formatted exclusion proof suitable for Aleo transactions.
|
|
166
|
+
*
|
|
167
|
+
* @param proof - An array of two {sibling path, leafindex} objects.
|
|
168
|
+
* @returns String representation of the exclusion proof.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const addresses = [
|
|
173
|
+
* "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
|
|
174
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
175
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
176
|
+
* ];
|
|
177
|
+
* const sealance = new SealanceMerkleTree();
|
|
178
|
+
* const leaves = sealance.generateLeaves(addresses);
|
|
179
|
+
* const tree = sealance.buildTree(leaves);
|
|
180
|
+
* const [leftIdx, rightIdx] = sealance.getLeafIndices(tree, "aleo1...");
|
|
181
|
+
* const proof1 = getSiblingPath(tree, leftIdx, 15);
|
|
182
|
+
* const proof2 = getSiblingPath(tree, rightIdx, 15);
|
|
183
|
+
* const formattedProof = formatMerkleProof([proof1, proof2]);
|
|
184
|
+
* // formattedProof = "[{ siblings: [0field, 1field, ...], leaf_index: 0u32 }, { siblings: [0field, 2field, ...], leaf_index: 1u32 }]"
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
formatMerkleProof(proof: {
|
|
188
|
+
siblings: bigint[];
|
|
189
|
+
leaf_index: number;
|
|
190
|
+
}[]): string;
|
|
120
191
|
}
|
|
121
192
|
export { SealanceMerkleTree };
|
|
@@ -12,17 +12,31 @@ interface AleoNetworkClientOptions {
|
|
|
12
12
|
[key: string]: string;
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Interface for the JWT data.
|
|
17
|
+
*
|
|
18
|
+
* @property jwt {string} The JWT token string.
|
|
19
|
+
* @property expiration {number} The expiration time of the JWT token in UNIX timestamp format.
|
|
20
|
+
*/
|
|
21
|
+
interface JWTData {
|
|
22
|
+
jwt: string;
|
|
23
|
+
expiration: number;
|
|
24
|
+
}
|
|
15
25
|
/**
|
|
16
26
|
* Options for submitting a proving request.
|
|
17
27
|
*
|
|
18
28
|
* @property provingRequest {ProvingRequest | string} The proving request being submitted to the network.
|
|
19
29
|
* @property url {string} The URL of the delegated proving service.
|
|
20
|
-
* @property apiKey {string} The API key
|
|
30
|
+
* @property apiKey {string} The API key used for generating a JWT.
|
|
31
|
+
* @property consumerId {string} The consumer ID associated with the API key.
|
|
32
|
+
* @property jwt {string} An optional JWT token used for authenticating with the proving service.
|
|
21
33
|
*/
|
|
22
34
|
interface DelegatedProvingParams {
|
|
23
35
|
provingRequest: ProvingRequest | string;
|
|
24
36
|
url?: string;
|
|
25
37
|
apiKey?: string;
|
|
38
|
+
consumerId?: string;
|
|
39
|
+
jwtData?: JWTData;
|
|
26
40
|
}
|
|
27
41
|
/**
|
|
28
42
|
* Client library that encapsulates REST calls to publicly exposed endpoints of Aleo nodes. The methods provided in this
|
|
@@ -35,6 +49,8 @@ interface DelegatedProvingParams {
|
|
|
35
49
|
*
|
|
36
50
|
* // Connection to a public beacon node
|
|
37
51
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
52
|
+
* const apiKey = process.env.apiKey;
|
|
53
|
+
* const consumerId = process.env.consumerId;
|
|
38
54
|
* const publicNetworkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined, account);
|
|
39
55
|
*/
|
|
40
56
|
declare class AleoNetworkClient {
|
|
@@ -48,6 +64,9 @@ declare class AleoNetworkClient {
|
|
|
48
64
|
};
|
|
49
65
|
verboseErrors: boolean;
|
|
50
66
|
readonly network: string;
|
|
67
|
+
apiKey?: string;
|
|
68
|
+
consumerId?: string;
|
|
69
|
+
jwtData?: JWTData;
|
|
51
70
|
constructor(host: string, options?: AleoNetworkClientOptions);
|
|
52
71
|
/**
|
|
53
72
|
* Set an account to use in networkClient calls
|
|
@@ -477,7 +496,7 @@ declare class AleoNetworkClient {
|
|
|
477
496
|
* programImports = await networkClient.getProgramImports(double_test);
|
|
478
497
|
* assert.deepStrictEqual(programImports, expectedImports);
|
|
479
498
|
*/
|
|
480
|
-
getProgramImports(inputProgram: Program | string): Promise<ProgramImports>;
|
|
499
|
+
getProgramImports(inputProgram: Program | string, imports?: ProgramImports): Promise<ProgramImports>;
|
|
481
500
|
/**
|
|
482
501
|
* Get a list of the program names that a program imports.
|
|
483
502
|
*
|
|
@@ -734,6 +753,14 @@ declare class AleoNetworkClient {
|
|
|
734
753
|
* @returns {Promise<string>} The solution id of the submitted solution or the resulting error.
|
|
735
754
|
*/
|
|
736
755
|
submitSolution(solution: string): Promise<string>;
|
|
756
|
+
/**
|
|
757
|
+
* Refreshes the JWT by making a POST request to /jwts/{consumer_id}
|
|
758
|
+
*
|
|
759
|
+
* @param {string} apiKey - The API key for authentication.
|
|
760
|
+
* @param {string} consumerId - The consumer ID associated with the API key.
|
|
761
|
+
* @returns {Promise<JwtData>} The JWT token and expiration time
|
|
762
|
+
*/
|
|
763
|
+
private refreshJwt;
|
|
737
764
|
/**
|
|
738
765
|
* Submit a `ProvingRequest` to a remote proving service for delegated proving. If the broadcast flag of the `ProvingRequest` is set to `true` the remote service will attempt to broadcast the result `Transaction` on behalf of the requestor.
|
|
739
766
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-polyfill.js","sources":["../../src/polyfill/crypto.ts","../../src/polyfill/fetch.ts","../../src/polyfill/xmlhttprequest.ts","../../src/polyfill/worker.ts","../../src/node-polyfill.ts"],"sourcesContent":["import { webcrypto } from \"node:crypto\";\n\nif ((globalThis as any).crypto == null) {\n (globalThis as any).crypto = webcrypto;\n}\n","import * as $fs from \"node:fs\";\nimport $mime from \"mime/lite\";\n\n\nconst oldFetch = globalThis.fetch;\n\n\nlet supports: Promise<boolean> | null = null;\n\nasync function checkFetch() {\n try {\n await oldFetch(new URL(\"file:\"));\n return true;\n\n } catch (e) {\n return false;\n }\n}\n\nasync function supportsFetch(): Promise<boolean> {\n if (supports === null) {\n supports = checkFetch();\n }\n\n return await supports;\n}\n\n\n// We always polyfill fetch because Node's fetch doesn't support file URLs.\n(globalThis.fetch as any) = async function (resource: URL | RequestInfo, options: RequestInit | undefined): Promise<Response> {\n const request = new Request(resource, options);\n\n const url = new URL(request.url);\n\n if (!(await supportsFetch()) && url.protocol === \"file:\") {\n const readStream = $fs.createReadStream(url);\n\n const headers: HeadersInit = {};\n\n const type = $mime.getType(url.pathname);\n\n if (type) {\n headers[\"Content-Type\"] = type;\n }\n\n return new Response(readStream as any, {\n status: 200,\n statusText: \"OK\",\n headers,\n });\n\n } else {\n return await oldFetch(request);\n }\n};\n","// @ts-ignore\nimport $xmlhttprequest from \"xmlhttprequest-ssl\";\nimport $request from \"sync-request\";\n\nif (globalThis.XMLHttpRequest == null) {\n globalThis.XMLHttpRequest = class extends $xmlhttprequest.XMLHttpRequest {\n // We have to override the methods inside of the `constructor`\n // because `xmlhttprequest-ssl` doesn't use a regular class,\n // instead it defines all of the methods inside of the constructor.\n constructor(...args: Array<any>) {\n super(...args);\n\n const open = (this as any).open;\n const send = (this as any).send;\n\n let _async: boolean = true;\n let _url: null | string = null;\n let _mime: string = \"text/xml\";\n\n function reset() {\n _async = true;\n _url = null;\n _mime = \"text/xml\";\n }\n\n (this as any).open = function (method: string, url: string, async: boolean, user?: string, password?: string) {\n // Special behavior for synchronous requests\n if (method === \"GET\" && !async && !user && !password) {\n _async = false;\n _url = url;\n\n // Default to the normal polyfill for async requests\n } else {\n reset();\n return open.call(this, method, url, async, user, password);\n }\n };\n\n (this as any).send = function (data: any) {\n if (_async) {\n return send.call(this, data);\n\n // Use `sync-request` for synchronous requests.\n } else {\n const response = $request(\"GET\", _url!, {\n headers: {\n \"Content-Type\": _mime,\n }\n });\n\n const buffer = (response.body as Buffer).buffer as any;\n\n const responseText = new TextDecoder(\"iso-8859-5\", { fatal: true }).decode(buffer);\n\n (this as any).status = 200;\n (this as any).response = (this as any).responseText = responseText;\n\n reset();\n }\n };\n\n (this as any).overrideMimeType = function (mime: string) {\n _mime = mime;\n };\n }\n } as any;\n}\n","import * as $worker from \"node:worker_threads\";\nimport * as $os from \"node:os\";\n\n// This is technically not a part of the Worker polyfill,\n// but Workers are used for multi-threading, so this is often\n// needed when writing Worker code.\nif (globalThis.navigator == null) {\n globalThis.navigator = {\n hardwareConcurrency: $os.cpus().length,\n } as Navigator;\n}\n\nif (globalThis.Worker == null) {\n globalThis.Worker = class Worker extends EventTarget {\n private _worker: import(\"node:worker_threads\").Worker;\n\n constructor(url: string | URL, options?: WorkerOptions | undefined) {\n super();\n\n if (url instanceof URL) {\n if (url.protocol !== \"file:\") {\n throw new Error(\"Worker only supports file: URLs\");\n }\n\n url = url.href;\n\n } else {\n throw new Error(\"Filepaths are unreliable, use `new URL(\\\"...\\\", import.meta.url)` instead.\");\n }\n\n if (!options || options.type !== \"module\") {\n throw new Error(\"Workers must use \\`type: \\\"module\\\"\\`\");\n }\n\n const code = `\n import(\"node:worker_threads\")\n .then(({ workerData }) => {\n return import(workerData.polyfill)\n .then(() => import(workerData.url))\n })\n .catch((e) => {\n // TODO maybe it should send a message to the parent?\n console.error(e.stack);\n });\n `;\n\n this._worker = new $worker.Worker(code, {\n eval: true,\n workerData: {\n url,\n polyfill: new URL(\"node-polyfill.js\", import.meta.url).href,\n },\n });\n\n this._worker.on(\"message\", (data) => {\n this.dispatchEvent(new MessageEvent(\"message\", { data }));\n });\n\n this._worker.on(\"messageerror\", (error) => {\n throw new Error(\"UNIMPLEMENTED\");\n });\n\n this._worker.on(\"error\", (error) => {\n // TODO attach the error to the event somehow\n const event = new Event(\"error\");\n this.dispatchEvent(event);\n });\n }\n\n set onmessage(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n set onmessageerror(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n set onerror(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n postMessage(message: any, transfer: Array<Transferable>): void;\n postMessage(message: any, options?: StructuredSerializeOptions | undefined): void;\n postMessage(value: any, transfer: any) {\n this._worker.postMessage(value, transfer);\n }\n\n terminate() {\n this._worker.terminate();\n }\n\n // This is Node-specific, it allows the process to exit\n // even if the Worker is still running.\n unref() {\n this._worker.unref();\n }\n };\n}\n\n\nif (!$worker.isMainThread) {\n const globals = globalThis as unknown as DedicatedWorkerGlobalScope;\n\n // This is used to create the onmessage, onmessageerror, and onerror setters\n const makeSetter = (prop: string, event: string) => {\n let oldvalue: () => void;\n\n Object.defineProperty(globals, prop, {\n get() {\n return oldvalue;\n },\n set(value) {\n if (oldvalue) {\n globals.removeEventListener(event, oldvalue);\n }\n\n oldvalue = value;\n\n if (oldvalue) {\n globals.addEventListener(event, oldvalue);\n }\n },\n });\n };\n\n // This makes sure that `f` is only run once\n const memoize = (f: () => void) => {\n let run = false;\n\n return () => {\n if (!run) {\n run = true;\n f();\n }\n };\n };\n\n\n // We only start listening for messages / errors when the worker calls addEventListener\n const startOnMessage = memoize(() => {\n $worker.parentPort!.on(\"message\", (data) => {\n workerEvents.dispatchEvent(new MessageEvent(\"message\", { data }));\n });\n });\n\n const startOnMessageError = memoize(() => {\n throw new Error(\"UNIMPLEMENTED\");\n });\n\n const startOnError = memoize(() => {\n $worker.parentPort!.on(\"error\", (data) => {\n workerEvents.dispatchEvent(new Event(\"error\"));\n });\n });\n\n\n // Node workers don't have top-level events, so we have to make our own\n const workerEvents = new EventTarget();\n\n globals.close = () => {\n process.exit();\n };\n\n globals.addEventListener = (type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined) => {\n workerEvents.addEventListener(type, callback, options);\n\n if (type === \"message\") {\n startOnMessage();\n } else if (type === \"messageerror\") {\n startOnMessageError();\n } else if (type === \"error\") {\n startOnError();\n }\n };\n\n globals.removeEventListener = (type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined) => {\n workerEvents.removeEventListener(type, callback, options);\n };\n\n function postMessage(message: any, transfer: Transferable[]): void;\n function postMessage(message: any, options?: StructuredSerializeOptions | undefined): void;\n function postMessage(value: any, transfer: any) {\n $worker.parentPort!.postMessage(value, transfer);\n }\n\n globals.postMessage = postMessage;\n\n makeSetter(\"onmessage\", \"message\");\n makeSetter(\"onmessageerror\", \"messageerror\");\n makeSetter(\"onerror\", \"error\");\n}\n","import \"./polyfill/shared.js\";\nimport \"./polyfill/crypto.js\";\nimport \"./polyfill/fetch.js\";\nimport \"./polyfill/xmlhttprequest.js\";\nimport \"./polyfill/worker.js\";\n\nif (!globalThis.self) {\n (globalThis as any).self = globalThis;\n}\n"],"names":[],"mappings":";;;;;;;;;AAEA,IAAK,UAAkB,CAAC,MAAM,IAAI,IAAI,EAAE;AACnC,IAAA,UAAkB,CAAC,MAAM,GAAG,SAAS;AAC1C;;ACAA,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK;AAGjC,IAAI,QAAQ,GAA4B,IAAI;AAE5C,eAAe,UAAU,GAAA;AACrB,IAAA,IAAI;QACA,MAAM,QAAQ,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;AAChC,QAAA,OAAO,IAAI;;IAEb,OAAO,CAAC,EAAE;AACR,QAAA,OAAO,KAAK;;AAEpB;AAEA,eAAe,aAAa,GAAA;AACxB,IAAA,IAAI,QAAQ,KAAK,IAAI,EAAE;QACnB,QAAQ,GAAG,UAAU,EAAE;;IAG3B,OAAO,MAAM,QAAQ;AACzB;AAGA;AACC,UAAU,CAAC,KAAa,GAAG,gBAAgB,QAA2B,EAAE,OAAgC,EAAA;IACrG,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC;IAE9C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC;AAEhC,IAAA,IAAI,EAAE,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;AAEtB,KAAC;IAED,OAAO,CAAC,mBAAmB,GAAG,CAAC,IAAY,EAAE,QAAmD,EAAE,OAAoD,KAAI;QACtJ,YAAY,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC;AAC7D,KAAC;AAID,IAAA,SAAS,WAAW,CAAC,KAAU,EAAE,QAAa,EAAA;QAC1C,OAAO,CAAC,UAAW,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC;;AAGpD,IAAA,OAAO,CAAC,WAAW,GAAG,WAAW;AAEjC,IAAA,UAAU,CAAC,WAAW,EAAE,SAAS,CAAC;AAClC,IAAA,UAAU,CAAC,gBAAgB,EAAE,cAAc,CAAC;AAC5C,IAAA,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC;AAClC;;ACxLA,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;AACjB,IAAA,UAAkB,CAAC,IAAI,GAAG,UAAU;AACzC"}
|
|
1
|
+
{"version":3,"file":"node-polyfill.js","sources":["../../src/polyfill/crypto.ts","../../src/polyfill/fetch.ts","../../src/polyfill/xmlhttprequest.ts","../../src/polyfill/worker.ts","../../src/node-polyfill.ts"],"sourcesContent":["import { webcrypto } from \"node:crypto\";\n\nif ((globalThis as any).crypto == null) {\n (globalThis as any).crypto = webcrypto;\n}\n","import * as $fs from \"node:fs\";\nimport $mime from \"mime/lite\";\n\n\nconst oldFetch = globalThis.fetch;\n\n\nlet supports: Promise<boolean> | null = null;\n\nasync function checkFetch() {\n try {\n await oldFetch(new URL(\"file:\"));\n return true;\n\n } catch (e) {\n return false;\n }\n}\n\nasync function supportsFetch(): Promise<boolean> {\n if (supports === null) {\n supports = checkFetch();\n }\n\n return await supports;\n}\n\n\n// We always polyfill fetch because Node's fetch doesn't support file URLs.\n(globalThis.fetch as any) = async function (resource: URL | RequestInfo, options: RequestInit | undefined): Promise<Response> {\n const request = new Request(resource, options);\n\n const url = new URL(request.url);\n\n if (!(await supportsFetch()) && url.protocol === \"file:\") {\n const readStream = $fs.createReadStream(url);\n\n const headers: HeadersInit = {};\n\n const type = $mime.getType(url.pathname);\n\n if (type) {\n headers[\"Content-Type\"] = type;\n }\n\n return new Response(readStream as any, {\n status: 200,\n statusText: \"OK\",\n headers,\n });\n\n } else {\n return await oldFetch(request);\n }\n};\n","// @ts-ignore\nimport $xmlhttprequest from \"xmlhttprequest-ssl\";\nimport $request from \"sync-request\";\n\nif (globalThis.XMLHttpRequest == null) {\n globalThis.XMLHttpRequest = class extends $xmlhttprequest.XMLHttpRequest {\n // We have to override the methods inside of the `constructor`\n // because `xmlhttprequest-ssl` doesn't use a regular class,\n // instead it defines all of the methods inside of the constructor.\n constructor(...args: Array<any>) {\n super(...args);\n\n const open = (this as any).open;\n const send = (this as any).send;\n\n let _async: boolean = true;\n let _url: null | string = null;\n let _mime: string = \"text/xml\";\n\n function reset() {\n _async = true;\n _url = null;\n _mime = \"text/xml\";\n }\n\n (this as any).open = function (method: string, url: string, async: boolean, user?: string, password?: string) {\n // Special behavior for synchronous requests\n if (method === \"GET\" && !async && !user && !password) {\n _async = false;\n _url = url;\n\n // Default to the normal polyfill for async requests\n } else {\n reset();\n return open.call(this, method, url, async, user, password);\n }\n };\n\n (this as any).send = function (data: any) {\n if (_async) {\n return send.call(this, data);\n\n // Use `sync-request` for synchronous requests.\n } else {\n const response = $request(\"GET\", _url!, {\n headers: {\n \"Content-Type\": _mime,\n }\n });\n\n const buffer = (response.body as Buffer).buffer as any;\n\n const responseText = new TextDecoder(\"iso-8859-5\", { fatal: true }).decode(buffer);\n\n (this as any).status = 200;\n (this as any).response = (this as any).responseText = responseText;\n\n reset();\n }\n };\n\n (this as any).overrideMimeType = function (mime: string) {\n _mime = mime;\n };\n }\n } as any;\n}\n","import * as $worker from \"node:worker_threads\";\nimport * as $os from \"node:os\";\n\n// This is technically not a part of the Worker polyfill,\n// but Workers are used for multi-threading, so this is often\n// needed when writing Worker code.\nif (globalThis.navigator == null) {\n globalThis.navigator = {\n hardwareConcurrency: $os.cpus().length,\n } as Navigator;\n}\n\nif (globalThis.Worker == null) {\n globalThis.Worker = class Worker extends EventTarget {\n private _worker: import(\"node:worker_threads\").Worker;\n\n constructor(url: string | URL, options?: WorkerOptions | undefined) {\n super();\n\n if (url instanceof URL) {\n if (url.protocol !== \"file:\") {\n throw new Error(\"Worker only supports file: URLs\");\n }\n\n url = url.href;\n\n } else {\n throw new Error(\"Filepaths are unreliable, use `new URL(\\\"...\\\", import.meta.url)` instead.\");\n }\n\n if (!options || options.type !== \"module\") {\n throw new Error(\"Workers must use \\`type: \\\"module\\\"\\`\");\n }\n\n const code = `\n import(\"node:worker_threads\")\n .then(({ workerData }) => {\n return import(workerData.polyfill)\n .then(() => import(workerData.url))\n })\n .catch((e) => {\n // TODO maybe it should send a message to the parent?\n console.error(e.stack);\n });\n `;\n\n this._worker = new $worker.Worker(code, {\n eval: true,\n workerData: {\n url,\n polyfill: new URL(\"node-polyfill.js\", import.meta.url).href,\n },\n });\n\n this._worker.on(\"message\", (data) => {\n this.dispatchEvent(new MessageEvent(\"message\", { data }));\n });\n\n this._worker.on(\"messageerror\", (error) => {\n throw new Error(\"UNIMPLEMENTED\");\n });\n\n this._worker.on(\"error\", (error) => {\n // TODO attach the error to the event somehow\n const event = new Event(\"error\");\n this.dispatchEvent(event);\n });\n }\n\n set onmessage(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n set onmessageerror(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n set onerror(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n postMessage(message: any, transfer: Array<Transferable>): void;\n postMessage(message: any, options?: StructuredSerializeOptions | undefined): void;\n postMessage(value: any, transfer: any) {\n this._worker.postMessage(value, transfer);\n }\n\n terminate() {\n this._worker.terminate();\n }\n\n // This is Node-specific, it allows the process to exit\n // even if the Worker is still running.\n unref() {\n this._worker.unref();\n }\n };\n}\n\n\nif (!$worker.isMainThread) {\n const globals = globalThis as unknown as DedicatedWorkerGlobalScope;\n\n // This is used to create the onmessage, onmessageerror, and onerror setters\n const makeSetter = (prop: string, event: string) => {\n let oldvalue: () => void;\n\n Object.defineProperty(globals, prop, {\n get() {\n return oldvalue;\n },\n set(value) {\n if (oldvalue) {\n globals.removeEventListener(event, oldvalue);\n }\n\n oldvalue = value;\n\n if (oldvalue) {\n globals.addEventListener(event, oldvalue);\n }\n },\n });\n };\n\n // This makes sure that `f` is only run once\n const memoize = (f: () => void) => {\n let run = false;\n\n return () => {\n if (!run) {\n run = true;\n f();\n }\n };\n };\n\n\n // We only start listening for messages / errors when the worker calls addEventListener\n const startOnMessage = memoize(() => {\n $worker.parentPort!.on(\"message\", (data) => {\n workerEvents.dispatchEvent(new MessageEvent(\"message\", { data }));\n });\n });\n\n const startOnMessageError = memoize(() => {\n throw new Error(\"UNIMPLEMENTED\");\n });\n\n const startOnError = memoize(() => {\n $worker.parentPort!.on(\"error\", (data) => {\n workerEvents.dispatchEvent(new Event(\"error\"));\n });\n });\n\n\n // Node workers don't have top-level events, so we have to make our own\n const workerEvents = new EventTarget();\n\n globals.close = () => {\n process.exit();\n };\n\n globals.addEventListener = (type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined) => {\n workerEvents.addEventListener(type, callback, options);\n\n if (type === \"message\") {\n startOnMessage();\n } else if (type === \"messageerror\") {\n startOnMessageError();\n } else if (type === \"error\") {\n startOnError();\n }\n };\n\n globals.removeEventListener = (type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined) => {\n workerEvents.removeEventListener(type, callback, options);\n };\n\n function postMessage(message: any, transfer: Transferable[]): void;\n function postMessage(message: any, options?: StructuredSerializeOptions | undefined): void;\n function postMessage(value: any, transfer: any) {\n $worker.parentPort!.postMessage(value, transfer);\n }\n\n globals.postMessage = postMessage;\n\n makeSetter(\"onmessage\", \"message\");\n makeSetter(\"onmessageerror\", \"messageerror\");\n makeSetter(\"onerror\", \"error\");\n}\n","import \"./polyfill/shared.js\";\nimport \"./polyfill/crypto.js\";\nimport \"./polyfill/fetch.js\";\nimport \"./polyfill/xmlhttprequest.js\";\nimport \"./polyfill/worker.js\";\n\nif (!globalThis.self) {\n (globalThis as any).self = globalThis;\n}\n"],"names":[],"mappings":";;;;;;;;;AAEA,IAAK,UAAkB,CAAC,MAAM,IAAI,IAAI,EAAE;AACnC,IAAA,UAAkB,CAAC,MAAM,GAAG,SAAS;AAC1C;;ACAA,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK;AAGjC,IAAI,QAAQ,GAA4B,IAAI;AAE5C,eAAe,UAAU,GAAA;AACrB,IAAA,IAAI;QACA,MAAM,QAAQ,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;AAChC,QAAA,OAAO,IAAI;IAEf;IAAE,OAAO,CAAC,EAAE;AACR,QAAA,OAAO,KAAK;IAChB;AACJ;AAEA,eAAe,aAAa,GAAA;AACxB,IAAA,IAAI,QAAQ,KAAK,IAAI,EAAE;QACnB,QAAQ,GAAG,UAAU,EAAE;IAC3B;IAEA,OAAO,MAAM,QAAQ;AACzB;AAGA;AACC,UAAU,CAAC,KAAa,GAAG,gBAAgB,QAA2B,EAAE,OAAgC,EAAA;IACrG,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC;IAE9C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC;AAEhC,IAAA,IAAI,EAAE,MAAM,aAAa,EAAE,CAAC,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,EAAE;QACtD,MAAM,UAAU,GAAG,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC;QAE5C,MAAM,OAAO,GAAgB,EAAE;QAE/B,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;QAExC,IAAI,IAAI,EAAE;AACN,YAAA,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI;QA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AAI;QACtJ,YAAY,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC;AAC7D,IAAA,CAAC;AAID,IAAA,SAAS,WAAW,CAAC,KAAU,EAAE,QAAa,EAAA;QAC1C,OAAO,CAAC,UAAW,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC;IACpD;AAEA,IAAA,OAAO,CAAC,WAAW,GAAG,WAAW;AAEjC,IAAA,UAAU,CAAC,WAAW,EAAE,SAAS,CAAC;AAClC,IAAA,UAAU,CAAC,gBAAgB,EAAE,cAAc,CAAC;AAC5C,IAAA,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC;AAClC;;ACxLA,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;AACjB,IAAA,UAAkB,CAAC,IAAI,GAAG,UAAU;AACzC"}
|
|
@@ -5,6 +5,25 @@ import { RecordProvider } from "./record-provider.js";
|
|
|
5
5
|
import { RecordSearchParams } from "./models/record-provider/recordSearchParams.js";
|
|
6
6
|
import { FunctionKeyPair, FunctionKeyProvider, KeySearchParams } from "./function-key-provider.js";
|
|
7
7
|
import { Authorization, ExecutionResponse, OfflineQuery, RecordPlaintext, PrivateKey, Program, ProvingKey, ProvingRequest, VerifyingKey, Transaction } from "./wasm.js";
|
|
8
|
+
/**
|
|
9
|
+
* Represents the options for deploying and upgrading a transaction in the Aleo network.
|
|
10
|
+
* This interface is used to specify the parameters required for building and submitting an deployment transaction.
|
|
11
|
+
*
|
|
12
|
+
* @property {string} program - The program source code to be deployed.
|
|
13
|
+
* @property {number} priorityFee - The optional priority fee to be paid for the transaction.
|
|
14
|
+
* @property {boolean} privateFee - If true, uses a private record to pay the fee; otherwise, uses the account's public credit balance.
|
|
15
|
+
* @property {RecordSearchParams | undefined} [recordSearchParams] - Optional parameters for searching for a record to pay the execution transaction fee.
|
|
16
|
+
* @property {string | RecordPlaintext | undefined} [feeRecord] - Optional fee record to use for the transaction.
|
|
17
|
+
* @property {PrivateKey} [privateKey] - Optional private key to use for the transaction.
|
|
18
|
+
*/
|
|
19
|
+
interface DeployOptions {
|
|
20
|
+
program: string;
|
|
21
|
+
priorityFee: number;
|
|
22
|
+
privateFee: boolean;
|
|
23
|
+
recordSearchParams?: RecordSearchParams;
|
|
24
|
+
feeRecord?: string | RecordPlaintext;
|
|
25
|
+
privateKey?: PrivateKey;
|
|
26
|
+
}
|
|
8
27
|
/**
|
|
9
28
|
* Represents the options for executing a transaction in the Aleo network.
|
|
10
29
|
* This interface is used to specify the parameters required for building and submitting an execution transaction.
|
|
@@ -285,6 +304,39 @@ declare class ProgramManager {
|
|
|
285
304
|
* }, 20000);
|
|
286
305
|
*/
|
|
287
306
|
buildDeploymentTransaction(program: string, priorityFee: number, privateFee: boolean, recordSearchParams?: RecordSearchParams, feeRecord?: string | RecordPlaintext, privateKey?: PrivateKey): Promise<Transaction>;
|
|
307
|
+
/**
|
|
308
|
+
* Builds a deployment transaction for submission to the Aleo network that upgrades an existing program.
|
|
309
|
+
*
|
|
310
|
+
* @param {DeployOptions} options The deployment options.
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* /// Import the mainnet version of the sdk.
|
|
314
|
+
* import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
315
|
+
*
|
|
316
|
+
* // Create a new NetworkClient, KeyProvider, and RecordProvider
|
|
317
|
+
* const keyProvider = new AleoKeyProvider();
|
|
318
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
319
|
+
* keyProvider.useCache(true);
|
|
320
|
+
*
|
|
321
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for deployments
|
|
322
|
+
* const program = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n";
|
|
323
|
+
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
324
|
+
* programManager.setAccount(Account);
|
|
325
|
+
*
|
|
326
|
+
* // Define a fee in credits
|
|
327
|
+
* const priorityFee = 0.0;
|
|
328
|
+
*
|
|
329
|
+
* // Create the deployment transaction.
|
|
330
|
+
* const tx = await programManager.buildUpgradeTransaction({program: program, priorityFee: fee, privateFee: false});
|
|
331
|
+
* await programManager.networkClient.submitTransaction(tx);
|
|
332
|
+
*
|
|
333
|
+
* // Verify the transaction was successful
|
|
334
|
+
* setTimeout(async () => {
|
|
335
|
+
* const transaction = await programManager.networkClient.getTransaction(tx.id());
|
|
336
|
+
* assert(transaction.id() === tx.id());
|
|
337
|
+
* }, 20000);
|
|
338
|
+
*/
|
|
339
|
+
buildUpgradeTransaction(options: DeployOptions): Promise<Transaction>;
|
|
288
340
|
/**
|
|
289
341
|
* Deploy an Aleo program to the Aleo network
|
|
290
342
|
*
|
|
@@ -1298,5 +1350,118 @@ declare class ProgramManager {
|
|
|
1298
1350
|
*/
|
|
1299
1351
|
estimateExecutionFee(options: FeeEstimateOptions): Promise<bigint>;
|
|
1300
1352
|
getCreditsRecord(amount: number, nonces: string[], record?: RecordPlaintext | string, params?: RecordSearchParams): Promise<RecordPlaintext>;
|
|
1353
|
+
/**
|
|
1354
|
+
* Builds an execution transaction for submission to the a local devnode.
|
|
1355
|
+
* This method skips proof generation and is not meant for use with the mainnet or testnet Aleo networks.
|
|
1356
|
+
* Note: getOrInitConsensusVersionTestHeights must be called prior to using this method for this method to work properly.
|
|
1357
|
+
*
|
|
1358
|
+
* @param {ExecuteOptions} options - The options for the execution transaction.
|
|
1359
|
+
* @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error.
|
|
1360
|
+
*
|
|
1361
|
+
* @example
|
|
1362
|
+
* /// Import the mainnet version of the sdk.
|
|
1363
|
+
* import { AleoKeyProvider, getOrInitConsensusVersionTestHeights, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
1364
|
+
*
|
|
1365
|
+
* // Initialize the development consensus heights in order to work with devnode.
|
|
1366
|
+
* getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11");
|
|
1367
|
+
*
|
|
1368
|
+
* // Create a new NetworkClient and RecordProvider.
|
|
1369
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
1370
|
+
* keyProvider.useCache(true);
|
|
1371
|
+
*
|
|
1372
|
+
* // Initialize a program manager.
|
|
1373
|
+
* const programManager = new ProgramManager("http://localhost:3030", recordProvider);
|
|
1374
|
+
*
|
|
1375
|
+
* // Build and execute the transaction.
|
|
1376
|
+
* const tx = await programManager.buildDevnodeExecutionTransaction({
|
|
1377
|
+
* programName: "hello_hello.aleo",
|
|
1378
|
+
* functionName: "hello_hello",
|
|
1379
|
+
* priorityFee: 0.0,
|
|
1380
|
+
* privateFee: false,
|
|
1381
|
+
* inputs: ["5u32", "5u32"],
|
|
1382
|
+
* });
|
|
1383
|
+
*
|
|
1384
|
+
* // Submit the transaction to the network
|
|
1385
|
+
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
1386
|
+
*
|
|
1387
|
+
* // Verify the transaction was successful
|
|
1388
|
+
* setTimeout(async () => {
|
|
1389
|
+
* const transaction = await programManager.networkClient.getTransaction(tx.id());
|
|
1390
|
+
* assert(transaction.id() === tx.id());
|
|
1391
|
+
* }, 10000);
|
|
1392
|
+
*/
|
|
1393
|
+
buildDevnodeExecutionTransaction(options: ExecuteOptions): Promise<Transaction>;
|
|
1394
|
+
/**
|
|
1395
|
+
* Builds a deployment transaction with placeholder certificates and verifying keys for each function in the program.
|
|
1396
|
+
* Intended for use with a local devnode.
|
|
1397
|
+
* `getOrInitConsensusVersionTestHeights` must be called with development heights prior to invoking this method for it to work properly.
|
|
1398
|
+
*
|
|
1399
|
+
* @param {DeployOptions} options - The options for the deployment transaction.
|
|
1400
|
+
* @returns {string} The transaction id of the deployed program or a failure message from the network
|
|
1401
|
+
*
|
|
1402
|
+
* @example
|
|
1403
|
+
* /// Import the mainnet version of the sdk.
|
|
1404
|
+
* import { ProgramManager, NetworkRecordProvider, getOrInitConsensusVersionTestHeights } from "@provablehq/sdk/mainnet.js";
|
|
1405
|
+
*
|
|
1406
|
+
* // Initialize the development consensus heights in order to work with a local devnode.
|
|
1407
|
+
* getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11");
|
|
1408
|
+
*
|
|
1409
|
+
* // Create a new NetworkClient, and RecordProvider
|
|
1410
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
1411
|
+
* keyProvider.useCache(true);
|
|
1412
|
+
*
|
|
1413
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for deployments
|
|
1414
|
+
* const program = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n";
|
|
1415
|
+
* const programManager = new ProgramManager("http://localhost:3030", recordProvider);
|
|
1416
|
+
* programManager.setAccount(Account);
|
|
1417
|
+
*
|
|
1418
|
+
* // Define a fee in credits
|
|
1419
|
+
* const priorityFee = 0.0;
|
|
1420
|
+
*
|
|
1421
|
+
* // Create the deployment transaction.
|
|
1422
|
+
* const tx = await programManager.buildDevnodeDeploymentTransaction({program: program, fee: priorityFee, privateFee: false});
|
|
1423
|
+
* await programManager.networkClient.submitTransaction(tx);
|
|
1424
|
+
*
|
|
1425
|
+
* // Verify the transaction was successful
|
|
1426
|
+
* setTimeout(async () => {
|
|
1427
|
+
* const transaction = await programManager.networkClient.getTransaction(tx.id());
|
|
1428
|
+
* assert(transaction.id() === tx.id());
|
|
1429
|
+
* }, 20000);
|
|
1430
|
+
*/
|
|
1431
|
+
buildDevnodeDeploymentTransaction(options: DeployOptions): Promise<Transaction>;
|
|
1432
|
+
/**
|
|
1433
|
+
* Builds an upgrade transaction on a local devnodewith placeholder certificates and verifying keys for each function in the program.
|
|
1434
|
+
* This method is only intended for use with a local devnode.
|
|
1435
|
+
*
|
|
1436
|
+
* @param {DeployOptions} options - The options for the deployment transaction.
|
|
1437
|
+
* @returns {string} The transaction id of the deployed program or a failure message from the network
|
|
1438
|
+
*
|
|
1439
|
+
* @example
|
|
1440
|
+
* /// Import the mainnet version of the sdk.
|
|
1441
|
+
* import { ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
1442
|
+
*
|
|
1443
|
+
* // Create a new NetworkClient, and RecordProvider
|
|
1444
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
1445
|
+
* keyProvider.useCache(true);
|
|
1446
|
+
*
|
|
1447
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for deployments
|
|
1448
|
+
* const program = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n";
|
|
1449
|
+
* const programManager = new ProgramManager("http://localhost:3030", recordProvider);
|
|
1450
|
+
* programManager.setAccount(Account);
|
|
1451
|
+
*
|
|
1452
|
+
* // Define a fee in credits
|
|
1453
|
+
* const priorityFee = 0.0;
|
|
1454
|
+
*
|
|
1455
|
+
* // Create the deployment transaction.
|
|
1456
|
+
* const tx = await programManager.buildDevnodeUpgradeTransaction({program: program, fee: priorityFee, privateFee: false});
|
|
1457
|
+
* await programManager.networkClient.submitTransaction(tx);
|
|
1458
|
+
*
|
|
1459
|
+
* // Verify the transaction was successful
|
|
1460
|
+
* setTimeout(async () => {
|
|
1461
|
+
* const transaction = await programManager.networkClient.getTransaction(tx.id());
|
|
1462
|
+
* assert(transaction.id() === tx.id());
|
|
1463
|
+
* }, 20000);
|
|
1464
|
+
*/
|
|
1465
|
+
buildDevnodeUpgradeTransaction(options: DeployOptions): Promise<Transaction>;
|
|
1301
1466
|
}
|
|
1302
1467
|
export { ProgramManager, AuthorizationOptions, FeeAuthorizationOptions, ExecuteOptions, ProvingRequestOptions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@provablehq/sdk",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.14",
|
|
4
4
|
"description": "A Software Development Kit (SDK) for Zero-Knowledge Transactions",
|
|
5
5
|
"collaborators": [
|
|
6
6
|
"The Provable Team"
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://github.com/ProvableHQ/sdk#readme",
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@provablehq/wasm": "^0.9.
|
|
54
|
+
"@provablehq/wasm": "^0.9.14",
|
|
55
55
|
"@scure/base": "^2.0.0",
|
|
56
56
|
"comlink": "^4.4.2",
|
|
57
57
|
"core-js": "^3.40.0",
|