@prosopo/procaptcha 0.2.14 → 0.2.15

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 (50) hide show
  1. package/dist/api/Extension.d.ts +0 -10
  2. package/dist/api/Extension.d.ts.map +1 -1
  3. package/dist/api/Extension.js +0 -3
  4. package/dist/api/Extension.js.map +1 -1
  5. package/dist/api/ExtensionWeb2.d.ts +0 -3
  6. package/dist/api/ExtensionWeb2.d.ts.map +1 -1
  7. package/dist/api/ExtensionWeb2.js +0 -9
  8. package/dist/api/ExtensionWeb2.js.map +1 -1
  9. package/dist/api/ExtensionWeb3.d.ts +0 -3
  10. package/dist/api/ExtensionWeb3.d.ts.map +1 -1
  11. package/dist/api/ExtensionWeb3.js +0 -5
  12. package/dist/api/ExtensionWeb3.js.map +1 -1
  13. package/dist/api/errors.js +0 -13
  14. package/dist/api/errors.js.map +1 -1
  15. package/dist/api/handlers.js +0 -15
  16. package/dist/api/handlers.js.map +1 -1
  17. package/dist/api/index.js +0 -13
  18. package/dist/api/index.js.map +1 -1
  19. package/dist/api/sign.js +0 -13
  20. package/dist/api/sign.js.map +1 -1
  21. package/dist/cjs/modules/Manager.cjs +5 -1
  22. package/dist/index.js +0 -13
  23. package/dist/index.js.map +1 -1
  24. package/dist/modules/Manager.d.ts +0 -3
  25. package/dist/modules/Manager.d.ts.map +1 -1
  26. package/dist/modules/Manager.js +2 -79
  27. package/dist/modules/Manager.js.map +1 -1
  28. package/dist/modules/ProsopoCaptchaApi.js +0 -27
  29. package/dist/modules/ProsopoCaptchaApi.js.map +1 -1
  30. package/dist/modules/canvas.js +0 -14
  31. package/dist/modules/canvas.js.map +1 -1
  32. package/dist/modules/index.js +0 -13
  33. package/dist/modules/index.js.map +1 -1
  34. package/dist/modules/storage.d.ts +0 -12
  35. package/dist/modules/storage.d.ts.map +1 -1
  36. package/dist/modules/storage.js +0 -25
  37. package/dist/modules/storage.js.map +1 -1
  38. package/dist/tests/mocks/browser.js +0 -13
  39. package/dist/tests/mocks/browser.js.map +1 -1
  40. package/dist/types/api.js +0 -19
  41. package/dist/types/api.js.map +1 -1
  42. package/dist/types/index.js +0 -13
  43. package/dist/types/index.js.map +1 -1
  44. package/dist/types/manager.d.ts +0 -24
  45. package/dist/types/manager.d.ts.map +1 -1
  46. package/dist/utils/index.js +0 -13
  47. package/dist/utils/index.js.map +1 -1
  48. package/dist/utils/utils.js +0 -13
  49. package/dist/utils/utils.js.map +1 -1
  50. package/package.json +10 -8
@@ -1,16 +1,6 @@
1
1
  import { Account } from '../types/index.js';
2
2
  import { ProcaptchaClientConfigOutput } from '@prosopo/types';
3
- /**
4
- * Class to interface with accounts.
5
- */
6
3
  export default abstract class Extension {
7
- /**
8
- * Find an account given an address.
9
- * @param address the address of the account
10
- * @param dappName the name of the dapp wanting to gain access to accounts (e.g. "Prosopo")
11
- * @returns the account
12
- * @throws if the account is not found
13
- */
14
4
  abstract getAccount(config: ProcaptchaClientConfigOutput): Promise<Account>;
15
5
  }
16
6
  //# sourceMappingURL=Extension.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Extension.d.ts","sourceRoot":"","sources":["../../src/api/Extension.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAA;AAE7D;;GAEG;AACH,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,SAAS;IACnC;;;;;;OAMG;aACa,UAAU,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,OAAO,CAAC;CACrF"}
