@provablehq/sdk 0.11.1 → 0.11.2

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.
@@ -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.2",
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.2",
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
  });
@@ -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 = "";