@prosopo/datasets 3.0.13 → 3.0.42
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/CHANGELOG.md +336 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +493 -0
- package/coverage/coverage-final.json +7 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +131 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/coverage/src/captcha/captcha.ts.html +1093 -0
- package/coverage/src/captcha/dataset.ts.html +490 -0
- package/coverage/src/captcha/index.html +176 -0
- package/coverage/src/captcha/index.ts.html +136 -0
- package/coverage/src/captcha/merkle.ts.html +610 -0
- package/coverage/src/captcha/util.ts.html +187 -0
- package/coverage/src/index.html +116 -0
- package/coverage/src/index.ts.html +139 -0
- package/dist/captcha/captcha.d.ts +21 -0
- package/dist/captcha/captcha.d.ts.map +1 -0
- package/dist/captcha/captcha.js +155 -173
- package/dist/captcha/captcha.js.map +1 -0
- package/dist/captcha/dataset.d.ts +8 -0
- package/dist/captcha/dataset.d.ts.map +1 -0
- package/dist/captcha/dataset.js +69 -83
- package/dist/captcha/dataset.js.map +1 -0
- package/dist/captcha/index.d.ts +5 -0
- package/dist/captcha/index.d.ts.map +1 -0
- package/dist/captcha/index.js +5 -27
- package/dist/captcha/index.js.map +1 -0
- package/dist/captcha/merkle.d.ts +20 -0
- package/dist/captcha/merkle.d.ts.map +1 -0
- package/dist/captcha/merkle.js +111 -113
- package/dist/captcha/merkle.js.map +1 -0
- package/dist/captcha/util.d.ts +2 -0
- package/dist/captcha/util.d.ts.map +1 -0
- package/dist/captcha/util.js +18 -19
- package/dist/captcha/util.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -31
- package/dist/index.js.map +1 -0
- package/dist/tests/captcha.unit.test.d.ts +2 -0
- package/dist/tests/captcha.unit.test.d.ts.map +1 -0
- package/dist/tests/captcha.unit.test.js +357 -0
- package/dist/tests/captcha.unit.test.js.map +1 -0
- package/dist/tests/dataset.unit.test.d.ts +2 -0
- package/dist/tests/dataset.unit.test.d.ts.map +1 -0
- package/dist/tests/dataset.unit.test.js +126 -0
- package/dist/tests/dataset.unit.test.js.map +1 -0
- package/dist/tests/merkle.unit.test.d.ts +2 -0
- package/dist/tests/merkle.unit.test.d.ts.map +1 -0
- package/dist/tests/merkle.unit.test.js +171 -0
- package/dist/tests/merkle.unit.test.js.map +1 -0
- package/dist/tests/mocks/data/captchas.d.ts +24 -0
- package/dist/tests/mocks/data/captchas.d.ts.map +1 -0
- package/dist/tests/mocks/data/captchas.js +1033 -1039
- package/dist/tests/mocks/data/captchas.js.map +1 -0
- package/dist/tests/mocks/data/captchas.json +886 -886
- package/dist/tests/mocks/data/captchas1.json +132 -132
- package/dist/tests/mocks/data/captchas2.json +175 -175
- package/dist/tests/mocks/data/captchas3.json +133 -133
- package/dist/tests/mocks/data/captchas4.json +132 -132
- package/package.json +15 -20
- package/dist/cjs/captcha/captcha.cjs +0 -194
- package/dist/cjs/captcha/dataset.cjs +0 -93
- package/dist/cjs/captcha/index.cjs +0 -27
- package/dist/cjs/captcha/merkle.cjs +0 -127
- package/dist/cjs/captcha/util.cjs +0 -23
- package/dist/cjs/index.cjs +0 -31
- package/dist/cjs/tests/mocks/data/captchas.cjs +0 -1044
package/dist/captcha/captcha.js
CHANGED
|
@@ -1,194 +1,176 @@
|
|
|
1
1
|
import { isHex } from "@polkadot/util";
|
|
2
|
-
import { ProsopoDatasetError, ProsopoEnvError
|
|
3
|
-
import { DatasetWithNumericSolutionSchema,
|
|
2
|
+
import { ProsopoDatasetError, ProsopoEnvError } from "@prosopo/common";
|
|
3
|
+
import { CaptchaSolutionArraySchema, DatasetWithNumericSolutionSchema, } from "@prosopo/types";
|
|
4
4
|
import { at } from "@prosopo/util";
|
|
5
|
+
import { hexHash, hexHashArray } from "@prosopo/util-crypto";
|
|
5
6
|
import { downloadImage } from "./util.js";
|
|
6
|
-
const NO_SOLUTION_VALUE = "NO_SOLUTION";
|
|
7
|
-
function parseCaptchaDataset(datasetJSON) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
export const NO_SOLUTION_VALUE = "NO_SOLUTION";
|
|
8
|
+
export function parseCaptchaDataset(datasetJSON) {
|
|
9
|
+
try {
|
|
10
|
+
const result = DatasetWithNumericSolutionSchema.parse(datasetJSON);
|
|
11
|
+
const result2 = {
|
|
12
|
+
format: result.format,
|
|
13
|
+
captchas: result.captchas.map((captcha) => {
|
|
14
|
+
return {
|
|
15
|
+
...captcha,
|
|
16
|
+
solution: captcha.solution
|
|
17
|
+
? matchItemsToSolutions(captcha.solution, captcha.items)
|
|
18
|
+
: [],
|
|
19
|
+
unlabelled: captcha.unlabelled
|
|
20
|
+
? matchItemsToSolutions(captcha.unlabelled, captcha.items)
|
|
21
|
+
: [],
|
|
22
|
+
};
|
|
23
|
+
}),
|
|
17
24
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function parseAndSortCaptchaSolutions(captchaJSON) {
|
|
35
|
-
try {
|
|
36
|
-
return CaptchaSolutionArraySchema.parse(captchaJSON).map((captcha) => ({
|
|
37
|
-
...captcha,
|
|
38
|
-
solution: captcha.solution.sort()
|
|
39
|
-
}));
|
|
40
|
-
} catch (err) {
|
|
41
|
-
throw new ProsopoDatasetError("DATASET.SOLUTION_PARSE_ERROR", {
|
|
42
|
-
context: { error: err }
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function captchaSort(a, b) {
|
|
47
|
-
return a.captchaId.localeCompare(b.captchaId);
|
|
48
|
-
}
|
|
49
|
-
function sortAndComputeHashes(received, stored) {
|
|
50
|
-
received.sort(captchaSort);
|
|
51
|
-
stored.sort(captchaSort);
|
|
52
|
-
return stored.map(
|
|
53
|
-
({ salt, items = [], target = "", captchaId, solved }, index) => {
|
|
54
|
-
const item = at(received, index);
|
|
55
|
-
if (captchaId !== item.captchaId) {
|
|
56
|
-
throw new ProsopoEnvError("CAPTCHA.ID_MISMATCH");
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
hash: computeCaptchaHash(
|
|
60
|
-
{
|
|
61
|
-
solution: solved ? item.solution : [],
|
|
62
|
-
salt,
|
|
63
|
-
items,
|
|
64
|
-
target
|
|
65
|
-
},
|
|
66
|
-
true,
|
|
67
|
-
true,
|
|
68
|
-
false
|
|
69
|
-
),
|
|
70
|
-
captchaId
|
|
71
|
-
};
|
|
25
|
+
if (result.datasetId !== undefined)
|
|
26
|
+
result2.datasetId = result.datasetId;
|
|
27
|
+
if (result.contentTree !== undefined)
|
|
28
|
+
result2.contentTree = result.contentTree;
|
|
29
|
+
if (result.datasetContentId !== undefined)
|
|
30
|
+
result2.datasetContentId = result.datasetContentId;
|
|
31
|
+
if (result.solutionTree !== undefined)
|
|
32
|
+
result2.solutionTree = result.solutionTree;
|
|
33
|
+
return result2;
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
throw new ProsopoDatasetError("DATASET.DATASET_PARSE_ERROR", {
|
|
37
|
+
context: { error: err },
|
|
38
|
+
});
|
|
72
39
|
}
|
|
73
|
-
);
|
|
74
40
|
}
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (received.length && solutions.length && received.length === solutions.length) {
|
|
82
|
-
const captchaIdMismatch = received.some(
|
|
83
|
-
(captcha, index) => solutions[index] && captcha.captchaId !== solutions[index].captchaId
|
|
84
|
-
);
|
|
85
|
-
if (captchaIdMismatch) {
|
|
86
|
-
return false;
|
|
41
|
+
export function parseAndSortCaptchaSolutions(captchaJSON) {
|
|
42
|
+
try {
|
|
43
|
+
return CaptchaSolutionArraySchema.parse(captchaJSON).map((captcha) => ({
|
|
44
|
+
...captcha,
|
|
45
|
+
solution: captcha.solution.sort(),
|
|
46
|
+
}));
|
|
87
47
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (!targetSolution) {
|
|
93
|
-
return false;
|
|
48
|
+
catch (err) {
|
|
49
|
+
throw new ProsopoDatasetError("DATASET.SOLUTION_PARSE_ERROR", {
|
|
50
|
+
context: { error: err },
|
|
51
|
+
});
|
|
94
52
|
}
|
|
95
|
-
const incorrectCount = sortedReceivedSolution.filter(
|
|
96
|
-
(solution) => !targetSolution.includes(solution)
|
|
97
|
-
).length;
|
|
98
|
-
const missingCount = targetSolution.filter(
|
|
99
|
-
(solution) => !sortedReceivedSolution.includes(solution)
|
|
100
|
-
).length;
|
|
101
|
-
const totalIncorrect = incorrectCount + missingCount;
|
|
102
|
-
const percentageCorrect = 1 - totalIncorrect / totalImages;
|
|
103
|
-
return percentageCorrect >= threshold;
|
|
104
|
-
});
|
|
105
53
|
}
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
54
|
+
export function captchaSort(a, b) {
|
|
55
|
+
return a.captchaId.localeCompare(b.captchaId);
|
|
56
|
+
}
|
|
57
|
+
export function sortAndComputeHashes(received, stored) {
|
|
58
|
+
received.sort(captchaSort);
|
|
59
|
+
stored.sort(captchaSort);
|
|
60
|
+
return stored.map(({ salt, items = [], target = "", captchaId, solved }, index) => {
|
|
61
|
+
const item = at(received, index);
|
|
62
|
+
if (captchaId !== item.captchaId) {
|
|
63
|
+
throw new ProsopoEnvError("CAPTCHA.ID_MISMATCH");
|
|
116
64
|
}
|
|
117
|
-
|
|
65
|
+
return {
|
|
66
|
+
hash: computeCaptchaHash({
|
|
67
|
+
solution: solved ? item.solution : [],
|
|
68
|
+
salt,
|
|
69
|
+
items,
|
|
70
|
+
target,
|
|
71
|
+
}, true, true, false),
|
|
72
|
+
captchaId,
|
|
73
|
+
};
|
|
118
74
|
});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
75
|
+
}
|
|
76
|
+
export function compareCaptchaSolutions(received, solutions, totalImages, threshold) {
|
|
77
|
+
received.sort(captchaSort);
|
|
78
|
+
solutions.sort(captchaSort);
|
|
79
|
+
if (received.length !== solutions.length) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (received.length &&
|
|
83
|
+
solutions.length &&
|
|
84
|
+
received.length === solutions.length) {
|
|
85
|
+
const captchaIdMismatch = received.some((captcha, index) => solutions[index] && captcha.captchaId !== solutions[index].captchaId);
|
|
86
|
+
if (captchaIdMismatch) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return received.every((captcha, index) => {
|
|
91
|
+
const sortedReceivedSolution = captcha.solution.sort();
|
|
92
|
+
const targetSolution = solutions[index]?.solution.sort();
|
|
93
|
+
if (!targetSolution) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
const incorrectCount = sortedReceivedSolution.filter((solution) => !targetSolution.includes(solution)).length;
|
|
97
|
+
const missingCount = targetSolution.filter((solution) => !sortedReceivedSolution.includes(solution)).length;
|
|
98
|
+
const totalIncorrect = incorrectCount + missingCount;
|
|
99
|
+
const percentageCorrect = 1 - totalIncorrect / totalImages;
|
|
100
|
+
return percentageCorrect >= threshold;
|
|
130
101
|
});
|
|
131
|
-
}
|
|
132
102
|
}
|
|
133
|
-
function
|
|
134
|
-
|
|
103
|
+
export function computeCaptchaHash(captcha, includeSolution, includeSalt, sortItemHashes) {
|
|
104
|
+
try {
|
|
105
|
+
const itemHashes = captcha.items.map((item, index) => {
|
|
106
|
+
if (item.hash) {
|
|
107
|
+
return item.hash;
|
|
108
|
+
}
|
|
109
|
+
throw new ProsopoDatasetError("CAPTCHA.MISSING_ITEM_HASH", {
|
|
110
|
+
context: {
|
|
111
|
+
computeCaptchaHashName: computeCaptchaHash.name,
|
|
112
|
+
index,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
return hexHashArray([
|
|
117
|
+
captcha.target,
|
|
118
|
+
...(includeSolution ? getSolutionValueToHash(captcha.solution) : []),
|
|
119
|
+
includeSalt ? captcha.salt : "",
|
|
120
|
+
sortItemHashes ? itemHashes.sort() : itemHashes,
|
|
121
|
+
]);
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
throw new ProsopoDatasetError("DATASET.HASH_ERROR", {
|
|
125
|
+
context: { error: err },
|
|
126
|
+
});
|
|
127
|
+
}
|
|
135
128
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return { ...item, hash: hexHash(item.data) };
|
|
139
|
-
}
|
|
140
|
-
if (item.type === "image") {
|
|
141
|
-
return { ...item, hash: hexHash(await downloadImage(item.data)) };
|
|
142
|
-
}
|
|
143
|
-
throw new ProsopoDatasetError("CAPTCHA.INVALID_ITEM_FORMAT");
|
|
129
|
+
export function getSolutionValueToHash(solution) {
|
|
130
|
+
return solution !== undefined ? solution.sort() : [NO_SOLUTION_VALUE];
|
|
144
131
|
}
|
|
145
|
-
function
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (!items?.some((item) => item.hash === solution)) {
|
|
152
|
-
throw new ProsopoDatasetError("CAPTCHA.INVALID_ITEM_HASH");
|
|
153
|
-
}
|
|
154
|
-
return solution;
|
|
132
|
+
export async function computeItemHash(item) {
|
|
133
|
+
if (item.type === "text") {
|
|
134
|
+
return { ...item, hash: hexHash(item.data) };
|
|
135
|
+
}
|
|
136
|
+
if (item.type === "image") {
|
|
137
|
+
return { ...item, hash: hexHash(await downloadImage(item.data)) };
|
|
155
138
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
139
|
+
throw new ProsopoDatasetError("CAPTCHA.INVALID_ITEM_FORMAT");
|
|
140
|
+
}
|
|
141
|
+
export function matchItemsToSolutions(solutions, items) {
|
|
142
|
+
if (!items) {
|
|
143
|
+
return [];
|
|
159
144
|
}
|
|
160
|
-
|
|
161
|
-
|
|
145
|
+
return solutions.map((solution) => {
|
|
146
|
+
if (typeof solution === "string" && isHex(solution)) {
|
|
147
|
+
if (!items?.some((item) => item.hash === solution)) {
|
|
148
|
+
throw new ProsopoDatasetError("CAPTCHA.INVALID_ITEM_HASH");
|
|
149
|
+
}
|
|
150
|
+
return solution;
|
|
151
|
+
}
|
|
152
|
+
if (typeof solution === "number") {
|
|
153
|
+
const item = at(items, solution);
|
|
154
|
+
return item.hash;
|
|
155
|
+
}
|
|
156
|
+
throw new ProsopoDatasetError("CAPTCHA.INVALID_SOLUTION_TYPE");
|
|
157
|
+
});
|
|
162
158
|
}
|
|
163
|
-
function computeCaptchaSolutionHash(captcha) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
159
|
+
export function computeCaptchaSolutionHash(captcha) {
|
|
160
|
+
return hexHashArray([
|
|
161
|
+
captcha.captchaId,
|
|
162
|
+
captcha.captchaContentId,
|
|
163
|
+
[...captcha.solution].sort(),
|
|
164
|
+
captcha.salt,
|
|
165
|
+
]);
|
|
170
166
|
}
|
|
171
|
-
function computePendingRequestHash(captchaIds, userAccount, salt) {
|
|
172
|
-
|
|
167
|
+
export function computePendingRequestHash(captchaIds, userAccount, salt) {
|
|
168
|
+
return hexHashArray([...captchaIds.sort(), userAccount, salt]);
|
|
173
169
|
}
|
|
174
|
-
function parseCaptchaAssets(item, assetsResolver) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
170
|
+
export function parseCaptchaAssets(item, assetsResolver) {
|
|
171
|
+
return {
|
|
172
|
+
...item,
|
|
173
|
+
data: assetsResolver?.resolveAsset(item.data).getURL() || item.data,
|
|
174
|
+
};
|
|
179
175
|
}
|
|
180
|
-
|
|
181
|
-
NO_SOLUTION_VALUE,
|
|
182
|
-
captchaSort,
|
|
183
|
-
compareCaptchaSolutions,
|
|
184
|
-
computeCaptchaHash,
|
|
185
|
-
computeCaptchaSolutionHash,
|
|
186
|
-
computeItemHash,
|
|
187
|
-
computePendingRequestHash,
|
|
188
|
-
getSolutionValueToHash,
|
|
189
|
-
matchItemsToSolutions,
|
|
190
|
-
parseAndSortCaptchaSolutions,
|
|
191
|
-
parseCaptchaAssets,
|
|
192
|
-
parseCaptchaDataset,
|
|
193
|
-
sortAndComputeHashes
|
|
194
|
-
};
|
|
176
|
+
//# sourceMappingURL=captcha.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captcha.js","sourceRoot":"","sources":["../../src/captcha/captcha.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAIN,0BAA0B,EAG1B,gCAAgC,GAKhC,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAO/C,MAAM,UAAU,mBAA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,IAAI,GAAG,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAEjC,OAAO,IAAI,CAAC,IAAI,CAAC;QAClB,CAAC;QACD,MAAM,IAAI,mBAAmB,CAAC,+BAA+B,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACJ,CAAC;AAOD,MAAM,UAAU,0BAA0B,CAAC,OAAwB;IAClE,OAAO,YAAY,CAAC;QACnB,OAAO,CAAC,SAAS;QACjB,OAAO,CAAC,gBAAgB;QACxB,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE;QAC5B,OAAO,CAAC,IAAI;KACZ,CAAC,CAAC;AACJ,CAAC;AASD,MAAM,UAAU,yBAAyB,CACxC,UAAoB,EACpB,WAA8B,EAC9B,IAAY;IAEZ,OAAO,YAAY,CAAC,CAAC,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;AAChE,CAAC;AAOD,MAAM,UAAU,kBAAkB,CACjC,IAAU,EACV,cAA0C;IAE1C,OAAO;QACN,GAAG,IAAI;QACP,IAAI,EAAE,cAAc,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,IAAI,IAAI,CAAC,IAAI;KACnE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Captcha, Dataset, DatasetRaw } from "@prosopo/types";
|
|
2
|
+
import { CaptchaMerkleTree } from "./merkle.js";
|
|
3
|
+
export declare function hashDatasetItems(datasetRaw: Dataset | DatasetRaw): Promise<Promise<Captcha>[]>;
|
|
4
|
+
export declare function validateDatasetContent(datasetOriginal: Dataset): Promise<boolean>;
|
|
5
|
+
export declare function buildDataset(datasetRaw: DatasetRaw): Promise<Dataset>;
|
|
6
|
+
export declare function buildCaptchaTree(dataset: Dataset, includeSolution: boolean, includeSalt: boolean, sortItemHashes: boolean): Promise<CaptchaMerkleTree>;
|
|
7
|
+
export declare function addSolutionHashesToDataset(datasetRaw: DatasetRaw): Dataset;
|
|
8
|
+
//# sourceMappingURL=dataset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset.d.ts","sourceRoot":"","sources":["../../src/captcha/dataset.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACX,OAAO,EAEP,OAAO,EACP,UAAU,EACV,MAAM,gBAAgB,CAAC;AAOxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIhD,wBAAsB,gBAAgB,CACrC,UAAU,EAAE,OAAO,GAAG,UAAU,GAC9B,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAU7B;AAMD,wBAAsB,sBAAsB,CAC3C,eAAe,EAAE,OAAO,GACtB,OAAO,CAAC,OAAO,CAAC,CAwBlB;AAED,wBAAsB,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAqB3E;AAED,wBAAsB,gBAAgB,CACrC,OAAO,EAAE,OAAO,EAChB,eAAe,EAAE,OAAO,EACxB,WAAW,EAAE,OAAO,EACpB,cAAc,EAAE,OAAO,GACrB,OAAO,CAAC,iBAAiB,CAAC,CAY5B;AAED,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAgB1E"}
|
package/dist/captcha/dataset.js
CHANGED
|
@@ -1,93 +1,79 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProsopoEnvError, getLogger } from "@prosopo/common";
|
|
2
2
|
import { at } from "@prosopo/util";
|
|
3
|
-
import {
|
|
3
|
+
import { computeCaptchaHash, computeItemHash, matchItemsToSolutions, } from "./captcha.js";
|
|
4
4
|
import { CaptchaMerkleTree } from "./merkle.js";
|
|
5
5
|
const logger = getLogger("info", import.meta.url);
|
|
6
|
-
async function hashDatasetItems(datasetRaw) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
});
|
|
6
|
+
export async function hashDatasetItems(datasetRaw) {
|
|
7
|
+
return datasetRaw.captchas.map(async (captcha) => {
|
|
8
|
+
const items = await Promise.all(captcha.items.map(async (item) => computeItemHash(item)));
|
|
9
|
+
return {
|
|
10
|
+
...captcha,
|
|
11
|
+
items,
|
|
12
|
+
};
|
|
13
|
+
});
|
|
16
14
|
}
|
|
17
|
-
async function validateDatasetContent(datasetOriginal) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
return
|
|
34
|
-
});
|
|
35
|
-
return hashes.every((hash) => hash);
|
|
15
|
+
export async function validateDatasetContent(datasetOriginal) {
|
|
16
|
+
const captchaPromises = await hashDatasetItems(datasetOriginal);
|
|
17
|
+
const captchas = await Promise.all(captchaPromises);
|
|
18
|
+
const dataset = {
|
|
19
|
+
...datasetOriginal,
|
|
20
|
+
captchas,
|
|
21
|
+
};
|
|
22
|
+
const hashes = dataset.captchas.map((captcha) => {
|
|
23
|
+
const captchaRaw = datasetOriginal.captchas.find((captchaRaw) => "captchaId" in captchaRaw
|
|
24
|
+
? captchaRaw.captchaId === captcha.captchaId
|
|
25
|
+
: false);
|
|
26
|
+
if (captchaRaw) {
|
|
27
|
+
return captcha.items.every((item, index) => item.hash === at(captchaRaw.items, index).hash);
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
});
|
|
31
|
+
return hashes.every((hash) => hash);
|
|
36
32
|
}
|
|
37
|
-
async function buildDataset(datasetRaw) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
dataset.datasetContentId = contentTree.root?.hash;
|
|
56
|
-
return dataset;
|
|
33
|
+
export async function buildDataset(datasetRaw) {
|
|
34
|
+
logger.debug(() => ({ msg: "Adding solution hashes to dataset" }));
|
|
35
|
+
const dataset = await addSolutionHashesToDataset(datasetRaw);
|
|
36
|
+
logger.debug(() => ({ msg: "Building dataset merkle trees" }));
|
|
37
|
+
const contentTree = await buildCaptchaTree(dataset, false, false, true);
|
|
38
|
+
const solutionTree = await buildCaptchaTree(dataset, true, true, false);
|
|
39
|
+
dataset.captchas = dataset.captchas.map((captcha, index) => ({
|
|
40
|
+
...captcha,
|
|
41
|
+
captchaId: at(solutionTree.leaves, index).hash,
|
|
42
|
+
captchaContentId: at(contentTree.leaves, index).hash,
|
|
43
|
+
datasetId: solutionTree.root?.hash,
|
|
44
|
+
datasetContentId: contentTree.root?.hash,
|
|
45
|
+
}));
|
|
46
|
+
dataset.solutionTree = solutionTree.layers;
|
|
47
|
+
dataset.contentTree = contentTree.layers;
|
|
48
|
+
dataset.datasetId = solutionTree.root?.hash;
|
|
49
|
+
dataset.datasetContentId = contentTree.root?.hash;
|
|
50
|
+
return dataset;
|
|
57
51
|
}
|
|
58
|
-
async function buildCaptchaTree(dataset, includeSolution, includeSalt, sortItemHashes) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
52
|
+
export async function buildCaptchaTree(dataset, includeSolution, includeSalt, sortItemHashes) {
|
|
53
|
+
try {
|
|
54
|
+
const tree = new CaptchaMerkleTree();
|
|
55
|
+
const datasetWithItemHashes = { ...dataset };
|
|
56
|
+
const captchaHashes = datasetWithItemHashes.captchas.map((captcha) => computeCaptchaHash(captcha, includeSolution, includeSalt, sortItemHashes));
|
|
57
|
+
tree.build(captchaHashes);
|
|
58
|
+
return tree;
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
throw new ProsopoEnvError("DATASET.HASH_ERROR");
|
|
62
|
+
}
|
|
70
63
|
}
|
|
71
|
-
function addSolutionHashesToDataset(datasetRaw) {
|
|
72
|
-
|
|
64
|
+
export function addSolutionHashesToDataset(datasetRaw) {
|
|
65
|
+
const captchas = datasetRaw.captchas.map((captcha) => {
|
|
66
|
+
return {
|
|
67
|
+
...captcha,
|
|
68
|
+
items: captcha.items,
|
|
69
|
+
...(captcha.solution !== undefined && {
|
|
70
|
+
solution: matchItemsToSolutions(captcha.solution, captcha.items),
|
|
71
|
+
}),
|
|
72
|
+
};
|
|
73
|
+
});
|
|
73
74
|
return {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// some captcha challenges will not have a solution
|
|
77
|
-
...captcha.solution !== void 0 && {
|
|
78
|
-
solution: matchItemsToSolutions(captcha.solution, captcha.items)
|
|
79
|
-
}
|
|
75
|
+
...datasetRaw,
|
|
76
|
+
captchas,
|
|
80
77
|
};
|
|
81
|
-
});
|
|
82
|
-
return {
|
|
83
|
-
...datasetRaw,
|
|
84
|
-
captchas
|
|
85
|
-
};
|
|
86
78
|
}
|
|
87
|
-
|
|
88
|
-
addSolutionHashesToDataset,
|
|
89
|
-
buildCaptchaTree,
|
|
90
|
-
buildDataset,
|
|
91
|
-
hashDatasetItems,
|
|
92
|
-
validateDatasetContent
|
|
93
|
-
};
|
|
79
|
+
//# sourceMappingURL=dataset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset.js","sourceRoot":"","sources":["../../src/captcha/dataset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAoB7D,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AACnC,OAAO,EACN,kBAAkB,EAClB,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,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/captcha/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
package/dist/captcha/index.js
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
CaptchaMerkleTree,
|
|
7
|
-
NO_SOLUTION_VALUE,
|
|
8
|
-
addSolutionHashesToDataset,
|
|
9
|
-
buildCaptchaTree,
|
|
10
|
-
buildDataset,
|
|
11
|
-
captchaSort,
|
|
12
|
-
compareCaptchaSolutions,
|
|
13
|
-
computeCaptchaHash,
|
|
14
|
-
computeCaptchaSolutionHash,
|
|
15
|
-
computeItemHash,
|
|
16
|
-
computePendingRequestHash,
|
|
17
|
-
downloadImage,
|
|
18
|
-
getSolutionValueToHash,
|
|
19
|
-
hashDatasetItems,
|
|
20
|
-
matchItemsToSolutions,
|
|
21
|
-
parseAndSortCaptchaSolutions,
|
|
22
|
-
parseCaptchaAssets,
|
|
23
|
-
parseCaptchaDataset,
|
|
24
|
-
sortAndComputeHashes,
|
|
25
|
-
validateDatasetContent,
|
|
26
|
-
verifyProof
|
|
27
|
-
};
|
|
1
|
+
export * from "./captcha.js";
|
|
2
|
+
export * from "./merkle.js";
|
|
3
|
+
export * from "./util.js";
|
|
4
|
+
export * from "./dataset.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/captcha/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MerkleLayer, MerkleLeaf, MerkleNodeInterface, MerkleProof } from "@prosopo/types";
|
|
2
|
+
declare class MerkleNode implements MerkleNodeInterface {
|
|
3
|
+
hash: string;
|
|
4
|
+
parent: string | null;
|
|
5
|
+
constructor(hash: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class CaptchaMerkleTree {
|
|
8
|
+
leaves: MerkleNode[];
|
|
9
|
+
layers: MerkleLayer[];
|
|
10
|
+
root: MerkleNode | undefined;
|
|
11
|
+
constructor();
|
|
12
|
+
getRoot(): MerkleNode;
|
|
13
|
+
build(leaves: string[]): void;
|
|
14
|
+
buildMerkleTree(leaves: MerkleNode[]): MerkleNode[];
|
|
15
|
+
createParent(leftChild: MerkleNode, rightChild: MerkleNode): MerkleNode;
|
|
16
|
+
proof(leafHash: MerkleLeaf): MerkleProof;
|
|
17
|
+
}
|
|
18
|
+
export declare function verifyProof(leaf: MerkleLeaf, proof: MerkleProof): boolean;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=merkle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merkle.d.ts","sourceRoot":"","sources":["../../src/captcha/merkle.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EACX,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,WAAW,EAEX,MAAM,gBAAgB,CAAC;AAIxB,cAAM,UAAW,YAAW,mBAAmB;IAC9C,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEV,IAAI,EAAE,MAAM;CAIxB;AAED,qBAAa,iBAAiB;IAC7B,MAAM,EAAE,UAAU,EAAE,CAAC;IAErB,MAAM,EAAE,WAAW,EAAE,CAAC;IAEtB,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;;IAO7B,OAAO;IAYP,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE;IAetB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE;IA+BnD,YAAY,CAAC,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU;IASvE,KAAK,CAAC,QAAQ,EAAE,UAAU,GAAG,WAAW;CAsCxC;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAmBzE"}
|