1
+ {"version":3,"file":"Extension.d.ts","sourceRoot":"","sources":["../../src/api/Extension.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAA;AAK7D,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,SAAS;aAQnB,UAAU,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,OAAO,CAAC;CACrF"}
@@ -1,6 +1,3 @@
1
- /**
2
- * Class to interface with accounts.
3
- */
4
1
  export default class Extension {
5
2
  }
6
3
  //# sourceMappingURL=Extension.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Extension.js","sourceRoot":"","sources":["../../src/api/Extension.ts"],"names":[],"mappings":"AAgBA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAgB,SAAS;CAStC"}
1
+ {"version":3,"file":"Extension.js","sourceRoot":"","sources":["../../src/api/Extension.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAC,OAAO,OAAgB,SAAS;CAStC"}
@@ -1,9 +1,6 @@
1
1
  import { Account } from '../types/index.js';
2
2
  import { ProcaptchaClientConfigOutput } from '@prosopo/types';
3
3
  import Extension from './Extension.js';
4
- /**
5
- * Class for interfacing with web3 accounts.
6
- */
7
4
  export default class ExtWeb2 extends Extension {
8
5
  getAccount(config: ProcaptchaClientConfigOutput): Promise<Account>;
9
6
  private createExtension;
@@ -1 +1 @@
1
- {"version":3,"file":"ExtensionWeb2.d.ts","sourceRoot":"","sources":["../../src/api/ExtensionWeb2.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAO3C,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAA;AAU7D,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAKtC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,SAAS;IAC7B,UAAU,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,OAAO,CAAC;YAajE,eAAe;YAiCf,aAAa;YAgCb,cAAc;CAU/B"}
1
+ {"version":3,"file":"ExtensionWeb2.d.ts","sourceRoot":"","sources":["../../src/api/ExtensionWeb2.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAO3C,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAA;AAU7D,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAQtC,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,SAAS;IAC7B,UAAU,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,OAAO,CAAC;YAajE,eAAe;YAiCf,aAAa;YAgCb,cAAc;CAU/B"}
@@ -11,9 +11,6 @@ import { stringToU8a } from '@polkadot/util/string';
11
11
  import { u8aToHex } from '@polkadot/util/u8a';
12
12
  import Extension from './Extension.js';
13
13
  import Signer from '@polkadot/extension-base/page/Signer';
14
- /**
15
- * Class for interfacing with web3 accounts.
16
- */
17
14
  export default class ExtWeb2 extends Extension {
18
15
  async getAccount(config) {
19
16
  const network = getNetwork(config);
@@ -29,7 +26,6 @@ export default class ExtWeb2 extends Extension {
29
26
  const signer = new Signer(async () => {
30
27
  return;
31
28
  });
32
- // signing carried out by the keypair. Signs the data with the private key, creating a signature. Other people can verify this signature given the message and the public key, proving that the message was indeed signed by account and proving ownership of the account.
33
29
  signer.signRaw = async (payload) => {
34
30
  const signature = account.keypair.sign(payload.data);
35
31
  return {
@@ -40,11 +36,9 @@ export default class ExtWeb2 extends Extension {
40
36
  return {
41
37
  accounts: {
42
38
  get: async () => {
43
- // there is only ever 1 account
44
39
  return [account];
45
40
  },
46
41
  subscribe: () => {
47
- // do nothing, there will never be account changes
48
42
  return () => {
49
43
  return;
50
44
  };
@@ -85,12 +79,9 @@ export default class ExtWeb2 extends Extension {
85
79
  };
86
80
  }
87
81
  async getFingerprint() {
88
- // Initialize an agent at application startup.
89
82
  const fpPromise = load();
90
- // Get the visitor identifier when you need it.
91
83
  const fp = await fpPromise;
92
84
  const result = await fp.get();
93
- // strip out the components that change in incognito mode
94
85
  const { screenFrame, ...componentsReduced } = result.components;
95
86
  return hashComponents(componentsReduced);
96
87
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Ext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AC,CAAA;QACtC,MAAM,QAAQ,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAA;QAC7C,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAA;QAC9E,MAAM,IAAI,GAAgB,SAAS,CAAA;QACnC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAA;QACzE,MAAM,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAA;QACjD,MAAM,OAAO,GACT,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,EAAE;YACzB,CAAC,CAAC,OAAO,CAAC,OAAO;YACjB,CAAC,CAAC,aAAa,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;QAC/E,OAAO;YACH,OAAO;YACP,IAAI;YACJ,IAAI,EAAE,OAAO;YACb,OAAO;SACV,CAAA;IACL,CAAC;IAEO,KAAK,CAAC,cAAc;QAExB,MAAM,SAAS,GAAG,IAAI,EAAE,CAAA;QAExB,MAAM,EAAE,GAAG,MAAM,SAAS,CAAA;QAC1B,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,EAAE,CAAA;QAE7B,MAAM,EAAE,WAAW,EAAE,GAAG,iBAAiB,EAAE,GAAG,MAAM,CAAC,UAAU,CAAA;QAC/D,OAAO,cAAc,CAAC,iBAAiB,CAAC,CAAA;IAC5C,CAAC;CACJ"}
@@ -1,9 +1,6 @@
1
1
  import { Account } from '../types/index.js';
2
2
  import { ProcaptchaClientConfigOutput } from '@prosopo/types';
3
3
  import Extension from './Extension.js';
4
- /**
5
- * Class for interfacing with web3 accounts.
6
- */
7
4
  export default class ExtWeb3 extends Extension {
8
5
  getAccount(config: ProcaptchaClientConfigOutput): Promise<Account>;
9
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ExtensionWeb3.d.ts","sourceRoot":"","sources":["../../src/api/ExtensionWeb3.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAG3C,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAA;AAE7D,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAEtC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,SAAS;IAC7B,UAAU,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,OAAO,CAAC;CAwBlF"}
1
+ {"version":3,"file":"ExtensionWeb3.d.ts","sourceRoot":"","sources":["../../src/api/ExtensionWeb3.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAG3C,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAA;AAE7D,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAKtC,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,SAAS;IAC7B,UAAU,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,OAAO,CAAC;CAwBlF"}
@@ -1,21 +1,16 @@
1
1
  import { AccountNotFoundError, ExtensionNotFoundError } from './errors.js';
2
2
  import { web3Enable } from '@polkadot/extension-dapp';
3
3
  import Extension from './Extension.js';
4
- /**
5
- * Class for interfacing with web3 accounts.
6
- */
7
4
  export default class ExtWeb3 extends Extension {
8
5
  async getAccount(config) {
9
6
  const { dappName, userAccountAddress: address } = config;
10
7
  if (!address) {
11
8
  throw new AccountNotFoundError('No account address provided');
12
9
  }
13
- // enable access to all extensions
14
10
  const extensions = await web3Enable(dappName);
15
11
  if (extensions.length === 0) {
16
12
  throw new ExtensionNotFoundError();
17
13
  }
18
- // search through all extensions for the one that has the account
19
14
  for (const extension of extensions) {
20
15
  const accounts = await extension.accounts.get();
21
16
  const account = accounts.find((account) => account.address === address);
@@ -1 +1 @@
1
- {"version":3,"file":"ExtensionWeb3.js","sourceRoot":"","sources":["../../src/api/ExtensionWeb3.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAG1E,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAEtC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,SAAS;IACnC,KAAK,CAAC,UAAU,CAAC,MAAoC;QACxD,MAAM,EAAE,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;QAExD,IAAI,CAAC,OAAO,EAAE;YACV,MAAM,IAAI,oBAAoB,CAAC,6BAA6B,CAAC,CAAA;SAChE;QAED,kCAAkC;QAClC,MAAM,UAAU,GAAwB,MAAM,UAAU,CAAC,QAAQ,CAAC,CAAA;QAClE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;YACzB,MAAM,IAAI,sBAAsB,EAAE,CAAA;SACrC;QAED,iEAAiE;QACjE,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE;YAChC,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAA;YAC/C,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;YACvE,IAAI,OAAO,EAAE;gBACT,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAA;aAChC;SACJ;QAED,MAAM,IAAI,oBAAoB,CAAC,4BAA4B,GAAG,OAAO,CAAC,CAAA;IAC1E,CAAC;CACJ"}
1
+ {"version":3,"file":"ExtensionWeb3.js","sourceRoot":"","sources":["../../src/api/ExtensionWeb3.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAG1E,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAKtC,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,SAAS;IACnC,KAAK,CAAC,UAAU,CAAC,MAAoC;QACxD,MAAM,EAAE,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;QAExD,IAAI,CAAC,OAAO,EAAE;YACV,MAAM,IAAI,oBAAoB,CAAC,6BAA6B,CAAC,CAAA;SAChE;QAGD,MAAM,UAAU,GAAwB,MAAM,UAAU,CAAC,QAAQ,CAAC,CAAA;QAClE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;YACzB,MAAM,IAAI,sBAAsB,EAAE,CAAA;SACrC;QAGD,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE;YAChC,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAA;YAC/C,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;YACvE,IAAI,OAAO,EAAE;gBACT,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAA;aAChC;SACJ;QAED,MAAM,IAAI,oBAAoB,CAAC,4BAA4B,GAAG,OAAO,CAAC,CAAA;IAC1E,CAAC;CACJ"}
@@ -1,16 +1,3 @@
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
1
  export class NoExtensionsFoundError extends Error {
15
2
  constructor(msg) {
16
3
  super(msg || 'No extensions found');
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/api/errors.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,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC7C,YAAY,GAAY;QACpB,KAAK,CAAC,GAAG,IAAI,qBAAqB,CAAC,CAAA;IACvC,CAAC;CACJ;AAED,MAAM,OAAO,+BAAgC,SAAQ,KAAK;IACtD,YAAY,GAAY;QACpB,KAAK,CAAC,GAAG,IAAI,mCAAmC,CAAC,CAAA;IACrD,CAAC;CACJ;AAED,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC3C,YAAY,GAAY;QACpB,KAAK,CAAC,GAAG,IAAI,kBAAkB,CAAC,CAAA;IACpC,CAAC;CACJ;AAED,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC7C,YAAY,GAAY;QACpB,KAAK,CAAC,GAAG,IAAI,qBAAqB,CAAC,CAAA;IACvC,CAAC;CACJ;AAED,MAAM,OAAO,YAAa,SAAQ,KAAK;IACnC,YAAY,GAAY;QACpB,KAAK,CAAC,GAAG,IAAI,2BAA2B,CAAC,CAAA;IAC7C,CAAC;CACJ"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/api/errors.ts"],"names":[],"mappings":"AAaA,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC7C,YAAY,GAAY;QACpB,KAAK,CAAC,GAAG,IAAI,qBAAqB,CAAC,CAAA;IACvC,CAAC;CACJ;AAED,MAAM,OAAO,+BAAgC,SAAQ,KAAK;IACtD,YAAY,GAAY;QACpB,KAAK,CAAC,GAAG,IAAI,mCAAmC,CAAC,CAAA;IACrD,CAAC;CACJ;AAED,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC3C,YAAY,GAAY;QACpB,KAAK,CAAC,GAAG,IAAI,kBAAkB,CAAC,CAAA;IACpC,CAAC;CACJ;AAED,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC7C,YAAY,GAAY;QACpB,KAAK,CAAC,GAAG,IAAI,qBAAqB,CAAC,CAAA;IACvC,CAAC;CACJ;AAED,MAAM,OAAO,YAAa,SAAQ,KAAK;IACnC,YAAY,GAAY;QACpB,KAAK,CAAC,GAAG,IAAI,2BAA2B,CAAC,CAAA;IAC7C,CAAC;CACJ"}
@@ -1,25 +1,10 @@
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
1
  export class ProsopoApiError extends Error {
15
2
  constructor(error, context, ...params) {
16
- // If error is an instance of Response, it's an HTTP error
17
3
  if (error instanceof Response) {
18
4
  super(`HTTP Error: ${error.status} ${error.statusText}`);
19
5
  this.cause = error;
20
6
  }
21
7
  else {
22
- // Otherwise, it's a network error, or something else
23
8
  super(error.message || 'Unknown API Error');
24
9
  this.cause = error;
25
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/api/handlers.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;A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AC,KAAK,GAAG,KAAK,CAAA;SACrB;QAED,IAAI,CAAC,IAAI,GAAG,CAAC,OAAO,IAAI,GAAG,eAAe,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC,IAAI,eAAe,CAAC,IAAI,CAAA;QAErF,OAAO,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAA;QACtE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,MAAM,CAAC,CAAA;IACpD,CAAC;CACJ"}
package/dist/api/index.js CHANGED
@@ -1,16 +1,3 @@
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
1
  export * from './ExtensionWeb3.js';
15
2
  export * from './ExtensionWeb2.js';
16
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.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,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAaA,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA"}
package/dist/api/sign.js CHANGED
@@ -1,16 +1,3 @@
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
1
  import { Keyring } from '@polkadot/keyring';
15
2
  import { blake2AsHex } from '@polkadot/util-crypto/blake2';
16
3
  import { u8aToHex } from '@polkadot/util/u8a';
@@ -1 +1 @@
1
- {"version":3,"file":"sign.js","sourceRoot":"","sources":["../../src/api/sign.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,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE7C,MAAM,UAAU,IAAI,CAAC,OAAe;IAChC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;IAC9C,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;IAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC9B,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;IAC/B,MAAM,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;IACxC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,CAAA;AACrC,CAAC"}
1
+ {"version":3,"file":"sign.js","sourceRoot":"","sources":["../../src/api/sign.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE7C,MAAM,UAAU,IAAI,CAAC,OAAe;IAChC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;IAC9C,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;IAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC9B,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;IAC/B,MAAM,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;IACxC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,CAAA;AACrC,CAAC"}
@@ -146,7 +146,11 @@ function Manager(configOptional, state, onStateUpdate, callbacks) {
146
146
  if (providerUrlFromStorage) {
147
147
  providerApi = await loadProviderApi(providerUrlFromStorage);
148
148
  try {
149
- const verifyDappUserResponse = await providerApi.verifyDappUser(account.account.address);
149
+ const verifyDappUserResponse = await providerApi.verifyDappUser(
150
+ account.account.address,
151
+ void 0,
152
+ configOptional.challengeValidLength
153
+ );
150
154
  if (verifyDappUserResponse.solutionApproved) {
151
155
  updateState({ isHuman: true, loading: false });
152
156
  events.onHuman({
package/dist/index.js CHANGED
@@ -1,16 +1,3 @@
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
1
  export * from './api/index.js';
15
2
  export * from './modules/index.js';
16
3
  export * from './types/index.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.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,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA"}
@@ -10,9 +10,6 @@ export declare const getNetwork: (config: ProcaptchaClientConfigOutput) => {
10
10
  pairType: "sr25519" | "ed25519" | "ecdsa" | "ethereum";
11
11
  ss58Format: number;
12
12
  };
13
- /**
14
- * 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.
15
- */
16
13
  export declare function Manager(configOptional: ProcaptchaConfigOptional, state: ProcaptchaState, onStateUpdate: ProcaptchaStateUpdateFn, callbacks: ProcaptchaCallbacks): {
17
14
  start: () => Promise<void>;
18
15
  cancel: () => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"Manager.d.ts","sourceRoot":"","sources":["../../src/modules/Manager.ts"],"names":[],"mappings":"AAaA,OAAO,EAEH,mBAAmB,EACnB,wBAAwB,EAExB,eAAe,EACf,uBAAuB,EAC1B,MAAM,qBAAqB,CAAA;AAG5B,OAAO,EAGH,4BAA4B,EAE/B,MAAM,gBAAgB,CAAA;AAmBvB,eAAO,MAAM,YAAY,QAAO,QAAQ,eAAe,CAatD,CAAA;AAgBD,eAAO,MAAM,UAAU,WAAY,4BAA4B;;;;;;;;CAM9D,CAAA;AAED;;GAEG;AACH,wBAAgB,OAAO,CACnB,cAAc,EAAE,wBAAwB,EACxC,KAAK,EAAE,eAAe,EACtB,aAAa,EAAE,uBAAuB,EACtC,SAAS,EAAE,mBAAmB;;;;mBAmTR,MAAM;;EA+K/B"}
1
+ {"version":3,"file":"Manager.d.ts","sourceRoot":"","sources":["../../src/modules/Manager.ts"],"names":[],"mappings":"AAaA,OAAO,EAEH,mBAAmB,EACnB,wBAAwB,EAExB,eAAe,EACf,uBAAuB,EAC1B,MAAM,qBAAqB,CAAA;AAG5B,OAAO,EAGH,4BAA4B,EAE/B,MAAM,gBAAgB,CAAA;AAmBvB,eAAO,MAAM,YAAY,QAAO,QAAQ,eAAe,CAatD,CAAA;AAgBD,eAAO,MAAM,UAAU,WAAY,4BAA4B;;;;;;;;CAM9D,CAAA;AAKD,wBAAgB,OAAO,CACnB,cAAc,EAAE,wBAAwB,EACxC,KAAK,EAAE,eAAe,EACtB,aAAa,EAAE,uBAAuB,EACtC,SAAS,EAAE,mBAAmB;;;;mBAuTR,MAAM;;EA+K/B"}
@@ -17,7 +17,6 @@ import ProsopoCaptchaApi from './ProsopoCaptchaApi.js';
17
17
  import storage from './storage.js';
18
18
  export const defaultState = () => {
19
19
  return {
20
- // note order matters! see buildUpdateState. These fields are set in order, so disable modal first, then set loading to false, etc.
21
20
  showModal: false,
22
21
  loading: false,
23
22
  index: 0,
@@ -26,15 +25,11 @@ export const defaultState = () => {
26
25
  isHuman: false,
27
26
  captchaApi: undefined,
28
27
  account: undefined,
29
- // don't handle timeout here, this should be handled by the state management
30
28
  };
31
29
  };
32
30
  const buildUpdateState = (state, onStateUpdate) => {
33
31
  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
32
  Object.assign(state, nextState);
37
- // then call the update function for the frontend to do the same
38
33
  onStateUpdate(nextState);
39
34
  console.log('Procaptcha state update:', nextState, '\nResult:', state);
40
35
  };
@@ -47,11 +42,7 @@ export const getNetwork = (config) => {
47
42
  }
48
43
  return network;
49
44
  };
50
- /**
51
- * 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.
52
- */
53
45
  export function Manager(configOptional, state, onStateUpdate, callbacks) {
54
- // 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.
55
46
  const alertError = (error) => {
56
47
  console.log(error);
57
48
  alert(error.message);
@@ -90,22 +81,12 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
90
81
  events.onError(error);
91
82
  }
92
83
  };
93
- // get the state update mechanism
94
84
  const updateState = buildUpdateState(state, onStateUpdate);
95
- /**
96
- * Build the config on demand, using the optional config passed in from the outside. State may override various
97
- * config values depending on the state of the captcha process. E.g. if the process has been started using account
98
- * "ABC" and then the user changes account to "DEF" via the optional config prop, the account in use will not change.
99
- * This is because the captcha process has already been started using account "ABC".
100
- * @returns the config for procaptcha
101
- */
102
85
  const getConfig = () => {
103
86
  const config = {
104
87
  userAccountAddress: '',
105
88
  ...configOptional,
106
89
  };
107
- // overwrite the account in use with the one in state if it exists. Reduces likelihood of bugs where the user
108
- // changes account in the middle of the captcha process.
109
90
  if (state.account) {
110
91
  config.userAccountAddress = state.account.account.address;
111
92
  }
@@ -117,15 +98,10 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
117
98
  }
118
99
  catch (err) {
119
100
  console.error(err);
120
- // dispatch relevant error event
121
101
  dispatchErrorEvent(err);
122
- // hit an error, disallow user's claim to be human
123
102
  updateState({ isHuman: false, showModal: false, loading: false });
124
103
  }
125
104
  };
126
- /**
127
- * Called on start of user verification. This is when the user ticks the box to claim they are human.
128
- */
129
105
  const start = async () => {
130
106
  console.log('Starting procaptcha');
131
107
  events.onOpen();
@@ -139,19 +115,12 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
139
115
  return;
140
116
  }
141
117
  resetState();
142
- // set the loading flag to true (allow UI to show some sort of loading / pending indicator while we get the captcha process going)
143
118
  updateState({ loading: true });
144
- // snapshot the config into the state
145
119
  const config = getConfig();
146
120
  updateState({ dappAccount: config.account.address });
147
- // allow UI to catch up with the loading state
148
121
  await sleep(100);
149
- // check accounts / setup accounts
150
122
  const account = await loadAccount();
151
- // account has been found, check if account is already marked as human
152
- // first, ask the smart contract
153
123
  const contract = await loadContract();
154
- // We don't need to show CAPTCHA challenges if the user is determined as human by the contract
155
124
  let contractIsHuman = false;
156
125
  try {
157
126
  contractIsHuman = (await contract.query.dappOperatorIsHumanUser(account.account.address, config.solutionThreshold)).value
@@ -170,15 +139,12 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
170
139
  setValidChallengeTimeout();
171
140
  return;
172
141
  }
173
- // Check if there is a provider in local storage or get a random one from the contract
174
142
  const providerUrlFromStorage = storage.getProviderUrl();
175
143
  let providerApi;
176
144
  if (providerUrlFromStorage) {
177
145
  providerApi = await loadProviderApi(providerUrlFromStorage);
178
- // if the provider was already in storage, the user may have already solved some captchas but they have not been put on chain yet
179
- // so contact the provider to check if this is the case
180
146
  try {
181
- const verifyDappUserResponse = await providerApi.verifyDappUser(account.account.address);
147
+ const verifyDappUserResponse = await providerApi.verifyDappUser(account.account.address, undefined, configOptional.challengeValidLength);
182
148
  if (verifyDappUserResponse.solutionApproved) {
183
149
  updateState({ isHuman: true, loading: false });
184
150
  events.onHuman({
@@ -192,9 +158,7 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
192
158
  }
193
159
  }
194
160
  catch (err) {
195
- // if the provider is down, we should continue with the process of selecting a random provider
196
161
  console.error('Error contacting provider from storage', providerUrlFromStorage);
197
- // continue as if the provider was not in storage
198
162
  }
199
163
  }
200
164
  const payload = {
@@ -204,15 +168,12 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
204
168
  };
205
169
  const signed = await account.extension.signer.signRaw(payload);
206
170
  console.log('Signature:', signed);
207
- // get a random provider
208
171
  const getRandomProviderResponse = await wrapQuery(contract.query.getRandomActiveProvider, contract.query)(account.account.address, getDappAccount());
209
172
  const blockNumber = parseInt(getRandomProviderResponse.blockNumber.toString());
210
173
  console.log('provider', getRandomProviderResponse);
211
174
  const providerUrl = trimProviderUrl(getRandomProviderResponse.provider.url.toString());
212
- // get the provider api inst
213
175
  providerApi = await loadProviderApi(providerUrl);
214
176
  console.log('providerApi', providerApi);
215
- // get the captcha challenge and begin the challenge
216
177
  const captchaApi = await loadCaptchaApi(contract, getRandomProviderResponse, providerApi);
217
178
  console.log('captchaApi', captchaApi);
218
179
  const challenge = await captchaApi.getCaptchaChallenge();
@@ -220,17 +181,14 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
220
181
  if (challenge.captchas.length <= 0) {
221
182
  throw new Error('No captchas returned from provider');
222
183
  }
223
- // setup timeout
224
184
  const timeMillis = challenge.captchas
225
185
  .map((captcha) => captcha.captcha.timeLimitMs || 30 * 1000)
226
186
  .reduce((a, b) => a + b);
227
187
  const timeout = setTimeout(() => {
228
188
  console.log('challenge expired after ' + timeMillis + 'ms');
229
189
  events.onChallengeExpired();
230
- // expired, disallow user's claim to be human
231
190
  updateState({ isHuman: false, showModal: false, loading: false });
232
191
  }, timeMillis);
233
- // update state with new challenge
234
192
  updateState({
235
193
  index: 0,
236
194
  solutions: challenge.captchas.map(() => []),
@@ -244,16 +202,13 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
244
202
  const submit = async () => {
245
203
  await fallable(async () => {
246
204
  console.log('submitting solutions');
247
- // disable the time limit, user has submitted their solution in time
248
205
  clearTimeout();
249
206
  if (!state.challenge) {
250
207
  throw new Error('cannot submit, no challenge found');
251
208
  }
252
- // hide the modal, no further input required from user
253
209
  updateState({ showModal: false });
254
210
  const challenge = state.challenge;
255
211
  const salt = randomAsHex();
256
- // append solution to each captcha in the challenge
257
212
  const captchaSolution = state.challenge.captchas.map((captcha, index) => {
258
213
  const solution = at(state.solutions, index);
259
214
  return {
@@ -271,15 +226,11 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
271
226
  throw new Error('No datasetId set for challenge');
272
227
  }
273
228
  const captchaApi = getCaptchaApi();
274
- // send the commitment to the provider
275
229
  const submission = await captchaApi.submitCaptchaSolution(signer, challenge.requestHash, first.captcha.datasetId, captchaSolution, salt);
276
- // mark as is human if solution has been approved
277
230
  const isHuman = submission[0].solutionApproved;
278
231
  if (!isHuman) {
279
- // user failed the captcha for some reason according to the provider
280
232
  events.onFailed();
281
233
  }
282
- // update the state with the result of the submission
283
234
  updateState({
284
235
  submission,
285
236
  isHuman,
@@ -287,7 +238,6 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
287
238
  });
288
239
  if (state.isHuman) {
289
240
  const trimmedUrl = trimProviderUrl(captchaApi.provider.provider.url.toString());
290
- // cache this provider for future use
291
241
  storage.setProviderUrl(trimmedUrl);
292
242
  events.onHuman({
293
243
  providerUrl: trimmedUrl,
@@ -302,17 +252,10 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
302
252
  };
303
253
  const cancel = async () => {
304
254
  console.log('cancel');
305
- // disable the time limit
306
255
  clearTimeout();
307
- // abandon the captcha process
308
256
  resetState();
309
- // trigger the onClose event
310
257
  events.onClose();
311
258
  };
312
- /**
313
- * (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).
314
- * @param hash the hash of the image
315
- */
316
259
  const select = (hash) => {
317
260
  if (!state.challenge) {
318
261
  throw new Error('cannot select, no challenge found');
@@ -325,19 +268,14 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
325
268
  const solution = at(solutions, index);
326
269
  if (solution.includes(hash)) {
327
270
  console.log('deselecting', hash);
328
- // remove the hash from the solution
329
271
  solution.splice(solution.indexOf(hash), 1);
330
272
  }
331
273
  else {
332
274
  console.log('selecting', hash);
333
- // add the hash to the solution
334
275
  solution.push(hash);
335
276
  }
336
277
  updateState({ solutions });
337
278
  };
338
- /**
339
- * Proceed to the next round of the challenge.
340
- */
341
279
  const nextRound = () => {
342
280
  if (!state.challenge) {
343
281
  throw new Error('cannot proceed to next round, no challenge found');
@@ -350,7 +288,6 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
350
288
  };
351
289
  const loadCaptchaApi = async (contract, provider, providerApi) => {
352
290
  const config = getConfig();
353
- // setup the captcha api to carry out a challenge
354
291
  const captchaApi = new ProsopoCaptchaApi(getAccount().account.address, contract, provider, providerApi, config.web2, getDappAccount());
355
292
  updateState({ captchaApi });
356
293
  return getCaptchaApi();
@@ -364,24 +301,20 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
364
301
  return new ProviderApi(network, providerUrl, config.account.address);
365
302
  };
366
303
  const clearTimeout = () => {
367
- // clear the timeout
368
304
  window.clearTimeout(state.timeout);
369
- // then clear the timeout from the state
370
305
  updateState({ timeout: undefined });
371
306
  };
372
307
  const setValidChallengeTimeout = () => {
373
308
  console.log('setting valid challenge timeout');
374
- const timeMillis = configOptional.challengeValidLength || 120 * 1000; // default to 2 minutes
309
+ const timeMillis = configOptional.challengeValidLength || 120 * 1000;
375
310
  const successfullChallengeTimeout = setTimeout(() => {
376
311
  console.log('valid challenge expired after ' + timeMillis + 'ms');
377
- // Human state expired, disallow user's claim to be human
378
312
  updateState({ isHuman: false });
379
313
  events.onExpired();
380
314
  }, timeMillis);
381
315
  updateState({ successfullChallengeTimeout });
382
316
  };
383
317
  const resetState = () => {
384
- // clear timeout just in case a timer is still active (shouldn't be)
385
318
  clearTimeout();
386
319
  updateState(defaultState());
387
320
  };
@@ -391,19 +324,13 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
391
324
  }
392
325
  return state.captchaApi;
393
326
  };
394
- /**
395
- * Load the account using address specified in config, or generate new address if not found in local storage for web2 mode.
396
- */
397
327
  const loadAccount = async () => {
398
328
  const config = getConfig();
399
- // check if account has been provided in config (doesn't matter in web2 mode)
400
329
  if (!config.web2 && !config.userAccountAddress) {
401
330
  throw new Error('Account address has not been set for web3 mode');
402
331
  }
403
- // check if account exists in extension
404
332
  const ext = config.web2 ? new ExtensionWeb2() : new ExtensionWeb3();
405
333
  const account = await ext.getAccount(config);
406
- // Store the account in local storage
407
334
  storage.setAccount(account.account.address);
408
335
  console.log('Using account:', account);
409
336
  updateState({ account });
@@ -430,14 +357,10 @@ export function Manager(configOptional, state, onStateUpdate, callbacks) {
430
357
  const blockNumber = state.blockNumber;
431
358
  return blockNumber;
432
359
  };
433
- /**
434
- * Load the contract instance using addresses from config.
435
- */
436
360
  const loadContract = async () => {
437
361
  const config = getConfig();
438
362
  const network = getNetwork(config);
439
363
  const api = await ApiPromise.create({ provider: new WsProvider(network.endpoint), initWasm: false });
440
- // TODO create a shared keyring that's stored somewhere
441
364
  const type = 'sr25519';
442
365
  const keyring = new Keyring({ type, ss58Format: api.registry.chainSS58 });
443
366
  return new ProsopoCaptchaContract(api, JSON.parse(abiJson), network.contract.address, 'prosopo', 0, keyring.addFromAddress(getAccount().account.address));