@prosopo/datasets 0.1.8

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.
Files changed (51) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.js +24 -0
  3. package/LICENSE +201 -0
  4. package/README.md +25 -0
  5. package/captchas.json +184 -0
  6. package/dist/js/captcha/captcha.d.ts +65 -0
  7. package/dist/js/captcha/captcha.d.ts.map +1 -0
  8. package/dist/js/captcha/captcha.js +194 -0
  9. package/dist/js/captcha/captcha.js.map +1 -0
  10. package/dist/js/captcha/dataset.d.ts +6 -0
  11. package/dist/js/captcha/dataset.d.ts.map +1 -0
  12. package/dist/js/captcha/dataset.js +46 -0
  13. package/dist/js/captcha/dataset.js.map +1 -0
  14. package/dist/js/captcha/index.d.ts +5 -0
  15. package/dist/js/captcha/index.d.ts.map +1 -0
  16. package/dist/js/captcha/index.js +23 -0
  17. package/dist/js/captcha/index.js.map +1 -0
  18. package/dist/js/captcha/merkle.d.ts +19 -0
  19. package/dist/js/captcha/merkle.d.ts.map +1 -0
  20. package/dist/js/captcha/merkle.js +119 -0
  21. package/dist/js/captcha/merkle.js.map +1 -0
  22. package/dist/js/captcha/util.d.ts +3 -0
  23. package/dist/js/captcha/util.d.ts.map +1 -0
  24. package/dist/js/captcha/util.js +26 -0
  25. package/dist/js/captcha/util.js.map +1 -0
  26. package/dist/js/index.d.ts +3 -0
  27. package/dist/js/index.d.ts.map +1 -0
  28. package/dist/js/index.js +21 -0
  29. package/dist/js/index.js.map +1 -0
  30. package/dist/js/types/assets.d.ts +8 -0
  31. package/dist/js/types/assets.d.ts.map +1 -0
  32. package/dist/js/types/assets.js +18 -0
  33. package/dist/js/types/assets.js.map +1 -0
  34. package/dist/js/types/captcha.d.ts +285 -0
  35. package/dist/js/types/captcha.d.ts.map +1 -0
  36. package/dist/js/types/captcha.js +67 -0
  37. package/dist/js/types/captcha.js.map +1 -0
  38. package/dist/js/types/dataset.d.ts +312 -0
  39. package/dist/js/types/dataset.d.ts.map +1 -0
  40. package/dist/js/types/dataset.js +28 -0
  41. package/dist/js/types/dataset.js.map +1 -0
  42. package/dist/js/types/index.d.ts +5 -0
  43. package/dist/js/types/index.d.ts.map +1 -0
  44. package/dist/js/types/index.js +8 -0
  45. package/dist/js/types/index.js.map +1 -0
  46. package/dist/js/types/merkle.d.ts +16 -0
  47. package/dist/js/types/merkle.d.ts.map +1 -0
  48. package/dist/js/types/merkle.js +24 -0
  49. package/dist/js/types/merkle.js.map +1 -0
  50. package/package.json +67 -0
  51. package/tsconfig.json +12 -0
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseCaptchaAssets = exports.computePendingRequestHash = exports.convertCaptchaToCaptchaSolution = exports.computeCaptchaSolutionHash = exports.matchItemsToSolutions = exports.calculateItemHashes = exports.computeCaptchaHash = exports.compareCaptchaSolutions = exports.sortAndComputeHashes = exports.parseCaptchaSolutions = exports.parseCaptchaDataset = void 0;
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
+ const index_1 = require("../types/index");
20
+ const util_1 = require("./util");
21
+ const contract_1 = require("@prosopo/contract");
22
+ // import {encodeAddress} from "@polkadot/util-crypto";
23
+ /**
24
+ * Parse a dataset
25
+ * @return {JSON} captcha dataset, stored in JSON
26
+ * @param datasetJSON
27
+ */
28
+ function parseCaptchaDataset(datasetJSON) {
29
+ try {
30
+ return index_1.DatasetSchema.parse(datasetJSON);
31
+ }
32
+ catch (err) {
33
+ throw new contract_1.ProsopoEnvError(err, "ERRORS.DATASET.PARSE_ERROR");
34
+ }
35
+ }
36
+ exports.parseCaptchaDataset = parseCaptchaDataset;
37
+ /**
38
+ * Make sure captcha solutions are in the correct format
39
+ * @param {JSON} captchaJSON captcha solutions received from the api
40
+ * @return {CaptchaSolution[]} an array of parsed captcha solutions
41
+ */
42
+ function parseCaptchaSolutions(captchaJSON) {
43
+ try {
44
+ return index_1.CaptchaSolutionSchema.parse(captchaJSON);
45
+ }
46
+ catch (err) {
47
+ throw new contract_1.ProsopoEnvError(err, "ERRORS.CAPTCHA.PARSE_ERROR");
48
+ }
49
+ }
50
+ exports.parseCaptchaSolutions = parseCaptchaSolutions;
51
+ function captchaSort(a, b) {
52
+ return a.captchaId.localeCompare(b.captchaId);
53
+ }
54
+ function sortAndComputeHashes(received, stored) {
55
+ received.sort(captchaSort);
56
+ stored.sort(captchaSort);
57
+ return stored.map(({ salt, items = [], target = "", captchaId, solved }, index) => {
58
+ if (captchaId != received[index].captchaId) {
59
+ throw new contract_1.ProsopoEnvError("CAPTCHA.ID_MISMATCH");
60
+ }
61
+ return {
62
+ hash: computeCaptchaHash({
63
+ solution: solved ? received[index].solution : [],
64
+ salt,
65
+ items,
66
+ target,
67
+ }, true, true, false),
68
+ captchaId,
69
+ };
70
+ });
71
+ }
72
+ exports.sortAndComputeHashes = sortAndComputeHashes;
73
+ /**
74
+ * Take an array of CaptchaSolutions and Captchas and check if the solutions are the same for each pair
75
+ * @param {CaptchaSolution[]} received
76
+ * @param {Captcha[]} stored
77
+ * @return {boolean}
78
+ */
79
+ function compareCaptchaSolutions(received, stored) {
80
+ if (received.length && stored.length && received.length === stored.length) {
81
+ const hashes = sortAndComputeHashes(received, stored);
82
+ return hashes.every(({ hash, captchaId }) => hash === captchaId);
83
+ }
84
+ return false;
85
+ }
86
+ exports.compareCaptchaSolutions = compareCaptchaSolutions;
87
+ /**
88
+ * Compute the hash of various types of captcha
89
+ * @param {Captcha} captcha
90
+ * @param {boolean} includeSolution
91
+ * @param {boolean} includeSalt
92
+ * @param {boolean} sortItemHashes
93
+ * @return {string} the hex string hash
94
+ */
95
+ function computeCaptchaHash(captcha, includeSolution = false, includeSalt = false, sortItemHashes) {
96
+ try {
97
+ const itemHashes = captcha.items.map((item, index) => item.hash ? item.hash : calculateItemHashes([item])[0].hash);
98
+ return (0, util_1.hexHash)([
99
+ captcha.target,
100
+ ...(includeSolution && captcha.solution ? captcha.solution.sort() : []),
101
+ includeSalt ? captcha.salt : '',
102
+ sortItemHashes ? itemHashes.sort() : itemHashes,
103
+ ].join());
104
+ }
105
+ catch (err) {
106
+ throw new contract_1.ProsopoEnvError(err);
107
+ }
108
+ }
109
+ exports.computeCaptchaHash = computeCaptchaHash;
110
+ function calculateItemHashes(items) {
111
+ return items.map((item) => {
112
+ if (item.type === "image" || item.type === "text") {
113
+ return Object.assign(Object.assign({}, item), { hash: (0, util_1.hexHash)((item.data)) });
114
+ }
115
+ else {
116
+ throw new contract_1.ProsopoEnvError("CAPTCHA.INVALID_ITEM_FORMAT");
117
+ }
118
+ });
119
+ }
120
+ exports.calculateItemHashes = calculateItemHashes;
121
+ function matchItemsToSolutions(solutions, items) {
122
+ return (solutions === null || solutions === void 0 ? void 0 : solutions.map((solution) => {
123
+ const hash = items === null || items === void 0 ? void 0 : items[solution].hash;
124
+ if (!hash) {
125
+ throw new contract_1.ProsopoEnvError("CAPTCHA.MISSING_ITEM_HASH");
126
+ }
127
+ return hash;
128
+ })) || [];
129
+ }
130
+ exports.matchItemsToSolutions = matchItemsToSolutions;
131
+ // export function hashSolutions<T>(solutions: T[]): T[] {
132
+ // try {
133
+ // return solutions?.map(({ solution, ...rest }: any) => ({
134
+ // ...rest,
135
+ // solution: hashSolutionRaw(solution),
136
+ // }));
137
+ // } catch (err) {
138
+ // console.error(err);
139
+ // // @ts-ignore
140
+ // return arg0;
141
+ // }
142
+ // }
143
+ /**
144
+ * Create a unique solution commitment
145
+ * @param {CaptchaSolution} captcha
146
+ * @return {string} the hex string hash
147
+ */
148
+ function computeCaptchaSolutionHash(captcha) {
149
+ return (0, util_1.hexHash)([captcha.captchaId, captcha.captchaContentId, [...captcha.solution].sort(), captcha.salt].join());
150
+ }
151
+ exports.computeCaptchaSolutionHash = computeCaptchaSolutionHash;
152
+ // /**
153
+ // * Compute hashes for an array of captchas
154
+ // * @param {Captcha[]} captchas
155
+ // * @return {Promise<CaptchaSolution[]>} captchasWithHashes
156
+ // */
157
+ // export async function computeCaptchaHashes(captchas: CaptchaWithoutId[]): Promise<CaptchaSolution[]> {
158
+ // const captchasWithHashes: CaptchaSolution[] = [];
159
+ // for (const captcha of captchas) {
160
+ // const captchaId = await computeCaptchaHash(captcha);
161
+ // const captchaWithId: Captcha = {captchaId, ...captcha};
162
+ // const captchaSol = convertCaptchaToCaptchaSolution(captchaWithId);
163
+ // captchasWithHashes.push(captchaSol);
164
+ // }
165
+ // return captchasWithHashes;
166
+ // }
167
+ /**
168
+ * Map a Captcha to a Captcha solution (drop items, target, etc.)
169
+ * @param {Captcha} captcha
170
+ * @return {CaptchaSolution}
171
+ */
172
+ function convertCaptchaToCaptchaSolution(captcha) {
173
+ return { captchaId: captcha.captchaId, captchaContentId: captcha.captchaContentId, salt: captcha.salt, solution: captcha.solution || [] };
174
+ }
175
+ exports.convertCaptchaToCaptchaSolution = convertCaptchaToCaptchaSolution;
176
+ /**
177
+ * Compute hash for an array of captcha ids, userAccount, and salt, which serves as the identifier for a pending request
178
+ * @param {string[]} captchaIds
179
+ * @param {string} userAccount
180
+ * @param {string} salt
181
+ * @return {string}
182
+ */
183
+ function computePendingRequestHash(captchaIds, userAccount, salt) {
184
+ return (0, util_1.hexHash)([...captchaIds.sort(), userAccount, salt].join());
185
+ }
186
+ exports.computePendingRequestHash = computePendingRequestHash;
187
+ /**
188
+ * Parse the image items in a captcha and pass back a URI if they exist
189
+ */
190
+ function parseCaptchaAssets(item, assetsResolver) {
191
+ return Object.assign(Object.assign({}, item), { path: (assetsResolver === null || assetsResolver === void 0 ? void 0 : assetsResolver.resolveAsset(item.data).getURL()) || item.data });
192
+ }
193
+ exports.parseCaptchaAssets = parseCaptchaAssets;
194
+ //# sourceMappingURL=captcha.js.map
@@ -0,0 +1 @@
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,0CAWwB;AACxB,iCAA+B;AAC/B,gDAAkD;AAElD,uDAAuD;AAIvD;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,WAAiB;IACjD,IAAI;QACA,OAAO,qBAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;KAC3C;IAAC,OAAO,GAAG,EAAE;QACV,MAAM,IAAI,0BAAe,CAAC,GAAG,EAAE,4BAA4B,CAAC,CAAC;KAChE;AACL,CAAC;AAND,kDAMC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,WAAiB;IACnD,IAAI;QACA,OAAO,6BAAqB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;KACnD;IAAC,OAAO,GAAG,EAAE;QACV,MAAM,IAAI,0BAAe,CAAC,GAAG,EAAE,4BAA4B,CAAC,CAAC;KAChE;AACL,CAAC;AAND,sDAMC;AAED,SAAS,WAAW,CAAkC,CAAI,EAAE,CAAI;IAC5D,OAAO,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAClD,CAAC;AAED,SAAgB,oBAAoB,CAChC,QAA2B,EAC3B,MAAiB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;AACH,SAAgB,yBAAyB,CAAC,UAAoB,EAAE,WAAmB,EAAE,IAAY;IAC7F,OAAO,IAAA,cAAO,EAAC,CAAC,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AACrE,CAAC;AAFD,8DAEC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,IAAU,EAAE,cAA0C;IACrF,uCAAW,IAAI,KAAE,IAAI,EAAE,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAI,IAAI,CAAC,IAAI,IAAC;AACzF,CAAC;AAFD,gDAEC"}
@@ -0,0 +1,6 @@
1
+ import { Dataset, DatasetRaw } from "../types/dataset";
2
+ import { CaptchaMerkleTree } from "./merkle";
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataset.d.ts","sourceRoot":"","sources":["../../../src/js/captcha/dataset.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,OAAO,EACP,UAAU,EACb,MAAM,kBAAkB,CAAC;AAS1B,OAAO,EAAC,iBAAiB,EAAC,MAAM,UAAU,CAAA;AAG1C,wBAAsB,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAY3E;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAS5J;AAED,wBAAsB,uCAAuC,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAatG"}
@@ -0,0 +1,46 @@
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 captcha_1 = require("./captcha");
6
+ const merkle_1 = require("./merkle");
7
+ const contract_1 = require("@prosopo/contract");
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) => (Object.assign(Object.assign({}, captcha), { captchaId: solutionTree.leaves[index].hash, captchaContentId: contentTree.leaves[index].hash })));
15
+ dataset.solutionTree = solutionTree.layers;
16
+ dataset.contentTree = contentTree.layers;
17
+ dataset.datasetId = (_a = solutionTree.root) === null || _a === void 0 ? void 0 : _a.hash;
18
+ dataset.datasetContentId = (_b = contentTree.root) === null || _b === void 0 ? void 0 : _b.hash;
19
+ return dataset;
20
+ });
21
+ }
22
+ exports.buildDataset = buildDataset;
23
+ function buildCaptchaTree(dataset, includeSolution, includeSalt, sortItemHashes) {
24
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
25
+ try {
26
+ const tree = new merkle_1.CaptchaMerkleTree();
27
+ const captchaHashes = dataset.captchas.map((captcha) => (0, captcha_1.computeCaptchaHash)(captcha, includeSolution, includeSalt, sortItemHashes));
28
+ tree.build(captchaHashes);
29
+ return tree;
30
+ }
31
+ catch (err) {
32
+ throw new contract_1.ProsopoEnvError("DATASET.HASH_ERROR");
33
+ }
34
+ });
35
+ }
36
+ exports.buildCaptchaTree = buildCaptchaTree;
37
+ function addItemHashesAndSolutionHashesToDataset(datasetRaw) {
38
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
39
+ return Object.assign(Object.assign({}, datasetRaw), { captchas: datasetRaw.captchas.map((captcha) => {
40
+ const items = (0, captcha_1.calculateItemHashes)(captcha.items);
41
+ return Object.assign(Object.assign({}, captcha), { items, solution: (0, captcha_1.matchItemsToSolutions)(captcha.solution, items) });
42
+ }) });
43
+ });
44
+ }
45
+ exports.addItemHashesAndSolutionHashesToDataset = addItemHashesAndSolutionHashesToDataset;
46
+ //# sourceMappingURL=dataset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataset.js","sourceRoot":"","sources":["../../../src/js/captcha/dataset.ts"],"names":[],"mappings":";;;;AAOA,uCAIkB;AAClB,qCAA0C;AAC1C,gDAAiD;AAEjD,SAAsB,YAAY,CAAC,UAAsB;;;QACrD,MAAM,OAAO,GAAG,MAAM,uCAAuC,CAAC,UAAU,CAAC,CAAC;QAC1E,MAAM,WAAW,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACxE,MAAM,YAAY,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QACxE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,CACxD,gCAAI,OAAO,KAAE,SAAS,EAAE,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,GAC5G,CAAA,CAAC,CAAC;QACH,OAAO,CAAC,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC;QAC3C,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC;QACzC,OAAO,CAAC,SAAS,GAAG,MAAA,YAAY,CAAC,IAAI,0CAAE,IAAI,CAAC;QAC5C,OAAO,CAAC,gBAAgB,GAAG,MAAA,WAAW,CAAC,IAAI,0CAAE,IAAI,CAAC;QAClD,OAAO,OAAO,CAAA;;CACjB;AAZD,oCAYC;AAED,SAAsB,gBAAgB,CAAC,OAAgB,EAAE,eAAwB,EAAE,WAAoB,EAAE,cAAuB;;QAC5H,IAAI;YACA,MAAM,IAAI,GAAG,IAAI,0BAAiB,EAAE,CAAC;YACrC,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAA,4BAAkB,EAAC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC;YACnI,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YAC1B,OAAO,IAAI,CAAA;SACd;QAAC,OAAO,GAAG,EAAE;YACV,MAAM,IAAI,0BAAe,CAAC,oBAAoB,CAAC,CAAC;SACnD;IACL,CAAC;CAAA;AATD,4CASC;AAED,SAAsB,uCAAuC,CAAC,UAAsB;;QAChF,OAAO,gCACA,UAAU,KACb,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;gBAC1C,MAAM,KAAK,GAAG,IAAA,6BAAmB,EAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAEjD,uCACO,OAAO,KACV,KAAK,EACL,QAAQ,EAAE,IAAA,+BAAqB,EAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,IAC1D;YACN,CAAC,CAAC,GACM,CAAA;IAChB,CAAC;CAAA;AAbD,0FAaC"}
@@ -0,0 +1,5 @@
1
+ export * from './captcha';
2
+ export * from './merkle';
3
+ export * from './util';
4
+ export * from './dataset';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,23 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,19 @@
1
+ import { MerkleNodeInterface } from '../types/merkle';
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: string[][];
10
+ root: MerkleNode | undefined;
11
+ constructor();
12
+ build(leaves: string[]): void;
13
+ buildMerkleTree(leaves: any): any;
14
+ createParent(leftChild: any, rightChild: any): MerkleNode;
15
+ proof(leafHash: string): string[][];
16
+ }
17
+ export declare function verifyProof(leaf: string, proof: string[][]): boolean;
18
+ export {};
19
+ //# sourceMappingURL=merkle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merkle.d.ts","sourceRoot":"","sources":["../../../src/js/captcha/merkle.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAErD,cAAM,UAAW,YAAW,mBAAmB;IAC3C,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;gBAET,IAAI,KAAA;CAIpB;AAED,qBAAa,iBAAiB;IAC1B,MAAM,EAAE,UAAU,EAAE,CAAA;IAEpB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAA;IAElB,IAAI,EAAE,UAAU,GAAG,SAAS,CAAA;;IAO5B,KAAK,CAAE,MAAM,EAAE,MAAM,EAAE;IAevB,eAAe,CAAE,MAAM,KAAA;IAyBvB,YAAY,CAAE,SAAS,KAAA,EAAE,UAAU,KAAA,GAAG,UAAU;IAOhD,KAAK,CAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE;CAyBvC;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,OAAO,CAkBpE"}
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyProof = exports.CaptchaMerkleTree = void 0;
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
+ const util_1 = require("./util");
20
+ class MerkleNode {
21
+ constructor(hash) {
22
+ this.hash = hash;
23
+ this.parent = null;
24
+ }
25
+ }
26
+ class CaptchaMerkleTree {
27
+ constructor() {
28
+ this.leaves = [];
29
+ this.layers = [];
30
+ }
31
+ build(leaves) {
32
+ // allow rebuild
33
+ if (this.layers.length) {
34
+ this.layers = [];
35
+ }
36
+ const layerZero = [];
37
+ for (const leaf of leaves) {
38
+ const node = new MerkleNode(leaf);
39
+ this.leaves.push(node);
40
+ layerZero.push(node.hash);
41
+ }
42
+ this.layers.push(layerZero);
43
+ this.root = this.buildMerkleTree(this.leaves);
44
+ }
45
+ buildMerkleTree(leaves) {
46
+ // Builds the Merkle tree from a list of leaves. In case of an odd number of leaves, the last leaf is duplicated.
47
+ const numLeaves = leaves.length;
48
+ if (numLeaves === 1) {
49
+ return leaves[0];
50
+ }
51
+ const parents = [];
52
+ let leafIndex = 0;
53
+ const newLayer = [];
54
+ while (leafIndex < numLeaves) {
55
+ const leftChild = leaves[leafIndex];
56
+ const rightChild = (leafIndex + 1 < numLeaves) ? leaves[leafIndex + 1] : leftChild;
57
+ const parentNode = this.createParent(leftChild, rightChild);
58
+ newLayer.push(parentNode.hash);
59
+ parents.push(parentNode);
60
+ leafIndex += 2;
61
+ }
62
+ this.layers.push(newLayer);
63
+ return this.buildMerkleTree(parents);
64
+ }
65
+ createParent(leftChild, rightChild) {
66
+ const parent = new MerkleNode((0, util_1.hexHash)([leftChild.hash, rightChild.hash].join()));
67
+ leftChild.parent = parent;
68
+ rightChild.parent = parent;
69
+ return parent;
70
+ }
71
+ proof(leafHash) {
72
+ const proofTree = [];
73
+ let layerNum = 0;
74
+ while (layerNum < this.layers.length) {
75
+ const leafIndex = this.layers[layerNum].indexOf(leafHash);
76
+ // if layer 0 leaf index is 3, it should be partnered with 2: [L0,L1],[L2,L3],[L3,L4],...
77
+ // layer one pairs looks like [L0L1, L2L3], [L3L4, L5L6],...etc
78
+ const partnerIndex = (leafIndex % 2 && leafIndex > 0) ? leafIndex - 1 : leafIndex + 1;
79
+ const pair = [leafHash];
80
+ const layer = this.layers[layerNum];
81
+ if (partnerIndex < layer.length) {
82
+ // determine whether the leaf sits on the left or the right of its partner
83
+ if (partnerIndex > leafIndex) {
84
+ pair.push(layer[partnerIndex]);
85
+ }
86
+ else {
87
+ pair.unshift(layer[partnerIndex]);
88
+ }
89
+ }
90
+ proofTree.push(pair);
91
+ layerNum += 1;
92
+ leafHash = (0, util_1.hexHash)(pair.join());
93
+ }
94
+ return proofTree;
95
+ }
96
+ }
97
+ exports.CaptchaMerkleTree = CaptchaMerkleTree;
98
+ function verifyProof(leaf, proof) {
99
+ try {
100
+ if (proof[0].indexOf(leaf) === -1) {
101
+ return false;
102
+ }
103
+ for (const [layerIndex, layer] of proof.entries()) {
104
+ leaf = (0, util_1.hexHash)(layer.join());
105
+ if (proof[layerIndex + 1].indexOf(leaf) === -1) {
106
+ return false;
107
+ }
108
+ if (leaf === proof[proof.length - 1][0]) {
109
+ return true;
110
+ }
111
+ }
112
+ return false;
113
+ }
114
+ catch (err) {
115
+ return false;
116
+ }
117
+ }
118
+ exports.verifyProof = verifyProof;
119
+ //# sourceMappingURL=merkle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merkle.js","sourceRoot":"","sources":["../../../src/js/captcha/merkle.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AAC5C,uEAAuE;AACvE,EAAE;AACF,mEAAmE;AACnE,uEAAuE;AAC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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"}
@@ -0,0 +1,3 @@
1
+ export declare const HEX_HASH_BIT_LENGTH = 256;
2
+ export declare function hexHash(data: string | Uint8Array, bitLength?: 256 | 512 | 64 | 128 | 384 | undefined): string;
3
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/js/captcha/util.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC,wBAAgB,OAAO,CAAE,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,SAAS,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,SAAS,GAAI,MAAM,CAG/G"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hexHash = exports.HEX_HASH_BIT_LENGTH = void 0;
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
+ const util_crypto_1 = require("@polkadot/util-crypto");
20
+ exports.HEX_HASH_BIT_LENGTH = 256;
21
+ function hexHash(data, bitLength) {
22
+ // default bit length is 256
23
+ return (0, util_crypto_1.blake2AsHex)(data, bitLength);
24
+ }
25
+ exports.hexHash = hexHash;
26
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
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,uDAAoD;AAEvC,QAAA,mBAAmB,GAAG,GAAG,CAAC;AAEvC,SAAgB,OAAO,CAAE,IAAyB,EAAE,SAAkD;IAClG,4BAA4B;IAC5B,OAAO,IAAA,yBAAW,EAAC,IAAI,EAAE,SAAS,CAAC,CAAA;AACvC,CAAC;AAHD,0BAGC"}
@@ -0,0 +1,3 @@
1
+ export * from './captcha/index';
2
+ export * from './types/index';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/js/index.ts"],"names":[],"mappings":"AAeA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA"}
@@ -0,0 +1,21 @@
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
+ tslib_1.__exportStar(require("./types/index"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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;AAC/B,wDAA6B"}
@@ -0,0 +1,8 @@
1
+ export interface Asset {
2
+ URI: string;
3
+ getURL(): string;
4
+ }
5
+ export interface AssetsResolver {
6
+ resolveAsset(assetURI: string): Asset;
7
+ }
8
+ //# sourceMappingURL=assets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../../../src/js/types/assets.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,KAAK;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,IAAI,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC3B,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAI,KAAK,CAAC;CAC1C"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ // Copyright (C) 2021-2022 Prosopo (UK) Ltd.
3
+ // This file is part of provider <https://github.com/prosopo/provider>.
4
+ //
5
+ // provider is free software: you can redistribute it and/or modify
6
+ // it under the terms of the GNU General Public License as published by
7
+ // the Free Software Foundation, either version 3 of the License, or
8
+ // (at your option) any later version.
9
+ //
10
+ // provider is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU General Public License for more details.
14
+ //
15
+ // You should have received a copy of the GNU General Public License
16
+ // along with provider. If not, see <http://www.gnu.org/licenses/>.
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ //# sourceMappingURL=assets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets.js","sourceRoot":"","sources":["../../../src/js/types/assets.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"}