@prosopo/procaptcha-bundle 0.3.3 → 0.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.
@@ -0,0 +1,112 @@
1
+ import { A as f, P as I, j as n, C as W, W as _, a as C, c as k, e as P, f as R, g as O, i as G, L as H, k as U, m as L, n as j, l as F, d as B, r as b } from "./index-HgeMtpKw.js";
2
+ import { B as K, u as M, n as q, h as w, l as X, w as $, t as z, q as J, A as Q, W as V, K as Y, x as Z, C as ee, m as D, y as te, z as ne } from "./utils-CfklpKIj.js";
3
+ const oe = (a, e) => {
4
+ let o = 0;
5
+ const c = "0".repeat(e);
6
+ for (; ; ) {
7
+ const d = new TextEncoder().encode(o + a);
8
+ if (ae(K(d)).startsWith(c))
9
+ return o;
10
+ o += 1;
11
+ }
12
+ }, ae = (a) => Array.from(a).map((e) => e.toString(16).padStart(2, "0")).join(""), re = (a, e, o, c) => {
13
+ const d = () => ({
14
+ showModal: !1,
15
+ loading: !1,
16
+ index: 0,
17
+ challenge: void 0,
18
+ solutions: void 0,
19
+ isHuman: !1,
20
+ captchaApi: void 0,
21
+ account: void 0
22
+ }), r = () => {
23
+ window.clearTimeout(e.timeout), u({ timeout: void 0 });
24
+ }, i = () => {
25
+ const t = {
26
+ userAccountAddress: "",
27
+ ...a
28
+ };
29
+ return I.parse(t);
30
+ }, p = (t) => {
31
+ const s = t.networks[t.defaultNetwork];
32
+ if (!s)
33
+ throw new w("DEVELOPER.NETWORK_NOT_FOUND", {
34
+ context: { error: `No network found for environment ${t.defaultEnvironment}` }
35
+ });
36
+ return s;
37
+ }, A = async () => {
38
+ const t = p(i()), s = await Q.create({
39
+ provider: new V(t.endpoint),
40
+ initWasm: !1,
41
+ noInitWarn: !0
42
+ }), h = "sr25519", m = new Y({ type: h, ss58Format: s.registry.chainSS58 });
43
+ return new Z(s, JSON.parse(ee), t.contract.address, "prosopo", 0, m.addFromAddress(i().account.address || ""));
44
+ }, x = () => {
45
+ if (!e.account)
46
+ throw new w("GENERAL.ACCOUNT_NOT_FOUND", { context: { error: "Account not loaded" } });
47
+ return e.account;
48
+ }, l = () => {
49
+ if (!e.dappAccount)
50
+ throw new w("GENERAL.SITE_KEY_MISSING");
51
+ return e.dappAccount;
52
+ }, u = D(e, o), N = () => {
53
+ r(), u(d());
54
+ };
55
+ return {
56
+ start: async () => {
57
+ if (e.loading || e.isHuman)
58
+ return;
59
+ N();
60
+ const t = i(), s = new M(), h = t.userAccountAddress || (await s.getAccount(t)).account.address;
61
+ if (u({
62
+ loading: !0,
63
+ account: { account: { address: h } }
64
+ }), u({ dappAccount: t.account.address }), await q(100), !t.web2 && !t.userAccountAddress)
65
+ throw new w("GENERAL.ACCOUNT_NOT_FOUND", {
66
+ context: { error: "Account address has not been set for web3 mode" }
67
+ });
68
+ const m = await A(), S = X(o, e, c), v = await $(m.query.getRandomActiveProvider, m.query)(h, l()), y = z(v.provider.url.toString()), E = new J(p(i()), y, l()), g = await E.getPowCaptchaChallenge(h, l()), T = oe(g.challenge, g.difficulty);
69
+ (await E.submitPowCaptchaSolution(g, x().account.address, l(), v, T))[f.verified] && (u({
70
+ isHuman: !0,
71
+ loading: !1
72
+ }), S.onHuman({
73
+ providerUrl: y,
74
+ [f.user]: x().account.address,
75
+ [f.dapp]: l(),
76
+ [f.challenge]: g.challenge,
77
+ [f.blockNumber]: v.blockNumber
78
+ }));
79
+ }
80
+ };
81
+ }, le = (a) => {
82
+ const e = a.config, o = e.theme === "light" ? "light" : "dark", c = a.config.theme === "light" ? F : B, d = a.callbacks || {}, [r, i] = te(b.useState, b.useRef), p = D(r, i), A = re(e, r, p, d);
83
+ return n("div", { children: n("div", { style: { maxWidth: "100%", maxHeight: "100%", overflowX: "auto" }, children: n(W, { children: n(_, { children: C("div", { style: k, "data-cy": "button-human", children: [" ", C("div", { style: {
84
+ padding: P,
85
+ border: R,
86
+ backgroundColor: c.palette.background.default,
87
+ borderColor: c.palette.grey[300],
88
+ borderRadius: O,
89
+ display: "flex",
90
+ alignItems: "center",
91
+ flexWrap: "wrap",
92
+ justifyContent: "space-between",
93
+ minHeight: `${G}px`,
94
+ overflow: "hidden"
95
+ }, children: [n("div", { style: { display: "inline-flex", flexDirection: "column" }, children: n("div", { style: {
96
+ display: "flex",
97
+ justifyContent: "flex-start",
98
+ alignItems: "center",
99
+ flexWrap: "wrap"
100
+ }, children: n("div", { style: {
101
+ display: "flex",
102
+ alignItems: "center",
103
+ justifyContent: "center",
104
+ flexDirection: "column",
105
+ verticalAlign: "middle"
106
+ }, children: n("div", { style: {
107
+ display: "flex"
108
+ }, children: n("div", { style: { flex: 1 }, children: r.loading ? n(H, { themeColor: o }) : n(ne, { checked: r.isHuman, onChange: A.start, themeColor: o, labelText: "I am human" }) }) }) }) }) }), n("div", { style: { display: "inline-flex", flexDirection: "column" }, children: n("a", { href: U, target: "_blank", "aria-label": L, children: n("div", { style: { flex: 1 }, children: n(j, { themeColor: o }) }) }) })] })] }) }) }) }) });
109
+ };
110
+ export {
111
+ le as default
112
+ };