@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.
package/dist/internal.js CHANGED
@@ -6,8 +6,8 @@ import {
6
6
  createBoundClient,
7
7
  getRuntime,
8
8
  onConfigured
9
- } from "./chunk-XF7NM6HF.js";
10
- import "./chunk-43BGZCNU.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,15 +86,24 @@ var MAX_POW_DIFFICULTY = 24;
85
86
  function powBudget(difficulty) {
86
87
  return 8 * 2 ** difficulty;
87
88
  }
89
+ var POW_DEADLINE_MS = 12e4;
88
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++) {
95
- if ((nonce & 1023) === 0 && signal?.aborted) {
96
- throw new DOMException("proof-of-work solve aborted", "AbortError");
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
+ }
97
107
  }
98
108
  const digest = await crypto.subtle.digest("SHA-256", encoder.encode(challenge.prefix + nonce));
99
109
  if (leadingZeroBits(new Uint8Array(digest)) >= challenge.difficulty) {
@@ -9167,7 +9177,7 @@ function defaultSessionStorage(key) {
9167
9177
  }
9168
9178
 
9169
9179
  // src/version.ts
9170
- var VERSION = "7.3.3";
9180
+ var VERSION = "7.3.4";
9171
9181
 
9172
9182
  // src/runtime.ts
9173
9183
  function buildRuntime(config) {