@prosopo/procaptcha 0.2.13 → 0.2.14
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/api/ExtensionWeb2.d.ts.map +1 -1
- package/dist/api/ExtensionWeb2.js +9 -8
- package/dist/api/ExtensionWeb2.js.map +1 -1
- package/dist/api/sign.js +2 -2
- package/dist/api/sign.js.map +1 -1
- package/dist/cjs/api/ExtensionWeb2.cjs +17 -16
- package/dist/cjs/modules/Manager.cjs +213 -212
- package/dist/cjs/modules/ProsopoCaptchaApi.cjs +10 -12
- package/dist/modules/Manager.d.ts.map +1 -1
- package/dist/modules/Manager.js +252 -267
- package/dist/modules/Manager.js.map +1 -1
- package/dist/modules/ProsopoCaptchaApi.d.ts +1 -1
- package/dist/modules/ProsopoCaptchaApi.d.ts.map +1 -1
- package/dist/modules/ProsopoCaptchaApi.js +1 -1
- package/dist/modules/ProsopoCaptchaApi.js.map +1 -1
- package/package.json +7 -7
- package/dist/cjs/contracts/captcha/dist/build-extrinsic/captcha.cjs +0 -339
- package/dist/cjs/contracts/captcha/dist/contract-info/captcha.cjs +0 -6
- package/dist/cjs/contracts/captcha/dist/contracts/captcha.cjs +0 -79
- package/dist/cjs/contracts/captcha/dist/data/captcha.json.cjs +0 -3374
- package/dist/cjs/contracts/captcha/dist/event-data/captcha.json.cjs +0 -3
- package/dist/cjs/contracts/captcha/dist/events/captcha.cjs +0 -23
- package/dist/cjs/contracts/captcha/dist/index.cjs +0 -44
- package/dist/cjs/contracts/captcha/dist/mixed-methods/captcha.cjs +0 -470
- package/dist/cjs/contracts/captcha/dist/query/captcha.cjs +0 -468
- package/dist/cjs/contracts/captcha/dist/shared/utils.cjs +0 -31
- package/dist/cjs/contracts/captcha/dist/tx-sign-and-send/captcha.cjs +0 -426
- package/dist/cjs/contracts/captcha/dist/types-arguments/captcha.cjs +0 -62
- package/dist/cjs/packages/datasets/dist/captcha/captcha.cjs +0 -143
- package/dist/cjs/packages/datasets/dist/captcha/dataset.cjs +0 -87
- package/dist/cjs/packages/datasets/dist/captcha/index.cjs +0 -27
- package/dist/cjs/packages/datasets/dist/captcha/merkle.cjs +0 -106
- package/dist/cjs/packages/datasets/dist/captcha/util.cjs +0 -16
- package/dist/cjs/packages/datasets/dist/index.cjs +0 -2
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const merkle = require("./merkle.cjs");
|
|
4
|
-
const common = require("@prosopo/common");
|
|
5
|
-
const util = require("@prosopo/util");
|
|
6
|
-
const captcha = require("./captcha.cjs");
|
|
7
|
-
const logger = common.getLogger(`Info`, `dataset.ts`);
|
|
8
|
-
async function hashDatasetItems(datasetRaw) {
|
|
9
|
-
return datasetRaw.captchas.map(async (captcha$1) => {
|
|
10
|
-
const items = await Promise.all(captcha$1.items.map(async (item) => captcha.computeItemHash(item)));
|
|
11
|
-
return {
|
|
12
|
-
...captcha$1,
|
|
13
|
-
items
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
async function validateDatasetContent(datasetOriginal) {
|
|
18
|
-
const captchaPromises = await hashDatasetItems(datasetOriginal);
|
|
19
|
-
const captchas = await Promise.all(captchaPromises);
|
|
20
|
-
const dataset = {
|
|
21
|
-
...datasetOriginal,
|
|
22
|
-
captchas
|
|
23
|
-
};
|
|
24
|
-
const hashes = dataset.captchas.map((captcha2) => {
|
|
25
|
-
const captchaRaw = datasetOriginal.captchas.find((captchaRaw2) => "captchaId" in captchaRaw2 ? captchaRaw2.captchaId === captcha2.captchaId : false);
|
|
26
|
-
if (captchaRaw) {
|
|
27
|
-
return captcha2.items.every((item, index) => item.hash === util.at(captchaRaw.items, index).hash);
|
|
28
|
-
} else {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
return hashes.every((hash) => hash);
|
|
33
|
-
}
|
|
34
|
-
async function buildDataset(datasetRaw) {
|
|
35
|
-
var _a, _b;
|
|
36
|
-
logger.info(`Adding solution hashes to dataset`);
|
|
37
|
-
const dataset = await addSolutionHashesToDataset(datasetRaw);
|
|
38
|
-
logger.info(`Building dataset merkle trees`);
|
|
39
|
-
const contentTree = await buildCaptchaTree(dataset, false, false, true);
|
|
40
|
-
const solutionTree = await buildCaptchaTree(dataset, true, true, false);
|
|
41
|
-
dataset.captchas = dataset.captchas.map((captcha2, index) => {
|
|
42
|
-
var _a2, _b2;
|
|
43
|
-
return {
|
|
44
|
-
...captcha2,
|
|
45
|
-
captchaId: util.at(solutionTree.leaves, index).hash,
|
|
46
|
-
captchaContentId: util.at(contentTree.leaves, index).hash,
|
|
47
|
-
datasetId: (_a2 = solutionTree.root) == null ? void 0 : _a2.hash,
|
|
48
|
-
datasetContentId: (_b2 = contentTree.root) == null ? void 0 : _b2.hash
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
dataset.solutionTree = solutionTree.layers;
|
|
52
|
-
dataset.contentTree = contentTree.layers;
|
|
53
|
-
dataset.datasetId = (_a = solutionTree.root) == null ? void 0 : _a.hash;
|
|
54
|
-
dataset.datasetContentId = (_b = contentTree.root) == null ? void 0 : _b.hash;
|
|
55
|
-
return dataset;
|
|
56
|
-
}
|
|
57
|
-
async function buildCaptchaTree(dataset, includeSolution, includeSalt, sortItemHashes) {
|
|
58
|
-
try {
|
|
59
|
-
const tree = new merkle.CaptchaMerkleTree();
|
|
60
|
-
const datasetWithItemHashes = { ...dataset };
|
|
61
|
-
const captchaHashes = datasetWithItemHashes.captchas.map((captcha$1) => captcha.computeCaptchaHash(captcha$1, includeSolution, includeSalt, sortItemHashes));
|
|
62
|
-
tree.build(captchaHashes);
|
|
63
|
-
return tree;
|
|
64
|
-
} catch (err) {
|
|
65
|
-
throw new common.ProsopoEnvError("DATASET.HASH_ERROR");
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
async function addSolutionHashesToDataset(datasetRaw) {
|
|
69
|
-
const captchaPromises = datasetRaw.captchas.map(async (captcha$1) => {
|
|
70
|
-
return {
|
|
71
|
-
...captcha$1,
|
|
72
|
-
items: captcha$1.items,
|
|
73
|
-
// some captcha challenges will not have a solution
|
|
74
|
-
...captcha$1.solution !== void 0 && { solution: captcha.matchItemsToSolutions(captcha$1.solution, captcha$1.items) }
|
|
75
|
-
};
|
|
76
|
-
});
|
|
77
|
-
const captchas = await Promise.all(captchaPromises);
|
|
78
|
-
return {
|
|
79
|
-
...datasetRaw,
|
|
80
|
-
captchas
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
exports.addSolutionHashesToDataset = addSolutionHashesToDataset;
|
|
84
|
-
exports.buildCaptchaTree = buildCaptchaTree;
|
|
85
|
-
exports.buildDataset = buildDataset;
|
|
86
|
-
exports.hashDatasetItems = hashDatasetItems;
|
|
87
|
-
exports.validateDatasetContent = validateDatasetContent;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const captcha = require("./captcha.cjs");
|
|
4
|
-
const merkle = require("./merkle.cjs");
|
|
5
|
-
const util = require("./util.cjs");
|
|
6
|
-
const dataset = require("./dataset.cjs");
|
|
7
|
-
exports.NO_SOLUTION_VALUE = captcha.NO_SOLUTION_VALUE;
|
|
8
|
-
exports.captchaSort = captcha.captchaSort;
|
|
9
|
-
exports.compareCaptchaSolutions = captcha.compareCaptchaSolutions;
|
|
10
|
-
exports.computeCaptchaHash = captcha.computeCaptchaHash;
|
|
11
|
-
exports.computeCaptchaSolutionHash = captcha.computeCaptchaSolutionHash;
|
|
12
|
-
exports.computeItemHash = captcha.computeItemHash;
|
|
13
|
-
exports.computePendingRequestHash = captcha.computePendingRequestHash;
|
|
14
|
-
exports.getSolutionValueToHash = captcha.getSolutionValueToHash;
|
|
15
|
-
exports.matchItemsToSolutions = captcha.matchItemsToSolutions;
|
|
16
|
-
exports.parseAndSortCaptchaSolutions = captcha.parseAndSortCaptchaSolutions;
|
|
17
|
-
exports.parseCaptchaAssets = captcha.parseCaptchaAssets;
|
|
18
|
-
exports.parseCaptchaDataset = captcha.parseCaptchaDataset;
|
|
19
|
-
exports.sortAndComputeHashes = captcha.sortAndComputeHashes;
|
|
20
|
-
exports.CaptchaMerkleTree = merkle.CaptchaMerkleTree;
|
|
21
|
-
exports.verifyProof = merkle.verifyProof;
|
|
22
|
-
exports.downloadImage = util.downloadImage;
|
|
23
|
-
exports.addSolutionHashesToDataset = dataset.addSolutionHashesToDataset;
|
|
24
|
-
exports.buildCaptchaTree = dataset.buildCaptchaTree;
|
|
25
|
-
exports.buildDataset = dataset.buildDataset;
|
|
26
|
-
exports.hashDatasetItems = dataset.hashDatasetItems;
|
|
27
|
-
exports.validateDatasetContent = dataset.validateDatasetContent;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const util = require("@prosopo/util");
|
|
4
|
-
const common = 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
|
-
if (this.layers.length) {
|
|
18
|
-
this.layers = [];
|
|
19
|
-
}
|
|
20
|
-
const layerZero = [];
|
|
21
|
-
for (const leaf of leaves) {
|
|
22
|
-
const node = new MerkleNode(leaf);
|
|
23
|
-
this.leaves.push(node);
|
|
24
|
-
layerZero.push(node.hash);
|
|
25
|
-
}
|
|
26
|
-
this.layers.push(layerZero);
|
|
27
|
-
this.root = this.buildMerkleTree(this.leaves)[0];
|
|
28
|
-
}
|
|
29
|
-
buildMerkleTree(leaves) {
|
|
30
|
-
const numLeaves = leaves.length;
|
|
31
|
-
if (numLeaves === 1) {
|
|
32
|
-
return leaves;
|
|
33
|
-
}
|
|
34
|
-
const parents = [];
|
|
35
|
-
let leafIndex = 0;
|
|
36
|
-
const newLayer = [];
|
|
37
|
-
while (leafIndex < numLeaves) {
|
|
38
|
-
const leftChild = leaves[leafIndex];
|
|
39
|
-
if (leftChild === void 0) {
|
|
40
|
-
throw new Error("leftChild undefined");
|
|
41
|
-
}
|
|
42
|
-
const rightChild = leafIndex + 1 < numLeaves ? util.at(leaves, leafIndex + 1) : leftChild;
|
|
43
|
-
const parentNode = this.createParent(leftChild, rightChild);
|
|
44
|
-
newLayer.push(parentNode.hash);
|
|
45
|
-
parents.push(parentNode);
|
|
46
|
-
leafIndex += 2;
|
|
47
|
-
}
|
|
48
|
-
this.layers.push(newLayer);
|
|
49
|
-
return this.buildMerkleTree(parents);
|
|
50
|
-
}
|
|
51
|
-
createParent(leftChild, rightChild) {
|
|
52
|
-
const parent = new MerkleNode(common.hexHashArray([leftChild.hash, rightChild.hash]));
|
|
53
|
-
leftChild.parent = parent.hash;
|
|
54
|
-
rightChild.parent = parent.hash;
|
|
55
|
-
return parent;
|
|
56
|
-
}
|
|
57
|
-
proof(leafHash) {
|
|
58
|
-
const proofTree = [];
|
|
59
|
-
let layerNum = 0;
|
|
60
|
-
while (layerNum < this.layers.length - 1) {
|
|
61
|
-
const layer = this.layers[layerNum];
|
|
62
|
-
if (layer === void 0) {
|
|
63
|
-
throw new Error("layer undefined");
|
|
64
|
-
}
|
|
65
|
-
const leafIndex = layer.indexOf(leafHash);
|
|
66
|
-
let partnerIndex = leafIndex % 2 && leafIndex > 0 ? leafIndex - 1 : leafIndex + 1;
|
|
67
|
-
if (partnerIndex > layer.length - 1) {
|
|
68
|
-
partnerIndex = leafIndex;
|
|
69
|
-
}
|
|
70
|
-
const pair = [leafHash];
|
|
71
|
-
const partner = util.at(layer, partnerIndex);
|
|
72
|
-
if (partnerIndex > leafIndex) {
|
|
73
|
-
pair.push(partner);
|
|
74
|
-
} else {
|
|
75
|
-
pair.unshift(partner);
|
|
76
|
-
}
|
|
77
|
-
proofTree.push([util.at(pair, 0), util.at(pair, 1)]);
|
|
78
|
-
layerNum += 1;
|
|
79
|
-
leafHash = common.hexHashArray(pair);
|
|
80
|
-
}
|
|
81
|
-
const last = util.at(this.layers, this.layers.length - 1);
|
|
82
|
-
return [...proofTree, [util.at(last, 0)]];
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
function verifyProof(leaf, proof) {
|
|
86
|
-
try {
|
|
87
|
-
if (util.at(proof, 0).indexOf(leaf) === -1) {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
for (const [layerIndex, layer] of proof.entries()) {
|
|
91
|
-
leaf = common.hexHashArray(layer);
|
|
92
|
-
if (util.at(proof, layerIndex + 1).indexOf(leaf) === -1) {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
const last = util.at(proof, proof.length - 1);
|
|
96
|
-
if (leaf === util.at(last, 0)) {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
} catch (err) {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
exports.CaptchaMerkleTree = CaptchaMerkleTree;
|
|
106
|
-
exports.verifyProof = verifyProof;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const common = require("@prosopo/common");
|
|
4
|
-
async function downloadImage(url) {
|
|
5
|
-
try {
|
|
6
|
-
const response = await fetch(url);
|
|
7
|
-
if (!response.ok) {
|
|
8
|
-
throw new Error(`Network response was not ok, status: ${response.status}`);
|
|
9
|
-
}
|
|
10
|
-
const buffer = await response.arrayBuffer();
|
|
11
|
-
return new Uint8Array(buffer);
|
|
12
|
-
} catch (error) {
|
|
13
|
-
throw new common.ProsopoEnvError(error);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.downloadImage = downloadImage;
|