@prosopo/procaptcha-pow 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.
@@ -1,5 +1,6 @@
1
- import { ProcaptchaCallbacks, ProcaptchaClientConfigInput, ProcaptchaState, ProcaptchaStateUpdateFn } from '@prosopo/types';
1
+ import { type ProcaptchaCallbacks, type ProcaptchaClientConfigInput, type ProcaptchaState, type ProcaptchaStateUpdateFn } from "@prosopo/types";
2
2
  export declare const Manager: (configInput: ProcaptchaClientConfigInput, state: ProcaptchaState, onStateUpdate: ProcaptchaStateUpdateFn, callbacks: ProcaptchaCallbacks) => {
3
3
  start: () => Promise<void>;
4
+ resetState: () => void;
4
5
  };
5
6
  //# sourceMappingURL=Manager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Manager.d.ts","sourceRoot":"","sources":["../../src/Services/Manager.ts"],"names":[],"mappings":"AAaA,OAAO,EAGH,mBAAmB,EACnB,2BAA2B,EAG3B,eAAe,EACf,uBAAuB,EAE1B,MAAM,gBAAgB,CAAA;AAcvB,eAAO,MAAM,OAAO,gBACH,2BAA2B,SACjC,eAAe,iBACP,uBAAuB,aAC3B,mBAAmB;;CAiMjC,CAAA"}
