@prosopo/datasets 0.1.16 → 0.1.17
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/README.md +1 -17
- package/dist/{js/captcha → captcha}/captcha.d.ts +8 -2
- package/dist/captcha/captcha.d.ts.map +1 -0
- package/dist/captcha/captcha.js +178 -0
- package/dist/captcha/captcha.js.map +1 -0
- package/dist/captcha/dataset.d.ts +12 -0
- package/dist/captcha/dataset.d.ts.map +1 -0
- package/dist/captcha/dataset.js +77 -0
- 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 +18 -0
- package/dist/captcha/index.js.map +1 -0
- package/dist/captcha/merkle.d.ts.map +1 -0
- package/dist/{js/captcha → captcha}/merkle.js +6 -11
- package/dist/captcha/merkle.js.map +1 -0
- package/dist/captcha/util.d.ts.map +1 -0
- package/dist/captcha/util.js +27 -0
- package/dist/captcha/util.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -56
- package/dist/js/captcha/captcha.d.ts.map +0 -1
- package/dist/js/captcha/captcha.js +0 -187
- package/dist/js/captcha/captcha.js.map +0 -1
- package/dist/js/captcha/dataset.d.ts +0 -6
- package/dist/js/captcha/dataset.d.ts.map +0 -1
- package/dist/js/captcha/dataset.js +0 -50
- package/dist/js/captcha/dataset.js.map +0 -1
- package/dist/js/captcha/index.d.ts +0 -5
- package/dist/js/captcha/index.d.ts.map +0 -1
- package/dist/js/captcha/index.js +0 -23
- package/dist/js/captcha/index.js.map +0 -1
- package/dist/js/captcha/merkle.d.ts.map +0 -1
- package/dist/js/captcha/merkle.js.map +0 -1
- package/dist/js/captcha/util.d.ts.map +0 -1
- package/dist/js/captcha/util.js +0 -33
- package/dist/js/captcha/util.js.map +0 -1
- package/dist/js/index.d.ts +0 -2
- package/dist/js/index.d.ts.map +0 -1
- package/dist/js/index.js +0 -20
- package/dist/js/index.js.map +0 -1
- /package/dist/{js/captcha → captcha}/merkle.d.ts +0 -0
- /package/dist/{js/captcha → captcha}/util.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# datasets
|
|
2
|
+
|
|
2
3
|
Datasets for use with providers
|
|
3
4
|
|
|
4
5
|
## STL10
|
|
@@ -6,20 +7,3 @@ Datasets for use with providers
|
|
|
6
7
|
Workbook adapted from [kaggle notebook](https://www.kaggle.com/code/pratt3000/generate-stl10/notebook) to generate 10,000 unique CAPTCHA.
|
|
7
8
|
|
|
8
9
|
Download the [binary files here](http://ai.stanford.edu/~acoates/stl10/stl10_binary.tar.gz).
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## How to produce captchas
|
|
12
|
-
|
|
13
|
-
To generate captchas with 0-9 target images, run:
|
|
14
|
-
```commandline
|
|
15
|
-
python3 src/python/generate_captchas.py --solved 2 --unsolved 2 --size 9 --min 0 --max 9 --output captchas.json --seed 0 --data data.json
|
|
16
|
-
```
|
|
17
|
-
or with 2-4 target images, run:
|
|
18
|
-
```commandline
|
|
19
|
-
python3 src/python/generate_captchas.py --solved 2 --unsolved 2 --size 9 --min 2 --max 4 --output captchas.json --seed 0 --data data.json
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Unsure of how the captcha generation works?
|
|
23
|
-
```commandline
|
|
24
|
-
python3 generate_captchas.py -h
|
|
25
|
-
```
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AssetsResolver, Captcha, CaptchaSolution, CaptchaWithoutId, DatasetRaw, HashedItem, HashedSolution, Item, RawSolution } from '@prosopo/types';
|
|
2
|
+
export declare const NO_SOLUTION_VALUE = "NO_SOLUTION";
|
|
2
3
|
/**
|
|
3
4
|
* Parse a dataset
|
|
4
5
|
* @return {JSON} captcha dataset, stored in JSON
|
|
@@ -34,6 +35,11 @@ export declare function compareCaptchaSolutions(received: CaptchaSolution[], sto
|
|
|
34
35
|
* @return {string} the hex string hash
|
|
35
36
|
*/
|
|
36
37
|
export declare function computeCaptchaHash(captcha: CaptchaWithoutId, includeSolution: boolean | undefined, includeSalt: boolean | undefined, sortItemHashes: boolean): string;
|
|
38
|
+
/** Return the sorted solution value or ['NO_SOLUTION'] if there is no solution. Ensures that an empty array is a valid
|
|
39
|
+
* solution
|
|
40
|
+
* @param solution
|
|
41
|
+
*/
|
|
42
|
+
export declare function getSolutionValueToHash(solution?: HashedSolution[] | RawSolution[]): string[] | number[];
|
|
37
43
|
/** Compute the hash of a captcha item, downloading the image if necessary
|
|
38
44
|
* @param {Item} item
|
|
39
45
|
* @return {Promise<HashedItem>} the hex string hash of the item
|
|
@@ -45,7 +51,7 @@ export declare function computeItemHash(item: Item): Promise<HashedItem>;
|
|
|
45
51
|
* @param {RawSolution[] | HashedSolution[]} solutions
|
|
46
52
|
* @param {Item[]} items
|
|
47
53
|
*/
|
|
48
|
-
export declare function matchItemsToSolutions(solutions: RawSolution[] | HashedSolution[], items:
|
|
54
|
+
export declare function matchItemsToSolutions(solutions: RawSolution[] | HashedSolution[], items: HashedItem[] | undefined): HashedSolution[];
|
|
49
55
|
/**
|
|
50
56
|
* Create a unique solution commitment
|
|
51
57
|
* @param {CaptchaSolution} captcha
|
|
@@ -67,6 +73,6 @@ export declare function parseCaptchaAssets(item: Item, assetsResolver: AssetsRes
|
|
|
67
73
|
path: string;
|
|
68
74
|
type: import("@prosopo/types").CaptchaItemTypes;
|
|
69
75
|
data: string;
|
|
70
|
-
hash
|
|
76
|
+
hash: string;
|
|
71
77
|
};
|
|
72
78
|
//# sourceMappingURL=captcha.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captcha.d.ts","sourceRoot":"","sources":["../../src/captcha/captcha.ts"],"names":[],"mappings":"AAaA,OAAO,EACH,cAAc,EACd,OAAO,EACP,eAAe,EAEf,gBAAgB,EAChB,UAAU,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BAA0B,CAAC,OAAO,EAAE,eAAe,UAGlE;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzG;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,cAAc,GAAG,SAAS;;;;;EAExF"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
import { CaptchaSolutionArraySchema, DatasetSchema, } from '@prosopo/types';
|
|
16
|
+
import { ProsopoEnvError, hexHash, hexHashArray } from '@prosopo/common';
|
|
17
|
+
import { downloadImage } from './util.js';
|
|
18
|
+
import { isHex } from '@polkadot/util';
|
|
19
|
+
export const NO_SOLUTION_VALUE = 'NO_SOLUTION';
|
|
20
|
+
/**
|
|
21
|
+
* Parse a dataset
|
|
22
|
+
* @return {JSON} captcha dataset, stored in JSON
|
|
23
|
+
* @param datasetJSON
|
|
24
|
+
*/
|
|
25
|
+
export function parseCaptchaDataset(datasetJSON) {
|
|
26
|
+
try {
|
|
27
|
+
return DatasetSchema.parse(datasetJSON);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
throw new ProsopoEnvError(err, 'ERRORS.DATASET.PARSE_ERROR');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Make sure captcha solutions are in the correct format
|
|
35
|
+
* @param {JSON} captchaJSON captcha solutions received from the api
|
|
36
|
+
* @return {CaptchaSolution[]} an array of parsed and sorted captcha solutions
|
|
37
|
+
*/
|
|
38
|
+
export function parseAndSortCaptchaSolutions(captchaJSON) {
|
|
39
|
+
try {
|
|
40
|
+
return CaptchaSolutionArraySchema.parse(captchaJSON).map((captcha) => (Object.assign(Object.assign({}, captcha), { solution: captcha.solution.sort() })));
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
throw new ProsopoEnvError(err, 'ERRORS.CAPTCHA.PARSE_ERROR');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function captchaSort(a, b) {
|
|
47
|
+
return a.captchaId.localeCompare(b.captchaId);
|
|
48
|
+
}
|
|
49
|
+
export function sortAndComputeHashes(received, stored) {
|
|
50
|
+
received.sort(captchaSort);
|
|
51
|
+
stored.sort(captchaSort);
|
|
52
|
+
return stored.map(({ salt, items = [], target = '', captchaId, solved }, index) => {
|
|
53
|
+
if (captchaId != received[index].captchaId) {
|
|
54
|
+
throw new ProsopoEnvError('CAPTCHA.ID_MISMATCH');
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
hash: computeCaptchaHash({
|
|
58
|
+
solution: solved ? received[index].solution : [],
|
|
59
|
+
salt,
|
|
60
|
+
items,
|
|
61
|
+
target,
|
|
62
|
+
}, true, true, false),
|
|
63
|
+
captchaId,
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Take an array of CaptchaSolutions and Captchas and check if the solutions are the same for each pair
|
|
69
|
+
* @param {CaptchaSolution[]} received
|
|
70
|
+
* @param {Captcha[]} stored
|
|
71
|
+
* @return {boolean}
|
|
72
|
+
*/
|
|
73
|
+
export function compareCaptchaSolutions(received, stored) {
|
|
74
|
+
if (received.length && stored.length && received.length === stored.length) {
|
|
75
|
+
const hashes = sortAndComputeHashes(received, stored);
|
|
76
|
+
return hashes.every(({ hash, captchaId }) => hash === captchaId);
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Compute the hash of various types of captcha
|
|
82
|
+
* @param {Captcha} captcha
|
|
83
|
+
* @param {boolean} includeSolution
|
|
84
|
+
* @param {boolean} includeSalt
|
|
85
|
+
* @param {boolean} sortItemHashes
|
|
86
|
+
* @return {string} the hex string hash
|
|
87
|
+
*/
|
|
88
|
+
export function computeCaptchaHash(captcha, includeSolution = false, includeSalt = false, sortItemHashes) {
|
|
89
|
+
try {
|
|
90
|
+
const itemHashes = captcha.items.map((item, index) => {
|
|
91
|
+
if (item.hash) {
|
|
92
|
+
return item.hash;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw new ProsopoEnvError('CAPTCHA.MISSING_ITEM_HASH', computeCaptchaHash.name, undefined, index);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return hexHashArray([
|
|
99
|
+
captcha.target,
|
|
100
|
+
// empty array hashes as empty string, undefined solution results in the array [`NO_SOLUTION`]
|
|
101
|
+
// [undefined] also hashes as empty string, which is why we don't use it
|
|
102
|
+
...(includeSolution ? getSolutionValueToHash(captcha.solution) : []),
|
|
103
|
+
includeSalt ? captcha.salt : '',
|
|
104
|
+
sortItemHashes ? itemHashes.sort() : itemHashes,
|
|
105
|
+
]);
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
throw new ProsopoEnvError(err);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Return the sorted solution value or ['NO_SOLUTION'] if there is no solution. Ensures that an empty array is a valid
|
|
112
|
+
* solution
|
|
113
|
+
* @param solution
|
|
114
|
+
*/
|
|
115
|
+
export function getSolutionValueToHash(solution) {
|
|
116
|
+
return solution !== undefined ? solution.sort() : [NO_SOLUTION_VALUE];
|
|
117
|
+
}
|
|
118
|
+
/** Compute the hash of a captcha item, downloading the image if necessary
|
|
119
|
+
* @param {Item} item
|
|
120
|
+
* @return {Promise<HashedItem>} the hex string hash of the item
|
|
121
|
+
*/
|
|
122
|
+
export function computeItemHash(item) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
if (item.type === 'text') {
|
|
125
|
+
return Object.assign(Object.assign({}, item), { hash: hexHash(item.data) });
|
|
126
|
+
}
|
|
127
|
+
else if (item.type === 'image') {
|
|
128
|
+
return Object.assign(Object.assign({}, item), { hash: hexHash(yield downloadImage(item.data)) });
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
throw new ProsopoEnvError('CAPTCHA.INVALID_ITEM_FORMAT');
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Converts an indexed captcha solution to a hashed captcha solution or simply returns the hash if it is already hashed
|
|
137
|
+
* @return {HashedSolution[]}
|
|
138
|
+
* @param {RawSolution[] | HashedSolution[]} solutions
|
|
139
|
+
* @param {Item[]} items
|
|
140
|
+
*/
|
|
141
|
+
export function matchItemsToSolutions(solutions, items) {
|
|
142
|
+
return ((solutions === null || solutions === void 0 ? void 0 : solutions.map((solution) => {
|
|
143
|
+
const hash = items && items[solution] && items[solution].hash ? items[solution].hash : solution;
|
|
144
|
+
if (!hash) {
|
|
145
|
+
throw new ProsopoEnvError('CAPTCHA.MISSING_ITEM_HASH');
|
|
146
|
+
}
|
|
147
|
+
if (!isHex(hash)) {
|
|
148
|
+
throw new ProsopoEnvError('CAPTCHA.INVALID_ITEM_HASH');
|
|
149
|
+
}
|
|
150
|
+
return hash;
|
|
151
|
+
})) || []);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Create a unique solution commitment
|
|
155
|
+
* @param {CaptchaSolution} captcha
|
|
156
|
+
* @return {string} the hex string hash
|
|
157
|
+
*/
|
|
158
|
+
export function computeCaptchaSolutionHash(captcha) {
|
|
159
|
+
// TODO: should the captchaContentId be validated?
|
|
160
|
+
return hexHashArray([captcha.captchaId, captcha.captchaContentId, [...captcha.solution].sort(), captcha.salt]);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Compute hash for an array of captcha ids, userAccount, and salt, which serves as the identifier for a pending request
|
|
164
|
+
* @param {string[]} captchaIds
|
|
165
|
+
* @param {string} userAccount
|
|
166
|
+
* @param {string} salt
|
|
167
|
+
* @return {string}
|
|
168
|
+
*/
|
|
169
|
+
export function computePendingRequestHash(captchaIds, userAccount, salt) {
|
|
170
|
+
return hexHashArray([...captchaIds.sort(), userAccount, salt]);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Parse the image items in a captcha and pass back a URI if they exist
|
|
174
|
+
*/
|
|
175
|
+
export function parseCaptchaAssets(item, assetsResolver) {
|
|
176
|
+
return Object.assign(Object.assign({}, item), { path: (assetsResolver === null || assetsResolver === void 0 ? void 0 : assetsResolver.resolveAsset(item.data).getURL()) || item.data });
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=captcha.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captcha.js","sourceRoot":"","sources":["../../src/captcha/captcha.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,OAAO,EAIH,0BAA0B,EAG1B,aAAa,GAKhB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,K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,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAA;QAE/F,IAAI,CAAC,IAAI,EAAE;YACP,MAAM,IAAI,eAAe,CAAC,2BAA2B,CAAC,CAAA;SACzD;QAED,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;YACd,MAAM,IAAI,eAAe,CAAC,2BAA2B,CAAC,CAAA;SACzD;QAED,OAAO,IAAI,CAAA;IACf,CAAC,CAAC,KAAI,EAAE,CACX,CAAA;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CAAC,OAAwB;IAC/D,kDAAkD;IAClD,OAAO,YAAY,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,gBAAgB,EAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;AAClH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CAAC,UAAoB,EAAE,WAAmB,EAAE,IAAY;IAC7F,OAAO,YAAY,CAAC,CAAC,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC,CAAA;AAClE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAU,EAAE,cAA0C;IACrF,uCAAY,IAAI,KAAE,IAAI,EAAE,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAI,IAAI,CAAC,IAAI,IAAE;AAC3F,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Captcha, Dataset, DatasetRaw } from '@prosopo/types';
|
|
2
|
+
import { CaptchaMerkleTree } from './merkle.js';
|
|
3
|
+
export declare function hashDatasetItems(datasetRaw: Dataset | DatasetRaw): Promise<Promise<Captcha>[]>;
|
|
4
|
+
/**
|
|
5
|
+
* Take a dataset and hash all the items, making sure that the existing captchaIds and item hashes are correct
|
|
6
|
+
* @param datasetOriginal
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateDatasetContent(datasetOriginal: Dataset): Promise<boolean>;
|
|
9
|
+
export declare function buildDataset(datasetRaw: DatasetRaw): Promise<Dataset>;
|
|
10
|
+
export declare function buildCaptchaTree(dataset: Dataset, includeSolution: boolean, includeSalt: boolean, sortItemHashes: boolean): Promise<CaptchaMerkleTree>;
|
|
11
|
+
export declare function addSolutionHashesToDataset(datasetRaw: DatasetRaw): Promise<Dataset>;
|
|
12
|
+
//# sourceMappingURL=dataset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset.d.ts","sourceRoot":"","sources":["../../src/captcha/dataset.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAoB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAI/C,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAQpG;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAAC,eAAe,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAqBvF;AAED,wBAAsB,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAoB3E;AAED,wBAAsB,gBAAgB,CAClC,OAAO,EAAE,OAAO,EAChB,eAAe,EAAE,OAAO,EACxB,WAAW,EAAE,OAAO,EACpB,cAAc,EAAE,OAAO,GACxB,OAAO,CAAC,iBAAiB,CAAC,CAY5B;AAED,wBAAsB,0BAA0B,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAiBzF"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { CaptchaMerkleTree } from './merkle.js';
|
|
3
|
+
import { ProsopoEnvError } from '@prosopo/common';
|
|
4
|
+
import { computeCaptchaHash, computeItemHash, matchItemsToSolutions } from './captcha.js';
|
|
5
|
+
export function hashDatasetItems(datasetRaw) {
|
|
6
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7
|
+
return datasetRaw.captchas.map((captcha) => __awaiter(this, void 0, void 0, function* () {
|
|
8
|
+
const items = yield Promise.all(captcha.items.map((item) => __awaiter(this, void 0, void 0, function* () { return computeItemHash(item); })));
|
|
9
|
+
return Object.assign(Object.assign({}, captcha), { items });
|
|
10
|
+
}));
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Take a dataset and hash all the items, making sure that the existing captchaIds and item hashes are correct
|
|
15
|
+
* @param datasetOriginal
|
|
16
|
+
*/
|
|
17
|
+
export function validateDatasetContent(datasetOriginal) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const captchaPromises = yield hashDatasetItems(datasetOriginal);
|
|
20
|
+
const captchas = yield Promise.all(captchaPromises);
|
|
21
|
+
const dataset = Object.assign(Object.assign({}, datasetOriginal), { captchas });
|
|
22
|
+
// compare each of the Item hashes in each of the captchas in the dataset to each of the item hashes in each of the
|
|
23
|
+
// captchas in datasetOriginal
|
|
24
|
+
const hashes = dataset.captchas.map((captcha) => {
|
|
25
|
+
const captchaRaw = datasetOriginal.captchas.find((captchaRaw) => 'captchaId' in captchaRaw ? captchaRaw.captchaId === captcha.captchaId : false);
|
|
26
|
+
if (captchaRaw) {
|
|
27
|
+
return captcha.items.every((item, index) => item.hash === captchaRaw.items[index].hash);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return hashes.every((hash) => hash);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export function buildDataset(datasetRaw) {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const dataset = yield addSolutionHashesToDataset(datasetRaw);
|
|
40
|
+
const contentTree = yield buildCaptchaTree(dataset, false, false, true);
|
|
41
|
+
const solutionTree = yield buildCaptchaTree(dataset, true, true, false);
|
|
42
|
+
dataset.captchas = dataset.captchas.map((captcha, index) => {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
return (Object.assign(Object.assign({}, captcha), { captchaId: solutionTree.leaves[index].hash, captchaContentId: contentTree.leaves[index].hash, datasetId: (_a = solutionTree.root) === null || _a === void 0 ? void 0 : _a.hash, datasetContentId: (_b = contentTree.root) === null || _b === void 0 ? void 0 : _b.hash }));
|
|
45
|
+
});
|
|
46
|
+
dataset.solutionTree = solutionTree.layers;
|
|
47
|
+
dataset.contentTree = contentTree.layers;
|
|
48
|
+
dataset.datasetId = (_a = solutionTree.root) === null || _a === void 0 ? void 0 : _a.hash;
|
|
49
|
+
dataset.datasetContentId = (_b = contentTree.root) === null || _b === void 0 ? void 0 : _b.hash;
|
|
50
|
+
return dataset;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export function buildCaptchaTree(dataset, includeSolution, includeSalt, sortItemHashes) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
try {
|
|
56
|
+
const tree = new CaptchaMerkleTree();
|
|
57
|
+
const datasetWithItemHashes = Object.assign({}, dataset);
|
|
58
|
+
const captchaHashes = datasetWithItemHashes.captchas.map((captcha) => computeCaptchaHash(captcha, includeSolution, includeSalt, sortItemHashes));
|
|
59
|
+
tree.build(captchaHashes);
|
|
60
|
+
return tree;
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
throw new ProsopoEnvError('DATASET.HASH_ERROR');
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
export function addSolutionHashesToDataset(datasetRaw) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const captchaPromises = datasetRaw.captchas.map((captcha) => __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
//const items = await Promise.all(captcha.items.map(async (item) => await computeItemHash(item)))
|
|
71
|
+
return Object.assign(Object.assign(Object.assign({}, captcha), { items: captcha.items }), (captcha.solution !== undefined && { solution: matchItemsToSolutions(captcha.solution, captcha.items) }));
|
|
72
|
+
}));
|
|
73
|
+
const captchas = yield Promise.all(captchaPromises);
|
|
74
|
+
return Object.assign(Object.assign({}, datasetRaw), { captchas });
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=dataset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset.js","sourceRoot":"","sources":["../../src/captcha/dataset.ts"],"names":[],"mappings":";AAcA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAEzF,MAAM,UAAgB,gBAAgB,CAAC,UAAgC;;QACnE,OAAO,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAO,OAAO,EAAE,EAAE;YAC7C,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAO,IAAI,EAAE,EAAE,gDAAC,OAAA,eAAe,CAAC,IAAI,CAAC,CAAA,GAAA,CAAC,CAAC,CAAA;YACzF,OAAO,gCACA,OAAO,KACV,KAAK,GACG,CAAA;QAChB,CAAC,CAAA,CAAC,CAAA;IACN,CAAC;CAAA;AAED;;;GAGG;AACH,MAAM,UAAgB,sBAAsB,CAAC,eAAwB;;QACjE,MAAM,eAAe,GAAG,MAAM,gBAAgB,CAAC,eAAe,CAAC,CAAA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AC,CAAO,OAAO,EAAE,EAAE;YAC9D,iGAAiG;YACjG,qDACO,OAAO,KACV,KAAK,EAAE,OAAO,CAAC,KAAK,KAEjB,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,QAAQ,EAAE,qBAAqB,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,EAC9G;QACL,CAAC,CAAA,CAAC,CAAA;QAEF,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;QAEnD,uCACO,UAAU,KACb,QAAQ,IACX;IACL,CAAC;CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/captcha/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
export * from './captcha.js';
|
|
15
|
+
export * from './merkle.js';
|
|
16
|
+
export * from './util.js';
|
|
17
|
+
export * from './dataset.js';
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/captcha/index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merkle.d.ts","sourceRoot":"","sources":["../../src/captcha/merkle.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,mBAAmB,EAAE,WAAW,EAAoB,MAAM,gBAAgB,CAAA;AAG5G,cAAM,UAAW,YAAW,mBAAmB;IAC3C,IAAI,EAAE,MAAM,CAAA;IAEZ,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;gBAET,IAAI,KAAA;CAInB;AAED,qBAAa,iBAAiB;IAC1B,MAAM,EAAE,UAAU,EAAE,CAAA;IAEpB,MAAM,EAAE,WAAW,EAAE,CAAA;IAErB,IAAI,EAAE,UAAU,GAAG,SAAS,CAAA;;IAO5B,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE;IAetB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE;IAyBpC,YAAY,CAAC,SAAS,KAAA,EAAE,UAAU,KAAA,GAAG,UAAU;IAO/C,KAAK,CAAC,QAAQ,EAAE,UAAU,GAAG,WAAW;CA0B3C;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAkBzE"}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.verifyProof = exports.CaptchaMerkleTree = void 0;
|
|
4
|
-
const common_1 = require("@prosopo/common");
|
|
1
|
+
import { hexHashArray } from '@prosopo/common';
|
|
5
2
|
class MerkleNode {
|
|
6
3
|
constructor(hash) {
|
|
7
4
|
this.hash = hash;
|
|
8
5
|
this.parent = null;
|
|
9
6
|
}
|
|
10
7
|
}
|
|
11
|
-
class CaptchaMerkleTree {
|
|
8
|
+
export class CaptchaMerkleTree {
|
|
12
9
|
constructor() {
|
|
13
10
|
this.leaves = [];
|
|
14
11
|
this.layers = [];
|
|
@@ -48,7 +45,7 @@ class CaptchaMerkleTree {
|
|
|
48
45
|
return this.buildMerkleTree(parents);
|
|
49
46
|
}
|
|
50
47
|
createParent(leftChild, rightChild) {
|
|
51
|
-
const parent = new MerkleNode(
|
|
48
|
+
const parent = new MerkleNode(hexHashArray([leftChild.hash, rightChild.hash]));
|
|
52
49
|
leftChild.parent = parent;
|
|
53
50
|
rightChild.parent = parent;
|
|
54
51
|
return parent;
|
|
@@ -76,19 +73,18 @@ class CaptchaMerkleTree {
|
|
|
76
73
|
}
|
|
77
74
|
proofTree.push([pair[0], pair[1]]);
|
|
78
75
|
layerNum += 1;
|
|
79
|
-
leafHash =
|
|
76
|
+
leafHash = hexHashArray(pair);
|
|
80
77
|
}
|
|
81
78
|
return [...proofTree, [this.layers[this.layers.length - 1][0]]];
|
|
82
79
|
}
|
|
83
80
|
}
|
|
84
|
-
|
|
85
|
-
function verifyProof(leaf, proof) {
|
|
81
|
+
export function verifyProof(leaf, proof) {
|
|
86
82
|
try {
|
|
87
83
|
if (proof[0].indexOf(leaf) === -1) {
|
|
88
84
|
return false;
|
|
89
85
|
}
|
|
90
86
|
for (const [layerIndex, layer] of proof.entries()) {
|
|
91
|
-
leaf =
|
|
87
|
+
leaf = hexHashArray(layer);
|
|
92
88
|
if (proof[layerIndex + 1].indexOf(leaf) === -1) {
|
|
93
89
|
return false;
|
|
94
90
|
}
|
|
@@ -102,5 +98,4 @@ function verifyProof(leaf, proof) {
|
|
|
102
98
|
return false;
|
|
103
99
|
}
|
|
104
100
|
}
|
|
105
|
-
exports.verifyProof = verifyProof;
|
|
106
101
|
//# sourceMappingURL=merkle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merkle.js","sourceRoot":"","sources":["../../src/captcha/merkle.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,MAAM,UAAU;IAKZ,YAAY,IAAI;QACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;IACtB,CAAC;CACJ;AAED,MAAM,OAAO,iBAAiB;IAO1B;QACI,IAAI,CAAC,MAAM,GAAG,EAAE,CAAA;QAChB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,MAAgB;QAClB,gBAAgB;QAChB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;YACpB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAA;SACnB;QACD,MAAM,SAAS,GAAa,EAAE,CAAA;QAC9B,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE;YACvB,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAA;YACjC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACtB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;SAC5B;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACjD,CAAC;IAED,eAAe,CAAC,MAAoB;QAChC,iHAAiH;QAEjH,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAA;QAC/B,IAAI,SAAS,KAAK,CAAC,EAAE;YACjB,OAAO,MAAM,CAAC,CAAC,CA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M,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE;YAC/C,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,CAAA;YAC1B,IAAI,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE;gBAC5C,OAAO,KAAK,CAAA;aACf;YACD,IAAI,IAAI,KAAK,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;gBACrC,OAAO,IAAI,CAAA;aACd;SACJ;QACD,OAAO,KAAK,CAAA;KACf;IAAC,OAAO,GAAG,EAAE;QACV,OAAO,KAAK,CAAA;KACf;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/captcha/util.ts"],"names":[],"mappings":"AAgBA,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAQpE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
import { ProsopoEnvError } from '@prosopo/common';
|
|
16
|
+
import client from 'axios';
|
|
17
|
+
export function downloadImage(url) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
try {
|
|
20
|
+
return new Uint8Array((yield client.default.get(url, { url, method: 'GET', responseType: 'arraybuffer' })).data);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw new ProsopoEnvError(error, downloadImage.name);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/captcha/util.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,MAAM,MAAM,OAAO,CAAA;AAE1B,MAAM,UAAgB,aAAa,CAAC,GAAW;;QAC3C,IAAI;YACA,OAAO,IAAI,UAAU,CACjB,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,GAAG,CAAc,GAAG,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,IAAI,CACzG,CAAA;SACJ;QAAC,OAAO,KAAK,EAAE;YACZ,MAAM,IAAI,eAAe,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,CAAA;SACvD;IACL,CAAC;CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,oBAAoB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
export * from './captcha/index.js';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,cAAc,oBAAoB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,58 +1,60 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
2
|
+
"name": "@prosopo/datasets",
|
|
3
|
+
"version": "0.1.17",
|
|
4
|
+
"author": "PROSOPO LIMITED <info@prosopo.io>",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"private": false,
|
|
7
|
+
"scripts": {
|
|
8
|
+
"clean": "tsc --build --clean",
|
|
9
|
+
"build": "tsc --build --verbose",
|
|
10
|
+
"lint": "npx eslint .",
|
|
11
|
+
"lint:fix": "npx eslint . --fix --config ../../.eslintrc.js",
|
|
12
|
+
"cli": "node ./dist/cli.js",
|
|
13
|
+
"test": "NODE_ENV=test ts-mocha \"./tests/js/**/*.test.ts\" --timeout 120000 --recursive --exit"
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": "./dist/index.js",
|
|
20
|
+
"./types": "./dist/types/index.js",
|
|
21
|
+
"./captcha": "./dist/captcha/index.js"
|
|
22
|
+
},
|
|
23
|
+
"typesVersions": {
|
|
24
|
+
"*": {
|
|
25
|
+
"types": [
|
|
26
|
+
"dist/types"
|
|
27
|
+
],
|
|
28
|
+
"captcha": [
|
|
29
|
+
"dist/captcha"
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@polkadot/util": "^12.3.2",
|
|
35
|
+
"@prosopo/common": "^0.1.17",
|
|
36
|
+
"@prosopo/contract": "^0.1.17",
|
|
37
|
+
"@prosopo/types": "^0.1.17",
|
|
38
|
+
"axios": "^0.27.2"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/mocha": "^10.0.0",
|
|
42
|
+
"typescript": "^4.9.5"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/prosopo/captcha.git"
|
|
47
|
+
},
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/prosopo/captcha/issues"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://github.com/prosopo/captcha#readme",
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"registry": "https://registry.npmjs.org"
|
|
54
|
+
},
|
|
55
|
+
"description": "Datasets for use with providers",
|
|
56
|
+
"directories": {
|
|
57
|
+
"test": "tests"
|
|
58
|
+
},
|
|
59
|
+
"sideEffects": false
|
|
58
60
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"captcha.d.ts","sourceRoot":"","sources":["../../../src/js/captcha/captcha.ts"],"names":[],"mappings":"AAeA,OAAO,EACH,cAAc,EACd,OAAO,EACP,eAAe,EAEf,gBAAgB,EAChB,UAAU,EAEV,UAAU,EACV,cAAc,EACd,IAAI,EACJ,WAAW,EACd,MAAM,gBAAgB,CAAA;AAOvB;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,IAAI,GAAG,UAAU,CAMjE;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,WAAW,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE,CAQ9F;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,UAEtE;AAED,wBAAgB,oBAAoB,CAChC,QAAQ,EAAE,eAAe,EAAE,EAC3B,MAAM,EAAE,OAAO,EAAE,GAClB;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,CAwBvC;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,eAAe,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAO/F;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAC9B,OAAO,EAAE,gBAAgB,EACzB,eAAe,qBAAQ,EACvB,WAAW,qBAAQ,EACnB,cAAc,EAAE,OAAO,GACxB,MAAM,CAkBR;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CAQrE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACjC,SAAS,EAAE,WAAW,EAAE,GAAG,cAAc,EAAE,EAC3C,KAAK,EAAE,IAAI,EAAE,GAAG,SAAS,GAC1B,cAAc,EAAE,CAgBlB;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,eAAe,UAGlE;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzG;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,cAAc,GAAG,SAAS;;;;;EAExF"}
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseCaptchaAssets = exports.computePendingRequestHash = exports.computeCaptchaSolutionHash = exports.matchItemsToSolutions = exports.computeItemHash = exports.computeCaptchaHash = exports.compareCaptchaSolutions = exports.sortAndComputeHashes = exports.captchaSort = exports.parseAndSortCaptchaSolutions = exports.parseCaptchaDataset = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
6
|
-
// This file is part of provider <https://github.com/prosopo/provider>.
|
|
7
|
-
//
|
|
8
|
-
// provider is free software: you can redistribute it and/or modify
|
|
9
|
-
// it under the terms of the GNU General Public License as published by
|
|
10
|
-
// the Free Software Foundation, either version 3 of the License, or
|
|
11
|
-
// (at your option) any later version.
|
|
12
|
-
//
|
|
13
|
-
// provider is distributed in the hope that it will be useful,
|
|
14
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
-
// GNU General Public License for more details.
|
|
17
|
-
//
|
|
18
|
-
// You should have received a copy of the GNU General Public License
|
|
19
|
-
// along with provider. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
-
const types_1 = require("@prosopo/types");
|
|
21
|
-
const common_1 = require("@prosopo/common");
|
|
22
|
-
const util_1 = require("./util");
|
|
23
|
-
const util_2 = require("@polkadot/util");
|
|
24
|
-
// import {encodeAddress} from "@polkadot/util-crypto";
|
|
25
|
-
/**
|
|
26
|
-
* Parse a dataset
|
|
27
|
-
* @return {JSON} captcha dataset, stored in JSON
|
|
28
|
-
* @param datasetJSON
|
|
29
|
-
*/
|
|
30
|
-
function parseCaptchaDataset(datasetJSON) {
|
|
31
|
-
try {
|
|
32
|
-
return types_1.DatasetSchema.parse(datasetJSON);
|
|
33
|
-
}
|
|
34
|
-
catch (err) {
|
|
35
|
-
throw new common_1.ProsopoEnvError(err, 'ERRORS.DATASET.PARSE_ERROR');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.parseCaptchaDataset = parseCaptchaDataset;
|
|
39
|
-
/**
|
|
40
|
-
* Make sure captcha solutions are in the correct format
|
|
41
|
-
* @param {JSON} captchaJSON captcha solutions received from the api
|
|
42
|
-
* @return {CaptchaSolution[]} an array of parsed and sorted captcha solutions
|
|
43
|
-
*/
|
|
44
|
-
function parseAndSortCaptchaSolutions(captchaJSON) {
|
|
45
|
-
try {
|
|
46
|
-
const parsed = types_1.CaptchaSolutionArraySchema.parse(captchaJSON);
|
|
47
|
-
parsed.map((captcha) => (Object.assign(Object.assign({}, captcha), { solution: captcha.solution.sort() })));
|
|
48
|
-
return parsed;
|
|
49
|
-
}
|
|
50
|
-
catch (err) {
|
|
51
|
-
throw new common_1.ProsopoEnvError(err, 'ERRORS.CAPTCHA.PARSE_ERROR');
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.parseAndSortCaptchaSolutions = parseAndSortCaptchaSolutions;
|
|
55
|
-
function captchaSort(a, b) {
|
|
56
|
-
return a.captchaId.localeCompare(b.captchaId);
|
|
57
|
-
}
|
|
58
|
-
exports.captchaSort = captchaSort;
|
|
59
|
-
function sortAndComputeHashes(received, stored) {
|
|
60
|
-
received.sort(captchaSort);
|
|
61
|
-
stored.sort(captchaSort);
|
|
62
|
-
return stored.map(({ salt, items = [], target = '', captchaId, solved }, index) => {
|
|
63
|
-
if (captchaId != received[index].captchaId) {
|
|
64
|
-
throw new common_1.ProsopoEnvError('CAPTCHA.ID_MISMATCH');
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
67
|
-
hash: computeCaptchaHash({
|
|
68
|
-
solution: solved ? received[index].solution : [],
|
|
69
|
-
salt,
|
|
70
|
-
items,
|
|
71
|
-
target,
|
|
72
|
-
}, true, true, false),
|
|
73
|
-
captchaId,
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
exports.sortAndComputeHashes = sortAndComputeHashes;
|
|
78
|
-
/**
|
|
79
|
-
* Take an array of CaptchaSolutions and Captchas and check if the solutions are the same for each pair
|
|
80
|
-
* @param {CaptchaSolution[]} received
|
|
81
|
-
* @param {Captcha[]} stored
|
|
82
|
-
* @return {boolean}
|
|
83
|
-
*/
|
|
84
|
-
function compareCaptchaSolutions(received, stored) {
|
|
85
|
-
if (received.length && stored.length && received.length === stored.length) {
|
|
86
|
-
const hashes = sortAndComputeHashes(received, stored);
|
|
87
|
-
return hashes.every(({ hash, captchaId }) => hash === captchaId);
|
|
88
|
-
}
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
exports.compareCaptchaSolutions = compareCaptchaSolutions;
|
|
92
|
-
/**
|
|
93
|
-
* Compute the hash of various types of captcha
|
|
94
|
-
* @param {Captcha} captcha
|
|
95
|
-
* @param {boolean} includeSolution
|
|
96
|
-
* @param {boolean} includeSalt
|
|
97
|
-
* @param {boolean} sortItemHashes
|
|
98
|
-
* @return {string} the hex string hash
|
|
99
|
-
*/
|
|
100
|
-
function computeCaptchaHash(captcha, includeSolution = false, includeSalt = false, sortItemHashes) {
|
|
101
|
-
try {
|
|
102
|
-
const itemHashes = captcha.items.map((item, index) => {
|
|
103
|
-
if (item.hash) {
|
|
104
|
-
return item.hash;
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
throw new common_1.ProsopoEnvError('CAPTCHA.MISSING_ITEM_HASH', computeCaptchaHash.name, undefined, index);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
return (0, common_1.hexHashArray)([
|
|
111
|
-
captcha.target,
|
|
112
|
-
...(includeSolution && captcha.solution ? captcha.solution.sort() : []),
|
|
113
|
-
includeSalt ? captcha.salt : '',
|
|
114
|
-
sortItemHashes ? itemHashes.sort() : itemHashes,
|
|
115
|
-
]);
|
|
116
|
-
}
|
|
117
|
-
catch (err) {
|
|
118
|
-
throw new common_1.ProsopoEnvError(err);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
exports.computeCaptchaHash = computeCaptchaHash;
|
|
122
|
-
/** Compute the hash of a captcha item, downloading the image if necessary
|
|
123
|
-
* @param {Item} item
|
|
124
|
-
* @return {Promise<HashedItem>} the hex string hash of the item
|
|
125
|
-
*/
|
|
126
|
-
function computeItemHash(item) {
|
|
127
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
if (item.type === 'text') {
|
|
129
|
-
return Object.assign(Object.assign({}, item), { hash: (0, common_1.hexHash)(item.data) });
|
|
130
|
-
}
|
|
131
|
-
else if (item.type === 'image') {
|
|
132
|
-
return Object.assign(Object.assign({}, item), { hash: (0, common_1.hexHash)(yield (0, util_1.downloadImage)(item.data)) });
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
throw new common_1.ProsopoEnvError('CAPTCHA.INVALID_ITEM_FORMAT');
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
exports.computeItemHash = computeItemHash;
|
|
140
|
-
/**
|
|
141
|
-
* Converts an indexed captcha solution to a hashed captcha solution or simply returns the hash if it is already hashed
|
|
142
|
-
* @return {HashedSolution[]}
|
|
143
|
-
* @param {RawSolution[] | HashedSolution[]} solutions
|
|
144
|
-
* @param {Item[]} items
|
|
145
|
-
*/
|
|
146
|
-
function matchItemsToSolutions(solutions, items) {
|
|
147
|
-
return ((solutions === null || solutions === void 0 ? void 0 : solutions.map((solution) => {
|
|
148
|
-
const hash = items && items[solution] && items[solution].hash ? items[solution].hash : solution;
|
|
149
|
-
if (!hash) {
|
|
150
|
-
throw new common_1.ProsopoEnvError('CAPTCHA.MISSING_ITEM_HASH');
|
|
151
|
-
}
|
|
152
|
-
if (!(0, util_2.isHex)(hash)) {
|
|
153
|
-
throw new common_1.ProsopoEnvError('CAPTCHA.INVALID_ITEM_HASH');
|
|
154
|
-
}
|
|
155
|
-
return hash;
|
|
156
|
-
})) || []);
|
|
157
|
-
}
|
|
158
|
-
exports.matchItemsToSolutions = matchItemsToSolutions;
|
|
159
|
-
/**
|
|
160
|
-
* Create a unique solution commitment
|
|
161
|
-
* @param {CaptchaSolution} captcha
|
|
162
|
-
* @return {string} the hex string hash
|
|
163
|
-
*/
|
|
164
|
-
function computeCaptchaSolutionHash(captcha) {
|
|
165
|
-
// TODO: should the captchaContentId be validated?
|
|
166
|
-
return (0, common_1.hexHashArray)([captcha.captchaId, captcha.captchaContentId, [...captcha.solution].sort(), captcha.salt]);
|
|
167
|
-
}
|
|
168
|
-
exports.computeCaptchaSolutionHash = computeCaptchaSolutionHash;
|
|
169
|
-
/**
|
|
170
|
-
* Compute hash for an array of captcha ids, userAccount, and salt, which serves as the identifier for a pending request
|
|
171
|
-
* @param {string[]} captchaIds
|
|
172
|
-
* @param {string} userAccount
|
|
173
|
-
* @param {string} salt
|
|
174
|
-
* @return {string}
|
|
175
|
-
*/
|
|
176
|
-
function computePendingRequestHash(captchaIds, userAccount, salt) {
|
|
177
|
-
return (0, common_1.hexHashArray)([...captchaIds.sort(), userAccount, salt]);
|
|
178
|
-
}
|
|
179
|
-
exports.computePendingRequestHash = computePendingRequestHash;
|
|
180
|
-
/**
|
|
181
|
-
* Parse the image items in a captcha and pass back a URI if they exist
|
|
182
|
-
*/
|
|
183
|
-
function parseCaptchaAssets(item, assetsResolver) {
|
|
184
|
-
return Object.assign(Object.assign({}, item), { path: (assetsResolver === null || assetsResolver === void 0 ? void 0 : assetsResolver.resolveAsset(item.data).getURL()) || item.data });
|
|
185
|
-
}
|
|
186
|
-
exports.parseCaptchaAssets = parseCaptchaAssets;
|
|
187
|
-
//# sourceMappingURL=captcha.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"captcha.js","sourceRoot":"","sources":["../../../src/js/captcha/captcha.ts"],"names":[],"mappings":";;;;AAAA,4CAA4C;AAC5C,uEAAuE;AACvE,EAAE;AACF,mEAAmE;AACnE,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,8DAA8D;AAC9D,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,oEAAoE;AACpE,0CAYuB;AACvB,4CAAwE;AACxE,iCAAsC;AACtC,yCAAsC;AAEtC,uDAAuD;AAEvD;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,WAAiB;IACjD,IAAI;QACA,OAAO,qBAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;KAC1C;I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d,MAAM,IAAI,wBAAe,CAAC,2BAA2B,CAAC,CAAA;SACzD;QAED,OAAO,IAAI,CAAA;IACf,CAAC,CAAC,KAAI,EAAE,CACX,CAAA;AACL,CAAC;AAnBD,sDAmBC;AAED;;;;GAIG;AACH,SAAgB,0BAA0B,CAAC,OAAwB;IAC/D,kDAAkD;IAClD,OAAO,IAAA,qBAAY,EAAC,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,gBAAgB,EAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;AAClH,CAAC;AAHD,gEAGC;AAED;;;;;;GAMG;AACH,SAAgB,yBAAyB,CAAC,UAAoB,EAAE,WAAmB,EAAE,IAAY;IAC7F,OAAO,IAAA,qBAAY,EAAC,CAAC,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC,CAAA;AAClE,CAAC;AAFD,8DAEC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,IAAU,EAAE,cAA0C;IACrF,uCAAY,IAAI,KAAE,IAAI,EAAE,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAI,IAAI,CAAC,IAAI,IAAE;AAC3F,CAAC;AAFD,gDAEC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { CaptchaMerkleTree } from './merkle';
|
|
2
|
-
import { Dataset, DatasetRaw } from '@prosopo/types';
|
|
3
|
-
export declare function buildDataset(datasetRaw: DatasetRaw): Promise<Dataset>;
|
|
4
|
-
export declare function buildCaptchaTree(dataset: Dataset, includeSolution: boolean, includeSalt: boolean, sortItemHashes: boolean): Promise<CaptchaMerkleTree>;
|
|
5
|
-
export declare function addItemHashesAndSolutionHashesToDataset(datasetRaw: DatasetRaw): Promise<Dataset>;
|
|
6
|
-
//# sourceMappingURL=dataset.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dataset.d.ts","sourceRoot":"","sources":["../../../src/js/captcha/dataset.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAIpD,wBAAsB,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAmB3E;AAED,wBAAsB,gBAAgB,CAClC,OAAO,EAAE,OAAO,EAChB,eAAe,EAAE,OAAO,EACxB,WAAW,EAAE,OAAO,EACpB,cAAc,EAAE,OAAO,GACxB,OAAO,CAAC,iBAAiB,CAAC,CAY5B;AAED,wBAAsB,uCAAuC,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAgBtG"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addItemHashesAndSolutionHashesToDataset = exports.buildCaptchaTree = exports.buildDataset = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const merkle_1 = require("./merkle");
|
|
6
|
-
const common_1 = require("@prosopo/common");
|
|
7
|
-
const captcha_1 = require("./captcha");
|
|
8
|
-
function buildDataset(datasetRaw) {
|
|
9
|
-
var _a, _b;
|
|
10
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
11
|
-
const dataset = yield addItemHashesAndSolutionHashesToDataset(datasetRaw);
|
|
12
|
-
const contentTree = yield buildCaptchaTree(dataset, false, false, true);
|
|
13
|
-
const solutionTree = yield buildCaptchaTree(dataset, true, true, false);
|
|
14
|
-
dataset.captchas = dataset.captchas.map((captcha, index) => {
|
|
15
|
-
var _a, _b;
|
|
16
|
-
return (Object.assign(Object.assign({}, captcha), { captchaId: solutionTree.leaves[index].hash, captchaContentId: contentTree.leaves[index].hash, datasetId: (_a = solutionTree.root) === null || _a === void 0 ? void 0 : _a.hash, datasetContentId: (_b = contentTree.root) === null || _b === void 0 ? void 0 : _b.hash }));
|
|
17
|
-
});
|
|
18
|
-
dataset.solutionTree = solutionTree.layers;
|
|
19
|
-
dataset.contentTree = contentTree.layers;
|
|
20
|
-
dataset.datasetId = (_a = solutionTree.root) === null || _a === void 0 ? void 0 : _a.hash;
|
|
21
|
-
dataset.datasetContentId = (_b = contentTree.root) === null || _b === void 0 ? void 0 : _b.hash;
|
|
22
|
-
return dataset;
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
exports.buildDataset = buildDataset;
|
|
26
|
-
function buildCaptchaTree(dataset, includeSolution, includeSalt, sortItemHashes) {
|
|
27
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
try {
|
|
29
|
-
const tree = new merkle_1.CaptchaMerkleTree();
|
|
30
|
-
const datasetWithItemHashes = Object.assign({}, dataset);
|
|
31
|
-
const captchaHashes = datasetWithItemHashes.captchas.map((captcha) => (0, captcha_1.computeCaptchaHash)(captcha, includeSolution, includeSalt, sortItemHashes));
|
|
32
|
-
tree.build(captchaHashes);
|
|
33
|
-
return tree;
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
throw new common_1.ProsopoEnvError('DATASET.HASH_ERROR');
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
exports.buildCaptchaTree = buildCaptchaTree;
|
|
41
|
-
function addItemHashesAndSolutionHashesToDataset(datasetRaw) {
|
|
42
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
return Object.assign(Object.assign({}, datasetRaw), { captchas: yield Promise.all(datasetRaw.captchas.map((captcha) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
const items = yield Promise.all(captcha.items.map((item) => tslib_1.__awaiter(this, void 0, void 0, function* () { return yield (0, captcha_1.computeItemHash)(item); })));
|
|
45
|
-
return Object.assign(Object.assign(Object.assign({}, captcha), { items }), (captcha.solution !== undefined && { solution: (0, captcha_1.matchItemsToSolutions)(captcha.solution, items) }));
|
|
46
|
-
}))) });
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
exports.addItemHashesAndSolutionHashesToDataset = addItemHashesAndSolutionHashesToDataset;
|
|
50
|
-
//# sourceMappingURL=dataset.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dataset.js","sourceRoot":"","sources":["../../../src/js/captcha/dataset.ts"],"names":[],"mappings":";;;;AACA,qCAA4C;AAE5C,4CAAiD;AACjD,uCAAsF;AAEtF,SAAsB,YAAY,CAAC,UAAsB;;;QACrD,MAAM,OAAO,GAAG,MAAM,uCAAuC,CAAC,UAAU,CAAC,CAAA;QACzE,MAAM,WAAW,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;QACvE,MAAM,YAAY,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;QACvE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CACnC,CAAC,OAAyB,EAAE,KAAa,EAAE,EAAE;;YACzC,OAAA,CAAC,gCACM,OAAO,KACV,SAAS,EAAE,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAC1C,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAChD,SAAS,EAAE,MAAA,YAAY,CAAC,IAAI,0CAAE,IAAI,EAClC,gBAAgB,EAAE,MAAA,WAAW,CAAC,IAAI,0CAAE,IAAI,GAC/B,CAAA,CAAA;SAAA,CACpB,CAAA;QACD,OAAO,CAAC,YAAY,GAAG,YAAY,CAAC,MAAM,CAAA;QAC1C,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC,MAA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B,EAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,EACtG;YACL,CAAC,CAAA,CAAC,CACL,GACO,CAAA;IAChB,CAAC;CAAA;AAhBD,0FAgBC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/js/captcha/index.ts"],"names":[],"mappings":"AAeA,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,WAAW,CAAA"}
|
package/dist/js/captcha/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
5
|
-
// This file is part of provider <https://github.com/prosopo/provider>.
|
|
6
|
-
//
|
|
7
|
-
// provider is free software: you can redistribute it and/or modify
|
|
8
|
-
// it under the terms of the GNU General Public License as published by
|
|
9
|
-
// the Free Software Foundation, either version 3 of the License, or
|
|
10
|
-
// (at your option) any later version.
|
|
11
|
-
//
|
|
12
|
-
// provider is distributed in the hope that it will be useful,
|
|
13
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
-
// GNU General Public License for more details.
|
|
16
|
-
//
|
|
17
|
-
// You should have received a copy of the GNU General Public License
|
|
18
|
-
// along with provider. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
-
tslib_1.__exportStar(require("./captcha"), exports);
|
|
20
|
-
tslib_1.__exportStar(require("./merkle"), exports);
|
|
21
|
-
tslib_1.__exportStar(require("./util"), exports);
|
|
22
|
-
tslib_1.__exportStar(require("./dataset"), exports);
|
|
23
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/js/captcha/index.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AAC5C,uEAAuE;AACvE,EAAE;AACF,mEAAmE;AACnE,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,8DAA8D;AAC9D,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,oEAAoE;AACpE,oDAAyB;AACzB,mDAAwB;AACxB,iDAAsB;AACtB,oDAAyB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"merkle.d.ts","sourceRoot":"","sources":["../../../src/js/captcha/merkle.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,mBAAmB,EAAE,WAAW,EAAoB,MAAM,gBAAgB,CAAA;AAG5G,cAAM,UAAW,YAAW,mBAAmB;IAC3C,IAAI,EAAE,MAAM,CAAA;IAEZ,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;gBAET,IAAI,KAAA;CAInB;AAED,qBAAa,iBAAiB;IAC1B,MAAM,EAAE,UAAU,EAAE,CAAA;IAEpB,MAAM,EAAE,WAAW,EAAE,CAAA;IAErB,IAAI,EAAE,UAAU,GAAG,SAAS,CAAA;;IAO5B,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE;IAetB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE;IAyBpC,YAAY,CAAC,SAAS,KAAA,EAAE,UAAU,KAAA,GAAG,UAAU;IAO/C,KAAK,CAAC,QAAQ,EAAE,UAAU,GAAG,WAAW;CA0B3C;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAkBzE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"merkle.js","sourceRoot":"","sources":["../../../src/js/captcha/merkle.ts"],"names":[],"mappings":";;;AAgBA,4CAA8C;AAE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C,OAAO,KAAK,CAAA;aACf;YACD,IAAI,IAAI,KAAK,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;gBACrC,OAAO,IAAI,CAAA;aACd;SACJ;QACD,OAAO,KAAK,CAAA;KACf;IAAC,OAAO,GAAG,EAAE;QACV,OAAO,KAAK,CAAA;KACf;AACL,CAAC;AAlBD,kCAkBC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/js/captcha/util.ts"],"names":[],"mappings":"AAkBA,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAQpE"}
|
package/dist/js/captcha/util.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.downloadImage = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
6
|
-
// This file is part of provider <https://github.com/prosopo/provider>.
|
|
7
|
-
//
|
|
8
|
-
// provider is free software: you can redistribute it and/or modify
|
|
9
|
-
// it under the terms of the GNU General Public License as published by
|
|
10
|
-
// the Free Software Foundation, either version 3 of the License, or
|
|
11
|
-
// (at your option) any later version.
|
|
12
|
-
//
|
|
13
|
-
// provider is distributed in the hope that it will be useful,
|
|
14
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
-
// GNU General Public License for more details.
|
|
17
|
-
//
|
|
18
|
-
// You should have received a copy of the GNU General Public License
|
|
19
|
-
// along with provider. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
-
const common_1 = require("@prosopo/common");
|
|
21
|
-
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
22
|
-
function downloadImage(url) {
|
|
23
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
try {
|
|
25
|
-
return new Uint8Array((yield axios_1.default.get(url, { url, method: 'GET', responseType: 'arraybuffer' })).data);
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
throw new common_1.ProsopoEnvError(error, downloadImage.name);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
exports.downloadImage = downloadImage;
|
|
33
|
-
//# sourceMappingURL=util.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/js/captcha/util.ts"],"names":[],"mappings":";;;;AAAA,4CAA4C;AAC5C,uEAAuE;AACvE,EAAE;AACF,mEAAmE;AACnE,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,8DAA8D;AAC9D,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,oEAAoE;AACpE,4CAAiD;AACjD,0DAA0B;AAE1B,SAAsB,aAAa,CAAC,GAAW;;QAC3C,IAAI;YACA,OAAO,IAAI,UAAU,CACjB,CAAC,MAAM,eAAM,CAAC,GAAG,CAAc,GAAG,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,IAAI,CACjG,CAAA;SACJ;QAAC,OAAO,KAAK,EAAE;YACZ,MAAM,IAAI,wBAAe,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,CAAA;SACvD;IACL,CAAC;CAAA;AARD,sCAQC"}
|
package/dist/js/index.d.ts
DELETED
package/dist/js/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/js/index.ts"],"names":[],"mappings":"AAeA,cAAc,iBAAiB,CAAA"}
|
package/dist/js/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
5
|
-
// This file is part of provider <https://github.com/prosopo/provider>.
|
|
6
|
-
//
|
|
7
|
-
// provider is free software: you can redistribute it and/or modify
|
|
8
|
-
// it under the terms of the GNU General Public License as published by
|
|
9
|
-
// the Free Software Foundation, either version 3 of the License, or
|
|
10
|
-
// (at your option) any later version.
|
|
11
|
-
//
|
|
12
|
-
// provider is distributed in the hope that it will be useful,
|
|
13
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
-
// GNU General Public License for more details.
|
|
16
|
-
//
|
|
17
|
-
// You should have received a copy of the GNU General Public License
|
|
18
|
-
// along with provider. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
-
tslib_1.__exportStar(require("./captcha/index"), exports);
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
package/dist/js/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/js/index.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AAC5C,uEAAuE;AACvE,EAAE;AACF,mEAAmE;AACnE,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,8DAA8D;AAC9D,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,oEAAoE;AACpE,0DAA+B"}
|
|
File without changes
|
|
File without changes
|