@prosopo/procaptcha-bundle 1.0.2 → 2.0.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.
@@ -0,0 +1,166 @@
1
+ import { A as o, e as O, a as H, P as L, r as v, j as n, W as U, C as j, c as M, b as y, f as B, g as F, h as K, i as V, k as X, L as Y, m as $, n as q, o as z, l as J, d as Q } from "./index-DvT5XLGE.js";
2
+ import { v as Z, k as _, E as ee, p as te, n as ne, f as w, o as oe, s as ae, q as re, l as k, t as se, C as ce } from "./utils-nH-g73b2.js";
3
+ const ie = (s, e) => {
4
+ let r = 0;
5
+ const d = "0".repeat(e);
6
+ for (; ; ) {
7
+ const p = new TextEncoder().encode(r + s);
8
+ if (le(Z(p)).startsWith(d))
9
+ return r;
10
+ r += 1;
11
+ }
12
+ }, le = (s) => Array.from(s).map((e) => e.toString(16).padStart(2, "0")).join(""), de = (s, e, r, d) => {
13
+ const p = _(r, e, d), u = () => ({
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
+ }), T = () => {
23
+ window.clearTimeout(e.timeout), a({ timeout: void 0 });
24
+ }, b = () => {
25
+ window.clearTimeout(e.successfullChallengeTimeout), a({ successfullChallengeTimeout: void 0 });
26
+ }, i = () => {
27
+ const t = {
28
+ userAccountAddress: "",
29
+ ...s
30
+ };
31
+ return e.account && (t.userAccountAddress = e.account.account.address), L.parse(t);
32
+ }, E = (t) => {
33
+ const c = t.networks[t.defaultNetwork];
34
+ if (!c)
35
+ throw new w("DEVELOPER.NETWORK_NOT_FOUND", {
36
+ context: {
37
+ error: `No network found for environment ${t.defaultEnvironment}`
38
+ }
39
+ });
40
+ return c;
41
+ }, g = () => {
42
+ if (!e.account)
43
+ throw new w("GENERAL.ACCOUNT_NOT_FOUND", {
44
+ context: { error: "Account not loaded" }
45
+ });
46
+ return { account: e.account };
47
+ }, l = () => {
48
+ if (!e.dappAccount)
49
+ throw new w("GENERAL.SITE_KEY_MISSING");
50
+ return e.dappAccount;
51
+ }, a = k(e, r), I = () => {
52
+ T(), b(), a(u());
53
+ }, P = () => {
54
+ const t = i().captchas.pow.solutionTimeout, c = setTimeout(() => {
55
+ a({ isHuman: !1 }), p.onExpired();
56
+ }, t);
57
+ a({ successfullChallengeTimeout: c });
58
+ }, W = async () => {
59
+ var S;
60
+ if (e.loading || e.isHuman)
61
+ return;
62
+ I(), a({
63
+ loading: !0
64
+ });
65
+ const t = i(), c = t.web2 ? new ee() : new te(), h = t.userAccountAddress || (await c.getAccount(t)).account.address;
66
+ if (a({
67
+ account: { account: { address: h } }
68
+ }), a({ dappAccount: t.account.address }), await ne(100), !t.web2 && !t.userAccountAddress)
69
+ throw new w("GENERAL.ACCOUNT_NOT_FOUND", {
70
+ context: { error: "Account address has not been set for web3 mode" }
71
+ });
72
+ const f = G(), x = _(r, e, d), A = f.provider.url, D = new oe(E(i()), A, l()), m = await D.getPowCaptchaChallenge(h, l()), N = ie(m.challenge, m.difficulty), C = (S = (await c.getAccount(i())).extension) == null ? void 0 : S.signer;
73
+ if (!C || !C.signRaw)
74
+ throw new w("GENERAL.CANT_FIND_KEYRINGPAIR", {
75
+ context: {
76
+ error: "Signer is not defined, cannot sign message to prove account ownership"
77
+ }
78
+ });
79
+ const R = await C.signRaw({
80
+ address: h,
81
+ data: ae(m[o.timestamp].toString()),
82
+ type: "bytes"
83
+ });
84
+ (await D.submitPowCaptchaSolution(m, g().account.account.address, l(), N, R.signature.toString(), t.captchas.pow.verifiedTimeout))[o.verified] && (a({
85
+ isHuman: !0,
86
+ loading: !1
87
+ }), x.onHuman(O({
88
+ [o.providerUrl]: A,
89
+ [o.user]: g().account.account.address,
90
+ [o.dapp]: l(),
91
+ [o.challenge]: m.challenge,
92
+ [o.blockNumber]: f.blockNumber,
93
+ [o.nonce]: N,
94
+ [o.timestamp]: m.timestamp,
95
+ [o.signature]: {
96
+ [o.provider]: m.signature.provider,
97
+ [o.user]: {
98
+ [o.timestamp]: R.signature.toString()
99
+ }
100
+ }
101
+ })), P());
102
+ }, G = () => {
103
+ const t = (x, A) => Math.floor(Math.random() * (A - x + 1) + x), c = i().defaultEnvironment, h = re(c), f = H(h, t(0, h.length - 1));
104
+ return {
105
+ providerAccount: f.address,
106
+ provider: {
107
+ url: f.url,
108
+ datasetId: f.datasetId,
109
+ datasetIdContent: f.datasetIdContent
110
+ },
111
+ blockNumber: 0
112
+ };
113
+ };
114
+ return {
115
+ start: W,
116
+ resetState: I
117
+ };
118
+ }, pe = (s) => {
119
+ const e = s.config, r = e.theme === "light" ? "light" : "dark", d = s.config.theme === "light" ? J : Q, p = s.callbacks || {}, [u, T] = se(v.useState, v.useRef), b = k(u, T), i = v.useRef(de(e, u, b, p)), E = v.useRef(null);
120
+ return v.useEffect(() => {
121
+ const g = E.current;
122
+ if (!g)
123
+ return;
124
+ const l = g.closest("form");
125
+ if (!l)
126
+ return;
127
+ const a = () => {
128
+ i.current.resetState();
129
+ };
130
+ return l.addEventListener("submit", a), () => {
131
+ l.removeEventListener("submit", a);
132
+ };
133
+ }, []), n("div", { ref: E, children: n("div", { style: {
134
+ maxWidth: U,
135
+ maxHeight: "100%",
136
+ overflowX: "auto"
137
+ }, children: n(j, { children: n(M, { children: y("div", { style: B, "data-cy": "button-human", children: [" ", y("div", { style: {
138
+ padding: F,
139
+ border: K,
140
+ backgroundColor: d.palette.background.default,
141
+ borderColor: d.palette.grey[300],
142
+ borderRadius: V,
143
+ display: "flex",
144
+ alignItems: "center",
145
+ flexWrap: "wrap",
146
+ justifyContent: "space-between",
147
+ minHeight: `${X}px`,
148
+ overflow: "hidden"
149
+ }, children: [n("div", { style: { display: "inline-flex", flexDirection: "column" }, children: n("div", { style: {
150
+ display: "flex",
151
+ justifyContent: "flex-start",
152
+ alignItems: "center",
153
+ flexWrap: "wrap"
154
+ }, children: n("div", { style: {
155
+ display: "flex",
156
+ alignItems: "center",
157
+ justifyContent: "center",
158
+ flexDirection: "column",
159
+ verticalAlign: "middle"
160
+ }, children: n("div", { style: {
161
+ display: "flex"
162
+ }, children: n("div", { style: { flex: 1 }, children: u.loading ? n(Y, { themeColor: r, "aria-label": "Loading spinner" }) : n(ce, { checked: u.isHuman, onChange: i.current.start, themeColor: r, labelText: "I am human", "aria-label": "human checkbox" }) }) }) }) }) }), n("div", { style: { display: "inline-flex", flexDirection: "column" }, children: n("a", { href: $, target: "_blank", "aria-label": q, rel: "noreferrer", children: n("div", { style: { flex: 1 }, children: n(z, { themeColor: r, "aria-label": "Prosopo logo" }) }) }) })] })] }) }) }) }) });
163
+ };
164
+ export {
165
+ pe as default
166
+ };