@zerohash-sdk/travel-rule-react 0.2.1 → 0.2.2
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/index.d.ts +8 -0
- package/dist/index.js +92 -81
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -114,6 +114,14 @@ declare interface TravelRuleProps {
|
|
|
114
114
|
* @example "deposit-abc123"
|
|
115
115
|
*/
|
|
116
116
|
depositId: string;
|
|
117
|
+
/**
|
|
118
|
+
* Wallet address the travel-rule submission relates to. Optional —
|
|
119
|
+
* carried alongside `depositId` when known. Init-only: post-mount changes are
|
|
120
|
+
* ignored, matching the behaviour of `depositId` / `env`.
|
|
121
|
+
*
|
|
122
|
+
* @example "0xabc123..."
|
|
123
|
+
*/
|
|
124
|
+
walletAddress?: string;
|
|
117
125
|
/**
|
|
118
126
|
* Target environment for the Zerohash Travel Rule service.
|
|
119
127
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsxs as W, jsx as
|
|
2
|
-
import j, { useEffect as
|
|
1
|
+
import { jsxs as W, jsx as y } from "react/jsx-runtime";
|
|
2
|
+
import j, { useEffect as U, useState as z, useCallback as D, useRef as M } from "react";
|
|
3
3
|
const $ = {
|
|
4
4
|
dev: "https://grafana-faro-collector.dev.0hash.com/collect",
|
|
5
5
|
cert: "https://grafana-faro-collector.cert.zerohash.com/collect",
|
|
@@ -15,48 +15,48 @@ const $ = {
|
|
|
15
15
|
if (t.length < 2)
|
|
16
16
|
return null;
|
|
17
17
|
try {
|
|
18
|
-
const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), r = o + "===".slice(0, (4 - o.length % 4) % 4),
|
|
18
|
+
const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), r = o + "===".slice(0, (4 - o.length % 4) % 4), n = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), c = JSON.parse(n)?.payload?.region;
|
|
19
19
|
if (typeof c != "string")
|
|
20
20
|
return null;
|
|
21
|
-
const
|
|
22
|
-
return
|
|
21
|
+
const a = c.toLowerCase();
|
|
22
|
+
return a === "us" || a === "eu" ? a : null;
|
|
23
23
|
} catch {
|
|
24
24
|
return null;
|
|
25
25
|
}
|
|
26
|
-
},
|
|
26
|
+
}, A = (e, t) => V(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, P = (e) => {
|
|
27
27
|
if (!e || typeof e != "string")
|
|
28
28
|
return {};
|
|
29
29
|
const t = e.split(".");
|
|
30
30
|
if (t.length < 2)
|
|
31
31
|
return {};
|
|
32
32
|
try {
|
|
33
|
-
const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), r = o + "===".slice(0, (4 - o.length % 4) % 4),
|
|
33
|
+
const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), r = o + "===".slice(0, (4 - o.length % 4) % 4), n = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), l = JSON.parse(n), c = l?.payload ?? {}, a = (s) => typeof s == "string" && s.length > 0 ? s : void 0;
|
|
34
34
|
return {
|
|
35
|
-
participantCode:
|
|
36
|
-
platformName:
|
|
37
|
-
platformCode:
|
|
38
|
-
region:
|
|
35
|
+
participantCode: a(c.participant_code),
|
|
36
|
+
platformName: a(c.platform_name),
|
|
37
|
+
platformCode: a(l.platform_code),
|
|
38
|
+
region: a(c.region)
|
|
39
39
|
};
|
|
40
40
|
} catch {
|
|
41
41
|
return {};
|
|
42
42
|
}
|
|
43
43
|
}, L = (e, t, o) => {
|
|
44
|
-
const r =
|
|
44
|
+
const r = A(t, o);
|
|
45
45
|
return e[r] ?? e[t] ?? e.prod;
|
|
46
46
|
}, J = (e, t, o) => {
|
|
47
|
-
const r =
|
|
47
|
+
const r = A(t, o);
|
|
48
48
|
return e[r] ?? e[t];
|
|
49
49
|
}, x = () => {
|
|
50
50
|
}, H = () => {
|
|
51
51
|
const e = new Uint8Array(8);
|
|
52
52
|
return globalThis.crypto.getRandomValues(e), Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
|
|
53
53
|
}, K = (e, t) => {
|
|
54
|
-
const o = H(), r = globalThis.__ZH_WEB_SDK_VERSION__,
|
|
55
|
-
e.claims.participantCode && (
|
|
54
|
+
const o = H(), r = globalThis.__ZH_WEB_SDK_VERSION__, n = {};
|
|
55
|
+
e.claims.participantCode && (n.participant_code = e.claims.participantCode), e.claims.platformName && (n.platform_name = e.claims.platformName), e.claims.platformCode && (n.platform_code = e.claims.platformCode), e.claims.region && (n.region = e.claims.region), r && (n.zh_web_sdk_version = r);
|
|
56
56
|
const l = {
|
|
57
57
|
meta: {
|
|
58
58
|
app: { name: e.appName, version: t ?? "unknown", environment: e.env },
|
|
59
|
-
session: { id: o, attributes:
|
|
59
|
+
session: { id: o, attributes: n },
|
|
60
60
|
browser: typeof navigator < "u" ? { userAgent: navigator.userAgent } : void 0,
|
|
61
61
|
page: typeof window < "u" ? { url: window.location.origin } : void 0
|
|
62
62
|
},
|
|
@@ -79,59 +79,59 @@ const $ = {
|
|
|
79
79
|
}, G = (e, t, o) => {
|
|
80
80
|
if (!e || typeof fetch > "u")
|
|
81
81
|
return;
|
|
82
|
-
const { sessionId: r, payload:
|
|
82
|
+
const { sessionId: r, payload: n } = K(t, o);
|
|
83
83
|
try {
|
|
84
84
|
fetch(e, {
|
|
85
85
|
method: "POST",
|
|
86
86
|
headers: { "Content-Type": "application/json", "x-faro-session-id": r },
|
|
87
|
-
body: JSON.stringify(
|
|
87
|
+
body: JSON.stringify(n),
|
|
88
88
|
keepalive: !0
|
|
89
89
|
}).catch(() => {
|
|
90
90
|
});
|
|
91
91
|
} catch {
|
|
92
92
|
}
|
|
93
93
|
}, Z = (e) => {
|
|
94
|
-
const { webComponentTag: t, appName: o, appVersion: r, scriptUrls:
|
|
94
|
+
const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: n, fallbackScriptUrls: l, collectorUrls: c, env: a, jwt: s, timeoutMs: g = 15e3, onLoad: _, onError: f } = e;
|
|
95
95
|
if (typeof document > "u")
|
|
96
96
|
return x;
|
|
97
|
-
const d = `${t}-script-${
|
|
97
|
+
const d = `${t}-script-${a}`;
|
|
98
98
|
if (customElements.get(t) || document.getElementById(d))
|
|
99
99
|
return x;
|
|
100
|
-
const
|
|
101
|
-
let
|
|
102
|
-
const
|
|
100
|
+
const b = P(s), v = e.report ?? ((p) => G(c && J(c, a, s), p, r));
|
|
101
|
+
let m = !1, E = 0, C;
|
|
102
|
+
const S = () => {
|
|
103
103
|
C !== void 0 && clearTimeout(C);
|
|
104
|
-
}, k = (p,
|
|
105
|
-
if (
|
|
104
|
+
}, k = (p, h, i) => {
|
|
105
|
+
if (m)
|
|
106
106
|
return;
|
|
107
|
-
const I = Math.round(performance.now() -
|
|
107
|
+
const I = Math.round(performance.now() - E), N = {
|
|
108
108
|
webComponentTag: t,
|
|
109
109
|
appName: o,
|
|
110
|
-
env:
|
|
111
|
-
scriptUrl:
|
|
110
|
+
env: a,
|
|
111
|
+
scriptUrl: h,
|
|
112
112
|
reason: p,
|
|
113
113
|
triedFallback: i,
|
|
114
114
|
elapsedMs: I,
|
|
115
|
-
claims:
|
|
115
|
+
claims: b
|
|
116
116
|
};
|
|
117
117
|
v(N);
|
|
118
|
-
const O = i ? void 0 : L(l ?? {},
|
|
119
|
-
if (O && O !==
|
|
120
|
-
|
|
118
|
+
const O = i ? void 0 : L(l ?? {}, a, s);
|
|
119
|
+
if (O && O !== h) {
|
|
120
|
+
T(O, !0);
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
|
-
|
|
124
|
-
},
|
|
125
|
-
|
|
123
|
+
m = !0, S(), document.getElementById(d)?.remove(), f?.(N);
|
|
124
|
+
}, T = (p, h) => {
|
|
125
|
+
S(), E = performance.now();
|
|
126
126
|
const i = document.createElement("script");
|
|
127
127
|
i.id = d, i.src = p, i.type = "module", i.async = !0, i.onload = () => {
|
|
128
128
|
setTimeout(() => {
|
|
129
|
-
|
|
129
|
+
m || (customElements.get(t) ? (m = !0, S(), _?.()) : k("not-defined", p, h));
|
|
130
130
|
}, 0);
|
|
131
|
-
}, i.onerror = () => k("network", p,
|
|
132
|
-
},
|
|
133
|
-
return
|
|
134
|
-
|
|
131
|
+
}, i.onerror = () => k("network", p, h), C = setTimeout(() => k("timeout", p, h), g), document.getElementById(d)?.remove(), document.head.appendChild(i);
|
|
132
|
+
}, w = L(n, a, s);
|
|
133
|
+
return w ? (T(w, !1), () => {
|
|
134
|
+
m = !0, S();
|
|
135
135
|
}) : x;
|
|
136
136
|
}, u = {
|
|
137
137
|
local: "http://localhost:5173",
|
|
@@ -141,19 +141,19 @@ const $ = {
|
|
|
141
141
|
"eu-cert": "https://sdk-cdn.cert.zerohash.eu",
|
|
142
142
|
"eu-prod": "https://sdk-cdn.zerohash.eu"
|
|
143
143
|
}, q = (e, t, o = {}) => {
|
|
144
|
-
const { eu: r = !1, legacyAliases:
|
|
144
|
+
const { eu: r = !1, legacyAliases: n = !1, local: l = u.local } = o, c = (s) => `${s}/${e}/${t}`, a = {
|
|
145
145
|
local: c(l),
|
|
146
146
|
dev: c(u.dev),
|
|
147
147
|
cert: c(u.cert),
|
|
148
148
|
prod: c(u.prod)
|
|
149
149
|
};
|
|
150
|
-
return
|
|
150
|
+
return n && (a.sandbox = c(u.cert), a.production = c(u.prod)), r && (a["eu-cert"] = c(u["eu-cert"]), a["eu-prod"] = c(u["eu-prod"])), a;
|
|
151
151
|
};
|
|
152
152
|
var F;
|
|
153
153
|
(function(e) {
|
|
154
154
|
e.NETWORK_ERROR = "network_error", e.AUTH_ERROR = "auth_error", e.NOT_FOUND_ERROR = "not_found_error", e.VALIDATION_ERROR = "validation_error", e.SERVER_ERROR = "server_error", e.CLIENT_ERROR = "client_error", e.UNKNOWN_ERROR = "unknown_error";
|
|
155
155
|
})(F || (F = {}));
|
|
156
|
-
const
|
|
156
|
+
const R = {
|
|
157
157
|
evergreen: "#00381D",
|
|
158
158
|
green: "#CCFFD0",
|
|
159
159
|
offBlack: "#1C1B1C",
|
|
@@ -168,86 +168,97 @@ const b = {
|
|
|
168
168
|
padding: "32px 24px",
|
|
169
169
|
textAlign: "center",
|
|
170
170
|
fontFamily: "inherit",
|
|
171
|
-
color:
|
|
171
|
+
color: R.offBlack,
|
|
172
172
|
background: "#FFFFFF",
|
|
173
|
-
border: `1px solid ${
|
|
173
|
+
border: `1px solid ${R.grayLight}`,
|
|
174
174
|
borderRadius: "12px"
|
|
175
|
-
}, children: [
|
|
175
|
+
}, children: [y("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: y("path", { d: "M12 9v4m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z", stroke: R.evergreen, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }), y("p", { style: { margin: 0, fontSize: "16px", fontWeight: 600 }, children: "Something went wrong" }), y("p", { style: { margin: 0, fontSize: "14px", opacity: 0.75 }, children: "We couldn't load this content. Please check your internet connection and try again." }), y("button", { type: "button", onClick: e, style: {
|
|
176
176
|
marginTop: "8px",
|
|
177
177
|
padding: "8px 20px",
|
|
178
178
|
fontSize: "14px",
|
|
179
179
|
fontWeight: 600,
|
|
180
180
|
fontFamily: "inherit",
|
|
181
|
-
color:
|
|
182
|
-
background:
|
|
181
|
+
color: R.green,
|
|
182
|
+
background: R.evergreen,
|
|
183
183
|
border: "none",
|
|
184
184
|
borderRadius: "8px",
|
|
185
185
|
cursor: "pointer"
|
|
186
186
|
}, children: "Try again" })] }), X = (e, t) => {
|
|
187
|
-
|
|
187
|
+
U(() => {
|
|
188
188
|
const o = e.current;
|
|
189
189
|
if (o)
|
|
190
|
-
for (const [r,
|
|
191
|
-
|
|
190
|
+
for (const [r, n] of Object.entries(t))
|
|
191
|
+
n !== void 0 && (o[r] = n);
|
|
192
192
|
});
|
|
193
193
|
}, Y = (e) => {
|
|
194
|
-
const { webComponentTag: t, appName: o, appVersion: r, scriptUrls:
|
|
195
|
-
|
|
194
|
+
const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: n, fallbackScriptUrls: l, collectorUrls: c, env: a, jwt: s, timeoutMs: g } = e, [_, f] = z(!1), [d, b] = z(0);
|
|
195
|
+
U(() => (f(!1), Z({
|
|
196
196
|
webComponentTag: t,
|
|
197
197
|
appName: o ?? t,
|
|
198
198
|
appVersion: r,
|
|
199
|
-
scriptUrls:
|
|
199
|
+
scriptUrls: n,
|
|
200
200
|
fallbackScriptUrls: l,
|
|
201
201
|
collectorUrls: c ?? $,
|
|
202
|
-
env:
|
|
202
|
+
env: a,
|
|
203
203
|
jwt: s,
|
|
204
|
-
timeoutMs:
|
|
205
|
-
onError: () =>
|
|
204
|
+
timeoutMs: g,
|
|
205
|
+
onError: () => f(!0)
|
|
206
206
|
})), [
|
|
207
207
|
t,
|
|
208
208
|
o,
|
|
209
209
|
r,
|
|
210
|
-
|
|
210
|
+
n,
|
|
211
211
|
l,
|
|
212
212
|
c,
|
|
213
|
-
|
|
213
|
+
a,
|
|
214
214
|
s,
|
|
215
|
-
|
|
215
|
+
g,
|
|
216
216
|
d
|
|
217
217
|
]);
|
|
218
|
-
const v = D(() =>
|
|
219
|
-
return { loadFailed:
|
|
220
|
-
}, ee = q("travel-rule-web", "index.js", { eu: !0 }),
|
|
218
|
+
const v = D(() => b((m) => m + 1), []);
|
|
219
|
+
return { loadFailed: _, retry: v };
|
|
220
|
+
}, ee = q("travel-rule-web", "index.js", { eu: !0 }), B = "zerohash-travel-rule", re = ({
|
|
221
221
|
jwt: e,
|
|
222
222
|
depositId: t,
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
223
|
+
walletAddress: o,
|
|
224
|
+
env: r = "prod",
|
|
225
|
+
theme: n,
|
|
226
|
+
onCompleted: l,
|
|
227
|
+
onError: c,
|
|
228
|
+
onClose: a,
|
|
229
|
+
onLoaded: s,
|
|
230
|
+
onEvent: g,
|
|
231
|
+
..._
|
|
231
232
|
}) => {
|
|
232
|
-
const
|
|
233
|
-
X(
|
|
234
|
-
|
|
235
|
-
|
|
233
|
+
const f = M(null);
|
|
234
|
+
X(f, {
|
|
235
|
+
theme: n,
|
|
236
|
+
depositId: t,
|
|
237
|
+
walletAddress: o,
|
|
238
|
+
onCompleted: l,
|
|
239
|
+
onError: c,
|
|
240
|
+
onClose: a,
|
|
241
|
+
onLoaded: s,
|
|
242
|
+
onEvent: g
|
|
243
|
+
});
|
|
244
|
+
const { loadFailed: d, retry: b } = Y({
|
|
245
|
+
webComponentTag: B,
|
|
236
246
|
scriptUrls: ee,
|
|
237
|
-
env:
|
|
247
|
+
env: r,
|
|
238
248
|
jwt: e
|
|
239
249
|
});
|
|
240
|
-
return
|
|
241
|
-
ref:
|
|
250
|
+
return d ? /* @__PURE__ */ y(Q, { onRetry: b }) : j.createElement(B, {
|
|
251
|
+
ref: f,
|
|
242
252
|
jwt: e,
|
|
243
|
-
env:
|
|
244
|
-
theme:
|
|
253
|
+
env: r,
|
|
254
|
+
theme: n,
|
|
245
255
|
// camelCase — React 19 sets this as a property via the extra-prop setter
|
|
246
256
|
// before connectedCallback runs, so the value lands in the URL fragment
|
|
247
257
|
// reliably (the hyphenated attribute path fails for JSON extra props
|
|
248
258
|
// because the raw string isn't valid JSON).
|
|
249
259
|
depositId: t,
|
|
250
|
-
|
|
260
|
+
walletAddress: o,
|
|
261
|
+
..._
|
|
251
262
|
});
|
|
252
263
|
};
|
|
253
264
|
export {
|