@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/CHANGELOG.md CHANGED
@@ -4,6 +4,17 @@ All notable changes to `@qed-proof/sdk` are documented here. Format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project uses
5
5
  [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [0.1.5] - Unreleased
8
+
9
+ ### Changed
10
+ - `waitForVerdict` backs off exponentially (x2 per poll, capped at 30 s), matching the Python SDK. It still never sleeps past `timeoutMs` and still honours `Retry-After`.
11
+ - A generated `client_claim_id` uses `crypto.getRandomValues` when `crypto.randomUUID` is unavailable, before falling back to `Math.random`.
12
+
13
+ ## [0.1.4] - Unreleased
14
+
15
+ ### Fixed
16
+ - Works in browsers: `QedProof` now calls `fetch` as a plain function. 0.1.0–0.1.3 called it as a method of the client, which browsers reject with "Illegal invocation" (Node accepts it).
17
+
7
18
  ## [0.1.3] - Unreleased
8
19
 
9
20
  Same code as 0.1.2. 0.1.2 was tagged but never published: the release job's npm was too old for trusted publishing.
package/dist/index.cjs CHANGED
@@ -1768,10 +1768,11 @@ var QedProof = class {
1768
1768
  constructor(options = {}) {
1769
1769
  this.apiKey = options.apiKey;
1770
1770
  this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
1771
- this.fetchImpl = options.fetch ?? globalThis.fetch;
1772
- if (!this.fetchImpl) {
1771
+ const f = options.fetch ?? globalThis.fetch;
1772
+ if (!f) {
1773
1773
  throw new Error("QedProof: no fetch implementation available; pass { fetch } explicitly");
1774
1774
  }
1775
+ this.fetchImpl = (input, init) => f(input, init);
1775
1776
  }
1776
1777
  async request(method, path, { auth = true, body, text = false } = {}) {
1777
1778
  const headers = { accept: "application/json" };
@@ -1835,8 +1836,9 @@ var QedProof = class {
1835
1836
  const timeoutMs = options.timeoutMs ?? 12e4;
1836
1837
  const pollIntervalMs = options.pollIntervalMs ?? 2e3;
1837
1838
  const deadline = Date.now() + timeoutMs;
1839
+ let interval = pollIntervalMs;
1838
1840
  for (; ; ) {
1839
- let wait = pollIntervalMs;
1841
+ let wait = interval;
1840
1842
  try {
1841
1843
  const status = await this.getClaim(claimId);
1842
1844
  if (status.state === "decided") return status;
@@ -1851,6 +1853,7 @@ var QedProof = class {
1851
1853
  throw new QedProofError(408, `timed out after ${timeoutMs}ms waiting for claim ${claimId} to decide`);
1852
1854
  }
1853
1855
  await sleep(Math.min(wait, Math.max(0, deadline - Date.now())));
1856
+ interval = Math.min(interval * 2, 3e4);
1854
1857
  }
1855
1858
  }
1856
1859
  /**
@@ -1905,6 +1908,12 @@ function sleep(ms) {
1905
1908
  function cryptoRandomId() {
1906
1909
  const g = globalThis;
1907
1910
  if (g.crypto?.randomUUID) return g.crypto.randomUUID();
1911
+ if (g.crypto?.getRandomValues) {
1912
+ const bytes = new Uint8Array(16);
1913
+ g.crypto.getRandomValues(bytes);
1914
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
1915
+ return `claim-${Date.now()}-${hex}`;
1916
+ }
1908
1917
  return `claim-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1909
1918
  }
1910
1919