@palbase/web 7.3.0 → 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/{chunk-ACCJV6FV.js → chunk-HKZVA3I3.js} +67 -5
- package/dist/chunk-HKZVA3I3.js.map +1 -0
- package/dist/{chunk-ZC6Q3GPX.js → chunk-OZLTH7YB.js} +2 -2
- package/dist/{chunk-YBURINUN.js → chunk-TQAQR3OP.js} +5 -44
- package/dist/chunk-TQAQR3OP.js.map +1 -0
- package/dist/index.cjs +49 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/internal.cjs +65 -46
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.js +2 -2
- package/dist/next/client.cjs +65 -46
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +2 -2
- package/dist/next/index.cjs +65 -46
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.js +3 -3
- package/dist/next/proxy.js +2 -2
- package/dist/react/index.cjs +49 -42
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-ACCJV6FV.js.map +0 -1
- package/dist/chunk-YBURINUN.js.map +0 -1
- /package/dist/{chunk-ZC6Q3GPX.js.map → chunk-OZLTH7YB.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -61,6 +61,54 @@ 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
|
+
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
|
+
}
|
|
99
|
+
for (let nonce = 0; nonce < maxIterations; nonce++) {
|
|
100
|
+
const digest = await crypto.subtle.digest("SHA-256", encoder.encode(challenge.prefix + nonce));
|
|
101
|
+
if (leadingZeroBits(new Uint8Array(digest)) >= challenge.difficulty) {
|
|
102
|
+
return {
|
|
103
|
+
[POW_CHALLENGE_ID_HEADER]: challenge.id,
|
|
104
|
+
[POW_NONCE_HEADER]: String(nonce)
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
throw new Error(
|
|
109
|
+
`proof-of-work: no nonce found for difficulty ${challenge.difficulty} within ${maxIterations} attempts`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
64
112
|
|
|
65
113
|
// src/errors.ts
|
|
66
114
|
var BackendError = class _BackendError extends Error {
|
|
@@ -181,47 +229,6 @@ function redactUrl(rawUrl) {
|
|
|
181
229
|
return path.split("/").map((seg2) => isSensitiveSegment(seg2) ? ":id" : seg2).join("/");
|
|
182
230
|
}
|
|
183
231
|
|
|
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
232
|
// src/request.ts
|
|
226
233
|
var MUTATING = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
227
234
|
var PERF_EXCLUDED_PREFIX = "/v1/analytics/";
|
|
@@ -7958,7 +7965,7 @@ function localStorageSessionStorage(key = DEFAULT_KEY) {
|
|
|
7958
7965
|
}
|
|
7959
7966
|
|
|
7960
7967
|
// src/version.ts
|
|
7961
|
-
var VERSION = "7.3.
|
|
7968
|
+
var VERSION = "7.3.2";
|
|
7962
7969
|
|
|
7963
7970
|
// src/internal.ts
|
|
7964
7971
|
function getRuntime() {
|