@binopartner/pay-sdk 0.1.0 → 0.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/README.md +3 -5
- package/dist/frame.js +5 -4
- package/dist/react.js +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/widget-url.d.ts +1 -0
- package/dist/widget-url.js +13 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,8 +24,6 @@ npm install
|
|
|
24
24
|
npm run build -w @binopartner/pay-sdk
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
Releases are published from CI, see [PUBLISHING.md](PUBLISHING.md).
|
|
28
|
-
|
|
29
27
|
## Your backend: the session endpoint
|
|
30
28
|
|
|
31
29
|
Your server creates a one-time widget session with the Broker API and returns the response unchanged. The SDK needs nothing else: no client secret and no Broker API token in the browser.
|
|
@@ -100,6 +98,7 @@ A session is created only when the widget opens and is dropped when it closes. U
|
|
|
100
98
|
| `onCredited` | `({ amount, asset }) => void` | | A deposit was credited. UI signal only, see Security. |
|
|
101
99
|
| `onStatusChange`, `onError` | | | See Status. |
|
|
102
100
|
| `requireChannel` | `boolean` | `false` | Refuse frames that do not prove the channel (no legacy fallback). |
|
|
101
|
+
| `allowedWidgetOrigins` | `string[]` | | Origins the widget may be served from, for example `["https://binodex.app"]`. A widget URL on any other origin is refused with `invalid_widget_url` and no iframe is created. An empty list refuses every widget. Not set: any https origin the session names is accepted. |
|
|
103
102
|
| `required` | `PayPart[]` | `[]` | Extra parts that must be present, on top of `frame`. |
|
|
104
103
|
|
|
105
104
|
## Parts
|
|
@@ -178,7 +177,8 @@ What is checked:
|
|
|
178
177
|
- Your page → widget: `init` is posted with an exact target origin, never `*`, so a widget frame navigated elsewhere never receives the session. The widget accepts `init` only from its parent window, only from an origin registered for your client, only with the exact expected fields and, with a channel, only with its own channel.
|
|
179
178
|
- Widget → your page: the SDK accepts a message only when it comes from its own iframe window, from the widget origin, has a known type with valid fields and, once the widget proved the channel, carries that channel. Another iframe, a popup or a second widget instance on the page cannot drive yours.
|
|
180
179
|
- Secrets: the SDK only ever hands the widget the one-time `wss_` session (single use, valid for 60 seconds, bound to the user, client and mode). The widget exchanges it for a short-lived token inside the iframe.
|
|
181
|
-
- `widget_url` must be https (plain http only on loopback hosts), must not carry credentials and must match `widget_origin`. Take it from the Broker API response only, never from user input.
|
|
180
|
+
- `widget_url` must be https (plain http only on loopback hosts), must not carry credentials and must match `widget_origin`. Take it from the Broker API response only, never from user input. Set `allowedWidgetOrigins` to pin the widget to the Binodex origins you expect: if your session route ever returns a foreign `widget_url`, the SDK refuses it and never hands the session to that origin. The session response can name a regional widget host, so list every Binodex widget origin you expect.
|
|
181
|
+
- The iframe permissions (`payment`, `clipboard-write`) are granted to the widget origin only, not to every origin.
|
|
182
182
|
- The iframe is created with `referrerpolicy="origin"`: the widget learns your origin to verify it, never your page path.
|
|
183
183
|
|
|
184
184
|
Out of scope, and how to handle it:
|
|
@@ -194,5 +194,3 @@ npm run build -w @binopartner/pay-sdk # ESM + .d.ts into dist/
|
|
|
194
194
|
npm run typecheck -w @binopartner/pay-sdk
|
|
195
195
|
npm test -w @binopartner/pay-sdk # vitest + jsdom
|
|
196
196
|
```
|
|
197
|
-
|
|
198
|
-
Releases go out through the `Publish pay-sdk` GitHub Actions workflow, see [PUBLISHING.md](PUBLISHING.md).
|
package/dist/frame.js
CHANGED
|
@@ -4,7 +4,7 @@ import { initMessage, readWidgetMessage, } from "./protocol.js";
|
|
|
4
4
|
import { holdSession, requestSession } from "./session.js";
|
|
5
5
|
import { resolveWidgetLocation } from "./widget-url.js";
|
|
6
6
|
const DEFAULT_HEIGHTS = { initial: 720, min: 520, max: 900 };
|
|
7
|
-
const
|
|
7
|
+
const FRAME_FEATURES = ["payment", "clipboard-write"];
|
|
8
8
|
const finiteSize = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0
|
|
9
9
|
? value
|
|
10
10
|
: null;
|
|
@@ -17,10 +17,10 @@ export const heightBounds = (options) => {
|
|
|
17
17
|
const initial = fit(finiteSize(options.initialHeight) ?? DEFAULT_HEIGHTS.initial, min, max);
|
|
18
18
|
return { initial, min, max };
|
|
19
19
|
};
|
|
20
|
-
const createFrame = (src, title, height) => {
|
|
20
|
+
const createFrame = (src, origin, title, height) => {
|
|
21
21
|
const frame = document.createElement("iframe");
|
|
22
22
|
frame.setAttribute("title", title);
|
|
23
|
-
frame.setAttribute("allow",
|
|
23
|
+
frame.setAttribute("allow", FRAME_FEATURES.map((feature) => `${feature} ${origin}`).join("; "));
|
|
24
24
|
frame.setAttribute("referrerpolicy", "origin");
|
|
25
25
|
frame.style.display = "block";
|
|
26
26
|
frame.style.width = "100%";
|
|
@@ -152,13 +152,14 @@ export const runPayFrame = (container, options, events) => {
|
|
|
152
152
|
platformUrl: options.platformUrl,
|
|
153
153
|
lang: options.lang,
|
|
154
154
|
theme: options.theme,
|
|
155
|
+
allowedOrigins: options.allowedWidgetOrigins,
|
|
155
156
|
});
|
|
156
157
|
if (!location) {
|
|
157
158
|
throw new PaySdkError("invalid_widget_url", "The widget session has no usable widget URL");
|
|
158
159
|
}
|
|
159
160
|
held = holdSession(session, Date.now());
|
|
160
161
|
widgetOrigin = location.origin;
|
|
161
|
-
frame = createFrame(location.src, options.title || (options.mode === "withdraw" ? "Withdraw" : "Deposit"), bounds.initial);
|
|
162
|
+
frame = createFrame(location.src, location.origin, options.title || (options.mode === "withdraw" ? "Withdraw" : "Deposit"), bounds.initial);
|
|
162
163
|
frame.addEventListener("load", onLoad);
|
|
163
164
|
window.addEventListener("message", onMessage);
|
|
164
165
|
setStatus("loading");
|
package/dist/react.js
CHANGED
package/dist/types.d.ts
CHANGED
package/dist/widget-url.d.ts
CHANGED
package/dist/widget-url.js
CHANGED
|
@@ -10,6 +10,15 @@ const fallbackUrl = ({ mode, clientId, platformUrl, }) => {
|
|
|
10
10
|
};
|
|
11
11
|
const isTransportAllowed = (url) => url.protocol === "https:" ||
|
|
12
12
|
(url.protocol === "http:" && LOOPBACK_HOST.test(url.hostname));
|
|
13
|
+
const normalizeOrigins = (entries) => entries.flatMap((entry) => {
|
|
14
|
+
try {
|
|
15
|
+
const url = new URL(entry);
|
|
16
|
+
return isTransportAllowed(url) ? [url.origin] : [];
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
13
22
|
export const resolveWidgetLocation = (input) => {
|
|
14
23
|
try {
|
|
15
24
|
const base = input.session.widget_url || fallbackUrl(input);
|
|
@@ -21,6 +30,10 @@ export const resolveWidgetLocation = (input) => {
|
|
|
21
30
|
const declaredOrigin = input.session.widget_origin;
|
|
22
31
|
if (declaredOrigin && declaredOrigin !== url.origin)
|
|
23
32
|
return null;
|
|
33
|
+
if (input.allowedOrigins &&
|
|
34
|
+
!normalizeOrigins(input.allowedOrigins).includes(url.origin)) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
24
37
|
if (input.lang && LANG_PATTERN.test(input.lang)) {
|
|
25
38
|
url.searchParams.set("lang", input.lang);
|
|
26
39
|
}
|