@provablehq/sdk 0.11.8 → 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 -7
- package/dist/mainnet/api-auth.d.ts +14 -7
- package/dist/mainnet/browser.cjs +550 -193
- 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 +550 -194
- 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 -7
- package/dist/testnet/api-auth.d.ts +14 -7
- package/dist/testnet/browser.cjs +550 -193
- 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 +550 -194
- 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
|
}
|
|
@@ -1631,11 +1638,14 @@ class ApiAuth {
|
|
|
1631
1638
|
* both a usable token and the material to mint one.
|
|
1632
1639
|
*/
|
|
1633
1640
|
async headers() {
|
|
1634
|
-
if (this.config.mode === "none")
|
|
1635
|
-
return {};
|
|
1636
1641
|
if (this.config.mode === "api-key") {
|
|
1637
1642
|
return { [this.config.header ?? DEFAULT_API_KEY_HEADER]: this.config.value };
|
|
1638
1643
|
}
|
|
1644
|
+
if (this.config.mode === "none") {
|
|
1645
|
+
// A token injected via setJwtData authenticates even without mint
|
|
1646
|
+
// material: an external session owns minting and hands tokens in.
|
|
1647
|
+
return this.jwtData?.jwt ? { Authorization: this.jwtData.jwt } : {};
|
|
1648
|
+
}
|
|
1639
1649
|
const stale = !this.jwtData || Date.now() >= this.jwtData.expiration - FIVE_MINUTES;
|
|
1640
1650
|
if (stale) {
|
|
1641
1651
|
const { apiKey, consumerId } = this.config;
|
|
@@ -1713,7 +1723,7 @@ const HEADERS = new Set([
|
|
|
1713
1723
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
1714
1724
|
* const apiKey = process.env.apiKey;
|
|
1715
1725
|
* const consumerId = process.env.consumerId;
|
|
1716
|
-
* const publicNetworkClient = new AleoNetworkClient("https://
|
|
1726
|
+
* const publicNetworkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined, account);
|
|
1717
1727
|
*/
|
|
1718
1728
|
class AleoNetworkClient {
|
|
1719
1729
|
host;
|
|
@@ -1732,6 +1742,9 @@ class AleoNetworkClient {
|
|
|
1732
1742
|
// The consumer the cached jwtData was minted for, so the cache is never
|
|
1733
1743
|
// reused for a different identity on a shared client.
|
|
1734
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;
|
|
1735
1748
|
proverUri;
|
|
1736
1749
|
recordScannerUri;
|
|
1737
1750
|
constructor(host, options) {
|
|
@@ -1751,7 +1764,7 @@ class AleoNetworkClient {
|
|
|
1751
1764
|
else {
|
|
1752
1765
|
this.headers = {
|
|
1753
1766
|
// This is replaced by the actual version by a Rollup plugin
|
|
1754
|
-
"X-Aleo-SDK-Version": "0.11.
|
|
1767
|
+
"X-Aleo-SDK-Version": "0.11.10",
|
|
1755
1768
|
"X-Aleo-environment": environment(),
|
|
1756
1769
|
};
|
|
1757
1770
|
}
|
|
@@ -1773,7 +1786,7 @@ class AleoNetworkClient {
|
|
|
1773
1786
|
else {
|
|
1774
1787
|
this.headers = {
|
|
1775
1788
|
// This is replaced by the actual version by a Rollup plugin
|
|
1776
|
-
"X-Aleo-SDK-Version": "0.11.
|
|
1789
|
+
"X-Aleo-SDK-Version": "0.11.10",
|
|
1777
1790
|
"X-Aleo-environment": environment(),
|
|
1778
1791
|
};
|
|
1779
1792
|
}
|
|
@@ -1785,7 +1798,7 @@ class AleoNetworkClient {
|
|
|
1785
1798
|
* @example
|
|
1786
1799
|
* import { Account, AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1787
1800
|
*
|
|
1788
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
1801
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
1789
1802
|
* const account = new Account();
|
|
1790
1803
|
* networkClient.setAccount(account);
|
|
1791
1804
|
*/
|
|
@@ -1813,7 +1826,7 @@ class AleoNetworkClient {
|
|
|
1813
1826
|
* const networkClient = new AleoNetworkClient("http://0.0.0.0:3030", undefined);
|
|
1814
1827
|
*
|
|
1815
1828
|
* // Set the host to a public node.
|
|
1816
|
-
* networkClient.setHost("https://
|
|
1829
|
+
* networkClient.setHost("https://edge.provable.com/api/v2");
|
|
1817
1830
|
*/
|
|
1818
1831
|
setHost(host) {
|
|
1819
1832
|
this.host = host + "/testnet";
|
|
@@ -1827,7 +1840,7 @@ class AleoNetworkClient {
|
|
|
1827
1840
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1828
1841
|
*
|
|
1829
1842
|
* // Create a networkClient that connects to the provable explorer api.
|
|
1830
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
1843
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
1831
1844
|
*
|
|
1832
1845
|
* // Set the prover uri.
|
|
1833
1846
|
* networkClient.setProverUri("https://prover.provable.prove");
|
|
@@ -1844,7 +1857,7 @@ class AleoNetworkClient {
|
|
|
1844
1857
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1845
1858
|
*
|
|
1846
1859
|
* // Create a networkClient that connects to the provable explorer api.
|
|
1847
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
1860
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
1848
1861
|
*
|
|
1849
1862
|
* // Set the record scanner uri.
|
|
1850
1863
|
* networkClient.setRecordScannerUri("https://scanner.provable.scan");
|
|
@@ -1972,7 +1985,7 @@ class AleoNetworkClient {
|
|
|
1972
1985
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
1973
1986
|
*
|
|
1974
1987
|
* // Create a network client.
|
|
1975
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
1988
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
1976
1989
|
* networkClient.setAccount(account);
|
|
1977
1990
|
*
|
|
1978
1991
|
* // Find specific amounts
|
|
@@ -2195,7 +2208,7 @@ class AleoNetworkClient {
|
|
|
2195
2208
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
2196
2209
|
*
|
|
2197
2210
|
* // Create a network client and set an account to search for records with.
|
|
2198
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2211
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2199
2212
|
* networkClient.setAccount(account);
|
|
2200
2213
|
*
|
|
2201
2214
|
* // Find specific amounts
|
|
@@ -2251,7 +2264,7 @@ class AleoNetworkClient {
|
|
|
2251
2264
|
* @example
|
|
2252
2265
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2253
2266
|
*
|
|
2254
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2267
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2255
2268
|
* const block = networkClient.getBlockByHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9");
|
|
2256
2269
|
*/
|
|
2257
2270
|
async getBlockByHash(blockHash) {
|
|
@@ -2309,7 +2322,7 @@ class AleoNetworkClient {
|
|
|
2309
2322
|
* import { AleoNetworkClient } from "@provablehq/sdk/testnet.js";
|
|
2310
2323
|
*
|
|
2311
2324
|
* // Get the transaction ID of the deployment transaction for a program.
|
|
2312
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2325
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2313
2326
|
* const transactionId = networkClient.getDeploymentTransactionIDForProgram("hello_hello.aleo");
|
|
2314
2327
|
*
|
|
2315
2328
|
* // Get the transaction data for the deployment transaction.
|
|
@@ -2344,7 +2357,7 @@ class AleoNetworkClient {
|
|
|
2344
2357
|
* import { AleoNetworkClient, DeploymentJSON } from "@provablehq/sdk/testnet.js";
|
|
2345
2358
|
*
|
|
2346
2359
|
* // Get the transaction ID of the deployment transaction for a program.
|
|
2347
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2360
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2348
2361
|
* const transaction = networkClient.getDeploymentTransactionForProgram("hello_hello.aleo");
|
|
2349
2362
|
*
|
|
2350
2363
|
* // Get the verifying keys for each function in the deployment.
|
|
@@ -2377,7 +2390,7 @@ class AleoNetworkClient {
|
|
|
2377
2390
|
* import { AleoNetworkClient } from "@provablehq/sdk/testnet.js";
|
|
2378
2391
|
*
|
|
2379
2392
|
* // Get the transaction ID of the deployment transaction for a program.
|
|
2380
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2393
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2381
2394
|
* const transactionId = networkClient.getDeploymentTransactionIDForProgram("hello_hello.aleo");
|
|
2382
2395
|
*
|
|
2383
2396
|
* // Get the transaction data for the deployment transaction.
|
|
@@ -2408,7 +2421,7 @@ class AleoNetworkClient {
|
|
|
2408
2421
|
* import { AleoNetworkClient } from "@provablehq/sdk/testnet.js";
|
|
2409
2422
|
*
|
|
2410
2423
|
* // Create a network client.
|
|
2411
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2424
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2412
2425
|
*
|
|
2413
2426
|
* const latestHeight = networkClient.getLatestBlock();
|
|
2414
2427
|
*/
|
|
@@ -2433,10 +2446,10 @@ class AleoNetworkClient {
|
|
|
2433
2446
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2434
2447
|
*
|
|
2435
2448
|
* // Create a network client.
|
|
2436
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2449
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2437
2450
|
*
|
|
2438
2451
|
* // Create a network client and get the latest committee.
|
|
2439
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2452
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2440
2453
|
* const latestCommittee = await networkClient.getLatestCommittee();
|
|
2441
2454
|
*/
|
|
2442
2455
|
async getLatestCommittee() {
|
|
@@ -2461,10 +2474,10 @@ class AleoNetworkClient {
|
|
|
2461
2474
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2462
2475
|
*
|
|
2463
2476
|
* // Create a network client.
|
|
2464
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2477
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2465
2478
|
*
|
|
2466
2479
|
* // Create a network client and get the committee for a specific block.
|
|
2467
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2480
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2468
2481
|
* const committee = await networkClient.getCommitteeByBlockHeight(1234);
|
|
2469
2482
|
*/
|
|
2470
2483
|
async getCommitteeByBlockHeight(blockHeight) {
|
|
@@ -2488,7 +2501,7 @@ class AleoNetworkClient {
|
|
|
2488
2501
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2489
2502
|
*
|
|
2490
2503
|
* // Create a network client.
|
|
2491
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2504
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2492
2505
|
*
|
|
2493
2506
|
* const latestHeight = networkClient.getLatestHeight();
|
|
2494
2507
|
*/
|
|
@@ -2532,7 +2545,7 @@ class AleoNetworkClient {
|
|
|
2532
2545
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2533
2546
|
*
|
|
2534
2547
|
* // Create a network client.
|
|
2535
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2548
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2536
2549
|
*
|
|
2537
2550
|
* // Get the latest block hash.
|
|
2538
2551
|
* const latestHash = networkClient.getLatestBlockHash();
|
|
@@ -2560,7 +2573,7 @@ class AleoNetworkClient {
|
|
|
2560
2573
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2561
2574
|
*
|
|
2562
2575
|
* // Create a network client.
|
|
2563
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2576
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2564
2577
|
*
|
|
2565
2578
|
* // Get the source code of a program.)
|
|
2566
2579
|
* @returns {Promise<string>} Source code of the program
|
|
@@ -2569,7 +2582,7 @@ class AleoNetworkClient {
|
|
|
2569
2582
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2570
2583
|
*
|
|
2571
2584
|
* // Create a network client.
|
|
2572
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2585
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2573
2586
|
*
|
|
2574
2587
|
* const program = networkClient.getProgram("hello_hello.aleo");
|
|
2575
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"
|
|
@@ -2602,7 +2615,7 @@ class AleoNetworkClient {
|
|
|
2602
2615
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2603
2616
|
*
|
|
2604
2617
|
* // Create a network client.
|
|
2605
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2618
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2606
2619
|
*
|
|
2607
2620
|
* const programVersion = networkClient.getLatestProgramEdition("hello_hello.aleo");
|
|
2608
2621
|
* assert.equal(programVersion, 1);
|
|
@@ -2627,7 +2640,7 @@ class AleoNetworkClient {
|
|
|
2627
2640
|
* @returns {{ program_id: string, edition: number, amendment_count: number }}
|
|
2628
2641
|
*
|
|
2629
2642
|
* @example
|
|
2630
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2643
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
2631
2644
|
* const info = await networkClient.getProgramAmendmentCount("hello_hello.aleo");
|
|
2632
2645
|
* console.log(info.edition, info.amendment_count);
|
|
2633
2646
|
*/
|
|
@@ -2655,7 +2668,7 @@ class AleoNetworkClient {
|
|
|
2655
2668
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2656
2669
|
*
|
|
2657
2670
|
* // Create a network client.
|
|
2658
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2671
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2659
2672
|
*
|
|
2660
2673
|
* const programID = "hello_hello.aleo";
|
|
2661
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"
|
|
@@ -2695,7 +2708,7 @@ class AleoNetworkClient {
|
|
|
2695
2708
|
* }
|
|
2696
2709
|
*
|
|
2697
2710
|
* // Create a network client.
|
|
2698
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2711
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2699
2712
|
*
|
|
2700
2713
|
* // Imports can be fetched using the program ID, source code, or program object
|
|
2701
2714
|
* let programImports = await networkClient.getProgramImports("double_test.aleo");
|
|
@@ -2765,7 +2778,7 @@ class AleoNetworkClient {
|
|
|
2765
2778
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2766
2779
|
*
|
|
2767
2780
|
* // Create a network client.
|
|
2768
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2781
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2769
2782
|
*
|
|
2770
2783
|
* const programImportsNames = networkClient.getProgramImports("wrapped_credits.aleo");
|
|
2771
2784
|
* const expectedImportsNames = ["credits.aleo"];
|
|
@@ -2796,7 +2809,7 @@ class AleoNetworkClient {
|
|
|
2796
2809
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2797
2810
|
*
|
|
2798
2811
|
* // Create a network client.
|
|
2799
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2812
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2800
2813
|
*
|
|
2801
2814
|
* const mappings = networkClient.getProgramMappingNames("credits.aleo");
|
|
2802
2815
|
* const expectedMappings = [
|
|
@@ -2834,7 +2847,7 @@ class AleoNetworkClient {
|
|
|
2834
2847
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2835
2848
|
*
|
|
2836
2849
|
* // Create a network client.
|
|
2837
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2850
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2838
2851
|
*
|
|
2839
2852
|
* // Get public balance of an account
|
|
2840
2853
|
* const mappingValue = networkClient.getMappingValue("credits.aleo", "account", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
|
|
@@ -2866,7 +2879,7 @@ class AleoNetworkClient {
|
|
|
2866
2879
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
2867
2880
|
*
|
|
2868
2881
|
* // Create a network client.
|
|
2869
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2882
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2870
2883
|
*
|
|
2871
2884
|
* // Get the bond state as an account.
|
|
2872
2885
|
* const unbondedState = networkClient.getMappingPlaintext("credits.aleo", "bonded", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
|
|
@@ -2912,7 +2925,7 @@ class AleoNetworkClient {
|
|
|
2912
2925
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
2913
2926
|
*
|
|
2914
2927
|
* // Create a network client.
|
|
2915
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2928
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2916
2929
|
*
|
|
2917
2930
|
* // Get the balance of an account from either an address object or address string.
|
|
2918
2931
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
@@ -2943,7 +2956,7 @@ class AleoNetworkClient {
|
|
|
2943
2956
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
2944
2957
|
*
|
|
2945
2958
|
* // Create a network client.
|
|
2946
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2959
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2947
2960
|
*
|
|
2948
2961
|
* // Get the latest state root.
|
|
2949
2962
|
* const stateRoot = networkClient.getStateRoot();
|
|
@@ -2970,7 +2983,7 @@ class AleoNetworkClient {
|
|
|
2970
2983
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
2971
2984
|
*
|
|
2972
2985
|
* // Create a network client.
|
|
2973
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
2986
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
2974
2987
|
*
|
|
2975
2988
|
* const transaction = networkClient.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
|
|
2976
2989
|
*/
|
|
@@ -2996,7 +3009,7 @@ class AleoNetworkClient {
|
|
|
2996
3009
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
2997
3010
|
*
|
|
2998
3011
|
* // Create a network client.
|
|
2999
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3012
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
3000
3013
|
*
|
|
3001
3014
|
* const transaction = networkClient.getConfirmedTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
|
|
3002
3015
|
* assert.equal(transaction.status, "confirmed");
|
|
@@ -3061,7 +3074,7 @@ class AleoNetworkClient {
|
|
|
3061
3074
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
3062
3075
|
*
|
|
3063
3076
|
* // Create a network client.
|
|
3064
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3077
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
3065
3078
|
*
|
|
3066
3079
|
* const transactions = networkClient.getTransactions(654);
|
|
3067
3080
|
*/
|
|
@@ -3087,7 +3100,7 @@ class AleoNetworkClient {
|
|
|
3087
3100
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
3088
3101
|
*
|
|
3089
3102
|
* // Create a network client.
|
|
3090
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3103
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
3091
3104
|
*
|
|
3092
3105
|
* const transactions = networkClient.getTransactionsByBlockHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9");
|
|
3093
3106
|
*/
|
|
@@ -3114,7 +3127,7 @@ class AleoNetworkClient {
|
|
|
3114
3127
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
3115
3128
|
*
|
|
3116
3129
|
* // Create a network client.
|
|
3117
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3130
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
3118
3131
|
*
|
|
3119
3132
|
* // Get the current transactions in the mempool.
|
|
3120
3133
|
* const transactions = networkClient.getTransactionsInMempool();
|
|
@@ -3275,17 +3288,34 @@ class AleoNetworkClient {
|
|
|
3275
3288
|
if (options.auth && (options.apiKey !== undefined || options.consumerId !== undefined || options.jwtData !== undefined)) {
|
|
3276
3289
|
throw new Error("Pass either `auth` or the legacy apiKey/consumerId/jwtData options, not both");
|
|
3277
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;
|
|
3278
3306
|
const config = options.auth ?? this.auth ?? normalizeAuthConfig({
|
|
3279
3307
|
apiKey: options.apiKey ?? this.apiKey,
|
|
3280
3308
|
consumerId: options.consumerId ?? this.consumerId,
|
|
3281
|
-
jwtData: options.jwtData ??
|
|
3309
|
+
jwtData: options.jwtData ?? injectedJwt,
|
|
3282
3310
|
});
|
|
3283
|
-
const auth = new ApiAuth(config,
|
|
3284
|
-
//
|
|
3285
|
-
//
|
|
3286
|
-
// consumer that minted it
|
|
3287
|
-
// client never
|
|
3288
|
-
|
|
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) {
|
|
3289
3319
|
auth.setJwtData(this.jwtData);
|
|
3290
3320
|
}
|
|
3291
3321
|
// Resolves the auth headers, which refreshes the JWT when it is stale. Runs before
|
|
@@ -3294,7 +3324,12 @@ class AleoNetworkClient {
|
|
|
3294
3324
|
const jwtData = auth.getJwtData();
|
|
3295
3325
|
if (config.mode === "jwt" && jwtData) {
|
|
3296
3326
|
this.jwtData = jwtData;
|
|
3297
|
-
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
|
+
}
|
|
3298
3333
|
options.jwtData = jwtData;
|
|
3299
3334
|
}
|
|
3300
3335
|
// Create the necessary headers to hit the provable api.
|
|
@@ -3385,7 +3420,7 @@ class AleoNetworkClient {
|
|
|
3385
3420
|
* import { AleoNetworkClient, Account, ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
3386
3421
|
*
|
|
3387
3422
|
* // Create a network client and program manager.
|
|
3388
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3423
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2", undefined);
|
|
3389
3424
|
* const programManager = new ProgramManager(networkClient);
|
|
3390
3425
|
*
|
|
3391
3426
|
* // Set the account for the program manager.
|
|
@@ -3633,12 +3668,12 @@ class AleoKeyProvider {
|
|
|
3633
3668
|
*
|
|
3634
3669
|
* @example
|
|
3635
3670
|
* // Create a new object which implements the KeyProvider interface
|
|
3636
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3671
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
3637
3672
|
* const keyProvider = new AleoKeyProvider();
|
|
3638
3673
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
3639
3674
|
*
|
|
3640
3675
|
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
3641
|
-
* const programManager = new ProgramManager("https://
|
|
3676
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
3642
3677
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
3643
3678
|
*
|
|
3644
3679
|
* // Keys can also be fetched manually using the key provider
|
|
@@ -3685,12 +3720,12 @@ class AleoKeyProvider {
|
|
|
3685
3720
|
*
|
|
3686
3721
|
* @example
|
|
3687
3722
|
* // Create a new AleoKeyProvider object
|
|
3688
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3723
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
3689
3724
|
* const keyProvider = new AleoKeyProvider();
|
|
3690
3725
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
3691
3726
|
*
|
|
3692
3727
|
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
3693
|
-
* const programManager = new ProgramManager("https://
|
|
3728
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
3694
3729
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
3695
3730
|
*
|
|
3696
3731
|
* // Keys can also be fetched manually
|
|
@@ -3808,12 +3843,12 @@ class AleoKeyProvider {
|
|
|
3808
3843
|
*
|
|
3809
3844
|
* @example
|
|
3810
3845
|
* // Create a new AleoKeyProvider
|
|
3811
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
3846
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
3812
3847
|
* const keyProvider = new AleoKeyProvider();
|
|
3813
3848
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
3814
3849
|
*
|
|
3815
3850
|
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
3816
|
-
* const programManager = new ProgramManager("https://
|
|
3851
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
3817
3852
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
3818
3853
|
*
|
|
3819
3854
|
* // Keys can also be fetched manually
|
|
@@ -4158,7 +4193,7 @@ class OfflineSearchParams {
|
|
|
4158
4193
|
* const offlineExecuteTx = <Transaction>await this.buildExecutionTransaction("hello_hello.aleo", "hello", 1, false, ["5u32", "5u32"], undefined, offlineSearchParams, undefined, undefined, undefined, undefined, offlineQuery, program);
|
|
4159
4194
|
*
|
|
4160
4195
|
* // Broadcast the transaction later on a machine with internet access
|
|
4161
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
4196
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
4162
4197
|
* const txId = await networkClient.broadcastTransaction(offlineExecuteTx);
|
|
4163
4198
|
*/
|
|
4164
4199
|
class OfflineKeyProvider {
|
|
@@ -4618,7 +4653,7 @@ class NetworkRecordProvider {
|
|
|
4618
4653
|
*
|
|
4619
4654
|
* @example
|
|
4620
4655
|
* // Create a new NetworkRecordProvider
|
|
4621
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
4656
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
4622
4657
|
* const keyProvider = new AleoKeyProvider();
|
|
4623
4658
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
4624
4659
|
*
|
|
@@ -4631,7 +4666,7 @@ class NetworkRecordProvider {
|
|
|
4631
4666
|
*
|
|
4632
4667
|
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
4633
4668
|
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
4634
|
-
* const programManager = new ProgramManager("https://
|
|
4669
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
4635
4670
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
4636
4671
|
*
|
|
4637
4672
|
* */
|
|
@@ -4679,7 +4714,7 @@ class NetworkRecordProvider {
|
|
|
4679
4714
|
*
|
|
4680
4715
|
* @example
|
|
4681
4716
|
* // Create a new NetworkRecordProvider
|
|
4682
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
4717
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
4683
4718
|
* const keyProvider = new AleoKeyProvider();
|
|
4684
4719
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
4685
4720
|
*
|
|
@@ -4692,7 +4727,7 @@ class NetworkRecordProvider {
|
|
|
4692
4727
|
*
|
|
4693
4728
|
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
4694
4729
|
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
4695
|
-
* const programManager = new ProgramManager("https://
|
|
4730
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
4696
4731
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
4697
4732
|
*/
|
|
4698
4733
|
async findCreditsRecord(microcredits, searchParameters) {
|
|
@@ -4788,7 +4823,7 @@ class NetworkRecordProvider {
|
|
|
4788
4823
|
* const params = new BlockHeightSearch(89995, 99995);
|
|
4789
4824
|
*
|
|
4790
4825
|
* // Create a new NetworkRecordProvider
|
|
4791
|
-
* const networkClient = new AleoNetworkClient("https://
|
|
4826
|
+
* const networkClient = new AleoNetworkClient("https://edge.provable.com/api/v2");
|
|
4792
4827
|
* const keyProvider = new AleoKeyProvider();
|
|
4793
4828
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
4794
4829
|
*
|
|
@@ -4979,7 +5014,9 @@ class RecordScanner {
|
|
|
4979
5014
|
* @param {RecordScannerJWTData | undefined} jwtData The JWT data to use, or undefined to clear.
|
|
4980
5015
|
*/
|
|
4981
5016
|
setJwtData(jwtData) {
|
|
4982
|
-
|
|
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);
|
|
4983
5020
|
}
|
|
4984
5021
|
/**
|
|
4985
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.
|
|
@@ -5942,33 +5979,129 @@ function generateHookData(recipientAddress, secretNonce) {
|
|
|
5942
5979
|
return hookData;
|
|
5943
5980
|
}
|
|
5944
5981
|
|
|
5945
|
-
const
|
|
5946
|
-
|
|
5947
|
-
|
|
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);
|
|
5948
6090
|
if (!builder) {
|
|
5949
|
-
throw new Error(
|
|
6091
|
+
throw new Error(preparedContext instanceof PreparedProcess
|
|
6092
|
+
? "Prepared process has already been freed"
|
|
6093
|
+
: "Prepared program has already been freed");
|
|
5950
6094
|
}
|
|
5951
6095
|
// The WASM clone is a cheap shared Rc handle, not a deep copy. Mutations
|
|
5952
6096
|
// made while authorizing intentionally remain cached in the prepared context.
|
|
5953
6097
|
return builder.clone();
|
|
5954
6098
|
}
|
|
5955
|
-
function programImportsFromBuilder(builder, entryProgramName) {
|
|
5956
|
-
const imports = {};
|
|
5957
|
-
for (const name of Array.from(builder.programNames())) {
|
|
5958
|
-
if (name === entryProgramName)
|
|
5959
|
-
continue;
|
|
5960
|
-
const source = builder.getProgram(name);
|
|
5961
|
-
if (source)
|
|
5962
|
-
imports[name] = source;
|
|
5963
|
-
}
|
|
5964
|
-
return imports;
|
|
5965
|
-
}
|
|
5966
6099
|
/**
|
|
5967
6100
|
* A reusable program context created by {@link ProgramManager.prepareProgram}.
|
|
5968
6101
|
*
|
|
5969
|
-
* The context is scoped to one program function.
|
|
5970
|
-
*
|
|
5971
|
-
* 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.
|
|
5972
6105
|
*/
|
|
5973
6106
|
class PreparedProgram {
|
|
5974
6107
|
programName;
|
|
@@ -5988,8 +6121,45 @@ class PreparedProgram {
|
|
|
5988
6121
|
* Release the prepared snarkVM process. This method is idempotent.
|
|
5989
6122
|
*/
|
|
5990
6123
|
free() {
|
|
5991
|
-
|
|
5992
|
-
|
|
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);
|
|
5993
6163
|
}
|
|
5994
6164
|
}
|
|
5995
6165
|
/**
|
|
@@ -6010,7 +6180,7 @@ class ProgramManager {
|
|
|
6010
6180
|
* @param { RecordProvider | undefined } recordProvider A record provider that implements {@link RecordProvider} interface
|
|
6011
6181
|
*/
|
|
6012
6182
|
constructor(host, keyProvider, recordProvider, networkClientOptions, keyStore) {
|
|
6013
|
-
this.host = host ? host : "https://
|
|
6183
|
+
this.host = host ? host : "https://edge.provable.com/api/v2";
|
|
6014
6184
|
this.networkClient = new AleoNetworkClient(this.host, networkClientOptions);
|
|
6015
6185
|
this.keyProvider = keyProvider ? keyProvider : new AleoKeyProvider({ transport: networkClientOptions?.transport });
|
|
6016
6186
|
this.recordProvider = recordProvider;
|
|
@@ -6141,11 +6311,16 @@ class ProgramManager {
|
|
|
6141
6311
|
program = program.toString();
|
|
6142
6312
|
}
|
|
6143
6313
|
const parsedProgram = testnet_js.Program.fromString(program);
|
|
6144
|
-
|
|
6145
|
-
|
|
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
|
+
}
|
|
6146
6321
|
}
|
|
6147
|
-
|
|
6148
|
-
|
|
6322
|
+
finally {
|
|
6323
|
+
parsedProgram.free();
|
|
6149
6324
|
}
|
|
6150
6325
|
const edition = options.edition
|
|
6151
6326
|
?? (await this.resolveEditionAndAmendment(options.programName)).edition;
|
|
@@ -6153,10 +6328,171 @@ class ProgramManager {
|
|
|
6153
6328
|
// Add the entry program as well as its imports so the snarkVM process is
|
|
6154
6329
|
// fully initialized before an authorization is requested.
|
|
6155
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
|
+
}
|
|
6156
6341
|
const preparedProgram = new PreparedProgram(options.programName, options.functionName, program, edition);
|
|
6157
|
-
|
|
6342
|
+
preparedContextBuilders.set(preparedProgram, builder);
|
|
6343
|
+
preparedProgramImports.set(preparedProgram, importSources);
|
|
6158
6344
|
return preparedProgram;
|
|
6159
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
|
+
}
|
|
6160
6496
|
validatePreparedProgram(preparedProgram, options) {
|
|
6161
6497
|
if (preparedProgram.programName !== options.programName
|
|
6162
6498
|
|| preparedProgram.functionName !== options.functionName) {
|
|
@@ -6174,18 +6510,65 @@ class ProgramManager {
|
|
|
6174
6510
|
throw new Error("Prepared program edition does not match the supplied edition");
|
|
6175
6511
|
}
|
|
6176
6512
|
if (options.programImports) {
|
|
6177
|
-
const
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
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`);
|
|
6183
6520
|
}
|
|
6184
6521
|
}
|
|
6185
|
-
|
|
6186
|
-
|
|
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
|
+
}
|
|
6187
6548
|
}
|
|
6188
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
|
+
};
|
|
6189
6572
|
}
|
|
6190
6573
|
/**
|
|
6191
6574
|
* Collect static imports declared by the entry program together with any
|
|
@@ -6514,7 +6897,7 @@ class ProgramManager {
|
|
|
6514
6897
|
* import { ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
6515
6898
|
*
|
|
6516
6899
|
* // Create a ProgramManager
|
|
6517
|
-
* const programManager = new ProgramManager("https://
|
|
6900
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2");
|
|
6518
6901
|
*
|
|
6519
6902
|
* // Set the value of the `Accept-Language` header to `en-US`
|
|
6520
6903
|
* programManager.setHeader('Accept-Language', 'en-US');
|
|
@@ -6535,7 +6918,7 @@ class ProgramManager {
|
|
|
6535
6918
|
* keyProvider.useCache(true);
|
|
6536
6919
|
*
|
|
6537
6920
|
* // Create a ProgramManager
|
|
6538
|
-
* const programManager = new ProgramManager("https://
|
|
6921
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider);
|
|
6539
6922
|
*
|
|
6540
6923
|
* // Set the inclusion keys.
|
|
6541
6924
|
* programManager.setInclusionProver();
|
|
@@ -6569,7 +6952,7 @@ class ProgramManager {
|
|
|
6569
6952
|
* import { ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
6570
6953
|
*
|
|
6571
6954
|
* // Create a ProgramManager
|
|
6572
|
-
* const programManager = new ProgramManager("https://
|
|
6955
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2");
|
|
6573
6956
|
*
|
|
6574
6957
|
* // Remove the default `X-Aleo-SDK-Version` header
|
|
6575
6958
|
* programManager.removeHeader('X-Aleo-SDK-Version');
|
|
@@ -6599,7 +6982,7 @@ class ProgramManager {
|
|
|
6599
6982
|
*
|
|
6600
6983
|
* // Initialize a program manager with the key provider to automatically fetch keys for deployments
|
|
6601
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";
|
|
6602
|
-
* const programManager = new ProgramManager("https://
|
|
6985
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
6603
6986
|
* programManager.setAccount(Account);
|
|
6604
6987
|
*
|
|
6605
6988
|
* // Define a fee in credits
|
|
@@ -6711,7 +7094,7 @@ class ProgramManager {
|
|
|
6711
7094
|
*
|
|
6712
7095
|
* // Initialize a program manager with the key provider to automatically fetch keys for deployments
|
|
6713
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";
|
|
6714
|
-
* const programManager = new ProgramManager("https://
|
|
7097
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
6715
7098
|
* programManager.setAccount(Account);
|
|
6716
7099
|
*
|
|
6717
7100
|
* // Define a fee in credits
|
|
@@ -6829,7 +7212,7 @@ class ProgramManager {
|
|
|
6829
7212
|
*
|
|
6830
7213
|
* // Initialize a program manager with the key provider to automatically fetch keys for deployments
|
|
6831
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";
|
|
6832
|
-
* const programManager = new ProgramManager("https://
|
|
7215
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
6833
7216
|
*
|
|
6834
7217
|
* // Define a fee in credits
|
|
6835
7218
|
* const priorityFee = 0.0;
|
|
@@ -6877,7 +7260,7 @@ class ProgramManager {
|
|
|
6877
7260
|
* keyProvider.useCache(true);
|
|
6878
7261
|
*
|
|
6879
7262
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
6880
|
-
* const programManager = new ProgramManager("https://
|
|
7263
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
6881
7264
|
*
|
|
6882
7265
|
* // Build and execute the transaction
|
|
6883
7266
|
* const tx = await programManager.buildExecutionTransaction({
|
|
@@ -7034,7 +7417,7 @@ class ProgramManager {
|
|
|
7034
7417
|
* keyProvider.useCache(true);
|
|
7035
7418
|
*
|
|
7036
7419
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions.
|
|
7037
|
-
* const programManager = new ProgramManager("https://
|
|
7420
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider);
|
|
7038
7421
|
*
|
|
7039
7422
|
* // Build the `Authorization`.
|
|
7040
7423
|
* const privateKey = new PrivateKey(); // Change this to a private key that has an aleo credit balance.
|
|
@@ -7172,7 +7555,7 @@ class ProgramManager {
|
|
|
7172
7555
|
* keyProvider.useCache(true);
|
|
7173
7556
|
*
|
|
7174
7557
|
* // Initialize a ProgramManager with the key and record providers.
|
|
7175
|
-
* const programManager = new ProgramManager("https://
|
|
7558
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7176
7559
|
*
|
|
7177
7560
|
* // Build the `Authorization`.
|
|
7178
7561
|
* const authorization = await programManager.buildAuthorization({
|
|
@@ -7187,15 +7570,12 @@ class ProgramManager {
|
|
|
7187
7570
|
async buildAuthorization(options) {
|
|
7188
7571
|
// Destructure the options object to access the parameters.
|
|
7189
7572
|
const { functionName, inputs, } = options;
|
|
7190
|
-
const
|
|
7191
|
-
if (preparedProgram) {
|
|
7192
|
-
this.validatePreparedProgram(preparedProgram, options);
|
|
7193
|
-
}
|
|
7573
|
+
const preparedCall = this.preparedCallContext(options);
|
|
7194
7574
|
const privateKey = options.privateKey;
|
|
7195
|
-
let program =
|
|
7196
|
-
let programName =
|
|
7575
|
+
let program = preparedCall?.programSource ?? options.programSource;
|
|
7576
|
+
let programName = preparedCall?.programName ?? options.programName;
|
|
7197
7577
|
const imports = options.programImports;
|
|
7198
|
-
let edition =
|
|
7578
|
+
let edition = preparedCall?.edition ?? options.edition;
|
|
7199
7579
|
// Ensure the function exists on the network.
|
|
7200
7580
|
if (program === undefined) {
|
|
7201
7581
|
try {
|
|
@@ -7221,7 +7601,7 @@ class ProgramManager {
|
|
|
7221
7601
|
if (typeof executionPrivateKey === "undefined") {
|
|
7222
7602
|
throw "No private key provided and no private key set in the ProgramManager";
|
|
7223
7603
|
}
|
|
7224
|
-
if (!
|
|
7604
|
+
if (!preparedCall) {
|
|
7225
7605
|
const resolved = await this.resolveEditionAndAmendment(programName, edition);
|
|
7226
7606
|
edition = edition ?? resolved.edition;
|
|
7227
7607
|
}
|
|
@@ -7229,13 +7609,13 @@ class ProgramManager {
|
|
|
7229
7609
|
const preparedInputs = this.prepareInputs(program, functionName, inputs);
|
|
7230
7610
|
// Build ProgramImportsBuilder for import resolution (no key loading —
|
|
7231
7611
|
// authorizations don't synthesize keys).
|
|
7232
|
-
const builder =
|
|
7233
|
-
?
|
|
7612
|
+
const builder = preparedCall
|
|
7613
|
+
? clonePreparedContextBuilder(preparedCall.context)
|
|
7234
7614
|
: (await this.buildProgramImports(program, imports, false, functionName)).builder;
|
|
7235
|
-
const
|
|
7236
|
-
const hasImports = !builder.isEmpty();
|
|
7615
|
+
const hasPreparedContext = preparedCall !== undefined;
|
|
7616
|
+
const hasImports = !hasPreparedContext && !builder.isEmpty();
|
|
7237
7617
|
// Build and return an `Authorization` for the desired function.
|
|
7238
|
-
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));
|
|
7239
7619
|
return authorization;
|
|
7240
7620
|
}
|
|
7241
7621
|
/**
|
|
@@ -7254,7 +7634,7 @@ class ProgramManager {
|
|
|
7254
7634
|
* keyProvider.useCache(true);
|
|
7255
7635
|
*
|
|
7256
7636
|
* // Initialize a ProgramManager with the key and record providers.
|
|
7257
|
-
* const programManager = new ProgramManager("https://
|
|
7637
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7258
7638
|
*
|
|
7259
7639
|
* // Build the unchecked `Authorization`.
|
|
7260
7640
|
* const authorization = await programManager.buildAuthorizationUnchecked({
|
|
@@ -7269,15 +7649,12 @@ class ProgramManager {
|
|
|
7269
7649
|
async buildAuthorizationUnchecked(options) {
|
|
7270
7650
|
// Destructure the options object to access the parameters.
|
|
7271
7651
|
const { functionName, inputs, } = options;
|
|
7272
|
-
const
|
|
7273
|
-
if (preparedProgram) {
|
|
7274
|
-
this.validatePreparedProgram(preparedProgram, options);
|
|
7275
|
-
}
|
|
7652
|
+
const preparedCall = this.preparedCallContext(options);
|
|
7276
7653
|
const privateKey = options.privateKey;
|
|
7277
|
-
let program =
|
|
7278
|
-
let programName =
|
|
7654
|
+
let program = preparedCall?.programSource ?? options.programSource;
|
|
7655
|
+
let programName = preparedCall?.programName ?? options.programName;
|
|
7279
7656
|
const imports = options.programImports;
|
|
7280
|
-
let edition =
|
|
7657
|
+
let edition = preparedCall?.edition ?? options.edition;
|
|
7281
7658
|
// Ensure the function exists on the network.
|
|
7282
7659
|
if (program === undefined) {
|
|
7283
7660
|
try {
|
|
@@ -7303,7 +7680,7 @@ class ProgramManager {
|
|
|
7303
7680
|
if (typeof executionPrivateKey === "undefined") {
|
|
7304
7681
|
throw "No private key provided and no private key set in the ProgramManager";
|
|
7305
7682
|
}
|
|
7306
|
-
if (!
|
|
7683
|
+
if (!preparedCall) {
|
|
7307
7684
|
const resolved = await this.resolveEditionAndAmendment(programName, edition);
|
|
7308
7685
|
edition = edition ?? resolved.edition;
|
|
7309
7686
|
}
|
|
@@ -7311,13 +7688,13 @@ class ProgramManager {
|
|
|
7311
7688
|
const preparedInputs = this.prepareInputs(program, functionName, inputs);
|
|
7312
7689
|
// Build ProgramImportsBuilder for import resolution (no key loading —
|
|
7313
7690
|
// authorizations don't synthesize keys).
|
|
7314
|
-
const builder =
|
|
7315
|
-
?
|
|
7691
|
+
const builder = preparedCall
|
|
7692
|
+
? clonePreparedContextBuilder(preparedCall.context)
|
|
7316
7693
|
: (await this.buildProgramImports(program, imports, false, functionName)).builder;
|
|
7317
|
-
const
|
|
7318
|
-
const hasImports = !builder.isEmpty();
|
|
7694
|
+
const hasPreparedContext = preparedCall !== undefined;
|
|
7695
|
+
const hasImports = !hasPreparedContext && !builder.isEmpty();
|
|
7319
7696
|
// Build and return an `Authorization` for the desired function.
|
|
7320
|
-
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));
|
|
7321
7698
|
return authorization;
|
|
7322
7699
|
}
|
|
7323
7700
|
/**
|
|
@@ -7336,7 +7713,7 @@ class ProgramManager {
|
|
|
7336
7713
|
* keyProvider.useCache(true);
|
|
7337
7714
|
*
|
|
7338
7715
|
* // Initialize a ProgramManager with the key and record providers.
|
|
7339
|
-
* const programManager = new ProgramManager("https://
|
|
7716
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7340
7717
|
*
|
|
7341
7718
|
* // Build the proving request.
|
|
7342
7719
|
* const provingRequest = await programManager.provingRequest({
|
|
@@ -7354,18 +7731,15 @@ class ProgramManager {
|
|
|
7354
7731
|
async provingRequest(options) {
|
|
7355
7732
|
// Destructure the options object to access the parameters.
|
|
7356
7733
|
const { functionName, priorityFee, privateFee, inputs, recordSearchParams, broadcast = false, unchecked = false, } = options;
|
|
7357
|
-
const
|
|
7358
|
-
if (preparedProgram) {
|
|
7359
|
-
this.validatePreparedProgram(preparedProgram, options);
|
|
7360
|
-
}
|
|
7734
|
+
const preparedCall = this.preparedCallContext(options);
|
|
7361
7735
|
const baseFee = options.baseFee ? options.baseFee : 0;
|
|
7362
7736
|
const privateKey = options.privateKey;
|
|
7363
7737
|
const useFeeMaster = options.useFeeMaster ? options.useFeeMaster : false;
|
|
7364
|
-
let program =
|
|
7365
|
-
let programName =
|
|
7738
|
+
let program = preparedCall?.programSource ?? options.programSource;
|
|
7739
|
+
let programName = preparedCall?.programName ?? options.programName;
|
|
7366
7740
|
let feeRecord = options.feeRecord;
|
|
7367
7741
|
let imports = options.programImports;
|
|
7368
|
-
let edition =
|
|
7742
|
+
let edition = preparedCall?.edition ?? options.edition;
|
|
7369
7743
|
if (!inputs && !options.executionRequest) {
|
|
7370
7744
|
throw new Error("Either function inputs or an execution request must be provided to form a proving request");
|
|
7371
7745
|
}
|
|
@@ -7385,7 +7759,7 @@ class ProgramManager {
|
|
|
7385
7759
|
if (programName === undefined) {
|
|
7386
7760
|
programName = testnet_js.Program.fromString(program).id();
|
|
7387
7761
|
}
|
|
7388
|
-
if (!
|
|
7762
|
+
if (!preparedCall) {
|
|
7389
7763
|
const resolved = await this.resolveEditionAndAmendment(programName, edition);
|
|
7390
7764
|
edition = edition ?? resolved.edition;
|
|
7391
7765
|
}
|
|
@@ -7397,8 +7771,8 @@ class ProgramManager {
|
|
|
7397
7771
|
executionPrivateKey = this.account.privateKey();
|
|
7398
7772
|
}
|
|
7399
7773
|
// Resolve the program imports if they exist.
|
|
7400
|
-
const numberOfImports =
|
|
7401
|
-
if (!
|
|
7774
|
+
const numberOfImports = ProgramManager.getImportNames(program).length;
|
|
7775
|
+
if (!preparedCall && numberOfImports > 0 && !imports) {
|
|
7402
7776
|
try {
|
|
7403
7777
|
imports = (await this.networkClient.getProgramImports(programName));
|
|
7404
7778
|
}
|
|
@@ -7408,33 +7782,19 @@ class ProgramManager {
|
|
|
7408
7782
|
}
|
|
7409
7783
|
// Build ProgramImportsBuilder for import resolution (no key loading —
|
|
7410
7784
|
// proving requests don't synthesize keys).
|
|
7411
|
-
const builder =
|
|
7412
|
-
?
|
|
7785
|
+
const builder = preparedCall
|
|
7786
|
+
? clonePreparedContextBuilder(preparedCall.context)
|
|
7413
7787
|
: (await this.buildProgramImports(program, imports, false, functionName)).builder;
|
|
7414
|
-
const
|
|
7415
|
-
const hasImports = !builder.isEmpty();
|
|
7416
|
-
|
|
7417
|
-
// both the private-fee estimate below and the Rust-side fee estimator
|
|
7418
|
-
// (estimate_fee_for_authorization uses the legacy imports Object to
|
|
7419
|
-
// avoid a RefCell double-borrow — see proving_request.rs) see all
|
|
7420
|
-
// transitive imports, not just the caller's partial set. Use
|
|
7421
|
-
// programNames + getProgram to avoid serializing key bytes (toObject
|
|
7422
|
-
// would serialize all proving/verifying keys, which can be tens of
|
|
7423
|
-
// MB). The prepared executionRequest path skips the copy: it passes
|
|
7424
|
-
// the process builder directly and never estimates fees, so the
|
|
7425
|
-
// imports Object goes unused there.
|
|
7426
|
-
const importsObjectUnused = hasPreparedProcess
|
|
7427
|
-
&& options.executionRequest instanceof testnet_js.ExecutionRequest;
|
|
7428
|
-
if ((hasPreparedProcess || hasImports) && !importsObjectUnused) {
|
|
7429
|
-
imports = programImportsFromBuilder(builder, programName);
|
|
7430
|
-
}
|
|
7788
|
+
const hasPreparedContext = preparedCall !== undefined;
|
|
7789
|
+
const hasImports = !hasPreparedContext && !builder.isEmpty();
|
|
7790
|
+
const hasProcessBuilder = hasPreparedContext || hasImports;
|
|
7431
7791
|
// Get the fee record from the account if it is not provided in the parameters
|
|
7432
7792
|
try {
|
|
7433
7793
|
if (privateFee && !useFeeMaster && !options.executionRequest) {
|
|
7434
7794
|
let fee = priorityFee;
|
|
7435
7795
|
// If a fee record wasn't provided, estimate the fee that needs to be paid.
|
|
7436
7796
|
if (!feeRecord) {
|
|
7437
|
-
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)));
|
|
7438
7798
|
fee = baseFee + priorityFee;
|
|
7439
7799
|
}
|
|
7440
7800
|
// Get a credits.aleo record for the fee.
|
|
@@ -7449,10 +7809,7 @@ class ProgramManager {
|
|
|
7449
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.`);
|
|
7450
7810
|
}
|
|
7451
7811
|
if (options.executionRequest instanceof testnet_js.ExecutionRequest) {
|
|
7452
|
-
return await testnet_js.ProgramManager.buildProvingRequestFromExecutionRequest(options.executionRequest, program, unchecked, broadcast, edition,
|
|
7453
|
-
// The prepared process supersedes the legacy imports Object;
|
|
7454
|
-
// without one, imports is kept for fee estimation in Rust.
|
|
7455
|
-
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));
|
|
7456
7813
|
}
|
|
7457
7814
|
else {
|
|
7458
7815
|
// Ensure the private key exists.
|
|
@@ -7466,8 +7823,7 @@ class ProgramManager {
|
|
|
7466
7823
|
// Auto-convert bare string inputs to field elements where the function expects field type.
|
|
7467
7824
|
const preparedInputs = this.prepareInputs(program, functionName, inputs);
|
|
7468
7825
|
// Build and return the `ProvingRequest`.
|
|
7469
|
-
return await testnet_js.ProgramManager.buildProvingRequest(executionPrivateKey, program, functionName, preparedInputs, baseFee, priorityFee, feeRecord, imports,
|
|
7470
|
-
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));
|
|
7471
7827
|
}
|
|
7472
7828
|
}
|
|
7473
7829
|
/**
|
|
@@ -7486,7 +7842,7 @@ class ProgramManager {
|
|
|
7486
7842
|
* keyProvider.useCache(true);
|
|
7487
7843
|
*
|
|
7488
7844
|
* // Initialize a ProgramManager with the key and record providers.
|
|
7489
|
-
* const programManager = new ProgramManager("https://
|
|
7845
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7490
7846
|
*
|
|
7491
7847
|
* // Build a credits.aleo/fee_public `Authorization`.
|
|
7492
7848
|
* const feePublicAuthorization = await programManager.buildFeeAuthorization({
|
|
@@ -7533,7 +7889,7 @@ class ProgramManager {
|
|
|
7533
7889
|
* keyProvider.useCache(true);
|
|
7534
7890
|
*
|
|
7535
7891
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
7536
|
-
* const programManager = new ProgramManager("https://
|
|
7892
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7537
7893
|
*
|
|
7538
7894
|
* // Build and execute the transaction
|
|
7539
7895
|
* const tx_id = await programManager.execute({
|
|
@@ -7708,7 +8064,7 @@ class ProgramManager {
|
|
|
7708
8064
|
* keyProvider.useCache(true);
|
|
7709
8065
|
*
|
|
7710
8066
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
7711
|
-
* const programManager = new ProgramManager("https://
|
|
8067
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7712
8068
|
* const record_1 = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}"
|
|
7713
8069
|
* const record_2 = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 1540945439182663264862696551825005342995406165131907382295858612069623286213group.public}"
|
|
7714
8070
|
* const tx_id = await programManager.join(record_1, record_2, 0.05, false);
|
|
@@ -7815,7 +8171,7 @@ class ProgramManager {
|
|
|
7815
8171
|
* keyProvider.useCache(true);
|
|
7816
8172
|
*
|
|
7817
8173
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
7818
|
-
* const programManager = new ProgramManager("https://
|
|
8174
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7819
8175
|
* const record = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}"
|
|
7820
8176
|
* const tx_id = await programManager.split(25000000, record);
|
|
7821
8177
|
*
|
|
@@ -7926,7 +8282,7 @@ class ProgramManager {
|
|
|
7926
8282
|
* keyProvider.useCache(true);
|
|
7927
8283
|
*
|
|
7928
8284
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
7929
|
-
* const programManager = new ProgramManager("https://
|
|
8285
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
7930
8286
|
* const tx = await programManager.buildTransferTransaction(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "public", 0.2, false);
|
|
7931
8287
|
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
7932
8288
|
*
|
|
@@ -8015,7 +8371,7 @@ class ProgramManager {
|
|
|
8015
8371
|
* keyProvider.useCache(true);
|
|
8016
8372
|
*
|
|
8017
8373
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
8018
|
-
* const programManager = new ProgramManager("https://
|
|
8374
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
8019
8375
|
* const tx = await programManager.buildTransferPublicTransaction(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", 0.2);
|
|
8020
8376
|
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
8021
8377
|
*
|
|
@@ -8048,7 +8404,7 @@ class ProgramManager {
|
|
|
8048
8404
|
* keyProvider.useCache(true);
|
|
8049
8405
|
*
|
|
8050
8406
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
8051
|
-
* const programManager = new ProgramManager("https://
|
|
8407
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
8052
8408
|
* const tx = await programManager.buildTransferPublicAsSignerTransaction(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", 0.2);
|
|
8053
8409
|
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
8054
8410
|
*
|
|
@@ -8086,7 +8442,7 @@ class ProgramManager {
|
|
|
8086
8442
|
* keyProvider.useCache(true);
|
|
8087
8443
|
*
|
|
8088
8444
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
8089
|
-
* const programManager = new ProgramManager("https://
|
|
8445
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, recordProvider);
|
|
8090
8446
|
* const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "public", 0.2, false);
|
|
8091
8447
|
*
|
|
8092
8448
|
* // Verify the transaction was successful
|
|
@@ -8131,7 +8487,7 @@ class ProgramManager {
|
|
|
8131
8487
|
* keyProvider.useCache(true);
|
|
8132
8488
|
*
|
|
8133
8489
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8134
|
-
* const programManager = new ProgramManager("https://
|
|
8490
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8135
8491
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
8136
8492
|
*
|
|
8137
8493
|
* // Create the bonding transaction object for later submission
|
|
@@ -8187,7 +8543,7 @@ class ProgramManager {
|
|
|
8187
8543
|
* keyProvider.useCache(true);
|
|
8188
8544
|
*
|
|
8189
8545
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8190
|
-
* const programManager = new ProgramManager("https://
|
|
8546
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8191
8547
|
*
|
|
8192
8548
|
* // Create the bonding transaction
|
|
8193
8549
|
* tx_id = await programManager.bondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
|
|
@@ -8235,7 +8591,7 @@ class ProgramManager {
|
|
|
8235
8591
|
* keyProvider.useCache(true);
|
|
8236
8592
|
*
|
|
8237
8593
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8238
|
-
* const programManager = new ProgramManager("https://
|
|
8594
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8239
8595
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
8240
8596
|
*
|
|
8241
8597
|
* // Create the bond validator transaction object for later use.
|
|
@@ -8294,7 +8650,7 @@ class ProgramManager {
|
|
|
8294
8650
|
* keyProvider.useCache(true);
|
|
8295
8651
|
*
|
|
8296
8652
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8297
|
-
* const programManager = new ProgramManager("https://
|
|
8653
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8298
8654
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
8299
8655
|
*
|
|
8300
8656
|
* // Create the bonding transaction
|
|
@@ -8341,7 +8697,7 @@ class ProgramManager {
|
|
|
8341
8697
|
* keyProvider.useCache(true);
|
|
8342
8698
|
*
|
|
8343
8699
|
* // Create a new ProgramManager with the key that will be used to unbond credits.
|
|
8344
|
-
* const programManager = new ProgramManager("https://
|
|
8700
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8345
8701
|
* const tx = await programManager.buildUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", 2000000);
|
|
8346
8702
|
*
|
|
8347
8703
|
* // The transaction can be submitted later to the network using the network client.
|
|
@@ -8394,7 +8750,7 @@ class ProgramManager {
|
|
|
8394
8750
|
* keyProvider.useCache(true);
|
|
8395
8751
|
*
|
|
8396
8752
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8397
|
-
* const programManager = new ProgramManager("https://
|
|
8753
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8398
8754
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
8399
8755
|
*
|
|
8400
8756
|
* // Create the unbond_public transaction and send it to the network
|
|
@@ -8440,7 +8796,7 @@ class ProgramManager {
|
|
|
8440
8796
|
* keyProvider.useCache(true);
|
|
8441
8797
|
*
|
|
8442
8798
|
* // Create a new ProgramManager with the key that will be used to claim unbonded credits.
|
|
8443
|
-
* const programManager = new ProgramManager("https://
|
|
8799
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8444
8800
|
*
|
|
8445
8801
|
* // Create the claim_unbond_public transaction object for later use.
|
|
8446
8802
|
* const tx = await programManager.buildClaimUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j");
|
|
@@ -8490,7 +8846,7 @@ class ProgramManager {
|
|
|
8490
8846
|
* keyProvider.useCache(true);
|
|
8491
8847
|
*
|
|
8492
8848
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8493
|
-
* const programManager = new ProgramManager("https://
|
|
8849
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8494
8850
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
8495
8851
|
*
|
|
8496
8852
|
* // Create the claim_unbond_public transaction
|
|
@@ -8544,7 +8900,7 @@ class ProgramManager {
|
|
|
8544
8900
|
* keyProvider.useCache(true);
|
|
8545
8901
|
*
|
|
8546
8902
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8547
|
-
* const programManager = new ProgramManager("https://
|
|
8903
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8548
8904
|
*
|
|
8549
8905
|
* // Create the set_validator_state transaction
|
|
8550
8906
|
* const tx = await programManager.buildSetValidatorStateTransaction(true);
|
|
@@ -8600,7 +8956,7 @@ class ProgramManager {
|
|
|
8600
8956
|
* keyProvider.useCache(true);
|
|
8601
8957
|
*
|
|
8602
8958
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
8603
|
-
* const programManager = new ProgramManager("https://
|
|
8959
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider, undefined);
|
|
8604
8960
|
*
|
|
8605
8961
|
* // Create the set_validator_state transaction
|
|
8606
8962
|
* const tx_id = await programManager.setValidatorState(true);
|
|
@@ -8722,7 +9078,7 @@ class ProgramManager {
|
|
|
8722
9078
|
* keyProvider.useCache(true);
|
|
8723
9079
|
*
|
|
8724
9080
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions.
|
|
8725
|
-
* const programManager = new ProgramManager("https://
|
|
9081
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider);
|
|
8726
9082
|
*
|
|
8727
9083
|
* // Build the `Authorization`.
|
|
8728
9084
|
* const privateKey = new PrivateKey(); // Change this to a private key that has an aleo credit balance.
|
|
@@ -8779,7 +9135,7 @@ class ProgramManager {
|
|
|
8779
9135
|
* import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
|
|
8780
9136
|
*
|
|
8781
9137
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions.
|
|
8782
|
-
* const programManager = new ProgramManager("https://
|
|
9138
|
+
* const programManager = new ProgramManager("https://edge.provable.com/api/v2", keyProvider);
|
|
8783
9139
|
*
|
|
8784
9140
|
* // Get the base fee in microcredits.
|
|
8785
9141
|
* const baseFeeMicrocredits = await programManager.estimateExecutionFee({programName: "credits.aleo"});
|
|
@@ -9781,6 +10137,7 @@ exports.PRIVATE_TRANSFER_TYPES = PRIVATE_TRANSFER_TYPES;
|
|
|
9781
10137
|
exports.PUBLIC_TO_PRIVATE_TRANSFER = PUBLIC_TO_PRIVATE_TRANSFER;
|
|
9782
10138
|
exports.PUBLIC_TRANSFER = PUBLIC_TRANSFER;
|
|
9783
10139
|
exports.PUBLIC_TRANSFER_AS_SIGNER = PUBLIC_TRANSFER_AS_SIGNER;
|
|
10140
|
+
exports.PreparedProcess = PreparedProcess;
|
|
9784
10141
|
exports.PreparedProgram = PreparedProgram;
|
|
9785
10142
|
exports.ProgramManager = ProgramManager;
|
|
9786
10143
|
exports.RECORD_DOMAIN = RECORD_DOMAIN;
|