@prosopo/datasets 0.2.29 → 0.2.32
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/dist/cjs/captcha/captcha.cjs +11 -19
- package/dist/cjs/captcha/dataset.cjs +5 -4
- package/dist/cjs/captcha/merkle.cjs +3 -5
- package/dist/cjs/captcha/util.cjs +3 -5
- package/dist/cjs/index.cjs +0 -3
- package/dist/tests/mocks/data/captchas.json +17 -17
- package/package.json +4 -4
- package/dist/cjs/tests/mocks/data/captchas.cjs +0 -1043
|
@@ -4,7 +4,6 @@ const types = require("@prosopo/types");
|
|
|
4
4
|
const common = require("@prosopo/common");
|
|
5
5
|
const util = require("@prosopo/util");
|
|
6
6
|
const util$1 = require("./util.cjs");
|
|
7
|
-
const util$2 = require("@polkadot/util");
|
|
8
7
|
const NO_SOLUTION_VALUE = "NO_SOLUTION";
|
|
9
8
|
function parseCaptchaDataset(datasetJSON) {
|
|
10
9
|
try {
|
|
@@ -29,7 +28,7 @@ function parseCaptchaDataset(datasetJSON) {
|
|
|
29
28
|
result2.solutionTree = result.solutionTree;
|
|
30
29
|
return result2;
|
|
31
30
|
} catch (err) {
|
|
32
|
-
throw new common.
|
|
31
|
+
throw new common.ProsopoEnvError(err);
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
function parseAndSortCaptchaSolutions(captchaJSON) {
|
|
@@ -39,7 +38,7 @@ function parseAndSortCaptchaSolutions(captchaJSON) {
|
|
|
39
38
|
solution: captcha.solution.sort()
|
|
40
39
|
}));
|
|
41
40
|
} catch (err) {
|
|
42
|
-
throw new common.
|
|
41
|
+
throw new common.ProsopoEnvError(err);
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
function captchaSort(a, b) {
|
|
@@ -82,12 +81,7 @@ function computeCaptchaHash(captcha, includeSolution = false, includeSalt = fals
|
|
|
82
81
|
if (item.hash) {
|
|
83
82
|
return item.hash;
|
|
84
83
|
} else {
|
|
85
|
-
throw new common.
|
|
86
|
-
context: {
|
|
87
|
-
computeCaptchaHashName: computeCaptchaHash.name,
|
|
88
|
-
index
|
|
89
|
-
}
|
|
90
|
-
});
|
|
84
|
+
throw new common.ProsopoEnvError("CAPTCHA.MISSING_ITEM_HASH", computeCaptchaHash.name, void 0, index);
|
|
91
85
|
}
|
|
92
86
|
});
|
|
93
87
|
return common.hexHashArray([
|
|
@@ -99,7 +93,7 @@ function computeCaptchaHash(captcha, includeSolution = false, includeSalt = fals
|
|
|
99
93
|
sortItemHashes ? itemHashes.sort() : itemHashes
|
|
100
94
|
]);
|
|
101
95
|
} catch (err) {
|
|
102
|
-
throw new common.
|
|
96
|
+
throw new common.ProsopoEnvError(err);
|
|
103
97
|
}
|
|
104
98
|
}
|
|
105
99
|
function getSolutionValueToHash(solution) {
|
|
@@ -111,7 +105,7 @@ async function computeItemHash(item) {
|
|
|
111
105
|
} else if (item.type === "image") {
|
|
112
106
|
return { ...item, hash: common.hexHash(await util$1.downloadImage(item.data)) };
|
|
113
107
|
} else {
|
|
114
|
-
throw new common.
|
|
108
|
+
throw new common.ProsopoEnvError("CAPTCHA.INVALID_ITEM_FORMAT");
|
|
115
109
|
}
|
|
116
110
|
}
|
|
117
111
|
function matchItemsToSolutions(solutions, items) {
|
|
@@ -119,17 +113,15 @@ function matchItemsToSolutions(solutions, items) {
|
|
|
119
113
|
return [];
|
|
120
114
|
}
|
|
121
115
|
return solutions.map((solution) => {
|
|
122
|
-
if (typeof solution === "string"
|
|
123
|
-
if (!(items == null ? void 0 : items.some((
|
|
124
|
-
throw new common.
|
|
116
|
+
if (typeof solution === "string") {
|
|
117
|
+
if (!(items == null ? void 0 : items.some((item2) => item2.hash === solution))) {
|
|
118
|
+
throw new common.ProsopoEnvError("CAPTCHA.INVALID_ITEM_HASH");
|
|
125
119
|
}
|
|
126
120
|
return solution;
|
|
127
|
-
} else if (typeof solution === "number") {
|
|
128
|
-
const item = util.at(items, solution);
|
|
129
|
-
return item.hash;
|
|
130
|
-
} else {
|
|
131
|
-
throw new common.ProsopoDatasetError("CAPTCHA.INVALID_SOLUTION_TYPE");
|
|
132
121
|
}
|
|
122
|
+
const item = util.at(items, solution);
|
|
123
|
+
const hash = item.hash;
|
|
124
|
+
return hash;
|
|
133
125
|
});
|
|
134
126
|
}
|
|
135
127
|
function computeCaptchaSolutionHash(captcha) {
|
|
@@ -35,9 +35,9 @@ async function validateDatasetContent(datasetOriginal) {
|
|
|
35
35
|
}
|
|
36
36
|
async function buildDataset(datasetRaw) {
|
|
37
37
|
var _a, _b;
|
|
38
|
-
logger.
|
|
38
|
+
logger.info(`Adding solution hashes to dataset`);
|
|
39
39
|
const dataset = await addSolutionHashesToDataset(datasetRaw);
|
|
40
|
-
logger.
|
|
40
|
+
logger.info(`Building dataset merkle trees`);
|
|
41
41
|
const contentTree = await buildCaptchaTree(dataset, false, false, true);
|
|
42
42
|
const solutionTree = await buildCaptchaTree(dataset, true, true, false);
|
|
43
43
|
dataset.captchas = dataset.captchas.map(
|
|
@@ -71,8 +71,8 @@ async function buildCaptchaTree(dataset, includeSolution, includeSalt, sortItemH
|
|
|
71
71
|
throw new common.ProsopoEnvError("DATASET.HASH_ERROR");
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
function addSolutionHashesToDataset(datasetRaw) {
|
|
75
|
-
const
|
|
74
|
+
async function addSolutionHashesToDataset(datasetRaw) {
|
|
75
|
+
const captchaPromises = datasetRaw.captchas.map(async (captcha$1) => {
|
|
76
76
|
return {
|
|
77
77
|
...captcha$1,
|
|
78
78
|
items: captcha$1.items,
|
|
@@ -80,6 +80,7 @@ function addSolutionHashesToDataset(datasetRaw) {
|
|
|
80
80
|
...captcha$1.solution !== void 0 && { solution: captcha.matchItemsToSolutions(captcha$1.solution, captcha$1.items) }
|
|
81
81
|
};
|
|
82
82
|
});
|
|
83
|
+
const captchas = await Promise.all(captchaPromises);
|
|
83
84
|
return {
|
|
84
85
|
...datasetRaw,
|
|
85
86
|
captchas
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const common = require("@prosopo/common");
|
|
4
3
|
const util = require("@prosopo/util");
|
|
4
|
+
const common = require("@prosopo/common");
|
|
5
5
|
class MerkleNode {
|
|
6
6
|
constructor(hash) {
|
|
7
7
|
this.hash = hash;
|
|
@@ -37,7 +37,7 @@ class CaptchaMerkleTree {
|
|
|
37
37
|
while (leafIndex < numLeaves) {
|
|
38
38
|
const leftChild = leaves[leafIndex];
|
|
39
39
|
if (leftChild === void 0) {
|
|
40
|
-
throw new
|
|
40
|
+
throw new Error("leftChild undefined");
|
|
41
41
|
}
|
|
42
42
|
const rightChild = leafIndex + 1 < numLeaves ? util.at(leaves, leafIndex + 1) : leftChild;
|
|
43
43
|
const parentNode = this.createParent(leftChild, rightChild);
|
|
@@ -60,9 +60,7 @@ class CaptchaMerkleTree {
|
|
|
60
60
|
while (layerNum < this.layers.length - 1) {
|
|
61
61
|
const layer = this.layers[layerNum];
|
|
62
62
|
if (layer === void 0) {
|
|
63
|
-
throw new
|
|
64
|
-
context: { error: "layer undefined", failedFuncName: this.proof.name, layerNum }
|
|
65
|
-
});
|
|
63
|
+
throw new Error("layer undefined");
|
|
66
64
|
}
|
|
67
65
|
const leafIndex = layer.indexOf(leafHash);
|
|
68
66
|
let partnerIndex = leafIndex % 2 && leafIndex > 0 ? leafIndex - 1 : leafIndex + 1;
|
|
@@ -5,14 +5,12 @@ async function downloadImage(url) {
|
|
|
5
5
|
try {
|
|
6
6
|
const response = await fetch(url);
|
|
7
7
|
if (!response.ok) {
|
|
8
|
-
throw new
|
|
9
|
-
context: { error: `Network response was not ok, status: ${response.status}`, url }
|
|
10
|
-
});
|
|
8
|
+
throw new Error(`Network response was not ok, status: ${response.status}`);
|
|
11
9
|
}
|
|
12
10
|
const buffer = await response.arrayBuffer();
|
|
13
11
|
return new Uint8Array(buffer);
|
|
14
|
-
} catch (
|
|
15
|
-
throw new common.ProsopoEnvError(
|
|
12
|
+
} catch (error) {
|
|
13
|
+
throw new common.ProsopoEnvError(error);
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
exports.downloadImage = downloadImage;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
require("./captcha/index.cjs");
|
|
4
|
-
const captchas = require("./tests/mocks/data/captchas.cjs");
|
|
5
4
|
const captcha = require("./captcha/captcha.cjs");
|
|
6
5
|
const merkle = require("./captcha/merkle.cjs");
|
|
7
6
|
const util = require("./captcha/util.cjs");
|
|
8
7
|
const dataset = require("./captcha/dataset.cjs");
|
|
9
|
-
exports.datasetWithIndexSolutions = captchas.datasetWithIndexSolutions;
|
|
10
|
-
exports.datasetWithSolutionHashes = captchas.datasetWithSolutionHashes;
|
|
11
8
|
exports.NO_SOLUTION_VALUE = captcha.NO_SOLUTION_VALUE;
|
|
12
9
|
exports.captchaSort = captcha.captchaSort;
|
|
13
10
|
exports.compareCaptchaSolutions = captcha.compareCaptchaSolutions;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"datasetId": "0x80f2e82ed079330c5fd9ea849a2b068e5b5c3473061219e5b33f2f210e6f1715",
|
|
3
3
|
"captchas": [
|
|
4
4
|
{
|
|
5
|
-
"salt": "
|
|
5
|
+
"salt": "0x0ee5e8130bf5834978971abbb3e94703",
|
|
6
6
|
"solution": [1, 2, 3],
|
|
7
7
|
"timeLimit": 20,
|
|
8
8
|
"items": [
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"target": "bus"
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
|
-
"salt": "
|
|
58
|
+
"salt": "0xc91bc6807f3b240802b4fbb77b7a64cc",
|
|
59
59
|
"solution": [0, 7, 8],
|
|
60
60
|
"items": [
|
|
61
61
|
{
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"target": "train"
|
|
108
108
|
},
|
|
109
109
|
{
|
|
110
|
-
"salt": "
|
|
110
|
+
"salt": "0x2b1bab8943b8a24ffdaa23e16b66ad91",
|
|
111
111
|
"solution": [],
|
|
112
112
|
"items": [
|
|
113
113
|
{
|
|
@@ -159,7 +159,7 @@
|
|
|
159
159
|
"target": "car"
|
|
160
160
|
},
|
|
161
161
|
{
|
|
162
|
-
"salt": "
|
|
162
|
+
"salt": "0x70c4756934dbb66b1aafa44178aa9e2e",
|
|
163
163
|
"items": [
|
|
164
164
|
{
|
|
165
165
|
"hash": "0x7f4313a6d4240e206d7c7f16d368ddf12d5f1d78296fd3de7e91df1d7739a35f",
|
|
@@ -210,7 +210,7 @@
|
|
|
210
210
|
"target": "plane"
|
|
211
211
|
},
|
|
212
212
|
{
|
|
213
|
-
"salt": "
|
|
213
|
+
"salt": "0x5f3e0f226785935762337f97aee6eb9b",
|
|
214
214
|
"solution": [2, 3, 8],
|
|
215
215
|
"items": [
|
|
216
216
|
{
|
|
@@ -262,7 +262,7 @@
|
|
|
262
262
|
"target": "dog"
|
|
263
263
|
},
|
|
264
264
|
{
|
|
265
|
-
"salt": "
|
|
265
|
+
"salt": "0x2e81556317a19f15942558cc17715afc",
|
|
266
266
|
"solution": [0, 1, 4],
|
|
267
267
|
"items": [
|
|
268
268
|
{
|
|
@@ -314,7 +314,7 @@
|
|
|
314
314
|
"target": "cat"
|
|
315
315
|
},
|
|
316
316
|
{
|
|
317
|
-
"salt": "
|
|
317
|
+
"salt": "0xdc77a6623da63d4379ebacd5ad440907",
|
|
318
318
|
"items": [
|
|
319
319
|
{
|
|
320
320
|
"hash": "0x0138ab8b1951c2b36284f6abacfc40cc3ec8280adc38462cc5f6b852e17ffe59",
|
|
@@ -365,7 +365,7 @@
|
|
|
365
365
|
"target": "horse"
|
|
366
366
|
},
|
|
367
367
|
{
|
|
368
|
-
"salt": "
|
|
368
|
+
"salt": "0x0e33da9deb5f1cbeef4dce867c33c0c5",
|
|
369
369
|
"solution": [0, 7],
|
|
370
370
|
"items": [
|
|
371
371
|
{
|
|
@@ -417,7 +417,7 @@
|
|
|
417
417
|
"target": "plane"
|
|
418
418
|
},
|
|
419
419
|
{
|
|
420
|
-
"salt": "
|
|
420
|
+
"salt": "0x71ed6ca839978fc286f0651dfcef7862",
|
|
421
421
|
"solution": [4, 6, 8],
|
|
422
422
|
"items": [
|
|
423
423
|
{
|
|
@@ -469,7 +469,7 @@
|
|
|
469
469
|
"target": "dog"
|
|
470
470
|
},
|
|
471
471
|
{
|
|
472
|
-
"salt": "
|
|
472
|
+
"salt": "0xcc8730f359718c4d94c8dc565938621c",
|
|
473
473
|
"solution": [2, 3, 5],
|
|
474
474
|
"items": [
|
|
475
475
|
{
|
|
@@ -521,7 +521,7 @@
|
|
|
521
521
|
"target": "horse"
|
|
522
522
|
},
|
|
523
523
|
{
|
|
524
|
-
"salt": "
|
|
524
|
+
"salt": "0x234e4dc3fe6db2588645a66b78b9128a",
|
|
525
525
|
"items": [
|
|
526
526
|
{
|
|
527
527
|
"hash": "0x6e0784791bf2edbb348ed69fb8080f69f4c38d3a8169f9204b5600a44bdaa600",
|
|
@@ -572,7 +572,7 @@
|
|
|
572
572
|
"target": "bird"
|
|
573
573
|
},
|
|
574
574
|
{
|
|
575
|
-
"salt": "
|
|
575
|
+
"salt": "0xe7988f0244c7bbf76a8f3986c9e0e136",
|
|
576
576
|
"solution": [1, 6, 8],
|
|
577
577
|
"items": [
|
|
578
578
|
{
|
|
@@ -624,7 +624,7 @@
|
|
|
624
624
|
"target": "cat"
|
|
625
625
|
},
|
|
626
626
|
{
|
|
627
|
-
"salt": "
|
|
627
|
+
"salt": "0x743db1f415ed40fc96d83957034e624c",
|
|
628
628
|
"solution": [0, 3, 4],
|
|
629
629
|
"items": [
|
|
630
630
|
{
|
|
@@ -676,7 +676,7 @@
|
|
|
676
676
|
"target": "plane"
|
|
677
677
|
},
|
|
678
678
|
{
|
|
679
|
-
"salt": "
|
|
679
|
+
"salt": "0xaeb51120352c09c503caae1c811421ba",
|
|
680
680
|
"solution": [2, 5, 7],
|
|
681
681
|
"items": [
|
|
682
682
|
{
|
|
@@ -728,7 +728,7 @@
|
|
|
728
728
|
"target": "car"
|
|
729
729
|
},
|
|
730
730
|
{
|
|
731
|
-
"salt": "
|
|
731
|
+
"salt": "0x1ef72a0d9424c9d616f41537a5dc6add",
|
|
732
732
|
"solution": [3, 6, 7],
|
|
733
733
|
"items": [
|
|
734
734
|
{
|
|
@@ -780,7 +780,7 @@
|
|
|
780
780
|
"target": "cat"
|
|
781
781
|
},
|
|
782
782
|
{
|
|
783
|
-
"salt": "
|
|
783
|
+
"salt": "0xf6abd9232e3c3dd786be74e31a2dde62",
|
|
784
784
|
"solution": [8, 5, 1],
|
|
785
785
|
"items": [
|
|
786
786
|
{
|
|
@@ -832,7 +832,7 @@
|
|
|
832
832
|
"target": "deer"
|
|
833
833
|
},
|
|
834
834
|
{
|
|
835
|
-
"salt": "
|
|
835
|
+
"salt": "0xc567e7b688bd615d75b8ae7d108c3dfb",
|
|
836
836
|
"items": [
|
|
837
837
|
{
|
|
838
838
|
"hash": "0xeba2c2c032639c02627f28c6fb77bdd48de56d7a7260f4898a2cfbaa916aa488",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/datasets",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.32",
|
|
4
4
|
"author": "PROSOPO LIMITED <info@prosopo.io>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"private": false,
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@polkadot/util": "^12.3.2",
|
|
50
|
-
"@prosopo/common": "0.2.
|
|
51
|
-
"@prosopo/types": "0.2.
|
|
50
|
+
"@prosopo/common": "0.2.32",
|
|
51
|
+
"@prosopo/types": "0.2.32",
|
|
52
52
|
"vitest": "^0.34.6"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@prosopo/config": "0.2.
|
|
55
|
+
"@prosopo/config": "0.2.32",
|
|
56
56
|
"tslib": "2.6.2",
|
|
57
57
|
"typescript": "5.1.6"
|
|
58
58
|
},
|