@palbase/web 7.3.4 → 7.3.5
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-PYJ3CMA2.js → chunk-2VURERR2.js} +3 -3
- package/dist/{chunk-PYJ3CMA2.js.map → chunk-2VURERR2.js.map} +1 -1
- 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/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 +48 -6
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.js +2 -2
- package/dist/next/client.cjs +48 -6
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +2 -2
- package/dist/next/index.cjs +48 -6
- 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 +1 -1
- package/dist/chunk-RAP37ILS.js.map +0 -1
- /package/dist/{chunk-IVD6BP5Z.js.map → chunk-HT5SNA5H.js.map} +0 -0
package/dist/next/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
importNextServer
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-HT5SNA5H.js";
|
|
4
4
|
import {
|
|
5
5
|
SESSION_COOKIE_ATTRS,
|
|
6
6
|
clearedSessionCookieNames,
|
|
@@ -14,10 +14,10 @@ import {
|
|
|
14
14
|
buildRuntime,
|
|
15
15
|
createBoundClient,
|
|
16
16
|
getRuntime
|
|
17
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-2VURERR2.js";
|
|
18
18
|
import {
|
|
19
19
|
BackendError
|
|
20
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-6DGCUHSO.js";
|
|
21
21
|
import {
|
|
22
22
|
environmentRefFromApiKey,
|
|
23
23
|
environmentRefFromPublishableApiKey
|
package/dist/next/proxy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
importNextServer
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-HT5SNA5H.js";
|
|
4
4
|
import {
|
|
5
5
|
SESSION_COOKIE_ATTRS,
|
|
6
6
|
clearedSessionCookieNames,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from "../chunk-6VGKMNXO.js";
|
|
10
10
|
import {
|
|
11
11
|
BackendError
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-6DGCUHSO.js";
|
|
13
13
|
import {
|
|
14
14
|
environmentRefFromPublishableApiKey
|
|
15
15
|
} from "../chunk-CFDU23TB.js";
|
package/dist/react/index.cjs
CHANGED
|
@@ -63,6 +63,28 @@ function asPowChallenge(details) {
|
|
|
63
63
|
return { id, prefix, difficulty };
|
|
64
64
|
}
|
|
65
65
|
var encoder = new TextEncoder();
|
|
66
|
+
var hasher = null;
|
|
67
|
+
async function digester() {
|
|
68
|
+
if (hasher) return hasher;
|
|
69
|
+
const runtime = globalThis;
|
|
70
|
+
const nodeish = runtime.process?.versions?.node !== void 0 || runtime.process?.versions?.bun !== void 0;
|
|
71
|
+
if (nodeish) {
|
|
72
|
+
try {
|
|
73
|
+
const mod = await import(
|
|
74
|
+
/* @vite-ignore */
|
|
75
|
+
`${"node:"}crypto`
|
|
76
|
+
);
|
|
77
|
+
if (typeof mod.createHash === "function") {
|
|
78
|
+
const createHash = mod.createHash;
|
|
79
|
+
hasher = (input) => new Uint8Array(createHash("sha256").update(input).digest());
|
|
80
|
+
return hasher;
|
|
81
|
+
}
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
hasher = async (input) => new Uint8Array(await crypto.subtle.digest("SHA-256", encoder.encode(input)));
|
|
86
|
+
return hasher;
|
|
87
|
+
}
|
|
66
88
|
var now = () => typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
|
|
67
89
|
function leadingZeroBits(hash) {
|
|
68
90
|
let bits = 0;
|
|
@@ -79,14 +101,19 @@ var MAX_POW_DIFFICULTY = 24;
|
|
|
79
101
|
function powBudget(difficulty) {
|
|
80
102
|
return 8 * 2 ** difficulty;
|
|
81
103
|
}
|
|
82
|
-
var
|
|
104
|
+
var POW_TIME_BUDGET_MS = 12e4;
|
|
105
|
+
var CALIBRATION_WARMUP = 1024;
|
|
106
|
+
var CALIBRATION_END = 9216;
|
|
83
107
|
async function solvePowChallenge(challenge, maxIterations = powBudget(challenge.difficulty), signal) {
|
|
84
108
|
if (challenge.difficulty > MAX_POW_DIFFICULTY) {
|
|
85
109
|
throw new Error(
|
|
86
110
|
`proof-of-work: refusing difficulty ${challenge.difficulty}; this client attempts at most ${MAX_POW_DIFFICULTY}, which is the highest a Palbase stack issues`
|
|
87
111
|
);
|
|
88
112
|
}
|
|
89
|
-
const
|
|
113
|
+
const digest = await digester();
|
|
114
|
+
let warmedAt = 0;
|
|
115
|
+
let calibrated = false;
|
|
116
|
+
let deadline = Number.POSITIVE_INFINITY;
|
|
90
117
|
for (let nonce = 0; nonce < maxIterations; nonce++) {
|
|
91
118
|
if ((nonce & 1023) === 0) {
|
|
92
119
|
if (signal?.aborted) {
|
|
@@ -94,12 +121,27 @@ async function solvePowChallenge(challenge, maxIterations = powBudget(challenge.
|
|
|
94
121
|
}
|
|
95
122
|
if (now() > deadline) {
|
|
96
123
|
throw new Error(
|
|
97
|
-
`proof-of-work: gave up after ${
|
|
124
|
+
`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`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (nonce === CALIBRATION_WARMUP) {
|
|
129
|
+
warmedAt = now();
|
|
130
|
+
}
|
|
131
|
+
if (!calibrated && nonce === CALIBRATION_END) {
|
|
132
|
+
calibrated = true;
|
|
133
|
+
const elapsed = Math.max(now() - warmedAt, 1e-3);
|
|
134
|
+
const rate = (CALIBRATION_END - CALIBRATION_WARMUP) / (elapsed / 1e3);
|
|
135
|
+
const expectedMs = 2 ** challenge.difficulty / rate * 1e3;
|
|
136
|
+
if (expectedMs > POW_TIME_BUDGET_MS) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
`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`
|
|
98
139
|
);
|
|
99
140
|
}
|
|
141
|
+
deadline = now() + (POW_TIME_BUDGET_MS - (now() - warmedAt));
|
|
100
142
|
}
|
|
101
|
-
const
|
|
102
|
-
if (leadingZeroBits(
|
|
143
|
+
const hash = await digest(challenge.prefix + nonce);
|
|
144
|
+
if (leadingZeroBits(hash) >= challenge.difficulty) {
|
|
103
145
|
return {
|
|
104
146
|
[POW_CHALLENGE_ID_HEADER]: challenge.id,
|
|
105
147
|
[POW_NONCE_HEADER]: String(nonce)
|
|
@@ -424,7 +466,7 @@ function applyBrowserOriginHeader(headers) {
|
|
|
424
466
|
}
|
|
425
467
|
|
|
426
468
|
// src/version.ts
|
|
427
|
-
var VERSION = "7.3.
|
|
469
|
+
var VERSION = "7.3.5";
|
|
428
470
|
|
|
429
471
|
// src/call.ts
|
|
430
472
|
async function callEndpoint(resolveRt, name, input, options) {
|