@palbase/web 7.3.4 → 7.3.6
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-RAP37ILS.js → chunk-6DGCUHSO.js} +48 -6
- package/dist/chunk-6DGCUHSO.js.map +1 -0
- package/dist/{chunk-IVD6BP5Z.js → chunk-HT5SNA5H.js} +2 -2
- package/dist/{chunk-PYJ3CMA2.js → chunk-SQWG3PTU.js} +4 -8
- package/dist/{chunk-PYJ3CMA2.js.map → chunk-SQWG3PTU.js.map} +1 -1
- package/dist/gen/cli.cjs +0 -3
- package/dist/gen/cli.cjs.map +1 -1
- package/dist/gen/cli.js +0 -3
- package/dist/gen/cli.js.map +1 -1
- package/dist/index.cjs +48 -6
- 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 +49 -11
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.js +2 -2
- package/dist/next/client.cjs +49 -11
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +2 -2
- package/dist/next/index.cjs +49 -11
- 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 +48 -6
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +2 -2
- package/package.json +2 -2
- package/dist/chunk-RAP37ILS.js.map +0 -1
- /package/dist/{chunk-IVD6BP5Z.js.map → chunk-HT5SNA5H.js.map} +0 -0
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -11,11 +11,11 @@ import {
|
|
|
11
11
|
localStorageSessionStorage,
|
|
12
12
|
memorySessionStorage,
|
|
13
13
|
pb
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-SQWG3PTU.js";
|
|
15
15
|
import {
|
|
16
16
|
BackendError,
|
|
17
17
|
isBackendError
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-6DGCUHSO.js";
|
|
19
19
|
import "./chunk-CFDU23TB.js";
|
|
20
20
|
import "./chunk-PZ5AY32C.js";
|
|
21
21
|
export {
|
package/dist/internal.cjs
CHANGED
|
@@ -68,6 +68,28 @@ function asPowChallenge(details) {
|
|
|
68
68
|
return { id, prefix, difficulty };
|
|
69
69
|
}
|
|
70
70
|
var encoder = new TextEncoder();
|
|
71
|
+
var hasher = null;
|
|
72
|
+
async function digester() {
|
|
73
|
+
if (hasher) return hasher;
|
|
74
|
+
const runtime = globalThis;
|
|
75
|
+
const nodeish = runtime.process?.versions?.node !== void 0 || runtime.process?.versions?.bun !== void 0;
|
|
76
|
+
if (nodeish) {
|
|
77
|
+
try {
|
|
78
|
+
const mod = await import(
|
|
79
|
+
/* @vite-ignore */
|
|
80
|
+
`${"node:"}crypto`
|
|
81
|
+
);
|
|
82
|
+
if (typeof mod.createHash === "function") {
|
|
83
|
+
const createHash = mod.createHash;
|
|
84
|
+
hasher = (input) => new Uint8Array(createHash("sha256").update(input).digest());
|
|
85
|
+
return hasher;
|
|
86
|
+
}
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
hasher = async (input) => new Uint8Array(await crypto.subtle.digest("SHA-256", encoder.encode(input)));
|
|
91
|
+
return hasher;
|
|
92
|
+
}
|
|
71
93
|
var now = () => typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
|
|
72
94
|
function leadingZeroBits(hash) {
|
|
73
95
|
let bits = 0;
|
|
@@ -84,14 +106,19 @@ var MAX_POW_DIFFICULTY = 24;
|
|
|
84
106
|
function powBudget(difficulty) {
|
|
85
107
|
return 8 * 2 ** difficulty;
|
|
86
108
|
}
|
|
87
|
-
var
|
|
109
|
+
var POW_TIME_BUDGET_MS = 12e4;
|
|
110
|
+
var CALIBRATION_WARMUP = 1024;
|
|
111
|
+
var CALIBRATION_END = 9216;
|
|
88
112
|
async function solvePowChallenge(challenge, maxIterations = powBudget(challenge.difficulty), signal) {
|
|
89
113
|
if (challenge.difficulty > MAX_POW_DIFFICULTY) {
|
|
90
114
|
throw new Error(
|
|
91
115
|
`proof-of-work: refusing difficulty ${challenge.difficulty}; this client attempts at most ${MAX_POW_DIFFICULTY}, which is the highest a Palbase stack issues`
|
|
92
116
|
);
|
|
93
117
|
}
|
|
94
|
-
const
|
|
118
|
+
const digest = await digester();
|
|
119
|
+
let warmedAt = 0;
|
|
120
|
+
let calibrated = false;
|
|
121
|
+
let deadline = Number.POSITIVE_INFINITY;
|
|
95
122
|
for (let nonce = 0; nonce < maxIterations; nonce++) {
|
|
96
123
|
if ((nonce & 1023) === 0) {
|
|
97
124
|
if (signal?.aborted) {
|
|
@@ -99,12 +126,27 @@ async function solvePowChallenge(challenge, maxIterations = powBudget(challenge.
|
|
|
99
126
|
}
|
|
100
127
|
if (now() > deadline) {
|
|
101
128
|
throw new Error(
|
|
102
|
-
`proof-of-work: gave up after ${
|
|
129
|
+
`proof-of-work: gave up on difficulty ${challenge.difficulty} after ${POW_TIME_BUDGET_MS / 1e3}s and ${nonce.toLocaleString()} attempts \u2014 the tail this run drew is longer than the allowance`
|
|
103
130
|
);
|
|
104
131
|
}
|
|
105
132
|
}
|
|
106
|
-
|
|
107
|
-
|
|
133
|
+
if (nonce === CALIBRATION_WARMUP) {
|
|
134
|
+
warmedAt = now();
|
|
135
|
+
}
|
|
136
|
+
if (!calibrated && nonce === CALIBRATION_END) {
|
|
137
|
+
calibrated = true;
|
|
138
|
+
const elapsed = Math.max(now() - warmedAt, 1e-3);
|
|
139
|
+
const rate = (CALIBRATION_END - CALIBRATION_WARMUP) / (elapsed / 1e3);
|
|
140
|
+
const expectedMs = 2 ** challenge.difficulty / rate * 1e3;
|
|
141
|
+
if (expectedMs > POW_TIME_BUDGET_MS) {
|
|
142
|
+
throw new Error(
|
|
143
|
+
`proof-of-work: difficulty ${challenge.difficulty} needs about ${Math.round(expectedMs / 1e3)}s here (${Math.round(rate).toLocaleString()} digests/s) and this client allows ${POW_TIME_BUDGET_MS / 1e3}s; refusing before spending the time rather than after`
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
deadline = now() + (POW_TIME_BUDGET_MS - (now() - warmedAt));
|
|
147
|
+
}
|
|
148
|
+
const hash = await digest(challenge.prefix + nonce);
|
|
149
|
+
if (leadingZeroBits(hash) >= challenge.difficulty) {
|
|
108
150
|
return {
|
|
109
151
|
[POW_CHALLENGE_ID_HEADER]: challenge.id,
|
|
110
152
|
[POW_NONCE_HEADER]: String(nonce)
|
|
@@ -9377,7 +9419,7 @@ function defaultSessionStorage(key) {
|
|
|
9377
9419
|
}
|
|
9378
9420
|
|
|
9379
9421
|
// src/version.ts
|
|
9380
|
-
var VERSION = "7.3.
|
|
9422
|
+
var VERSION = "7.3.6";
|
|
9381
9423
|
|
|
9382
9424
|
// src/runtime.ts
|
|
9383
9425
|
function buildRuntime(config) {
|
|
@@ -9385,15 +9427,11 @@ function buildRuntime(config) {
|
|
|
9385
9427
|
if (projectRef === "") {
|
|
9386
9428
|
throw new Error("PalbeConfig.apiKey does not contain a valid publishable project identity");
|
|
9387
9429
|
}
|
|
9388
|
-
let runtimeURL;
|
|
9389
9430
|
try {
|
|
9390
|
-
|
|
9431
|
+
new URL(config.url);
|
|
9391
9432
|
} catch {
|
|
9392
9433
|
throw new Error("PalbeConfig.url must be a valid URL");
|
|
9393
9434
|
}
|
|
9394
|
-
if (runtimeURL.hostname.endsWith(".palbase.studio") && runtimeURL.hostname.split(".")[0] !== projectRef) {
|
|
9395
|
-
throw new Error("PalbeConfig.url must match the project identity in apiKey for palbase.studio");
|
|
9396
|
-
}
|
|
9397
9435
|
const http = new HttpClient(config.apiKey, {
|
|
9398
9436
|
url: config.url,
|
|
9399
9437
|
headers: { "X-Client-Info": `palbe-web/${VERSION}`, ...config.headers }
|