@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/{chunk-ACCJV6FV.js → chunk-53TN7KYR.js} +58 -5
- package/dist/chunk-53TN7KYR.js.map +1 -0
- package/dist/{chunk-ZC6Q3GPX.js → chunk-CBN3PWNL.js} +2 -2
- package/dist/{chunk-YBURINUN.js → chunk-RRHJV6YD.js} +5 -44
- package/dist/chunk-RRHJV6YD.js.map +1 -0
- package/dist/index.cjs +40 -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 +56 -46
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.js +2 -2
- package/dist/next/client.cjs +56 -46
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +2 -2
- package/dist/next/index.cjs +56 -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 +40 -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-CBN3PWNL.js.map} +0 -0
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.
|
|
7959
|
+
var VERSION = "7.3.1";
|
|
7962
7960
|
|
|
7963
7961
|
// src/internal.ts
|
|
7964
7962
|
function getRuntime() {
|