@qed-proof/sdk 0.1.3 → 0.1.5

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/index.js CHANGED
@@ -1721,10 +1721,11 @@ var QedProof = class {
1721
1721
  constructor(options = {}) {
1722
1722
  this.apiKey = options.apiKey;
1723
1723
  this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
1724
- this.fetchImpl = options.fetch ?? globalThis.fetch;
1725
- if (!this.fetchImpl) {
1724
+ const f = options.fetch ?? globalThis.fetch;
1725
+ if (!f) {
1726
1726
  throw new Error("QedProof: no fetch implementation available; pass { fetch } explicitly");
1727
1727
  }
1728
+ this.fetchImpl = (input, init) => f(input, init);
1728
1729
  }
1729
1730
  async request(method, path, { auth = true, body, text = false } = {}) {
1730
1731
  const headers = { accept: "application/json" };
@@ -1788,8 +1789,9 @@ var QedProof = class {
1788
1789
  const timeoutMs = options.timeoutMs ?? 12e4;
1789
1790
  const pollIntervalMs = options.pollIntervalMs ?? 2e3;
1790
1791
  const deadline = Date.now() + timeoutMs;
1792
+ let interval = pollIntervalMs;
1791
1793
  for (; ; ) {
1792
- let wait = pollIntervalMs;
1794
+ let wait = interval;
1793
1795
  try {
1794
1796
  const status = await this.getClaim(claimId);
1795
1797
  if (status.state === "decided") return status;
@@ -1804,6 +1806,7 @@ var QedProof = class {
1804
1806
  throw new QedProofError(408, `timed out after ${timeoutMs}ms waiting for claim ${claimId} to decide`);
1805
1807
  }
1806
1808
  await sleep(Math.min(wait, Math.max(0, deadline - Date.now())));
1809
+ interval = Math.min(interval * 2, 3e4);
1807
1810
  }
1808
1811
  }
1809
1812
  /**
@@ -1858,6 +1861,12 @@ function sleep(ms) {
1858
1861
  function cryptoRandomId() {
1859
1862
  const g = globalThis;
1860
1863
  if (g.crypto?.randomUUID) return g.crypto.randomUUID();
1864
+ if (g.crypto?.getRandomValues) {
1865
+ const bytes = new Uint8Array(16);
1866
+ g.crypto.getRandomValues(bytes);
1867
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
1868
+ return `claim-${Date.now()}-${hex}`;
1869
+ }
1861
1870
  return `claim-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1862
1871
  }
1863
1872