@prosopo/procaptcha-pow 2.13.18 → 2.14.0
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 +10 -7
- package/.turbo/{turbo-build.log → turbo-build$colon$esm.log} +12 -10
- package/.turbo/turbo-build$colon$tsc.log +17 -17
- package/.turbo/turbo-build$colon$types.log +1 -0
- package/CHANGELOG.md +52 -0
- package/dist/cjs/services/Manager.cjs +3 -3
- package/dist/cjs/services/multiThreadedSolver.cjs +81 -0
- package/dist/cjs/services/powWorker.cjs +19 -0
- package/dist/{services → esm/services}/Manager.js +5 -5
- package/dist/esm/services/multiThreadedSolver.js +81 -0
- package/dist/esm/services/powWorker.js +19 -0
- package/dist/tsc/components/procaptchaPoW.d.ts.map +1 -0
- package/dist/tsc/components/procaptchaPoW.js +19 -0
- package/dist/tsc/components/procaptchaPoW.js.map +1 -0
- package/dist/tsc/components/procaptchaWidget.d.ts.map +1 -0
- package/dist/tsc/components/procaptchaWidget.js +184 -0
- package/dist/tsc/components/procaptchaWidget.js.map +1 -0
- package/dist/tsc/errorSites.d.ts.map +1 -0
- package/dist/{errorSites.js.map → tsc/errorSites.js.map} +1 -1
- package/dist/tsc/index.d.ts.map +1 -0
- package/dist/tsc/index.js +3 -0
- package/dist/tsc/index.js.map +1 -0
- package/dist/tsc/services/Manager.d.ts.map +1 -0
- package/dist/tsc/services/Manager.js +286 -0
- package/dist/tsc/services/Manager.js.map +1 -0
- package/dist/tsc/services/multiThreadedSolver.d.ts +2 -0
- package/dist/tsc/services/multiThreadedSolver.d.ts.map +1 -0
- package/dist/tsc/services/multiThreadedSolver.js +68 -0
- package/dist/tsc/services/multiThreadedSolver.js.map +1 -0
- package/dist/tsc/services/powWorker.d.ts +8 -0
- package/dist/tsc/services/powWorker.d.ts.map +1 -0
- package/dist/tsc/services/powWorker.js +8 -0
- package/dist/tsc/services/powWorker.js.map +1 -0
- package/dist/tsc/tests/domHarness.d.ts.map +1 -0
- package/dist/tsc/tests/domHarness.js.map +1 -0
- package/dist/tsc/tests/manager.unit.test.d.ts.map +1 -0
- package/dist/{tests → tsc/tests}/manager.unit.test.js +10 -3
- 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/procaptchaPoW.unit.test.d.ts.map +1 -0
- package/dist/tsc/tests/procaptchaPoW.unit.test.js.map +1 -0
- package/dist/tsc/tests/procaptchaPow.test-d.d.ts.map +1 -0
- package/dist/tsc/tests/procaptchaPow.test-d.js.map +1 -0
- package/dist/tsc/tests/procaptchaWidget.unit.test.d.ts.map +1 -0
- package/dist/tsc/tests/procaptchaWidget.unit.test.js.map +1 -0
- package/dist/types/components/procaptchaPoW.d.ts +7 -0
- package/dist/types/components/procaptchaPoW.d.ts.map +1 -0
- package/dist/types/components/procaptchaWidget.d.ts +7 -0
- package/dist/types/components/procaptchaWidget.d.ts.map +1 -0
- package/dist/types/errorSites.d.ts +10 -0
- package/dist/types/errorSites.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/services/Manager.d.ts +7 -0
- package/dist/types/services/Manager.d.ts.map +1 -0
- package/dist/types/services/multiThreadedSolver.d.ts +2 -0
- package/dist/types/services/multiThreadedSolver.d.ts.map +1 -0
- package/dist/types/services/powWorker.d.ts +8 -0
- package/dist/types/services/powWorker.d.ts.map +1 -0
- package/dist/types/tests/domHarness.d.ts +20 -0
- package/dist/types/tests/domHarness.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 +17 -0
- package/dist/types/tests/managerHarness.d.ts.map +1 -0
- package/dist/types/tests/procaptchaPoW.unit.test.d.ts +2 -0
- package/dist/types/tests/procaptchaPoW.unit.test.d.ts.map +1 -0
- package/dist/types/tests/procaptchaPow.test-d.d.ts +2 -0
- package/dist/types/tests/procaptchaPow.test-d.d.ts.map +1 -0
- package/dist/types/tests/procaptchaWidget.unit.test.d.ts +2 -0
- package/dist/types/tests/procaptchaWidget.unit.test.d.ts.map +1 -0
- package/package.json +18 -19
- package/dist/components/procaptchaPoW.d.ts.map +0 -1
- package/dist/components/procaptchaPoW.js.map +0 -1
- package/dist/components/procaptchaWidget.d.ts.map +0 -1
- package/dist/components/procaptchaWidget.js.map +0 -1
- package/dist/errorSites.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/services/Manager.d.ts.map +0 -1
- package/dist/services/Manager.js.map +0 -1
- package/dist/tests/domHarness.d.ts.map +0 -1
- package/dist/tests/domHarness.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/procaptchaPoW.unit.test.d.ts.map +0 -1
- package/dist/tests/procaptchaPoW.unit.test.js.map +0 -1
- package/dist/tests/procaptchaPow.test-d.d.ts.map +0 -1
- package/dist/tests/procaptchaPow.test-d.js.map +0 -1
- package/dist/tests/procaptchaWidget.unit.test.d.ts.map +0 -1
- package/dist/tests/procaptchaWidget.unit.test.js.map +0 -1
- /package/dist/{_virtual → esm/_virtual}/_rolldown/runtime.js +0 -0
- /package/dist/{components → esm/components}/procaptchaPoW.js +0 -0
- /package/dist/{components → esm/components}/procaptchaWidget.js +0 -0
- /package/dist/{index.js → esm/index.js} +0 -0
- /package/dist/{components → tsc/components}/procaptchaPoW.d.ts +0 -0
- /package/dist/{components → tsc/components}/procaptchaWidget.d.ts +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/{services → tsc/services}/Manager.d.ts +0 -0
- /package/dist/{tests → tsc/tests}/domHarness.d.ts +0 -0
- /package/dist/{tests → tsc/tests}/domHarness.js +0 -0
- /package/dist/{tests → tsc/tests}/manager.unit.test.d.ts +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}/procaptchaPoW.unit.test.d.ts +0 -0
- /package/dist/{tests → tsc/tests}/procaptchaPoW.unit.test.js +0 -0
- /package/dist/{tests → tsc/tests}/procaptchaPow.test-d.d.ts +0 -0
- /package/dist/{tests → tsc/tests}/procaptchaPow.test-d.js +0 -0
- /package/dist/{tests → tsc/tests}/procaptchaWidget.unit.test.d.ts +0 -0
- /package/dist/{tests → tsc/tests}/procaptchaWidget.unit.test.js +0 -0
|
@@ -37,13 +37,16 @@ ViteCommonJSConfig: .
|
|
|
37
37
|
[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
|
|
38
38
|
[36mvite v8.1.6 [32mbuilding ssr environment for production...[36m[39m
|
|
39
39
|
Bundle build started
|
|
40
|
-
[2K
|
|
41
|
-
|
|
40
|
+
[2K
|
|
41
|
+
Build end
|
|
42
|
+
✓ 7 modules transformed.
|
|
42
43
|
rendering chunks...
|
|
43
44
|
computing gzip size...
|
|
44
|
-
dist/cjs/index.cjs
|
|
45
|
-
dist/cjs/components/procaptchaPoW.cjs
|
|
46
|
-
dist/cjs/
|
|
47
|
-
dist/cjs/
|
|
45
|
+
dist/cjs/index.cjs 0.43 kB │ gzip: 0.19 kB
|
|
46
|
+
dist/cjs/components/procaptchaPoW.cjs 0.71 kB │ gzip: 0.38 kB
|
|
47
|
+
dist/cjs/services/multiThreadedSolver.cjs 2.91 kB │ gzip: 1.29 kB
|
|
48
|
+
dist/cjs/components/procaptchaWidget.cjs 5.32 kB │ gzip: 1.71 kB
|
|
49
|
+
dist/cjs/services/powWorker.cjs 7.40 kB │ gzip: 3.57 kB
|
|
50
|
+
dist/cjs/services/Manager.cjs 10.47 kB │ gzip: 3.00 kB
|
|
48
51
|
|
|
49
|
-
[32m✓ built in
|
|
52
|
+
[32m✓ built in 149ms[39m
|
|
@@ -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: [
|
|
@@ -38,14 +37,17 @@ ViteEsmConfig: .
|
|
|
38
37
|
[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
|
|
39
38
|
[36mvite v8.1.6 [32mbuilding ssr environment for production...[36m[39m
|
|
40
39
|
Bundle build started
|
|
41
|
-
[2K
|
|
42
|
-
|
|
40
|
+
[2K
|
|
41
|
+
Build end
|
|
42
|
+
✓ 7 modules transformed.
|
|
43
43
|
rendering chunks...
|
|
44
44
|
computing gzip size...
|
|
45
|
-
dist/_virtual/_rolldown/runtime.js
|
|
46
|
-
dist/index.js
|
|
47
|
-
dist/components/procaptchaPoW.js
|
|
48
|
-
dist/
|
|
49
|
-
dist/
|
|
45
|
+
dist/esm/_virtual/_rolldown/runtime.js 0.04 kB │ gzip: 0.06 kB
|
|
46
|
+
dist/esm/index.js 0.27 kB │ gzip: 0.14 kB
|
|
47
|
+
dist/esm/components/procaptchaPoW.js 0.63 kB │ gzip: 0.36 kB
|
|
48
|
+
dist/esm/services/multiThreadedSolver.js 2.83 kB │ gzip: 1.27 kB
|
|
49
|
+
dist/esm/components/procaptchaWidget.js 5.05 kB │ gzip: 1.70 kB
|
|
50
|
+
dist/esm/services/powWorker.js 7.40 kB │ gzip: 3.57 kB
|
|
51
|
+
dist/esm/services/Manager.js 9.78 kB │ gzip: 2.96 kB
|
|
50
52
|
|
|
51
|
-
[32m✓ built in
|
|
53
|
+
[32m✓ built in 112ms[39m
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
$ tsc --build --verbose
|
|
2
|
-
|
|
2
|
+
12:57:34 PM - Projects in this build:
|
|
3
3
|
* ../../dev/config/tsconfig.json
|
|
4
4
|
* ../util/tsconfig.json
|
|
5
5
|
* ../locale/tsconfig.json
|
|
@@ -16,35 +16,35 @@ $ tsc --build --verbose
|
|
|
16
16
|
* ../procaptcha-common/tsconfig.json
|
|
17
17
|
* tsconfig.json
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
12:57:34 PM - Project '../../dev/config/tsconfig.json' is up to date because newest input '../../dev/config/src/vite/vite.esm.config.ts' is older than output '../../dev/config/dist/tsc/tsconfig.tsbuildinfo'
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
12:57:34 PM - Project '../util/tsconfig.json' is up to date because newest input '../util/src/url.ts' is older than output '../util/dist/tsc/tsconfig.tsbuildinfo'
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
12:57:34 PM - Project '../locale/tsconfig.json' is up to date because newest input '../locale/src/translator.ts' is older than output '../locale/dist/tsc/tsconfig.tsbuildinfo'
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
12:57:34 PM - 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'
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
12:57:34 PM - 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'
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
12:57:34 PM - 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'
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
12:57:34 PM - 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
|
+
12:57:34 PM - Project '../fingerprintjs/tsconfig.json' is up to date because newest input '../fingerprintjs/src/sources/webgl.ts' is older than output '../fingerprintjs/dist/tsc/tsconfig.tsbuildinfo'
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
12:57:34 PM - 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'
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
12:57:34 PM - 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'
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
12:57:34 PM - Project '../widget-skeleton/tsconfig.json' is up to date because newest input '../widget-skeleton/src/theme.ts' is older than output '../widget-skeleton/dist/tsc/tsconfig.tsbuildinfo'
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
12:57:34 PM - Project '../keyring/tsconfig.json' is up to date because newest input '../keyring/src/keyring/keyring.test.ts' is older than output '../keyring/dist/tsc/tsconfig.tsbuildinfo'
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
12:57:34 PM - 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'
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
12:57:34 PM - Project '../procaptcha-common/tsconfig.json' is up to date because newest input '../procaptcha-common/src/tests/protectSession.test.ts' is older than output '../procaptcha-common/dist/tsc/tsconfig.tsbuildinfo'
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
12:57:34 PM - Project 'tsconfig.json' is out of date because output file 'dist/tsc/tsconfig.tsbuildinfo' does not exist
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
12:57:34 PM - Building project '/home/runner/work/captcha/captcha/packages/procaptcha-pow/tsconfig.json'...
|
|
50
50
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
$ tsc --project tsconfig.types.json
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
# @prosopo/procaptcha-pow
|
|
2
2
|
|
|
3
|
+
## 2.14.0
|
|
4
|
+
### Minor Changes
|
|
5
|
+
|
|
6
|
+
- f13677e: Solve PoW captchas across a pool of web workers. The nonce space is divided and conquered across the pool (worker `i` tries nonces `i, i+N, i+2N, …`), keeping the UI responsive on higher-difficulty challenges, with a synchronous fallback when web workers are unavailable. The pool defaults to 4 workers (`PROSOPO_POW_WORKERS`) and never uses more than one fewer than the device's cores, so the page keeps a core free. Adds the `solvePoWOffset` helper to `@prosopo/util`; `@prosopo/procaptcha-pow` now solves PoW challenges on a worker pool internally.
|
|
7
|
+
|
|
8
|
+
### Patch Changes
|
|
9
|
+
|
|
10
|
+
- 76b6edd: The widget now tells the provider which bundle it is and where it was loaded from, on every request:
|
|
11
|
+
|
|
12
|
+
- `X-Prosopo-Bundle-Version`: the release the bundle was built from, or `dev` for a local build.
|
|
13
|
+
- `X-Prosopo-Bundle-Origin`: the origin the widget's code came from. `https://js.prosopo.io` is the hosted bundle. Anything else is a site serving its own copy, or building our npm packages into its app.
|
|
14
|
+
|
|
15
|
+
Providers store request headers on the session and in the request logs, so together with the site key these show which sites self-host and which version each one runs.
|
|
16
|
+
|
|
17
|
+
The provider now allows both headers in CORS. Every provider must run this version before the new bundle is published to the CDN: a widget sending these headers to an older provider fails the browser's preflight check and cannot load a captcha.
|
|
18
|
+
- Updated dependencies [1966fc1]
|
|
19
|
+
- Updated dependencies [c69b636]
|
|
20
|
+
- Updated dependencies [78107d9]
|
|
21
|
+
- Updated dependencies [d6cc6fe]
|
|
22
|
+
- Updated dependencies [f13677e]
|
|
23
|
+
- Updated dependencies [77bd891]
|
|
24
|
+
- Updated dependencies [76b6edd]
|
|
25
|
+
- @prosopo/common@3.3.2
|
|
26
|
+
- @prosopo/fingerprint@2.8.4
|
|
27
|
+
- @prosopo/locale@3.13.2
|
|
28
|
+
- @prosopo/procaptcha-common@2.21.10
|
|
29
|
+
- @prosopo/types@5.20.0
|
|
30
|
+
- @prosopo/util@3.4.0
|
|
31
|
+
- @prosopo/util-crypto@13.6.3
|
|
32
|
+
- @prosopo/widget-skeleton@2.10.5
|
|
33
|
+
- @prosopo/api@4.8.0
|
|
34
|
+
|
|
35
|
+
## 2.13.19
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- 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.
|
|
39
|
+
|
|
40
|
+
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.
|
|
41
|
+
|
|
42
|
+
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.
|
|
43
|
+
- Updated dependencies [2086040]
|
|
44
|
+
- Updated dependencies [915f30b]
|
|
45
|
+
- @prosopo/api@4.7.7
|
|
46
|
+
- @prosopo/common@3.3.1
|
|
47
|
+
- @prosopo/fingerprint@2.8.3
|
|
48
|
+
- @prosopo/locale@3.13.1
|
|
49
|
+
- @prosopo/procaptcha-common@2.21.9
|
|
50
|
+
- @prosopo/types@5.19.0
|
|
51
|
+
- @prosopo/util-crypto@13.6.2
|
|
52
|
+
- @prosopo/util@3.3.17
|
|
53
|
+
- @prosopo/widget-skeleton@2.10.4
|
|
54
|
+
|
|
3
55
|
## 2.13.18
|
|
4
56
|
### Patch Changes
|
|
5
57
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const require_multiThreadedSolver = require("./multiThreadedSolver.cjs");
|
|
2
2
|
let _prosopo_procaptcha_common = require("@prosopo/procaptcha-common");
|
|
3
3
|
let _prosopo_types = require("@prosopo/types");
|
|
4
4
|
let _polkadot_util_string = require("@polkadot/util/string");
|
|
@@ -125,7 +125,7 @@ var Manager = (configInput, state, onStateUpdate, callbacks, frictionlessState,
|
|
|
125
125
|
}
|
|
126
126
|
const providerUrl = getRandomProviderResponse.provider.url;
|
|
127
127
|
previousProviderUrl = providerUrl;
|
|
128
|
-
const providerApi = new _prosopo_api.ProviderApi(providerUrl, getDappAccount(), void 0, (0,
|
|
128
|
+
const providerApi = new _prosopo_api.ProviderApi(providerUrl, getDappAccount(), void 0, (0, _prosopo_procaptcha_common.widgetRequestHeaders)(getConfig().language));
|
|
129
129
|
const simdReadingsOnChallenge = frictionlessState?.getSimdReadings ? await frictionlessState.getSimdReadings(0) : void 0;
|
|
130
130
|
const challengeRequestedAt = Date.now();
|
|
131
131
|
const challenge = await providerApi.getPowCaptchaChallenge(userAccount, getDappAccount(), frictionlessState?.sessionId, simdReadingsOnChallenge);
|
|
@@ -134,7 +134,7 @@ var Manager = (configInput, state, onStateUpdate, callbacks, frictionlessState,
|
|
|
134
134
|
error: challenge.error
|
|
135
135
|
});
|
|
136
136
|
else {
|
|
137
|
-
const solution = await
|
|
137
|
+
const solution = await require_multiThreadedSolver.solvePoWParallel(challenge.challenge, challenge.difficulty);
|
|
138
138
|
let salt;
|
|
139
139
|
if (x !== void 0 && y !== void 0) {
|
|
140
140
|
const coords = [x, y];
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const require_powWorker = require("./powWorker.cjs");
|
|
2
|
+
let _prosopo_util = require("@prosopo/util");
|
|
3
|
+
//#region src/services/multiThreadedSolver.ts
|
|
4
|
+
var POW_WORKER_COUNT = Number.parseInt(process.env.PROSOPO_POW_WORKERS || "4", 10);
|
|
5
|
+
var MAX_POW_WORKERS = 16;
|
|
6
|
+
/**
|
|
7
|
+
* Number of workers to use, guaranteed to be a sane positive integer.
|
|
8
|
+
*
|
|
9
|
+
* The configured count is clamped to a hard maximum and, where the browser
|
|
10
|
+
* exposes it, to one fewer than `navigator.hardwareConcurrency`. Occupying every
|
|
11
|
+
* core starves the main thread and drops frames, and spawning more workers than
|
|
12
|
+
* cores does not speed up a CPU-bound PoW search.
|
|
13
|
+
*/
|
|
14
|
+
var getWorkerCount = () => {
|
|
15
|
+
if (!Number.isFinite(POW_WORKER_COUNT) || POW_WORKER_COUNT < 1) return 1;
|
|
16
|
+
const hardwareLimit = typeof navigator !== "undefined" && Number.isFinite(navigator.hardwareConcurrency) && navigator.hardwareConcurrency > 0 ? Math.max(1, navigator.hardwareConcurrency - 1) : MAX_POW_WORKERS;
|
|
17
|
+
return Math.min(Math.floor(POW_WORKER_COUNT), hardwareLimit, MAX_POW_WORKERS);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Spawn a single PoW web worker.
|
|
21
|
+
*
|
|
22
|
+
* Kept as a separate function so the orchestrator can be tested/mocked and so
|
|
23
|
+
* environments without web worker support (e.g. SSR) fail fast and fall back to
|
|
24
|
+
* the synchronous solver.
|
|
25
|
+
*/
|
|
26
|
+
var spawnWorker = () => new require_powWorker.default();
|
|
27
|
+
/**
|
|
28
|
+
* Solve a PoW challenge across a pool of web workers.
|
|
29
|
+
*
|
|
30
|
+
* The nonce space is divided and conquered: with `n` workers, worker `i` only
|
|
31
|
+
* tries nonces `i, i + n, i + 2n, ...`, so the workers collectively cover every
|
|
32
|
+
* nonce exactly once with no overlap. The first worker to find a valid nonce
|
|
33
|
+
* wins; all workers are then terminated and its nonce is returned.
|
|
34
|
+
*
|
|
35
|
+
* Falls back to the synchronous single-threaded solver when web workers are not
|
|
36
|
+
* available (e.g. server-side rendering) or only a single worker is configured.
|
|
37
|
+
*/
|
|
38
|
+
var solvePoWParallel = (data, difficulty) => {
|
|
39
|
+
const workerCount = getWorkerCount();
|
|
40
|
+
if (workerCount <= 1 || typeof Worker === "undefined") return Promise.resolve((0, _prosopo_util.solvePoW)(data, difficulty));
|
|
41
|
+
return new Promise((resolve) => {
|
|
42
|
+
let workers = [];
|
|
43
|
+
let settled = false;
|
|
44
|
+
const cleanup = () => {
|
|
45
|
+
for (const worker of workers) worker.terminate();
|
|
46
|
+
workers = [];
|
|
47
|
+
};
|
|
48
|
+
const fallbackToSync = () => {
|
|
49
|
+
if (settled) return;
|
|
50
|
+
settled = true;
|
|
51
|
+
cleanup();
|
|
52
|
+
resolve((0, _prosopo_util.solvePoW)(data, difficulty));
|
|
53
|
+
};
|
|
54
|
+
try {
|
|
55
|
+
for (let i = 0; i < workerCount; i++) {
|
|
56
|
+
const worker = spawnWorker();
|
|
57
|
+
worker.onmessage = (event) => {
|
|
58
|
+
if (settled) return;
|
|
59
|
+
settled = true;
|
|
60
|
+
cleanup();
|
|
61
|
+
resolve(event.data);
|
|
62
|
+
};
|
|
63
|
+
worker.onerror = () => {
|
|
64
|
+
fallbackToSync();
|
|
65
|
+
};
|
|
66
|
+
const request = {
|
|
67
|
+
data,
|
|
68
|
+
difficulty,
|
|
69
|
+
start: i,
|
|
70
|
+
step: workerCount
|
|
71
|
+
};
|
|
72
|
+
worker.postMessage(request);
|
|
73
|
+
workers.push(worker);
|
|
74
|
+
}
|
|
75
|
+
} catch {
|
|
76
|
+
fallbackToSync();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
exports.solvePoWParallel = solvePoWParallel;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/services/powWorker.ts?worker&inline
|
|
2
|
+
var jsContent = "(function(){let e=e=>e/2**32|0,t=e=>e>>>0;function n(n,r,i,a){let o=e(i),s=t(i);n.setUint32(r,a?s:o,a),n.setUint32(r+4,a?o:s,a)}function r(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}let i=e=>e?`\"${e}\" `:``;function a(e,t=``){if(typeof e!=`number`)throw TypeError(i(t)+`expected number, got `+typeof e);if(!Number.isSafeInteger(e)||e<0)throw RangeError(i(t)+`expected integer >= 0, got `+e);return e}function o(e,t,n=``){if(r(e)&&(t===void 0||e.length===t))return e;t!==void 0&&a(t,`length`);let o=r(e),s=t===void 0?``:` of length ${t}`,c=o?`length=${e.length}`:`type=${typeof e}`,l=i(n)+`expected Uint8Array`+s+`, got `+c;throw o?RangeError(l):TypeError(l)}let s=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError((t===`object`?``:`\"${t}\" `)+`expected object, got type=`+typeof e)},c=(e,t)=>{s(e,t);let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw TypeError(`\"${t}\" expected plain object`);if(Object.hasOwn(e,`__proto__`))throw TypeError(`\"${t}.__proto__\" is not allowed`)};function l(e,t=!0){if(e.destroyed)throw Error(`hash was destroyed`);if(t&&e.finished)throw Error(`digest() was already called`)}function u(e,t){o(e,void 0,`output`);let n=t.outputLen;if(!(e.length>=n))throw RangeError(`\"output\" expected length >= `+n)}function d(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function f(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function p(e,t){return e<<32-t|e>>>t}function m(e,t,n=`opts`){return c(e,`defaults`),t!==void 0&&c(t,n),Object.assign(Object.create(null),e,t)}function h(e,t={}){if(typeof e!=`function`)throw TypeError(`\"hashCons\" expected function, got type=`+typeof e);t=m({},t,`info`);let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}let g=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function _(e,t,n){return e&t^~e&n}function v(e,t,n){return e&t^e&n^t&n}var y=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=f(this.buffer)}update(e){l(this),o(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length,a=!1;for(let o=0;o<i;){let s=Math.min(r-this.pos,i-o);if(s===r){let t=f(e);for(;r<=i-o;o+=r)this.process(t,o);a=!0;continue}n.set(o===0&&s===i?e:e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(t,0),this.pos=0,a=!0)}return this.length+=e.length,a&&this.roundClean(),this}digestInto(e){l(this),u(e,this),this.finished=!0;let{buffer:t,view:r,blockLen:i,isLE:a}=this,{pos:o}=this;t[o++]=128,t.fill(0,o),this.padOffset>i-o&&(this.process(r,0),t.fill(0)),n(r,i-8,this.length*8,a),this.process(r,0),this.roundClean();let s=e===t?r:f(e),c=this.outputLen,d=c/4,p=this.get();if(c%4||d>p.length)throw Error(`invalid outputLen`);for(let e=0;e<d;e++)s.setUint32(4*e,p[e],a)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:t,length:n,finished:r,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=r,e.length=n,e.pos=a,a&&e.buffer.set(t),e}clone(){return this._cloneInto()}};let b=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),x=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),S=new Uint32Array(64);var C=class extends y{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,t){super(64,e,8,!1),this.A=t[0]|0,this.B=t[1]|0,this.C=t[2]|0,this.D=t[3]|0,this.E=t[4]|0,this.F=t[5]|0,this.G=t[6]|0,this.H=t[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let n=0;n<16;n++,t+=4)S[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=S[e-15],n=S[e-2],r=p(t,7)^p(t,18)^t>>>3,i=p(n,17)^p(n,19)^n>>>10;S[e]=i+S[e-7]+r+S[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=p(o,6)^p(o,11)^p(o,25),u=l+t+_(o,s,c)+x[e]+S[e]|0,d=(p(n,2)^p(n,13)^p(n,22))+v(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){d(S)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),d(this.buffer)}},w=class extends C{constructor(){super(32,b)}};let T=h(()=>new w,g(1));var E=4,D=256,O=e=>{if(!Number.isFinite(e))throw Error(`Invalid PoW difficulty: ${e}`);return Math.round(E*e)},k=e=>{let t=O(e);if(t<=0)return{zeroBytes:0,partialBound:1,always:!0,requireZeroHash:!1};if(t>=D)return{zeroBytes:32,partialBound:1,always:!1,requireZeroHash:!0};let n=t>>3,r=t&7;return{zeroBytes:n,partialBound:r===0?1:1<<8-r,always:!1,requireZeroHash:!1}},A=(e,t)=>{if(t.always)return!0;for(let n=0;n<t.zeroBytes;n++)if(e[n]!==0)return!1;return t.requireZeroHash?!0:t.partialBound>1?e[t.zeroBytes]<t.partialBound:!0},j=e=>{let t=new TextEncoder().encode(e),n=1,r=10,i=new Uint8Array(n+t.length);return i.set(t,n),e=>{for(;e>=r;)n+=1,r*=10,i=new Uint8Array(n+t.length),i.set(t,n);let a=e;for(let e=n-1;e>=0;e--)i[e]=48+a%10,a=Math.floor(a/10);return i}},M=(e,t,n,r)=>{if(!Number.isInteger(n)||n<0)throw Error(`solvePoWOffset: start must be a non-negative integer, got ${n}`);if(!Number.isInteger(r)||r<1)throw Error(`solvePoWOffset: step must be a positive integer, got ${r}`);if(!Number.isFinite(t)||t<0)throw Error(`solvePoWOffset: difficulty must be a non-negative number, got ${t}`);let i=k(t),a=j(e),o=n;for(;;){if(A(T(a(o)),i))return o;o+=r}};let N=self;N.onmessage=e=>{let{data:t,difficulty:n,start:r,step:i}=e.data,a=M(t,n,r,i);N.postMessage(a)}})();";
|
|
3
|
+
var blob = typeof self !== "undefined" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", jsContent], { type: "text/javascript;charset=utf-8" });
|
|
4
|
+
function WorkerWrapper(options) {
|
|
5
|
+
let objURL;
|
|
6
|
+
try {
|
|
7
|
+
objURL = blob && (self.URL || self.webkitURL).createObjectURL(blob);
|
|
8
|
+
if (!objURL) throw "";
|
|
9
|
+
const worker = new Worker(objURL, { name: options?.name });
|
|
10
|
+
worker.addEventListener("error", () => {
|
|
11
|
+
(self.URL || self.webkitURL).revokeObjectURL(objURL);
|
|
12
|
+
});
|
|
13
|
+
return worker;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(jsContent), { name: options?.name });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.default = WorkerWrapper;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ExtensionLoader, buildClientMetaData, buildUpdateState, getDefaultEvents, getProcaptchaRandomActiveProvider, getSimdReadingsForSubmit, pickIpMode, providerRetry } from "@prosopo/procaptcha-common";
|
|
1
|
+
import { solvePoWParallel } from "./multiThreadedSolver.js";
|
|
2
|
+
import { ExtensionLoader, buildClientMetaData, buildUpdateState, getDefaultEvents, getProcaptchaRandomActiveProvider, getSimdReadingsForSubmit, pickIpMode, providerRetry, widgetRequestHeaders } from "@prosopo/procaptcha-common";
|
|
3
3
|
import { ApiParams, CaptchaType, DEFAULT_POW_CAPTCHA_SOLUTION_TIMEOUT, ProcaptchaConfigSchema, encodeProcaptchaOutput } from "@prosopo/types";
|
|
4
4
|
import { stringToHex } from "@polkadot/util/string";
|
|
5
5
|
import { ProviderApi } from "@prosopo/api";
|
|
6
6
|
import { ProsopoError } from "@prosopo/common";
|
|
7
7
|
import { FINGERPRINT_DISCLOSURE_KEYS, encodeFingerprintProof, getFingerprintProof } from "@prosopo/fingerprint";
|
|
8
|
-
import { embedData, sleep
|
|
8
|
+
import { embedData, sleep } from "@prosopo/util";
|
|
9
9
|
import { randomAsHex } from "@prosopo/util-crypto";
|
|
10
10
|
//#region src/services/Manager.ts
|
|
11
11
|
var Manager = (configInput, state, onStateUpdate, callbacks, frictionlessState, onEscalate, getHoneypotValue) => {
|
|
@@ -125,7 +125,7 @@ var Manager = (configInput, state, onStateUpdate, callbacks, frictionlessState,
|
|
|
125
125
|
}
|
|
126
126
|
const providerUrl = getRandomProviderResponse.provider.url;
|
|
127
127
|
previousProviderUrl = providerUrl;
|
|
128
|
-
const providerApi = new ProviderApi(providerUrl, getDappAccount(), void 0,
|
|
128
|
+
const providerApi = new ProviderApi(providerUrl, getDappAccount(), void 0, widgetRequestHeaders(getConfig().language));
|
|
129
129
|
const simdReadingsOnChallenge = frictionlessState?.getSimdReadings ? await frictionlessState.getSimdReadings(0) : void 0;
|
|
130
130
|
const challengeRequestedAt = Date.now();
|
|
131
131
|
const challenge = await providerApi.getPowCaptchaChallenge(userAccount, getDappAccount(), frictionlessState?.sessionId, simdReadingsOnChallenge);
|
|
@@ -134,7 +134,7 @@ var Manager = (configInput, state, onStateUpdate, callbacks, frictionlessState,
|
|
|
134
134
|
error: challenge.error
|
|
135
135
|
});
|
|
136
136
|
else {
|
|
137
|
-
const solution = await
|
|
137
|
+
const solution = await solvePoWParallel(challenge.challenge, challenge.difficulty);
|
|
138
138
|
let salt;
|
|
139
139
|
if (x !== void 0 && y !== void 0) {
|
|
140
140
|
const coords = [x, y];
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import WorkerWrapper from "./powWorker.js";
|
|
2
|
+
import { solvePoW } from "@prosopo/util";
|
|
3
|
+
//#region src/services/multiThreadedSolver.ts
|
|
4
|
+
var POW_WORKER_COUNT = Number.parseInt(process.env.PROSOPO_POW_WORKERS || "4", 10);
|
|
5
|
+
var MAX_POW_WORKERS = 16;
|
|
6
|
+
/**
|
|
7
|
+
* Number of workers to use, guaranteed to be a sane positive integer.
|
|
8
|
+
*
|
|
9
|
+
* The configured count is clamped to a hard maximum and, where the browser
|
|
10
|
+
* exposes it, to one fewer than `navigator.hardwareConcurrency`. Occupying every
|
|
11
|
+
* core starves the main thread and drops frames, and spawning more workers than
|
|
12
|
+
* cores does not speed up a CPU-bound PoW search.
|
|
13
|
+
*/
|
|
14
|
+
var getWorkerCount = () => {
|
|
15
|
+
if (!Number.isFinite(POW_WORKER_COUNT) || POW_WORKER_COUNT < 1) return 1;
|
|
16
|
+
const hardwareLimit = typeof navigator !== "undefined" && Number.isFinite(navigator.hardwareConcurrency) && navigator.hardwareConcurrency > 0 ? Math.max(1, navigator.hardwareConcurrency - 1) : MAX_POW_WORKERS;
|
|
17
|
+
return Math.min(Math.floor(POW_WORKER_COUNT), hardwareLimit, MAX_POW_WORKERS);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Spawn a single PoW web worker.
|
|
21
|
+
*
|
|
22
|
+
* Kept as a separate function so the orchestrator can be tested/mocked and so
|
|
23
|
+
* environments without web worker support (e.g. SSR) fail fast and fall back to
|
|
24
|
+
* the synchronous solver.
|
|
25
|
+
*/
|
|
26
|
+
var spawnWorker = () => new WorkerWrapper();
|
|
27
|
+
/**
|
|
28
|
+
* Solve a PoW challenge across a pool of web workers.
|
|
29
|
+
*
|
|
30
|
+
* The nonce space is divided and conquered: with `n` workers, worker `i` only
|
|
31
|
+
* tries nonces `i, i + n, i + 2n, ...`, so the workers collectively cover every
|
|
32
|
+
* nonce exactly once with no overlap. The first worker to find a valid nonce
|
|
33
|
+
* wins; all workers are then terminated and its nonce is returned.
|
|
34
|
+
*
|
|
35
|
+
* Falls back to the synchronous single-threaded solver when web workers are not
|
|
36
|
+
* available (e.g. server-side rendering) or only a single worker is configured.
|
|
37
|
+
*/
|
|
38
|
+
var solvePoWParallel = (data, difficulty) => {
|
|
39
|
+
const workerCount = getWorkerCount();
|
|
40
|
+
if (workerCount <= 1 || typeof Worker === "undefined") return Promise.resolve(solvePoW(data, difficulty));
|
|
41
|
+
return new Promise((resolve) => {
|
|
42
|
+
let workers = [];
|
|
43
|
+
let settled = false;
|
|
44
|
+
const cleanup = () => {
|
|
45
|
+
for (const worker of workers) worker.terminate();
|
|
46
|
+
workers = [];
|
|
47
|
+
};
|
|
48
|
+
const fallbackToSync = () => {
|
|
49
|
+
if (settled) return;
|
|
50
|
+
settled = true;
|
|
51
|
+
cleanup();
|
|
52
|
+
resolve(solvePoW(data, difficulty));
|
|
53
|
+
};
|
|
54
|
+
try {
|
|
55
|
+
for (let i = 0; i < workerCount; i++) {
|
|
56
|
+
const worker = spawnWorker();
|
|
57
|
+
worker.onmessage = (event) => {
|
|
58
|
+
if (settled) return;
|
|
59
|
+
settled = true;
|
|
60
|
+
cleanup();
|
|
61
|
+
resolve(event.data);
|
|
62
|
+
};
|
|
63
|
+
worker.onerror = () => {
|
|
64
|
+
fallbackToSync();
|
|
65
|
+
};
|
|
66
|
+
const request = {
|
|
67
|
+
data,
|
|
68
|
+
difficulty,
|
|
69
|
+
start: i,
|
|
70
|
+
step: workerCount
|
|
71
|
+
};
|
|
72
|
+
worker.postMessage(request);
|
|
73
|
+
workers.push(worker);
|
|
74
|
+
}
|
|
75
|
+
} catch {
|
|
76
|
+
fallbackToSync();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
export { solvePoWParallel };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/services/powWorker.ts?worker&inline
|
|
2
|
+
var jsContent = "(function(){let e=e=>e/2**32|0,t=e=>e>>>0;function n(n,r,i,a){let o=e(i),s=t(i);n.setUint32(r,a?s:o,a),n.setUint32(r+4,a?o:s,a)}function r(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}let i=e=>e?`\"${e}\" `:``;function a(e,t=``){if(typeof e!=`number`)throw TypeError(i(t)+`expected number, got `+typeof e);if(!Number.isSafeInteger(e)||e<0)throw RangeError(i(t)+`expected integer >= 0, got `+e);return e}function o(e,t,n=``){if(r(e)&&(t===void 0||e.length===t))return e;t!==void 0&&a(t,`length`);let o=r(e),s=t===void 0?``:` of length ${t}`,c=o?`length=${e.length}`:`type=${typeof e}`,l=i(n)+`expected Uint8Array`+s+`, got `+c;throw o?RangeError(l):TypeError(l)}let s=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError((t===`object`?``:`\"${t}\" `)+`expected object, got type=`+typeof e)},c=(e,t)=>{s(e,t);let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw TypeError(`\"${t}\" expected plain object`);if(Object.hasOwn(e,`__proto__`))throw TypeError(`\"${t}.__proto__\" is not allowed`)};function l(e,t=!0){if(e.destroyed)throw Error(`hash was destroyed`);if(t&&e.finished)throw Error(`digest() was already called`)}function u(e,t){o(e,void 0,`output`);let n=t.outputLen;if(!(e.length>=n))throw RangeError(`\"output\" expected length >= `+n)}function d(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function f(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function p(e,t){return e<<32-t|e>>>t}function m(e,t,n=`opts`){return c(e,`defaults`),t!==void 0&&c(t,n),Object.assign(Object.create(null),e,t)}function h(e,t={}){if(typeof e!=`function`)throw TypeError(`\"hashCons\" expected function, got type=`+typeof e);t=m({},t,`info`);let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}let g=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function _(e,t,n){return e&t^~e&n}function v(e,t,n){return e&t^e&n^t&n}var y=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=f(this.buffer)}update(e){l(this),o(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length,a=!1;for(let o=0;o<i;){let s=Math.min(r-this.pos,i-o);if(s===r){let t=f(e);for(;r<=i-o;o+=r)this.process(t,o);a=!0;continue}n.set(o===0&&s===i?e:e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(t,0),this.pos=0,a=!0)}return this.length+=e.length,a&&this.roundClean(),this}digestInto(e){l(this),u(e,this),this.finished=!0;let{buffer:t,view:r,blockLen:i,isLE:a}=this,{pos:o}=this;t[o++]=128,t.fill(0,o),this.padOffset>i-o&&(this.process(r,0),t.fill(0)),n(r,i-8,this.length*8,a),this.process(r,0),this.roundClean();let s=e===t?r:f(e),c=this.outputLen,d=c/4,p=this.get();if(c%4||d>p.length)throw Error(`invalid outputLen`);for(let e=0;e<d;e++)s.setUint32(4*e,p[e],a)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:t,length:n,finished:r,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=r,e.length=n,e.pos=a,a&&e.buffer.set(t),e}clone(){return this._cloneInto()}};let b=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),x=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),S=new Uint32Array(64);var C=class extends y{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,t){super(64,e,8,!1),this.A=t[0]|0,this.B=t[1]|0,this.C=t[2]|0,this.D=t[3]|0,this.E=t[4]|0,this.F=t[5]|0,this.G=t[6]|0,this.H=t[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let n=0;n<16;n++,t+=4)S[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=S[e-15],n=S[e-2],r=p(t,7)^p(t,18)^t>>>3,i=p(n,17)^p(n,19)^n>>>10;S[e]=i+S[e-7]+r+S[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=p(o,6)^p(o,11)^p(o,25),u=l+t+_(o,s,c)+x[e]+S[e]|0,d=(p(n,2)^p(n,13)^p(n,22))+v(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){d(S)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),d(this.buffer)}},w=class extends C{constructor(){super(32,b)}};let T=h(()=>new w,g(1));var E=4,D=256,O=e=>{if(!Number.isFinite(e))throw Error(`Invalid PoW difficulty: ${e}`);return Math.round(E*e)},k=e=>{let t=O(e);if(t<=0)return{zeroBytes:0,partialBound:1,always:!0,requireZeroHash:!1};if(t>=D)return{zeroBytes:32,partialBound:1,always:!1,requireZeroHash:!0};let n=t>>3,r=t&7;return{zeroBytes:n,partialBound:r===0?1:1<<8-r,always:!1,requireZeroHash:!1}},A=(e,t)=>{if(t.always)return!0;for(let n=0;n<t.zeroBytes;n++)if(e[n]!==0)return!1;return t.requireZeroHash?!0:t.partialBound>1?e[t.zeroBytes]<t.partialBound:!0},j=e=>{let t=new TextEncoder().encode(e),n=1,r=10,i=new Uint8Array(n+t.length);return i.set(t,n),e=>{for(;e>=r;)n+=1,r*=10,i=new Uint8Array(n+t.length),i.set(t,n);let a=e;for(let e=n-1;e>=0;e--)i[e]=48+a%10,a=Math.floor(a/10);return i}},M=(e,t,n,r)=>{if(!Number.isInteger(n)||n<0)throw Error(`solvePoWOffset: start must be a non-negative integer, got ${n}`);if(!Number.isInteger(r)||r<1)throw Error(`solvePoWOffset: step must be a positive integer, got ${r}`);if(!Number.isFinite(t)||t<0)throw Error(`solvePoWOffset: difficulty must be a non-negative number, got ${t}`);let i=k(t),a=j(e),o=n;for(;;){if(A(T(a(o)),i))return o;o+=r}};let N=self;N.onmessage=e=>{let{data:t,difficulty:n,start:r,step:i}=e.data,a=M(t,n,r,i);N.postMessage(a)}})();";
|
|
3
|
+
var blob = typeof self !== "undefined" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", jsContent], { type: "text/javascript;charset=utf-8" });
|
|
4
|
+
function WorkerWrapper(options) {
|
|
5
|
+
let objURL;
|
|
6
|
+
try {
|
|
7
|
+
objURL = blob && (self.URL || self.webkitURL).createObjectURL(blob);
|
|
8
|
+
if (!objURL) throw "";
|
|
9
|
+
const worker = new Worker(objURL, { name: options?.name });
|
|
10
|
+
worker.addEventListener("error", () => {
|
|
11
|
+
(self.URL || self.webkitURL).revokeObjectURL(objURL);
|
|
12
|
+
});
|
|
13
|
+
return worker;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(jsContent), { name: options?.name });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { WorkerWrapper as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procaptchaPoW.d.ts","sourceRoot":"","sources":["../../../src/components/procaptchaPoW.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEjE,YAAY,EAAE,mBAAmB,EAAE,CAAC;AAEpC,MAAM,MAAM,oBAAoB,GAAG,CAClC,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,eAAe,KAClB,mBAAmB,CAAC;AAMzB,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC,oBAAoB,CACN,CAAC;AAElE,eAAO,MAAM,kBAAkB,cACnB,WAAW,SACf,eAAe,KACpB,mBAkBF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const loadProcaptchaPow = async () => (await import("./procaptchaWidget.js")).mountProcaptchaPowWidget;
|
|
2
|
+
export const mountProcaptchaPow = (container, props) => {
|
|
3
|
+
let destroyed = false;
|
|
4
|
+
let inner;
|
|
5
|
+
void loadProcaptchaPow().then((mount) => {
|
|
6
|
+
if (destroyed) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
inner = mount(container, props);
|
|
10
|
+
});
|
|
11
|
+
return {
|
|
12
|
+
destroy: () => {
|
|
13
|
+
destroyed = true;
|
|
14
|
+
inner?.destroy();
|
|
15
|
+
inner = undefined;
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=procaptchaPoW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procaptchaPoW.js","sourceRoot":"","sources":["../../../src/components/procaptchaPoW.ts"],"names":[],"mappings":"AA4BA,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,IAAmC,EAAE,CAC1E,CAAC,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC,CAAC,wBAAwB,CAAC;AAElE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CACjC,SAAsB,EACtB,KAAsB,EACA,EAAE;IACxB,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,IAAI,KAAsC,CAAC;IAE3C,KAAK,iBAAiB,EAAE,CAAC,IAAI,CAAC,CAAC,KAA2B,EAAE,EAAE;QAC7D,IAAI,SAAS,EAAE,CAAC;YACf,OAAO;QACR,CAAC;QACD,KAAK,GAAG,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,OAAO;QACN,OAAO,EAAE,GAAG,EAAE;YACb,SAAS,GAAG,IAAI,CAAC;YACjB,KAAK,EAAE,OAAO,EAAE,CAAC;YACjB,KAAK,GAAG,SAAS,CAAC;QACnB,CAAC;KACD,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procaptchaWidget.d.ts","sourceRoot":"","sources":["../../../src/components/procaptchaWidget.ts"],"names":[],"mappings":"AA6BA,OAAO,EAEN,KAAK,eAAe,EAEpB,MAAM,gBAAgB,CAAC;AAOxB,MAAM,WAAW,mBAAmB;IACnC,OAAO,IAAI,IAAI,CAAC;CAChB;AAED,eAAO,MAAM,wBAAwB,cACzB,WAAW,SACf,eAAe,KACpB,mBAuPF,CAAC;AAEF,eAAe,wBAAwB,CAAC"}
|