@prosopo/datasets 3.1.54 → 3.1.55
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/.turbo/turbo-build$colon$cjs.log +15 -13
- package/.turbo/turbo-build$colon$tsc.log +11 -11
- package/.turbo/turbo-build.log +17 -14
- package/CHANGELOG.md +14 -0
- package/dist/_virtual/_rolldown/runtime.js +3 -0
- package/dist/captcha/captcha.js +171 -168
- package/dist/captcha/dataset.js +64 -82
- package/dist/captcha/index.js +2 -24
- package/dist/captcha/merkle.js +93 -123
- package/dist/captcha/util.js +14 -20
- package/dist/cjs/captcha/captcha.cjs +173 -158
- package/dist/cjs/captcha/dataset.cjs +64 -79
- package/dist/cjs/captcha/index.cjs +25 -27
- package/dist/cjs/captcha/merkle.cjs +95 -124
- package/dist/cjs/captcha/util.cjs +14 -20
- package/dist/cjs/index.cjs +28 -30
- package/dist/cjs/tests/mocks/data/captchas.cjs +1026 -1040
- package/dist/index.js +4 -28
- package/dist/tests/mocks/data/captchas.js +1027 -1042
- package/package.json +9 -9
|
@@ -1,128 +1,99 @@
|
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
layerNum
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
const leafIndex = layer.indexOf(leafHash);
|
|
88
|
-
let partnerIndex = leafIndex % 2 && leafIndex > 0 ? leafIndex - 1 : leafIndex + 1;
|
|
89
|
-
if (partnerIndex > layer.length - 1) {
|
|
90
|
-
partnerIndex = leafIndex;
|
|
91
|
-
}
|
|
92
|
-
const pair = [leafHash];
|
|
93
|
-
const partner = util.at(layer, partnerIndex);
|
|
94
|
-
if (partnerIndex > leafIndex) {
|
|
95
|
-
pair.push(partner);
|
|
96
|
-
} else {
|
|
97
|
-
pair.unshift(partner);
|
|
98
|
-
}
|
|
99
|
-
proofTree.push([util.at(pair, 0), util.at(pair, 1)]);
|
|
100
|
-
layerNum += 1;
|
|
101
|
-
leafHash = utilCrypto.hexHashArray(pair);
|
|
102
|
-
}
|
|
103
|
-
const last = util.at(this.layers, this.layers.length - 1);
|
|
104
|
-
return [...proofTree, [util.at(last, 0)]];
|
|
105
|
-
}
|
|
106
|
-
}
|
|
1
|
+
let _prosopo_common = require("@prosopo/common");
|
|
2
|
+
let _prosopo_util = require("@prosopo/util");
|
|
3
|
+
let _prosopo_util_crypto = require("@prosopo/util-crypto");
|
|
4
|
+
//#region src/captcha/merkle.ts
|
|
5
|
+
var MerkleNode = class {
|
|
6
|
+
constructor(hash) {
|
|
7
|
+
this.hash = hash;
|
|
8
|
+
this.parent = null;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var CaptchaMerkleTree = class {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.leaves = [];
|
|
14
|
+
this.layers = [];
|
|
15
|
+
}
|
|
16
|
+
getRoot() {
|
|
17
|
+
if (this.root === void 0) throw new _prosopo_common.ProsopoError("DATASET.MERKLE_ERROR", { context: {
|
|
18
|
+
error: "root undefined",
|
|
19
|
+
failedFuncName: this.getRoot.name
|
|
20
|
+
} });
|
|
21
|
+
return this.root;
|
|
22
|
+
}
|
|
23
|
+
build(leaves) {
|
|
24
|
+
if (this.layers.length) this.layers = [];
|
|
25
|
+
const layerZero = [];
|
|
26
|
+
for (const leaf of leaves) {
|
|
27
|
+
const node = new MerkleNode(leaf);
|
|
28
|
+
this.leaves.push(node);
|
|
29
|
+
layerZero.push(node.hash);
|
|
30
|
+
}
|
|
31
|
+
this.layers.push(layerZero);
|
|
32
|
+
this.root = this.buildMerkleTree(this.leaves)[0];
|
|
33
|
+
}
|
|
34
|
+
buildMerkleTree(leaves) {
|
|
35
|
+
const numLeaves = leaves.length;
|
|
36
|
+
if (numLeaves === 1) return leaves;
|
|
37
|
+
const parents = [];
|
|
38
|
+
let leafIndex = 0;
|
|
39
|
+
const newLayer = [];
|
|
40
|
+
while (leafIndex < numLeaves) {
|
|
41
|
+
const leftChild = leaves[leafIndex];
|
|
42
|
+
if (leftChild === void 0) throw new _prosopo_common.ProsopoError("DEVELOPER.GENERAL", { context: { error: "leftChild undefined" } });
|
|
43
|
+
const rightChild = leafIndex + 1 < numLeaves ? (0, _prosopo_util.at)(leaves, leafIndex + 1) : leftChild;
|
|
44
|
+
const parentNode = this.createParent(leftChild, rightChild);
|
|
45
|
+
newLayer.push(parentNode.hash);
|
|
46
|
+
parents.push(parentNode);
|
|
47
|
+
leafIndex += 2;
|
|
48
|
+
}
|
|
49
|
+
this.layers.push(newLayer);
|
|
50
|
+
return this.buildMerkleTree(parents);
|
|
51
|
+
}
|
|
52
|
+
createParent(leftChild, rightChild) {
|
|
53
|
+
const parent = new MerkleNode((0, _prosopo_util_crypto.hexHashArray)([leftChild.hash, rightChild.hash]));
|
|
54
|
+
leftChild.parent = parent.hash;
|
|
55
|
+
rightChild.parent = parent.hash;
|
|
56
|
+
return parent;
|
|
57
|
+
}
|
|
58
|
+
proof(leafHash) {
|
|
59
|
+
const proofTree = [];
|
|
60
|
+
let layerNum = 0;
|
|
61
|
+
while (layerNum < this.layers.length - 1) {
|
|
62
|
+
const layer = this.layers[layerNum];
|
|
63
|
+
if (layer === void 0) throw new _prosopo_common.ProsopoError("DATASET.MERKLE_ERROR", { context: {
|
|
64
|
+
error: "layer undefined",
|
|
65
|
+
failedFuncName: this.proof.name,
|
|
66
|
+
layerNum
|
|
67
|
+
} });
|
|
68
|
+
const leafIndex = layer.indexOf(leafHash);
|
|
69
|
+
let partnerIndex = leafIndex % 2 && leafIndex > 0 ? leafIndex - 1 : leafIndex + 1;
|
|
70
|
+
if (partnerIndex > layer.length - 1) partnerIndex = leafIndex;
|
|
71
|
+
const pair = [leafHash];
|
|
72
|
+
const partner = (0, _prosopo_util.at)(layer, partnerIndex);
|
|
73
|
+
if (partnerIndex > leafIndex) pair.push(partner);
|
|
74
|
+
else pair.unshift(partner);
|
|
75
|
+
proofTree.push([(0, _prosopo_util.at)(pair, 0), (0, _prosopo_util.at)(pair, 1)]);
|
|
76
|
+
layerNum += 1;
|
|
77
|
+
leafHash = (0, _prosopo_util_crypto.hexHashArray)(pair);
|
|
78
|
+
}
|
|
79
|
+
const last = (0, _prosopo_util.at)(this.layers, this.layers.length - 1);
|
|
80
|
+
return [...proofTree, [(0, _prosopo_util.at)(last, 0)]];
|
|
81
|
+
}
|
|
82
|
+
};
|
|
107
83
|
function verifyProof(leaf, proof) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return false;
|
|
123
|
-
} catch (err) {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
84
|
+
try {
|
|
85
|
+
if ((0, _prosopo_util.at)(proof, 0).indexOf(leaf) === -1) return false;
|
|
86
|
+
for (const [layerIndex, layer] of proof.entries()) {
|
|
87
|
+
leaf = (0, _prosopo_util_crypto.hexHashArray)(layer);
|
|
88
|
+
if ((0, _prosopo_util.at)(proof, layerIndex + 1).indexOf(leaf) === -1) return false;
|
|
89
|
+
const last = (0, _prosopo_util.at)(proof, proof.length - 1);
|
|
90
|
+
if (leaf === (0, _prosopo_util.at)(last, 0)) return true;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
} catch (err) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
126
96
|
}
|
|
97
|
+
//#endregion
|
|
127
98
|
exports.CaptchaMerkleTree = CaptchaMerkleTree;
|
|
128
99
|
exports.verifyProof = verifyProof;
|
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const common = require("@prosopo/common");
|
|
1
|
+
let _prosopo_common = require("@prosopo/common");
|
|
2
|
+
//#region src/captcha/util.ts
|
|
4
3
|
async function downloadImage(url) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return new Uint8Array(buffer);
|
|
17
|
-
} catch (err) {
|
|
18
|
-
throw new common.ProsopoEnvError("DATABASE.IMAGE_GET_FAILED", {
|
|
19
|
-
context: { error: err }
|
|
20
|
-
});
|
|
21
|
-
}
|
|
4
|
+
try {
|
|
5
|
+
const response = await fetch(url);
|
|
6
|
+
if (!response.ok) throw new _prosopo_common.ProsopoDatasetError("API.BAD_REQUEST", { context: {
|
|
7
|
+
error: `Network response was not ok, status: ${response.status}`,
|
|
8
|
+
url
|
|
9
|
+
} });
|
|
10
|
+
const buffer = await response.arrayBuffer();
|
|
11
|
+
return new Uint8Array(buffer);
|
|
12
|
+
} catch (err) {
|
|
13
|
+
throw new _prosopo_common.ProsopoEnvError("DATABASE.IMAGE_GET_FAILED", { context: { error: err } });
|
|
14
|
+
}
|
|
22
15
|
}
|
|
16
|
+
//#endregion
|
|
23
17
|
exports.downloadImage = downloadImage;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
require("./captcha/
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
-
exports.
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
14
|
-
exports.
|
|
15
|
-
exports.
|
|
16
|
-
exports.
|
|
17
|
-
exports.
|
|
18
|
-
exports.
|
|
19
|
-
exports.
|
|
20
|
-
exports.
|
|
21
|
-
exports.
|
|
22
|
-
exports.
|
|
23
|
-
exports.
|
|
24
|
-
exports.
|
|
25
|
-
exports.
|
|
26
|
-
exports.
|
|
27
|
-
exports.
|
|
28
|
-
exports.
|
|
29
|
-
exports.
|
|
30
|
-
exports.
|
|
31
|
-
exports.validateDatasetContent = dataset.validateDatasetContent;
|
|
2
|
+
const require_util = require("./captcha/util.cjs");
|
|
3
|
+
const require_captcha = require("./captcha/captcha.cjs");
|
|
4
|
+
const require_merkle = require("./captcha/merkle.cjs");
|
|
5
|
+
const require_dataset = require("./captcha/dataset.cjs");
|
|
6
|
+
const require_captchas = require("./tests/mocks/data/captchas.cjs");
|
|
7
|
+
exports.CaptchaMerkleTree = require_merkle.CaptchaMerkleTree;
|
|
8
|
+
exports.NO_SOLUTION_VALUE = require_captcha.NO_SOLUTION_VALUE;
|
|
9
|
+
exports.addSolutionHashesToDataset = require_dataset.addSolutionHashesToDataset;
|
|
10
|
+
exports.buildCaptchaTree = require_dataset.buildCaptchaTree;
|
|
11
|
+
exports.buildDataset = require_dataset.buildDataset;
|
|
12
|
+
exports.captchaSort = require_captcha.captchaSort;
|
|
13
|
+
exports.compareCaptchaSolutions = require_captcha.compareCaptchaSolutions;
|
|
14
|
+
exports.computeCaptchaHash = require_captcha.computeCaptchaHash;
|
|
15
|
+
exports.computeCaptchaSolutionHash = require_captcha.computeCaptchaSolutionHash;
|
|
16
|
+
exports.computeItemHash = require_captcha.computeItemHash;
|
|
17
|
+
exports.computePendingRequestHash = require_captcha.computePendingRequestHash;
|
|
18
|
+
exports.datasetWithIndexSolutions = require_captchas.datasetWithIndexSolutions;
|
|
19
|
+
exports.datasetWithSolutionHashes = require_captchas.datasetWithSolutionHashes;
|
|
20
|
+
exports.downloadImage = require_util.downloadImage;
|
|
21
|
+
exports.getSolutionValueToHash = require_captcha.getSolutionValueToHash;
|
|
22
|
+
exports.hashDatasetItems = require_dataset.hashDatasetItems;
|
|
23
|
+
exports.matchItemsToSolutions = require_captcha.matchItemsToSolutions;
|
|
24
|
+
exports.parseAndSortCaptchaSolutions = require_captcha.parseAndSortCaptchaSolutions;
|
|
25
|
+
exports.parseCaptchaAssets = require_captcha.parseCaptchaAssets;
|
|
26
|
+
exports.parseCaptchaDataset = require_captcha.parseCaptchaDataset;
|
|
27
|
+
exports.sortAndComputeHashes = require_captcha.sortAndComputeHashes;
|
|
28
|
+
exports.validateDatasetContent = require_dataset.validateDatasetContent;
|
|
29
|
+
exports.verifyProof = require_merkle.verifyProof;
|