@prosopo/procaptcha 0.1.17 → 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 +63 -60
  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 -6
  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 -97
  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 -29
  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 -29
  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 -39
  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 -9
  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 -17
  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 -25
  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 -18
  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 -421
  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 -114
  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 -358
  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 -16
  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 -46
  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 -21
  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 -2
  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 -2
  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 -18
  73. package/dist/types/index.js.map +0 -1
  74. package/dist/types/manager.d.ts +0 -62
  75. package/dist/types/manager.d.ts.map +0 -1
  76. package/dist/types/manager.js +0 -9
  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 -2
  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 -15
  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 -17
  89. package/dist/utils/utils.js.map +0 -1
@@ -1,421 +0,0 @@
1
- import { ApiPromise, Keyring } from '@polkadot/api';
2
- import { ProviderApi } from '@prosopo/api';
3
- import { ProsopoCaptchaContract, abiJson, wrapQuery } from '@prosopo/contract';
4
- import { WsProvider } from '@polkadot/rpc-provider';
5
- import { randomAsHex } from '@polkadot/util-crypto';
6
- import { sleep } from '../utils/utils.js';
7
- import { stringToU8a } from '@polkadot/util';
8
- import { trimProviderUrl } from '@prosopo/common';
9
- import ExtensionWeb2 from '../api/ExtensionWeb2.js';
10
- import ExtensionWeb3 from '../api/ExtensionWeb3.js';
11
- import ProsopoCaptchaApi from './ProsopoCaptchaApi.js';
12
- import storage from './storage.js';
13
- export const defaultState = () => {
14
- return {
15
- // note order matters! see buildUpdateState. These fields are set in order, so disable modal first, then set loading to false, etc.
16
- showModal: false,
17
- loading: false,
18
- challenge: undefined,
19
- solutions: [],
20
- index: -1,
21
- isHuman: false,
22
- captchaApi: undefined,
23
- account: undefined,
24
- // don't handle timeout here, this should be handled by the state management
25
- };
26
- };
27
- const buildUpdateState = (state, onStateUpdate) => {
28
- const updateCurrentState = (nextState) => {
29
- // mutate the current state. Note that this is in order of properties in the nextState object.
30
- // 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.
31
- for (const key in nextState) {
32
- state[key] = nextState[key];
33
- }
34
- // then call the update function for the frontend to do the same
35
- onStateUpdate(nextState);
36
- console.log('Procaptcha state update:', nextState, '\nResult:', state);
37
- };
38
- return updateCurrentState;
39
- };
40
- export const getNetwork = (config) => {
41
- const network = config.networks[config.defaultEnvironment];
42
- if (!network) {
43
- throw new Error(`No network found for environment ${config.defaultEnvironment}`);
44
- }
45
- return network;
46
- };
47
- /**
48
- * 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.
49
- */
50
- export function Manager(configOptional, state, onStateUpdate, callbacks) {
51
- // 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.
52
- const events = Object.assign({
53
- onAccountNotFound: (address) => {
54
- alert(`Account ${address} not found`);
55
- },
56
- onError: (error) => {
57
- alert(`${error?.message ?? 'An unexpected error occurred'}, please try again`);
58
- },
59
- onHuman: (output) => {
60
- console.log('onHuman event triggered', output);
61
- },
62
- onExtensionNotFound: () => {
63
- alert('No extension found');
64
- },
65
- onExpired: () => {
66
- alert('Challenge has expired, please try again');
67
- },
68
- onFailed: () => {
69
- alert('Captcha challenge failed. Please try again');
70
- },
71
- }, callbacks);
72
- // mapping of type of error to relevant event callback
73
- const errorToEventMap = {
74
- AccountNotFoundError: events.onAccountNotFound,
75
- ExtensionNotFoundError: events.onExtensionNotFound,
76
- Error: events.onError,
77
- ExpiredError: events.onExpired,
78
- };
79
- // get the state update mechanism
80
- const updateState = buildUpdateState(state, onStateUpdate);
81
- /**
82
- * Build the config on demand, using the optional config passed in from the outside. State may override various
83
- * config values depending on the state of the captcha process. E.g. if the process has been started using account
84
- * "ABC" and then the user changes account to "DEF" via the optional config prop, the account in use will not change.
85
- * This is because the captcha process has already been started using account "ABC".
86
- * @returns the config for procaptcha
87
- */
88
- const getConfig = () => {
89
- const config = {
90
- userAccountAddress: '',
91
- ...configOptional,
92
- };
93
- // overwrite the account in use with the one in state if it exists. Reduces likelihood of bugs where the user
94
- // changes account in the middle of the captcha process.
95
- if (state.account) {
96
- config.userAccountAddress = state.account.account.address;
97
- }
98
- return config;
99
- };
100
- /**
101
- * Called on start of user verification. This is when the user ticks the box to claim they are human.
102
- */
103
- const start = async () => {
104
- console.log('Starting procaptcha');
105
- try {
106
- if (state.loading) {
107
- console.log('Procaptcha already loading');
108
- return;
109
- }
110
- if (state.isHuman) {
111
- console.log('already human');
112
- return;
113
- }
114
- resetState();
115
- // set the loading flag to true (allow UI to show some sort of loading / pending indicator while we get the captcha process going)
116
- updateState({ loading: true });
117
- // snapshot the config into the state
118
- const config = getConfig();
119
- updateState({ dappAccount: config.account.address });
120
- // allow UI to catch up with the loading state
121
- await sleep(100);
122
- // check accounts / setup accounts
123
- const account = await loadAccount();
124
- // account has been found, check if account is already marked as human
125
- // first, ask the smart contract
126
- const contract = await loadContract();
127
- // We don't need to show CAPTCHA challenges if the user is determined as human by the contract
128
- let contractIsHuman = false;
129
- try {
130
- contractIsHuman = (await contract.query.dappOperatorIsHumanUser(account.account.address, config.solutionThreshold)).value
131
- .unwrap()
132
- .unwrap();
133
- }
134
- catch (error) {
135
- console.warn(error);
136
- }
137
- if (contractIsHuman) {
138
- updateState({ isHuman: true, loading: false });
139
- events.onHuman({
140
- user: account.account.address,
141
- dapp: config.account.address,
142
- });
143
- return;
144
- }
145
- // Check if there is a provider in local storage or get a random one from the contract
146
- const providerUrlFromStorage = storage.getProviderUrl();
147
- let providerApi;
148
- if (providerUrlFromStorage) {
149
- providerApi = await loadProviderApi(providerUrlFromStorage);
150
- // if the provider was already in storage, the user may have already solved some captchas but they have not been put on chain yet
151
- // so contact the provider to check if this is the case
152
- try {
153
- const verifyDappUserResponse = await providerApi.verifyDappUser(account.account.address);
154
- if (verifyDappUserResponse.solutionApproved) {
155
- updateState({ isHuman: true, loading: false });
156
- events.onHuman({
157
- providerUrl: providerUrlFromStorage,
158
- user: account.account.address,
159
- dapp: config.account.address,
160
- commitmentId: verifyDappUserResponse.commitmentId,
161
- });
162
- return;
163
- }
164
- }
165
- catch (err) {
166
- // if the provider is down, we should continue with the process of selecting a random provider
167
- console.error('Error contacting provider from storage', providerUrlFromStorage);
168
- // continue as if the provider was not in storage
169
- }
170
- }
171
- const payload = {
172
- address: account.account.address,
173
- data: stringToU8a('message'),
174
- type: 'bytes',
175
- };
176
- const signed = await account.extension.signer.signRaw(payload);
177
- console.log('Signature:', signed);
178
- // get a random provider
179
- const getRandomProviderResponse = await wrapQuery(contract.query.getRandomActiveProvider, contract.query)(account.account.address, config.account.address);
180
- const blockNumber = getRandomProviderResponse.blockNumber;
181
- console.log('provider', getRandomProviderResponse);
182
- const providerUrl = trimProviderUrl(getRandomProviderResponse.provider.url.toString());
183
- // get the provider api inst
184
- providerApi = await loadProviderApi(providerUrl);
185
- console.log('providerApi', providerApi);
186
- // get the captcha challenge and begin the challenge
187
- const captchaApi = await loadCaptchaApi(contract, getRandomProviderResponse, providerApi);
188
- console.log('captchaApi', captchaApi);
189
- const challenge = await captchaApi.getCaptchaChallenge();
190
- console.log('challenge', challenge);
191
- if (challenge.captchas.length <= 0) {
192
- throw new Error('No captchas returned from provider');
193
- }
194
- // setup timeout
195
- const timeMillis = challenge.captchas
196
- .map((captcha) => captcha.captcha.timeLimitMs || 30 * 1000)
197
- .reduce((a, b) => a + b);
198
- const timeout = setTimeout(() => {
199
- console.log('challenge expired after ' + timeMillis + 'ms');
200
- events.onExpired();
201
- // expired, disallow user's claim to be human
202
- updateState({ isHuman: false, showModal: false, loading: false });
203
- }, timeMillis);
204
- // update state with new challenge
205
- updateState({
206
- index: 0,
207
- solutions: challenge.captchas.map(() => []),
208
- challenge,
209
- showModal: true,
210
- timeout,
211
- blockNumber,
212
- });
213
- }
214
- catch (err) {
215
- console.error(err);
216
- // dispatch relevant error event
217
- const event = errorToEventMap[err.constructor] || events.onError;
218
- event(err);
219
- // hit an error, disallow user's claim to be human
220
- updateState({ isHuman: false, showModal: false, loading: false });
221
- }
222
- };
223
- const submit = async () => {
224
- try {
225
- console.log('submitting solutions');
226
- // disable the time limit, user has submitted their solution in time
227
- clearTimeout();
228
- if (!state.challenge) {
229
- throw new Error('cannot submit, no challenge found');
230
- }
231
- // hide the modal, no further input required from user
232
- updateState({ showModal: false });
233
- const challenge = state.challenge;
234
- const salt = randomAsHex();
235
- // append solution to each captcha in the challenge
236
- const captchaSolution = state.challenge.captchas.map((captcha, index) => {
237
- const solution = state.solutions[index];
238
- return {
239
- captchaId: captcha.captcha.captchaId,
240
- captchaContentId: captcha.captcha.captchaContentId,
241
- salt,
242
- solution,
243
- };
244
- });
245
- const account = getAccount();
246
- const blockNumber = getBlockNumber();
247
- const signer = account.extension.signer;
248
- if (!challenge.captchas[0].captcha.datasetId) {
249
- throw new Error('No datasetId set for challenge');
250
- }
251
- const captchaApi = getCaptchaApi();
252
- // send the commitment to the provider
253
- const submission = await captchaApi.submitCaptchaSolution(signer, challenge.requestHash, challenge.captchas[0].captcha.datasetId, captchaSolution, salt);
254
- // mark as is human if solution has been approved
255
- const isHuman = submission[0].solutionApproved;
256
- if (!isHuman) {
257
- // user failed the captcha for some reason according to the provider
258
- events.onFailed();
259
- }
260
- // update the state with the result of the submission
261
- updateState({
262
- submission,
263
- isHuman,
264
- loading: false,
265
- });
266
- if (state.isHuman) {
267
- const trimmedUrl = trimProviderUrl(captchaApi.provider.provider.url.toString());
268
- // cache this provider for future use
269
- storage.setProviderUrl(trimmedUrl);
270
- events.onHuman({
271
- providerUrl: trimmedUrl,
272
- user: account.account.address,
273
- dapp: getDappAccount(),
274
- commitmentId: submission[1],
275
- blockNumber,
276
- });
277
- }
278
- }
279
- catch (err) {
280
- // dispatch relevant error event
281
- const event = errorToEventMap[err.constructor] || events.onError;
282
- event(err);
283
- // hit an error, disallow user's claim to be human
284
- updateState({ isHuman: false, showModal: false, loading: false });
285
- }
286
- };
287
- const cancel = async () => {
288
- console.log('cancel');
289
- // disable the time limit
290
- clearTimeout();
291
- // abandon the captcha process
292
- resetState();
293
- };
294
- /**
295
- * (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).
296
- * @param hash the hash of the image
297
- */
298
- const select = (hash) => {
299
- if (!state.challenge) {
300
- throw new Error('cannot select, no challenge found');
301
- }
302
- if (state.index >= state.challenge.captchas.length || state.index < 0) {
303
- throw new Error('cannot select, round index out of range');
304
- }
305
- const index = state.index;
306
- const solutions = state.solutions;
307
- const solution = solutions[index];
308
- if (solution.includes(hash)) {
309
- console.log('deselecting', hash);
310
- // remove the hash from the solution
311
- solution.splice(solution.indexOf(hash), 1);
312
- }
313
- else {
314
- console.log('selecting', hash);
315
- // add the hash to the solution
316
- solution.push(hash);
317
- }
318
- updateState({ solutions });
319
- };
320
- /**
321
- * Proceed to the next round of the challenge.
322
- */
323
- const nextRound = () => {
324
- if (!state.challenge) {
325
- throw new Error('cannot proceed to next round, no challenge found');
326
- }
327
- if (state.index + 1 >= state.challenge.captchas.length) {
328
- throw new Error('cannot proceed to next round, already at last round');
329
- }
330
- console.log('proceeding to next round');
331
- updateState({ index: state.index + 1 });
332
- };
333
- const loadCaptchaApi = async (contract, provider, providerApi) => {
334
- const config = getConfig();
335
- // setup the captcha api to carry out a challenge
336
- const captchaApi = new ProsopoCaptchaApi(getAccount().account.address, contract, provider, providerApi, config.web2, config.account.address);
337
- updateState({ captchaApi });
338
- return getCaptchaApi();
339
- };
340
- const loadProviderApi = async (providerUrl) => {
341
- const config = getConfig();
342
- const network = getNetwork(config);
343
- return new ProviderApi(network, providerUrl, config.account.address);
344
- };
345
- const clearTimeout = () => {
346
- // clear the timeout
347
- window.clearTimeout(state.timeout);
348
- // then clear the timeout from the state
349
- updateState({ timeout: undefined });
350
- };
351
- const resetState = () => {
352
- // clear timeout just in case a timer is still active (shouldn't be)
353
- clearTimeout();
354
- updateState(defaultState());
355
- };
356
- const getCaptchaApi = () => {
357
- if (!state.captchaApi) {
358
- throw new Error('Captcha api not set');
359
- }
360
- return state.captchaApi;
361
- };
362
- /**
363
- * Load the account using address specified in config, or generate new address if not found in local storage for web2 mode.
364
- */
365
- const loadAccount = async () => {
366
- const config = getConfig();
367
- // check if account has been provided in config (doesn't matter in web2 mode)
368
- if (!config.web2 && !config.userAccountAddress) {
369
- throw new Error('Account address has not been set for web3 mode');
370
- }
371
- // check if account exists in extension
372
- const ext = config.web2 ? new ExtensionWeb2() : new ExtensionWeb3();
373
- const account = await ext.getAccount(config);
374
- // Store the account in local storage
375
- storage.setAccount(account.account.address);
376
- console.log('Using account:', account);
377
- updateState({ account });
378
- return getAccount();
379
- };
380
- const getAccount = () => {
381
- if (!state.account) {
382
- throw new Error('Account not loaded');
383
- }
384
- const account = state.account;
385
- return account;
386
- };
387
- const getDappAccount = () => {
388
- if (!state.dappAccount) {
389
- throw new Error('Dapp account not loaded');
390
- }
391
- const dappAccount = state.dappAccount;
392
- return dappAccount;
393
- };
394
- const getBlockNumber = () => {
395
- if (!state.blockNumber) {
396
- throw new Error('Account not loaded');
397
- }
398
- const blockNumber = state.blockNumber;
399
- return blockNumber;
400
- };
401
- /**
402
- * Load the contract instance using addresses from config.
403
- */
404
- const loadContract = async () => {
405
- const config = getConfig();
406
- const network = getNetwork(config);
407
- const api = await ApiPromise.create({ provider: new WsProvider(network.endpoint) });
408
- // TODO create a shared keyring that's stored somewhere
409
- const type = 'sr25519';
410
- const keyring = new Keyring({ type, ss58Format: api.registry.chainSS58 });
411
- return new ProsopoCaptchaContract(api, abiJson, network.contract.address, keyring.addFromAddress(getAccount().account.address), 'prosopo', 0);
412
- };
413
- return {
414
- start,
415
- cancel,
416
- submit,
417
- select,
418
- nextRound,
419
- };
420
- }
421
- //# sourceMappingURL=Manager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Manager.js","sourceRoot":"","sources":["../../src/modules/Manager.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAQnD,OAAO,EAAsB,WAAW,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAG9E,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAu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KAAK,CAAC,yBAAyB,CAAC,CAAA;SAC7C;QACD,MAAM,WAAW,GAAW,KAAK,CAAC,WAAW,CAAA;QAC7C,OAAO,WAAW,CAAA;IACtB,CAAC,CAAA;IAED,MAAM,cAAc,GAAG,GAAG,EAAE;QACxB,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;SACxC;QACD,MAAM,WAAW,GAAW,KAAK,CAAC,WAAW,CAAA;QAC7C,OAAO,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,UAAU,CAAC,MAAM,CAAC,CAAA;QAClC,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QACnF,uDAAuD;QACvD,MAAM,IAAI,GAAG,SAAS,CAAA;QACtB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAA;QACzE,OAAO,IAAI,sBAAsB,CAC7B,GAAG,EACH,OAAsB,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"}
@@ -1,21 +0,0 @@
1
- import { CaptchaSolution } from '@prosopo/types';
2
- import { GetCaptchaResponse } from '../types/api.js';
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.js';
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":"AAoBA,OAAO,EAAE,eAAe,EAAoB,MAAM,gBAAgB,CAAA;AAClE,OAAO,EAA2B,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAG7E,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,oBAAoB,CAAA;AAGzD,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,114 +0,0 @@
1
- // Copyright 2021-2023 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
- import { CaptchaMerkleTree, computeCaptchaHash, computeCaptchaSolutionHash, computeItemHash, verifyProof, } from '@prosopo/datasets';
15
- import { ProsopoApiError } from '../api/handlers.js';
16
- import { ProsopoEnvError } from '@prosopo/common';
17
- import { stringToHex } from '@polkadot/util';
18
- export class ProsopoCaptchaApi {
19
- userAccount;
20
- contract;
21
- provider;
22
- providerApi;
23
- dappAccount;
24
- web2;
25
- constructor(userAccount, contract, provider, providerApi, web2, dappAccount) {
26
- this.userAccount = userAccount;
27
- this.contract = contract;
28
- this.provider = provider;
29
- this.providerApi = providerApi;
30
- this.web2 = web2;
31
- this.dappAccount = dappAccount;
32
- }
33
- async getCaptchaChallenge() {
34
- try {
35
- const captchaChallenge = await this.providerApi.getCaptchaChallenge(this.userAccount, this.provider);
36
- this.verifyCaptchaChallengeContent(this.provider, captchaChallenge);
37
- return captchaChallenge;
38
- }
39
- catch (e) {
40
- throw new ProsopoEnvError(e);
41
- }
42
- }
43
- verifyCaptchaChallengeContent(provider, captchaChallenge) {
44
- // TODO make sure root is equal to root on the provider
45
- const proofLength = captchaChallenge.captchas[0].proof.length;
46
- console.log(provider.provider);
47
- if (provider.provider.datasetIdContent.toString() !== captchaChallenge.captchas[0].proof[proofLength - 1][0]) {
48
- throw new ProsopoEnvError('CAPTCHA.INVALID_DATASET_CONTENT_ID');
49
- }
50
- for (const captchaWithProof of captchaChallenge.captchas) {
51
- //TODO calculate the captchaId from the captcha content
52
- if (!verifyCaptchaData(captchaWithProof)) {
53
- throw new ProsopoEnvError('CAPTCHA.INVALID_CAPTCHA_CHALLENGE');
54
- }
55
- if (!verifyProof(captchaWithProof.captcha.captchaContentId, captchaWithProof.proof)) {
56
- throw new ProsopoEnvError('CAPTCHA.INVALID_CAPTCHA_CHALLENGE');
57
- }
58
- }
59
- console.log('CAPTCHA.CHALLENGE_VERIFIED');
60
- return;
61
- }
62
- async submitCaptchaSolution(signer, requestHash, datasetId, solutions, salt) {
63
- const tree = new CaptchaMerkleTree();
64
- const captchasHashed = solutions.map((captcha) => computeCaptchaSolutionHash(captcha));
65
- tree.build(captchasHashed);
66
- const commitmentId = tree.root.hash;
67
- console.log('solveCaptchaChallenge commitmentId', commitmentId);
68
- const tx = undefined;
69
- let signature = undefined;
70
- if (this.web2) {
71
- if (!signer || !signer.signRaw) {
72
- throw new Error('Signer is not defined, cannot sign message to prove account ownership');
73
- }
74
- // sign the request hash to prove account ownership
75
- const signed = await signer.signRaw({
76
- address: this.userAccount,
77
- data: stringToHex(requestHash),
78
- type: 'bytes',
79
- });
80
- signature = signed.signature;
81
- }
82
- let result;
83
- try {
84
- result = await this.providerApi.submitCaptchaSolution(solutions, requestHash, this.contract.pair.address, salt, signature);
85
- }
86
- catch (err) {
87
- throw new ProsopoApiError(err);
88
- }
89
- return [result, commitmentId, tx];
90
- }
91
- }
92
- /**
93
- * Verify the captcha data by hashing the images and checking the hashes correspond to the hashes passed in the captcha
94
- * Verify the captcha content id is present in the first layer of the proof
95
- * @param {CaptchaWithProof} captchaWithProof
96
- * @returns {boolean}
97
- */
98
- async function verifyCaptchaData(captchaWithProof) {
99
- const captcha = captchaWithProof.captcha;
100
- const proof = captchaWithProof.proof;
101
- // Check that all the item hashes are equal to the provided item hashes in the captcha
102
- if (!(await Promise.all(captcha.items.map(async (item) => (await computeItemHash(item)).hash === item.hash))).every((hash) => hash === true)) {
103
- return false;
104
- }
105
- // Check that the computed captcha content id is equal to the provided captcha content id
106
- const captchaHash = computeCaptchaHash(captcha, false, false, false);
107
- if (captchaHash !== captcha.captchaContentId) {
108
- return false;
109
- }
110
- // Check that the captcha content id is present in the first layer of the proof
111
- return proof[0].indexOf(captchaHash) !== -1;
112
- }
113
- export default ProsopoCaptchaApi;
114
- //# sourceMappingURL=ProsopoCaptchaApi.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ProsopoCaptchaApi.js","sourceRoot":"","sources":["../../src/modules/ProsopoCaptchaApi.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,OAAO,EACH,iBAAiB,EACjB,kBAAkB,EAClB,0BAA0B,EAC1B,eAAe,EACf,WAAW,GACd,MAAM,mBAAmB,CAAA;AAI1B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAKjD,OAA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AgB,EAAE;QAC1C,OAAO,KAAK,CAAA;KACf;IACD,+EAA+E;IAC/E,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAA;AAC/C,CAAC;AAED,eAAe,iBAAiB,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":"AAwNA,wBAAgB,aAAa,CAAC,WAAW,KAAA,EAAE,IAAI,KAAA,EAAE,MAAM,KAAA,UA4MtD"}