@prosopo/provider 2.1.1 → 2.1.2
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/package.json +11 -11
- package/.dockerignore +0 -5
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/clover.xml +0 -6
- package/coverage/coverage-final.json +0 -1
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -101
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -196
- package/dist/api/admin.d.ts +0 -4
- package/dist/api/admin.d.ts.map +0 -1
- package/dist/api/admin.js +0 -37
- package/dist/api/admin.js.map +0 -1
- package/dist/api/authMiddleware.d.ts +0 -6
- package/dist/api/authMiddleware.d.ts.map +0 -1
- package/dist/api/authMiddleware.js +0 -57
- package/dist/api/authMiddleware.js.map +0 -1
- package/dist/api/captcha.d.ts +0 -4
- package/dist/api/captcha.d.ts.map +0 -1
- package/dist/api/captcha.js +0 -161
- package/dist/api/captcha.js.map +0 -1
- package/dist/api/errorHandler.d.ts +0 -5
- package/dist/api/errorHandler.d.ts.map +0 -1
- package/dist/api/errorHandler.js +0 -14
- package/dist/api/errorHandler.js.map +0 -1
- package/dist/api/verify.d.ts +0 -4
- package/dist/api/verify.d.ts.map +0 -1
- package/dist/api/verify.js +0 -127
- package/dist/api/verify.js.map +0 -1
- package/dist/cjs/api/admin.cjs +0 -38
- package/dist/cjs/api/authMiddleware.cjs +0 -57
- package/dist/cjs/api/captcha.cjs +0 -210
- package/dist/cjs/api/errorHandler.cjs +0 -14
- package/dist/cjs/api/verify.cjs +0 -140
- package/dist/cjs/index.cjs +0 -21
- package/dist/cjs/schedulers/captchaScheduler.cjs +0 -33
- package/dist/cjs/schedulers/getClientList.cjs +0 -31
- package/dist/cjs/tasks/client/clientTasks.cjs +0 -148
- package/dist/cjs/tasks/dataset/datasetTasks.cjs +0 -30
- package/dist/cjs/tasks/dataset/datasetTasksUtils.cjs +0 -34
- package/dist/cjs/tasks/imgCaptcha/imgCaptchaTasks.cjs +0 -281
- package/dist/cjs/tasks/imgCaptcha/imgCaptchaTasksUtils.cjs +0 -25
- package/dist/cjs/tasks/index.cjs +0 -4
- package/dist/cjs/tasks/powCaptcha/powTasks.cjs +0 -133
- package/dist/cjs/tasks/powCaptcha/powTasksUtils.cjs +0 -26
- package/dist/cjs/tasks/tasks.cjs +0 -40
- package/dist/cjs/util.cjs +0 -45
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -9
- package/dist/index.js.map +0 -1
- package/dist/schedulers/captchaScheduler.d.ts +0 -4
- package/dist/schedulers/captchaScheduler.d.ts.map +0 -1
- package/dist/schedulers/captchaScheduler.js +0 -28
- package/dist/schedulers/captchaScheduler.js.map +0 -1
- package/dist/schedulers/getClientList.d.ts +0 -4
- package/dist/schedulers/getClientList.d.ts.map +0 -1
- package/dist/schedulers/getClientList.js +0 -28
- package/dist/schedulers/getClientList.js.map +0 -1
- package/dist/tasks/client/clientTasks.d.ts +0 -13
- package/dist/tasks/client/clientTasks.d.ts.map +0 -1
- package/dist/tasks/client/clientTasks.js +0 -87
- package/dist/tasks/client/clientTasks.js.map +0 -1
- package/dist/tasks/dataset/datasetTasks.d.ts +0 -13
- package/dist/tasks/dataset/datasetTasks.d.ts.map +0 -1
- package/dist/tasks/dataset/datasetTasks.js +0 -19
- package/dist/tasks/dataset/datasetTasks.js.map +0 -1
- package/dist/tasks/dataset/datasetTasksUtils.d.ts +0 -3
- package/dist/tasks/dataset/datasetTasksUtils.d.ts.map +0 -1
- package/dist/tasks/dataset/datasetTasksUtils.js +0 -34
- package/dist/tasks/dataset/datasetTasksUtils.js.map +0 -1
- package/dist/tasks/imgCaptcha/imgCaptchaTasks.d.ts +0 -28
- package/dist/tasks/imgCaptcha/imgCaptchaTasks.d.ts.map +0 -1
- package/dist/tasks/imgCaptcha/imgCaptchaTasks.js +0 -208
- package/dist/tasks/imgCaptcha/imgCaptchaTasks.js.map +0 -1
- package/dist/tasks/imgCaptcha/imgCaptchaTasksUtils.d.ts +0 -7
- package/dist/tasks/imgCaptcha/imgCaptchaTasksUtils.d.ts.map +0 -1
- package/dist/tasks/imgCaptcha/imgCaptchaTasksUtils.js +0 -18
- package/dist/tasks/imgCaptcha/imgCaptchaTasksUtils.js.map +0 -1
- package/dist/tasks/index.d.ts +0 -2
- package/dist/tasks/index.d.ts.map +0 -1
- package/dist/tasks/index.js +0 -2
- package/dist/tasks/index.js.map +0 -1
- package/dist/tasks/powCaptcha/powTasks.d.ts +0 -13
- package/dist/tasks/powCaptcha/powTasks.d.ts.map +0 -1
- package/dist/tasks/powCaptcha/powTasks.js +0 -83
- package/dist/tasks/powCaptcha/powTasks.js.map +0 -1
- package/dist/tasks/powCaptcha/powTasksUtils.d.ts +0 -3
- package/dist/tasks/powCaptcha/powTasksUtils.d.ts.map +0 -1
- package/dist/tasks/powCaptcha/powTasksUtils.js +0 -22
- package/dist/tasks/powCaptcha/powTasksUtils.js.map +0 -1
- package/dist/tasks/tasks.d.ts +0 -22
- package/dist/tasks/tasks.d.ts.map +0 -1
- package/dist/tasks/tasks.js +0 -24
- package/dist/tasks/tasks.js.map +0 -1
- package/dist/tests/index.d.ts +0 -2
- package/dist/tests/index.d.ts.map +0 -1
- package/dist/tests/index.js +0 -2
- package/dist/tests/index.js.map +0 -1
- package/dist/tests/integration/imgCaptcha.integration.test.d.ts +0 -2
- package/dist/tests/integration/imgCaptcha.integration.test.d.ts.map +0 -1
- package/dist/tests/integration/imgCaptcha.integration.test.js +0 -133
- package/dist/tests/integration/imgCaptcha.integration.test.js.map +0 -1
- package/dist/tests/integration/mocks/solvedTestCaptchas.d.ts +0 -32
- package/dist/tests/integration/mocks/solvedTestCaptchas.d.ts.map +0 -1
- package/dist/tests/integration/mocks/solvedTestCaptchas.js +0 -1046
- package/dist/tests/integration/mocks/solvedTestCaptchas.js.map +0 -1
- package/dist/tests/integration/powCaptcha.integration.test.d.ts +0 -2
- package/dist/tests/integration/powCaptcha.integration.test.d.ts.map +0 -1
- package/dist/tests/integration/powCaptcha.integration.test.js +0 -229
- package/dist/tests/integration/powCaptcha.integration.test.js.map +0 -1
- package/dist/tests/integration/registerSitekey.d.ts +0 -2
- package/dist/tests/integration/registerSitekey.d.ts.map +0 -1
- package/dist/tests/integration/registerSitekey.js +0 -17
- package/dist/tests/integration/registerSitekey.js.map +0 -1
- package/dist/tests/unit/api/authMiddleware.unit.test.d.ts +0 -2
- package/dist/tests/unit/api/authMiddleware.unit.test.d.ts.map +0 -1
- package/dist/tests/unit/api/authMiddleware.unit.test.js +0 -87
- package/dist/tests/unit/api/authMiddleware.unit.test.js.map +0 -1
- package/dist/tests/unit/api/errorHandler.unit.test.d.ts +0 -2
- package/dist/tests/unit/api/errorHandler.unit.test.d.ts.map +0 -1
- package/dist/tests/unit/api/errorHandler.unit.test.js +0 -65
- package/dist/tests/unit/api/errorHandler.unit.test.js.map +0 -1
- package/dist/tests/unit/schedulers/captchaScheduler.unit.test.d.ts +0 -2
- package/dist/tests/unit/schedulers/captchaScheduler.unit.test.d.ts.map +0 -1
- package/dist/tests/unit/schedulers/captchaScheduler.unit.test.js +0 -63
- package/dist/tests/unit/schedulers/captchaScheduler.unit.test.js.map +0 -1
- package/dist/tests/unit/tasks/client/clientTasks.unit.test.d.ts +0 -2
- package/dist/tests/unit/tasks/client/clientTasks.unit.test.d.ts.map +0 -1
- package/dist/tests/unit/tasks/client/clientTasks.unit.test.js +0 -172
- package/dist/tests/unit/tasks/client/clientTasks.unit.test.js.map +0 -1
- package/dist/tests/unit/tasks/dataset/datasetTasks.unit.test.d.ts +0 -2
- package/dist/tests/unit/tasks/dataset/datasetTasks.unit.test.d.ts.map +0 -1
- package/dist/tests/unit/tasks/dataset/datasetTasks.unit.test.js +0 -86
- package/dist/tests/unit/tasks/dataset/datasetTasks.unit.test.js.map +0 -1
- package/dist/tests/unit/tasks/dataset/datasetTasksUtils.unit.test.d.ts +0 -2
- package/dist/tests/unit/tasks/dataset/datasetTasksUtils.unit.test.d.ts.map +0 -1
- package/dist/tests/unit/tasks/dataset/datasetTasksUtils.unit.test.js +0 -75
- package/dist/tests/unit/tasks/dataset/datasetTasksUtils.unit.test.js.map +0 -1
- package/dist/tests/unit/tasks/imgCaptcha/imgCaptchaTasks.unit.test.d.ts +0 -2
- package/dist/tests/unit/tasks/imgCaptcha/imgCaptchaTasks.unit.test.d.ts.map +0 -1
- package/dist/tests/unit/tasks/imgCaptcha/imgCaptchaTasks.unit.test.js +0 -266
- package/dist/tests/unit/tasks/imgCaptcha/imgCaptchaTasks.unit.test.js.map +0 -1
- package/dist/tests/unit/tasks/imgCaptcha/imgCaptchaTasksUtils.unit.test.d.ts +0 -2
- package/dist/tests/unit/tasks/imgCaptcha/imgCaptchaTasksUtils.unit.test.d.ts.map +0 -1
- package/dist/tests/unit/tasks/imgCaptcha/imgCaptchaTasksUtils.unit.test.js +0 -46
- package/dist/tests/unit/tasks/imgCaptcha/imgCaptchaTasksUtils.unit.test.js.map +0 -1
- package/dist/tests/unit/tasks/powCaptcha/powTasks.unit.test.d.ts +0 -2
- package/dist/tests/unit/tasks/powCaptcha/powTasks.unit.test.d.ts.map +0 -1
- package/dist/tests/unit/tasks/powCaptcha/powTasks.unit.test.js +0 -209
- package/dist/tests/unit/tasks/powCaptcha/powTasks.unit.test.js.map +0 -1
- package/dist/tests/unit/tasks/powCaptcha/powTasksUtils.unit.test.d.ts +0 -2
- package/dist/tests/unit/tasks/powCaptcha/powTasksUtils.unit.test.d.ts.map +0 -1
- package/dist/tests/unit/tasks/powCaptcha/powTasksUtils.unit.test.js +0 -65
- package/dist/tests/unit/tasks/powCaptcha/powTasksUtils.unit.test.js.map +0 -1
- package/dist/util.d.ts +0 -6
- package/dist/util.d.ts.map +0 -1
- package/dist/util.js +0 -34
- package/dist/util.js.map +0 -1
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { stringToHex, u8aToHex } from "@polkadot/util";
|
|
2
|
-
import { randomAsHex, signatureVerify } from "@polkadot/util-crypto";
|
|
3
|
-
import { ProsopoEnvError } from "@prosopo/common";
|
|
4
|
-
import { compareCaptchaSolutions, computePendingRequestHash, parseAndSortCaptchaSolutions, } from "@prosopo/datasets";
|
|
5
|
-
import { CaptchaStatus, DEFAULT_IMAGE_CAPTCHA_TIMEOUT, } from "@prosopo/types";
|
|
6
|
-
import { at } from "@prosopo/util";
|
|
7
|
-
import { shuffleArray } from "../../util.js";
|
|
8
|
-
import { buildTreeAndGetCommitmentId } from "./imgCaptchaTasksUtils.js";
|
|
9
|
-
export class ImgCaptchaManager {
|
|
10
|
-
constructor(db, pair, logger, captchaConfig) {
|
|
11
|
-
this.db = db;
|
|
12
|
-
this.pair = pair;
|
|
13
|
-
this.logger = logger;
|
|
14
|
-
this.captchaConfig = captchaConfig;
|
|
15
|
-
}
|
|
16
|
-
async getCaptchaWithProof(datasetId, solved, size) {
|
|
17
|
-
const captchaDocs = await this.db.getRandomCaptcha(solved, datasetId, size);
|
|
18
|
-
if (!captchaDocs) {
|
|
19
|
-
throw new ProsopoEnvError("DATABASE.CAPTCHA_GET_FAILED", {
|
|
20
|
-
context: {
|
|
21
|
-
failedFuncName: this.getCaptchaWithProof.name,
|
|
22
|
-
datasetId,
|
|
23
|
-
solved,
|
|
24
|
-
size,
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return captchaDocs;
|
|
29
|
-
}
|
|
30
|
-
async getRandomCaptchasAndRequestHash(datasetId, userAccount, ipAddress, headers) {
|
|
31
|
-
const dataset = await this.db.getDatasetDetails(datasetId);
|
|
32
|
-
if (!dataset) {
|
|
33
|
-
throw new ProsopoEnvError("DATABASE.DATASET_GET_FAILED", {
|
|
34
|
-
context: {
|
|
35
|
-
failedFuncName: this.getRandomCaptchasAndRequestHash.name,
|
|
36
|
-
dataset,
|
|
37
|
-
datasetId,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
const unsolvedCount = Math.abs(Math.trunc(this.captchaConfig.unsolved.count));
|
|
42
|
-
const solvedCount = Math.abs(Math.trunc(this.captchaConfig.solved.count));
|
|
43
|
-
if (!solvedCount) {
|
|
44
|
-
throw new ProsopoEnvError("CONFIG.INVALID_CAPTCHA_NUMBER");
|
|
45
|
-
}
|
|
46
|
-
const solved = await this.getCaptchaWithProof(datasetId, true, solvedCount);
|
|
47
|
-
let unsolved = [];
|
|
48
|
-
if (unsolvedCount) {
|
|
49
|
-
unsolved = await this.getCaptchaWithProof(datasetId, false, unsolvedCount);
|
|
50
|
-
}
|
|
51
|
-
const captchas = shuffleArray([...solved, ...unsolved]);
|
|
52
|
-
const salt = randomAsHex();
|
|
53
|
-
const requestHash = computePendingRequestHash(captchas.map((c) => c.captchaId), userAccount, salt);
|
|
54
|
-
const currentTime = Date.now();
|
|
55
|
-
const signedRequestHash = u8aToHex(this.pair.sign(stringToHex(requestHash)));
|
|
56
|
-
const timeLimit = captchas
|
|
57
|
-
.map((captcha) => captcha.timeLimitMs || DEFAULT_IMAGE_CAPTCHA_TIMEOUT)
|
|
58
|
-
.reduce((a, b) => a + b, 0);
|
|
59
|
-
const deadlineTs = timeLimit + currentTime;
|
|
60
|
-
const currentBlockNumber = 0;
|
|
61
|
-
await this.db.storeDappUserPending(userAccount, requestHash, salt, deadlineTs, currentTime, ipAddress, headers);
|
|
62
|
-
return {
|
|
63
|
-
captchas,
|
|
64
|
-
requestHash,
|
|
65
|
-
timestamp: currentTime,
|
|
66
|
-
signedRequestHash,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
async dappUserSolution(userAccount, dappAccount, requestHash, captchas, userRequestHashSignature, timestamp, providerRequestHashSignature, ipAddress, headers) {
|
|
70
|
-
const verification = signatureVerify(stringToHex(requestHash), userRequestHashSignature, userAccount);
|
|
71
|
-
if (!verification.isValid) {
|
|
72
|
-
this.logger.info("Invalid user requestHash signature");
|
|
73
|
-
throw new ProsopoEnvError("GENERAL.INVALID_SIGNATURE", {
|
|
74
|
-
context: { failedFuncName: this.dappUserSolution.name, userAccount },
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
const providerRequestHashSignatureVerify = signatureVerify(stringToHex(requestHash.toString()), providerRequestHashSignature, this.pair.address);
|
|
78
|
-
if (!providerRequestHashSignatureVerify.isValid) {
|
|
79
|
-
this.logger.info("Invalid provider requestHash signature");
|
|
80
|
-
throw new ProsopoEnvError("GENERAL.INVALID_SIGNATURE", {
|
|
81
|
-
context: {
|
|
82
|
-
failedFuncName: this.dappUserSolution.name,
|
|
83
|
-
userAccount,
|
|
84
|
-
error: "requestHash signature is invalid",
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
let response = {
|
|
89
|
-
captchas: [],
|
|
90
|
-
verified: false,
|
|
91
|
-
};
|
|
92
|
-
const pendingRecord = await this.db.getDappUserPending(requestHash);
|
|
93
|
-
const unverifiedCaptchaIds = captchas.map((captcha) => captcha.captchaId);
|
|
94
|
-
const pendingRequest = await this.validateDappUserSolutionRequestIsPending(requestHash, pendingRecord, userAccount, unverifiedCaptchaIds);
|
|
95
|
-
if (pendingRequest) {
|
|
96
|
-
const { storedCaptchas, receivedCaptchas, captchaIds } = await this.validateReceivedCaptchasAgainstStoredCaptchas(captchas);
|
|
97
|
-
const { tree, commitmentId } = buildTreeAndGetCommitmentId(receivedCaptchas);
|
|
98
|
-
const datasetId = at(storedCaptchas, 0).datasetId;
|
|
99
|
-
if (!datasetId) {
|
|
100
|
-
throw new ProsopoEnvError("CAPTCHA.ID_MISMATCH", {
|
|
101
|
-
context: { failedFuncName: this.dappUserSolution.name },
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
await this.db.updateDappUserPendingStatus(requestHash);
|
|
105
|
-
const commit = {
|
|
106
|
-
id: commitmentId,
|
|
107
|
-
userAccount: userAccount,
|
|
108
|
-
dappAccount,
|
|
109
|
-
providerAccount: this.pair.address,
|
|
110
|
-
datasetId,
|
|
111
|
-
result: { status: CaptchaStatus.pending },
|
|
112
|
-
userSignature: userRequestHashSignature,
|
|
113
|
-
userSubmitted: true,
|
|
114
|
-
serverChecked: false,
|
|
115
|
-
requestedAtTimestamp: timestamp,
|
|
116
|
-
ipAddress,
|
|
117
|
-
headers,
|
|
118
|
-
};
|
|
119
|
-
await this.db.storeDappUserSolution(receivedCaptchas, commit);
|
|
120
|
-
if (compareCaptchaSolutions(receivedCaptchas, storedCaptchas)) {
|
|
121
|
-
response = {
|
|
122
|
-
captchas: captchaIds.map((id) => ({
|
|
123
|
-
captchaId: id,
|
|
124
|
-
proof: tree.proof(id),
|
|
125
|
-
})),
|
|
126
|
-
verified: true,
|
|
127
|
-
};
|
|
128
|
-
await this.db.approveDappUserCommitment(commitmentId);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
await this.db.disapproveDappUserCommitment(commitmentId, "CAPTCHA.INVALID_SOLUTION");
|
|
132
|
-
response = {
|
|
133
|
-
captchas: captchaIds.map((id) => ({
|
|
134
|
-
captchaId: id,
|
|
135
|
-
proof: [[]],
|
|
136
|
-
})),
|
|
137
|
-
verified: false,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
this.logger.info("Request hash not found");
|
|
143
|
-
}
|
|
144
|
-
return response;
|
|
145
|
-
}
|
|
146
|
-
async validateReceivedCaptchasAgainstStoredCaptchas(captchas) {
|
|
147
|
-
const receivedCaptchas = parseAndSortCaptchaSolutions(captchas);
|
|
148
|
-
const captchaIds = receivedCaptchas.map((captcha) => captcha.captchaId);
|
|
149
|
-
const storedCaptchas = await this.db.getCaptchaById(captchaIds);
|
|
150
|
-
if (!storedCaptchas || receivedCaptchas.length !== storedCaptchas.length) {
|
|
151
|
-
throw new ProsopoEnvError("CAPTCHA.INVALID_CAPTCHA_ID", {
|
|
152
|
-
context: {
|
|
153
|
-
failedFuncName: this.validateReceivedCaptchasAgainstStoredCaptchas.name,
|
|
154
|
-
captchas,
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
if (!storedCaptchas.every((captcha) => captcha.datasetId === at(storedCaptchas, 0).datasetId)) {
|
|
159
|
-
throw new ProsopoEnvError("CAPTCHA.DIFFERENT_DATASET_IDS", {
|
|
160
|
-
context: {
|
|
161
|
-
failedFuncName: this.validateReceivedCaptchasAgainstStoredCaptchas.name,
|
|
162
|
-
captchas,
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
return { storedCaptchas, receivedCaptchas, captchaIds };
|
|
167
|
-
}
|
|
168
|
-
async validateDappUserSolutionRequestIsPending(requestHash, pendingRecord, userAccount, captchaIds) {
|
|
169
|
-
const currentTime = Date.now();
|
|
170
|
-
if (!pendingRecord) {
|
|
171
|
-
this.logger.info("No pending record found");
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
if (pendingRecord.deadlineTimestamp < currentTime) {
|
|
175
|
-
this.logger.info("Deadline for responding to captcha has expired");
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
if (pendingRecord) {
|
|
179
|
-
const pendingHashComputed = computePendingRequestHash(captchaIds, userAccount, pendingRecord.salt);
|
|
180
|
-
return requestHash === pendingHashComputed;
|
|
181
|
-
}
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
async getDappUserCommitmentById(commitmentId) {
|
|
185
|
-
const dappUserSolution = await this.db.getDappUserCommitmentById(commitmentId);
|
|
186
|
-
if (!dappUserSolution) {
|
|
187
|
-
throw new ProsopoEnvError("CAPTCHA.DAPP_USER_SOLUTION_NOT_FOUND", {
|
|
188
|
-
context: {
|
|
189
|
-
failedFuncName: this.getDappUserCommitmentById.name,
|
|
190
|
-
commitmentId: commitmentId,
|
|
191
|
-
},
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
return dappUserSolution;
|
|
195
|
-
}
|
|
196
|
-
async getDappUserCommitmentByAccount(userAccount, dappAccount) {
|
|
197
|
-
const dappUserSolutions = await this.db.getDappUserCommitmentByAccount(userAccount, dappAccount);
|
|
198
|
-
if (dappUserSolutions.length > 0) {
|
|
199
|
-
for (const dappUserSolution of dappUserSolutions) {
|
|
200
|
-
if (dappUserSolution.result.status === CaptchaStatus.approved) {
|
|
201
|
-
return dappUserSolution;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return undefined;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
//# sourceMappingURL=imgCaptchaTasks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"imgCaptchaTasks.js","sourceRoot":"","sources":["../../../src/tasks/imgCaptcha/imgCaptchaTasks.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAe,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EACN,uBAAuB,EACvB,yBAAyB,EACzB,4BAA4B,GAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAIN,aAAa,EACb,6BAA6B,GAK7B,MAAM,gBAAgB,CAAC;AAKxB,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AAExE,MAAM,OAAO,iBAAiB;IAM7B,YACC,EAAqB,EACrB,IAAiB,EACjB,MAAc,EACd,aAA4B;QAE5B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,aAAa,CAA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AgB,EAAE,CAAC;YACvB,MAAM,IAAI,eAAe,CAAC,sCAAsC,EAAE;gBACjE,OAAO,EAAE;oBACR,cAAc,EAAE,IAAI,CAAC,yBAAyB,CAAC,IAAI;oBACnD,YAAY,EAAE,YAAY;iBAC1B;aACD,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,gBAAgB,CAAC;IACzB,CAAC;IAGD,KAAK,CAAC,8BAA8B,CACnC,WAAmB,EACnB,WAAmB;QAEnB,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,8BAA8B,CACrE,WAAW,EACX,WAAW,CACX,CAAC;QACF,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAClC,KAAK,MAAM,gBAAgB,IAAI,iBAAiB,EAAE,CAAC;gBAClD,IAAI,gBAAgB,CAAC,MAAM,CAAC,MAAM,KAAK,aAAa,CAAC,QAAQ,EAAE,CAAC;oBAC/D,OAAO,gBAAgB,CAAC;gBACzB,CAAC;YACF,CAAC;QACF,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;CACD"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { CaptchaMerkleTree } from "@prosopo/datasets";
|
|
2
|
-
import type { CaptchaSolution } from "@prosopo/types";
|
|
3
|
-
export declare const buildTreeAndGetCommitmentId: (captchaSolutions: CaptchaSolution[]) => {
|
|
4
|
-
tree: CaptchaMerkleTree;
|
|
5
|
-
commitmentId: string;
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=imgCaptchaTasksUtils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"imgCaptchaTasksUtils.d.ts","sourceRoot":"","sources":["../../../src/tasks/imgCaptcha/imgCaptchaTasksUtils.ts"],"names":[],"mappings":"AAcA,OAAO,EACN,iBAAiB,EAEjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAOtD,eAAO,MAAM,2BAA2B,qBACrB,eAAe,EAAE,KACjC;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAqBjD,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ProsopoEnvError } from "@prosopo/common";
|
|
2
|
-
import { CaptchaMerkleTree, computeCaptchaSolutionHash, } from "@prosopo/datasets";
|
|
3
|
-
export const buildTreeAndGetCommitmentId = (captchaSolutions) => {
|
|
4
|
-
const tree = new CaptchaMerkleTree();
|
|
5
|
-
const solutionsHashed = captchaSolutions.map((captcha) => computeCaptchaSolutionHash(captcha));
|
|
6
|
-
tree.build(solutionsHashed);
|
|
7
|
-
const commitmentId = tree.root?.hash;
|
|
8
|
-
if (!commitmentId) {
|
|
9
|
-
throw new ProsopoEnvError("CONTRACT.CAPTCHA_SOLUTION_COMMITMENT_DOES_NOT_EXIST", {
|
|
10
|
-
context: {
|
|
11
|
-
failedFuncName: buildTreeAndGetCommitmentId.name,
|
|
12
|
-
commitmentId: commitmentId,
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return { tree, commitmentId };
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=imgCaptchaTasksUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"imgCaptchaTasksUtils.js","sourceRoot":"","sources":["../../../src/tasks/imgCaptcha/imgCaptchaTasksUtils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EACN,iBAAiB,EACjB,0BAA0B,GAC1B,MAAM,mBAAmB,CAAC;AAQ3B,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAC1C,gBAAmC,EACiB,EAAE;IACtD,MAAM,IAAI,GAAG,IAAI,iBAAiB,EAAE,CAAC;IACrC,MAAM,eAAe,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CACxD,0BAA0B,CAAC,OAAO,CAAC,CACnC,CAAC;IACF,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IAE5B,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC;IACrC,IAAI,CAAC,YAAY,EAAE,CAAC;QACnB,MAAM,IAAI,eAAe,CACxB,qDAAqD,EACrD;YACC,OAAO,EAAE;gBACR,cAAc,EAAE,2BAA2B,CAAC,IAAI;gBAChD,YAAY,EAAE,YAAY;aAC1B;SACD,CACD,CAAC;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;AAC/B,CAAC,CAAC"}
|
package/dist/tasks/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tasks/index.ts"],"names":[],"mappings":"AAaA,cAAc,YAAY,CAAC"}
|
package/dist/tasks/index.js
DELETED
package/dist/tasks/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tasks/index.ts"],"names":[],"mappings":"AAaA,cAAc,YAAY,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { KeyringPair } from "@polkadot/keyring/types";
|
|
2
|
-
import { type PoWCaptcha, type PoWChallengeId, type RequestHeaders } from "@prosopo/types";
|
|
3
|
-
import type { IProviderDatabase } from "@prosopo/types-database";
|
|
4
|
-
export declare class PowCaptchaManager {
|
|
5
|
-
pair: KeyringPair;
|
|
6
|
-
db: IProviderDatabase;
|
|
7
|
-
POW_SEPARATOR: string;
|
|
8
|
-
constructor(pair: KeyringPair, db: IProviderDatabase);
|
|
9
|
-
getPowCaptchaChallenge(userAccount: string, dappAccount: string, origin: string): Promise<PoWCaptcha>;
|
|
10
|
-
verifyPowCaptchaSolution(challenge: PoWChallengeId, difficulty: number, providerChallengeSignature: string, nonce: number, timeout: number, userTimestampSignature: string, ipAddress: string, headers: RequestHeaders): Promise<boolean>;
|
|
11
|
-
serverVerifyPowCaptchaSolution(dappAccount: string, challenge: string, timeout: number): Promise<boolean>;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=powTasks.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"powTasks.d.ts","sourceRoot":"","sources":["../../../src/tasks/powCaptcha/powTasks.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAG3D,OAAO,EAKN,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAMjE,qBAAa,iBAAiB;IAC7B,IAAI,EAAE,WAAW,CAAC;IAClB,EAAE,EAAE,iBAAiB,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,iBAAiB;IAa9C,sBAAsB,CAC3B,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,GACZ,OAAO,CAAC,UAAU,CAAC;IA2BhB,wBAAwB,CAC7B,SAAS,EAAE,cAAc,EACzB,UAAU,EAAE,MAAM,EAClB,0BAA0B,EAAE,MAAM,EAClC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,cAAc,GACrB,OAAO,CAAC,OAAO,CAAC;IAuEb,8BAA8B,CACnC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC;CAkCnB"}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { stringToHex, u8aToHex } from "@polkadot/util";
|
|
2
|
-
import { ProsopoEnvError, getLoggerDefault } from "@prosopo/common";
|
|
3
|
-
import { ApiParams, CaptchaStatus, POW_SEPARATOR, } from "@prosopo/types";
|
|
4
|
-
import { at, verifyRecency } from "@prosopo/util";
|
|
5
|
-
import { checkPowSignature, validateSolution } from "./powTasksUtils.js";
|
|
6
|
-
const logger = getLoggerDefault();
|
|
7
|
-
export class PowCaptchaManager {
|
|
8
|
-
constructor(pair, db) {
|
|
9
|
-
this.pair = pair;
|
|
10
|
-
this.db = db;
|
|
11
|
-
this.POW_SEPARATOR = POW_SEPARATOR;
|
|
12
|
-
}
|
|
13
|
-
async getPowCaptchaChallenge(userAccount, dappAccount, origin) {
|
|
14
|
-
const difficulty = 4;
|
|
15
|
-
const requestedAtTimestamp = Date.now();
|
|
16
|
-
const challenge = `${requestedAtTimestamp}___${userAccount}___${dappAccount}`;
|
|
17
|
-
const challengeSignature = u8aToHex(this.pair.sign(stringToHex(challenge)));
|
|
18
|
-
return {
|
|
19
|
-
challenge,
|
|
20
|
-
difficulty,
|
|
21
|
-
providerSignature: challengeSignature,
|
|
22
|
-
requestedAtTimestamp,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
async verifyPowCaptchaSolution(challenge, difficulty, providerChallengeSignature, nonce, timeout, userTimestampSignature, ipAddress, headers) {
|
|
26
|
-
checkPowSignature(challenge, providerChallengeSignature, this.pair.address, ApiParams.challenge);
|
|
27
|
-
const challengeSplit = challenge.split(this.POW_SEPARATOR);
|
|
28
|
-
const timestamp = Number.parseInt(at(challengeSplit, 0));
|
|
29
|
-
const userAccount = at(challengeSplit, 1);
|
|
30
|
-
checkPowSignature(timestamp.toString(), userTimestampSignature, userAccount, ApiParams.timestamp);
|
|
31
|
-
const challengeRecord = await this.db.getPowCaptchaRecordByChallenge(challenge);
|
|
32
|
-
if (!challengeRecord) {
|
|
33
|
-
logger.debug("No record of this challenge");
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
if (!verifyRecency(challenge, timeout)) {
|
|
37
|
-
await this.db.updatePowCaptchaRecord(challenge, {
|
|
38
|
-
status: CaptchaStatus.disapproved,
|
|
39
|
-
reason: "CAPTCHA.INVALID_TIMESTAMP",
|
|
40
|
-
}, false, true, userTimestampSignature);
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
const correct = validateSolution(nonce, challenge, difficulty);
|
|
44
|
-
let result = { status: CaptchaStatus.approved };
|
|
45
|
-
if (!correct) {
|
|
46
|
-
result = {
|
|
47
|
-
status: CaptchaStatus.disapproved,
|
|
48
|
-
reason: "CAPTCHA.INVALID_SOLUTION",
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
await this.db.updatePowCaptchaRecord(challenge, result, false, true, userTimestampSignature);
|
|
52
|
-
return correct;
|
|
53
|
-
}
|
|
54
|
-
async serverVerifyPowCaptchaSolution(dappAccount, challenge, timeout) {
|
|
55
|
-
const challengeRecord = await this.db.getPowCaptchaRecordByChallenge(challenge);
|
|
56
|
-
if (!challengeRecord) {
|
|
57
|
-
throw new ProsopoEnvError("DATABASE.CAPTCHA_GET_FAILED", {
|
|
58
|
-
context: {
|
|
59
|
-
failedFuncName: this.serverVerifyPowCaptchaSolution.name,
|
|
60
|
-
challenge,
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
if (challengeRecord.serverChecked)
|
|
65
|
-
return false;
|
|
66
|
-
const challengeDappAccount = challengeRecord.dappAccount;
|
|
67
|
-
if (dappAccount !== challengeDappAccount) {
|
|
68
|
-
throw new ProsopoEnvError("CAPTCHA.DAPP_USER_SOLUTION_NOT_FOUND", {
|
|
69
|
-
context: {
|
|
70
|
-
failedFuncName: this.serverVerifyPowCaptchaSolution.name,
|
|
71
|
-
dappAccount,
|
|
72
|
-
challengeDappAccount,
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
verifyRecency(challenge, timeout);
|
|
77
|
-
await this.db.markDappUserPoWCommitmentsChecked([
|
|
78
|
-
challengeRecord.challenge,
|
|
79
|
-
]);
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
//# sourceMappingURL=powTasks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"powTasks.js","sourceRoot":"","sources":["../../../src/tasks/powCaptcha/powTasks.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EACN,SAAS,EAET,aAAa,EACb,aAAa,GAIb,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEzE,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC;AAElC,MAAM,OAAO,iBAAiB;IAK7B,YAAY,IAAiB,EAAE,EAAqB;QACnD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACpC,CAAC;IASD,KAAK,CAAC,sBAAsB,CAC3B,WAAmB,EACnB,WAAmB,EACnB,MAAc;QAEd,MAAM,UAAU,GAAG,CAAC,CAAC;QACrB,MAAM,oBAAoB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAGxC,MAAM,SAAS,GAAmB,GAAG,oBAAoB,MAAM,WAAW,MAAM,WAAW,EAAE,CAAC;QAC9F,MAAM,kBAAkB,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAC5E,OAAO;YACN,SAAS;YACT,UAAU;YACV,iBAAiB,EAAE,kBAAkB;YACrC,oBAAo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ateSolution: (nonce: number, challenge: string, difficulty: number) => boolean;
|
|
2
|
-
export declare const checkPowSignature: (challenge: string, signature: string, address: string, signatureType?: string) => void;
|
|
3
|
-
//# sourceMappingURL=powTasksUtils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"powTasksUtils.d.ts","sourceRoot":"","sources":["../../../src/tasks/powCaptcha/powTasksUtils.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,gBAAgB,UACrB,MAAM,aACF,MAAM,cACL,MAAM,KAChB,OAIkC,CAAC;AAEtC,eAAO,MAAM,iBAAiB,cAClB,MAAM,aACN,MAAM,WACR,MAAM,kBACC,MAAM,KACpB,IAgBF,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { sha256 } from "@noble/hashes/sha256";
|
|
2
|
-
import { stringToHex } from "@polkadot/util";
|
|
3
|
-
import { signatureVerify } from "@polkadot/util-crypto";
|
|
4
|
-
import { ProsopoContractError } from "@prosopo/common";
|
|
5
|
-
export const validateSolution = (nonce, challenge, difficulty) => Array.from(sha256(new TextEncoder().encode(nonce + challenge)))
|
|
6
|
-
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
7
|
-
.join("")
|
|
8
|
-
.startsWith("0".repeat(difficulty));
|
|
9
|
-
export const checkPowSignature = (challenge, signature, address, signatureType) => {
|
|
10
|
-
const signatureVerification = signatureVerify(stringToHex(challenge), signature, address);
|
|
11
|
-
if (!signatureVerification.isValid) {
|
|
12
|
-
throw new ProsopoContractError("GENERAL.INVALID_SIGNATURE", {
|
|
13
|
-
context: {
|
|
14
|
-
ERROR: `Signature is invalid for this message: ${signatureType}`,
|
|
15
|
-
failedFuncName: checkPowSignature.name,
|
|
16
|
-
signature,
|
|
17
|
-
signatureType,
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=powTasksUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"powTasksUtils.js","sourceRoot":"","sources":["../../../src/tasks/powCaptcha/powTasksUtils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAIvD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC/B,KAAa,EACb,SAAiB,EACjB,UAAkB,EACR,EAAE,CACZ,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC;KAC7D,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;KACjD,IAAI,CAAC,EAAE,CAAC;KACR,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;AAEtC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAChC,SAAiB,EACjB,SAAiB,EACjB,OAAe,EACf,aAAsB,EACf,EAAE;IACT,MAAM,qBAAqB,GAAG,eAAe,CAC5C,WAAW,CAAC,SAAS,CAAC,EACtB,SAAS,EACT,OAAO,CACP,CAAC;IACF,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,CAAC;QACpC,MAAM,IAAI,oBAAoB,CAAC,2BAA2B,EAAE;YAC3D,OAAO,EAAE;gBACR,KAAK,EAAE,0CAA0C,aAAa,EAAE;gBAChE,cAAc,EAAE,iBAAiB,CAAC,IAAI;gBACtC,SAAS;gBACT,aAAa;aACb;SACD,CAAC,CAAC;IACJ,CAAC;AACF,CAAC,CAAC"}
|
package/dist/tasks/tasks.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { KeyringPair } from "@polkadot/keyring/types";
|
|
2
|
-
import { type Logger } from "@prosopo/common";
|
|
3
|
-
import type { CaptchaConfig, ProsopoConfigOutput } from "@prosopo/types";
|
|
4
|
-
import type { IProviderDatabase } from "@prosopo/types-database";
|
|
5
|
-
import type { ProviderEnvironment } from "@prosopo/types-env";
|
|
6
|
-
import { ClientTaskManager } from "./client/clientTasks.js";
|
|
7
|
-
import { DatasetManager } from "./dataset/datasetTasks.js";
|
|
8
|
-
import { ImgCaptchaManager } from "./imgCaptcha/imgCaptchaTasks.js";
|
|
9
|
-
import { PowCaptchaManager } from "./powCaptcha/powTasks.js";
|
|
10
|
-
export declare class Tasks {
|
|
11
|
-
db: IProviderDatabase;
|
|
12
|
-
captchaConfig: CaptchaConfig;
|
|
13
|
-
logger: Logger;
|
|
14
|
-
config: ProsopoConfigOutput;
|
|
15
|
-
pair: KeyringPair;
|
|
16
|
-
powCaptchaManager: PowCaptchaManager;
|
|
17
|
-
datasetManager: DatasetManager;
|
|
18
|
-
imgCaptchaManager: ImgCaptchaManager;
|
|
19
|
-
clientTaskManager: ClientTaskManager;
|
|
20
|
-
constructor(env: ProviderEnvironment);
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=tasks.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../../src/tasks/tasks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,KAAK,MAAM,EAA8B,MAAM,iBAAiB,CAAC;AAc1E,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAK7D,qBAAa,KAAK;IACjB,EAAE,EAAE,iBAAiB,CAAC;IACtB,aAAa,EAAE,aAAa,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,mBAAmB,CAAC;IAC5B,IAAI,EAAE,WAAW,CAAC;IAClB,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,cAAc,EAAE,cAAc,CAAC;IAC/B,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,iBAAiB,EAAE,iBAAiB,CAAC;gBAEzB,GAAG,EAAE,mBAAmB;CA+BpC"}
|
package/dist/tasks/tasks.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ProsopoEnvError, getLogger } from "@prosopo/common";
|
|
2
|
-
import { ClientTaskManager } from "./client/clientTasks.js";
|
|
3
|
-
import { DatasetManager } from "./dataset/datasetTasks.js";
|
|
4
|
-
import { ImgCaptchaManager } from "./imgCaptcha/imgCaptchaTasks.js";
|
|
5
|
-
import { PowCaptchaManager } from "./powCaptcha/powTasks.js";
|
|
6
|
-
export class Tasks {
|
|
7
|
-
constructor(env) {
|
|
8
|
-
this.config = env.config;
|
|
9
|
-
this.db = env.getDb();
|
|
10
|
-
this.captchaConfig = env.config.captchas;
|
|
11
|
-
this.logger = getLogger(env.config.logLevel, "Tasks");
|
|
12
|
-
if (!env.pair) {
|
|
13
|
-
throw new ProsopoEnvError("DEVELOPER.MISSING_PROVIDER_PAIR", {
|
|
14
|
-
context: { failedFuncName: "Tasks.constructor" },
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
this.pair = env.pair;
|
|
18
|
-
this.powCaptchaManager = new PowCaptchaManager(this.pair, this.db);
|
|
19
|
-
this.datasetManager = new DatasetManager(this.config, this.logger, this.captchaConfig, this.db);
|
|
20
|
-
this.imgCaptchaManager = new ImgCaptchaManager(this.db, this.pair, this.logger, this.captchaConfig);
|
|
21
|
-
this.clientTaskManager = new ClientTaskManager(this.config, this.logger, this.db);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=tasks.js.map
|
package/dist/tasks/tasks.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../src/tasks/tasks.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,eAAe,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAiB1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAK7D,MAAM,OAAO,KAAK;IAWjB,YAAY,GAAwB;QACnC,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;QACzB,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,aAAa,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC;QACzC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACtD,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YACf,MAAM,IAAI,eAAe,CAAC,iCAAiC,EAAE;gBAC5D,OAAO,EAAE,EAAE,cAAc,EAAE,mBAAmB,EAAE;aAChD,CAAC,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QAErB,IAAI,CAAC,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QACnE,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CACvC,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,EAAE,CACP,CAAC;QACF,IAAI,CAAC,iBAAiB,GAAG,IAAI,iBAAiB,CAC7C,IAAI,CAAC,EAAE,EACP,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,aAAa,CAClB,CAAC;QACF,IAAI,CAAC,iBAAiB,GAAG,IAAI,iBAAiB,CAC7C,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,EAAE,CACP,CAAC;IACH,CAAC;CACD"}
|
package/dist/tests/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tests/index.ts"],"names":[],"mappings":""}
|
package/dist/tests/index.js
DELETED
package/dist/tests/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tests/index.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"imgCaptcha.integration.test.d.ts","sourceRoot":"","sources":["../../../src/tests/integration/imgCaptcha.integration.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { stringToU8a, u8aToHex } from "@polkadot/util";
|
|
2
|
-
import { getPairAsync } from "@prosopo/contract";
|
|
3
|
-
import { datasetWithSolutionHashes } from "@prosopo/datasets";
|
|
4
|
-
import { ApiParams, ApiPaths, } from "@prosopo/types";
|
|
5
|
-
import fetch from "node-fetch";
|
|
6
|
-
import { beforeAll, describe, expect, it } from "vitest";
|
|
7
|
-
import { dummyUserAccount } from "./mocks/solvedTestCaptchas.js";
|
|
8
|
-
import { registerSiteKey } from "./registerSitekey.js";
|
|
9
|
-
const solutions = datasetWithSolutionHashes;
|
|
10
|
-
const baseUrl = "http://localhost:9229";
|
|
11
|
-
const dappAccount = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY";
|
|
12
|
-
const userAccount = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty";
|
|
13
|
-
const unRegisteredDappAccount = "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL";
|
|
14
|
-
const getSolvedCaptchas = (captchas, solutions) => captchas.map((captcha) => {
|
|
15
|
-
const solvedCaptcha = solutions.find((solvedCaptcha) => solvedCaptcha.captchaContentId === captcha.captchaContentId);
|
|
16
|
-
if (!solvedCaptcha || !solvedCaptcha.solution) {
|
|
17
|
-
throw new Error("Solution not found for captcha");
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
captchaContentId: captcha.captchaContentId,
|
|
21
|
-
captchaId: captcha.captchaId,
|
|
22
|
-
salt: solvedCaptcha.salt,
|
|
23
|
-
solution: solvedCaptcha.solution,
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
describe("Image Captcha Integration Tests", () => {
|
|
27
|
-
describe("GetImageCaptchaChallenge", () => {
|
|
28
|
-
beforeAll(async () => {
|
|
29
|
-
await registerSiteKey(dappAccount);
|
|
30
|
-
});
|
|
31
|
-
it("should supply an image captcha challenge to a Dapp User", async () => {
|
|
32
|
-
const origin = "http://localhost";
|
|
33
|
-
const getImageCaptchaURL = `${baseUrl}${ApiPaths.GetImageCaptchaChallenge}/${solutions.datasetId}/${userAccount}/${dappAccount}`;
|
|
34
|
-
const response = await fetch(getImageCaptchaURL, {
|
|
35
|
-
method: "GET",
|
|
36
|
-
headers: {
|
|
37
|
-
"Content-Type": "application/json",
|
|
38
|
-
Origin: origin,
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
expect(response.status).toBe(200);
|
|
42
|
-
const data = await response.json();
|
|
43
|
-
expect(data).toHaveProperty("captchas");
|
|
44
|
-
});
|
|
45
|
-
it("should not supply an image captcha challenge to a Dapp User if the site key is not registered", async () => {
|
|
46
|
-
const origin = "http://localhost";
|
|
47
|
-
const getImageCaptchaURL = `${baseUrl}${ApiPaths.GetImageCaptchaChallenge}/${solutions.datasetId}/${userAccount}/${unRegisteredDappAccount}`;
|
|
48
|
-
const response = await fetch(getImageCaptchaURL, {
|
|
49
|
-
method: "GET",
|
|
50
|
-
headers: {
|
|
51
|
-
"Content-Type": "application/json",
|
|
52
|
-
Origin: origin,
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
expect(response.status).toBe(200);
|
|
56
|
-
const data = (await response.json());
|
|
57
|
-
expect(data).toHaveProperty("error");
|
|
58
|
-
expect(data.error).toBe("Site key not registered");
|
|
59
|
-
});
|
|
60
|
-
it("should fail if datasetID is incorrect", async () => {
|
|
61
|
-
const datasetId = "thewrongdsetId";
|
|
62
|
-
const getImageCaptchaURL = `${baseUrl}${ApiPaths.GetImageCaptchaChallenge}/${datasetId}/${userAccount}/${dappAccount}`;
|
|
63
|
-
const response = await fetch(getImageCaptchaURL, {
|
|
64
|
-
method: "GET",
|
|
65
|
-
headers: {
|
|
66
|
-
"Content-Type": "application/json",
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
expect(response.status).toBe(400);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
describe("SubmitImageCaptchaSolution", () => {
|
|
73
|
-
it("should verify a correctly completed image captcha as true", async () => {
|
|
74
|
-
const pair = await getPairAsync(dummyUserAccount.seed, undefined, "sr25519", 42);
|
|
75
|
-
const userAccount = dummyUserAccount.address;
|
|
76
|
-
const origin = "http://localhost";
|
|
77
|
-
const getImageCaptchaURL = `${baseUrl}${ApiPaths.GetImageCaptchaChallenge}/${solutions.datasetId}/${userAccount}/${dappAccount}`;
|
|
78
|
-
const response = await fetch(getImageCaptchaURL, {
|
|
79
|
-
method: "GET",
|
|
80
|
-
headers: {
|
|
81
|
-
"Content-Type": "application/json",
|
|
82
|
-
Origin: origin,
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
expect(response.status).toBe(200);
|
|
86
|
-
const data = (await response.json());
|
|
87
|
-
const solvedCaptchas = datasetWithSolutionHashes.captchas.map((captcha) => ({
|
|
88
|
-
captchaContentId: captcha.captchaContentId,
|
|
89
|
-
solution: captcha.solution
|
|
90
|
-
? captcha.solution.map((s) => s.toString())
|
|
91
|
-
: captcha.solution,
|
|
92
|
-
salt: captcha.salt,
|
|
93
|
-
}));
|
|
94
|
-
const temp = data.captchas.map((captcha) => {
|
|
95
|
-
const solvedCaptcha = solvedCaptchas.find((solvedCaptcha) => solvedCaptcha.captchaContentId === captcha.captchaContentId);
|
|
96
|
-
if (!solvedCaptcha || !solvedCaptcha.solution) {
|
|
97
|
-
throw new Error("wtf?");
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
captchaContentId: captcha.captchaContentId,
|
|
101
|
-
captchaId: captcha.captchaId,
|
|
102
|
-
salt: solvedCaptcha.salt,
|
|
103
|
-
solution: solvedCaptcha.solution,
|
|
104
|
-
};
|
|
105
|
-
});
|
|
106
|
-
const body = {
|
|
107
|
-
[ApiParams.captchas]: temp,
|
|
108
|
-
[ApiParams.dapp]: dappAccount,
|
|
109
|
-
[ApiParams.requestHash]: data.requestHash,
|
|
110
|
-
[ApiParams.signature]: {
|
|
111
|
-
[ApiParams.user]: {
|
|
112
|
-
[ApiParams.requestHash]: u8aToHex(pair.sign(stringToU8a(data.requestHash))),
|
|
113
|
-
},
|
|
114
|
-
[ApiParams.provider]: data[ApiParams.signature][ApiParams.provider],
|
|
115
|
-
},
|
|
116
|
-
[ApiParams.timestamp]: data.timestamp,
|
|
117
|
-
[ApiParams.user]: userAccount,
|
|
118
|
-
};
|
|
119
|
-
const solveThatCaptcha = await fetch(`${baseUrl}${ApiPaths.SubmitImageCaptchaSolution}`, {
|
|
120
|
-
method: "POST",
|
|
121
|
-
headers: {
|
|
122
|
-
"Content-Type": "application/json",
|
|
123
|
-
Origin: origin,
|
|
124
|
-
},
|
|
125
|
-
body: JSON.stringify(body),
|
|
126
|
-
});
|
|
127
|
-
const jsonRes = await solveThatCaptcha.json();
|
|
128
|
-
const res = jsonRes;
|
|
129
|
-
expect(res.status).toBe("You correctly answered the captchas");
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
//# sourceMappingURL=imgCaptcha.integration.test.js.map
|