@palbase/web 7.3.2 → 7.3.4

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/internal.js CHANGED
@@ -6,8 +6,8 @@ import {
6
6
  createBoundClient,
7
7
  getRuntime,
8
8
  onConfigured
9
- } from "./chunk-TQAQR3OP.js";
10
- import "./chunk-HKZVA3I3.js";
9
+ } from "./chunk-PYJ3CMA2.js";
10
+ import "./chunk-RAP37ILS.js";
11
11
  import "./chunk-CFDU23TB.js";
12
12
  import "./chunk-PZ5AY32C.js";
13
13
  export {
@@ -70,6 +70,7 @@ function asPowChallenge(details) {
70
70
  return { id, prefix, difficulty };
71
71
  }
72
72
  var encoder = new TextEncoder();
73
+ var now = () => typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
73
74
  function leadingZeroBits(hash) {
74
75
  let bits = 0;
75
76
  for (const byte of hash) {
@@ -85,13 +86,25 @@ var MAX_POW_DIFFICULTY = 24;
85
86
  function powBudget(difficulty) {
86
87
  return 8 * 2 ** difficulty;
87
88
  }
88
- async function solvePowChallenge(challenge, maxIterations = powBudget(challenge.difficulty)) {
89
+ var POW_DEADLINE_MS = 12e4;
90
+ async function solvePowChallenge(challenge, maxIterations = powBudget(challenge.difficulty), signal) {
89
91
  if (challenge.difficulty > MAX_POW_DIFFICULTY) {
90
92
  throw new Error(
91
93
  `proof-of-work: refusing difficulty ${challenge.difficulty}; this client attempts at most ${MAX_POW_DIFFICULTY}, which is the highest a Palbase stack issues`
92
94
  );
93
95
  }
96
+ const deadline = now() + POW_DEADLINE_MS;
94
97
  for (let nonce = 0; nonce < maxIterations; nonce++) {
98
+ if ((nonce & 1023) === 0) {
99
+ if (signal?.aborted) {
100
+ throw new DOMException("proof-of-work solve aborted", "AbortError");
101
+ }
102
+ if (now() > deadline) {
103
+ throw new Error(
104
+ `proof-of-work: gave up after ${POW_DEADLINE_MS / 1e3}s at difficulty ${challenge.difficulty} (${nonce} attempts)`
105
+ );
106
+ }
107
+ }
95
108
  const digest = await crypto.subtle.digest("SHA-256", encoder.encode(challenge.prefix + nonce));
96
109
  if (leadingZeroBits(new Uint8Array(digest)) >= challenge.difficulty) {
97
110
  return {
@@ -261,7 +274,7 @@ var HttpClient = class _HttpClient {
261
274
  if (attempt < MAX_RETRIES - 1) {
262
275
  const backoff = INITIAL_BACKOFF_MS * 2 ** attempt;
263
276
  await this.delay(backoff);
264
- return this.executeWithRetry(method, path, options, attempt + 1, earned);
277
+ return this.executeWithRetry(method, path, options, attempt + 1);
265
278
  }
266
279
  throw new PalbaseError(
267
280
  "network_error",
@@ -297,7 +310,7 @@ var HttpClient = class _HttpClient {
297
310
  path,
298
311
  options,
299
312
  attempt,
300
- await solvePowChallenge(challenge)
313
+ await solvePowChallenge(challenge, void 0, options?.signal)
301
314
  );
302
315
  }
303
316
  }
@@ -9164,7 +9177,7 @@ function defaultSessionStorage(key) {
9164
9177
  }
9165
9178
 
9166
9179
  // src/version.ts
9167
- var VERSION = "7.3.2";
9180
+ var VERSION = "7.3.4";
9168
9181
 
9169
9182
  // src/runtime.ts
9170
9183
  function buildRuntime(config) {