@prosopo/datasets 0.1.16 → 0.1.18

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 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
- ```
package/package.json CHANGED
@@ -1,58 +1,62 @@
1
1
  {
2
- "name": "@prosopo/datasets",
3
- "version": "0.1.16",
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",
12
- "test": "NODE_ENV=test ts-mocha \"./tests/js/**/*.test.ts\" --timeout 120000 --recursive --exit"
13
- },
14
- "main": "./dist/js/index.js",
15
- "types": "./dist/js/index.d.ts",
16
- "exports": {
17
- ".": "./dist/js/index.js",
18
- "./types": "./dist/js/types/index.js",
19
- "./captcha": "./dist/js/captcha/index.js"
20
- },
21
- "typesVersions": {
22
- "*": {
23
- "types": [
24
- "dist/js/types"
25
- ],
26
- "captcha": [
27
- "dist/js/captcha"
28
- ]
29
- }
30
- },
31
- "dependencies": {
32
- "@polkadot/util": "12.3.2",
33
- "@prosopo/common": "^0.1.16",
34
- "@prosopo/contract": "^0.1.16",
35
- "@prosopo/types": "^0.1.16",
36
- "axios": "^0.27.2"
37
- },
38
- "devDependencies": {
39
- "@types/mocha": "^10.0.0",
40
- "typescript": "^4.9.4"
41
- },
42
- "repository": {
43
- "type": "git",
44
- "url": "git+https://github.com/prosopo/captcha.git"
45
- },
46
- "bugs": {
47
- "url": "https://github.com/prosopo/captcha/issues"
48
- },
49
- "homepage": "https://github.com/prosopo/captcha#readme",
50
- "publishConfig": {
51
- "registry": "https://registry.npmjs.org"
52
- },
53
- "description": "Datasets for use with providers",
54
- "directories": {
55
- "test": "tests"
56
- },
57
- "sideEffects": false
2
+ "name": "@prosopo/datasets",
3
+ "version": "0.1.18",
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.18",
36
+ "@prosopo/contract": "^0.1.18",
37
+ "@prosopo/types": "^0.1.18",
38
+ "@prosopo/util": "^0.1.18",
39
+ "axios": "^0.27.2"
40
+ },
41
+ "devDependencies": {
42
+ "@types/mocha": "^10.0.0",
43
+ "tslib": "^2.6.2",
44
+ "typescript": "^5.1.6"
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/prosopo/captcha.git"
49
+ },
50
+ "bugs": {
51
+ "url": "https://github.com/prosopo/captcha/issues"
52
+ },
53
+ "homepage": "https://github.com/prosopo/captcha#readme",
54
+ "publishConfig": {
55
+ "registry": "https://registry.npmjs.org"
56
+ },
57
+ "description": "Datasets for use with providers",
58
+ "directories": {
59
+ "test": "tests"
60
+ },
61
+ "sideEffects": false
58
62
  }
@@ -1,72 +0,0 @@
1
- import { AssetsResolver, Captcha, CaptchaSolution, CaptchaWithoutId, DatasetRaw, HashedItem, HashedSolution, Item, RawSolution } from '@prosopo/types';
2
- /**
3
- * Parse a dataset
4
- * @return {JSON} captcha dataset, stored in JSON
5
- * @param datasetJSON
6
- */
7
- export declare function parseCaptchaDataset(datasetJSON: JSON): DatasetRaw;
8
- /**
9
- * Make sure captcha solutions are in the correct format
10
- * @param {JSON} captchaJSON captcha solutions received from the api
11
- * @return {CaptchaSolution[]} an array of parsed and sorted captcha solutions
12
- */
13
- export declare function parseAndSortCaptchaSolutions(captchaJSON: CaptchaSolution[]): CaptchaSolution[];
14
- export declare function captchaSort<T extends {
15
- captchaId: string;
16
- }>(a: T, b: T): number;
17
- export declare function sortAndComputeHashes(received: CaptchaSolution[], stored: Captcha[]): {
18
- captchaId: string;
19
- hash: string;
20
- }[];
21
- /**
22
- * Take an array of CaptchaSolutions and Captchas and check if the solutions are the same for each pair
23
- * @param {CaptchaSolution[]} received
24
- * @param {Captcha[]} stored
25
- * @return {boolean}
26
- */
27
- export declare function compareCaptchaSolutions(received: CaptchaSolution[], stored: Captcha[]): boolean;
28
- /**
29
- * Compute the hash of various types of captcha
30
- * @param {Captcha} captcha
31
- * @param {boolean} includeSolution
32
- * @param {boolean} includeSalt
33
- * @param {boolean} sortItemHashes
34
- * @return {string} the hex string hash
35
- */
36
- export declare function computeCaptchaHash(captcha: CaptchaWithoutId, includeSolution: boolean | undefined, includeSalt: boolean | undefined, sortItemHashes: boolean): string;
37
- /** Compute the hash of a captcha item, downloading the image if necessary
38
- * @param {Item} item
39
- * @return {Promise<HashedItem>} the hex string hash of the item
40
- */
41
- export declare function computeItemHash(item: Item): Promise<HashedItem>;
42
- /**
43
- * Converts an indexed captcha solution to a hashed captcha solution or simply returns the hash if it is already hashed
44
- * @return {HashedSolution[]}
45
- * @param {RawSolution[] | HashedSolution[]} solutions
46
- * @param {Item[]} items
47
- */
48
- export declare function matchItemsToSolutions(solutions: RawSolution[] | HashedSolution[], items: Item[] | undefined): HashedSolution[];
49
- /**
50
- * Create a unique solution commitment
51
- * @param {CaptchaSolution} captcha
52
- * @return {string} the hex string hash
53
- */
54
- export declare function computeCaptchaSolutionHash(captcha: CaptchaSolution): string;
55
- /**
56
- * Compute hash for an array of captcha ids, userAccount, and salt, which serves as the identifier for a pending request
57
- * @param {string[]} captchaIds
58
- * @param {string} userAccount
59
- * @param {string} salt
60
- * @return {string}
61
- */
62
- export declare function computePendingRequestHash(captchaIds: string[], userAccount: string, salt: string): string;
63
- /**
64
- * Parse the image items in a captcha and pass back a URI if they exist
65
- */
66
- export declare function parseCaptchaAssets(item: Item, assetsResolver: AssetsResolver | undefined): {
67
- path: string;
68
- type: import("@prosopo/types").CaptchaItemTypes;
69
- data: string;
70
- hash?: string | undefined;
71
- };
72
- //# sourceMappingURL=captcha.d.ts.map
@@ -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,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,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,WAA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C,IAAI,CAAC,EAAE;YACd,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,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AkB,EAAC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,CAAC,CAC5E,CAAA;YACD,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;YACzB,OAAO,IAAI,CAAA;SACd;QAAC,OAAO,GAAG,EAAE;YACV,MAAM,IAAI,wBAAe,CAAC,oBAAoB,CAAC,CAAA;SAClD;IACL,CAAC;CAAA;AAjBD,4CAiBC;AAED,SAAsB,uCAAuC,CAAC,UAAsB;;QAChF,OAAO,gCACA,UAAU,KACb,QAAQ,EAAE,MAAM,OAAO,CAAC,GAAG,CACvB,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAO,OAAO,EAAE,EAAE;gBACtC,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAO,IAAI,EAAE,EAAE,wDAAC,OAAA,MAAM,IAAA,yBAAe,EAAC,IAAI,CAAC,CAAA,GAAA,CAAC,CAAC,CAAA;gBAE/F,qDACO,OAAO,KACV,KAAK,KAEF,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,QAAQ,EAAE,IAAA,+BAAqB,EAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,EACtG;YACL,CAAC,CAAA,CAAC,CACL,GACO,CAAA;IAChB,CAAC;CAAA;AAhBD,0FAgBC"}
@@ -1,5 +0,0 @@
1
- export * from './captcha';
2
- export * from './merkle';
3
- export * from './util';
4
- export * from './dataset';
5
- //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -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,19 +0,0 @@
1
- import { MerkleLayer, MerkleLeaf, MerkleNodeInterface, MerkleProof } from '@prosopo/types';
2
- declare class MerkleNode implements MerkleNodeInterface {
3
- hash: string;
4
- parent: string | null;
5
- constructor(hash: any);
6
- }
7
- export declare class CaptchaMerkleTree {
8
- leaves: MerkleNode[];
9
- layers: MerkleLayer[];
10
- root: MerkleNode | undefined;
11
- constructor();
12
- build(leaves: string[]): void;
13
- buildMerkleTree(leaves: MerkleNode[]): any;
14
- createParent(leftChild: any, rightChild: any): MerkleNode;
15
- proof(leafHash: MerkleLeaf): MerkleProof;
16
- }
17
- export declare function verifyProof(leaf: MerkleLeaf, proof: MerkleProof): boolean;
18
- export {};
19
- //# sourceMappingURL=merkle.d.ts.map
@@ -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,106 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyProof = exports.CaptchaMerkleTree = void 0;
4
- const common_1 = require("@prosopo/common");
5
- class MerkleNode {
6
- constructor(hash) {
7
- this.hash = hash;
8
- this.parent = null;
9
- }
10
- }
11
- class CaptchaMerkleTree {
12
- constructor() {
13
- this.leaves = [];
14
- this.layers = [];
15
- }
16
- build(leaves) {
17
- // allow rebuild
18
- if (this.layers.length) {
19
- this.layers = [];
20
- }
21
- const layerZero = [];
22
- for (const leaf of leaves) {
23
- const node = new MerkleNode(leaf);
24
- this.leaves.push(node);
25
- layerZero.push(node.hash);
26
- }
27
- this.layers.push(layerZero);
28
- this.root = this.buildMerkleTree(this.leaves);
29
- }
30
- buildMerkleTree(leaves) {
31
- // Builds the Merkle tree from a list of leaves. In case of an odd number of leaves, the last leaf is duplicated.
32
- const numLeaves = leaves.length;
33
- if (numLeaves === 1) {
34
- return leaves[0];
35
- }
36
- const parents = [];
37
- let leafIndex = 0;
38
- const newLayer = [];
39
- while (leafIndex < numLeaves) {
40
- const leftChild = leaves[leafIndex];
41
- const rightChild = leafIndex + 1 < numLeaves ? leaves[leafIndex + 1] : leftChild;
42
- const parentNode = this.createParent(leftChild, rightChild);
43
- newLayer.push(parentNode.hash);
44
- parents.push(parentNode);
45
- leafIndex += 2;
46
- }
47
- this.layers.push(newLayer);
48
- return this.buildMerkleTree(parents);
49
- }
50
- createParent(leftChild, rightChild) {
51
- const parent = new MerkleNode((0, common_1.hexHashArray)([leftChild.hash, rightChild.hash]));
52
- leftChild.parent = parent;
53
- rightChild.parent = parent;
54
- return parent;
55
- }
56
- proof(leafHash) {
57
- const proofTree = [];
58
- let layerNum = 0;
59
- while (layerNum < this.layers.length - 1) {
60
- const leafIndex = this.layers[layerNum].indexOf(leafHash);
61
- // if layer 0 leaf index is 3, it should be partnered with 2: [L0,L1],[L2,L3],[L3,L4],...
62
- // layer one pairs looks like [L0L1, L2L3], [L3L4, L5L6],...etc
63
- let partnerIndex = leafIndex % 2 && leafIndex > 0 ? leafIndex - 1 : leafIndex + 1;
64
- // if there are an odd number of leaves in the layer, the last leaf is duplicated
65
- if (partnerIndex > this.layers[layerNum].length - 1) {
66
- partnerIndex = leafIndex;
67
- }
68
- const pair = [leafHash];
69
- const layer = this.layers[layerNum];
70
- // determine whether the leaf sits on the left or the right of its partner
71
- if (partnerIndex > leafIndex) {
72
- pair.push(layer[partnerIndex]);
73
- }
74
- else {
75
- pair.unshift(layer[partnerIndex]);
76
- }
77
- proofTree.push([pair[0], pair[1]]);
78
- layerNum += 1;
79
- leafHash = (0, common_1.hexHashArray)(pair);
80
- }
81
- return [...proofTree, [this.layers[this.layers.length - 1][0]]];
82
- }
83
- }
84
- exports.CaptchaMerkleTree = CaptchaMerkleTree;
85
- function verifyProof(leaf, proof) {
86
- try {
87
- if (proof[0].indexOf(leaf) === -1) {
88
- return false;
89
- }
90
- for (const [layerIndex, layer] of proof.entries()) {
91
- leaf = (0, common_1.hexHashArray)(layer);
92
- if (proof[layerIndex + 1].indexOf(leaf) === -1) {
93
- return false;
94
- }
95
- if (leaf === proof[proof.length - 1][0]) {
96
- return true;
97
- }
98
- }
99
- return false;
100
- }
101
- catch (err) {
102
- return false;
103
- }
104
- }
105
- exports.verifyProof = verifyProof;
106
- //# sourceMappingURL=merkle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merkle.js","sourceRoot":"","sources":["../../../src/js/captcha/merkle.ts"],"names":[],"mappings":";;;AAgBA,4CAA8C;AAE9C,MAAM,UAAU;IAKZ,YAAY,IAAI;QACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;IACtB,CAAC;CACJ;AAED,MAAa,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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AI,CAAC,CAAA;SAChC;QACD,OAAO,CAAC,GAAG,SAAS,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACnE,CAAC;CACJ;AArFD,8CAqFC;AAED,SAAgB,WAAW,CAAC,IAAgB,EAAE,KAAkB;IAC5D,IAAI;QACA,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE;YAC/B,OAAO,KAAK,CAAA;SACf;QACD,KAAK,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE;YAC/C,IAAI,GAAG,IAAA,qBAAY,EAAC,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;AAlBD,kCAkBC"}
@@ -1,2 +0,0 @@
1
- export declare function downloadImage(url: string): Promise<Uint8Array>;
2
- //# sourceMappingURL=util.d.ts.map
@@ -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"}
@@ -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"}
@@ -1,2 +0,0 @@
1
- export * from './captcha/index';
2
- //# sourceMappingURL=index.d.ts.map
@@ -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
@@ -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"}