@palbase/web 7.3.0 → 7.3.1

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
@@ -61,6 +61,45 @@ var PalbaseError = class extends Error {
61
61
  this.details = details;
62
62
  }
63
63
  };
64
+ var POW_CHALLENGE_ID_HEADER = "X-PoW-Challenge-ID";
65
+ var POW_NONCE_HEADER = "X-PoW-Nonce";
66
+ function asPowChallenge(details) {
67
+ if (typeof details !== "object" || details === null) return null;
68
+ const env = details;
69
+ if (env.error !== "pow_required") return null;
70
+ const c = env.challenge;
71
+ if (typeof c !== "object" || c === null) return null;
72
+ const { id, prefix, difficulty } = c;
73
+ if (typeof id !== "string" || typeof prefix !== "string") return null;
74
+ if (typeof difficulty !== "number" || !Number.isInteger(difficulty) || difficulty < 0) return null;
75
+ return { id, prefix, difficulty };
76
+ }
77
+ var encoder = new TextEncoder();
78
+ function leadingZeroBits(hash) {
79
+ let bits = 0;
80
+ for (const byte of hash) {
81
+ if (byte === 0) {
82
+ bits += 8;
83
+ continue;
84
+ }
85
+ return bits + Math.clz32(byte) - 24;
86
+ }
87
+ return bits;
88
+ }
89
+ async function solvePowChallenge(challenge, maxIterations = 1 << 24) {
90
+ for (let nonce = 0; nonce < maxIterations; nonce++) {
91
+ const digest = await crypto.subtle.digest("SHA-256", encoder.encode(challenge.prefix + nonce));
92
+ if (leadingZeroBits(new Uint8Array(digest)) >= challenge.difficulty) {
93
+ return {
94
+ [POW_CHALLENGE_ID_HEADER]: challenge.id,
95
+ [POW_NONCE_HEADER]: String(nonce)
96
+ };
97
+ }
98
+ }
99
+ throw new Error(
100
+ `proof-of-work: no nonce found for difficulty ${challenge.difficulty} within ${maxIterations} attempts`
101
+ );
102
+ }
64
103
 
65
104
  // src/errors.ts
66
105
  var BackendError = class _BackendError extends Error {
@@ -181,47 +220,6 @@ function redactUrl(rawUrl) {
181
220
  return path.split("/").map((seg2) => isSensitiveSegment(seg2) ? ":id" : seg2).join("/");
182
221
  }
183
222
 
184
- // src/pow.ts
185
- var POW_CHALLENGE_ID_HEADER = "X-PoW-Challenge-ID";
186
- var POW_NONCE_HEADER = "X-PoW-Nonce";
187
- function asPowChallenge(details) {
188
- if (typeof details !== "object" || details === null) return null;
189
- const env = details;
190
- if (env.error !== "pow_required") return null;
191
- const c = env.challenge;
192
- if (typeof c !== "object" || c === null) return null;
193
- const { id, prefix, difficulty } = c;
194
- if (typeof id !== "string" || typeof prefix !== "string") return null;
195
- if (typeof difficulty !== "number" || !Number.isInteger(difficulty) || difficulty < 0) return null;
196
- return { id, prefix, difficulty };
197
- }
198
- var encoder = new TextEncoder();
199
- function leadingZeroBits(hash) {
200
- let bits = 0;
201
- for (const byte of hash) {
202
- if (byte === 0) {
203
- bits += 8;
204
- continue;
205
- }
206
- return bits + Math.clz32(byte) - 24;
207
- }
208
- return bits;
209
- }
210
- async function solvePowChallenge(challenge, maxIterations = 1 << 24) {
211
- for (let nonce = 0; nonce < maxIterations; nonce++) {
212
- const digest = await crypto.subtle.digest("SHA-256", encoder.encode(challenge.prefix + nonce));
213
- if (leadingZeroBits(new Uint8Array(digest)) >= challenge.difficulty) {
214
- return {
215
- [POW_CHALLENGE_ID_HEADER]: challenge.id,
216
- [POW_NONCE_HEADER]: String(nonce)
217
- };
218
- }
219
- }
220
- throw new Error(
221
- `proof-of-work: no nonce found for difficulty ${challenge.difficulty} within ${maxIterations} attempts`
222
- );
223
- }
224
-
225
223
  // src/request.ts
226
224
  var MUTATING = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
227
225
  var PERF_EXCLUDED_PREFIX = "/v1/analytics/";
@@ -7958,7 +7956,7 @@ function localStorageSessionStorage(key = DEFAULT_KEY) {
7958
7956
  }
7959
7957
 
7960
7958
  // src/version.ts
7961
- var VERSION = "7.3.0";
7959
+ var VERSION = "7.3.1";
7962
7960
 
7963
7961
  // src/internal.ts
7964
7962
  function getRuntime() {