1
+ {"version":3,"file":"Manager.d.ts","sourceRoot":"","sources":["../../src/Services/Manager.ts"],"names":[],"mappings":"AAoBA,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAGhC,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAG7B,MAAM,gBAAgB,CAAC;AAGxB,eAAO,MAAM,OAAO,gBACL,2BAA2B,SACjC,eAAe,iBACP,uBAAuB,aAC3B,mBAAmB;;;CAwP/B,CAAC"}
@@ -1,15 +1,12 @@
1
- import { ApiParams, ProcaptchaConfigSchema, encodeProcaptchaOutput, } from '@prosopo/types';
2
- import { ApiPromise } from '@polkadot/api/promise/Api';
3
- import { ExtensionWeb2 } from '@prosopo/account';
4
- import { Keyring } from '@polkadot/keyring';
5
- import { ProsopoCaptchaContract, wrapQuery } from '@prosopo/contract';
6
- import { ProsopoEnvError, trimProviderUrl } from '@prosopo/common';
7
- import { ProviderApi } from '@prosopo/api';
8
- import { WsProvider } from '@polkadot/rpc-provider/ws';
9
- import { ContractAbi as abiJson } from '@prosopo/captcha-contract/contract-info';
10
- import { buildUpdateState, getDefaultEvents } from '@prosopo/procaptcha-common';
11
- import { sleep } from '@prosopo/procaptcha';
12
- import { solvePoW } from '@prosopo/util';
1
+ import { stringToHex } from "@polkadot/util/string";
2
+ import { ExtensionWeb2, ExtensionWeb3 } from "@prosopo/account";
3
+ import { ProviderApi } from "@prosopo/api";
4
+ import { ProsopoEnvError } from "@prosopo/common";
5
+ import { loadBalancer } from "@prosopo/load-balancer";
6
+ import { sleep } from "@prosopo/procaptcha";
7
+ import { buildUpdateState, getDefaultEvents } from "@prosopo/procaptcha-common";
8
+ import { ApiParams, ProcaptchaConfigSchema, encodeProcaptchaOutput, } from "@prosopo/types";
9
+ import { at, solvePoW } from "@prosopo/util";
13
10
  export const Manager = (configInput, state, onStateUpdate, callbacks) => {
14
11
  const events = getDefaultEvents(onStateUpdate, state, callbacks);
15
12
  const defaultState = () => {
@@ -28,43 +25,43 @@ export const Manager = (configInput, state, onStateUpdate, callbacks) => {
28
25
  window.clearTimeout(state.timeout);
29
26
  updateState({ timeout: undefined });
30
27
  };
28
+ const clearSuccessfulChallengeTimeout = () => {
29
+ window.clearTimeout(state.successfullChallengeTimeout);
30
+ updateState({ successfullChallengeTimeout: undefined });
31
+ };
31
32
  const getConfig = () => {
32
33
  const config = {
33
- userAccountAddress: '',
34
+ userAccountAddress: "",
34
35
  ...configInput,
35
36
  };
37
+ if (state.account) {
38
+ config.userAccountAddress = state.account.account.address;
39
+ }
36
40
  return ProcaptchaConfigSchema.parse(config);
37
41
  };
38
42
  const getNetwork = (config) => {
39
43
  const network = config.networks[config.defaultNetwork];
40
44
  if (!network) {
41
- throw new ProsopoEnvError('DEVELOPER.NETWORK_NOT_FOUND', {
42
- context: { error: `No network found for environment ${config.defaultEnvironment}` },
45
+ throw new ProsopoEnvError("DEVELOPER.NETWORK_NOT_FOUND", {
46
+ context: {
47
+ error: `No network found for environment ${config.defaultEnvironment}`,
48
+ },
43
49
  });
44
50
  }
45
51
  return network;
46
52
  };
47
- const loadContract = async () => {
48
- const network = getNetwork(getConfig());
49
- const api = await ApiPromise.create({
50
- provider: new WsProvider(network.endpoint),
51
- initWasm: false,
52
- noInitWarn: true,
53
- });
54
- const type = 'sr25519';
55
- const keyring = new Keyring({ type, ss58Format: api.registry.chainSS58 });
56
- return new ProsopoCaptchaContract(api, JSON.parse(abiJson), network.contract.address, 'prosopo', 0, keyring.addFromAddress(getConfig().account.address || ''));
57
- };
58
53
  const getAccount = () => {
59
54
  if (!state.account) {
60
- throw new ProsopoEnvError('GENERAL.ACCOUNT_NOT_FOUND', { context: { error: 'Account not loaded' } });
55
+ throw new ProsopoEnvError("GENERAL.ACCOUNT_NOT_FOUND", {
56
+ context: { error: "Account not loaded" },
57
+ });
61
58
  }
62
59
  const account = state.account;
63
- return account;
60
+ return { account };
64
61
  };
65
62
  const getDappAccount = () => {
66
63
  if (!state.dappAccount) {
67
- throw new ProsopoEnvError('GENERAL.SITE_KEY_MISSING');
64
+ throw new ProsopoEnvError("GENERAL.SITE_KEY_MISSING");
68
65
  }
69
66
  const dappAccount = state.dappAccount;
70
67
  return dappAccount;
@@ -72,6 +69,7 @@ export const Manager = (configInput, state, onStateUpdate, callbacks) => {
72
69
  const updateState = buildUpdateState(state, onStateUpdate);
73
70
  const resetState = () => {
74
71
  clearTimeout();
72
+ clearSuccessfulChallengeTimeout();
75
73
  updateState(defaultState());
76
74
  };
77
75
  const setValidChallengeTimeout = () => {
@@ -94,26 +92,40 @@ export const Manager = (configInput, state, onStateUpdate, callbacks) => {
94
92
  loading: true,
95
93
  });
96
94
  const config = getConfig();
97
- const ext = new ExtensionWeb2();
98
- const userAccount = config.userAccountAddress || (await ext.getAccount(config)).account.address;
95
+ const ext = config.web2 ? new ExtensionWeb2() : new ExtensionWeb3();
96
+ const userAccount = config.userAccountAddress ||
97
+ (await ext.getAccount(config)).account.address;
99
98
  updateState({
100
99
  account: { account: { address: userAccount } },
101
100
  });
102
101
  updateState({ dappAccount: config.account.address });
103
102
  await sleep(100);
104
103
  if (!config.web2 && !config.userAccountAddress) {
105
- throw new ProsopoEnvError('GENERAL.ACCOUNT_NOT_FOUND', {
106
- context: { error: 'Account address has not been set for web3 mode' },
104
+ throw new ProsopoEnvError("GENERAL.ACCOUNT_NOT_FOUND", {
105
+ context: { error: "Account address has not been set for web3 mode" },
107
106
  });
108
107
  }
109
- const contract = await loadContract();
108
+ const getRandomProviderResponse = getRandomActiveProvider();
110
109
  const events = getDefaultEvents(onStateUpdate, state, callbacks);
111
- const getRandomProviderResponse = await wrapQuery(contract.query.getRandomActiveProvider, contract.query)(userAccount, getDappAccount());
112
- const providerUrl = trimProviderUrl(getRandomProviderResponse.provider.url.toString());
110
+ const providerUrl = getRandomProviderResponse.provider.url;
113
111
  const providerApi = new ProviderApi(getNetwork(getConfig()), providerUrl, getDappAccount());
114
112
  const challenge = await providerApi.getPowCaptchaChallenge(userAccount, getDappAccount());
115
113
  const solution = solvePoW(challenge.challenge, challenge.difficulty);
116
- const verifiedSolution = await providerApi.submitPowCaptchaSolution(challenge, getAccount().account.address, getDappAccount(), getRandomProviderResponse, solution, config.captchas.pow.verifiedTimeout);
114
+ const user = await ext.getAccount(getConfig());
115
+ const signer = user.extension?.signer;
116
+ if (!signer || !signer.signRaw) {
117
+ throw new ProsopoEnvError("GENERAL.CANT_FIND_KEYRINGPAIR", {
118
+ context: {
119
+ error: "Signer is not defined, cannot sign message to prove account ownership",
120
+ },
121
+ });
122
+ }
123
+ const userTimestampSignature = await signer.signRaw({
124
+ address: userAccount,
125
+ data: stringToHex(challenge[ApiParams.timestamp].toString()),
126
+ type: "bytes",
127
+ });
128
+ const verifiedSolution = await providerApi.submitPowCaptchaSolution(challenge, getAccount().account.account.address, getDappAccount(), solution, userTimestampSignature.signature.toString(), config.captchas.pow.verifiedTimeout);
117
129
  if (verifiedSolution[ApiParams.verified]) {
118
130
  updateState({
119
131
  isHuman: true,
@@ -121,17 +133,40 @@ export const Manager = (configInput, state, onStateUpdate, callbacks) => {
121
133
  });
122
134
  events.onHuman(encodeProcaptchaOutput({
123
135
  [ApiParams.providerUrl]: providerUrl,
124
- [ApiParams.user]: getAccount().account.address,
136
+ [ApiParams.user]: getAccount().account.account.address,
125
137
  [ApiParams.dapp]: getDappAccount(),
126
138
  [ApiParams.challenge]: challenge.challenge,
127
139
  [ApiParams.blockNumber]: getRandomProviderResponse.blockNumber,
128
140
  [ApiParams.nonce]: solution,
141
+ [ApiParams.timestamp]: challenge.timestamp,
142
+ [ApiParams.signature]: {
143
+ [ApiParams.provider]: challenge.signature.provider,
144
+ [ApiParams.user]: {
145
+ [ApiParams.timestamp]: userTimestampSignature.signature.toString(),
146
+ },
147
+ },
129
148
  }));
130
149
  setValidChallengeTimeout();
131
150
  }
132
151
  };
152
+ const getRandomActiveProvider = () => {
153
+ const randomIntBetween = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);
154
+ const environment = getConfig().defaultEnvironment;
155
+ const PROVIDERS = loadBalancer(environment);
156
+ const randomProvderObj = at(PROVIDERS, randomIntBetween(0, PROVIDERS.length - 1));
157
+ return {
158
+ providerAccount: randomProvderObj.address,
159
+ provider: {
160
+ url: randomProvderObj.url,
161
+ datasetId: randomProvderObj.datasetId,
162
+ datasetIdContent: randomProvderObj.datasetIdContent,
163
+ },
164
+ blockNumber: 0,
165
+ };
166
+ };
133
167
  return {
134
168
  start,
169
+ resetState,
135
170
  };
136
171
  };
137
172
  //# sourceMappingURL=Manager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Manager.js","sourceRoot":"","sources":["../../src/Services/Manager.ts"],"names":[],"mappings":"AAaA,OAAO,EAEH,SAAS,EAIT,sBAAsB,EAGtB,sBAA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Q,EAAE;qBAC9C;iBACF;aACF,CAAC,CACH,CAAC;YACF,wBAAwB,EAAE,CAAC;SAC5B;IACH,CAAC,CAAC;IAEF,MAAM,uBAAuB,GAAG,GAAmB,EAAE;QACnD,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CACpD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;QAKpD,MAAM,WAAW,GAAG,SAAS,EAAE,CAAC,kBAAkB,CAAC;QACnD,MAAM,SAAS,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;QAE5C,MAAM,gBAAgB,GAAG,EAAE,CACzB,SAAS,EACT,gBAAgB,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAC1C,CAAC;QACF,OAAO;YACL,eAAe,EAAE,gBAAgB,CAAC,OAAO;YACzC,QAAQ,EAAE;gBACR,GAAG,EAAE,gBAAgB,CAAC,GAAG;gBACzB,SAAS,EAAE,gBAAgB,CAAC,SAAS;gBACrC,gBAAgB,EAAE,gBAAgB,CAAC,gBAAgB;aACpD;YACD,WAAW,EAAE,CAAC;SACf,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,KAAK;QACL,UAAU;KACX,CAAC;AACJ,CAAC,CAAC"}
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const types = require("@prosopo/types");
4
- const Api = require("@polkadot/api/promise/Api");
3
+ const string = require("@polkadot/util/string");
5
4
  const account = require("@prosopo/account");
6
- const keyring = require("@polkadot/keyring");
7
- const contract = require("@prosopo/contract");
8
- const common = require("@prosopo/common");
9
5
  const api = require("@prosopo/api");
10
- const ws = require("@polkadot/rpc-provider/ws");
11
- const contractInfo = require("@prosopo/captcha-contract/contract-info");
12
- const procaptchaCommon = require("@prosopo/procaptcha-common");
6
+ const common = require("@prosopo/common");
7
+ const loadBalancer = require("@prosopo/load-balancer");
13
8
  const procaptcha = require("@prosopo/procaptcha");
9
+ const procaptchaCommon = require("@prosopo/procaptcha-common");
10
+ const types = require("@prosopo/types");
14
11
  const util = require("@prosopo/util");
15
12
  const Manager = (configInput, state, onStateUpdate, callbacks) => {
16
13
  const events = procaptchaCommon.getDefaultEvents(onStateUpdate, state, callbacks);
@@ -32,46 +29,39 @@ const Manager = (configInput, state, onStateUpdate, callbacks) => {
32
29
  window.clearTimeout(state.timeout);
33
30
  updateState({ timeout: void 0 });
34
31
  };
32
+ const clearSuccessfulChallengeTimeout = () => {
33
+ window.clearTimeout(state.successfullChallengeTimeout);
34
+ updateState({ successfullChallengeTimeout: void 0 });
35
+ };
35
36
  const getConfig = () => {
36
37
  const config = {
37
38
  userAccountAddress: "",
38
39
  ...configInput
39
40
  };
41
+ if (state.account) {
42
+ config.userAccountAddress = state.account.account.address;
43
+ }
40
44
  return types.ProcaptchaConfigSchema.parse(config);
41
45
  };
42
46
  const getNetwork = (config) => {
43
47
  const network = config.networks[config.defaultNetwork];
44
48
  if (!network) {
45
49
  throw new common.ProsopoEnvError("DEVELOPER.NETWORK_NOT_FOUND", {
46
- context: { error: `No network found for environment ${config.defaultEnvironment}` }
50
+ context: {
51
+ error: `No network found for environment ${config.defaultEnvironment}`
52
+ }
47
53
  });
48
54
  }
49
55
  return network;
50
56
  };
51
- const loadContract = async () => {
52
- const network = getNetwork(getConfig());
53
- const api2 = await Api.ApiPromise.create({
54
- provider: new ws.WsProvider(network.endpoint),
55
- initWasm: false,
56
- noInitWarn: true
57
- });
58
- const type = "sr25519";
59
- const keyring$1 = new keyring.Keyring({ type, ss58Format: api2.registry.chainSS58 });
60
- return new contract.ProsopoCaptchaContract(
61
- api2,
62
- JSON.parse(contractInfo.ContractAbi),
63
- network.contract.address,
64
- "prosopo",
65
- 0,
66
- keyring$1.addFromAddress(getConfig().account.address || "")
67
- );
68
- };
69
57
  const getAccount = () => {
70
58
  if (!state.account) {
71
- throw new common.ProsopoEnvError("GENERAL.ACCOUNT_NOT_FOUND", { context: { error: "Account not loaded" } });
59
+ throw new common.ProsopoEnvError("GENERAL.ACCOUNT_NOT_FOUND", {
60
+ context: { error: "Account not loaded" }
61
+ });
72
62
  }
73
63
  const account2 = state.account;
74
- return account2;
64
+ return { account: account2 };
75
65
  };
76
66
  const getDappAccount = () => {
77
67
  if (!state.dappAccount) {
@@ -83,6 +73,7 @@ const Manager = (configInput, state, onStateUpdate, callbacks) => {
83
73
  const updateState = procaptchaCommon.buildUpdateState(state, onStateUpdate);
84
74
  const resetState = () => {
85
75
  clearTimeout();
76
+ clearSuccessfulChallengeTimeout();
86
77
  updateState(defaultState());
87
78
  };
88
79
  const setValidChallengeTimeout = () => {
@@ -105,7 +96,7 @@ const Manager = (configInput, state, onStateUpdate, callbacks) => {
105
96
  loading: true
106
97
  });
107
98
  const config = getConfig();
108
- const ext = new account.ExtensionWeb2();
99
+ const ext = config.web2 ? new account.ExtensionWeb2() : new account.ExtensionWeb3();
109
100
  const userAccount = config.userAccountAddress || (await ext.getAccount(config)).account.address;
110
101
  updateState({
111
102
  account: { account: { address: userAccount } }
@@ -117,22 +108,39 @@ const Manager = (configInput, state, onStateUpdate, callbacks) => {
117
108
  context: { error: "Account address has not been set for web3 mode" }
118
109
  });
119
110
  }
120
- const contract$1 = await loadContract();
111
+ const getRandomProviderResponse = getRandomActiveProvider();
121
112
  const events2 = procaptchaCommon.getDefaultEvents(onStateUpdate, state, callbacks);
122
- const getRandomProviderResponse = await contract.wrapQuery(
123
- contract$1.query.getRandomActiveProvider,
124
- contract$1.query
125
- )(userAccount, getDappAccount());
126
- const providerUrl = common.trimProviderUrl(getRandomProviderResponse.provider.url.toString());
127
- const providerApi = new api.ProviderApi(getNetwork(getConfig()), providerUrl, getDappAccount());
128
- const challenge = await providerApi.getPowCaptchaChallenge(userAccount, getDappAccount());
113
+ const providerUrl = getRandomProviderResponse.provider.url;
114
+ const providerApi = new api.ProviderApi(
115
+ getNetwork(getConfig()),
116
+ providerUrl,
117
+ getDappAccount()
118
+ );
119
+ const challenge = await providerApi.getPowCaptchaChallenge(
120
+ userAccount,
121
+ getDappAccount()
122
+ );
129
123
  const solution = util.solvePoW(challenge.challenge, challenge.difficulty);
124
+ const user = await ext.getAccount(getConfig());
125
+ const signer = user.extension?.signer;
126
+ if (!signer || !signer.signRaw) {
127
+ throw new common.ProsopoEnvError("GENERAL.CANT_FIND_KEYRINGPAIR", {
128
+ context: {
129
+ error: "Signer is not defined, cannot sign message to prove account ownership"
130
+ }
131
+ });
132
+ }
133
+ const userTimestampSignature = await signer.signRaw({
134
+ address: userAccount,
135
+ data: string.stringToHex(challenge[types.ApiParams.timestamp].toString()),
136
+ type: "bytes"
137
+ });
130
138
  const verifiedSolution = await providerApi.submitPowCaptchaSolution(
131
139
  challenge,
132
- getAccount().account.address,
140
+ getAccount().account.account.address,
133
141
  getDappAccount(),
134
- getRandomProviderResponse,
135
142
  solution,
143
+ userTimestampSignature.signature.toString(),
136
144
  config.captchas.pow.verifiedTimeout
137
145
  );
138
146
  if (verifiedSolution[types.ApiParams.verified]) {
@@ -143,18 +151,44 @@ const Manager = (configInput, state, onStateUpdate, callbacks) => {
143
151
  events2.onHuman(
144
152
  types.encodeProcaptchaOutput({
145
153
  [types.ApiParams.providerUrl]: providerUrl,
146
- [types.ApiParams.user]: getAccount().account.address,
154
+ [types.ApiParams.user]: getAccount().account.account.address,
147
155
  [types.ApiParams.dapp]: getDappAccount(),
148
156
  [types.ApiParams.challenge]: challenge.challenge,
149
157
  [types.ApiParams.blockNumber]: getRandomProviderResponse.blockNumber,
150
- [types.ApiParams.nonce]: solution
158
+ [types.ApiParams.nonce]: solution,
159
+ [types.ApiParams.timestamp]: challenge.timestamp,
160
+ [types.ApiParams.signature]: {
161
+ [types.ApiParams.provider]: challenge.signature.provider,
162
+ [types.ApiParams.user]: {
163
+ [types.ApiParams.timestamp]: userTimestampSignature.signature.toString()
164
+ }
165
+ }
151
166
  })
152
167
  );
153
168
  setValidChallengeTimeout();
154
169
  }
155
170
  };
171
+ const getRandomActiveProvider = () => {
172
+ const randomIntBetween = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);
173
+ const environment = getConfig().defaultEnvironment;
174
+ const PROVIDERS = loadBalancer.loadBalancer(environment);
175
+ const randomProvderObj = util.at(
176
+ PROVIDERS,
177
+ randomIntBetween(0, PROVIDERS.length - 1)
178
+ );
179
+ return {
180
+ providerAccount: randomProvderObj.address,
181
+ provider: {
182
+ url: randomProvderObj.url,
183
+ datasetId: randomProvderObj.datasetId,
184
+ datasetIdContent: randomProvderObj.datasetIdContent
185
+ },
186
+ blockNumber: 0
187
+ };
188
+ };
156
189
  return {
157
- start
190
+ start,
191
+ resetState
158
192
  };
159
193
  };
160
194
  exports.Manager = Manager;
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("@emotion/react/jsx-runtime");
4
- const react = require("react");
5
4
  const webComponents = require("@prosopo/web-components");
5
+ const react = require("react");
6
6
  const _interopNamespaceDefaultOnly = (e) => Object.freeze(Object.defineProperty({ __proto__: null, default: e }, Symbol.toStringTag, { value: "Module" }));
7
- const ProcaptchaWidget = react.lazy(
8
- async () => Promise.resolve().then(() => /* @__PURE__ */ _interopNamespaceDefaultOnly(require("./Captcha.cjs")))
9
- );
7
+ const ProcaptchaWidget = react.lazy(async () => Promise.resolve().then(() => /* @__PURE__ */ _interopNamespaceDefaultOnly(require("./ProcaptchaWidget.cjs"))));
10
8
  const ProcaptchaPow = (props) => /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx(webComponents.ProcaptchaPlaceholder, { darkMode: props.config.theme }), children: /* @__PURE__ */ jsxRuntime.jsx(ProcaptchaWidget, { config: props.config, callbacks: props.callbacks }) });
11
9
  exports.ProcaptchaPow = ProcaptchaPow;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ const jsxRuntime = require("@emotion/react/jsx-runtime");
3
+ const procaptchaCommon = require("@prosopo/procaptcha-common");
4
+ const webComponents = require("@prosopo/web-components");
5
+ const react = require("react");
6
+ const Manager = require("../Services/Manager.cjs");
7
+ const Procaptcha = (props) => {
8
+ const config = props.config;
9
+ const themeColor = config.theme === "light" ? "light" : "dark";
10
+ const theme = props.config.theme === "light" ? webComponents.lightTheme : webComponents.darkTheme;
11
+ const callbacks = props.callbacks || {};
12
+ const [state, _updateState] = procaptchaCommon.useProcaptcha(react.useState, react.useRef);
13
+ const updateState = procaptchaCommon.buildUpdateState(state, _updateState);
14
+ const manager = react.useRef(Manager.Manager(config, state, updateState, callbacks));
15
+ const captchaRef = react.useRef(null);
16
+ react.useEffect(() => {
17
+ const element = captchaRef.current;
18
+ if (!element) return;
19
+ const form = element.closest("form");
20
+ if (!form) return;
21
+ const handleSubmit = () => {
22
+ manager.current.resetState();
23
+ };
24
+ form.addEventListener("submit", handleSubmit);
25
+ return () => {
26
+ form.removeEventListener("submit", handleSubmit);
27
+ };
28
+ }, []);
29
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { ref: captchaRef, children: /* @__PURE__ */ jsxRuntime.jsx(
30
+ "div",
31
+ {
32
+ style: {
33
+ maxWidth: webComponents.WIDGET_MAX_WIDTH,
34
+ maxHeight: "100%",
35
+ overflowX: "auto"
36
+ },
37
+ children: /* @__PURE__ */ jsxRuntime.jsx(webComponents.ContainerDiv, { children: /* @__PURE__ */ jsxRuntime.jsx(webComponents.WidthBasedStylesDiv, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: webComponents.WIDGET_DIMENSIONS, "data-cy": "button-human", children: [
38
+ " ",
39
+ /* @__PURE__ */ jsxRuntime.jsxs(
40
+ "div",
41
+ {
42
+ style: {
43
+ padding: webComponents.WIDGET_PADDING,
44
+ border: webComponents.WIDGET_BORDER,
45
+ backgroundColor: theme.palette.background.default,
46
+ borderColor: theme.palette.grey[300],
47
+ borderRadius: webComponents.WIDGET_BORDER_RADIUS,
48
+ display: "flex",
49
+ alignItems: "center",
50
+ flexWrap: "wrap",
51
+ justifyContent: "space-between",
52
+ minHeight: `${webComponents.WIDGET_INNER_HEIGHT}px`,
53
+ overflow: "hidden"
54
+ },
55
+ children: [
56
+ /* @__PURE__ */ jsxRuntime.jsx(
57
+ "div",
58
+ {
59
+ style: { display: "inline-flex", flexDirection: "column" },
60
+ children: /* @__PURE__ */ jsxRuntime.jsx(
61
+ "div",
62
+ {
63
+ style: {
64
+ display: "flex",
65
+ justifyContent: "flex-start",
66
+ alignItems: "center",
67
+ flexWrap: "wrap"
68
+ },
69
+ children: /* @__PURE__ */ jsxRuntime.jsx(
70
+ "div",
71
+ {
72
+ style: {
73
+ display: "flex",
74
+ alignItems: "center",
75
+ justifyContent: "center",
76
+ flexDirection: "column",
77
+ verticalAlign: "middle"
78
+ },
79
+ children: /* @__PURE__ */ jsxRuntime.jsx(
80
+ "div",
81
+ {
82
+ style: {
83
+ display: "flex"
84
+ },
85
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { flex: 1 }, children: state.loading ? /* @__PURE__ */ jsxRuntime.jsx(
86
+ webComponents.LoadingSpinner,
87
+ {
88
+ themeColor,
89
+ "aria-label": "Loading spinner"
90
+ }
91
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
92
+ webComponents.Checkbox,
93
+ {
94
+ checked: state.isHuman,
95
+ onChange: manager.current.start,
96
+ themeColor,
97
+ labelText: "I am human",
98
+ "aria-label": "human checkbox"
99
+ }
100
+ ) })
101
+ }
102
+ )
103
+ }
104
+ )
105
+ }
106
+ )
107
+ }
108
+ ),
109
+ /* @__PURE__ */ jsxRuntime.jsx(
110
+ "div",
111
+ {
112
+ style: { display: "inline-flex", flexDirection: "column" },
113
+ children: /* @__PURE__ */ jsxRuntime.jsx(
114
+ "a",
115
+ {
116
+ href: webComponents.WIDGET_URL,
117
+ target: "_blank",
118
+ "aria-label": webComponents.WIDGET_URL_TEXT,
119
+ rel: "noreferrer",
120
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { flex: 1 }, children: /* @__PURE__ */ jsxRuntime.jsx(webComponents.Logo, { themeColor, "aria-label": "Prosopo logo" }) })
121
+ }
122
+ )
123
+ }
124
+ )
125
+ ]
126
+ }
127
+ )
128
+ ] }) }) })
129
+ }
130
+ ) });
131
+ };
132
+ module.exports = Procaptcha;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- require("./components/Captcha.cjs");
3
+ require("./components/ProcaptchaWidget.cjs");
4
4
  const ProcaptchaPoW = require("./components/ProcaptchaPoW.cjs");
