@provablehq/sdk 0.11.1 → 0.11.3

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.
@@ -177,6 +177,8 @@ declare class AleoNetworkClient {
177
177
  */
178
178
  setHeader(headerName: string, value: string): void;
179
179
  removeHeader(headerName: string): void;
180
+ private userHeaders;
181
+ private method;
180
182
  /**
181
183
  * Fetches data from the Aleo network and returns it as a JSON object.
182
184
  *
@@ -177,6 +177,8 @@ declare class AleoNetworkClient {
177
177
  */
178
178
  setHeader(headerName: string, value: string): void;
179
179
  removeHeader(headerName: string): void;
180
+ private userHeaders;
181
+ private method;
180
182
  /**
181
183
  * Fetches data from the Aleo network and returns it as a JSON object.
182
184
  *
@@ -1488,7 +1488,7 @@ declare class ProgramManager {
1488
1488
  * import { AleoKeyProvider, getOrInitConsensusVersionTestHeights, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
1489
1489
  *
1490
1490
  * // Initialize the development consensus heights in order to work with devnode.
1491
- * getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14");
1491
+ * getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16");
1492
1492
  *
1493
1493
  * // Create a new NetworkClient and RecordProvider.
1494
1494
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
@@ -1529,7 +1529,7 @@ declare class ProgramManager {
1529
1529
  * import { ProgramManager, NetworkRecordProvider, getOrInitConsensusVersionTestHeights } from "@provablehq/sdk/mainnet.js";
1530
1530
  *
1531
1531
  * // Initialize the development consensus heights in order to work with a local devnode.
1532
- * getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14");
1532
+ * getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16");
1533
1533
  *
1534
1534
  * // Create a new NetworkClient, and RecordProvider
1535
1535
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
@@ -1488,7 +1488,7 @@ declare class ProgramManager {
1488
1488
  * import { AleoKeyProvider, getOrInitConsensusVersionTestHeights, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
1489
1489
  *
1490
1490
  * // Initialize the development consensus heights in order to work with devnode.
1491
- * getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14");
1491
+ * getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16");
1492
1492
  *
1493
1493
  * // Create a new NetworkClient and RecordProvider.
1494
1494
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
@@ -1529,7 +1529,7 @@ declare class ProgramManager {
1529
1529
  * import { ProgramManager, NetworkRecordProvider, getOrInitConsensusVersionTestHeights } from "@provablehq/sdk/mainnet.js";
1530
1530
  *
1531
1531
  * // Initialize the development consensus heights in order to work with a local devnode.
1532
- * getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14");
1532
+ * getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16");
1533
1533
  *
1534
1534
  * // Create a new NetworkClient, and RecordProvider
1535
1535
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
@@ -1480,6 +1480,11 @@ const RECORD_DOMAIN = "RecordScannerV0";
1480
1480
  const ZERO_ADDRESS = "aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc";
1481
1481
  const FIVE_MINUTES = 5 * 60 * 1000; // 5 minutes in milliseconds
1482
1482
 
1483
+ const HEADERS = new Set([
1484
+ "x-aleo-sdk-version",
1485
+ "x-aleo-environment",
1486
+ "x-aleo-method",
1487
+ ]);
1483
1488
  /**
1484
1489
  * Client library that encapsulates REST calls to publicly exposed endpoints of Aleo nodes. The methods provided in this
1485
1490
  * allow users to query public information from the Aleo blockchain and submit transactions to the network.
@@ -1527,7 +1532,7 @@ class AleoNetworkClient {
1527
1532
  else {
1528
1533
  this.headers = {
1529
1534
  // This is replaced by the actual version by a Rollup plugin
1530
- "X-Aleo-SDK-Version": "0.11.1",
1535
+ "X-Aleo-SDK-Version": "0.11.3",
1531
1536
  "X-Aleo-environment": environment(),
1532
1537
  };
1533
1538
  }
@@ -1543,7 +1548,7 @@ class AleoNetworkClient {
1543
1548
  else {
1544
1549
  this.headers = {
1545
1550
  // This is replaced by the actual version by a Rollup plugin
1546
- "X-Aleo-SDK-Version": "0.11.1",
1551
+ "X-Aleo-SDK-Version": "0.11.3",
1547
1552
  "X-Aleo-environment": environment(),
1548
1553
  };
1549
1554
  }
@@ -1659,6 +1664,21 @@ class AleoNetworkClient {
1659
1664
  removeHeader(headerName) {
1660
1665
  delete this.headers[headerName];
1661
1666
  }
1667
+ userHeaders() {
1668
+ const result = {};
1669
+ for (const [key, value] of Object.entries(this.headers)) {
1670
+ if (!HEADERS.has(key.toLowerCase())) {
1671
+ result[key] = value;
1672
+ }
1673
+ }
1674
+ return result;
1675
+ }
1676
+ method(method) {
1677
+ if (this.hasCustomTransport) {
1678
+ return this.userHeaders();
1679
+ }
1680
+ return { ...this.headers, "X-ALEO-METHOD": method };
1681
+ }
1662
1682
  /**
1663
1683
  * Fetches data from the Aleo network and returns it as a JSON object.
1664
1684
  *
@@ -1686,10 +1706,9 @@ class AleoNetworkClient {
1686
1706
  const ctx = { ...this.ctx };
1687
1707
  return await retryWithBackoff(async () => {
1688
1708
  const response = await get(this.host + url, {
1689
- headers: {
1690
- ...this.headers,
1691
- ...ctx,
1692
- },
1709
+ headers: this.hasCustomTransport
1710
+ ? this.userHeaders()
1711
+ : { ...this.headers, ...ctx },
1693
1712
  }, this.transport);
1694
1713
  return await response.text();
1695
1714
  });
@@ -2390,7 +2409,7 @@ class AleoNetworkClient {
2390
2409
  async getProgramAmendmentCount(programId) {
2391
2410
  try {
2392
2411
  this.ctx = { "X-ALEO-METHOD": "getProgramAmendmentCount" };
2393
- const raw = await this.fetchRaw("/programs/" + programId + "/amendment_count");
2412
+ const raw = await this.fetchRaw("/program/" + programId + "/amendment_count");
2394
2413
  return JSON.parse(raw);
2395
2414
  }
2396
2415
  catch (error) {
@@ -2921,7 +2940,7 @@ class AleoNetworkClient {
2921
2940
  const endpoint = this.verboseErrors ? "transaction/broadcast?check_transaction=true" : "transaction/broadcast";
2922
2941
  const response = await retryWithBackoff(() => this._sendPost(`${this.host}/${endpoint}`, {
2923
2942
  body: transactionString,
2924
- headers: Object.assign({}, { ...this.headers, "X-ALEO-METHOD": "submitTransaction" }, {
2943
+ headers: Object.assign({}, this.method("submitTransaction"), {
2925
2944
  "Content-Type": "application/json",
2926
2945
  }),
2927
2946
  }));
@@ -2947,7 +2966,7 @@ class AleoNetworkClient {
2947
2966
  try {
2948
2967
  const response = await retryWithBackoff(() => post(this.host + "/solution/broadcast", {
2949
2968
  body: solution,
2950
- headers: Object.assign({}, { ...this.headers, "X-ALEO-METHOD": "submitSolution" }, {
2969
+ headers: Object.assign({}, this.method("submitSolution"), {
2951
2970
  "Content-Type": "application/json",
2952
2971
  }),
2953
2972
  }, this.transport));
@@ -2976,7 +2995,8 @@ class AleoNetworkClient {
2976
2995
  }
2977
2996
  const response = await post(`${this.baseUrl}/jwts/${consumerId}`, {
2978
2997
  headers: {
2979
- 'X-Provable-API-Key': apiKey
2998
+ ...this.method("refreshJwt"),
2999
+ 'X-Provable-API-Key': apiKey,
2980
3000
  }
2981
3001
  }, this.transport);
2982
3002
  const authHeader = response.headers.get('authorization');
@@ -3070,8 +3090,7 @@ class AleoNetworkClient {
3070
3090
  }
3071
3091
  // Create the necessary headers to hit the provable api.
3072
3092
  const headers = {
3073
- ...this.headers,
3074
- "X-ALEO-METHOD": "submitProvingRequest",
3093
+ ...this.method("submitProvingRequest"),
3075
3094
  "Content-Type": "application/json",
3076
3095
  };
3077
3096
  if (jwtData?.jwt) {
@@ -3185,10 +3204,7 @@ class AleoNetworkClient {
3185
3204
  }
3186
3205
  try {
3187
3206
  const res = await this.transport(`${this.host}/transaction/confirmed/${transactionId}`, {
3188
- headers: {
3189
- ...this.headers,
3190
- "X-ALEO-METHOD": "waitForTransactionConfirmation",
3191
- },
3207
+ headers: this.method("waitForTransactionConfirmation"),
3192
3208
  });
3193
3209
  if (!res.ok) {
3194
3210
  let text = "";
@@ -8449,7 +8465,7 @@ class ProgramManager {
8449
8465
  * import { AleoKeyProvider, getOrInitConsensusVersionTestHeights, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
8450
8466
  *
8451
8467
  * // Initialize the development consensus heights in order to work with devnode.
8452
- * getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14");
8468
+ * getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16");
8453
8469
  *
8454
8470
  * // Create a new NetworkClient and RecordProvider.
8455
8471
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
@@ -8576,7 +8592,7 @@ class ProgramManager {
8576
8592
  * import { ProgramManager, NetworkRecordProvider, getOrInitConsensusVersionTestHeights } from "@provablehq/sdk/mainnet.js";
8577
8593
  *
8578
8594
  * // Initialize the development consensus heights in order to work with a local devnode.
8579
- * getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14");
8595
+ * getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16");
8580
8596
  *
8581
8597
  * // Create a new NetworkClient, and RecordProvider
8582
8598
  * const recordProvider = new NetworkRecordProvider(account, networkClient);