@invonetwork/web-sdk 2.1.0 → 2.1.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/CHANGELOG.md +20 -0
- package/README.md +2 -2
- package/dist/{chunk-YCEW7NC3.js → chunk-4GNJIQY2.js} +19 -5
- package/dist/index.cjs +29 -5
- package/dist/index.js +14 -4
- package/dist/server.cjs +25 -5
- package/dist/server.js +11 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,26 @@ All notable changes to `@invonetwork/web-sdk` are documented here. This project
|
|
|
4
4
|
[Semantic Versioning](https://semver.org/). Releases are managed with
|
|
5
5
|
[changesets](https://github.com/changesets/changesets).
|
|
6
6
|
|
|
7
|
+
## [2.1.1] — 2026-07-06
|
|
8
|
+
|
|
9
|
+
**Security & correctness hardening** from a full audit + red-team of both SDKs. No API changes;
|
|
10
|
+
upgrade recommended.
|
|
11
|
+
|
|
12
|
+
- **Fail closed on HTTP redirects (security).** The transport now sends `redirect:"manual"` and
|
|
13
|
+
throws `UNEXPECTED_REDIRECT` on any 3xx instead of following it. Previously a redirect from
|
|
14
|
+
the API host could cause the game-secret header to be re-sent to an unvalidated URL (matches
|
|
15
|
+
the Python SDK fix, where the leak also covered the player token and an `http://` downgrade).
|
|
16
|
+
- **`retryAfter` no longer treats a blank `retry_after` as `0`.** An empty/whitespace
|
|
17
|
+
`retry_after` string used to become `0` (`Number("")===0`) — an immediate, no-backoff retry.
|
|
18
|
+
It's now correctly `undefined`, in both `InvoError.retryAfter` and the retry layer.
|
|
19
|
+
- **Whitespace OTP codes rejected client-side.** `recoveryComplete`/`enrollmentVerify` now
|
|
20
|
+
reject a whitespace-only `code` before the network call, so it can't burn an attempt against
|
|
21
|
+
the attempt-capped endpoints (parity with the Python SDK).
|
|
22
|
+
- **Webhook verify uses `crypto.timingSafeEqual`** on the sync path (parity with Python's
|
|
23
|
+
`hmac.compare_digest`); the runtime-agnostic async/edge path keeps its string compare.
|
|
24
|
+
- **WebAuthn option mappers fail cleanly.** A malformed `register/begin` body now throws
|
|
25
|
+
`WEBAUTHN_OPTIONS_MALFORMED` (an `InvoError`) instead of a raw `TypeError`.
|
|
26
|
+
|
|
7
27
|
## [2.1.0] — 2026-07-02
|
|
8
28
|
|
|
9
29
|
**Passkey recovery ("lost or replaced my passkey").** Deleting a passkey on the device never
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
First-party TypeScript SDK for integrating **INVO** into partner **web** platforms (storefronts, web games, dashboards). It wraps INVO's web money flows behind a typed, versioned API — the web analog of the Unity/Unreal plugins.
|
|
4
4
|
|
|
5
|
-
> **Status:** `v2.1.
|
|
5
|
+
> **Status:** `v2.1.1` — stable, published on npm. The backend it wraps is **live** on sandbox + production. The API is covered by a [stability commitment](#stability): no breaking changes without a major bump. **Since 2.0.0 (breaking):** `mintPlayerToken` requires `playerPhone` (E.164) — see the [CHANGELOG](CHANGELOG.md) migration note. **2.1.0 adds** self-serve passkey recovery (`recoveryBegin`/`recoveryComplete`); **2.1.1** is a security/correctness hardening patch.
|
|
6
6
|
> Canonical partner reference: **https://docs.invo.network/docs/currency-purchase** and **https://docs.invo.network/docs/game-developer-integration**.
|
|
7
7
|
|
|
8
8
|
## What it does
|
|
@@ -636,7 +636,7 @@ npm test # vitest
|
|
|
636
636
|
|
|
637
637
|
### Stability
|
|
638
638
|
|
|
639
|
-
|
|
639
|
+
Since **`1.0.0`** the public API is **stable**: it follows [semver](https://semver.org/), and **no breaking change ships without a major version bump + a migration note** (the `2.0.0` `playerPhone` requirement is the one such change to date). Patch = fixes, minor = additive surface (new methods/fields, backward-compatible — e.g. `2.1.0`'s passkey recovery), major = breaking changes (rare). The wire contract is the same live INVO API you'd call directly, and it's backward-compatible within a major — so a pinned SDK keeps working. Safe to depend on in production; pin a version and watch [releases](https://github.com/Invo-Technologies/invo-web-sdk/releases) for security updates.
|
|
640
640
|
|
|
641
641
|
Full history: [CHANGELOG](https://github.com/Invo-Technologies/invo-web-sdk/blob/main/CHANGELOG.md) · [release notes](https://github.com/Invo-Technologies/invo-web-sdk/blob/main/docs/RELEASES.md) (absolute links to `main`).
|
|
642
642
|
|
|
@@ -88,7 +88,7 @@ var InvoError = class _InvoError extends Error {
|
|
|
88
88
|
/** Seconds to wait before retrying, when the backend throttled the call (429 `retry_after`). */
|
|
89
89
|
get retryAfter() {
|
|
90
90
|
const v = this.bodyObject()["retry_after"];
|
|
91
|
-
const n = typeof v === "string" ? Number(v) : v;
|
|
91
|
+
const n = typeof v === "string" ? v.trim() === "" ? NaN : Number(v) : v;
|
|
92
92
|
return typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : void 0;
|
|
93
93
|
}
|
|
94
94
|
/** `body` as a plain object, or `{}` if it's a string/number/null (non-JSON responses).
|
|
@@ -191,7 +191,13 @@ var _Http = class _Http {
|
|
|
191
191
|
let res;
|
|
192
192
|
let networkError;
|
|
193
193
|
try {
|
|
194
|
-
res = await this.fetchImpl(url, {
|
|
194
|
+
res = await this.fetchImpl(url, {
|
|
195
|
+
method,
|
|
196
|
+
headers,
|
|
197
|
+
body: payload,
|
|
198
|
+
signal: controller.signal,
|
|
199
|
+
redirect: "manual"
|
|
200
|
+
});
|
|
195
201
|
} catch (err) {
|
|
196
202
|
networkError = new InvoError({
|
|
197
203
|
message: err instanceof Error && err.name === "AbortError" ? `Request to ${path} timed out after ${this.timeoutMs}ms` : `Network error calling ${path}: ${err?.message ?? err}`,
|
|
@@ -212,6 +218,14 @@ var _Http = class _Http {
|
|
|
212
218
|
}
|
|
213
219
|
throw networkError;
|
|
214
220
|
}
|
|
221
|
+
if (res.type === "opaqueredirect" || res.status >= 300 && res.status < 400) {
|
|
222
|
+
throw new InvoError({
|
|
223
|
+
message: `Refused to follow a redirect from ${path} \u2014 credentials are never re-sent to a redirected URL.`,
|
|
224
|
+
code: "UNEXPECTED_REDIRECT",
|
|
225
|
+
status: res.status || 0,
|
|
226
|
+
body: null
|
|
227
|
+
});
|
|
228
|
+
}
|
|
215
229
|
const requestId = pickRequestId(res.headers);
|
|
216
230
|
const text = await res.text();
|
|
217
231
|
let parsed = null;
|
|
@@ -292,7 +306,7 @@ function pickRequestId(headers) {
|
|
|
292
306
|
function retryAfterMs(parsed, headers) {
|
|
293
307
|
if (parsed && typeof parsed === "object") {
|
|
294
308
|
const v = parsed["retry_after"];
|
|
295
|
-
const n = typeof v === "string" ? Number(v) : v;
|
|
309
|
+
const n = typeof v === "string" ? v.trim() === "" ? NaN : Number(v) : v;
|
|
296
310
|
if (typeof n === "number" && Number.isFinite(n) && n >= 0) return n * 1e3;
|
|
297
311
|
}
|
|
298
312
|
const header = headers && typeof headers.get === "function" ? headers.get("retry-after") : null;
|
|
@@ -347,5 +361,5 @@ function toDestinationsResult(raw, direction) {
|
|
|
347
361
|
}
|
|
348
362
|
|
|
349
363
|
export { Http, InvoError, assertSecureBaseUrl, toDestinationsResult };
|
|
350
|
-
//# sourceMappingURL=chunk-
|
|
351
|
-
//# sourceMappingURL=chunk-
|
|
364
|
+
//# sourceMappingURL=chunk-4GNJIQY2.js.map
|
|
365
|
+
//# sourceMappingURL=chunk-4GNJIQY2.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -90,7 +90,7 @@ var InvoError = class _InvoError extends Error {
|
|
|
90
90
|
/** Seconds to wait before retrying, when the backend throttled the call (429 `retry_after`). */
|
|
91
91
|
get retryAfter() {
|
|
92
92
|
const v = this.bodyObject()["retry_after"];
|
|
93
|
-
const n = typeof v === "string" ? Number(v) : v;
|
|
93
|
+
const n = typeof v === "string" ? v.trim() === "" ? NaN : Number(v) : v;
|
|
94
94
|
return typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : void 0;
|
|
95
95
|
}
|
|
96
96
|
/** `body` as a plain object, or `{}` if it's a string/number/null (non-JSON responses).
|
|
@@ -193,7 +193,13 @@ var _Http = class _Http {
|
|
|
193
193
|
let res;
|
|
194
194
|
let networkError;
|
|
195
195
|
try {
|
|
196
|
-
res = await this.fetchImpl(url, {
|
|
196
|
+
res = await this.fetchImpl(url, {
|
|
197
|
+
method,
|
|
198
|
+
headers,
|
|
199
|
+
body: payload,
|
|
200
|
+
signal: controller.signal,
|
|
201
|
+
redirect: "manual"
|
|
202
|
+
});
|
|
197
203
|
} catch (err) {
|
|
198
204
|
networkError = new InvoError({
|
|
199
205
|
message: err instanceof Error && err.name === "AbortError" ? `Request to ${path} timed out after ${this.timeoutMs}ms` : `Network error calling ${path}: ${err?.message ?? err}`,
|
|
@@ -214,6 +220,14 @@ var _Http = class _Http {
|
|
|
214
220
|
}
|
|
215
221
|
throw networkError;
|
|
216
222
|
}
|
|
223
|
+
if (res.type === "opaqueredirect" || res.status >= 300 && res.status < 400) {
|
|
224
|
+
throw new InvoError({
|
|
225
|
+
message: `Refused to follow a redirect from ${path} \u2014 credentials are never re-sent to a redirected URL.`,
|
|
226
|
+
code: "UNEXPECTED_REDIRECT",
|
|
227
|
+
status: res.status || 0,
|
|
228
|
+
body: null
|
|
229
|
+
});
|
|
230
|
+
}
|
|
217
231
|
const requestId = pickRequestId(res.headers);
|
|
218
232
|
const text = await res.text();
|
|
219
233
|
let parsed = null;
|
|
@@ -294,7 +308,7 @@ function pickRequestId(headers) {
|
|
|
294
308
|
function retryAfterMs(parsed, headers) {
|
|
295
309
|
if (parsed && typeof parsed === "object") {
|
|
296
310
|
const v = parsed["retry_after"];
|
|
297
|
-
const n = typeof v === "string" ? Number(v) : v;
|
|
311
|
+
const n = typeof v === "string" ? v.trim() === "" ? NaN : Number(v) : v;
|
|
298
312
|
if (typeof n === "number" && Number.isFinite(n) && n >= 0) return n * 1e3;
|
|
299
313
|
}
|
|
300
314
|
const header = headers && typeof headers.get === "function" ? headers.get("retry-after") : null;
|
|
@@ -306,6 +320,13 @@ function retryAfterMs(parsed, headers) {
|
|
|
306
320
|
}
|
|
307
321
|
|
|
308
322
|
// src/shared/webauthn.ts
|
|
323
|
+
function malformedOptions(field) {
|
|
324
|
+
return new InvoError({
|
|
325
|
+
message: `Malformed WebAuthn options from the backend: missing/invalid \`${field}\`.`,
|
|
326
|
+
code: "WEBAUTHN_OPTIONS_MALFORMED",
|
|
327
|
+
status: 0
|
|
328
|
+
});
|
|
329
|
+
}
|
|
309
330
|
function b64urlToBuffer(value) {
|
|
310
331
|
const pad = value.length % 4 === 0 ? "" : "=".repeat(4 - value.length % 4);
|
|
311
332
|
const b64 = value.replace(/-/g, "+").replace(/_/g, "/") + pad;
|
|
@@ -331,6 +352,8 @@ function descriptorsToBinary(list) {
|
|
|
331
352
|
});
|
|
332
353
|
}
|
|
333
354
|
function toCreationOptions(json) {
|
|
355
|
+
if (typeof json?.["challenge"] !== "string") throw malformedOptions("challenge");
|
|
356
|
+
if (typeof json["user"]?.id !== "string") throw malformedOptions("user.id");
|
|
334
357
|
const opts = {
|
|
335
358
|
...json,
|
|
336
359
|
challenge: b64urlToBuffer(json["challenge"]),
|
|
@@ -345,6 +368,7 @@ function toCreationOptions(json) {
|
|
|
345
368
|
return opts;
|
|
346
369
|
}
|
|
347
370
|
function toRequestOptions(json) {
|
|
371
|
+
if (typeof json?.["challenge"] !== "string") throw malformedOptions("challenge");
|
|
348
372
|
const opts = {
|
|
349
373
|
...json,
|
|
350
374
|
challenge: b64urlToBuffer(json["challenge"])
|
|
@@ -633,7 +657,7 @@ var InvoClient = class {
|
|
|
633
657
|
}
|
|
634
658
|
/** Verify the enrollment OTP (see {@link enrollmentBegin}); on success, retry `enrollPasskey()`. */
|
|
635
659
|
async enrollmentVerify(code, opts) {
|
|
636
|
-
if (!code) throw new Error("enrollmentVerify requires the OTP `code`.");
|
|
660
|
+
if (!code || !code.trim()) throw new Error("enrollmentVerify requires the OTP `code`.");
|
|
637
661
|
return this.withTokenRetry(async () => {
|
|
638
662
|
const raw = await this.post(
|
|
639
663
|
"/api/sdk/device/enrollment/verify",
|
|
@@ -687,7 +711,7 @@ var InvoClient = class {
|
|
|
687
711
|
}
|
|
688
712
|
/** Verify the recovery code (see {@link recoveryBegin}); on success, call `enrollPasskey()`. */
|
|
689
713
|
async recoveryComplete(code, opts) {
|
|
690
|
-
if (!code) throw new Error("recoveryComplete requires the one-time `code`.");
|
|
714
|
+
if (!code || !code.trim()) throw new Error("recoveryComplete requires the one-time `code`.");
|
|
691
715
|
return this.withTokenRetry(async () => {
|
|
692
716
|
const raw = await this.post(
|
|
693
717
|
"/api/sdk/device/recover/complete",
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import { assertSecureBaseUrl, Http, toDestinationsResult, InvoError } from './chunk-
|
|
2
|
-
export { InvoError } from './chunk-
|
|
1
|
+
import { assertSecureBaseUrl, Http, toDestinationsResult, InvoError } from './chunk-4GNJIQY2.js';
|
|
2
|
+
export { InvoError } from './chunk-4GNJIQY2.js';
|
|
3
3
|
|
|
4
4
|
// src/shared/webauthn.ts
|
|
5
|
+
function malformedOptions(field) {
|
|
6
|
+
return new InvoError({
|
|
7
|
+
message: `Malformed WebAuthn options from the backend: missing/invalid \`${field}\`.`,
|
|
8
|
+
code: "WEBAUTHN_OPTIONS_MALFORMED",
|
|
9
|
+
status: 0
|
|
10
|
+
});
|
|
11
|
+
}
|
|
5
12
|
function b64urlToBuffer(value) {
|
|
6
13
|
const pad = value.length % 4 === 0 ? "" : "=".repeat(4 - value.length % 4);
|
|
7
14
|
const b64 = value.replace(/-/g, "+").replace(/_/g, "/") + pad;
|
|
@@ -27,6 +34,8 @@ function descriptorsToBinary(list) {
|
|
|
27
34
|
});
|
|
28
35
|
}
|
|
29
36
|
function toCreationOptions(json) {
|
|
37
|
+
if (typeof json?.["challenge"] !== "string") throw malformedOptions("challenge");
|
|
38
|
+
if (typeof json["user"]?.id !== "string") throw malformedOptions("user.id");
|
|
30
39
|
const opts = {
|
|
31
40
|
...json,
|
|
32
41
|
challenge: b64urlToBuffer(json["challenge"]),
|
|
@@ -41,6 +50,7 @@ function toCreationOptions(json) {
|
|
|
41
50
|
return opts;
|
|
42
51
|
}
|
|
43
52
|
function toRequestOptions(json) {
|
|
53
|
+
if (typeof json?.["challenge"] !== "string") throw malformedOptions("challenge");
|
|
44
54
|
const opts = {
|
|
45
55
|
...json,
|
|
46
56
|
challenge: b64urlToBuffer(json["challenge"])
|
|
@@ -286,7 +296,7 @@ var InvoClient = class {
|
|
|
286
296
|
}
|
|
287
297
|
/** Verify the enrollment OTP (see {@link enrollmentBegin}); on success, retry `enrollPasskey()`. */
|
|
288
298
|
async enrollmentVerify(code, opts) {
|
|
289
|
-
if (!code) throw new Error("enrollmentVerify requires the OTP `code`.");
|
|
299
|
+
if (!code || !code.trim()) throw new Error("enrollmentVerify requires the OTP `code`.");
|
|
290
300
|
return this.withTokenRetry(async () => {
|
|
291
301
|
const raw = await this.post(
|
|
292
302
|
"/api/sdk/device/enrollment/verify",
|
|
@@ -340,7 +350,7 @@ var InvoClient = class {
|
|
|
340
350
|
}
|
|
341
351
|
/** Verify the recovery code (see {@link recoveryBegin}); on success, call `enrollPasskey()`. */
|
|
342
352
|
async recoveryComplete(code, opts) {
|
|
343
|
-
if (!code) throw new Error("recoveryComplete requires the one-time `code`.");
|
|
353
|
+
if (!code || !code.trim()) throw new Error("recoveryComplete requires the one-time `code`.");
|
|
344
354
|
return this.withTokenRetry(async () => {
|
|
345
355
|
const raw = await this.post(
|
|
346
356
|
"/api/sdk/device/recover/complete",
|
package/dist/server.cjs
CHANGED
|
@@ -92,7 +92,7 @@ var InvoError = class _InvoError extends Error {
|
|
|
92
92
|
/** Seconds to wait before retrying, when the backend throttled the call (429 `retry_after`). */
|
|
93
93
|
get retryAfter() {
|
|
94
94
|
const v = this.bodyObject()["retry_after"];
|
|
95
|
-
const n = typeof v === "string" ? Number(v) : v;
|
|
95
|
+
const n = typeof v === "string" ? v.trim() === "" ? NaN : Number(v) : v;
|
|
96
96
|
return typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : void 0;
|
|
97
97
|
}
|
|
98
98
|
/** `body` as a plain object, or `{}` if it's a string/number/null (non-JSON responses).
|
|
@@ -195,7 +195,13 @@ var _Http = class _Http {
|
|
|
195
195
|
let res;
|
|
196
196
|
let networkError;
|
|
197
197
|
try {
|
|
198
|
-
res = await this.fetchImpl(url, {
|
|
198
|
+
res = await this.fetchImpl(url, {
|
|
199
|
+
method,
|
|
200
|
+
headers,
|
|
201
|
+
body: payload,
|
|
202
|
+
signal: controller.signal,
|
|
203
|
+
redirect: "manual"
|
|
204
|
+
});
|
|
199
205
|
} catch (err) {
|
|
200
206
|
networkError = new InvoError({
|
|
201
207
|
message: err instanceof Error && err.name === "AbortError" ? `Request to ${path} timed out after ${this.timeoutMs}ms` : `Network error calling ${path}: ${err?.message ?? err}`,
|
|
@@ -216,6 +222,14 @@ var _Http = class _Http {
|
|
|
216
222
|
}
|
|
217
223
|
throw networkError;
|
|
218
224
|
}
|
|
225
|
+
if (res.type === "opaqueredirect" || res.status >= 300 && res.status < 400) {
|
|
226
|
+
throw new InvoError({
|
|
227
|
+
message: `Refused to follow a redirect from ${path} \u2014 credentials are never re-sent to a redirected URL.`,
|
|
228
|
+
code: "UNEXPECTED_REDIRECT",
|
|
229
|
+
status: res.status || 0,
|
|
230
|
+
body: null
|
|
231
|
+
});
|
|
232
|
+
}
|
|
219
233
|
const requestId = pickRequestId(res.headers);
|
|
220
234
|
const text = await res.text();
|
|
221
235
|
let parsed = null;
|
|
@@ -296,7 +310,7 @@ function pickRequestId(headers) {
|
|
|
296
310
|
function retryAfterMs(parsed, headers) {
|
|
297
311
|
if (parsed && typeof parsed === "object") {
|
|
298
312
|
const v = parsed["retry_after"];
|
|
299
|
-
const n = typeof v === "string" ? Number(v) : v;
|
|
313
|
+
const n = typeof v === "string" ? v.trim() === "" ? NaN : Number(v) : v;
|
|
300
314
|
if (typeof n === "number" && Number.isFinite(n) && n >= 0) return n * 1e3;
|
|
301
315
|
}
|
|
302
316
|
const header = headers && typeof headers.get === "function" ? headers.get("retry-after") : null;
|
|
@@ -379,6 +393,12 @@ function parseSignatureHeader(header) {
|
|
|
379
393
|
function hmacHex(secret, message) {
|
|
380
394
|
return crypto.createHmac("sha256", secret).update(message).digest("hex");
|
|
381
395
|
}
|
|
396
|
+
function safeEqualHexNode(a, b) {
|
|
397
|
+
const ba = Buffer.from(a, "utf8");
|
|
398
|
+
const bb = Buffer.from(b, "utf8");
|
|
399
|
+
if (ba.length !== bb.length) return false;
|
|
400
|
+
return crypto.timingSafeEqual(ba, bb);
|
|
401
|
+
}
|
|
382
402
|
function safeEqualHex(a, b) {
|
|
383
403
|
if (a.length !== b.length) return false;
|
|
384
404
|
let diff = 0;
|
|
@@ -431,7 +451,7 @@ function verifyWebhook(rawBody, signatureHeader, secret, opts = {}) {
|
|
|
431
451
|
);
|
|
432
452
|
const matched = secrets.some((s) => {
|
|
433
453
|
const expected = hmacHex(s, message);
|
|
434
|
-
return sigs.some((sig) =>
|
|
454
|
+
return sigs.some((sig) => safeEqualHexNode(sig, expected));
|
|
435
455
|
});
|
|
436
456
|
if (!matched) {
|
|
437
457
|
throw webhookError("Webhook signature verification failed.", "WEBHOOK_SIGNATURE_INVALID");
|
|
@@ -508,7 +528,7 @@ async function hmacHexSubtle(secret, message) {
|
|
|
508
528
|
}
|
|
509
529
|
|
|
510
530
|
// src/server.ts
|
|
511
|
-
var DEFAULT_UA = "invonetwork-web-sdk/2.1.
|
|
531
|
+
var DEFAULT_UA = "invonetwork-web-sdk/2.1.1 (+https://invo.network)";
|
|
512
532
|
var MAX_USD_AMOUNT = 999.99;
|
|
513
533
|
var MAX_ITEM_PRICE = 999999.99;
|
|
514
534
|
function invalidInput(label, value, why) {
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { InvoError, assertSecureBaseUrl, Http, toDestinationsResult } from './chunk-
|
|
2
|
-
export { InvoError } from './chunk-
|
|
3
|
-
import { createHmac } from 'crypto';
|
|
1
|
+
import { InvoError, assertSecureBaseUrl, Http, toDestinationsResult } from './chunk-4GNJIQY2.js';
|
|
2
|
+
export { InvoError } from './chunk-4GNJIQY2.js';
|
|
3
|
+
import { createHmac, timingSafeEqual } from 'crypto';
|
|
4
4
|
|
|
5
5
|
var DEFAULT_TOLERANCE_SEC = 300;
|
|
6
6
|
var ENCODER = new TextEncoder();
|
|
@@ -32,6 +32,12 @@ function parseSignatureHeader(header) {
|
|
|
32
32
|
function hmacHex(secret, message) {
|
|
33
33
|
return createHmac("sha256", secret).update(message).digest("hex");
|
|
34
34
|
}
|
|
35
|
+
function safeEqualHexNode(a, b) {
|
|
36
|
+
const ba = Buffer.from(a, "utf8");
|
|
37
|
+
const bb = Buffer.from(b, "utf8");
|
|
38
|
+
if (ba.length !== bb.length) return false;
|
|
39
|
+
return timingSafeEqual(ba, bb);
|
|
40
|
+
}
|
|
35
41
|
function safeEqualHex(a, b) {
|
|
36
42
|
if (a.length !== b.length) return false;
|
|
37
43
|
let diff = 0;
|
|
@@ -84,7 +90,7 @@ function verifyWebhook(rawBody, signatureHeader, secret, opts = {}) {
|
|
|
84
90
|
);
|
|
85
91
|
const matched = secrets.some((s) => {
|
|
86
92
|
const expected = hmacHex(s, message);
|
|
87
|
-
return sigs.some((sig) =>
|
|
93
|
+
return sigs.some((sig) => safeEqualHexNode(sig, expected));
|
|
88
94
|
});
|
|
89
95
|
if (!matched) {
|
|
90
96
|
throw webhookError("Webhook signature verification failed.", "WEBHOOK_SIGNATURE_INVALID");
|
|
@@ -161,7 +167,7 @@ async function hmacHexSubtle(secret, message) {
|
|
|
161
167
|
}
|
|
162
168
|
|
|
163
169
|
// src/server.ts
|
|
164
|
-
var DEFAULT_UA = "invonetwork-web-sdk/2.1.
|
|
170
|
+
var DEFAULT_UA = "invonetwork-web-sdk/2.1.1 (+https://invo.network)";
|
|
165
171
|
var MAX_USD_AMOUNT = 999.99;
|
|
166
172
|
var MAX_ITEM_PRICE = 999999.99;
|
|
167
173
|
function invalidInput(label, value, why) {
|
package/package.json
CHANGED