5
5
  exports.ProcaptchaPow = ProcaptchaPoW.ProcaptchaPow;
@@ -1,4 +1,2 @@
1
- import { ProcaptchaProps } from '@prosopo/types';
2
- declare const Procaptcha: (props: ProcaptchaProps) => import("@emotion/react/jsx-runtime").JSX.Element;
3
- export default Procaptcha;
1
+ export {};
4
2
  //# sourceMappingURL=Captcha.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Captcha.d.ts","sourceRoot":"","sources":["../../src/components/Captcha.tsx"],"names":[],"mappings":"AA8BA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAIhD,QAAA,MAAM,UAAU,UAAW,eAAe,qDA0FzC,CAAA;AACD,eAAe,UAAU,CAAA"}
1
+ {"version":3,"file":"Captcha.d.ts","sourceRoot":"","sources":["../../src/components/Captcha.tsx"],"names":[],"mappings":""}
@@ -1,42 +1,2 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
- import { Checkbox, ContainerDiv, LoadingSpinner, Logo, WIDGET_BORDER, WIDGET_BORDER_RADIUS, WIDGET_DIMENSIONS, WIDGET_INNER_HEIGHT, WIDGET_PADDING, WIDGET_URL, WIDGET_URL_TEXT, WidthBasedStylesDiv, darkTheme, lightTheme, } from '@prosopo/web-components';
3
- import { Manager } from '../Services/Manager.js';
4
- import { buildUpdateState, useProcaptcha } from '@prosopo/procaptcha-common';
5
- import { useRef, useState } from 'react';
6
- const Procaptcha = (props) => {
7
- const config = props.config;
8
- const themeColor = config.theme === 'light' ? 'light' : 'dark';
9
- const theme = props.config.theme === 'light' ? lightTheme : darkTheme;
10
- const callbacks = props.callbacks || {};
11
- const [state, _updateState] = useProcaptcha(useState, useRef);
12
- const updateState = buildUpdateState(state, _updateState);
13
- const manager = Manager(config, state, updateState, callbacks);
14
- return (_jsx("div", { children: _jsx("div", { style: { maxWidth: '100%', maxHeight: '100%', overflowX: 'auto' }, children: _jsx(ContainerDiv, { children: _jsx(WidthBasedStylesDiv, { children: _jsxs("div", { style: WIDGET_DIMENSIONS, "data-cy": 'button-human', children: [' ', _jsxs("div", { style: {
15
- padding: WIDGET_PADDING,
16
- border: WIDGET_BORDER,
17
- backgroundColor: theme.palette.background.default,
18
- borderColor: theme.palette.grey[300],
19
- borderRadius: WIDGET_BORDER_RADIUS,
20
- display: 'flex',
21
- alignItems: 'center',
22
- flexWrap: 'wrap',
23
- justifyContent: 'space-between',
24
- minHeight: `${WIDGET_INNER_HEIGHT}px`,
25
- overflow: 'hidden',
26
- }, children: [_jsx("div", { style: { display: 'inline-flex', flexDirection: 'column' }, children: _jsx("div", { style: {
27
- display: 'flex',
28
- justifyContent: 'flex-start',
29
- alignItems: 'center',
30
- flexWrap: 'wrap',
31
- }, children: _jsx("div", { style: {
32
- display: 'flex',
33
- alignItems: 'center',
34
- justifyContent: 'center',
35
- flexDirection: 'column',
36
- verticalAlign: 'middle',
37
- }, children: _jsx("div", { style: {
38
- display: 'flex',
39
- }, children: _jsx("div", { style: { flex: 1 }, children: state.loading ? (_jsx(LoadingSpinner, { themeColor: themeColor, "aria-label": "Loading spinner" })) : (_jsx(Checkbox, { checked: state.isHuman, onChange: manager.start, themeColor: themeColor, labelText: 'I am human', "aria-label": "human checkbox" })) }) }) }) }) }), _jsx("div", { style: { display: 'inline-flex', flexDirection: 'column' }, children: _jsx("a", { href: WIDGET_URL, target: "_blank", "aria-label": WIDGET_URL_TEXT, children: _jsx("div", { style: { flex: 1 }, children: _jsx(Logo, { themeColor: themeColor, "aria-label": "Prosopo logo" }) }) }) })] })] }) }) }) }) }));
40
- };
41
- export default Procaptcha;
1
+ export {};
42
2
  //# sourceMappingURL=Captcha.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Captcha.js","sourceRoot":"","sources":["../../src/components/Captcha.tsx"],"names":[],"mappings":";AAaA,OAAO,EACH,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,IAAI,EACJ,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,SAAS,EACT,UAAU,GACb,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAEhD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC5E,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAExC,MAAM,UAAU,GAAG,CAAC,KAAsB,EAAE,EAAE;IAC1C,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;IAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAA;IAC9D,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAA;IACrE,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,EAAE,CAAA;IACvC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,GAAG,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IAE7D,MAAM,WAAW,GAAG,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,YAClB,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CACb,KAAC,cAAc,IACX,UAAU,EAAE,UAAU,gBACX,iBAAiB,GAC9B,CACL,CAAC,CAAC,CAAC,CACA,KAAC,QAAQ,IACL,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,QAAQ,EAAE,OAAO,CAAC,KAAK,EACvB,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,YAAY,gBACZ,gBAAgB,GACnB,CACf,GACC,GACJ,GACJ,GACJ,GACJ,EAEN,cAAK,KAAK,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,YAC3D,YAAG,IAAI,EAAE,UAAU,EAAE,MAAM,EAAC,QAAQ,gBAAa,eAAe,YAC5D,cAAK,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,YACnB,KAAC,IAAI,IAAC,UAAU,EAAE,UAAU,gBAAa,cAAc,GAAQ,GAC7D,GACN,GACF,IACJ,IACJ,GACY,GACX,GACb,GACJ,CACT,CAAA;AACL,CAAC,CAAA;AACD,eAAe,UAAU,CAAA"}
