@palbase/web 7.3.1 → 7.3.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.
@@ -6,8 +6,8 @@ import {
6
6
  import {
7
7
  __configure,
8
8
  getRuntime
9
- } from "../chunk-RRHJV6YD.js";
10
- import "../chunk-53TN7KYR.js";
9
+ } from "../chunk-XF7NM6HF.js";
10
+ import "../chunk-43BGZCNU.js";
11
11
  import {
12
12
  environmentRefFromPublishableApiKey
13
13
  } from "../chunk-CFDU23TB.js";
@@ -191,8 +191,20 @@ function leadingZeroBits(hash) {
191
191
  }
192
192
  return bits;
193
193
  }
194
- async function solvePowChallenge(challenge, maxIterations = 1 << 24) {
194
+ var MAX_POW_DIFFICULTY = 24;
195
+ function powBudget(difficulty) {
196
+ return 8 * 2 ** difficulty;
197
+ }
198
+ async function solvePowChallenge(challenge, maxIterations = powBudget(challenge.difficulty), signal) {
199
+ if (challenge.difficulty > MAX_POW_DIFFICULTY) {
200
+ throw new Error(
201
+ `proof-of-work: refusing difficulty ${challenge.difficulty}; this client attempts at most ${MAX_POW_DIFFICULTY}, which is the highest a Palbase stack issues`
202
+ );
203
+ }
195
204
  for (let nonce = 0; nonce < maxIterations; nonce++) {
205
+ if ((nonce & 1023) === 0 && signal?.aborted) {
206
+ throw new DOMException("proof-of-work solve aborted", "AbortError");
207
+ }
196
208
  const digest = await crypto.subtle.digest("SHA-256", encoder.encode(challenge.prefix + nonce));
197
209
  if (leadingZeroBits(new Uint8Array(digest)) >= challenge.difficulty) {
198
210
  return {
@@ -362,7 +374,7 @@ var HttpClient = class _HttpClient {
362
374
  if (attempt < MAX_RETRIES - 1) {
363
375
  const backoff = INITIAL_BACKOFF_MS * 2 ** attempt;
364
376
  await this.delay(backoff);
365
- return this.executeWithRetry(method, path, options, attempt + 1, earned);
377
+ return this.executeWithRetry(method, path, options, attempt + 1);
366
378
  }
367
379
  throw new PalbaseError(
368
380
  "network_error",
@@ -398,7 +410,7 @@ var HttpClient = class _HttpClient {
398
410
  path,
399
411
  options,
400
412
  attempt,
401
- await solvePowChallenge(challenge)
413
+ await solvePowChallenge(challenge, void 0, options?.signal)
402
414
  );
403
415
  }
404
416
  }
@@ -9364,7 +9376,7 @@ function defaultSessionStorage(key) {
9364
9376
  }
9365
9377
 
9366
9378
  // src/version.ts
9367
- var VERSION = "7.3.1";
9379
+ var VERSION = "7.3.3";
9368
9380
 
9369
9381
  // src/runtime.ts
9370
9382
  function buildRuntime(config) {