@provablehq/sdk 0.11.9 → 0.11.10
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.cts +3 -3
- package/dist/mainnet/account.d.ts +3 -3
- package/dist/mainnet/api-auth.d.cts +14 -9
- package/dist/mainnet/api-auth.d.ts +14 -9
- package/dist/mainnet/browser.cjs +545 -191
- package/dist/mainnet/browser.cjs.map +1 -1
- package/dist/mainnet/browser.d.cts +1 -1
- package/dist/mainnet/browser.d.ts +1 -1
- package/dist/mainnet/browser.js +545 -192
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/keys/provider/interface.d.cts +4 -4
- package/dist/mainnet/keys/provider/interface.d.ts +4 -4
- package/dist/mainnet/keys/provider/memory.d.cts +6 -6
- package/dist/mainnet/keys/provider/memory.d.ts +6 -6
- package/dist/mainnet/keys/provider/offline.d.cts +1 -1
- package/dist/mainnet/keys/provider/offline.d.ts +1 -1
- package/dist/mainnet/network-client.d.cts +40 -38
- package/dist/mainnet/network-client.d.ts +40 -38
- package/dist/mainnet/node.cjs +1 -0
- package/dist/mainnet/node.cjs.map +1 -1
- package/dist/mainnet/node.js +1 -1
- package/dist/mainnet/program-manager.d.cts +132 -35
- package/dist/mainnet/program-manager.d.ts +132 -35
- package/dist/mainnet/record-provider.d.cts +7 -7
- package/dist/mainnet/record-provider.d.ts +7 -7
- package/dist/mainnet/record-scanner.d.cts +3 -3
- package/dist/mainnet/record-scanner.d.ts +3 -3
- package/dist/testnet/account.d.cts +3 -3
- package/dist/testnet/account.d.ts +3 -3
- package/dist/testnet/api-auth.d.cts +14 -9
- package/dist/testnet/api-auth.d.ts +14 -9
- package/dist/testnet/browser.cjs +545 -191
- package/dist/testnet/browser.cjs.map +1 -1
- package/dist/testnet/browser.d.cts +1 -1
- package/dist/testnet/browser.d.ts +1 -1
- package/dist/testnet/browser.js +545 -192
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/keys/provider/interface.d.cts +4 -4
- package/dist/testnet/keys/provider/interface.d.ts +4 -4
- package/dist/testnet/keys/provider/memory.d.cts +6 -6
- package/dist/testnet/keys/provider/memory.d.ts +6 -6
- package/dist/testnet/keys/provider/offline.d.cts +1 -1
- package/dist/testnet/keys/provider/offline.d.ts +1 -1
- package/dist/testnet/network-client.d.cts +40 -38
- package/dist/testnet/network-client.d.ts +40 -38
- package/dist/testnet/node.cjs +1 -0
- package/dist/testnet/node.cjs.map +1 -1
- package/dist/testnet/node.js +1 -1
- package/dist/testnet/program-manager.d.cts +132 -35
- package/dist/testnet/program-manager.d.ts +132 -35
- package/dist/testnet/record-provider.d.cts +7 -7
- package/dist/testnet/record-provider.d.ts +7 -7
- package/dist/testnet/record-scanner.d.cts +3 -3
- package/dist/testnet/record-scanner.d.ts +3 -3
- package/package.json +2 -2
package/dist/testnet/browser.cjs
CHANGED
|
@@ -852,7 +852,7 @@ class Account {
|
|
|
852
852
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/testnet.js";
|
|
853
853
|
*
|
|
854
854
|
* // Create a connection to the Aleo network and an account
|
|
855
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
855
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
856
856
|
* const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
|
|
857
857
|
*
|
|
858
858
|
* // Get the record ciphertexts from a transaction.
|
|
@@ -882,7 +882,7 @@ class Account {
|
|
|
882
882
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/testnet.js";
|
|
883
883
|
*
|
|
884
884
|
* // Create a connection to the Aleo network and an account
|
|
885
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
885
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
886
886
|
* const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
|
|
887
887
|
*
|
|
888
888
|
* // Get the record ciphertexts from a transaction.
|
|
@@ -956,7 +956,7 @@ class Account {
|
|
|
956
956
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/testnet.js";
|
|
957
957
|
*
|
|
958
958
|
* // Create a connection to the Aleo network and an account
|
|
959
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
959
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
960
960
|
* const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
|
|
961
961
|
*
|
|
962
962
|
* // Get the record ciphertexts from a transaction and check ownership of them.
|
|
@@ -1541,10 +1541,12 @@ const DEFAULT_API_KEY_HEADER = "X-API-Key";
|
|
|
1541
1541
|
/**
|
|
1542
1542
|
* Normalize legacy auth options into an explicit {@link ApiAuthConfig}.
|
|
1543
1543
|
*
|
|
1544
|
-
* Rules
|
|
1544
|
+
* Rules:
|
|
1545
1545
|
* - An explicit `auth` wins. Combining it with legacy fields throws — the caller's intent
|
|
1546
1546
|
* is ambiguous and guessing hides misconfiguration.
|
|
1547
|
-
* - A string `apiKey`
|
|
1547
|
+
* - A string `apiKey` on its own selects `api-key` mode with the default header: nothing can
|
|
1548
|
+
* mint a JWT without a `consumerId`, so a lone key is a provisioned edge key.
|
|
1549
|
+
* - A string `apiKey` with a `consumerId`, or a bare `jwtData`, selects `jwt` mode.
|
|
1548
1550
|
* - An `{ header, value }` apiKey selects `api-key` mode with that header. Combining it with
|
|
1549
1551
|
* a `consumerId` throws: keyed auth has no consumer and the pair would silently pick one.
|
|
1550
1552
|
* - Nothing configured selects `none`.
|
|
@@ -1565,6 +1567,11 @@ function normalizeAuthConfig(options) {
|
|
|
1565
1567
|
validateKeyed(config);
|
|
1566
1568
|
return config;
|
|
1567
1569
|
}
|
|
1570
|
+
if (typeof options.apiKey === "string" && options.apiKey !== "" && options.consumerId === undefined && options.jwtData === undefined) {
|
|
1571
|
+
// Nothing can mint a JWT without a consumerId, so a lone key is a provisioned
|
|
1572
|
+
// gateway key (edge.provable.com) and is sent verbatim.
|
|
1573
|
+
return { mode: "api-key", value: options.apiKey };
|
|
1574
|
+
}
|
|
1568
1575
|
if (options.apiKey !== undefined || options.consumerId !== undefined || options.jwtData !== undefined) {
|
|
1569
1576
|
return { mode: "jwt", apiKey: options.apiKey, consumerId: options.consumerId, jwtData: options.jwtData };
|
|
1570
1577
|
}
|
|
@@ -1716,7 +1723,7 @@ const HEADERS = new Set([
|
|
|
1716
1723
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
1717
1724
|
* const apiKey = process.env.apiKey;
|
|
1718
1725
|
* const consumerId = process.env.consumerId;
|
|
1719
|
-
* const publicNetworkClient = new AleoNetworkClient("https://
|
|
1726
|
+
* const publicNetworkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined, account);
|
|
1720
1727
|
*/
|
|
1721
1728
|
class AleoNetworkClient {
|
|
1722
1729
|
host;
|
|
@@ -1735,6 +1742,9 @@ class AleoNetworkClient {
|
|
|
1735
1742
|
// The consumer the cached jwtData was minted for, so the cache is never
|
|
1736
1743
|
// reused for a different identity on a shared client.
|
|
1737
1744
|
jwtConsumerId;
|
|
1745
|
+
// The origin the cached jwtData was minted at, so a token is never reused
|
|
1746
|
+
// for a proving request routed to a different gateway.
|
|
1747
|
+
jwtMintOrigin;
|
|
1738
1748
|
proverUri;
|
|
1739
1749
|
recordScannerUri;
|
|
1740
1750
|
constructor(host, options) {
|
|
@@ -1754,7 +1764,7 @@ class AleoNetworkClient {
|
|
|
1754
1764
|
else {
|
|
1755
1765
|
this.headers = {
|
|
1756
1766
|
// This is replaced by the actual version by a Rollup plugin
|
|
1757
|
-
"X-Aleo-SDK-Version": "0.11.
|
|
1767
|
+
"X-Aleo-SDK-Version": "0.11.10",
|
|
1758
1768
|
"X-Aleo-environment": environment(),
|
|
1759
1769
|
};
|
|
1760
1770
|
}
|
|
@@ -1776,7 +1786,7 @@ class AleoNetworkClient {
|
|
|
1776
1786
|
else {
|
|
1777
1787
|
this.headers = {
|
|
1778
1788
|
// This is replaced by the actual version by a Rollup plugin
|
|
1779
|
-
"X-Aleo-SDK-Version": "0.11.
|
|
1789
|
+
"X-Aleo-SDK-Version": "0.11.10",
|
|
1780
1790
|
"X-Aleo-environment": environment(),
|
|
1781
1791
|
};
|
|
1782
1792
|
}
|
|
@@ -1788,7 +1798,7 @@ class AleoNetworkClient {
|
|
|
1788
1798
|
* @example
|
|
1789
1799
|
* import { Account, AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1790
1800
|
*
|
|
1791
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
1801
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
1792
1802
|
* const account = new Account();
|
|
1793
1803
|
* networkClient.setAccount(account);
|
|
1794
1804
|
*/
|
|
@@ -1816,7 +1826,7 @@ class AleoNetworkClient {
|
|
|
1816
1826
|
* const networkClient = new AleoNetworkClient("http://0.0.0.0:3030", undefined);
|
|
1817
1827
|
*
|
|
1818
1828
|
* // Set the host to a public node.
|
|
1819
|
-
* networkClient.setHost("https://
|
|
1829
|
+
* networkClient.setHost("https://edge.provable.com/api/v2");
|
|
1820
1830
|
*/
|
|
1821
1831
|
setHost(host) {
|
|
1822
1832
|
this.host = host + "/testnet";
|
|
@@ -1830,7 +1840,7 @@ class AleoNetworkClient {
|
|
|
1830
1840
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1831
1841
|
*
|
|
1832
1842
|
* // Create a networkClient that connects to the provable explorer api.
|
|
1833
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
1843
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
1834
1844
|
*
|
|
1835
1845
|
* // Set the prover uri.
|
|
1836
1846
|
* networkClient.setProverUri("https://prover.provable.prove");
|
|
@@ -1847,7 +1857,7 @@ class AleoNetworkClient {
|
|
|
1847
1857
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1848
1858
|
*
|
|
1849
1859
|
* // Create a networkClient that connects to the provable explorer api.
|
|
1850
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
1860
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
1851
1861
|
*
|
|
1852
1862
|
* // Set the record scanner uri.
|
|
1853
1863
|
* networkClient.setRecordScannerUri("https://scanner.provable.scan");
|
|
@@ -1975,7 +1985,7 @@ class AleoNetworkClient {
|
|
|
1975
1985
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
1976
1986
|
*
|
|
1977
1987
|
* // Create a network client.
|
|
1978
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
1988
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
1979
1989
|
* networkClient.setAccount(account);
|
|
1980
1990
|
*
|
|
1981
1991
|
* // Find specific amounts
|
|
@@ -2198,7 +2208,7 @@ class AleoNetworkClient {
|
|
|
2198
2208
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
2199
2209
|
*
|
|
2200
2210
|
* // Create a network client and set an account to search for records with.
|
|
2201
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2211
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2202
2212
|
* networkClient.setAccount(account);
|
|
2203
2213
|
*
|
|
2204
2214
|
* // Find specific amounts
|
|
@@ -2254,7 +2264,7 @@ class AleoNetworkClient {
|
|
|
2254
2264
|
* @example
|
|
2255
2265
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2256
2266
|
*
|
|
2257
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2267
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2258
2268
|
* const block = networkClient.getBlockByHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9");
|
|
2259
2269
|
*/
|
|
2260
2270
|
async getBlockByHash(blockHash) {
|
|
@@ -2312,7 +2322,7 @@ class AleoNetworkClient {
|
|
|
2312
2322
|
* import { AleoNetworkClient } from "@provablehq/sdk/testnet.js";
|
|
2313
2323
|
*
|
|
2314
2324
|
* // Get the transaction ID of the deployment transaction for a program.
|
|
2315
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2325
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2316
2326
|
* const transactionId = networkClient.getDeploymentTransactionIDForProgram("hello_hello.aleo");
|
|
2317
2327
|
*
|
|
2318
2328
|
* // Get the transaction data for the deployment transaction.
|
|
@@ -2347,7 +2357,7 @@ class AleoNetworkClient {
|
|
|
2347
2357
|
* import { AleoNetworkClient, DeploymentJSON } from "@provablehq/sdk/testnet.js";
|
|
2348
2358
|
*
|
|
2349
2359
|
* // Get the transaction ID of the deployment transaction for a program.
|
|
2350
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2360
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2351
2361
|
* const transaction = networkClient.getDeploymentTransactionForProgram("hello_hello.aleo");
|
|
2352
2362
|
*
|
|
2353
2363
|
* // Get the verifying keys for each function in the deployment.
|
|
@@ -2380,7 +2390,7 @@ class AleoNetworkClient {
|
|
|
2380
2390
|
* import { AleoNetworkClient } from "@provablehq/sdk/testnet.js";
|
|
2381
2391
|
*
|
|
2382
2392
|
* // Get the transaction ID of the deployment transaction for a program.
|
|
2383
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2393
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2384
2394
|
* const transactionId = networkClient.getDeploymentTransactionIDForProgram("hello_hello.aleo");
|
|
2385
2395
|
*
|
|
2386
2396
|
* // Get the transaction data for the deployment transaction.
|
|
@@ -2411,7 +2421,7 @@ class AleoNetworkClient {
|
|
|
2411
2421
|
* import { AleoNetworkClient } from "@provablehq/sdk/testnet.js";
|
|
2412
2422
|
*
|
|
2413
2423
|
* // Create a network client.
|
|
2414
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2424
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2415
2425
|
*
|
|
2416
2426
|
* const latestHeight = networkClient.getLatestBlock();
|
|
2417
2427
|
*/
|
|
@@ -2436,10 +2446,10 @@ class AleoNetworkClient {
|
|
|
2436
2446
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2437
2447
|
*
|
|
2438
2448
|
* // Create a network client.
|
|
2439
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2449
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2440
2450
|
*
|
|
2441
2451
|
* // Create a network client and get the latest committee.
|
|
2442
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2452
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2443
2453
|
* const latestCommittee = await networkClient.getLatestCommittee();
|
|
2444
2454
|
*/
|
|
2445
2455
|
async getLatestCommittee() {
|
|
@@ -2464,10 +2474,10 @@ class AleoNetworkClient {
|
|
|
2464
2474
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2465
2475
|
*
|
|
2466
2476
|
* // Create a network client.
|
|
2467
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2477
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2468
2478
|
*
|
|
2469
2479
|
* // Create a network client and get the committee for a specific block.
|
|
2470
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2480
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2471
2481
|
* const committee = await networkClient.getCommitteeByBlockHeight(1234);
|
|
2472
2482
|
*/
|
|
2473
2483
|
async getCommitteeByBlockHeight(blockHeight) {
|
|
@@ -2491,7 +2501,7 @@ class AleoNetworkClient {
|
|
|
2491
2501
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2492
2502
|
*
|
|
2493
2503
|
* // Create a network client.
|
|
2494
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2504
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2495
2505
|
*
|
|
2496
2506
|
* const latestHeight = networkClient.getLatestHeight();
|
|
2497
2507
|
*/
|
|
@@ -2535,7 +2545,7 @@ class AleoNetworkClient {
|
|
|
2535
2545
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2536
2546
|
*
|
|
2537
2547
|
* // Create a network client.
|
|
2538
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2548
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2539
2549
|
*
|
|
2540
2550
|
* // Get the latest block hash.
|
|
2541
2551
|
* const latestHash = networkClient.getLatestBlockHash();
|
|
@@ -2563,7 +2573,7 @@ class AleoNetworkClient {
|
|
|
2563
2573
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2564
2574
|
*
|
|
2565
2575
|
* // Create a network client.
|
|
2566
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2576
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2567
2577
|
*
|
|
2568
2578
|
* // Get the source code of a program.)
|
|
2569
2579
|
* @returns {Promise<string>} Source code of the program
|
|
@@ -2572,7 +2582,7 @@ class AleoNetworkClient {
|
|
|
2572
2582
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2573
2583
|
*
|
|
2574
2584
|
* // Create a network client.
|
|
2575
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2585
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2576
2586
|
*
|
|
2577
2587
|
* const program = networkClient.getProgram("hello_hello.aleo");
|
|
2578
2588
|
* const expectedSource = "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"
|
|
@@ -2605,7 +2615,7 @@ class AleoNetworkClient {
|
|
|
2605
2615
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2606
2616
|
*
|
|
2607
2617
|
* // Create a network client.
|
|
2608
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2618
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2609
2619
|
*
|
|
2610
2620
|
* const programVersion = networkClient.getLatestProgramEdition("hello_hello.aleo");
|
|
2611
2621
|
* assert.equal(programVersion, 1);
|
|
@@ -2630,7 +2640,7 @@ class AleoNetworkClient {
|
|
|
2630
2640
|
* @returns {{ program_id: string, edition: number, amendment_count: number }}
|
|
2631
2641
|
*
|
|
2632
2642
|
* @example
|
|
2633
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2643
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
2634
2644
|
* const info = await networkClient.getProgramAmendmentCount("hello_hello.aleo");
|
|
2635
2645
|
* console.log(info.edition, info.amendment_count);
|
|
2636
2646
|
*/
|
|
@@ -2658,7 +2668,7 @@ class AleoNetworkClient {
|
|
|
2658
2668
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2659
2669
|
*
|
|
2660
2670
|
* // Create a network client.
|
|
2661
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2671
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2662
2672
|
*
|
|
2663
2673
|
* const programID = "hello_hello.aleo";
|
|
2664
2674
|
* const programSource = "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"
|
|
@@ -2698,7 +2708,7 @@ class AleoNetworkClient {
|
|
|
2698
2708
|
* }
|
|
2699
2709
|
*
|
|
2700
2710
|
* // Create a network client.
|
|
2701
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2711
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2702
2712
|
*
|
|
2703
2713
|
* // Imports can be fetched using the program ID, source code, or program object
|
|
2704
2714
|
* let programImports = await networkClient.getProgramImports("double_test.aleo");
|
|
@@ -2768,7 +2778,7 @@ class AleoNetworkClient {
|
|
|
2768
2778
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2769
2779
|
*
|
|
2770
2780
|
* // Create a network client.
|
|
2771
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2781
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2772
2782
|
*
|
|
2773
2783
|
* const programImportsNames = networkClient.getProgramImports("wrapped_credits.aleo");
|
|
2774
2784
|
* const expectedImportsNames = ["credits.aleo"];
|
|
@@ -2799,7 +2809,7 @@ class AleoNetworkClient {
|
|
|
2799
2809
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2800
2810
|
*
|
|
2801
2811
|
* // Create a network client.
|
|
2802
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2812
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2803
2813
|
*
|
|
2804
2814
|
* const mappings = networkClient.getProgramMappingNames("credits.aleo");
|
|
2805
2815
|
* const expectedMappings = [
|
|
@@ -2837,7 +2847,7 @@ class AleoNetworkClient {
|
|
|
2837
2847
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2838
2848
|
*
|
|
2839
2849
|
* // Create a network client.
|
|
2840
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2850
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2841
2851
|
*
|
|
2842
2852
|
* // Get public balance of an account
|
|
2843
2853
|
* const mappingValue = networkClient.getMappingValue("credits.aleo", "account", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
|
|
@@ -2869,7 +2879,7 @@ class AleoNetworkClient {
|
|
|
2869
2879
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2870
2880
|
*
|
|
2871
2881
|
* // Create a network client.
|
|
2872
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2882
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2873
2883
|
*
|
|
2874
2884
|
* // Get the bond state as an account.
|
|
2875
2885
|
* const unbondedState = networkClient.getMappingPlaintext("credits.aleo", "bonded", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
|
|
@@ -2915,7 +2925,7 @@ class AleoNetworkClient {
|
|
|
2915
2925
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
2916
2926
|
*
|
|
2917
2927
|
* // Create a network client.
|
|
2918
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2928
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2919
2929
|
*
|
|
2920
2930
|
* // Get the balance of an account from either an address object or address string.
|
|
2921
2931
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
@@ -2946,7 +2956,7 @@ class AleoNetworkClient {
|
|
|
2946
2956
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
2947
2957
|
*
|
|
2948
2958
|
* // Create a network client.
|
|
2949
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2959
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2950
2960
|
*
|
|
2951
2961
|
* // Get the latest state root.
|
|
2952
2962
|
* const stateRoot = networkClient.getStateRoot();
|
|
@@ -2973,7 +2983,7 @@ class AleoNetworkClient {
|
|
|
2973
2983
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
2974
2984
|
*
|
|
2975
2985
|
* // Create a network client.
|
|
2976
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2986
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2977
2987
|
*
|
|
2978
2988
|
* const transaction = networkClient.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
|
|
2979
2989
|
*/
|
|
@@ -2999,7 +3009,7 @@ class AleoNetworkClient {
|
|
|
2999
3009
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
3000
3010
|
*
|
|
3001
3011
|
* // Create a network client.
|
|
3002
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3012
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
3003
3013
|
*
|
|
3004
3014
|
* const transaction = networkClient.getConfirmedTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
|
|
3005
3015
|
* assert.equal(transaction.status, "confirmed");
|
|
@@ -3064,7 +3074,7 @@ class AleoNetworkClient {
|
|
|
3064
3074
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
3065
3075
|
*
|
|
3066
3076
|
* // Create a network client.
|
|
3067
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3077
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
3068
3078
|
*
|
|
3069
3079
|
* const transactions = networkClient.getTransactions(654);
|
|
3070
3080
|
*/
|
|
@@ -3090,7 +3100,7 @@ class AleoNetworkClient {
|
|
|
3090
3100
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
3091
3101
|
*
|
|
3092
3102
|
* // Create a network client.
|
|
3093
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3103
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
3094
3104
|
*
|
|
3095
3105
|
* const transactions = networkClient.getTransactionsByBlockHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9");
|
|
3096
3106
|
*/
|
|
@@ -3117,7 +3127,7 @@ class AleoNetworkClient {
|
|
|
3117
3127
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
3118
3128
|
*
|
|
3119
3129
|
* // Create a network client.
|
|
3120
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3130
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
3121
3131
|
*
|
|
3122
3132
|
* // Get the current transactions in the mempool.
|
|
3123
3133
|
* const transactions = networkClient.getTransactionsInMempool();
|
|
@@ -3278,17 +3288,34 @@ class AleoNetworkClient {
|
|
|
3278
3288
|
if (options.auth && (options.apiKey !== undefined || options.consumerId !== undefined || options.jwtData !== undefined)) {
|
|
3279
3289
|
throw new Error("Pass either `auth` or the legacy apiKey/consumerId/jwtData options, not both");
|
|
3280
3290
|
}
|
|
3291
|
+
// Mint the JWT at the origin the proving request actually lands on, not the
|
|
3292
|
+
// client's main host: a caller can route proving to a different gateway via
|
|
3293
|
+
// setProverUri or a per-request `url`, and the JWT is validated there.
|
|
3294
|
+
let mintOrigin = this.baseUrl;
|
|
3295
|
+
try {
|
|
3296
|
+
mintOrigin = new URL(proverUri).origin;
|
|
3297
|
+
}
|
|
3298
|
+
catch {
|
|
3299
|
+
// proverUri may carry the unsubstituted testnet placeholder in tests;
|
|
3300
|
+
// fall back to the client host origin.
|
|
3301
|
+
}
|
|
3302
|
+
// A token assigned directly to `jwtData` carries no mint scope: the caller
|
|
3303
|
+
// injected it (an external session owns minting) and it is honored as-is.
|
|
3304
|
+
// A token this client minted is scoped to its consumer and origin below.
|
|
3305
|
+
const injectedJwt = this.jwtMintOrigin === undefined ? this.jwtData : undefined;
|
|
3281
3306
|
const config = options.auth ?? this.auth ?? normalizeAuthConfig({
|
|
3282
3307
|
apiKey: options.apiKey ?? this.apiKey,
|
|
3283
3308
|
consumerId: options.consumerId ?? this.consumerId,
|
|
3284
|
-
jwtData: options.jwtData ??
|
|
3309
|
+
jwtData: options.jwtData ?? injectedJwt,
|
|
3285
3310
|
});
|
|
3286
|
-
const auth = new ApiAuth(config,
|
|
3287
|
-
//
|
|
3288
|
-
//
|
|
3289
|
-
// consumer that minted it
|
|
3290
|
-
// client never
|
|
3291
|
-
|
|
3311
|
+
const auth = new ApiAuth(config, mintOrigin, this.transport, this.method("refreshJwt"));
|
|
3312
|
+
// Reuse the cached client token until the refresh window instead of
|
|
3313
|
+
// minting on every request, but only when this submission targets the
|
|
3314
|
+
// same consumer AND the same gateway origin that minted it — so a shared
|
|
3315
|
+
// client never rides another identity's token or sends one gateway's
|
|
3316
|
+
// token to a different gateway. A per-request jwtData in the config wins.
|
|
3317
|
+
if (config.mode === "jwt" && !config.jwtData && this.jwtData
|
|
3318
|
+
&& config.consumerId === this.jwtConsumerId && mintOrigin === this.jwtMintOrigin) {
|
|
3292
3319
|
auth.setJwtData(this.jwtData);
|
|
3293
3320
|
}
|
|
3294
3321
|
// Resolves the auth headers, which refreshes the JWT when it is stale. Runs before
|
|
@@ -3297,7 +3324,12 @@ class AleoNetworkClient {
|
|
|
3297
3324
|
const jwtData = auth.getJwtData();
|
|
3298
3325
|
if (config.mode === "jwt" && jwtData) {
|
|
3299
3326
|
this.jwtData = jwtData;
|
|
3300
|
-
this.
|
|
3327
|
+
// Only a token this client minted gets a scope. An injected token that
|
|
3328
|
+
// passed through unchanged stays unscoped so later calls keep honoring it.
|
|
3329
|
+
if (jwtData !== config.jwtData) {
|
|
3330
|
+
this.jwtConsumerId = config.consumerId;
|
|
3331
|
+
this.jwtMintOrigin = mintOrigin;
|
|
3332
|
+
}
|
|
3301
3333
|
options.jwtData = jwtData;
|
|
3302
3334
|
}
|
|
3303
3335
|
// Create the necessary headers to hit the provable api.
|
|
@@ -3388,7 +3420,7 @@ class AleoNetworkClient {
|
|
|
3388
3420
|
* import { AleoNetworkClient, Account, ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
3389
3421
|
*
|
|
3390
3422
|
* // Create a network client and program manager.
|
|
3391
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3423
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
3392
3424
|
* const programManager = new ProgramManager(networkClient);
|
|
3393
3425
|
*
|
|
3394
3426
|
* // Set the account for the program manager.
|
|
@@ -3636,12 +3668,12 @@ class AleoKeyProvider {
|
|
|
3636
3668
|
*
|
|
3637
3669
|
* @example
|
|
3638
3670
|
* // Create a new object which implements the KeyProvider interface
|
|
3639
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3671
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
3640
3672
|
* const keyProvider = new AleoKeyProvider();
|
|
3641
3673
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
3642
3674
|
*
|
|
3643
3675
|
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
3644
|
-
* const programManager = new ProgramManager("https://
|
|
3676
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
3645
3677
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
3646
3678
|
*
|
|
3647
3679
|
* // Keys can also be fetched manually using the key provider
|
|
@@ -3688,12 +3720,12 @@ class AleoKeyProvider {
|
|
|
3688
3720
|
*
|
|
3689
3721
|
* @example
|
|
3690
3722
|
* // Create a new AleoKeyProvider object
|
|
3691
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3723
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
3692
3724
|
* const keyProvider = new AleoKeyProvider();
|
|
3693
3725
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
3694
3726
|
*
|
|
3695
3727
|
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
3696
|
-
* const programManager = new ProgramManager("https://
|
|
3728
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
3697
3729
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
3698
3730
|
*
|
|
3699
3731
|
* // Keys can also be fetched manually
|
|
@@ -3811,12 +3843,12 @@ class AleoKeyProvider {
|
|
|
3811
3843
|
*
|
|
3812
3844
|
* @example
|
|
3813
3845
|
* // Create a new AleoKeyProvider
|
|
3814
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3846
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
3815
3847
|
* const keyProvider = new AleoKeyProvider();
|
|
3816
3848
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
3817
3849
|
*
|
|
3818
3850
|
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
3819
|
-
* const programManager = new ProgramManager("https://
|
|
3851
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
3820
3852
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
3821
3853
|
*
|
|
3822
3854
|
* // Keys can also be fetched manually
|
|
@@ -4161,7 +4193,7 @@ class OfflineSearchParams {
|
|
|
4161
4193
|
* const offlineExecuteTx = <Transaction>await this.buildExecutionTransaction("hello_hello.aleo", "hello", 1, false, ["5u32", "5u32"], undefined, offlineSearchParams, undefined, undefined, undefined, undefined, offlineQuery, program);
|
|
4162
4194
|
*
|
|
4163
4195
|
* // Broadcast the transaction later on a machine with internet access
|
|
4164
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
4196
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
4165
4197
|
* const txId = await networkClient.broadcastTransaction(offlineExecuteTx);
|
|
4166
4198
|
*/
|
|
4167
4199
|
class OfflineKeyProvider {
|
|
@@ -4621,7 +4653,7 @@ class NetworkRecordProvider {
|
|
|
4621
4653
|
*
|
|
4622
4654
|
* @example
|
|
4623
4655
|
* // Create a new NetworkRecordProvider
|
|
4624
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
4656
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
4625
4657
|
* const keyProvider = new AleoKeyProvider();
|
|
4626
4658
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
4627
4659
|
*
|
|
@@ -4634,7 +4666,7 @@ class NetworkRecordProvider {
|
|
|
4634
4666
|
*
|
|
4635
4667
|
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
4636
4668
|
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
4637
|
-
* const programManager = new ProgramManager("https://
|
|
4669
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
4638
4670
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
4639
4671
|
*
|
|
4640
4672
|
* */
|
|
@@ -4682,7 +4714,7 @@ class NetworkRecordProvider {
|
|
|
4682
4714
|
*
|
|
4683
4715
|
* @example
|
|
4684
4716
|
* // Create a new NetworkRecordProvider
|
|
4685
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
4717
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
4686
4718
|
* const keyProvider = new AleoKeyProvider();
|
|
4687
4719
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
4688
4720
|
*
|
|
@@ -4695,7 +4727,7 @@ class NetworkRecordProvider {
|
|
|
4695
4727
|
*
|
|
4696
4728
|
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
4697
4729
|
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
4698
|
-
* const programManager = new ProgramManager("https://
|
|
4730
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
4699
4731
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
4700
4732
|
*/
|
|
4701
4733
|
async findCreditsRecord(microcredits, searchParameters) {
|
|
@@ -4791,7 +4823,7 @@ class NetworkRecordProvider {
|
|
|
4791
4823
|
* const params = new BlockHeightSearch(89995, 99995);
|
|
4792
4824
|
*
|
|
4793
4825
|
* // Create a new NetworkRecordProvider
|
|
4794
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
4826
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
4795
4827
|
* const keyProvider = new AleoKeyProvider();
|
|
4796
4828
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
4797
4829
|
*
|
|
@@ -4982,7 +5014,9 @@ class RecordScanner {
|
|
|
4982
5014
|
* @param {RecordScannerJWTData | undefined} jwtData The JWT data to use, or undefined to clear.
|
|
4983
5015
|
*/
|
|
4984
5016
|
setJwtData(jwtData) {
|
|
4985
|
-
|
|
5017
|
+
// Rebuild rather than store: with a lone legacy apiKey the mode is api-key
|
|
5018
|
+
// until a JWT exists, and a JWT is only sent from jwt mode.
|
|
5019
|
+
this.auth = this.buildAuth(jwtData);
|
|
4986
5020
|
}
|
|
4987
5021
|
/**
|
|
4988
5022
|
* Set whether /owned should automatically re-register on 422 (when a view key for the UUID is in viewKeys or account) and retry once.
|
|
@@ -5945,33 +5979,129 @@ function generateHookData(recipientAddress, secretNonce) {
|
|
|
5945
5979
|
return hookData;
|
|
5946
5980
|
}
|
|
5947
5981
|
|
|
5948
|
-
const
|
|
5949
|
-
|
|
5950
|
-
|
|
5982
|
+
const preparedContextBuilders = new WeakMap();
|
|
5983
|
+
const preparedProcessPrograms = new WeakMap();
|
|
5984
|
+
const preparedProgramImports = new WeakMap();
|
|
5985
|
+
const preparedContextQueues = new WeakMap();
|
|
5986
|
+
const CREDITS_PROGRAM_ID = "credits.aleo";
|
|
5987
|
+
let canonicalCreditsProgramSource;
|
|
5988
|
+
function normalizeProgramSource(program) {
|
|
5989
|
+
return program instanceof testnet_js.Program ? program.toString() : program;
|
|
5990
|
+
}
|
|
5991
|
+
function getCanonicalCreditsProgramSource() {
|
|
5992
|
+
if (canonicalCreditsProgramSource === undefined) {
|
|
5993
|
+
const creditsProgram = testnet_js.Program.getCreditsProgram();
|
|
5994
|
+
try {
|
|
5995
|
+
canonicalCreditsProgramSource = creditsProgram.toString();
|
|
5996
|
+
}
|
|
5997
|
+
finally {
|
|
5998
|
+
creditsProgram.free();
|
|
5999
|
+
}
|
|
6000
|
+
}
|
|
6001
|
+
return canonicalCreditsProgramSource;
|
|
6002
|
+
}
|
|
6003
|
+
function isCanonicalCreditsProgramSource(source) {
|
|
6004
|
+
if (source instanceof testnet_js.Program) {
|
|
6005
|
+
return source.toString() === getCanonicalCreditsProgramSource();
|
|
6006
|
+
}
|
|
6007
|
+
// API responses may format the same program differently (for example,
|
|
6008
|
+
// numeric separators), so compare snarkVM's canonical serialization.
|
|
6009
|
+
let parsed;
|
|
6010
|
+
try {
|
|
6011
|
+
parsed = testnet_js.Program.fromString(source);
|
|
6012
|
+
return parsed.toString() === getCanonicalCreditsProgramSource();
|
|
6013
|
+
}
|
|
6014
|
+
catch {
|
|
6015
|
+
return false;
|
|
6016
|
+
}
|
|
6017
|
+
finally {
|
|
6018
|
+
parsed?.free();
|
|
6019
|
+
}
|
|
6020
|
+
}
|
|
6021
|
+
function preparedProcessHasCompatibleImport(programs, name, source) {
|
|
6022
|
+
// Every snarkVM process already contains credits.aleo, and the imports
|
|
6023
|
+
// builder intentionally does not retain that built-in in its metadata.
|
|
6024
|
+
if (name === CREDITS_PROGRAM_ID) {
|
|
6025
|
+
return isCanonicalCreditsProgramSource(source);
|
|
6026
|
+
}
|
|
6027
|
+
return programs.get(name)?.programSource === normalizeProgramSource(source);
|
|
6028
|
+
}
|
|
6029
|
+
function preparedProcessSupports(preparedProcess, options) {
|
|
6030
|
+
const programs = preparedProcessPrograms.get(preparedProcess);
|
|
6031
|
+
const builder = preparedContextBuilders.get(preparedProcess);
|
|
6032
|
+
if (!programs || !builder)
|
|
6033
|
+
return false;
|
|
6034
|
+
const program = programs.get(options.programName);
|
|
6035
|
+
if (!program)
|
|
6036
|
+
return false;
|
|
6037
|
+
if (options.functionName !== undefined
|
|
6038
|
+
&& !program.functions.includes(options.functionName)) {
|
|
6039
|
+
return false;
|
|
6040
|
+
}
|
|
6041
|
+
if (options.programSource !== undefined
|
|
6042
|
+
&& normalizeProgramSource(options.programSource) !== program.programSource) {
|
|
6043
|
+
return false;
|
|
6044
|
+
}
|
|
6045
|
+
if (options.edition !== undefined && options.edition !== program.edition) {
|
|
6046
|
+
return false;
|
|
6047
|
+
}
|
|
6048
|
+
if (options.programImports) {
|
|
6049
|
+
for (const [name, source] of Object.entries(options.programImports)) {
|
|
6050
|
+
if (!preparedProcessHasCompatibleImport(programs, name, source)) {
|
|
6051
|
+
return false;
|
|
6052
|
+
}
|
|
6053
|
+
}
|
|
6054
|
+
}
|
|
6055
|
+
return true;
|
|
6056
|
+
}
|
|
6057
|
+
function selectedPreparedContext(options) {
|
|
6058
|
+
if (options.preparedProgram && options.preparedProcess) {
|
|
6059
|
+
throw new Error("Specify either preparedProgram or preparedProcess, not both");
|
|
6060
|
+
}
|
|
6061
|
+
return options.preparedProcess ?? options.preparedProgram;
|
|
6062
|
+
}
|
|
6063
|
+
/**
|
|
6064
|
+
* Serialize WASM calls that borrow a prepared context's snarkVM process.
|
|
6065
|
+
*
|
|
6066
|
+
* WASM builder clones are reference-counted handles to one mutable snarkVM
|
|
6067
|
+
* process guarded by a RefCell. Overlapping borrows would panic and abort the
|
|
6068
|
+
* WASM module, so calls sharing a context are queued behind one another at the
|
|
6069
|
+
* WASM boundary. Only the WASM call itself is queued: network resolution and
|
|
6070
|
+
* fee record lookup still run concurrently across calls.
|
|
6071
|
+
*
|
|
6072
|
+
* The entry points that accept a prepared context currently complete their
|
|
6073
|
+
* borrow without yielding, so the queue never waits in practice. It exists to
|
|
6074
|
+
* turn a future borrow-across-await into a delayed call rather than a panic.
|
|
6075
|
+
*/
|
|
6076
|
+
function withPreparedContextWasm(preparedContext, call) {
|
|
6077
|
+
if (!preparedContext)
|
|
6078
|
+
return call();
|
|
6079
|
+
const previous = preparedContextQueues.get(preparedContext) ?? Promise.resolve();
|
|
6080
|
+
const next = previous.then(call, call);
|
|
6081
|
+
// Keep the queue alive regardless of how this call settles so one failure
|
|
6082
|
+
// does not block later calls on the same context. Normalize both outcomes
|
|
6083
|
+
// so the queue does not retain a successful WASM result.
|
|
6084
|
+
const tail = next.then(() => undefined, () => undefined);
|
|
6085
|
+
preparedContextQueues.set(preparedContext, tail);
|
|
6086
|
+
return next;
|
|
6087
|
+
}
|
|
6088
|
+
function clonePreparedContextBuilder(preparedContext) {
|
|
6089
|
+
const builder = preparedContextBuilders.get(preparedContext);
|
|
5951
6090
|
if (!builder) {
|
|
5952
|
-
throw new Error(
|
|
6091
|
+
throw new Error(preparedContext instanceof PreparedProcess
|
|
6092
|
+
? "Prepared process has already been freed"
|
|
6093
|
+
: "Prepared program has already been freed");
|
|
5953
6094
|
}
|
|
5954
6095
|
// The WASM clone is a cheap shared Rc handle, not a deep copy. Mutations
|
|
5955
6096
|
// made while authorizing intentionally remain cached in the prepared context.
|
|
5956
6097
|
return builder.clone();
|
|
5957
6098
|
}
|
|
5958
|
-
function programImportsFromBuilder(builder, entryProgramName) {
|
|
5959
|
-
const imports = {};
|
|
5960
|
-
for (const name of Array.from(builder.programNames())) {
|
|
5961
|
-
if (name === entryProgramName)
|
|
5962
|
-
continue;
|
|
5963
|
-
const source = builder.getProgram(name);
|
|
5964
|
-
if (source)
|
|
5965
|
-
imports[name] = source;
|
|
5966
|
-
}
|
|
5967
|
-
return imports;
|
|
5968
|
-
}
|
|
5969
6099
|
/**
|
|
5970
6100
|
* A reusable program context created by {@link ProgramManager.prepareProgram}.
|
|
5971
6101
|
*
|
|
5972
|
-
* The context is scoped to one program function.
|
|
5973
|
-
*
|
|
5974
|
-
* is no longer needed.
|
|
6102
|
+
* The context is scoped to one program function. Concurrent calls sharing it
|
|
6103
|
+
* are serialized at the WASM boundary. The caller owns the context and should
|
|
6104
|
+
* call {@link free} when it is no longer needed.
|
|
5975
6105
|
*/
|
|
5976
6106
|
class PreparedProgram {
|
|
5977
6107
|
programName;
|
|
@@ -5991,8 +6121,45 @@ class PreparedProgram {
|
|
|
5991
6121
|
* Release the prepared snarkVM process. This method is idempotent.
|
|
5992
6122
|
*/
|
|
5993
6123
|
free() {
|
|
5994
|
-
|
|
5995
|
-
|
|
6124
|
+
preparedContextBuilders.get(this)?.free();
|
|
6125
|
+
preparedContextBuilders.delete(this);
|
|
6126
|
+
preparedProgramImports.delete(this);
|
|
6127
|
+
}
|
|
6128
|
+
}
|
|
6129
|
+
/**
|
|
6130
|
+
* A reusable snarkVM process created by {@link ProgramManager.prepareProcess}.
|
|
6131
|
+
*
|
|
6132
|
+
* Unlike {@link PreparedProgram}, a prepared process can authorize any
|
|
6133
|
+
* function in any loaded program. Extra loaded programs remain idle when a
|
|
6134
|
+
* call only needs a subset. Concurrent calls sharing the process are
|
|
6135
|
+
* serialized at the WASM boundary.
|
|
6136
|
+
*/
|
|
6137
|
+
class PreparedProcess {
|
|
6138
|
+
programs;
|
|
6139
|
+
/** Instances are normally created through {@link ProgramManager.prepareProcess}. */
|
|
6140
|
+
constructor(programs) {
|
|
6141
|
+
this.programs = Object.freeze(programs.map((program) => Object.freeze({
|
|
6142
|
+
...program,
|
|
6143
|
+
functions: Object.freeze([...program.functions]),
|
|
6144
|
+
})));
|
|
6145
|
+
}
|
|
6146
|
+
/** Names of all programs loaded into this process. */
|
|
6147
|
+
get programNames() {
|
|
6148
|
+
return this.programs.map(({ programName }) => programName);
|
|
6149
|
+
}
|
|
6150
|
+
/**
|
|
6151
|
+
* Check whether the process can serve a call without network resolution or
|
|
6152
|
+
* process rebuilding. Caller-provided imports may be a subset of the
|
|
6153
|
+
* programs loaded into the process.
|
|
6154
|
+
*/
|
|
6155
|
+
supports(options) {
|
|
6156
|
+
return preparedProcessSupports(this, options);
|
|
6157
|
+
}
|
|
6158
|
+
/** Release the prepared snarkVM process. This method is idempotent. */
|
|
6159
|
+
free() {
|
|
6160
|
+
preparedContextBuilders.get(this)?.free();
|
|
6161
|
+
preparedContextBuilders.delete(this);
|
|
6162
|
+
preparedProcessPrograms.delete(this);
|
|
5996
6163
|
}
|
|
5997
6164
|
}
|
|
5998
6165
|
/**
|
|
@@ -6013,7 +6180,7 @@ class ProgramManager {
|
|
|
6013
6180
|
* @param { RecordProvider | undefined } recordProvider A record provider that implements {@link RecordProvider} interface
|
|
6014
6181
|
*/
|
|
6015
6182
|
constructor(host, keyProvider, recordProvider, networkClientOptions, keyStore) {
|
|
6016
|
-
this.host = host ? host : "https://
|
|
6183
|
+
this.host = host ? host : "https://edge.provable.com/api/v2";
|
|
6017
6184
|
this.networkClient = new AleoNetworkClient(this.host, networkClientOptions);
|
|
6018
6185
|
this.keyProvider = keyProvider ? keyProvider : new AleoKeyProvider({ transport: networkClientOptions?.transport });
|
|
6019
6186
|
this.recordProvider = recordProvider;
|
|
@@ -6144,11 +6311,16 @@ class ProgramManager {
|
|
|
6144
6311
|
program = program.toString();
|
|
6145
6312
|
}
|
|
6146
6313
|
const parsedProgram = testnet_js.Program.fromString(program);
|
|
6147
|
-
|
|
6148
|
-
|
|
6314
|
+
try {
|
|
6315
|
+
if (parsedProgram.id() !== options.programName) {
|
|
6316
|
+
throw new Error(`Program source ID '${parsedProgram.id()}' does not match requested program '${options.programName}'`);
|
|
6317
|
+
}
|
|
6318
|
+
if (!parsedProgram.getFunctions().includes(options.functionName)) {
|
|
6319
|
+
throw new Error(`Function '${options.functionName}' does not exist in program '${options.programName}'`);
|
|
6320
|
+
}
|
|
6149
6321
|
}
|
|
6150
|
-
|
|
6151
|
-
|
|
6322
|
+
finally {
|
|
6323
|
+
parsedProgram.free();
|
|
6152
6324
|
}
|
|
6153
6325
|
const edition = options.edition
|
|
6154
6326
|
?? (await this.resolveEditionAndAmendment(options.programName)).edition;
|
|
@@ -6156,10 +6328,171 @@ class ProgramManager {
|
|
|
6156
6328
|
// Add the entry program as well as its imports so the snarkVM process is
|
|
6157
6329
|
// fully initialized before an authorization is requested.
|
|
6158
6330
|
builder.addProgram(options.programName, program, edition);
|
|
6331
|
+
// Snapshot the import sources once so later validation is answered from
|
|
6332
|
+
// JavaScript and never borrows the shared WASM process.
|
|
6333
|
+
const importSources = new Map();
|
|
6334
|
+
for (const name of Array.from(builder.programNames())) {
|
|
6335
|
+
if (name === options.programName)
|
|
6336
|
+
continue;
|
|
6337
|
+
const source = builder.getProgram(name);
|
|
6338
|
+
if (source !== undefined)
|
|
6339
|
+
importSources.set(name, source);
|
|
6340
|
+
}
|
|
6159
6341
|
const preparedProgram = new PreparedProgram(options.programName, options.functionName, program, edition);
|
|
6160
|
-
|
|
6342
|
+
preparedContextBuilders.set(preparedProgram, builder);
|
|
6343
|
+
preparedProgramImports.set(preparedProgram, importSources);
|
|
6161
6344
|
return preparedProgram;
|
|
6162
6345
|
}
|
|
6346
|
+
/**
|
|
6347
|
+
* Prepare one reusable snarkVM process for multiple programs and functions.
|
|
6348
|
+
*
|
|
6349
|
+
* Sources, editions, and transitive imports are resolved once. Every
|
|
6350
|
+
* loaded program can later be used as an entry program, and an invocation
|
|
6351
|
+
* may supply any matching subset of the preloaded imports.
|
|
6352
|
+
*
|
|
6353
|
+
* @example
|
|
6354
|
+
* const prepared = await programManager.prepareProcess({
|
|
6355
|
+
* programs: [
|
|
6356
|
+
* { programName: "wallet_router.aleo" },
|
|
6357
|
+
* { programName: "token_registry.aleo" },
|
|
6358
|
+
* ],
|
|
6359
|
+
* programImports: dynamicDispatchTargets,
|
|
6360
|
+
* });
|
|
6361
|
+
* try {
|
|
6362
|
+
* const authorization = await programManager.buildAuthorizationUnchecked({
|
|
6363
|
+
* programName: "wallet_router.aleo",
|
|
6364
|
+
* functionName: "transfer",
|
|
6365
|
+
* inputs,
|
|
6366
|
+
* preparedProcess: prepared,
|
|
6367
|
+
* });
|
|
6368
|
+
* } finally {
|
|
6369
|
+
* prepared.free();
|
|
6370
|
+
* }
|
|
6371
|
+
*/
|
|
6372
|
+
async prepareProcess(options) {
|
|
6373
|
+
if (!Array.isArray(options.programs) || options.programs.length === 0) {
|
|
6374
|
+
throw new Error("At least one program is required to prepare a process");
|
|
6375
|
+
}
|
|
6376
|
+
const requestedNames = new Set();
|
|
6377
|
+
for (const program of options.programs) {
|
|
6378
|
+
if (requestedNames.has(program.programName)) {
|
|
6379
|
+
throw new Error(`Program '${program.programName}' was requested more than once`);
|
|
6380
|
+
}
|
|
6381
|
+
requestedNames.add(program.programName);
|
|
6382
|
+
}
|
|
6383
|
+
const requestedPrograms = await Promise.all(options.programs.map(async (requested) => {
|
|
6384
|
+
let source = requested.programSource;
|
|
6385
|
+
if (source === undefined) {
|
|
6386
|
+
try {
|
|
6387
|
+
source = await this.networkClient.getProgram(requested.programName);
|
|
6388
|
+
}
|
|
6389
|
+
catch (e) {
|
|
6390
|
+
logAndThrow(`Error finding ${requested.programName}. Network response: '${e.message}'. Please ensure you're connected to a valid Aleo network the program is deployed to the network.`);
|
|
6391
|
+
}
|
|
6392
|
+
}
|
|
6393
|
+
const programSource = normalizeProgramSource(source);
|
|
6394
|
+
const edition = requested.edition
|
|
6395
|
+
?? (await this.resolveEditionAndAmendment(requested.programName)).edition;
|
|
6396
|
+
return { programName: requested.programName, programSource, edition };
|
|
6397
|
+
}));
|
|
6398
|
+
const sources = new Map();
|
|
6399
|
+
const editions = new Map();
|
|
6400
|
+
const mergeSource = (name, source) => {
|
|
6401
|
+
const existing = sources.get(name);
|
|
6402
|
+
if (existing !== undefined && existing !== source) {
|
|
6403
|
+
throw new Error(`Conflicting sources were supplied for program '${name}'`);
|
|
6404
|
+
}
|
|
6405
|
+
sources.set(name, source);
|
|
6406
|
+
};
|
|
6407
|
+
for (const program of requestedPrograms) {
|
|
6408
|
+
mergeSource(program.programName, program.programSource);
|
|
6409
|
+
editions.set(program.programName, program.edition);
|
|
6410
|
+
}
|
|
6411
|
+
// Treat every explicitly requested program as already known while
|
|
6412
|
+
// resolving imports for its siblings. Otherwise, a requested program
|
|
6413
|
+
// that statically imports another requested program would fetch that
|
|
6414
|
+
// sibling from the network again and could conflict with the source
|
|
6415
|
+
// supplied by the caller.
|
|
6416
|
+
const knownProgramSources = {
|
|
6417
|
+
...Object.fromEntries(requestedPrograms.map((program) => [
|
|
6418
|
+
program.programName,
|
|
6419
|
+
program.programSource,
|
|
6420
|
+
])),
|
|
6421
|
+
...(options.programImports ?? {}),
|
|
6422
|
+
};
|
|
6423
|
+
const collectedImports = await Promise.all(requestedPrograms.map((program) => this.collectProgramImports(program.programSource, knownProgramSources, true)));
|
|
6424
|
+
for (const imports of collectedImports) {
|
|
6425
|
+
for (const [name, source] of imports)
|
|
6426
|
+
mergeSource(name, source);
|
|
6427
|
+
}
|
|
6428
|
+
const functions = new Map();
|
|
6429
|
+
const staticImports = new Map();
|
|
6430
|
+
for (const [name, source] of sources) {
|
|
6431
|
+
const parsed = testnet_js.Program.fromString(source);
|
|
6432
|
+
try {
|
|
6433
|
+
if (parsed.id() !== name) {
|
|
6434
|
+
throw new Error(`Program source ID '${parsed.id()}' does not match supplied program name '${name}'`);
|
|
6435
|
+
}
|
|
6436
|
+
functions.set(name, Object.freeze(Array.from(parsed.getFunctions())));
|
|
6437
|
+
staticImports.set(name, Object.freeze(Array.from(parsed.getImports())));
|
|
6438
|
+
}
|
|
6439
|
+
finally {
|
|
6440
|
+
parsed.free();
|
|
6441
|
+
}
|
|
6442
|
+
}
|
|
6443
|
+
for (const [name, imports] of staticImports) {
|
|
6444
|
+
for (const importedName of imports) {
|
|
6445
|
+
if (importedName !== CREDITS_PROGRAM_ID && !sources.has(importedName)) {
|
|
6446
|
+
throw new Error(`Missing import '${importedName}' required by program '${name}'`);
|
|
6447
|
+
}
|
|
6448
|
+
}
|
|
6449
|
+
}
|
|
6450
|
+
await Promise.all(Array.from(sources.keys()).map(async (name) => {
|
|
6451
|
+
if (!editions.has(name)) {
|
|
6452
|
+
editions.set(name, (await this.resolveEditionAndAmendment(name)).edition);
|
|
6453
|
+
}
|
|
6454
|
+
}));
|
|
6455
|
+
const sortedNames = [];
|
|
6456
|
+
const visited = new Set();
|
|
6457
|
+
const visiting = new Set();
|
|
6458
|
+
const visit = (name) => {
|
|
6459
|
+
if (visited.has(name))
|
|
6460
|
+
return;
|
|
6461
|
+
if (visiting.has(name)) {
|
|
6462
|
+
throw new Error(`Cyclic program imports include '${name}'`);
|
|
6463
|
+
}
|
|
6464
|
+
visiting.add(name);
|
|
6465
|
+
for (const dependency of staticImports.get(name) ?? []) {
|
|
6466
|
+
if (sources.has(dependency))
|
|
6467
|
+
visit(dependency);
|
|
6468
|
+
}
|
|
6469
|
+
visiting.delete(name);
|
|
6470
|
+
visited.add(name);
|
|
6471
|
+
sortedNames.push(name);
|
|
6472
|
+
};
|
|
6473
|
+
for (const name of sources.keys())
|
|
6474
|
+
visit(name);
|
|
6475
|
+
const builder = new testnet_js.ProgramImports();
|
|
6476
|
+
try {
|
|
6477
|
+
for (const name of sortedNames) {
|
|
6478
|
+
builder.addProgram(name, sources.get(name), editions.get(name));
|
|
6479
|
+
}
|
|
6480
|
+
}
|
|
6481
|
+
catch (e) {
|
|
6482
|
+
builder.free();
|
|
6483
|
+
throw e;
|
|
6484
|
+
}
|
|
6485
|
+
const processPrograms = sortedNames.map((name) => ({
|
|
6486
|
+
programName: name,
|
|
6487
|
+
programSource: sources.get(name),
|
|
6488
|
+
edition: editions.get(name),
|
|
6489
|
+
functions: functions.get(name),
|
|
6490
|
+
}));
|
|
6491
|
+
const preparedProcess = new PreparedProcess(processPrograms);
|
|
6492
|
+
preparedContextBuilders.set(preparedProcess, builder);
|
|
6493
|
+
preparedProcessPrograms.set(preparedProcess, new Map(preparedProcess.programs.map((program) => [program.programName, program])));
|
|
6494
|
+
return preparedProcess;
|
|
6495
|
+
}
|
|
6163
6496
|
validatePreparedProgram(preparedProgram, options) {
|
|
6164
6497
|
if (preparedProgram.programName !== options.programName
|
|
6165
6498
|
|| preparedProgram.functionName !== options.functionName) {
|
|
@@ -6177,18 +6510,65 @@ class ProgramManager {
|
|
|
6177
6510
|
throw new Error("Prepared program edition does not match the supplied edition");
|
|
6178
6511
|
}
|
|
6179
6512
|
if (options.programImports) {
|
|
6180
|
-
const
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6513
|
+
const importSources = preparedProgramImports.get(preparedProgram);
|
|
6514
|
+
if (!importSources || !preparedContextBuilders.has(preparedProgram)) {
|
|
6515
|
+
throw new Error("Prepared program has already been freed");
|
|
6516
|
+
}
|
|
6517
|
+
for (const [name, source] of Object.entries(options.programImports)) {
|
|
6518
|
+
if (importSources.get(name) !== normalizeProgramSource(source)) {
|
|
6519
|
+
throw new Error(`Prepared program import '${name}' does not match the supplied import`);
|
|
6186
6520
|
}
|
|
6187
6521
|
}
|
|
6188
|
-
|
|
6189
|
-
|
|
6522
|
+
}
|
|
6523
|
+
}
|
|
6524
|
+
validatePreparedProcess(preparedProcess, options) {
|
|
6525
|
+
const programs = preparedProcessPrograms.get(preparedProcess);
|
|
6526
|
+
if (!programs || !preparedContextBuilders.has(preparedProcess)) {
|
|
6527
|
+
throw new Error("Prepared process has already been freed");
|
|
6528
|
+
}
|
|
6529
|
+
const program = programs.get(options.programName);
|
|
6530
|
+
if (!program) {
|
|
6531
|
+
throw new Error(`Prepared process does not contain program '${options.programName}'`);
|
|
6532
|
+
}
|
|
6533
|
+
if (!program.functions.includes(options.functionName)) {
|
|
6534
|
+
throw new Error(`Prepared process does not contain function '${options.programName}/${options.functionName}'`);
|
|
6535
|
+
}
|
|
6536
|
+
if (options.programSource !== undefined
|
|
6537
|
+
&& normalizeProgramSource(options.programSource) !== program.programSource) {
|
|
6538
|
+
throw new Error("Prepared process source does not match the supplied program source");
|
|
6539
|
+
}
|
|
6540
|
+
if (options.edition !== undefined && options.edition !== program.edition) {
|
|
6541
|
+
throw new Error("Prepared process edition does not match the supplied edition");
|
|
6542
|
+
}
|
|
6543
|
+
if (options.programImports) {
|
|
6544
|
+
for (const [name, source] of Object.entries(options.programImports)) {
|
|
6545
|
+
if (!preparedProcessHasCompatibleImport(programs, name, source)) {
|
|
6546
|
+
throw new Error(`Prepared process import '${name}' does not match a loaded program`);
|
|
6547
|
+
}
|
|
6190
6548
|
}
|
|
6191
6549
|
}
|
|
6550
|
+
return program;
|
|
6551
|
+
}
|
|
6552
|
+
preparedCallContext(options) {
|
|
6553
|
+
const context = selectedPreparedContext(options);
|
|
6554
|
+
if (!context)
|
|
6555
|
+
return undefined;
|
|
6556
|
+
if (context instanceof PreparedProcess) {
|
|
6557
|
+
const program = this.validatePreparedProcess(context, options);
|
|
6558
|
+
return {
|
|
6559
|
+
context,
|
|
6560
|
+
programName: program.programName,
|
|
6561
|
+
programSource: program.programSource,
|
|
6562
|
+
edition: program.edition,
|
|
6563
|
+
};
|
|
6564
|
+
}
|
|
6565
|
+
this.validatePreparedProgram(context, options);
|
|
6566
|
+
return {
|
|
6567
|
+
context,
|
|
6568
|
+
programName: context.programName,
|
|
6569
|
+
programSource: context.programSource,
|
|
6570
|
+
edition: context.edition,
|
|
6571
|
+
};
|
|
6192
6572
|
}
|
|
6193
6573
|
/**
|
|
6194
6574
|
* Collect static imports declared by the entry program together with any
|
|
@@ -6517,7 +6897,7 @@ class ProgramManager {
|
|
|
6517
6897
|
* import { ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
6518
6898
|
*
|
|
6519
6899
|
* // Create a ProgramManager
|
|
6520
|
-
* const programManager = new ProgramManager("https://
|
|
6900
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2");
|
|
6521
6901
|
*
|
|
6522
6902
|
* // Set the value of the `Accept-Language` header to `en-US`
|
|
6523
6903
|
* programManager.setHeader('Accept-Language', 'en-US');
|
|
@@ -6538,7 +6918,7 @@ class ProgramManager {
|
|
|
6538
6918
|
* keyProvider.useCache(true);
|
|
6539
6919
|
*
|
|
6540
6920
|
* // Create a ProgramManager
|
|
6541
|
-
* const programManager = new ProgramManager("https://
|
|
6921
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider);
|
|
6542
6922
|
*
|
|
6543
6923
|
* // Set the inclusion keys.
|
|
6544
6924
|
* programManager.setInclusionProver();
|
|
@@ -6572,7 +6952,7 @@ class ProgramManager {
|
|
|
6572
6952
|
* import { ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
6573
6953
|
*
|
|
6574
6954
|
* // Create a ProgramManager
|
|
6575
|
-
* const programManager = new ProgramManager("https://
|
|
6955
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2");
|
|
6576
6956
|
*
|
|
6577
6957
|
* // Remove the default `X-Aleo-SDK-Version` header
|
|
6578
6958
|
* programManager.removeHeader('X-Aleo-SDK-Version');
|
|
@@ -6602,7 +6982,7 @@ class ProgramManager {
|
|
|
6602
6982
|
*
|
|
6603
6983
|
* // Initialize a program manager with the key provider to automatically fetch keys for deployments
|
|
6604
6984
|
* 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";
|
|
6605
|
-
* const programManager = new ProgramManager("https://
|
|
6985
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
6606
6986
|
* programManager.setAccount(Account);
|
|
6607
6987
|
*
|
|
6608
6988
|
* // Define a fee in credits
|
|
@@ -6714,7 +7094,7 @@ class ProgramManager {
|
|
|
6714
7094
|
*
|
|
6715
7095
|
* // Initialize a program manager with the key provider to automatically fetch keys for deployments
|
|
6716
7096
|
* 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";
|
|
6717
|
-
* const programManager = new ProgramManager("https://
|
|
7097
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
6718
7098
|
* programManager.setAccount(Account);
|
|
6719
7099
|
*
|
|
6720
7100
|
* // Define a fee in credits
|
|
@@ -6832,7 +7212,7 @@ class ProgramManager {
|
|
|
6832
7212
|
*
|
|
6833
7213
|
* // Initialize a program manager with the key provider to automatically fetch keys for deployments
|
|
6834
7214
|
* 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";
|
|
6835
|
-
* const programManager = new ProgramManager("https://
|
|
7215
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
6836
7216
|
*
|
|
6837
7217
|
* // Define a fee in credits
|
|
6838
7218
|
* const priorityFee = 0.0;
|
|
@@ -6880,7 +7260,7 @@ class ProgramManager {
|
|
|
6880
7260
|
* keyProvider.useCache(true);
|
|
6881
7261
|
*
|
|
6882
7262
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
6883
|
-
* const programManager = new ProgramManager("https://
|
|
7263
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
6884
7264
|
*
|
|
6885
7265
|
* // Build and execute the transaction
|
|
6886
7266
|
* const tx = await programManager.buildExecutionTransaction({
|
|
@@ -7037,7 +7417,7 @@ class ProgramManager {
|
|
|
7037
7417
|
* keyProvider.useCache(true);
|
|
7038
7418
|
*
|
|
7039
7419
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions.
|
|
7040
|
-
* const programManager = new ProgramManager("https://
|
|
7420
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider);
|
|
7041
7421
|
*
|
|
7042
7422
|
* // Build the `Authorization`.
|
|
7043
7423
|
* const privateKey = new PrivateKey(); // Change this to a private key that has an aleo credit balance.
|
|
@@ -7175,7 +7555,7 @@ class ProgramManager {
|
|
|
7175
7555
|
* keyProvider.useCache(true);
|
|
7176
7556
|
*
|
|
7177
7557
|
* // Initialize a ProgramManager with the key and record providers.
|
|
7178
|
-
* const programManager = new ProgramManager("https://
|
|
7558
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7179
7559
|
*
|
|
7180
7560
|
* // Build the `Authorization`.
|
|
7181
7561
|
* const authorization = await programManager.buildAuthorization({
|
|
@@ -7190,15 +7570,12 @@ class ProgramManager {
|
|
|
7190
7570
|
async buildAuthorization(options) {
|
|
7191
7571
|
// Destructure the options object to access the parameters.
|
|
7192
7572
|
const { functionName, inputs, } = options;
|
|
7193
|
-
const
|
|
7194
|
-
if (preparedProgram) {
|
|
7195
|
-
this.validatePreparedProgram(preparedProgram, options);
|
|
7196
|
-
}
|
|
7573
|
+
const preparedCall = this.preparedCallContext(options);
|
|
7197
7574
|
const privateKey = options.privateKey;
|
|
7198
|
-
let program =
|
|
7199
|
-
let programName =
|
|
7575
|
+
let program = preparedCall?.programSource ?? options.programSource;
|
|
7576
|
+
let programName = preparedCall?.programName ?? options.programName;
|
|
7200
7577
|
const imports = options.programImports;
|
|
7201
|
-
let edition =
|
|
7578
|
+
let edition = preparedCall?.edition ?? options.edition;
|
|
7202
7579
|
// Ensure the function exists on the network.
|
|
7203
7580
|
if (program === undefined) {
|
|
7204
7581
|
try {
|
|
@@ -7224,7 +7601,7 @@ class ProgramManager {
|
|
|
7224
7601
|
if (typeof executionPrivateKey === "undefined") {
|
|
7225
7602
|
throw "No private key provided and no private key set in the ProgramManager";
|
|
7226
7603
|
}
|
|
7227
|
-
if (!
|
|
7604
|
+
if (!preparedCall) {
|
|
7228
7605
|
const resolved = await this.resolveEditionAndAmendment(programName, edition);
|
|
7229
7606
|
edition = edition ?? resolved.edition;
|
|
7230
7607
|
}
|
|
@@ -7232,13 +7609,13 @@ class ProgramManager {
|
|
|
7232
7609
|
const preparedInputs = this.prepareInputs(program, functionName, inputs);
|
|
7233
7610
|
// Build ProgramImportsBuilder for import resolution (no key loading —
|
|
7234
7611
|
// authorizations don't synthesize keys).
|
|
7235
|
-
const builder =
|
|
7236
|
-
?
|
|
7612
|
+
const builder = preparedCall
|
|
7613
|
+
? clonePreparedContextBuilder(preparedCall.context)
|
|
7237
7614
|
: (await this.buildProgramImports(program, imports, false, functionName)).builder;
|
|
7238
|
-
const
|
|
7239
|
-
const hasImports = !builder.isEmpty();
|
|
7615
|
+
const hasPreparedContext = preparedCall !== undefined;
|
|
7616
|
+
const hasImports = !hasPreparedContext && !builder.isEmpty();
|
|
7240
7617
|
// Build and return an `Authorization` for the desired function.
|
|
7241
|
-
const authorization = await testnet_js.ProgramManager.authorize(executionPrivateKey, program, functionName, preparedInputs,
|
|
7618
|
+
const authorization = await withPreparedContextWasm(preparedCall?.context, () => testnet_js.ProgramManager.authorize(executionPrivateKey, program, functionName, preparedInputs, hasPreparedContext || hasImports ? undefined : imports, edition, hasPreparedContext ? builder : hasImports ? builder.clone() : undefined));
|
|
7242
7619
|
return authorization;
|
|
7243
7620
|
}
|
|
7244
7621
|
/**
|
|
@@ -7257,7 +7634,7 @@ class ProgramManager {
|
|
|
7257
7634
|
* keyProvider.useCache(true);
|
|
7258
7635
|
*
|
|
7259
7636
|
* // Initialize a ProgramManager with the key and record providers.
|
|
7260
|
-
* const programManager = new ProgramManager("https://
|
|
7637
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7261
7638
|
*
|
|
7262
7639
|
* // Build the unchecked `Authorization`.
|
|
7263
7640
|
* const authorization = await programManager.buildAuthorizationUnchecked({
|
|
@@ -7272,15 +7649,12 @@ class ProgramManager {
|
|
|
7272
7649
|
async buildAuthorizationUnchecked(options) {
|
|
7273
7650
|
// Destructure the options object to access the parameters.
|
|
7274
7651
|
const { functionName, inputs, } = options;
|
|
7275
|
-
const
|
|
7276
|
-
if (preparedProgram) {
|
|
7277
|
-
this.validatePreparedProgram(preparedProgram, options);
|
|
7278
|
-
}
|
|
7652
|
+
const preparedCall = this.preparedCallContext(options);
|
|
7279
7653
|
const privateKey = options.privateKey;
|
|
7280
|
-
let program =
|
|
7281
|
-
let programName =
|
|
7654
|
+
let program = preparedCall?.programSource ?? options.programSource;
|
|
7655
|
+
let programName = preparedCall?.programName ?? options.programName;
|
|
7282
7656
|
const imports = options.programImports;
|
|
7283
|
-
let edition =
|
|
7657
|
+
let edition = preparedCall?.edition ?? options.edition;
|
|
7284
7658
|
// Ensure the function exists on the network.
|
|
7285
7659
|
if (program === undefined) {
|
|
7286
7660
|
try {
|
|
@@ -7306,7 +7680,7 @@ class ProgramManager {
|
|
|
7306
7680
|
if (typeof executionPrivateKey === "undefined") {
|
|
7307
7681
|
throw "No private key provided and no private key set in the ProgramManager";
|
|
7308
7682
|
}
|
|
7309
|
-
if (!
|
|
7683
|
+
if (!preparedCall) {
|
|
7310
7684
|
const resolved = await this.resolveEditionAndAmendment(programName, edition);
|
|
7311
7685
|
edition = edition ?? resolved.edition;
|
|
7312
7686
|
}
|
|
@@ -7314,13 +7688,13 @@ class ProgramManager {
|
|
|
7314
7688
|
const preparedInputs = this.prepareInputs(program, functionName, inputs);
|
|
7315
7689
|
// Build ProgramImportsBuilder for import resolution (no key loading —
|
|
7316
7690
|
// authorizations don't synthesize keys).
|
|
7317
|
-
const builder =
|
|
7318
|
-
?
|
|
7691
|
+
const builder = preparedCall
|
|
7692
|
+
? clonePreparedContextBuilder(preparedCall.context)
|
|
7319
7693
|
: (await this.buildProgramImports(program, imports, false, functionName)).builder;
|
|
7320
|
-
const
|
|
7321
|
-
const hasImports = !builder.isEmpty();
|
|
7694
|
+
const hasPreparedContext = preparedCall !== undefined;
|
|
7695
|
+
const hasImports = !hasPreparedContext && !builder.isEmpty();
|
|
7322
7696
|
// Build and return an `Authorization` for the desired function.
|
|
7323
|
-
const authorization = await testnet_js.ProgramManager.buildAuthorizationUnchecked(executionPrivateKey, program, functionName, preparedInputs,
|
|
7697
|
+
const authorization = await withPreparedContextWasm(preparedCall?.context, () => testnet_js.ProgramManager.buildAuthorizationUnchecked(executionPrivateKey, program, functionName, preparedInputs, hasPreparedContext || hasImports ? undefined : imports, edition, hasPreparedContext ? builder : hasImports ? builder.clone() : undefined));
|
|
7324
7698
|
return authorization;
|
|
7325
7699
|
}
|
|
7326
7700
|
/**
|
|
@@ -7339,7 +7713,7 @@ class ProgramManager {
|
|
|
7339
7713
|
* keyProvider.useCache(true);
|
|
7340
7714
|
*
|
|
7341
7715
|
* // Initialize a ProgramManager with the key and record providers.
|
|
7342
|
-
* const programManager = new ProgramManager("https://
|
|
7716
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7343
7717
|
*
|
|
7344
7718
|
* // Build the proving request.
|
|
7345
7719
|
* const provingRequest = await programManager.provingRequest({
|
|
@@ -7357,18 +7731,15 @@ class ProgramManager {
|
|
|
7357
7731
|
async provingRequest(options) {
|
|
7358
7732
|
// Destructure the options object to access the parameters.
|
|
7359
7733
|
const { functionName, priorityFee, privateFee, inputs, recordSearchParams, broadcast = false, unchecked = false, } = options;
|
|
7360
|
-
const
|
|
7361
|
-
if (preparedProgram) {
|
|
7362
|
-
this.validatePreparedProgram(preparedProgram, options);
|
|
7363
|
-
}
|
|
7734
|
+
const preparedCall = this.preparedCallContext(options);
|
|
7364
7735
|
const baseFee = options.baseFee ? options.baseFee : 0;
|
|
7365
7736
|
const privateKey = options.privateKey;
|
|
7366
7737
|
const useFeeMaster = options.useFeeMaster ? options.useFeeMaster : false;
|
|
7367
|
-
let program =
|
|
7368
|
-
let programName =
|
|
7738
|
+
let program = preparedCall?.programSource ?? options.programSource;
|
|
7739
|
+
let programName = preparedCall?.programName ?? options.programName;
|
|
7369
7740
|
let feeRecord = options.feeRecord;
|
|
7370
7741
|
let imports = options.programImports;
|
|
7371
|
-
let edition =
|
|
7742
|
+
let edition = preparedCall?.edition ?? options.edition;
|
|
7372
7743
|
if (!inputs && !options.executionRequest) {
|
|
7373
7744
|
throw new Error("Either function inputs or an execution request must be provided to form a proving request");
|
|
7374
7745
|
}
|
|
@@ -7388,7 +7759,7 @@ class ProgramManager {
|
|
|
7388
7759
|
if (programName === undefined) {
|
|
7389
7760
|
programName = testnet_js.Program.fromString(program).id();
|
|
7390
7761
|
}
|
|
7391
|
-
if (!
|
|
7762
|
+
if (!preparedCall) {
|
|
7392
7763
|
const resolved = await this.resolveEditionAndAmendment(programName, edition);
|
|
7393
7764
|
edition = edition ?? resolved.edition;
|
|
7394
7765
|
}
|
|
@@ -7400,8 +7771,8 @@ class ProgramManager {
|
|
|
7400
7771
|
executionPrivateKey = this.account.privateKey();
|
|
7401
7772
|
}
|
|
7402
7773
|
// Resolve the program imports if they exist.
|
|
7403
|
-
const numberOfImports =
|
|
7404
|
-
if (!
|
|
7774
|
+
const numberOfImports = ProgramManager.getImportNames(program).length;
|
|
7775
|
+
if (!preparedCall && numberOfImports > 0 && !imports) {
|
|
7405
7776
|
try {
|
|
7406
7777
|
imports = (await this.networkClient.getProgramImports(programName));
|
|
7407
7778
|
}
|
|
@@ -7411,33 +7782,19 @@ class ProgramManager {
|
|
|
7411
7782
|
}
|
|
7412
7783
|
// Build ProgramImportsBuilder for import resolution (no key loading —
|
|
7413
7784
|
// proving requests don't synthesize keys).
|
|
7414
|
-
const builder =
|
|
7415
|
-
?
|
|
7785
|
+
const builder = preparedCall
|
|
7786
|
+
? clonePreparedContextBuilder(preparedCall.context)
|
|
7416
7787
|
: (await this.buildProgramImports(program, imports, false, functionName)).builder;
|
|
7417
|
-
const
|
|
7418
|
-
const hasImports = !builder.isEmpty();
|
|
7419
|
-
|
|
7420
|
-
// both the private-fee estimate below and the Rust-side fee estimator
|
|
7421
|
-
// (estimate_fee_for_authorization uses the legacy imports Object to
|
|
7422
|
-
// avoid a RefCell double-borrow — see proving_request.rs) see all
|
|
7423
|
-
// transitive imports, not just the caller's partial set. Use
|
|
7424
|
-
// programNames + getProgram to avoid serializing key bytes (toObject
|
|
7425
|
-
// would serialize all proving/verifying keys, which can be tens of
|
|
7426
|
-
// MB). The prepared executionRequest path skips the copy: it passes
|
|
7427
|
-
// the process builder directly and never estimates fees, so the
|
|
7428
|
-
// imports Object goes unused there.
|
|
7429
|
-
const importsObjectUnused = hasPreparedProcess
|
|
7430
|
-
&& options.executionRequest instanceof testnet_js.ExecutionRequest;
|
|
7431
|
-
if ((hasPreparedProcess || hasImports) && !importsObjectUnused) {
|
|
7432
|
-
imports = programImportsFromBuilder(builder, programName);
|
|
7433
|
-
}
|
|
7788
|
+
const hasPreparedContext = preparedCall !== undefined;
|
|
7789
|
+
const hasImports = !hasPreparedContext && !builder.isEmpty();
|
|
7790
|
+
const hasProcessBuilder = hasPreparedContext || hasImports;
|
|
7434
7791
|
// Get the fee record from the account if it is not provided in the parameters
|
|
7435
7792
|
try {
|
|
7436
7793
|
if (privateFee && !useFeeMaster && !options.executionRequest) {
|
|
7437
7794
|
let fee = priorityFee;
|
|
7438
7795
|
// If a fee record wasn't provided, estimate the fee that needs to be paid.
|
|
7439
7796
|
if (!feeRecord) {
|
|
7440
|
-
const baseFee = Number(await
|
|
7797
|
+
const baseFee = Number(await withPreparedContextWasm(preparedCall?.context, async () => testnet_js.ProgramManager.estimateExecutionFee(program, functionName, hasProcessBuilder ? undefined : imports, edition, hasProcessBuilder ? builder.clone() : undefined)));
|
|
7441
7798
|
fee = baseFee + priorityFee;
|
|
7442
7799
|
}
|
|
7443
7800
|
// Get a credits.aleo record for the fee.
|
|
@@ -7452,10 +7809,7 @@ class ProgramManager {
|
|
|
7452
7809
|
logAndThrow(`Error finding fee record. Record finder response: '${e.message}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
|
|
7453
7810
|
}
|
|
7454
7811
|
if (options.executionRequest instanceof testnet_js.ExecutionRequest) {
|
|
7455
|
-
return await testnet_js.ProgramManager.buildProvingRequestFromExecutionRequest(options.executionRequest, program, unchecked, broadcast, edition,
|
|
7456
|
-
// The prepared process supersedes the legacy imports Object;
|
|
7457
|
-
// without one, imports is kept for fee estimation in Rust.
|
|
7458
|
-
hasPreparedProcess ? undefined : imports, executionPrivateKey, hasPreparedProcess ? builder : hasImports ? builder.clone() : undefined);
|
|
7812
|
+
return await withPreparedContextWasm(preparedCall?.context, () => testnet_js.ProgramManager.buildProvingRequestFromExecutionRequest(options.executionRequest, program, unchecked, broadcast, edition, hasProcessBuilder ? undefined : imports, executionPrivateKey, hasPreparedContext ? builder : hasImports ? builder.clone() : undefined));
|
|
7459
7813
|
}
|
|
7460
7814
|
else {
|
|
7461
7815
|
// Ensure the private key exists.
|
|
@@ -7469,8 +7823,7 @@ class ProgramManager {
|
|
|
7469
7823
|
// Auto-convert bare string inputs to field elements where the function expects field type.
|
|
7470
7824
|
const preparedInputs = this.prepareInputs(program, functionName, inputs);
|
|
7471
7825
|
// Build and return the `ProvingRequest`.
|
|
7472
|
-
return await testnet_js.ProgramManager.buildProvingRequest(executionPrivateKey, program, functionName, preparedInputs, baseFee, priorityFee, feeRecord, imports,
|
|
7473
|
-
broadcast, unchecked, edition, useFeeMaster, hasPreparedProcess ? builder : hasImports ? builder.clone() : undefined);
|
|
7826
|
+
return await withPreparedContextWasm(preparedCall?.context, () => testnet_js.ProgramManager.buildProvingRequest(executionPrivateKey, program, functionName, preparedInputs, baseFee, priorityFee, feeRecord, hasProcessBuilder ? undefined : imports, broadcast, unchecked, edition, useFeeMaster, hasPreparedContext ? builder : hasImports ? builder.clone() : undefined));
|
|
7474
7827
|
}
|
|
7475
7828
|
}
|
|
7476
7829
|
/**
|
|
@@ -7489,7 +7842,7 @@ class ProgramManager {
|
|
|
7489
7842
|
* keyProvider.useCache(true);
|
|
7490
7843
|
*
|
|
7491
7844
|
* // Initialize a ProgramManager with the key and record providers.
|
|
7492
|
-
* const programManager = new ProgramManager("https://
|
|
7845
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7493
7846
|
*
|
|
7494
7847
|
* // Build a credits.aleo/fee_public `Authorization`.
|
|
7495
7848
|
* const feePublicAuthorization = await programManager.buildFeeAuthorization({
|
|
@@ -7536,7 +7889,7 @@ class ProgramManager {
|
|
|
7536
7889
|
* keyProvider.useCache(true);
|
|
7537
7890
|
*
|
|
7538
7891
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
7539
|
-
* const programManager = new ProgramManager("https://
|
|
7892
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7540
7893
|
*
|
|
7541
7894
|
* // Build and execute the transaction
|
|
7542
7895
|
* const tx_id = await programManager.execute({
|
|
@@ -7711,7 +8064,7 @@ class ProgramManager {
|
|
|
7711
8064
|
* keyProvider.useCache(true);
|
|
7712
8065
|
*
|
|
7713
8066
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
7714
|
-
* const programManager = new ProgramManager("https://
|
|
8067
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7715
8068
|
* const record_1 = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}"
|
|
7716
8069
|
* const record_2 = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 1540945439182663264862696551825005342995406165131907382295858612069623286213group.public}"
|
|
7717
8070
|
* const tx_id = await programManager.join(record_1, record_2, 0.05, false);
|
|
@@ -7818,7 +8171,7 @@ class ProgramManager {
|
|
|
7818
8171
|
* keyProvider.useCache(true);
|
|
7819
8172
|
*
|
|
7820
8173
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
7821
|
-
* const programManager = new ProgramManager("https://
|
|
8174
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7822
8175
|
* const record = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}"
|
|
7823
8176
|
* const tx_id = await programManager.split(25000000, record);
|
|
7824
8177
|
*
|
|
@@ -7929,7 +8282,7 @@ class ProgramManager {
|
|
|
7929
8282
|
* keyProvider.useCache(true);
|
|
7930
8283
|
*
|
|
7931
8284
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
7932
|
-
* const programManager = new ProgramManager("https://
|
|
8285
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7933
8286
|
* const tx = await programManager.buildTransferTransaction(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "public", 0.2, false);
|
|
7934
8287
|
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
7935
8288
|
*
|
|
@@ -8018,7 +8371,7 @@ class ProgramManager {
|
|
|
8018
8371
|
* keyProvider.useCache(true);
|
|
8019
8372
|
*
|
|
8020
8373
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
8021
|
-
* const programManager = new ProgramManager("https://
|
|
8374
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
8022
8375
|
* const tx = await programManager.buildTransferPublicTransaction(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", 0.2);
|
|
8023
8376
|
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
8024
8377
|
*
|
|
@@ -8051,7 +8404,7 @@ class ProgramManager {
|
|
|
8051
8404
|
* keyProvider.useCache(true);
|
|
8052
8405
|
*
|
|
8053
8406
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
8054
|
-
* const programManager = new ProgramManager("https://
|
|
8407
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
8055
8408
|
* const tx = await programManager.buildTransferPublicAsSignerTransaction(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", 0.2);
|
|
8056
8409
|
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
8057
8410
|
*
|
|
@@ -8089,7 +8442,7 @@ class ProgramManager {
|
|
|
8089
8442
|
* keyProvider.useCache(true);
|
|
8090
8443
|
*
|
|
8091
8444
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
8092
|
-
* const programManager = new ProgramManager("https://
|
|
8445
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
8093
8446
|
* const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "public", 0.2, false);
|
|
8094
8447
|
*
|
|
8095
8448
|
* // Verify the transaction was successful
|
|
@@ -8134,7 +8487,7 @@ class ProgramManager {
|
|
|
8134
8487
|
* keyProvider.useCache(true);
|
|
8135
8488
|
*
|
|
8136
8489
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8137
|
-
* const programManager = new ProgramManager("https://
|
|
8490
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8138
8491
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
8139
8492
|
*
|
|
8140
8493
|
* // Create the bonding transaction object for later submission
|
|
@@ -8190,7 +8543,7 @@ class ProgramManager {
|
|
|
8190
8543
|
* keyProvider.useCache(true);
|
|
8191
8544
|
*
|
|
8192
8545
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8193
|
-
* const programManager = new ProgramManager("https://
|
|
8546
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8194
8547
|
*
|
|
8195
8548
|
* // Create the bonding transaction
|
|
8196
8549
|
* tx_id = await programManager.bondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
|
|
@@ -8238,7 +8591,7 @@ class ProgramManager {
|
|
|
8238
8591
|
* keyProvider.useCache(true);
|
|
8239
8592
|
*
|
|
8240
8593
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8241
|
-
* const programManager = new ProgramManager("https://
|
|
8594
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8242
8595
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
8243
8596
|
*
|
|
8244
8597
|
* // Create the bond validator transaction object for later use.
|
|
@@ -8297,7 +8650,7 @@ class ProgramManager {
|
|
|
8297
8650
|
* keyProvider.useCache(true);
|
|
8298
8651
|
*
|
|
8299
8652
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8300
|
-
* const programManager = new ProgramManager("https://
|
|
8653
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8301
8654
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
8302
8655
|
*
|
|
8303
8656
|
* // Create the bonding transaction
|
|
@@ -8344,7 +8697,7 @@ class ProgramManager {
|
|
|
8344
8697
|
* keyProvider.useCache(true);
|
|
8345
8698
|
*
|
|
8346
8699
|
* // Create a new ProgramManager with the key that will be used to unbond credits.
|
|
8347
|
-
* const programManager = new ProgramManager("https://
|
|
8700
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8348
8701
|
* const tx = await programManager.buildUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", 2000000);
|
|
8349
8702
|
*
|
|
8350
8703
|
* // The transaction can be submitted later to the network using the network client.
|
|
@@ -8397,7 +8750,7 @@ class ProgramManager {
|
|
|
8397
8750
|
* keyProvider.useCache(true);
|
|
8398
8751
|
*
|
|
8399
8752
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8400
|
-
* const programManager = new ProgramManager("https://
|
|
8753
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8401
8754
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
8402
8755
|
*
|
|
8403
8756
|
* // Create the unbond_public transaction and send it to the network
|
|
@@ -8443,7 +8796,7 @@ class ProgramManager {
|
|
|
8443
8796
|
* keyProvider.useCache(true);
|
|
8444
8797
|
*
|
|
8445
8798
|
* // Create a new ProgramManager with the key that will be used to claim unbonded credits.
|
|
8446
|
-
* const programManager = new ProgramManager("https://
|
|
8799
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8447
8800
|
*
|
|
8448
8801
|
* // Create the claim_unbond_public transaction object for later use.
|
|
8449
8802
|
* const tx = await programManager.buildClaimUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j");
|
|
@@ -8493,7 +8846,7 @@ class ProgramManager {
|
|
|
8493
8846
|
* keyProvider.useCache(true);
|
|
8494
8847
|
*
|
|
8495
8848
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8496
|
-
* const programManager = new ProgramManager("https://
|
|
8849
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8497
8850
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
8498
8851
|
*
|
|
8499
8852
|
* // Create the claim_unbond_public transaction
|
|
@@ -8547,7 +8900,7 @@ class ProgramManager {
|
|
|
8547
8900
|
* keyProvider.useCache(true);
|
|
8548
8901
|
*
|
|
8549
8902
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8550
|
-
* const programManager = new ProgramManager("https://
|
|
8903
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8551
8904
|
*
|
|
8552
8905
|
* // Create the set_validator_state transaction
|
|
8553
8906
|
* const tx = await programManager.buildSetValidatorStateTransaction(true);
|
|
@@ -8603,7 +8956,7 @@ class ProgramManager {
|
|
|
8603
8956
|
* keyProvider.useCache(true);
|
|
8604
8957
|
*
|
|
8605
8958
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8606
|
-
* const programManager = new ProgramManager("https://
|
|
8959
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8607
8960
|
*
|
|
8608
8961
|
* // Create the set_validator_state transaction
|
|
8609
8962
|
* const tx_id = await programManager.setValidatorState(true);
|
|
@@ -8725,7 +9078,7 @@ class ProgramManager {
|
|
|
8725
9078
|
* keyProvider.useCache(true);
|
|
8726
9079
|
*
|
|
8727
9080
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions.
|
|
8728
|
-
* const programManager = new ProgramManager("https://
|
|
9081
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider);
|
|
8729
9082
|
*
|
|
8730
9083
|
* // Build the `Authorization`.
|
|
8731
9084
|
* const privateKey = new PrivateKey(); // Change this to a private key that has an aleo credit balance.
|
|
@@ -8782,7 +9135,7 @@ class ProgramManager {
|
|
|
8782
9135
|
* import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
|
|
8783
9136
|
*
|
|
8784
9137
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions.
|
|
8785
|
-
* const programManager = new ProgramManager("https://
|
|
9138
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider);
|
|
8786
9139
|
*
|
|
8787
9140
|
* // Get the base fee in microcredits.
|
|
8788
9141
|
* const baseFeeMicrocredits = await programManager.estimateExecutionFee({programName: "credits.aleo"});
|
|
@@ -9784,6 +10137,7 @@ exports.PRIVATE_TRANSFER_TYPES = PRIVATE_TRANSFER_TYPES;
|
|
|
9784
10137
|
exports.PUBLIC_TO_PRIVATE_TRANSFER = PUBLIC_TO_PRIVATE_TRANSFER;
|
|
9785
10138
|
exports.PUBLIC_TRANSFER = PUBLIC_TRANSFER;
|
|
9786
10139
|
exports.PUBLIC_TRANSFER_AS_SIGNER = PUBLIC_TRANSFER_AS_SIGNER;
|
|
10140
|
+
exports.PreparedProcess = PreparedProcess;
|
|
9787
10141
|
exports.PreparedProgram = PreparedProgram;
|
|
9788
10142
|
exports.ProgramManager = ProgramManager;
|
|
9789
10143
|
exports.RECORD_DOMAIN = RECORD_DOMAIN;
|