1
+ {"version":3,"file":"Captcha.js","sourceRoot":"","sources":["../../src/components/Captcha.tsx"],"names":[],"mappings":""}
@@ -1,6 +1,6 @@
1
- import { LazyExoticComponent } from 'react';
2
- import { ProcaptchaEvents } from '@prosopo/types';
3
- import { ReactElement } from 'react';
1
+ import type { ProcaptchaEvents } from "@prosopo/types";
2
+ import { type LazyExoticComponent } from "react";
3
+ import type { ReactElement } from "react";
4
4
  type ProcaptchaProps = React.ComponentProps<typeof ProcaptchaWidget>;
5
5
  declare const ProcaptchaWidget: LazyExoticComponent<(props: any, callbacks: Partial<ProcaptchaEvents>) => ReactElement>;
6
6
  export declare const ProcaptchaPow: (props: ProcaptchaProps) => import("@emotion/react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"ProcaptchaPoW.d.ts","sourceRoot":"","sources":["../../src/components/ProcaptchaPoW.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,mBAAmB,EAAkB,MAAM,OAAO,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAEpC,KAAK,eAAe,GAAG,KAAK,CAAC,cAAc,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAEpE,QAAA,MAAM,gBAAgB,EAAE,mBAAmB,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,gBAAgB,CAAC,KAAK,YAAY,CAE7G,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,eAAe,qDAInD,CAAA"}
1
+ {"version":3,"file":"ProcaptchaPoW.d.ts","sourceRoot":"","sources":["../../src/components/ProcaptchaPoW.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAevD,OAAO,EAAE,KAAK,mBAAmB,EAAkB,MAAM,OAAO,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C,KAAK,eAAe,GAAG,KAAK,CAAC,cAAc,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAErE,QAAA,MAAM,gBAAgB,EAAE,mBAAmB,CAE1C,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,gBAAgB,CAAC,KAAK,YAAY,CACd,CAAC;AAEtD,eAAO,MAAM,aAAa,UAAW,eAAe,qDAInD,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
2
- import { Suspense, lazy } from 'react';
3
- import { ProcaptchaPlaceholder } from '@prosopo/web-components';
4
- const ProcaptchaWidget = lazy(async () => import('./Captcha.js'));
2
+ import { ProcaptchaPlaceholder } from "@prosopo/web-components";
3
+ import { Suspense, lazy } from "react";
4
+ const ProcaptchaWidget = lazy(async () => import("./ProcaptchaWidget.js"));
5
5
  export const ProcaptchaPow = (props) => (_jsx(Suspense, { fallback: _jsx(ProcaptchaPlaceholder, { darkMode: props.config.theme }), children: _jsx(ProcaptchaWidget, { config: props.config, callbacks: props.callbacks }) }));
6
6
  //# sourceMappingURL=ProcaptchaPoW.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ProcaptchaPoW.js","sourceRoot":"","sources":["../../src/components/ProcaptchaPoW.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAuB,QAAQ,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAK/D,MAAM,gBAAgB,GAA4F,IAAI,CAClH,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,CACrC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAsB,EAAE,EAAE,CAAC,CACrD,KAAC,QAAQ,IAAC,QAAQ,EAAE,KAAC,qBAAqB,IAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,GAAI,YACvE,KAAC,gBAAgB,IAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,GAAqB,GAChF,CACd,CAAA"}
1
+ {"version":3,"file":"ProcaptchaPoW.js","sourceRoot":"","sources":["../../src/components/ProcaptchaPoW.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAchE,OAAO,EAA4B,QAAQ,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAKjE,MAAM,gBAAgB,GAGlB,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC,CAAC;AAEtD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAsB,EAAE,EAAE,CAAC,CACxD,KAAC,QAAQ,IAAC,QAAQ,EAAE,KAAC,qBAAqB,IAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,GAAI,YAC1E,KAAC,gBAAgB,IAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,GAAI,GAC5D,CACX,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { ProcaptchaProps } from "@prosopo/types";
2
+ declare const Procaptcha: (props: ProcaptchaProps) => import("@emotion/react/jsx-runtime").JSX.Element;
3
+ export default Procaptcha;
4
+ //# sourceMappingURL=ProcaptchaWidget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProcaptchaWidget.d.ts","sourceRoot":"","sources":["../../src/components/ProcaptchaWidget.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAkCtD,QAAA,MAAM,UAAU,UAAW,eAAe,qDA4HzC,CAAC;AACF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
+ import { buildUpdateState, useProcaptcha } from "@prosopo/procaptcha-common";
3
+ import { Checkbox, ContainerDiv, LoadingSpinner, Logo, WIDGET_BORDER, WIDGET_BORDER_RADIUS, WIDGET_DIMENSIONS, WIDGET_INNER_HEIGHT, WIDGET_MAX_WIDTH, WIDGET_PADDING, WIDGET_URL, WIDGET_URL_TEXT, WidthBasedStylesDiv, darkTheme, lightTheme, } from "@prosopo/web-components";
4
+ import { useEffect, useRef, useState } from "react";
5
+ import { Manager } from "../Services/Manager.js";
6
+ const Procaptcha = (props) => {
7
+ const config = props.config;
8
+ const themeColor = config.theme === "light" ? "light" : "dark";
9
+ const theme = props.config.theme === "light" ? lightTheme : darkTheme;
10
+ const callbacks = props.callbacks || {};
11
+ const [state, _updateState] = useProcaptcha(useState, useRef);
12
+ const updateState = buildUpdateState(state, _updateState);
13
+ const manager = useRef(Manager(config, state, updateState, callbacks));
14
+ const captchaRef = useRef(null);
15
+ useEffect(() => {
16
+ const element = captchaRef.current;
17
+ if (!element)
18
+ return;
19
+ const form = element.closest("form");
20
+ if (!form)
21
+ return;
22
+ const handleSubmit = () => {
23
+ manager.current.resetState();
24
+ };
25
+ form.addEventListener("submit", handleSubmit);
26
+ return () => {
27
+ form.removeEventListener("submit", handleSubmit);
28
+ };
29
+ }, []);
30
+ return (_jsx("div", { ref: captchaRef, children: _jsx("div", { style: {
31
+ maxWidth: WIDGET_MAX_WIDTH,
32
+ maxHeight: "100%",
33
+ overflowX: "auto",
34
+ }, children: _jsx(ContainerDiv, { children: _jsx(WidthBasedStylesDiv, { children: _jsxs("div", { style: WIDGET_DIMENSIONS, "data-cy": "button-human", children: [" ", _jsxs("div", { style: {
35
+ padding: WIDGET_PADDING,
36
+ border: WIDGET_BORDER,
37
+ backgroundColor: theme.palette.background.default,
38
+ borderColor: theme.palette.grey[300],
39
+ borderRadius: WIDGET_BORDER_RADIUS,
40
+ display: "flex",
41
+ alignItems: "center",
42
+ flexWrap: "wrap",
43
+ justifyContent: "space-between",
44
+ minHeight: `${WIDGET_INNER_HEIGHT}px`,
45
+ overflow: "hidden",
46
+ }, children: [_jsx("div", { style: { display: "inline-flex", flexDirection: "column" }, children: _jsx("div", { style: {
47
+ display: "flex",
48
+ justifyContent: "flex-start",
49
+ alignItems: "center",
50
+ flexWrap: "wrap",
51
+ }, children: _jsx("div", { style: {
52
+ display: "flex",
53
+ alignItems: "center",
54
+ justifyContent: "center",
55
+ flexDirection: "column",
56
+ verticalAlign: "middle",
57
+ }, children: _jsx("div", { style: {
58
+ display: "flex",
59
+ }, children: _jsx("div", { style: { flex: 1 }, children: state.loading ? (_jsx(LoadingSpinner, { themeColor: themeColor, "aria-label": "Loading spinner" })) : (_jsx(Checkbox, { checked: state.isHuman, onChange: manager.current.start, themeColor: themeColor, labelText: "I am human", "aria-label": "human checkbox" })) }) }) }) }) }), _jsx("div", { style: { display: "inline-flex", flexDirection: "column" }, children: _jsx("a", { href: WIDGET_URL, target: "_blank", "aria-label": WIDGET_URL_TEXT, rel: "noreferrer", children: _jsx("div", { style: { flex: 1 }, children: _jsx(Logo, { themeColor: themeColor, "aria-label": "Prosopo logo" }) }) }) })] })] }) }) }) }) }));
60
+ };
61
+ export default Procaptcha;
62
+ //# sourceMappingURL=ProcaptchaWidget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProcaptchaWidget.js","sourceRoot":"","sources":["../../src/components/ProcaptchaWidget.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAe7E,OAAO,EACN,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,IAAI,EACJ,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,SAAS,EACT,UAAU,GACV,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,MAAM,UAAU,GAAG,CAAC,KAAsB,EAAE,EAAE;IAC7C,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;IAC/D,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;IACtE,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC;IACxC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,GAAG,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAE9D,MAAM,WAAW,GAAG,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Ac,GAAG,GACrD,GACH,GACC,IACD,IACD,GACe,GACR,GACV,GACD,CACN,CAAC;AACH,CAAC,CAAC;AACF,eAAe,UAAU,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './components/Captcha.js';
2
- export * from './components/ProcaptchaPoW.js';
1
+ export * from "./components/ProcaptchaWidget.js";
2
+ export * from "./components/ProcaptchaPoW.js";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,yBAAyB,CAAA;AACvC,cAAc,+BAA+B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,kCAAkC,CAAC;AACjD,cAAc,+BAA+B,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from './components/Captcha.js';
2
- export * from './components/ProcaptchaPoW.js';
1
+ export * from "./components/ProcaptchaWidget.js";
2
+ export * from "./components/ProcaptchaPoW.js";
3
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,yBAAyB,CAAA;AACvC,cAAc,+BAA+B,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,kCAAkC,CAAC;AACjD,cAAc,+BAA+B,CAAC"}
package/package.json CHANGED
@@ -1,76 +1,70 @@
1
1
  {
2
- "name": "@prosopo/procaptcha-pow",
3
- "version": "1.0.2",
4
- "author": "PROSOPO LIMITED <info@prosopo.io>",
5
- "license": "Apache-2.0",
6
- "main": "./dist/index.js",
7
- "type": "module",
8
- "sideEffects": false,
9
- "engines": {
10
- "node": ">=20",
11
- "npm": ">=9"
12
- },
13
- "exports": {
14
- ".": {
15
- "import": "./dist/index.js",
16
- "require": "./dist/cjs/index.cjs"
17
- }
18
- },
19
- "types": "./dist/index.d.ts",
20
- "source": "./src/index.ts",
21
- "scripts": {
22
- "test": "echo \"No test specified\"",
23
- "clean": "tsc --build --clean",
24
- "build": "tsc --build --verbose tsconfig.json",
25
- "build:cjs": "npx vite --config vite.cjs.config.ts build",
26
- "eslint": "npx eslint . --cache --cache-location ../../node_modules/.cache/eslint/.eslintcache --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore --quiet",
27
- "eslint:fix": "npm run eslint -- --fix",
28
- "prettier": "npx prettier . --cache --cache-location ../../node_modules/.cache/prettier/.prettiercache --check --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore",
29
- "prettier:fix": "npm run prettier -- --write",
30
- "lint": "npm run eslint && npm run prettier",
31
- "lint:fix": "npm run eslint:fix && npm run prettier:fix"
32
- },
33
- "browserslist": [
34
- "> 0.5%, last 2 versions, not dead"
35
- ],
36
- "dependencies": {
37
- "@emotion/react": "^11.11.1",
38
- "@prosopo/account": "1.0.2",
39
- "@polkadot/api": "10.13.1",
40
- "@polkadot/keyring": "12.6.2",
41
- "@polkadot/rpc-provider": "10.13.1",
42
- "@prosopo/api": "1.0.2",
43
- "@prosopo/captcha-contract": "1.0.2",
44
- "@prosopo/common": "1.0.2",
45
- "@prosopo/contract": "1.0.2",
46
- "@prosopo/procaptcha": "1.0.2",
47
- "@prosopo/procaptcha-common": "1.0.2",
48
- "@prosopo/types": "1.0.2",
49
- "@prosopo/util": "1.0.2",
50
- "@prosopo/web-components": "1.0.2",
51
- "react": "^18.3.1"
52
- },
53
- "overrides": {
54
- "@polkadot/extension-inject": {
55
- "@polkadot/api": {
56
- "version": "10.13.1"
57
- }
58
- }
59
- },
60
- "devDependencies": {
61
- "tslib": "2.6.2",
62
- "typescript": "5.1.6"
63
- },
64
- "repository": {
65
- "type": "git",
66
- "url": "git+https://github.com/prosopo/captcha.git"
67
- },
68
- "bugs": {
69
- "url": "https://github.com/prosopo/captcha/issues"
70
- },
71
- "homepage": "https://github.com/prosopo/captcha#readme",
72
- "description": "",
73
- "publishConfig": {
74
- "registry": "https://registry.npmjs.org"
75
- }
2
+ "name": "@prosopo/procaptcha-pow",
3
+ "version": "2.0.1",
4
+ "author": "PROSOPO LIMITED <info@prosopo.io>",
5
+ "license": "Apache-2.0",
6
+ "main": "./dist/index.js",
7
+ "type": "module",
8
+ "sideEffects": false,
9
+ "engines": {
10
+ "node": ">=20",
11
+ "npm": ">=9"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "import": "./dist/index.js",
16
+ "require": "./dist/cjs/index.cjs"
17
+ }
18
+ },
19
+ "types": "./dist/index.d.ts",
20
+ "source": "./src/index.ts",
21
+ "scripts": {
22
+ "test": "echo \"No test specified\"",
23
+ "clean": "tsc --build --clean",
24
+ "build": "tsc --build --verbose",
25
+ "build:cjs": "npx vite --config vite.cjs.config.ts build"
26
+ },
27
+ "browserslist": [
28
+ "> 0.5%, last 2 versions, not dead"
29
+ ],
30
+ "dependencies": {
31
+ "@emotion/react": "^11.11.1",
32
+ "@prosopo/account": "2.0.1",
33
+ "@polkadot/api": "10.13.1",
34
+ "@polkadot/keyring": "12.6.2",
35
+ "@polkadot/rpc-provider": "10.13.1",
36
+ "@prosopo/api": "2.0.1",
37
+ "@prosopo/common": "2.0.1",
38
+ "@prosopo/contract": "2.0.1",
39
+ "@prosopo/procaptcha": "2.0.1",
40
+ "@prosopo/procaptcha-common": "2.0.1",
41
+ "@prosopo/types": "2.0.1",
42
+ "@prosopo/util": "2.0.1",
43
+ "@prosopo/web-components": "2.0.1",
44
+ "react": "^18.3.1"
45
+ },
46
+ "overrides": {
47
+ "@polkadot/extension-inject": {
48
+ "@polkadot/api": {
49
+ "version": "10.13.1"
50
+ }
51
+ }
52
+ },
53
+ "devDependencies": {
54
+ "@prosopo/config": "2.0.1",
55
+ "tslib": "2.6.2",
56
+ "typescript": "5.1.6"
57
+ },
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "git+https://github.com/prosopo/captcha.git"
61
+ },
62
+ "bugs": {
63
+ "url": "https://github.com/prosopo/captcha/issues"
64
+ },
65
+ "homepage": "https://github.com/prosopo/captcha#readme",
66
+ "description": "",
67
+ "publishConfig": {
68
+ "registry": "https://registry.npmjs.org"
69
+ }
76
70
  }
@@ -1,3 +1,4 @@
1
+ import path from "node:path";
1
2
  // Copyright 2021-2024 Prosopo (UK) Ltd.
2
3
  //
3
4
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -11,9 +12,11 @@
11
12
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
13
  // See the License for the specific language governing permissions and
13
14
  // limitations under the License.
14
- import { ViteCommonJSConfig } from '@prosopo/config'
15
- import path from 'path'
15
+ import { ViteCommonJSConfig } from "@prosopo/config";
16
16
 
17
17
  export default function () {
18
- return ViteCommonJSConfig('procaptcha-pow', path.resolve('./tsconfig.cjs.json'))
18
+ return ViteCommonJSConfig(
19
+ "procaptcha-pow",
20
+ path.resolve("./tsconfig.cjs.json"),
21
+ );
19
22
  }
@@ -1,87 +0,0 @@
1
- "use strict";
2
- const jsxRuntime = require("@emotion/react/jsx-runtime");
3
- const webComponents = require("@prosopo/web-components");
4
- const Manager = require("../Services/Manager.cjs");
5
- const procaptchaCommon = require("@prosopo/procaptcha-common");
6
- const react = require("react");
7
- const Procaptcha = (props) => {
8
- const config = props.config;
9
- const themeColor = config.theme === "light" ? "light" : "dark";
10
- const theme = props.config.theme === "light" ? webComponents.lightTheme : webComponents.darkTheme;
11
- const callbacks = props.callbacks || {};
12
- const [state, _updateState] = procaptchaCommon.useProcaptcha(react.useState, react.useRef);
13
- const updateState = procaptchaCommon.buildUpdateState(state, _updateState);
14
- const manager = Manager.Manager(config, state, updateState, callbacks);
15
- return /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { maxWidth: "100%", maxHeight: "100%", overflowX: "auto" }, children: /* @__PURE__ */ jsxRuntime.jsx(webComponents.ContainerDiv, { children: /* @__PURE__ */ jsxRuntime.jsx(webComponents.WidthBasedStylesDiv, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: webComponents.WIDGET_DIMENSIONS, "data-cy": "button-human", children: [
16
- " ",
17
- /* @__PURE__ */ jsxRuntime.jsxs(
18
- "div",
19
- {
20
- style: {
21
- padding: webComponents.WIDGET_PADDING,
22
- border: webComponents.WIDGET_BORDER,
23
- backgroundColor: theme.palette.background.default,
24
- borderColor: theme.palette.grey[300],
25
- borderRadius: webComponents.WIDGET_BORDER_RADIUS,
26
- display: "flex",
27
- alignItems: "center",
28
- flexWrap: "wrap",
29
- justifyContent: "space-between",
30
- minHeight: `${webComponents.WIDGET_INNER_HEIGHT}px`,
31
- overflow: "hidden"
32
- },
33
- children: [
34
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "inline-flex", flexDirection: "column" }, children: /* @__PURE__ */ jsxRuntime.jsx(
35
- "div",
36
- {
37
- style: {
38
- display: "flex",
39
- justifyContent: "flex-start",
40
- alignItems: "center",
41
- flexWrap: "wrap"
42
- },
43
- children: /* @__PURE__ */ jsxRuntime.jsx(
44
- "div",
45
- {
46
- style: {
47
- display: "flex",
48
- alignItems: "center",
49
- justifyContent: "center",
50
- flexDirection: "column",
51
- verticalAlign: "middle"
52
- },
53
- children: /* @__PURE__ */ jsxRuntime.jsx(
54
- "div",
55
- {
56
- style: {
57
- display: "flex"
58
- },
59
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { flex: 1 }, children: state.loading ? /* @__PURE__ */ jsxRuntime.jsx(
60
- webComponents.LoadingSpinner,
61
- {
62
- themeColor,
63
- "aria-label": "Loading spinner"
64
- }
65
- ) : /* @__PURE__ */ jsxRuntime.jsx(
66
- webComponents.Checkbox,
67
- {
68
- checked: state.isHuman,
69
- onChange: manager.start,
70
- themeColor,
71
- labelText: "I am human",
72
- "aria-label": "human checkbox"
73
- }
74
- ) })
75
- }
76
- )
77
- }
78
- )
79
- }
80
- ) }),
81
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "inline-flex", flexDirection: "column" }, children: /* @__PURE__ */ jsxRuntime.jsx("a", { href: webComponents.WIDGET_URL, target: "_blank", "aria-label": webComponents.WIDGET_URL_TEXT, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { flex: 1 }, children: /* @__PURE__ */ jsxRuntime.jsx(webComponents.Logo, { themeColor, "aria-label": "Prosopo logo" }) }) }) })
82
- ]
83
- }
84
- )
85
- ] }) }) }) }) });
86
- };
87
- module.exports = Procaptcha;