@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.
@@ -1479,6 +1479,11 @@ const RECORD_DOMAIN = "RecordScannerV0";
1479
1479
  const ZERO_ADDRESS = "aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc";
1480
1480
  const FIVE_MINUTES = 5 * 60 * 1000; // 5 minutes in milliseconds
1481
1481
 
1482
+ const HEADERS = new Set([
1483
+ "x-aleo-sdk-version",
1484
+ "x-aleo-environment",
1485
+ "x-aleo-method",
1486
+ ]);
1482
1487
  /**
1483
1488
  * Client library that encapsulates REST calls to publicly exposed endpoints of Aleo nodes. The methods provided in this
1484
1489
  * allow users to query public information from the Aleo blockchain and submit transactions to the network.
@@ -1526,7 +1531,7 @@ class AleoNetworkClient {
1526
1531
  else {
1527
1532
  this.headers = {
1528
1533
  // This is replaced by the actual version by a Rollup plugin
1529
- "X-Aleo-SDK-Version": "0.11.1",
1534
+ "X-Aleo-SDK-Version": "0.11.2",
1530
1535
  "X-Aleo-environment": environment(),
1531
1536
  };
1532
1537
  }
@@ -1542,7 +1547,7 @@ class AleoNetworkClient {
1542
1547
  else {
1543
1548
  this.headers = {
1544
1549
  // This is replaced by the actual version by a Rollup plugin
1545
- "X-Aleo-SDK-Version": "0.11.1",
1550
+ "X-Aleo-SDK-Version": "0.11.2",
1546
1551
  "X-Aleo-environment": environment(),
1547
1552
  };
1548
1553
  }
@@ -1658,6 +1663,21 @@ class AleoNetworkClient {
1658
1663
  removeHeader(headerName) {
1659
1664
  delete this.headers[headerName];
1660
1665
  }
1666
+ userHeaders() {
1667
+ const result = {};
1668
+ for (const [key, value] of Object.entries(this.headers)) {
1669
+ if (!HEADERS.has(key.toLowerCase())) {
1670
+ result[key] = value;
1671
+ }
1672
+ }
1673
+ return result;
1674
+ }
1675
+ method(method) {
1676
+ if (this.hasCustomTransport) {
1677
+ return this.userHeaders();
1678
+ }
1679
+ return { ...this.headers, "X-ALEO-METHOD": method };
1680
+ }
1661
1681
  /**
1662
1682
  * Fetches data from the Aleo network and returns it as a JSON object.
1663
1683
  *
@@ -1685,10 +1705,9 @@ class AleoNetworkClient {
1685
1705
  const ctx = { ...this.ctx };
1686
1706
  return await retryWithBackoff(async () => {
1687
1707
  const response = await get(this.host + url, {
1688
- headers: {
1689
- ...this.headers,
1690
- ...ctx,
1691
- },
1708
+ headers: this.hasCustomTransport
1709
+ ? this.userHeaders()
1710
+ : { ...this.headers, ...ctx },
1692
1711
  }, this.transport);
1693
1712
  return await response.text();
1694
1713
  });
@@ -2920,7 +2939,7 @@ class AleoNetworkClient {
2920
2939
  const endpoint = this.verboseErrors ? "transaction/broadcast?check_transaction=true" : "transaction/broadcast";
2921
2940
  const response = await retryWithBackoff(() => this._sendPost(`${this.host}/${endpoint}`, {
2922
2941
  body: transactionString,
2923
- headers: Object.assign({}, { ...this.headers, "X-ALEO-METHOD": "submitTransaction" }, {
2942
+ headers: Object.assign({}, this.method("submitTransaction"), {
2924
2943
  "Content-Type": "application/json",
2925
2944
  }),
2926
2945
  }));
@@ -2946,7 +2965,7 @@ class AleoNetworkClient {
2946
2965
  try {
2947
2966
  const response = await retryWithBackoff(() => post(this.host + "/solution/broadcast", {
2948
2967
  body: solution,
2949
- headers: Object.assign({}, { ...this.headers, "X-ALEO-METHOD": "submitSolution" }, {
2968
+ headers: Object.assign({}, this.method("submitSolution"), {
2950
2969
  "Content-Type": "application/json",
2951
2970
  }),
2952
2971
  }, this.transport));
@@ -2975,7 +2994,8 @@ class AleoNetworkClient {
2975
2994
  }
2976
2995
  const response = await post(`${this.baseUrl}/jwts/${consumerId}`, {
2977
2996
  headers: {
2978
- 'X-Provable-API-Key': apiKey
2997
+ ...this.method("refreshJwt"),
2998
+ 'X-Provable-API-Key': apiKey,
2979
2999
  }
2980
3000
  }, this.transport);
2981
3001
  const authHeader = response.headers.get('authorization');
@@ -3069,8 +3089,7 @@ class AleoNetworkClient {
3069
3089
  }
3070
3090
  // Create the necessary headers to hit the provable api.
3071
3091
  const headers = {
3072
- ...this.headers,
3073
- "X-ALEO-METHOD": "submitProvingRequest",
3092
+ ...this.method("submitProvingRequest"),
3074
3093
  "Content-Type": "application/json",
3075
3094
  };
3076
3095
  if (jwtData?.jwt) {
@@ -3184,10 +3203,7 @@ class AleoNetworkClient {
3184
3203
  }
3185
3204
  try {
3186
3205
  const res = await this.transport(`${this.host}/transaction/confirmed/${transactionId}`, {
3187
- headers: {
3188
- ...this.headers,
3189
- "X-ALEO-METHOD": "waitForTransactionConfirmation",
3190
- },
3206
+ headers: this.method("waitForTransactionConfirmation"),
3191
3207
  });
3192
3208
  if (!res.ok) {
3193
3209
  let text = "";