@prosopo/datasets 0.1.17 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prosopo/datasets",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "author": "PROSOPO LIMITED <info@prosopo.io>",
5
5
  "license": "Apache-2.0",
6
6
  "private": false,
@@ -32,14 +32,16 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@polkadot/util": "^12.3.2",
35
- "@prosopo/common": "^0.1.17",
36
- "@prosopo/contract": "^0.1.17",
37
- "@prosopo/types": "^0.1.17",
35
+ "@prosopo/common": "^0.1.18",
36
+ "@prosopo/contract": "^0.1.18",
37
+ "@prosopo/types": "^0.1.18",
38
+ "@prosopo/util": "^0.1.18",
38
39
  "axios": "^0.27.2"
39
40
  },
40
41
  "devDependencies": {
41
42
  "@types/mocha": "^10.0.0",
42
- "typescript": "^4.9.5"
43
+ "tslib": "^2.6.2",
44
+ "typescript": "^5.1.6"
43
45
  },
44
46
  "repository": {
45
47
  "type": "git",
@@ -1,78 +0,0 @@
1
- import { AssetsResolver, Captcha, CaptchaSolution, CaptchaWithoutId, DatasetRaw, HashedItem, HashedSolution, Item, RawSolution } from '@prosopo/types';
2
- export declare const NO_SOLUTION_VALUE = "NO_SOLUTION";
3
- /**
4
- * Parse a dataset
5
- * @return {JSON} captcha dataset, stored in JSON
6
- * @param datasetJSON
7
- */
8
- export declare function parseCaptchaDataset(datasetJSON: JSON): DatasetRaw;
9
- /**
10
- * Make sure captcha solutions are in the correct format
11
- * @param {JSON} captchaJSON captcha solutions received from the api
12
- * @return {CaptchaSolution[]} an array of parsed and sorted captcha solutions
13
- */
14
- export declare function parseAndSortCaptchaSolutions(captchaJSON: CaptchaSolution[]): CaptchaSolution[];
15
- export declare function captchaSort<T extends {
16
- captchaId: string;
17
- }>(a: T, b: T): number;
18
- export declare function sortAndComputeHashes(received: CaptchaSolution[], stored: Captcha[]): {
19
- captchaId: string;
20
- hash: string;
21
- }[];
22
- /**
23
- * Take an array of CaptchaSolutions and Captchas and check if the solutions are the same for each pair
24
- * @param {CaptchaSolution[]} received
25
- * @param {Captcha[]} stored
26
- * @return {boolean}
27
- */
28
- export declare function compareCaptchaSolutions(received: CaptchaSolution[], stored: Captcha[]): boolean;
29
- /**
30
- * Compute the hash of various types of captcha
31
- * @param {Captcha} captcha
32
- * @param {boolean} includeSolution
33
- * @param {boolean} includeSalt
34
- * @param {boolean} sortItemHashes
35
- * @return {string} the hex string hash
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[];
43
- /** Compute the hash of a captcha item, downloading the image if necessary
44
- * @param {Item} item
45
- * @return {Promise<HashedItem>} the hex string hash of the item
46
- */
47
- export declare function computeItemHash(item: Item): Promise<HashedItem>;
48
- /**
49
- * Converts an indexed captcha solution to a hashed captcha solution or simply returns the hash if it is already hashed
50
- * @return {HashedSolution[]}
51
- * @param {RawSolution[] | HashedSolution[]} solutions
52
- * @param {Item[]} items
53
- */
54
- export declare function matchItemsToSolutions(solutions: RawSolution[] | HashedSolution[], items: HashedItem[] | undefined): HashedSolution[];
55
- /**
56
- * Create a unique solution commitment
57
- * @param {CaptchaSolution} captcha
58
- * @return {string} the hex string hash
59
- */
60
- export declare function computeCaptchaSolutionHash(captcha: CaptchaSolution): string;
61
- /**
62
- * Compute hash for an array of captcha ids, userAccount, and salt, which serves as the identifier for a pending request
63
- * @param {string[]} captchaIds
64
- * @param {string} userAccount
65
- * @param {string} salt
66
- * @return {string}
67
- */
68
- export declare function computePendingRequestHash(captchaIds: string[], userAccount: string, salt: string): string;
69
- /**
70
- * Parse the image items in a captcha and pass back a URI if they exist
71
- */
72
- export declare function parseCaptchaAssets(item: Item, assetsResolver: AssetsResolver | undefined): {
73
- path: string;
74
- type: import("@prosopo/types").CaptchaItemTypes;
75
- data: string;
76
- hash: string;
77
- };
78
- //# sourceMappingURL=captcha.d.ts.map
@@ -1 +0,0 @@
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,EAEV,UAAU,EACV,cAAc,EACd,IAAI,EACJ,WAAW,EACd,MAAM,gBAAgB,CAAA;AAKvB,eAAO,MAAM,iBAAiB,gBAAgB,CAAA;AAE9C;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,IAAI,GAAG,UAAU,CAMjE;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,WAAW,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE,CAS9F;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,CAoBR;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,CAAC,EAAE,cAAc,EAAE,GAAG,WAAW,EAAE,uBAEjF;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,UAAU,EAAE,GAAG,SAAS,GAChC,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,178 +0,0 @@
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
@@ -1 +0,0 @@
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,CAA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ashDatasetItems(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
@@ -1 +0,0 @@
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"}
@@ -1,77 +0,0 @@
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
@@ -1 +0,0 @@
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;AAE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iB,EAAE,CAAA;YACpC,MAAM,qBAAqB,qBAAQ,OAAO,CAAE,CAAA;YAC5C,MAAM,aAAa,GAAG,qBAAqB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CACjE,kBAAkB,CAAC,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,eAAe,CAAC,oBAAoB,CAAC,CAAA;SAClD;IACL,CAAC;CAAA;AAED,MAAM,UAAgB,0BAA0B,CAAC,UAAsB;;QACnE,MAAM,eAAe,GAAG,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,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"}
@@ -1,5 +0,0 @@
1
- export * from './captcha.js';
2
- export * from './merkle.js';
3
- export * from './util.js';
4
- export * from './dataset.js';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,18 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -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/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,101 +0,0 @@
1
- import { hexHashArray } from '@prosopo/common';
2
- class MerkleNode {
3
- constructor(hash) {
4
- this.hash = hash;
5
- this.parent = null;
6
- }
7
- }
8
- export class CaptchaMerkleTree {
9
- constructor() {
10
- this.leaves = [];
11
- this.layers = [];
12
- }
13
- build(leaves) {
14
- // allow rebuild
15
- if (this.layers.length) {
16
- this.layers = [];
17
- }
18
- const layerZero = [];
19
- for (const leaf of leaves) {
20
- const node = new MerkleNode(leaf);
21
- this.leaves.push(node);
22
- layerZero.push(node.hash);
23
- }
24
- this.layers.push(layerZero);
25
- this.root = this.buildMerkleTree(this.leaves);
26
- }
27
- buildMerkleTree(leaves) {
28
- // Builds the Merkle tree from a list of leaves. In case of an odd number of leaves, the last leaf is duplicated.
29
- const numLeaves = leaves.length;
30
- if (numLeaves === 1) {
31
- return leaves[0];
32
- }
33
- const parents = [];
34
- let leafIndex = 0;
35
- const newLayer = [];
36
- while (leafIndex < numLeaves) {
37
- const leftChild = leaves[leafIndex];
38
- const rightChild = leafIndex + 1 < numLeaves ? leaves[leafIndex + 1] : leftChild;
39
- const parentNode = this.createParent(leftChild, rightChild);
40
- newLayer.push(parentNode.hash);
41
- parents.push(parentNode);
42
- leafIndex += 2;
43
- }
44
- this.layers.push(newLayer);
45
- return this.buildMerkleTree(parents);
46
- }
47
- createParent(leftChild, rightChild) {
48
- const parent = new MerkleNode(hexHashArray([leftChild.hash, rightChild.hash]));
49
- leftChild.parent = parent;
50
- rightChild.parent = parent;
51
- return parent;
52
- }
53
- proof(leafHash) {
54
- const proofTree = [];
55
- let layerNum = 0;
56
- while (layerNum < this.layers.length - 1) {
57
- const leafIndex = this.layers[layerNum].indexOf(leafHash);
58
- // if layer 0 leaf index is 3, it should be partnered with 2: [L0,L1],[L2,L3],[L3,L4],...
59
- // layer one pairs looks like [L0L1, L2L3], [L3L4, L5L6],...etc
60
- let partnerIndex = leafIndex % 2 && leafIndex > 0 ? leafIndex - 1 : leafIndex + 1;
61
- // if there are an odd number of leaves in the layer, the last leaf is duplicated
62
- if (partnerIndex > this.layers[layerNum].length - 1) {
63
- partnerIndex = leafIndex;
64
- }
65
- const pair = [leafHash];
66
- const layer = this.layers[layerNum];
67
- // determine whether the leaf sits on the left or the right of its partner
68
- if (partnerIndex > leafIndex) {
69
- pair.push(layer[partnerIndex]);
70
- }
71
- else {
72
- pair.unshift(layer[partnerIndex]);
73
- }
74
- proofTree.push([pair[0], pair[1]]);
75
- layerNum += 1;
76
- leafHash = hexHashArray(pair);
77
- }
78
- return [...proofTree, [this.layers[this.layers.length - 1][0]]];
79
- }
80
- }
81
- export function verifyProof(leaf, proof) {
82
- try {
83
- if (proof[0].indexOf(leaf) === -1) {
84
- return false;
85
- }
86
- for (const [layerIndex, layer] of proof.entries()) {
87
- leaf = hexHashArray(layer);
88
- if (proof[layerIndex + 1].indexOf(leaf) === -1) {
89
- return false;
90
- }
91
- if (leaf === proof[proof.length - 1][0]) {
92
- return true;
93
- }
94
- }
95
- return false;
96
- }
97
- catch (err) {
98
- return false;
99
- }
100
- }
101
- //# sourceMappingURL=merkle.js.map
@@ -1 +0,0 @@
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,CA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AAC,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,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"}
@@ -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/captcha/util.ts"],"names":[],"mappings":"AAgBA,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAQpE"}
@@ -1,27 +0,0 @@
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
@@ -1 +0,0 @@
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 DELETED
@@ -1,2 +0,0 @@
1
- export * from './captcha/index.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,oBAAoB,CAAA"}
package/dist/index.js DELETED
@@ -1,15 +0,0 @@
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
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
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"}