@prosopo/procaptcha 0.1.16 → 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.
Files changed (89) hide show
  1. package/package.json +64 -50
  2. package/dist/api/Extension.d.ts +0 -16
  3. package/dist/api/Extension.d.ts.map +0 -1
  4. package/dist/api/Extension.js +0 -9
  5. package/dist/api/Extension.js.map +0 -1
  6. package/dist/api/ExtensionWeb2.d.ts +0 -13
  7. package/dist/api/ExtensionWeb2.d.ts.map +0 -1
  8. package/dist/api/ExtensionWeb2.js +0 -101
  9. package/dist/api/ExtensionWeb2.js.map +0 -1
  10. package/dist/api/ExtensionWeb3.d.ts +0 -10
  11. package/dist/api/ExtensionWeb3.d.ts.map +0 -1
  12. package/dist/api/ExtensionWeb3.js +0 -33
  13. package/dist/api/ExtensionWeb3.js.map +0 -1
  14. package/dist/api/HttpClientBase.d.ts +0 -9
  15. package/dist/api/HttpClientBase.d.ts.map +0 -1
  16. package/dist/api/HttpClientBase.js +0 -36
  17. package/dist/api/HttpClientBase.js.map +0 -1
  18. package/dist/api/errors.d.ts +0 -16
  19. package/dist/api/errors.d.ts.map +0 -1
  20. package/dist/api/errors.js +0 -34
  21. package/dist/api/errors.js.map +0 -1
  22. package/dist/api/handlers.d.ts +0 -5
  23. package/dist/api/handlers.d.ts.map +0 -1
  24. package/dist/api/handlers.js +0 -13
  25. package/dist/api/handlers.js.map +0 -1
  26. package/dist/api/index.d.ts +0 -4
  27. package/dist/api/index.d.ts.map +0 -1
  28. package/dist/api/index.js +0 -22
  29. package/dist/api/index.js.map +0 -1
  30. package/dist/api/sign.d.ts +0 -5
  31. package/dist/api/sign.d.ts.map +0 -1
  32. package/dist/api/sign.js +0 -16
  33. package/dist/api/sign.js.map +0 -1
  34. package/dist/index.d.ts +0 -5
  35. package/dist/index.d.ts.map +0 -1
  36. package/dist/index.js +0 -23
  37. package/dist/index.js.map +0 -1
  38. package/dist/modules/Manager.d.ts +0 -22
  39. package/dist/modules/Manager.d.ts.map +0 -1
  40. package/dist/modules/Manager.js +0 -419
  41. package/dist/modules/Manager.js.map +0 -1
  42. package/dist/modules/ProsopoCaptchaApi.d.ts +0 -21
  43. package/dist/modules/ProsopoCaptchaApi.d.ts.map +0 -1
  44. package/dist/modules/ProsopoCaptchaApi.js +0 -120
  45. package/dist/modules/ProsopoCaptchaApi.js.map +0 -1
  46. package/dist/modules/canvas.d.ts +0 -2
  47. package/dist/modules/canvas.d.ts.map +0 -1
  48. package/dist/modules/canvas.js +0 -349
  49. package/dist/modules/canvas.js.map +0 -1
  50. package/dist/modules/index.d.ts +0 -3
  51. package/dist/modules/index.d.ts.map +0 -1
  52. package/dist/modules/index.js +0 -21
  53. package/dist/modules/index.js.map +0 -1
  54. package/dist/modules/storage.d.ts +0 -24
  55. package/dist/modules/storage.d.ts.map +0 -1
  56. package/dist/modules/storage.js +0 -50
  57. package/dist/modules/storage.js.map +0 -1
  58. package/dist/types/api.d.ts +0 -35
  59. package/dist/types/api.d.ts.map +0 -1
  60. package/dist/types/api.js +0 -22
  61. package/dist/types/api.js.map +0 -1
  62. package/dist/types/client.d.ts +0 -5
  63. package/dist/types/client.d.ts.map +0 -1
  64. package/dist/types/client.js +0 -3
  65. package/dist/types/client.js.map +0 -1
  66. package/dist/types/contract.d.ts +0 -5
  67. package/dist/types/contract.d.ts.map +0 -1
  68. package/dist/types/contract.js +0 -3
  69. package/dist/types/contract.js.map +0 -1
  70. package/dist/types/index.d.ts +0 -5
  71. package/dist/types/index.d.ts.map +0 -1
  72. package/dist/types/index.js +0 -23
  73. package/dist/types/index.js.map +0 -1
  74. package/dist/types/manager.d.ts +0 -60
  75. package/dist/types/manager.d.ts.map +0 -1
  76. package/dist/types/manager.js +0 -3
  77. package/dist/types/manager.js.map +0 -1
  78. package/dist/types/utils.d.ts +0 -2
  79. package/dist/types/utils.d.ts.map +0 -1
  80. package/dist/types/utils.js +0 -3
  81. package/dist/types/utils.js.map +0 -1
  82. package/dist/utils/index.d.ts +0 -2
  83. package/dist/utils/index.d.ts.map +0 -1
  84. package/dist/utils/index.js +0 -5
  85. package/dist/utils/index.js.map +0 -1
  86. package/dist/utils/utils.d.ts +0 -2
  87. package/dist/utils/utils.d.ts.map +0 -1
  88. package/dist/utils/utils.js +0 -8
  89. package/dist/utils/utils.js.map +0 -1
