@prosopo/procaptcha 2.11.34 → 2.11.36
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/.turbo/turbo-build$colon$cjs.log +1 -1
- package/.turbo/{turbo-build.log → turbo-build$colon$esm.log} +9 -10
- package/.turbo/turbo-build$colon$tsc.log +19 -19
- package/.turbo/turbo-build$colon$types.log +1 -0
- package/CHANGELOG.md +34 -0
- package/dist/tsc/errorSites.d.ts.map +1 -0
- package/dist/{errorSites.js.map → tsc/errorSites.js.map} +1 -1
- package/dist/{index.d.ts.map → tsc/index.d.ts.map} +1 -1
- package/dist/tsc/index.js +2 -0
- package/dist/tsc/index.js.map +1 -0
- package/dist/tsc/modules/Manager.d.ts.map +1 -0
- package/dist/tsc/modules/Manager.js +445 -0
- package/dist/tsc/modules/Manager.js.map +1 -0
- package/dist/tsc/modules/ProsopoCaptchaApi.d.ts.map +1 -0
- package/dist/tsc/modules/ProsopoCaptchaApi.js +68 -0
- package/dist/tsc/modules/ProsopoCaptchaApi.js.map +1 -0
- package/dist/tsc/modules/collector.d.ts.map +1 -0
- package/dist/tsc/modules/collector.js +54 -0
- package/dist/tsc/modules/collector.js.map +1 -0
- package/dist/tsc/modules/index.d.ts.map +1 -0
- package/dist/tsc/modules/index.js +4 -0
- package/dist/tsc/modules/index.js.map +1 -0
- package/dist/tsc/tests/collector.unit.test.d.ts.map +1 -0
- package/dist/tsc/tests/collector.unit.test.js.map +1 -0
- package/dist/tsc/tests/manager.unit.test.d.ts.map +1 -0
- package/dist/tsc/tests/manager.unit.test.js.map +1 -0
- package/dist/tsc/tests/managerHarness.d.ts.map +1 -0
- package/dist/tsc/tests/managerHarness.js.map +1 -0
- package/dist/tsc/tests/procaptcha.test-d.d.ts.map +1 -0
- package/dist/tsc/tests/procaptcha.test-d.js.map +1 -0
- package/dist/tsc/tests/prosopoCaptchaApi.unit.test.d.ts.map +1 -0
- package/dist/tsc/tests/prosopoCaptchaApi.unit.test.js.map +1 -0
- package/dist/types/errorSites.d.ts +24 -0
- package/dist/types/errorSites.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/modules/Manager.d.ts +11 -0
- package/dist/types/modules/Manager.d.ts.map +1 -0
- package/dist/types/modules/ProsopoCaptchaApi.d.ts +16 -0
- package/dist/types/modules/ProsopoCaptchaApi.d.ts.map +1 -0
- package/dist/types/modules/collector.d.ts +8 -0
- package/dist/types/modules/collector.d.ts.map +1 -0
- package/dist/types/modules/index.d.ts +4 -0
- package/dist/types/modules/index.d.ts.map +1 -0
- package/dist/types/tests/collector.unit.test.d.ts +2 -0
- package/dist/types/tests/collector.unit.test.d.ts.map +1 -0
- package/dist/types/tests/manager.unit.test.d.ts +2 -0
- package/dist/types/tests/manager.unit.test.d.ts.map +1 -0
- package/dist/types/tests/managerHarness.d.ts +18 -0
- package/dist/types/tests/managerHarness.d.ts.map +1 -0
- package/dist/types/tests/procaptcha.test-d.d.ts +2 -0
- package/dist/types/tests/procaptcha.test-d.d.ts.map +1 -0
- package/dist/types/tests/prosopoCaptchaApi.unit.test.d.ts +2 -0
- package/dist/types/tests/prosopoCaptchaApi.unit.test.d.ts.map +1 -0
- package/package.json +21 -22
- package/dist/errorSites.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/modules/Manager.d.ts.map +0 -1
- package/dist/modules/Manager.js.map +0 -1
- package/dist/modules/ProsopoCaptchaApi.d.ts.map +0 -1
- package/dist/modules/ProsopoCaptchaApi.js.map +0 -1
- package/dist/modules/collector.d.ts.map +0 -1
- package/dist/modules/collector.js.map +0 -1
- package/dist/modules/index.d.ts.map +0 -1
- package/dist/modules/index.js.map +0 -1
- package/dist/tests/collector.unit.test.d.ts.map +0 -1
- package/dist/tests/collector.unit.test.js.map +0 -1
- package/dist/tests/manager.unit.test.d.ts.map +0 -1
- package/dist/tests/manager.unit.test.js.map +0 -1
- package/dist/tests/managerHarness.d.ts.map +0 -1
- package/dist/tests/managerHarness.js.map +0 -1
- package/dist/tests/procaptcha.test-d.d.ts.map +0 -1
- package/dist/tests/procaptcha.test-d.js.map +0 -1
- package/dist/tests/prosopoCaptchaApi.unit.test.d.ts.map +0 -1
- package/dist/tests/prosopoCaptchaApi.unit.test.js.map +0 -1
- /package/dist/{_virtual → esm/_virtual}/_rolldown/runtime.js +0 -0
- /package/dist/{index.js → esm/index.js} +0 -0
- /package/dist/{modules → esm/modules}/Manager.js +0 -0
- /package/dist/{modules → esm/modules}/ProsopoCaptchaApi.js +0 -0
- /package/dist/{modules → esm/modules}/collector.js +0 -0
- /package/dist/{modules → esm/modules}/index.js +0 -0
- /package/dist/{errorSites.d.ts → tsc/errorSites.d.ts} +0 -0
- /package/dist/{errorSites.js → tsc/errorSites.js} +0 -0
- /package/dist/{index.d.ts → tsc/index.d.ts} +0 -0
- /package/dist/{modules → tsc/modules}/Manager.d.ts +0 -0
- /package/dist/{modules → tsc/modules}/ProsopoCaptchaApi.d.ts +0 -0
- /package/dist/{modules → tsc/modules}/collector.d.ts +0 -0
- /package/dist/{modules → tsc/modules}/index.d.ts +0 -0
- /package/dist/{tests → tsc/tests}/collector.unit.test.d.ts +0 -0
- /package/dist/{tests → tsc/tests}/collector.unit.test.js +0 -0
- /package/dist/{tests → tsc/tests}/manager.unit.test.d.ts +0 -0
- /package/dist/{tests → tsc/tests}/manager.unit.test.js +0 -0
- /package/dist/{tests → tsc/tests}/managerHarness.d.ts +0 -0
- /package/dist/{tests → tsc/tests}/managerHarness.js +0 -0
- /package/dist/{tests → tsc/tests}/procaptcha.test-d.d.ts +0 -0
- /package/dist/{tests → tsc/tests}/procaptcha.test-d.js +0 -0
- /package/dist/{tests → tsc/tests}/prosopoCaptchaApi.unit.test.d.ts +0 -0
- /package/dist/{tests → tsc/tests}/prosopoCaptchaApi.unit.test.js +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
$
|
|
2
|
-
$ vite build --config vite.esm.config.ts --mode production
|
|
1
|
+
$ vite build --config vite.esm.config.ts --mode ${NODE_ENV:-development}
|
|
3
2
|
ViteEsmConfig: .
|
|
4
3
|
{
|
|
5
4
|
tsConfigPaths: [
|
|
@@ -20,7 +19,6 @@ ViteEsmConfig: .
|
|
|
20
19
|
'/home/runner/work/captcha/captcha/packages/keyring/tsconfig.json'
|
|
21
20
|
]
|
|
22
21
|
}
|
|
23
|
-
[33mThe plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the [1mresolve.tsconfigPaths[22m option. You can remove the plugin and set [1mresolve.tsconfigPaths: true[22m in your Vite config instead.[39m
|
|
24
22
|
{
|
|
25
23
|
externals: [
|
|
26
24
|
'@prosopo/datasets',
|
|
@@ -40,17 +38,18 @@ ViteEsmConfig: .
|
|
|
40
38
|
'@prosopo/keyring'
|
|
41
39
|
]
|
|
42
40
|
}
|
|
41
|
+
[33mThe plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the [1mresolve.tsconfigPaths[22m option. You can remove the plugin and set [1mresolve.tsconfigPaths: true[22m in your Vite config instead.[39m
|
|
43
42
|
[36mvite v8.1.6 [32mbuilding ssr environment for production...[36m[39m
|
|
44
43
|
Bundle build started
|
|
45
44
|
[2K
|
|
46
45
|
✓ 6 modules transformed.
|
|
47
46
|
rendering chunks...
|
|
48
47
|
computing gzip size...
|
|
49
|
-
dist/_virtual/_rolldown/runtime.js 0.04 kB │ gzip: 0.06 kB
|
|
50
|
-
dist/modules/index.js 0.20 kB │ gzip: 0.11 kB
|
|
51
|
-
dist/index.js 0.27 kB │ gzip: 0.14 kB
|
|
52
|
-
dist/modules/collector.js 1.81 kB │ gzip: 0.59 kB
|
|
53
|
-
dist/modules/ProsopoCaptchaApi.js 2.23 kB │ gzip: 0.80 kB
|
|
54
|
-
dist/modules/Manager.js 15.49 kB │ gzip: 4.32 kB
|
|
48
|
+
dist/esm/_virtual/_rolldown/runtime.js 0.04 kB │ gzip: 0.06 kB
|
|
49
|
+
dist/esm/modules/index.js 0.20 kB │ gzip: 0.11 kB
|
|
50
|
+
dist/esm/index.js 0.27 kB │ gzip: 0.14 kB
|
|
51
|
+
dist/esm/modules/collector.js 1.81 kB │ gzip: 0.59 kB
|
|
52
|
+
dist/esm/modules/ProsopoCaptchaApi.js 2.23 kB │ gzip: 0.80 kB
|
|
53
|
+
dist/esm/modules/Manager.js 15.49 kB │ gzip: 4.32 kB
|
|
55
54
|
|
|
56
|
-
[32m✓ built in
|
|
55
|
+
[32m✓ built in 60ms[39m
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
$ tsc --build --verbose
|
|
2
|
-
|
|
2
|
+
11:54:44 AM - Projects in this build:
|
|
3
3
|
* ../../dev/config/tsconfig.json
|
|
4
4
|
* ../util/tsconfig.json
|
|
5
5
|
* ../locale/tsconfig.json
|
|
@@ -18,39 +18,39 @@ $ tsc --build --verbose
|
|
|
18
18
|
* ../procaptcha-common/tsconfig.json
|
|
19
19
|
* tsconfig.json
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
11:54:44 AM - Project '../../dev/config/tsconfig.json' is up to date because newest input '../../dev/config/src/webpack/webpack.config.ts' is older than output '../../dev/config/dist/tsc/tsconfig.tsbuildinfo'
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
11:54:44 AM - Project '../util/tsconfig.json' is up to date because newest input '../util/src/url.ts' is older than output '../util/dist/tsc/tsconfig.tsbuildinfo'
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
11:54:44 AM - Project '../locale/tsconfig.json' is up to date because newest input '../locale/src/process.ts' is older than output '../locale/dist/tsc/tsconfig.tsbuildinfo'
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
11:54:44 AM - Project '../util-crypto/tsconfig.json' is up to date because newest input '../util-crypto/src/types.ts' is older than output '../util-crypto/dist/tsc/tsconfig.tsbuildinfo'
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
11:54:44 AM - Project '../types/tsconfig.json' is up to date because newest input '../types/src/types.test-d.ts' is older than output '../types/dist/tsc/tsconfig.tsbuildinfo'
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
11:54:44 AM - Project '../common/tsconfig.json' is up to date because newest input '../common/src/error.ts' is older than output '../common/dist/tsc/tsconfig.tsbuildinfo'
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
11:54:44 AM - Project '../logger/tsconfig.json' is up to date because newest input '../logger/src/index.ts' is older than output '../logger/dist/tsc/tsconfig.tsbuildinfo'
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
11:54:45 AM - Project '../datasets/tsconfig.json' is up to date because newest input '../datasets/src/errorSites.ts' is older than output '../datasets/dist/tsc/tsconfig.tsbuildinfo'
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
11:54:45 AM - Project '../api/tsconfig.json' is up to date because newest input '../api/src/tests/apiHarness.ts' is older than output '../api/dist/tsc/tsconfig.tsbuildinfo'
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
11:54:45 AM - Project '../load-balancer/tsconfig.json' is up to date because newest input '../load-balancer/src/balancer.ts' is older than output '../load-balancer/dist/tsc/tsconfig.tsbuildinfo'
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
11:54:45 AM - Project '../widget-skeleton/tsconfig.json' is up to date because newest input '../widget-skeleton/src/webComponent/createWidget.ts' is older than output '../widget-skeleton/dist/tsc/tsconfig.tsbuildinfo'
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
11:54:45 AM - Project '../fingerprintjs/tsconfig.json' is up to date because newest input '../fingerprintjs/src/utils/browser.ts' is older than output '../fingerprintjs/dist/tsc/tsconfig.tsbuildinfo'
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
11:54:45 AM - Project '../fingerprint/tsconfig.json' is up to date because newest input '../fingerprint/src/index.test.ts' is older than output '../fingerprint/dist/tsc/tsconfig.tsbuildinfo'
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
11:54:45 AM - Project '../keyring/tsconfig.json' is up to date because newest input '../keyring/src/errorSites.ts' is older than output '../keyring/dist/tsc/tsconfig.tsbuildinfo'
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
11:54:45 AM - Project '../account/tsconfig.json' is up to date because newest input '../account/src/custom.d.ts' is older than output '../account/dist/tsc/tsconfig.tsbuildinfo'
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
11:54:45 AM - Project '../procaptcha-common/tsconfig.json' is up to date because newest input '../procaptcha-common/src/extensionLoader.ts' is older than output '../procaptcha-common/dist/tsc/tsconfig.tsbuildinfo'
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
11:54:45 AM - Project 'tsconfig.json' is out of date because output file 'dist/tsc/tsconfig.tsbuildinfo' does not exist
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
11:54:45 AM - Building project '/home/runner/work/captcha/captcha/packages/procaptcha/tsconfig.json'...
|
|
56
56
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
$ tsc --project tsconfig.types.json
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @prosopo/procaptcha
|
|
2
2
|
|
|
3
|
+
## 2.11.36
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- 2086040: Each kind of build now writes to its own folder under dist: dist/esm (vite ESM), dist/cjs (vite CommonJS), dist/types (declarations), dist/tsc (plain tsc), dist/bundle and dist/bundle-webpack (bundles) and dist/native (the Rust addons). Turbo caches each folder separately, so building one variant no longer overwrites or invalidates another. Package exports point at the new folders; anything importing a file from dist by path has to add the variant folder.
|
|
7
|
+
|
|
8
|
+
The Rust addons are no longer committed. They are built into dist/native, in debug for development and tests and fully optimised when NODE_ENV=production, so building them now needs a Rust toolchain.
|
|
9
|
+
|
|
10
|
+
Code that found the repo root or its certificates by climbing a fixed number of folders up from its own file now starts from its package's folder instead (new `packageDir` in @prosopo/util/node). The fixed count stopped working once the build output moved one folder deeper.
|
|
11
|
+
- Updated dependencies [2086040]
|
|
12
|
+
- Updated dependencies [915f30b]
|
|
13
|
+
- @prosopo/api@4.7.7
|
|
14
|
+
- @prosopo/common@3.3.1
|
|
15
|
+
- @prosopo/datasets@3.2.12
|
|
16
|
+
- @prosopo/load-balancer@2.11.16
|
|
17
|
+
- @prosopo/locale@3.13.1
|
|
18
|
+
- @prosopo/procaptcha-common@2.21.9
|
|
19
|
+
- @prosopo/types@5.19.0
|
|
20
|
+
- @prosopo/util-crypto@13.6.2
|
|
21
|
+
- @prosopo/util@3.3.17
|
|
22
|
+
|
|
23
|
+
## 2.11.35
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [b460b0b]
|
|
27
|
+
- Updated dependencies [159766a]
|
|
28
|
+
- Updated dependencies [96dbf9a]
|
|
29
|
+
- @prosopo/locale@3.13.0
|
|
30
|
+
- @prosopo/types@5.18.0
|
|
31
|
+
- @prosopo/procaptcha-common@2.21.8
|
|
32
|
+
- @prosopo/api@4.7.6
|
|
33
|
+
- @prosopo/common@3.3.0
|
|
34
|
+
- @prosopo/datasets@3.2.11
|
|
35
|
+
- @prosopo/load-balancer@2.11.15
|
|
36
|
+
|
|
3
37
|
## 2.11.34
|
|
4
38
|
### Patch Changes
|
|
5
39
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorSites.d.ts","sourceRoot":"","sources":["../../src/errorSites.ts"],"names":[],"mappings":"AAcA,OAAO,QAAQ,iBAAiB,CAAC;IAChC,UAAU,UAAU;QACnB,QAAQ,EAAE,IAAI,CAAC;QACf,QAAQ,EAAE,IAAI,CAAC;QACf,QAAQ,EAAE,IAAI,CAAC;QACf,QAAQ,EAAE,IAAI,CAAC;QACf,QAAQ,EAAE,IAAI,CAAC;QACf,QAAQ,EAAE,IAAI,CAAC;QACf,QAAQ,EAAE,IAAI,CAAC;QACf,QAAQ,EAAE,IAAI,CAAC;QACf,QAAQ,EAAE,IAAI,CAAC;QACf,SAAS,EAAE,IAAI,CAAC;QAChB,SAAS,EAAE,IAAI,CAAC;QAChB,SAAS,EAAE,IAAI,CAAC;QAChB,SAAS,EAAE,IAAI,CAAC;QAChB,SAAS,EAAE,IAAI,CAAC;QAChB,SAAS,EAAE,IAAI,CAAC;QAChB,SAAS,EAAE,IAAI,CAAC;QAChB,SAAS,EAAE,IAAI,CAAC;QAChB,SAAS,EAAE,IAAI,CAAC;KAChB;CACD;AAED,OAAO,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorSites.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"errorSites.js","sourceRoot":"","sources":["../../src/errorSites.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Manager.d.ts","sourceRoot":"","sources":["../../../src/modules/Manager.ts"],"names":[],"mappings":"AA4BA,OAAO,EAMN,KAAK,iBAAiB,EACtB,WAAW,EACX,KAAK,mBAAmB,EAExB,KAAK,4BAA4B,EAEjC,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAG5B,MAAM,gBAAgB,CAAC;AAwBxB,wBAAgB,OAAO,CACtB,cAAc,EAAE,4BAA4B,EAC5C,KAAK,EAAE,eAAe,EACtB,aAAa,EAAE,uBAAuB,EACtC,SAAS,EAAE,mBAAmB,EAC9B,iBAAiB,CAAC,EAAE,iBAAiB,EAGrC,gBAAgB,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,EAM3C,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI;kEAiDpC,WAAW;;;mBAmZlB,MAAM,MACR,MAAM,MACN,MAAM,gBACG,WAAW;;;;EAmNzB"}
|
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { stringToHex } from "@polkadot/util/string";
|
|
2
|
+
import { ProviderApi } from "@prosopo/api";
|
|
3
|
+
import { ProsopoError, toPublicError } from "@prosopo/common";
|
|
4
|
+
import { widgetLanguageHeaders } from "@prosopo/locale";
|
|
5
|
+
import { ExtensionLoader, buildClientMetaData, buildUpdateState, getDefaultEvents, getProcaptchaRandomActiveProvider, getSimdReadingsForSubmit, pickIpMode, providerRetry, } from "@prosopo/procaptcha-common";
|
|
6
|
+
import { ApiParams, CaptchaType, InputMethod, ProcaptchaConfigSchema, encodeProcaptchaOutput, } from "@prosopo/types";
|
|
7
|
+
import { at, embedData, hashToHex } from "@prosopo/util";
|
|
8
|
+
import { sleep } from "@prosopo/util";
|
|
9
|
+
import { randomAsHex } from "@prosopo/util-crypto";
|
|
10
|
+
import ProsopoCaptchaApi from "./ProsopoCaptchaApi.js";
|
|
11
|
+
const defaultState = () => {
|
|
12
|
+
return {
|
|
13
|
+
showModal: false,
|
|
14
|
+
loading: false,
|
|
15
|
+
index: 0,
|
|
16
|
+
challenge: undefined,
|
|
17
|
+
solutions: undefined,
|
|
18
|
+
isHuman: false,
|
|
19
|
+
captchaApi: undefined,
|
|
20
|
+
account: undefined,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export function Manager(configOptional, state, onStateUpdate, callbacks, frictionlessState, getHoneypotValue, onReloadRequest) {
|
|
24
|
+
const events = getDefaultEvents(callbacks);
|
|
25
|
+
const updateState = buildUpdateState(state, onStateUpdate);
|
|
26
|
+
let checkboxClickX = 0;
|
|
27
|
+
let checkboxClickY = 0;
|
|
28
|
+
let checkboxInputMethod = InputMethod.pointer;
|
|
29
|
+
let previousProviderUrl;
|
|
30
|
+
let spentSessionId;
|
|
31
|
+
const getConfig = () => {
|
|
32
|
+
const config = {
|
|
33
|
+
userAccountAddress: "",
|
|
34
|
+
...configOptional,
|
|
35
|
+
};
|
|
36
|
+
if (state.account) {
|
|
37
|
+
config.userAccountAddress = state.account.account.address;
|
|
38
|
+
}
|
|
39
|
+
return ProcaptchaConfigSchema.parse(config);
|
|
40
|
+
};
|
|
41
|
+
const start = async (checkboxX = 0, checkboxY = 0, inputMethod = InputMethod.pointer) => {
|
|
42
|
+
checkboxClickX = checkboxX;
|
|
43
|
+
checkboxClickY = checkboxY;
|
|
44
|
+
if (state.answeredIncorrectly) {
|
|
45
|
+
updateState({ answeredIncorrectly: false });
|
|
46
|
+
}
|
|
47
|
+
checkboxInputMethod = inputMethod;
|
|
48
|
+
events.onOpen();
|
|
49
|
+
await providerRetry(async () => {
|
|
50
|
+
if (state.loading) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (state.isHuman) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
updateState({ loading: true });
|
|
57
|
+
updateState({
|
|
58
|
+
attemptCount: state.attemptCount ? state.attemptCount + 1 : 1,
|
|
59
|
+
});
|
|
60
|
+
updateState({
|
|
61
|
+
sessionId: frictionlessState?.sessionId,
|
|
62
|
+
});
|
|
63
|
+
const config = getConfig();
|
|
64
|
+
updateState({ dappAccount: config.account.address });
|
|
65
|
+
await sleep(100);
|
|
66
|
+
const account = await loadAccount();
|
|
67
|
+
let captchaApi = state.captchaApi;
|
|
68
|
+
if (!frictionlessState?.provider) {
|
|
69
|
+
const currentConfig = getConfig();
|
|
70
|
+
const getRandomProviderResponse = await getProcaptchaRandomActiveProvider(currentConfig.defaultEnvironment, pickIpMode(currentConfig), { attempt: state.attemptCount, excludeUrl: previousProviderUrl });
|
|
71
|
+
const providerUrl = getRandomProviderResponse.provider.url;
|
|
72
|
+
previousProviderUrl = providerUrl;
|
|
73
|
+
const { providerApi, siteKey } = await loadProviderApi(providerUrl);
|
|
74
|
+
captchaApi = new ProsopoCaptchaApi(account.account.address, getRandomProviderResponse, providerApi, config.web2, siteKey);
|
|
75
|
+
updateState({ captchaApi });
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const providerUrl = frictionlessState.provider.provider.url;
|
|
79
|
+
const { providerApi, siteKey } = await loadProviderApi(providerUrl);
|
|
80
|
+
captchaApi = new ProsopoCaptchaApi(account.account.address, frictionlessState.provider, providerApi, config.web2, siteKey);
|
|
81
|
+
updateState({ captchaApi });
|
|
82
|
+
}
|
|
83
|
+
if (state.sessionId && state.sessionId === spentSessionId) {
|
|
84
|
+
updateState({
|
|
85
|
+
loading: false,
|
|
86
|
+
error: toPublicError(new ProsopoError({
|
|
87
|
+
code: "NO_SESSION_FOUND",
|
|
88
|
+
errorSite: "PCAP-18",
|
|
89
|
+
}), "FRONTEND_ERROR"),
|
|
90
|
+
});
|
|
91
|
+
events.onError(new Error("No session found"));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const simdReadingsOnChallenge = frictionlessState?.getSimdReadings
|
|
95
|
+
? await frictionlessState.getSimdReadings(0)
|
|
96
|
+
: undefined;
|
|
97
|
+
const challengeSessionId = state.sessionId;
|
|
98
|
+
if (challengeSessionId)
|
|
99
|
+
spentSessionId = challengeSessionId;
|
|
100
|
+
const challenge = await captchaApi?.getCaptchaChallenge(challengeSessionId, simdReadingsOnChallenge);
|
|
101
|
+
if (challenge.error) {
|
|
102
|
+
updateState({
|
|
103
|
+
loading: false,
|
|
104
|
+
error: challenge.error,
|
|
105
|
+
});
|
|
106
|
+
events.onError(new Error(challenge.error?.message));
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
if (challenge.captchas.length <= 0) {
|
|
110
|
+
throw new ProsopoError({
|
|
111
|
+
code: "RECORD_NOT_FOUND",
|
|
112
|
+
errorSite: "PCAP-1",
|
|
113
|
+
message: "No captchas returned from provider",
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const timeMillis = challenge.captchas
|
|
117
|
+
.map((captcha) => captcha.timeLimitMs || config.captchas.image.challengeTimeout)
|
|
118
|
+
.reduce((a, b) => a + b);
|
|
119
|
+
const timeout = setTimeout(() => {
|
|
120
|
+
if (disposed)
|
|
121
|
+
return;
|
|
122
|
+
events.onChallengeExpired();
|
|
123
|
+
updateState({ isHuman: false, showModal: false, loading: false });
|
|
124
|
+
}, timeMillis);
|
|
125
|
+
updateState({
|
|
126
|
+
index: 0,
|
|
127
|
+
solutions: challenge.captchas.map(() => []),
|
|
128
|
+
challenge,
|
|
129
|
+
showModal: true,
|
|
130
|
+
timeout,
|
|
131
|
+
loading: false,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}, start, resetState, state.attemptCount, 10);
|
|
135
|
+
};
|
|
136
|
+
const submit = async () => {
|
|
137
|
+
await providerRetry(async () => {
|
|
138
|
+
clearTimeout();
|
|
139
|
+
if (!state.challenge) {
|
|
140
|
+
throw new ProsopoError({
|
|
141
|
+
code: "RECORD_NOT_FOUND",
|
|
142
|
+
errorSite: "PCAP-2",
|
|
143
|
+
message: "No captcha found",
|
|
144
|
+
context: { error: "Cannot submit, no Captcha found in state" },
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
updateState({ showModal: false });
|
|
148
|
+
const challenge = state.challenge;
|
|
149
|
+
const captchaSolution = state.challenge.captchas.map((captcha, index) => {
|
|
150
|
+
const solution = at(state.solutions, index);
|
|
151
|
+
const shapeCoords = solution.flatMap(([_, x, y]) => [x, y]);
|
|
152
|
+
const shapeInputMethods = solution.map(([, , , inputMethod]) => inputMethod);
|
|
153
|
+
const coords = index === 0
|
|
154
|
+
? [checkboxClickX, checkboxClickY, ...shapeCoords]
|
|
155
|
+
: shapeCoords;
|
|
156
|
+
const inputMethods = index === 0
|
|
157
|
+
? [checkboxInputMethod, ...shapeInputMethods]
|
|
158
|
+
: shapeInputMethods;
|
|
159
|
+
const countByte = 1;
|
|
160
|
+
const salt = randomAsHex(coords
|
|
161
|
+
.map((x) => x.toString(16).length + 4)
|
|
162
|
+
.reduce((acc, curr) => acc + curr, countByte));
|
|
163
|
+
const saltCoord = embedData(salt, coords);
|
|
164
|
+
return {
|
|
165
|
+
captchaId: captcha.captchaId,
|
|
166
|
+
captchaContentId: captcha.captchaContentId,
|
|
167
|
+
salt: saltCoord,
|
|
168
|
+
solution: solution.flatMap((s) => s[0]),
|
|
169
|
+
inputMethods,
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
const account = getAccount();
|
|
173
|
+
const signer = getExtension(account).signer;
|
|
174
|
+
const first = at(challenge.captchas, 0);
|
|
175
|
+
if (!first.datasetId) {
|
|
176
|
+
throw new ProsopoError({
|
|
177
|
+
code: "INVALID_DATA",
|
|
178
|
+
errorSite: "PCAP-3",
|
|
179
|
+
message: "Invalid captcha id",
|
|
180
|
+
context: { error: "No datasetId set for challenge" },
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
const captchaApi = state.captchaApi;
|
|
184
|
+
if (!captchaApi) {
|
|
185
|
+
throw new ProsopoError({
|
|
186
|
+
code: "INVALID_REQUEST",
|
|
187
|
+
errorSite: "PCAP-4",
|
|
188
|
+
message: "Invalid token",
|
|
189
|
+
context: { error: "No Captcha API found in state" },
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
if (!signer || !signer.signRaw) {
|
|
193
|
+
throw new ProsopoError({
|
|
194
|
+
code: "CONFIG_INVALID",
|
|
195
|
+
errorSite: "PCAP-5",
|
|
196
|
+
message: "Can't find the keyringpair for {{address}}",
|
|
197
|
+
context: {
|
|
198
|
+
error: "Signer is not defined, cannot sign message to prove account ownership",
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
const userTimestampSignature = await signer.signRaw({
|
|
203
|
+
address: account.account.address,
|
|
204
|
+
data: stringToHex(challenge[ApiParams.timestamp]),
|
|
205
|
+
type: "bytes",
|
|
206
|
+
});
|
|
207
|
+
let encryptedBehavioralData;
|
|
208
|
+
if (frictionlessState?.encryptBehavioralData &&
|
|
209
|
+
(frictionlessState?.behaviorCollector1 ||
|
|
210
|
+
frictionlessState?.behaviorCollector2 ||
|
|
211
|
+
frictionlessState?.behaviorCollector3 ||
|
|
212
|
+
frictionlessState?.behaviorCollector4)) {
|
|
213
|
+
try {
|
|
214
|
+
const behavioralData = {
|
|
215
|
+
collector1: frictionlessState.behaviorCollector1?.getData() || [],
|
|
216
|
+
collector2: frictionlessState.behaviorCollector2?.getData() || [],
|
|
217
|
+
collector3: frictionlessState.behaviorCollector3?.getData() || [],
|
|
218
|
+
collector4: frictionlessState.behaviorCollector4?.getData() || [],
|
|
219
|
+
deviceCapability: frictionlessState.deviceCapability || "unknown",
|
|
220
|
+
};
|
|
221
|
+
const dataToEncrypt = frictionlessState.packBehavioralData
|
|
222
|
+
? frictionlessState.packBehavioralData(behavioralData)
|
|
223
|
+
: behavioralData;
|
|
224
|
+
encryptedBehavioralData =
|
|
225
|
+
await frictionlessState.encryptBehavioralData(JSON.stringify(dataToEncrypt));
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const simdReadings = await getSimdReadingsForSubmit(frictionlessState);
|
|
231
|
+
const clientMetaData = buildClientMetaData(getHoneypotValue?.(), getConfig().clientSessionId);
|
|
232
|
+
const submission = await captchaApi.submitCaptchaSolution(userTimestampSignature.signature, challenge.requestHash, captchaSolution, challenge.timestamp, challenge.signature.provider.requestHash, encryptedBehavioralData, simdReadings, clientMetaData);
|
|
233
|
+
if (disposed)
|
|
234
|
+
return;
|
|
235
|
+
const isHuman = submission[0].verified;
|
|
236
|
+
updateState({
|
|
237
|
+
submission,
|
|
238
|
+
isHuman,
|
|
239
|
+
loading: false,
|
|
240
|
+
});
|
|
241
|
+
if (state.isHuman) {
|
|
242
|
+
const providerUrl = captchaApi.provider.provider.url;
|
|
243
|
+
events.onHuman(encodeProcaptchaOutput({
|
|
244
|
+
[ApiParams.providerUrl]: providerUrl,
|
|
245
|
+
[ApiParams.user]: account.account.address,
|
|
246
|
+
[ApiParams.dapp]: getDappAccount(),
|
|
247
|
+
[ApiParams.commitmentId]: hashToHex(submission[1]),
|
|
248
|
+
[ApiParams.timestamp]: challenge.timestamp,
|
|
249
|
+
[ApiParams.signature]: {
|
|
250
|
+
[ApiParams.provider]: {
|
|
251
|
+
[ApiParams.requestHash]: challenge.signature.provider.requestHash,
|
|
252
|
+
},
|
|
253
|
+
[ApiParams.user]: {
|
|
254
|
+
[ApiParams.timestamp]: userTimestampSignature.signature,
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
[ApiParams.captchaType]: CaptchaType.image,
|
|
258
|
+
}));
|
|
259
|
+
setValidChallengeTimeout();
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
events.onFailed();
|
|
263
|
+
updateState({ answeredIncorrectly: true });
|
|
264
|
+
resetState(frictionlessState
|
|
265
|
+
? () => frictionlessState.restart({ showRetry: true })
|
|
266
|
+
: undefined);
|
|
267
|
+
}
|
|
268
|
+
}, start, resetState, state.attemptCount, 10);
|
|
269
|
+
};
|
|
270
|
+
const cancel = async () => {
|
|
271
|
+
clearTimeout();
|
|
272
|
+
resetState(frictionlessState?.restart);
|
|
273
|
+
events.onClose();
|
|
274
|
+
};
|
|
275
|
+
const reload = async () => {
|
|
276
|
+
clearTimeout();
|
|
277
|
+
events.onReload();
|
|
278
|
+
if (onReloadRequest) {
|
|
279
|
+
resetState();
|
|
280
|
+
onReloadRequest(checkboxClickX, checkboxClickY);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
resetState(frictionlessState?.restart);
|
|
284
|
+
if (!frictionlessState?.restart) {
|
|
285
|
+
await start(checkboxClickX, checkboxClickY, checkboxInputMethod);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
const select = (hash, x, y, inputMethod = InputMethod.pointer) => {
|
|
289
|
+
if (!state.challenge) {
|
|
290
|
+
throw new ProsopoError({
|
|
291
|
+
code: "RECORD_NOT_FOUND",
|
|
292
|
+
errorSite: "PCAP-6",
|
|
293
|
+
message: "No captcha found",
|
|
294
|
+
context: { error: "Cannot select, no Captcha found in state" },
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
if (state.index >= state.challenge.captchas.length || state.index < 0) {
|
|
298
|
+
throw new ProsopoError({
|
|
299
|
+
code: "RECORD_NOT_FOUND",
|
|
300
|
+
errorSite: "PCAP-7",
|
|
301
|
+
message: "No captcha found",
|
|
302
|
+
context: {
|
|
303
|
+
error: "Cannot select, index is out of range for this Captcha",
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
const index = state.index;
|
|
308
|
+
const solutions = state.solutions;
|
|
309
|
+
const solution = at(solutions, index);
|
|
310
|
+
if (solution.some((s) => s[0] === hash)) {
|
|
311
|
+
const newSolution = solution.filter((s) => s[0] !== hash);
|
|
312
|
+
solutions[index] = newSolution;
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
solutions[index] = [...solution, [hash, x || 0, y || 0, inputMethod]];
|
|
316
|
+
}
|
|
317
|
+
updateState({ solutions });
|
|
318
|
+
};
|
|
319
|
+
const nextRound = () => {
|
|
320
|
+
if (!state.challenge) {
|
|
321
|
+
throw new ProsopoError({
|
|
322
|
+
code: "RECORD_NOT_FOUND",
|
|
323
|
+
errorSite: "PCAP-8",
|
|
324
|
+
message: "No captcha found",
|
|
325
|
+
context: { error: "Cannot select, no Captcha found in state" },
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
if (state.index + 1 >= state.challenge.captchas.length) {
|
|
329
|
+
throw new ProsopoError({
|
|
330
|
+
code: "RECORD_NOT_FOUND",
|
|
331
|
+
errorSite: "PCAP-9",
|
|
332
|
+
message: "No captcha found",
|
|
333
|
+
context: {
|
|
334
|
+
error: "Cannot select, index is out of range for this Captcha",
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
updateState({ index: state.index + 1 });
|
|
339
|
+
};
|
|
340
|
+
const loadProviderApi = async (providerUrl) => {
|
|
341
|
+
const config = getConfig();
|
|
342
|
+
const siteKey = config.account.address;
|
|
343
|
+
if (!siteKey) {
|
|
344
|
+
throw new ProsopoError({
|
|
345
|
+
code: "SITE_KEY_MISSING",
|
|
346
|
+
errorSite: "PCAP-10",
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
providerApi: new ProviderApi(providerUrl, siteKey, undefined, widgetLanguageHeaders(config.language)),
|
|
351
|
+
siteKey,
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
const clearTimeout = () => {
|
|
355
|
+
window.clearTimeout(Number(state.timeout));
|
|
356
|
+
updateState({ timeout: undefined });
|
|
357
|
+
};
|
|
358
|
+
const setValidChallengeTimeout = () => {
|
|
359
|
+
const timeMillis = configOptional.captchas.image.solutionTimeout;
|
|
360
|
+
const successfullChallengeTimeout = setTimeout(() => {
|
|
361
|
+
if (disposed)
|
|
362
|
+
return;
|
|
363
|
+
updateState({ isHuman: false });
|
|
364
|
+
events.onExpired();
|
|
365
|
+
}, timeMillis);
|
|
366
|
+
updateState({ successfullChallengeTimeout });
|
|
367
|
+
};
|
|
368
|
+
const resetState = (frictionlessRestart) => {
|
|
369
|
+
clearTimeout();
|
|
370
|
+
window.clearTimeout(Number(state.successfullChallengeTimeout));
|
|
371
|
+
updateState(defaultState());
|
|
372
|
+
events.onReset();
|
|
373
|
+
if (frictionlessRestart) {
|
|
374
|
+
frictionlessRestart();
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
const loadAccount = async () => {
|
|
378
|
+
const config = getConfig();
|
|
379
|
+
if (!config.web2 && !config.userAccountAddress) {
|
|
380
|
+
throw new ProsopoError({
|
|
381
|
+
code: "ACCOUNT_NOT_FOUND",
|
|
382
|
+
errorSite: "PCAP-11",
|
|
383
|
+
context: { error: "Account address has not been set for web3 mode" },
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
const selectAccount = async () => {
|
|
387
|
+
const ext = new (await ExtensionLoader(config.web2))();
|
|
388
|
+
if (frictionlessState) {
|
|
389
|
+
return frictionlessState.userAccount;
|
|
390
|
+
}
|
|
391
|
+
return await ext.getAccount(config);
|
|
392
|
+
};
|
|
393
|
+
const account = await selectAccount();
|
|
394
|
+
updateState({ account });
|
|
395
|
+
return getAccount();
|
|
396
|
+
};
|
|
397
|
+
const getAccount = () => {
|
|
398
|
+
if (!state.account) {
|
|
399
|
+
throw new ProsopoError({
|
|
400
|
+
code: "ACCOUNT_NOT_FOUND",
|
|
401
|
+
errorSite: "PCAP-12",
|
|
402
|
+
context: { error: "Account not loaded" },
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
const account = state.account;
|
|
406
|
+
return account;
|
|
407
|
+
};
|
|
408
|
+
const getDappAccount = () => {
|
|
409
|
+
if (!state.dappAccount) {
|
|
410
|
+
throw new ProsopoError({
|
|
411
|
+
code: "SITE_KEY_MISSING",
|
|
412
|
+
errorSite: "PCAP-13",
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
const dappAccount = state.dappAccount;
|
|
416
|
+
return dappAccount;
|
|
417
|
+
};
|
|
418
|
+
const getExtension = (account) => {
|
|
419
|
+
if (!account.extension) {
|
|
420
|
+
throw new ProsopoError({
|
|
421
|
+
code: "WALLET_NOT_FOUND",
|
|
422
|
+
errorSite: "PCAP-14",
|
|
423
|
+
message: "Polkadot extension not found",
|
|
424
|
+
context: { error: "Extension not loaded" },
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
return account.extension;
|
|
428
|
+
};
|
|
429
|
+
let disposed = false;
|
|
430
|
+
const dispose = () => {
|
|
431
|
+
disposed = true;
|
|
432
|
+
window.clearTimeout(Number(state.timeout));
|
|
433
|
+
window.clearTimeout(Number(state.successfullChallengeTimeout));
|
|
434
|
+
};
|
|
435
|
+
return {
|
|
436
|
+
start,
|
|
437
|
+
cancel,
|
|
438
|
+
submit,
|
|
439
|
+
select,
|
|
440
|
+
nextRound,
|
|
441
|
+
reload,
|
|
442
|
+
dispose,
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
//# sourceMappingURL=Manager.js.map
|