@palbase/web 7.3.3 → 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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  importNextServer
3
- } from "../chunk-IRPS637F.js";
3
+ } from "../chunk-IVD6BP5Z.js";
4
4
  import {
5
5
  SESSION_COOKIE_ATTRS,
6
6
  clearedSessionCookieNames,
@@ -14,10 +14,10 @@ import {
14
14
  buildRuntime,
15
15
  createBoundClient,
16
16
  getRuntime
17
- } from "../chunk-XF7NM6HF.js";
17
+ } from "../chunk-PYJ3CMA2.js";
18
18
  import {
19
19
  BackendError
20
- } from "../chunk-43BGZCNU.js";
20
+ } from "../chunk-RAP37ILS.js";
21
21
  import {
22
22
  environmentRefFromApiKey,
23
23
  environmentRefFromPublishableApiKey
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  importNextServer
3
- } from "../chunk-IRPS637F.js";
3
+ } from "../chunk-IVD6BP5Z.js";
4
4
  import {
5
5
  SESSION_COOKIE_ATTRS,
6
6
  clearedSessionCookieNames,
@@ -9,7 +9,7 @@ import {
9
9
  } from "../chunk-6VGKMNXO.js";
10
10
  import {
11
11
  BackendError
12
- } from "../chunk-43BGZCNU.js";
12
+ } from "../chunk-RAP37ILS.js";
13
13
  import {
14
14
  environmentRefFromPublishableApiKey
15
15
  } from "../chunk-CFDU23TB.js";
@@ -63,6 +63,7 @@ function asPowChallenge(details) {
63
63
  return { id, prefix, difficulty };
64
64
  }
65
65
  var encoder = new TextEncoder();
66
+ var now = () => typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
66
67
  function leadingZeroBits(hash) {
67
68
  let bits = 0;
68
69
  for (const byte of hash) {
@@ -78,15 +79,24 @@ var MAX_POW_DIFFICULTY = 24;
78
79
  function powBudget(difficulty) {
79
80
  return 8 * 2 ** difficulty;
80
81
  }
82
+ var POW_DEADLINE_MS = 12e4;
81
83
  async function solvePowChallenge(challenge, maxIterations = powBudget(challenge.difficulty), signal) {
82
84
  if (challenge.difficulty > MAX_POW_DIFFICULTY) {
83
85
  throw new Error(
84
86
  `proof-of-work: refusing difficulty ${challenge.difficulty}; this client attempts at most ${MAX_POW_DIFFICULTY}, which is the highest a Palbase stack issues`
85
87
  );
86
88
  }
89
+ const deadline = now() + POW_DEADLINE_MS;
87
90
  for (let nonce = 0; nonce < maxIterations; nonce++) {
88
- if ((nonce & 1023) === 0 && signal?.aborted) {
89
- throw new DOMException("proof-of-work solve aborted", "AbortError");
91
+ if ((nonce & 1023) === 0) {
92
+ if (signal?.aborted) {
93
+ throw new DOMException("proof-of-work solve aborted", "AbortError");
94
+ }
95
+ if (now() > deadline) {
96
+ throw new Error(
97
+ `proof-of-work: gave up after ${POW_DEADLINE_MS / 1e3}s at difficulty ${challenge.difficulty} (${nonce} attempts)`
98
+ );
99
+ }
90
100
  }
91
101
  const digest = await crypto.subtle.digest("SHA-256", encoder.encode(challenge.prefix + nonce));
92
102
  if (leadingZeroBits(new Uint8Array(digest)) >= challenge.difficulty) {
@@ -414,7 +424,7 @@ function applyBrowserOriginHeader(headers) {
414
424
  }
415
425
 
416
426
  // src/version.ts
417
- var VERSION = "7.3.3";
427
+ var VERSION = "7.3.4";
418
428
 
419
429
  // src/call.ts
420
430
  async function callEndpoint(resolveRt, name, input, options) {