@@ -1,419 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Manager = exports.getNetwork = exports.defaultState = void 0;
4
- const tslib_1 = require("tslib");
5
- const api_1 = require("@polkadot/api");
6
- const api_2 = require("@prosopo/api");
7
- const contract_1 = require("@prosopo/contract");
8
- const rpc_provider_1 = require("@polkadot/rpc-provider");
9
- const util_crypto_1 = require("@polkadot/util-crypto");
10
- const utils_1 = require("../utils/utils");
11
- const util_1 = require("@polkadot/util");
12
- const common_1 = require("@prosopo/common");
13
- const ExtensionWeb2_1 = tslib_1.__importDefault(require("../api/ExtensionWeb2"));
14
- const ExtensionWeb3_1 = tslib_1.__importDefault(require("../api/ExtensionWeb3"));
15
- const ProsopoCaptchaApi_1 = tslib_1.__importDefault(require("./ProsopoCaptchaApi"));
16
- const storage_1 = tslib_1.__importDefault(require("./storage"));
17
- const defaultState = () => {
18
- return {
19
- // note order matters! see buildUpdateState. These fields are set in order, so disable modal first, then set loading to false, etc.
20
- showModal: false,
21
- loading: false,
22
- challenge: undefined,
23
- solutions: [],
24
- index: -1,
25
- isHuman: false,
26
- captchaApi: undefined,
27
- account: undefined,
28
- // don't handle timeout here, this should be handled by the state management
29
- };
30
- };
31
- exports.defaultState = defaultState;
32
- const buildUpdateState = (state, onStateUpdate) => {
33
- const updateCurrentState = (nextState) => {
34
- // mutate the current state. Note that this is in order of properties in the nextState object.
35
- // e.g. given {b: 2, c: 3, a: 1}, b will be set, then c, then a. This is because JS stores fields in insertion order by default, unless you override it with a class or such by changing the key enumeration order.
36
- for (const key in nextState) {
37
- state[key] = nextState[key];
38
- }
39
- // then call the update function for the frontend to do the same
40
- onStateUpdate(nextState);
41
- console.log('Procaptcha state update:', nextState, '\nResult:', state);
42
- };
43
- return updateCurrentState;
44
- };
45
- const getNetwork = (config) => {
46
- const network = config.networks[config.defaultEnvironment];
47
- if (!network) {
48
- throw new Error(`No network found for environment ${config.defaultEnvironment}`);
49
- }
50
- return network;
51
- };
52
- exports.getNetwork = getNetwork;
53
- /**
54
- * The state operator. This is used to mutate the state of Procaptcha during the captcha process. State updates are published via the onStateUpdate callback. This should be used by frontends, e.g. react, to maintain the state of Procaptcha across renders.
55
- */
56
- const Manager = (configOptional, state, onStateUpdate, callbacks) => {
57
- // events are emitted at various points during the captcha process. These each have default behaviours below which can be overridden by the frontend using callbacks.
58
- const events = Object.assign({
59
- onAccountNotFound: (address) => {
60
- alert(`Account ${address} not found`);
61
- },
62
- onError: (error) => {
63
- alert(`${error?.message ?? 'An unexpected error occurred'}, please try again`);
64
- },
65
- onHuman: (output) => {
66
- console.log('onHuman event triggered', output);
67
- },
68
- onExtensionNotFound: () => {
69
- alert('No extension found');
70
- },
71
- onExpired: () => {
72
- alert('Challenge has expired, please try again');
73
- },
74
- onFailed: () => {
75
- alert('Captcha challenge failed. Please try again');
76
- },
77
- }, callbacks);
78
- // mapping of type of error to relevant event callback
79
- const errorToEventMap = {
80
- AccountNotFoundError: events.onAccountNotFound,
81
- ExtensionNotFoundError: events.onExtensionNotFound,
82
- Error: events.onError,
83
- ExpiredError: events.onExpired,
84
- };
85
- // get the state update mechanism
86
- const updateState = buildUpdateState(state, onStateUpdate);
87
- /**
88
- * Build the config on demand, using the optional config passed in from the outside. State may override various config values depending on the state of the captcha process. E.g. if the process has been started using account "ABC" and then the user changes account to "DEF" via the optional config prop, the account in use will not change. This is because the captcha process has already been started using account "ABC".
89
- * @returns the config for procaptcha
90
- */
91
- const getConfig = () => {
92
- const config = {
93
- userAccountAddress: '',
94
- ...configOptional,
95
- };
96
- // overwrite the account in use with the one in state if it exists. Reduces likelihood of bugs where the user changes account in the middle of the captcha process.
97
- if (state.account) {
98
- config.userAccountAddress = state.account.account.address;
99
- }
100
- return config;
101
- };
102
- /**
103
- * Called on start of user verification. This is when the user ticks the box to claim they are human.
104
- */
105
- const start = async () => {
106
- console.log('Starting procaptcha');
107
- try {
108
- if (state.loading) {
109
- console.log('Procaptcha already loading');
110
- return;
111
- }
112
- if (state.isHuman) {
113
- console.log('already human');
114
- return;
115
- }
116
- resetState();
117
- // set the loading flag to true (allow UI to show some sort of loading / pending indicator while we get the captcha process going)
118
- updateState({ loading: true });
119
- // snapshot the config into the state
120
- const config = getConfig();
121
- updateState({ dappAccount: config.account.address });
122
- // allow UI to catch up with the loading state
123
- await (0, utils_1.sleep)(100);
124
- // check accounts / setup accounts
125
- const account = await loadAccount();
126
- // account has been found, check if account is already marked as human
127
- // first, ask the smart contract
128
- const contract = await loadContract();
129
- // We don't need to show CAPTCHA challenges if the user is determined as human by the contract
130
- let contractIsHuman = false;
131
- try {
132
- contractIsHuman = (await contract.query.dappOperatorIsHumanUser(account.account.address, config.solutionThreshold)).value
133
- .unwrap()
134
- .unwrap();
135
- }
136
- catch (error) {
137
- console.warn(error);
138
- }
139
- if (contractIsHuman) {
140
- updateState({ isHuman: true, loading: false });
141
- events.onHuman({
142
- user: account.account.address,
143
- dapp: config.account.address,
144
- });
145
- return;
146
- }
147
- // Check if there is a provider in local storage or get a random one from the contract
148
- const providerUrlFromStorage = storage_1.default.getProviderUrl();
149
- let providerApi;
150
- if (providerUrlFromStorage) {
151
- providerApi = await loadProviderApi(providerUrlFromStorage);
152
- // if the provider was already in storage, the user may have already solved some captchas but they have not been put on chain yet
153
- // so contact the provider to check if this is the case
154
- try {
155
- const verifyDappUserResponse = await providerApi.verifyDappUser(account.account.address);
156
- if (verifyDappUserResponse.solutionApproved) {
157
- updateState({ isHuman: true, loading: false });
158
- events.onHuman({
159
- providerUrl: providerUrlFromStorage,
160
- user: account.account.address,
161
- dapp: config.account.address,
162
- commitmentId: verifyDappUserResponse.commitmentId,
163
- });
164
- return;
165
- }
166
- }
167
- catch (err) {
168
- // if the provider is down, we should continue with the process of selecting a random provider
169
- console.error('Error contacting provider from storage', providerUrlFromStorage);
170
- // continue as if the provider was not in storage
171
- }
172
- }
173
- const payload = {
174
- address: account.account.address,
175
- data: (0, util_1.stringToU8a)('message'),
176
- type: 'bytes',
177
- };
178
- const signed = await account.extension.signer.signRaw(payload);
179
- console.log('Signature:', signed);
180
- // get a random provider
181
- const getRandomProviderResponse = await (0, contract_1.wrapQuery)(contract.query.getRandomActiveProvider, contract.query)(account.account.address, config.account.address);
182
- const blockNumber = getRandomProviderResponse.blockNumber;
183
- console.log('provider', getRandomProviderResponse);
184
- const providerUrl = (0, common_1.trimProviderUrl)(getRandomProviderResponse.provider.url.toString());
185
- // get the provider api inst
186
- providerApi = await loadProviderApi(providerUrl);
187
- console.log('providerApi', providerApi);
188
- // get the captcha challenge and begin the challenge
189
- const captchaApi = await loadCaptchaApi(contract, getRandomProviderResponse, providerApi);
190
- console.log('captchaApi', captchaApi);
191
- const challenge = await captchaApi.getCaptchaChallenge();
192
- console.log('challenge', challenge);
193
- if (challenge.captchas.length <= 0) {
194
- throw new Error('No captchas returned from provider');
195
- }
196
- // setup timeout
197
- const timeMillis = challenge.captchas
198
- .map((captcha) => captcha.captcha.timeLimitMs || 30 * 1000)
199
- .reduce((a, b) => a + b);
200
- const timeout = setTimeout(() => {
201
- console.log('challenge expired after ' + timeMillis + 'ms');
202
- events.onExpired();
203
- // expired, disallow user's claim to be human
204
- updateState({ isHuman: false, showModal: false, loading: false });
205
- }, timeMillis);
206
- // update state with new challenge
207
- updateState({
208
- index: 0,
209
- solutions: challenge.captchas.map(() => []),
210
- challenge,
211
- showModal: true,
212
- timeout,
213
- blockNumber,
214
- });
215
- }
216
- catch (err) {
217
- console.error(err);
218
- // dispatch relevant error event
219
- const event = errorToEventMap[err.constructor] || events.onError;
220
- event(err);
221
- // hit an error, disallow user's claim to be human
222
- updateState({ isHuman: false, showModal: false, loading: false });
223
- }
224
- };
225
- const submit = async () => {
226
- try {
227
- console.log('submitting solutions');
228
- // disable the time limit, user has submitted their solution in time
229
- clearTimeout();
230
- if (!state.challenge) {
231
- throw new Error('cannot submit, no challenge found');
232
- }
233
- // hide the modal, no further input required from user
234
- updateState({ showModal: false });
235
- const challenge = state.challenge;
236
- const salt = (0, util_crypto_1.randomAsHex)();
237
- // append solution to each captcha in the challenge
238
- const captchaSolution = state.challenge.captchas.map((captcha, index) => {
239
- const solution = state.solutions[index];
240
- return {
241
- captchaId: captcha.captcha.captchaId,
242
- captchaContentId: captcha.captcha.captchaContentId,
243
- salt,
244
- solution,
245
- };
246
- });
247
- const account = getAccount();
248
- const blockNumber = getBlockNumber();
249
- const signer = account.extension.signer;
250
- if (!challenge.captchas[0].captcha.datasetId) {
251
- throw new Error('No datasetId set for challenge');
252
- }
253
- const captchaApi = getCaptchaApi();
254
- // send the commitment to the provider
255
- const submission = await captchaApi.submitCaptchaSolution(signer, challenge.requestHash, challenge.captchas[0].captcha.datasetId, captchaSolution, salt);
256
- // mark as is human if solution has been approved
257
- const isHuman = submission[0].solutionApproved;
258
- if (!isHuman) {
259
- // user failed the captcha for some reason according to the provider
260
- events.onFailed();
261
- }
262
- // update the state with the result of the submission
263
- updateState({
264
- submission,
265
- isHuman,
266
- loading: false,
267
- });
268
- if (state.isHuman) {
269
- events.onHuman({
270
- providerUrl: (0, common_1.trimProviderUrl)(captchaApi.provider.provider.url.toString()),
271
- user: account.account.address,
272
- dapp: getDappAccount(),
273
- commitmentId: submission[1],
274
- blockNumber,
275
- });
276
- }
277
- }
278
- catch (err) {
279
- // dispatch relevant error event
280
- const event = errorToEventMap[err.constructor] || events.onError;
281
- event(err);
282
- // hit an error, disallow user's claim to be human
283
- updateState({ isHuman: false, showModal: false, loading: false });
284
- }
285
- };
286
- const cancel = async () => {
287
- console.log('cancel');
288
- // disable the time limit
289
- clearTimeout();
290
- // abandon the captcha process
291
- resetState();
292
- };
293
- /**
294
- * (De)Select an image from the solution for the current round. If the hash is already in the solutions list, it will be removed (deselected) and if not it will be added (selected).
295
- * @param hash the hash of the image
296
- */
297
- const select = (hash) => {
298
- if (!state.challenge) {
299
- throw new Error('cannot select, no challenge found');
300
- }
301
- if (state.index >= state.challenge.captchas.length || state.index < 0) {
302
- throw new Error('cannot select, round index out of range');
303
- }
304
- const index = state.index;
305
- const solutions = state.solutions;
306
- const solution = solutions[index];
307
- if (solution.includes(hash)) {
308
- console.log('deselecting', hash);
309
- // remove the hash from the solution
310
- solution.splice(solution.indexOf(hash), 1);
311
- }
312
- else {
313
- console.log('selecting', hash);
314
- // add the hash to the solution
315
- solution.push(hash);
316
- }
317
- updateState({ solutions });
318
- };
319
- /**
320
- * Proceed to the next round of the challenge.
321
- */
322
- const nextRound = () => {
323
- if (!state.challenge) {
324
- throw new Error('cannot proceed to next round, no challenge found');
325
- }
326
- if (state.index + 1 >= state.challenge.captchas.length) {
327
- throw new Error('cannot proceed to next round, already at last round');
328
- }
329
- console.log('proceeding to next round');
330
- updateState({ index: state.index + 1 });
331
- };
332
- const loadCaptchaApi = async (contract, provider, providerApi) => {
333
- const config = getConfig();
334
- // setup the captcha api to carry out a challenge
335
- const captchaApi = new ProsopoCaptchaApi_1.default(getAccount().account.address, contract, provider, providerApi, config.web2, config.account.address);
336
- updateState({ captchaApi });
337
- return getCaptchaApi();
338
- };
339
- const loadProviderApi = async (providerUrl) => {
340
- const config = getConfig();
341
- const network = (0, exports.getNetwork)(config);
342
- return new api_2.ProviderApi(network, providerUrl, config.account.address);
343
- };
344
- const clearTimeout = () => {
345
- // clear the timeout
346
- window.clearTimeout(state.timeout);
347
- // then clear the timeout from the state
348
- updateState({ timeout: undefined });
349
- };
350
- const resetState = () => {
351
- // clear timeout just in case a timer is still active (shouldn't be)
352
- clearTimeout();
353
- updateState((0, exports.defaultState)());
354
- };
355
- const getCaptchaApi = () => {
356
- if (!state.captchaApi) {
357
- throw new Error('Captcha api not set');
358
- }
359
- return state.captchaApi;
360
- };
361
- /**
362
- * Load the account using address specified in config, or generate new address if not found in local storage for web2 mode.
363
- */
364
- const loadAccount = async () => {
365
- const config = getConfig();
366
- // check if account has been provided in config (doesn't matter in web2 mode)
367
- if (!config.web2 && !config.userAccountAddress) {
368
- throw new Error('Account address has not been set for web3 mode');
369
- }
370
- // check if account exists in extension
371
- const ext = config.web2 ? new ExtensionWeb2_1.default() : new ExtensionWeb3_1.default();
372
- const account = await ext.getAccount(config);
373
- console.log('Using account:', account);
374
- updateState({ account });
375
- return getAccount();
376
- };
377
- const getAccount = () => {
378
- if (!state.account) {
379
- throw new Error('Account not loaded');
380
- }
381
- const account = state.account;
382
- return account;
383
- };
384
- const getDappAccount = () => {
385
- if (!state.dappAccount) {
386
- throw new Error('Dapp account not loaded');
387
- }
388
- const dappAccount = state.dappAccount;
389
- return dappAccount;
390
- };
391
- const getBlockNumber = () => {
392
- if (!state.blockNumber) {
393
- throw new Error('Account not loaded');
394
- }
395
- const blockNumber = state.blockNumber;
396
- return blockNumber;
397
- };
398
- /**
399
- * Load the contract instance using addresses from config.
400
- */
401
- const loadContract = async () => {
402
- const config = getConfig();
403
- const network = (0, exports.getNetwork)(config);
404
- const api = await api_1.ApiPromise.create({ provider: new rpc_provider_1.WsProvider(network.endpoint) });
405
- // TODO create a shared keyring that's stored somewhere
406
- const type = 'sr25519';
407
- const keyring = new api_1.Keyring({ type, ss58Format: api.registry.chainSS58 });
408
- return new contract_1.ProsopoCaptchaContract(api, contract_1.abiJson, network.contract.address, keyring.addFromAddress(getAccount().account.address), 'prosopo', 0);
409
- };
410
- return {
411
- start,
412
- cancel,
413
- submit,
414
- select,
415
- nextRound,
416
- };
417
- };
418
- exports.Manager = Manager;
419
- //# sourceMappingURL=Manager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Manager.js","sourceRoot":"","sources":["../../src/modules/Manager.ts"],"names":[],"mappings":";;;;AAQA,uCAAmD;AAQnD,sCAA8D;AAC9D,gDAA8E;AAG9E,yDAAmD;AACnD,uDA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AO,WAAW,CAAA;IACtB,CAAC,CAAA;IAED;;OAEG;IACH,MAAM,YAAY,GAAG,KAAK,IAAqC,EAAE;QAC7D,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;QAC1B,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,MAAM,CAAC,CAAA;QAClC,MAAM,GAAG,GAAG,MAAM,gBAAU,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,yBAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QACnF,uDAAuD;QACvD,MAAM,IAAI,GAAG,SAAS,CAAA;QACtB,MAAM,OAAO,GAAG,IAAI,aAAO,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAA;QACzE,OAAO,IAAI,iCAAsB,CAC7B,GAAG,EACH,kBAAsB,EACtB,OAAO,CAAC,QAAQ,CAAC,OAAO,EACxB,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EACpD,SAAS,EACT,CAAC,CACJ,CAAA;IACL,CAAC,CAAA;IAED,OAAO;QACH,KAAK;QACL,MAAM;QACN,MAAM;QACN,MAAM;QACN,SAAS;KACZ,CAAA;AACL,CAAC,CAAA;AAzbY,QAAA,OAAO,WAybnB"}
@@ -1,21 +0,0 @@
1
- import { CaptchaSolution } from '@prosopo/types';
2
- import { GetCaptchaResponse } from '../types/api';
3
- import { ProsopoCaptchaContract } from '@prosopo/contract';
4
- import { ProviderApi } from '@prosopo/api';
5
- import { RandomProvider } from '@prosopo/types';
6
- import { Signer } from '@polkadot/api/types';
7
- import { TCaptchaSubmitResult } from '../types/client';
8
- export declare class ProsopoCaptchaApi {
9
- userAccount: string;
10
- contract: ProsopoCaptchaContract;
11
- provider: RandomProvider;
12
- providerApi: ProviderApi;
13
- dappAccount: string;
14
- private web2;
15
- constructor(userAccount: string, contract: ProsopoCaptchaContract, provider: RandomProvider, providerApi: ProviderApi, web2: boolean, dappAccount: string);
16
- getCaptchaChallenge(): Promise<GetCaptchaResponse>;
17
- verifyCaptchaChallengeContent(provider: RandomProvider, captchaChallenge: GetCaptchaResponse): void;
18
- submitCaptchaSolution(signer: Signer, requestHash: string, datasetId: string, solutions: CaptchaSolution[], salt: string): Promise<TCaptchaSubmitResult>;
19
- }
20
- export default ProsopoCaptchaApi;
21
- //# sourceMappingURL=ProsopoCaptchaApi.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ProsopoCaptchaApi.d.ts","sourceRoot":"","sources":["../../src/modules/ProsopoCaptchaApi.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,eAAe,EAAoB,MAAM,gBAAgB,CAAA;AAClE,OAAO,EAA2B,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAG1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAGtD,qBAAa,iBAAiB;IAC1B,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,sBAAsB,CAAA;IAChC,QAAQ,EAAE,cAAc,CAAA;IACxB,WAAW,EAAE,WAAW,CAAA;IACxB,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,IAAI,CAAS;gBAGjB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,sBAAsB,EAChC,QAAQ,EAAE,cAAc,EACxB,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,MAAM;IAUV,mBAAmB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAUxD,6BAA6B,CAAC,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,GAAG,IAAI;IAuB7F,qBAAqB,CAC9B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,eAAe,EAAE,EAC5B,IAAI,EAAE,MAAM,GACb,OAAO,CAAC,oBAAoB,CAAC;CA0CnC;AA4BD,eAAe,iBAAiB,CAAA"}
@@ -1,120 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProsopoCaptchaApi = void 0;
4
- // Copyright (C) 2021-2022 Prosopo (UK) Ltd.
5
- // This file is part of procaptcha <https://github.com/prosopo/procaptcha>.
6
- //
7
- // procaptcha 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
- // procaptcha 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 procaptcha. If not, see <http://www.gnu.org/licenses/>.
19
- const datasets_1 = require("@prosopo/datasets");
20
- const handlers_1 = require("../api/handlers");
21
- const common_1 = require("@prosopo/common");
22
- const util_1 = require("@polkadot/util");
23
- class ProsopoCaptchaApi {
24
- userAccount;
25
- contract;
26
- provider;
27
- providerApi;
28
- dappAccount;
29
- web2;
30
- constructor(userAccount, contract, provider, providerApi, web2, dappAccount) {
31
- this.userAccount = userAccount;
32
- this.contract = contract;
33
- this.provider = provider;
34
- this.providerApi = providerApi;
35
- this.web2 = web2;
36
- this.dappAccount = dappAccount;
37
- }
38
- async getCaptchaChallenge() {
39
- try {
40
- const captchaChallenge = await this.providerApi.getCaptchaChallenge(this.userAccount, this.provider);
41
- this.verifyCaptchaChallengeContent(this.provider, captchaChallenge);
42
- return captchaChallenge;
43
- }
44
- catch (e) {
45
- throw new common_1.ProsopoEnvError(e);
46
- }
47
- }
48
- verifyCaptchaChallengeContent(provider, captchaChallenge) {
49
- // TODO make sure root is equal to root on the provider
50
- const proofLength = captchaChallenge.captchas[0].proof.length;
51
- console.log(provider.provider);
52
- if (provider.provider.datasetIdContent.toString() !== captchaChallenge.captchas[0].proof[proofLength - 1][0]) {
53
- throw new common_1.ProsopoEnvError('CAPTCHA.INVALID_DATASET_CONTENT_ID');
54
- }
55
- for (const captchaWithProof of captchaChallenge.captchas) {
56
- //TODO calculate the captchaId from the captcha content
57
- if (!verifyCaptchaData(captchaWithProof)) {
58
- throw new common_1.ProsopoEnvError('CAPTCHA.INVALID_CAPTCHA_CHALLENGE');
59
- }
60
- if (!(0, datasets_1.verifyProof)(captchaWithProof.captcha.captchaContentId, captchaWithProof.proof)) {
61
- throw new common_1.ProsopoEnvError('CAPTCHA.INVALID_CAPTCHA_CHALLENGE');
62
- }
63
- }
64
- console.log('CAPTCHA.CHALLENGE_VERIFIED');
65
- return;
66
- }
67
- async submitCaptchaSolution(signer, requestHash, datasetId, solutions, salt) {
68
- const tree = new datasets_1.CaptchaMerkleTree();
69
- const captchasHashed = solutions.map((captcha) => (0, datasets_1.computeCaptchaSolutionHash)(captcha));
70
- tree.build(captchasHashed);
71
- const commitmentId = tree.root.hash;
72
- console.log('solveCaptchaChallenge commitmentId', commitmentId);
73
- const tx = undefined;
74
- let signature = undefined;
75
- if (this.web2) {
76
- if (!signer || !signer.signRaw) {
77
- throw new Error('Signer is not defined, cannot sign message to prove account ownership');
78
- }
79
- // sign the request hash to prove account ownership
80
- const signed = await signer.signRaw({
81
- address: this.userAccount,
82
- data: (0, util_1.stringToHex)(requestHash),
83
- type: 'bytes',
84
- });
85
- signature = signed.signature;
86
- }
87
- let result;
88
- try {
89
- result = await this.providerApi.submitCaptchaSolution(solutions, requestHash, this.contract.pair.address, salt, signature);
90
- }
91
- catch (err) {
92
- throw new handlers_1.ProsopoApiError(err);
93
- }
94
- return [result, commitmentId, tx];
95
- }
96
- }
97
- exports.ProsopoCaptchaApi = ProsopoCaptchaApi;
98
- /**
99
- * Verify the captcha data by hashing the images and checking the hashes correspond to the hashes passed in the captcha
100
- * Verify the captcha content id is present in the first layer of the proof
101
- * @param {CaptchaWithProof} captchaWithProof
102
- * @returns {boolean}
103
- */
104
- async function verifyCaptchaData(captchaWithProof) {
105
- const captcha = captchaWithProof.captcha;
106
- const proof = captchaWithProof.proof;
107
- // Check that all the item hashes are equal to the provided item hashes in the captcha
108
- if (!(await Promise.all(captcha.items.map(async (item) => (await (0, datasets_1.computeItemHash)(item)).hash === item.hash))).every((hash) => hash === true)) {
109
- return false;
110
- }
111
- // Check that the computed captcha content id is equal to the provided captcha content id
112
- const captchaHash = (0, datasets_1.computeCaptchaHash)(captcha, false, false, false);
113
- if (captchaHash !== captcha.captchaContentId) {
114
- return false;
115
- }
116
- // Check that the captcha content id is present in the first layer of the proof
117
- return proof[0].indexOf(captchaHash) !== -1;
118
- }
119
- exports.default = ProsopoCaptchaApi;
120
- //# sourceMappingURL=ProsopoCaptchaApi.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ProsopoCaptchaApi.js","sourceRoot":"","sources":["../../src/modules/ProsopoCaptchaApi.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AAC5C,2EAA2E;AAC3E,EAAE;AACF,qEAAqE;AACrE,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,gEAAgE;AAChE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,sEAAsE;AACtE,gDAM0B;AAI1B,8CAAiD;AAEjD,4CAAiD;AAKjD,yCAA4C;AAE5C,MAAa,iBAAiB;IAC1B,WAAW,CAAQ;IACnB,QAAQ,CAAwB;IAChC,QAAQ,CAAgB;IACxB,WAAW,CAAa;IACxB,WAAW,CAAQ;IACX,IAAI,CAAS;IAErB,YACI,WAAmB,EACnB,QAAgC,EAChC,QAAwB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BAAiB,CAAA"}
@@ -1,2 +0,0 @@
1
- export declare function picassoCanvas(roundNumber: any, seed: any, params: any): string;
2
- //# sourceMappingURL=canvas.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../../src/modules/canvas.ts"],"names":[],"mappings":"AA2MA,wBAAgB,aAAa,CAAC,WAAW,KAAA,EAAE,IAAI,KAAA,EAAE,MAAM,KAAA,UA4MtD"}