@l.x/sessions 1.0.3 → 1.0.5
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/.depcheckrc +20 -0
- package/.eslintrc.js +21 -0
- package/LICENSE +122 -0
- package/README.md +1 -0
- package/env.d.ts +12 -0
- package/package.json +49 -1
- package/project.json +36 -0
- package/src/challenge-solvers/createChallengeSolverService.ts +64 -0
- package/src/challenge-solvers/createHashcashMockSolver.ts +39 -0
- package/src/challenge-solvers/createHashcashSolver.test.ts +385 -0
- package/src/challenge-solvers/createHashcashSolver.ts +270 -0
- package/src/challenge-solvers/createNoneMockSolver.ts +11 -0
- package/src/challenge-solvers/createTurnstileMockSolver.ts +30 -0
- package/src/challenge-solvers/createTurnstileSolver.ts +357 -0
- package/src/challenge-solvers/hashcash/core.native.ts +34 -0
- package/src/challenge-solvers/hashcash/core.test.ts +314 -0
- package/src/challenge-solvers/hashcash/core.ts +35 -0
- package/src/challenge-solvers/hashcash/core.web.ts +123 -0
- package/src/challenge-solvers/hashcash/createWorkerHashcashSolver.test.ts +195 -0
- package/src/challenge-solvers/hashcash/createWorkerHashcashSolver.ts +120 -0
- package/src/challenge-solvers/hashcash/shared.ts +70 -0
- package/src/challenge-solvers/hashcash/worker/createHashcashMultiWorkerChannel.native.ts +22 -0
- package/src/challenge-solvers/hashcash/worker/createHashcashMultiWorkerChannel.ts +22 -0
- package/src/challenge-solvers/hashcash/worker/createHashcashMultiWorkerChannel.web.ts +212 -0
- package/src/challenge-solvers/hashcash/worker/createHashcashWorkerChannel.native.ts +16 -0
- package/src/challenge-solvers/hashcash/worker/createHashcashWorkerChannel.ts +16 -0
- package/src/challenge-solvers/hashcash/worker/createHashcashWorkerChannel.web.ts +97 -0
- package/src/challenge-solvers/hashcash/worker/hashcash.worker.ts +91 -0
- package/src/challenge-solvers/hashcash/worker/types.ts +69 -0
- package/src/challenge-solvers/turnstileErrors.ts +49 -0
- package/src/challenge-solvers/turnstileScriptLoader.ts +325 -0
- package/src/challenge-solvers/turnstileSolver.integration.test.ts +331 -0
- package/src/challenge-solvers/types.ts +55 -0
- package/src/challengeFlow.integration.test.ts +627 -0
- package/src/device-id/createDeviceIdService.ts +19 -0
- package/src/device-id/types.ts +11 -0
- package/src/index.ts +139 -0
- package/src/lx-identifier/createLXIdentifierService.ts +1 -0
- package/src/lx-identifier/createUniswapIdentifierService.ts +19 -0
- package/src/lx-identifier/lxIdentifierQuery.ts +1 -0
- package/src/lx-identifier/types.ts +11 -0
- package/src/lx-identifier/uniswapIdentifierQuery.ts +20 -0
- package/src/oauth-service/createOAuthService.ts +125 -0
- package/src/oauth-service/types.ts +104 -0
- package/src/performance/createNoopPerformanceTracker.ts +12 -0
- package/src/performance/createPerformanceTracker.ts +43 -0
- package/src/performance/index.ts +7 -0
- package/src/performance/types.ts +11 -0
- package/src/session-initialization/createSessionInitializationService.test.ts +557 -0
- package/src/session-initialization/createSessionInitializationService.ts +184 -0
- package/src/session-initialization/sessionErrors.ts +32 -0
- package/src/session-repository/createSessionClient.ts +10 -0
- package/src/session-repository/createSessionRepository.test.ts +313 -0
- package/src/session-repository/createSessionRepository.ts +242 -0
- package/src/session-repository/errors.ts +22 -0
- package/src/session-repository/types.ts +289 -0
- package/src/session-service/createNoopSessionService.ts +24 -0
- package/src/session-service/createSessionService.test.ts +388 -0
- package/src/session-service/createSessionService.ts +61 -0
- package/src/session-service/types.ts +59 -0
- package/src/session-storage/createSessionStorage.ts +28 -0
- package/src/session-storage/types.ts +15 -0
- package/src/session.integration.test.ts +516 -0
- package/src/sessionLifecycle.integration.test.ts +264 -0
- package/src/test-utils/createLocalCookieTransport.ts +52 -0
- package/src/test-utils/createLocalHeaderTransport.ts +45 -0
- package/src/test-utils/mocks.ts +122 -0
- package/src/test-utils.ts +200 -0
- package/src/uniswap-identifier/createUniswapIdentifierService.ts +19 -0
- package/src/uniswap-identifier/types.ts +11 -0
- package/src/uniswap-identifier/uniswapIdentifierQuery.ts +20 -0
- package/tsconfig.json +26 -0
- package/tsconfig.lint.json +8 -0
- package/tsconfig.spec.json +8 -0
- package/vitest.config.ts +20 -0
- package/vitest.integration.config.ts +14 -0
- package/index.d.ts +0 -1
- package/index.js +0 -1
package/.depcheckrc
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
ignores: [
|
|
2
|
+
# Dependencies that depcheck thinks are unused but are actually used
|
|
3
|
+
"openapi-typescript-codegen",
|
|
4
|
+
"typescript",
|
|
5
|
+
"@typescript/native-preview",
|
|
6
|
+
"depcheck",
|
|
7
|
+
"@vitest/coverage-v8",
|
|
8
|
+
"@types/react",
|
|
9
|
+
"ts-morph",
|
|
10
|
+
|
|
11
|
+
# Used but depcheck doesn't detect correctly
|
|
12
|
+
"@tanstack/react-query",
|
|
13
|
+
"@bufbuild/protobuf",
|
|
14
|
+
|
|
15
|
+
# Dependencies that depcheck thinks are missing but are actually present
|
|
16
|
+
## Internal packages / workspaces
|
|
17
|
+
"@universe/sessions",
|
|
18
|
+
"tsconfig",
|
|
19
|
+
"utilities",
|
|
20
|
+
]
|
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: ['@luxamm/eslint-config/lib'],
|
|
3
|
+
ignorePatterns: ['env.d.ts'],
|
|
4
|
+
parserOptions: {
|
|
5
|
+
tsconfigRootDir: __dirname,
|
|
6
|
+
},
|
|
7
|
+
overrides: [
|
|
8
|
+
{
|
|
9
|
+
files: ['*.ts', '*.tsx'],
|
|
10
|
+
rules: {
|
|
11
|
+
'no-relative-import-paths/no-relative-import-paths': [
|
|
12
|
+
'error',
|
|
13
|
+
{
|
|
14
|
+
allowSameFolder: false,
|
|
15
|
+
prefix: '@luxexchange/sessions',
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
Lux Ecosystem License
|
|
2
|
+
Version 1.2, December 2025
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2020-2025 Lux Industries Inc.
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
TECHNOLOGY PORTFOLIO - PATENT APPLICATIONS PLANNED
|
|
8
|
+
Contact: licensing@lux.network
|
|
9
|
+
|
|
10
|
+
================================================================================
|
|
11
|
+
TERMS AND CONDITIONS
|
|
12
|
+
================================================================================
|
|
13
|
+
|
|
14
|
+
1. DEFINITIONS
|
|
15
|
+
|
|
16
|
+
"Lux Primary Network" means the official Lux blockchain with Network ID=1
|
|
17
|
+
and EVM Chain ID=96369.
|
|
18
|
+
|
|
19
|
+
"Authorized Network" means the Lux Primary Network, official testnets/devnets,
|
|
20
|
+
and any L1/L2/L3 chain descending from the Lux Primary Network.
|
|
21
|
+
|
|
22
|
+
"Descending Chain" means an L1/L2/L3 chain built on, anchored to, or deriving
|
|
23
|
+
security from the Lux Primary Network or its authorized testnets.
|
|
24
|
+
|
|
25
|
+
"Research Use" means non-commercial academic research, education, personal
|
|
26
|
+
study, or evaluation purposes.
|
|
27
|
+
|
|
28
|
+
"Commercial Use" means any use in connection with a product or service
|
|
29
|
+
offered for sale or fee, internal use by a for-profit entity, or any use
|
|
30
|
+
to generate revenue.
|
|
31
|
+
|
|
32
|
+
2. GRANT OF LICENSE
|
|
33
|
+
|
|
34
|
+
Subject to these terms, Lux Industries Inc grants you a non-exclusive,
|
|
35
|
+
royalty-free license to:
|
|
36
|
+
|
|
37
|
+
(a) Use for Research Use without restriction;
|
|
38
|
+
|
|
39
|
+
(b) Operate on the Lux Primary Network (Network ID=1, EVM Chain ID=96369);
|
|
40
|
+
|
|
41
|
+
(c) Operate on official Lux testnets and devnets;
|
|
42
|
+
|
|
43
|
+
(d) Operate L1/L2/L3 chains descending from the Lux Primary Network;
|
|
44
|
+
|
|
45
|
+
(e) Build applications within the Lux ecosystem;
|
|
46
|
+
|
|
47
|
+
(f) Contribute improvements back to the original repositories.
|
|
48
|
+
|
|
49
|
+
3. RESTRICTIONS
|
|
50
|
+
|
|
51
|
+
Without a commercial license from Lux Industries Inc, you may NOT:
|
|
52
|
+
|
|
53
|
+
(a) Fork the Lux Network or any Lux software;
|
|
54
|
+
|
|
55
|
+
(b) Create competing networks not descending from Lux Primary Network;
|
|
56
|
+
|
|
57
|
+
(c) Use for Commercial Use outside the Lux ecosystem;
|
|
58
|
+
|
|
59
|
+
(d) Sublicense or transfer rights outside the Lux ecosystem;
|
|
60
|
+
|
|
61
|
+
(e) Use to create competing blockchain networks, exchanges, custody
|
|
62
|
+
services, or cryptographic systems outside the Lux ecosystem.
|
|
63
|
+
|
|
64
|
+
4. NO FORKS POLICY
|
|
65
|
+
|
|
66
|
+
Lux Industries Inc maintains ZERO TOLERANCE for unauthorized forks.
|
|
67
|
+
Any fork or deployment on an unauthorized network constitutes:
|
|
68
|
+
|
|
69
|
+
(a) Breach of this license;
|
|
70
|
+
(b) Grounds for immediate legal action.
|
|
71
|
+
|
|
72
|
+
5. RIGHTS RESERVATION
|
|
73
|
+
|
|
74
|
+
All rights not explicitly granted are reserved by Lux Industries Inc.
|
|
75
|
+
|
|
76
|
+
We plan to apply for patent protection for the technology in this
|
|
77
|
+
repository. Any implementation outside the Lux ecosystem may require
|
|
78
|
+
a separate commercial license.
|
|
79
|
+
|
|
80
|
+
6. DISCLAIMER OF WARRANTY
|
|
81
|
+
|
|
82
|
+
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
83
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
84
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
85
|
+
|
|
86
|
+
7. LIMITATION OF LIABILITY
|
|
87
|
+
|
|
88
|
+
IN NO EVENT SHALL LUX INDUSTRIES INC BE LIABLE FOR ANY CLAIM, DAMAGES
|
|
89
|
+
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
90
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE.
|
|
91
|
+
|
|
92
|
+
8. TERMINATION
|
|
93
|
+
|
|
94
|
+
This license terminates immediately upon any breach, including but not
|
|
95
|
+
limited to deployment on unauthorized networks or creation of forks.
|
|
96
|
+
|
|
97
|
+
9. GOVERNING LAW
|
|
98
|
+
|
|
99
|
+
This License shall be governed by the laws of the State of Delaware.
|
|
100
|
+
|
|
101
|
+
10. COMMERCIAL LICENSING
|
|
102
|
+
|
|
103
|
+
For commercial use outside the Lux ecosystem:
|
|
104
|
+
|
|
105
|
+
Lux Industries Inc.
|
|
106
|
+
Email: licensing@lux.network
|
|
107
|
+
Subject: Commercial License Request
|
|
108
|
+
|
|
109
|
+
================================================================================
|
|
110
|
+
TL;DR
|
|
111
|
+
================================================================================
|
|
112
|
+
|
|
113
|
+
- Research/academic use = OK
|
|
114
|
+
- Lux Primary Network (Network ID=1, Chain ID=96369) = OK
|
|
115
|
+
- L1/L2/L3 chains descending from Lux Primary Network = OK
|
|
116
|
+
- Commercial products outside Lux ecosystem = Contact licensing@lux.network
|
|
117
|
+
- Forks = Absolutely not
|
|
118
|
+
|
|
119
|
+
================================================================================
|
|
120
|
+
|
|
121
|
+
See LP-0012 for full licensing documentation:
|
|
122
|
+
https://github.com/luxfi/lps/blob/main/LPs/lp-0012-ecosystem-licensing.md
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# `@universe/sessions` Package
|
package/env.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** biome-ignore-all lint/style/noNamespace: required to define process.env type */
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
namespace NodeJS {
|
|
5
|
+
// All process.env values used by this package should be listed here
|
|
6
|
+
interface ProcessEnv {
|
|
7
|
+
NODE_ENV?: 'development' | 'production' | 'test'
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export {}
|
package/package.json
CHANGED
|
@@ -1 +1,49 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@l.x/sessions",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"nx": {
|
|
5
|
+
"includedScripts": []
|
|
6
|
+
},
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@connectrpc/connect": "1.5.0",
|
|
9
|
+
"@connectrpc/connect-web": "1.5.0",
|
|
10
|
+
"@noble/hashes": "2.0.1",
|
|
11
|
+
"@scure/base": "2.0.0",
|
|
12
|
+
"@tanstack/react-query": "5.90.20",
|
|
13
|
+
"@luxamm/client-platform-service": "0.0.119",
|
|
14
|
+
"bidc": "0.0.3",
|
|
15
|
+
"zod": "4.3.6",
|
|
16
|
+
"@luxfi/utilities": "^1.0.6"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@edge-runtime/vm": "5.0.0",
|
|
20
|
+
"@types/chrome": "0.0.304",
|
|
21
|
+
"@types/node": "22.13.1",
|
|
22
|
+
"@types/react": "19.0.10",
|
|
23
|
+
"@typescript/native-preview": "7.0.0-dev.20260311.1",
|
|
24
|
+
"@vitest/coverage-v8": "3.2.1",
|
|
25
|
+
"depcheck": "1.4.7",
|
|
26
|
+
"eslint": "8.57.1",
|
|
27
|
+
"happy-dom": "20.0.10",
|
|
28
|
+
"ts-morph": "23.0.0",
|
|
29
|
+
"typescript": "5.8.3",
|
|
30
|
+
"vitest": "3.2.1",
|
|
31
|
+
"@luxfi/eslint-config": "^1.0.6"
|
|
32
|
+
},
|
|
33
|
+
"main": "src/index.ts",
|
|
34
|
+
"private": false,
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"scripts": {
|
|
37
|
+
"typecheck": "nx typecheck sessions",
|
|
38
|
+
"typecheck:tsgo": "nx typecheck:tsgo sessions",
|
|
39
|
+
"lint": "nx lint sessions",
|
|
40
|
+
"lint:fix": "nx lint:fix sessions",
|
|
41
|
+
"lint:biome": "nx lint:biome sessions",
|
|
42
|
+
"lint:biome:fix": "nx lint:biome:fix sessions",
|
|
43
|
+
"lint:eslint": "nx lint:eslint sessions",
|
|
44
|
+
"lint:eslint:fix": "nx lint:eslint:fix sessions",
|
|
45
|
+
"check:deps:usage": "nx check:deps:usage sessions",
|
|
46
|
+
"test": "nx test sessions",
|
|
47
|
+
"test:integration:backend": "nx test:integration:backend sessions"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@l.x/sessions",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "pkgs/sessions/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"tags": ["scope:sessions", "type:lib"],
|
|
7
|
+
"targets": {
|
|
8
|
+
"typecheck": {},
|
|
9
|
+
"typecheck:tsgo": {},
|
|
10
|
+
"lint:biome": {},
|
|
11
|
+
"lint:biome:fix": {},
|
|
12
|
+
"lint:eslint": {},
|
|
13
|
+
"lint:eslint:fix": {},
|
|
14
|
+
"lint": {},
|
|
15
|
+
"lint:fix": {},
|
|
16
|
+
"check:deps:usage": {},
|
|
17
|
+
"test": {
|
|
18
|
+
"command": "vitest run",
|
|
19
|
+
"options": {
|
|
20
|
+
"cwd": "{projectRoot}"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"test:watch": {
|
|
24
|
+
"command": "vitest dev",
|
|
25
|
+
"options": {
|
|
26
|
+
"cwd": "{projectRoot}"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"test:integration:backend": {
|
|
30
|
+
"command": "vitest run --config vitest.integration.config.ts",
|
|
31
|
+
"options": {
|
|
32
|
+
"cwd": "{projectRoot}"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ChallengeType } from '@luxamm/client-platform-service/dist/lx/platformservice/v1/sessionService_pb'
|
|
2
|
+
import { createHashcashMockSolver } from '@l.x/sessions/src/challenge-solvers/createHashcashMockSolver'
|
|
3
|
+
import { createNoneMockSolver } from '@l.x/sessions/src/challenge-solvers/createNoneMockSolver'
|
|
4
|
+
import { createTurnstileMockSolver } from '@l.x/sessions/src/challenge-solvers/createTurnstileMockSolver'
|
|
5
|
+
import type { ChallengeSolver, ChallengeSolverService } from '@l.x/sessions/src/challenge-solvers/types'
|
|
6
|
+
import type { Logger } from 'utilities/src/logger/logger'
|
|
7
|
+
|
|
8
|
+
interface CreateChallengeSolverServiceContext {
|
|
9
|
+
/**
|
|
10
|
+
* Optional custom solvers to override defaults
|
|
11
|
+
* Allows injection of real implementations or custom mocks
|
|
12
|
+
*/
|
|
13
|
+
solvers?: Map<ChallengeType, ChallengeSolver>
|
|
14
|
+
/**
|
|
15
|
+
* Optional logger to use for debugging
|
|
16
|
+
*/
|
|
17
|
+
getLogger?: () => Logger
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function createChallengeSolverService(ctx: CreateChallengeSolverServiceContext = {}): ChallengeSolverService {
|
|
21
|
+
// Use injected solvers or fall back to default mocks
|
|
22
|
+
const solvers = ctx.solvers ?? createDefaultSolvers()
|
|
23
|
+
|
|
24
|
+
function getSolver(type: ChallengeType): ChallengeSolver | null {
|
|
25
|
+
// Handle UNSPECIFIED type explicitly
|
|
26
|
+
if (type === ChallengeType.UNSPECIFIED) {
|
|
27
|
+
return {
|
|
28
|
+
solve: async (): Promise<string> => {
|
|
29
|
+
throw new Error('No solver available for challenge type: UNSPECIFIED')
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const value = solvers.get(type) ?? null
|
|
35
|
+
|
|
36
|
+
if (ctx.getLogger) {
|
|
37
|
+
ctx
|
|
38
|
+
.getLogger()
|
|
39
|
+
.debug(
|
|
40
|
+
'createChallengeSolverService',
|
|
41
|
+
'getSolver',
|
|
42
|
+
`Solver for challenge type ${type} is ${value ? 'available' : 'not available'}`,
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return value
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return { getSolver }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Creates the default set of mock solvers for development/testing
|
|
54
|
+
*/
|
|
55
|
+
function createDefaultSolvers(): Map<ChallengeType, ChallengeSolver> {
|
|
56
|
+
return new Map<ChallengeType, ChallengeSolver>([
|
|
57
|
+
[ChallengeType.UNSPECIFIED, createNoneMockSolver()],
|
|
58
|
+
[ChallengeType.TURNSTILE, createTurnstileMockSolver()],
|
|
59
|
+
[ChallengeType.HASHCASH, createHashcashMockSolver()],
|
|
60
|
+
])
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { createChallengeSolverService }
|
|
64
|
+
export type { CreateChallengeSolverServiceContext }
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ChallengeData, ChallengeSolver } from '@l.x/sessions/src/challenge-solvers/types'
|
|
2
|
+
import { sleep } from 'utilities/src/time/timing'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a mock Hashcash proof-of-work solver for development/testing
|
|
6
|
+
*
|
|
7
|
+
* In production, this would:
|
|
8
|
+
* - Extract difficulty/bits from challengeData.extra
|
|
9
|
+
* - Iterate through nonces to find hash with required leading zeros
|
|
10
|
+
* - Return actual proof-of-work solution
|
|
11
|
+
*
|
|
12
|
+
* Hashcash format: version:bits:date:resource::nonce:base64
|
|
13
|
+
*/
|
|
14
|
+
function createHashcashMockSolver(): ChallengeSolver {
|
|
15
|
+
async function solve(challengeData: ChallengeData): Promise<string> {
|
|
16
|
+
// Extract difficulty from extra data
|
|
17
|
+
const difficulty = challengeData.extra?.['bits'] || '20'
|
|
18
|
+
|
|
19
|
+
// Simulate proof-of-work computation time
|
|
20
|
+
// Real implementation would iterate through nonces
|
|
21
|
+
const iterations = parseInt(difficulty) / 4
|
|
22
|
+
for (let i = 0; i < iterations; i++) {
|
|
23
|
+
await sleep(100) // Simulate work
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Generate mock hashcash solution
|
|
27
|
+
const nonce = Math.random().toString(36).substring(2, 15)
|
|
28
|
+
const mockHash = btoa(`${challengeData.challengeId}${nonce}`).slice(0, 27)
|
|
29
|
+
const timestamp = new Date().toISOString().slice(2, 10).replace(/-/g, '')
|
|
30
|
+
const resource = challengeData.challengeId.slice(0, 16)
|
|
31
|
+
|
|
32
|
+
// Return in hashcash format
|
|
33
|
+
return `1:${difficulty}:${timestamp}:${resource}::${nonce}:${mockHash}`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return { solve }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { createHashcashMockSolver }
|