@prosopo/procaptcha-frictionless 0.3.40 → 0.3.41

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.
@@ -14,6 +14,7 @@ const procaptcha = require("@prosopo/procaptcha");
14
14
  const util = require("@prosopo/util");
15
15
  const ExtensionWeb2 = require("../../../account/dist/extension/ExtensionWeb2.cjs");
16
16
  const Manager = (configInput, state, onStateUpdate, callbacks) => {
17
+ const events = procaptchaCommon.getDefaultEvents(onStateUpdate, state, callbacks);
17
18
  const defaultState = () => {
18
19
  return {
19
20
  showModal: false,
@@ -71,18 +72,19 @@ const Manager = (configInput, state, onStateUpdate, callbacks) => {
71
72
  const dappAccount = state.dappAccount;
72
73
  return dappAccount;
73
74
  };
74
- const getBlockNumber = () => {
75
- if (!state.blockNumber) {
76
- throw new common.ProsopoContractError("CAPTCHA.INVALID_BLOCK_NO", { context: { error: "Block number not found" } });
77
- }
78
- const blockNumber = state.blockNumber;
79
- return blockNumber;
80
- };
81
75
  const updateState = procaptchaCommon.buildUpdateState(state, onStateUpdate);
82
76
  const resetState = () => {
83
77
  clearTimeout();
84
78
  updateState(defaultState());
85
79
  };
80
+ const setValidChallengeTimeout = () => {
81
+ const timeMillis = getConfig().captchas.pow.solutionTimeout;
82
+ const successfullChallengeTimeout = setTimeout(() => {
83
+ updateState({ isHuman: false });
84
+ events.onExpired();
85
+ }, timeMillis);
86
+ updateState({ successfullChallengeTimeout });
87
+ };
86
88
  const start = async () => {
87
89
  if (state.loading) {
88
90
  return;
@@ -108,25 +110,26 @@ const Manager = (configInput, state, onStateUpdate, callbacks) => {
108
110
  });
109
111
  }
110
112
  const contract$1 = await loadContract();
111
- const events = procaptchaCommon.getDefaultEvents(onStateUpdate, state, callbacks);
113
+ const events2 = procaptchaCommon.getDefaultEvents(onStateUpdate, state, callbacks);
112
114
  const getRandomProviderResponse = await contract.wrapQuery(contract$1.query.getRandomActiveProvider, contract$1.query)(userAccount, getDappAccount());
113
115
  const providerUrl = common.trimProviderUrl(getRandomProviderResponse.provider.url.toString());
114
116
  const providerApi = new api.ProviderApi(getNetwork(getConfig()), providerUrl, getDappAccount());
115
117
  const challenge = await providerApi.getPowCaptchaChallenge(userAccount, getDappAccount());
116
118
  const solution = util.solvePoW(challenge.challenge, challenge.difficulty);
117
- const verifiedSolution = await providerApi.submitPowCaptchaSolution(challenge, getAccount().account.address, getDappAccount(), getRandomProviderResponse, solution);
119
+ const verifiedSolution = await providerApi.submitPowCaptchaSolution(challenge, getAccount().account.address, getDappAccount(), getRandomProviderResponse, solution, config.captchas.pow.verifiedTimeout);
118
120
  if (verifiedSolution[types.ApiParams.verified]) {
119
121
  updateState({
120
122
  isHuman: true,
121
123
  loading: false
122
124
  });
123
- events.onHuman({
125
+ events2.onHuman({
124
126
  providerUrl,
125
127
  [types.ApiParams.user]: getAccount().account.address,
126
128
  [types.ApiParams.dapp]: getDappAccount(),
127
129
  [types.ApiParams.challenge]: challenge.challenge,
128
130
  [types.ApiParams.blockNumber]: getRandomProviderResponse.blockNumber
129
131
  });
132
+ setValidChallengeTimeout();
130
133
  }
131
134
  };
132
135
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prosopo/procaptcha-frictionless",
3
- "version": "0.3.40",
3
+ "version": "0.3.41",
4
4
  "author": "PROSOPO LIMITED <info@prosopo.io>",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
@@ -35,10 +35,10 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@fingerprintjs/botd": "^1.9.0",
38
- "@prosopo/procaptcha-pow": "0.3.40",
39
- "@prosopo/procaptcha-react": "0.3.40",
40
- "@prosopo/types": "0.3.40",
41
- "@prosopo/web-components": "0.3.40",
38
+ "@prosopo/procaptcha-pow": "0.3.41",
39
+ "@prosopo/procaptcha-react": "0.3.41",
40
+ "@prosopo/types": "0.3.41",
41
+ "@prosopo/web-components": "0.3.41",
42
42
  "react": "^18.3.1"
43
43
  },
44
44
  "devDependencies": {