@palbase/web 7.3.1 → 7.3.2

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/index.cjs CHANGED
@@ -86,7 +86,16 @@ function leadingZeroBits(hash) {
86
86
  }
87
87
  return bits;
88
88
  }
89
- async function solvePowChallenge(challenge, maxIterations = 1 << 24) {
89
+ var MAX_POW_DIFFICULTY = 24;
90
+ function powBudget(difficulty) {
91
+ return 8 * 2 ** difficulty;
92
+ }
93
+ async function solvePowChallenge(challenge, maxIterations = powBudget(challenge.difficulty)) {
94
+ if (challenge.difficulty > MAX_POW_DIFFICULTY) {
95
+ throw new Error(
96
+ `proof-of-work: refusing difficulty ${challenge.difficulty}; this client attempts at most ${MAX_POW_DIFFICULTY}, which is the highest a Palbase stack issues`
97
+ );
98
+ }
90
99
  for (let nonce = 0; nonce < maxIterations; nonce++) {
91
100
  const digest = await crypto.subtle.digest("SHA-256", encoder.encode(challenge.prefix + nonce));
92
101
  if (leadingZeroBits(new Uint8Array(digest)) >= challenge.difficulty) {
@@ -7956,7 +7965,7 @@ function localStorageSessionStorage(key = DEFAULT_KEY) {
7956
7965
  }
7957
7966
 
7958
7967
  // src/version.ts
7959
- var VERSION = "7.3.1";
7968
+ var VERSION = "7.3.2";
7960
7969
 
7961
7970
  // src/internal.ts
7962
7971
  function getRuntime() {