@prosopo/procaptcha 0.1.0 → 0.1.1

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 (88) hide show
  1. package/dist/api/AsyncFactory.d.ts +7 -0
  2. package/dist/api/AsyncFactory.d.ts.map +1 -0
  3. package/dist/api/AsyncFactory.js +29 -0
  4. package/dist/api/AsyncFactory.js.map +1 -0
  5. package/dist/api/Extension.d.ts +22 -0
  6. package/dist/api/Extension.d.ts.map +1 -0
  7. package/dist/api/Extension.js +103 -0
  8. package/dist/api/Extension.js.map +1 -0
  9. package/dist/api/HttpClientBase.d.ts +9 -0
  10. package/dist/api/HttpClientBase.d.ts.map +1 -0
  11. package/dist/api/HttpClientBase.js +36 -0
  12. package/dist/api/HttpClientBase.js.map +1 -0
  13. package/dist/api/ProsopoContract.d.ts +12 -0
  14. package/dist/api/ProsopoContract.d.ts.map +1 -0
  15. package/dist/api/ProsopoContract.js +36 -0
  16. package/dist/api/ProsopoContract.js.map +1 -0
  17. package/dist/api/ProsopoContractBase.d.ts +31 -0
  18. package/dist/api/ProsopoContractBase.d.ts.map +1 -0
  19. package/dist/api/ProsopoContractBase.js +131 -0
  20. package/dist/api/ProsopoContractBase.js.map +1 -0
  21. package/dist/api/ProviderApi.d.ts +21 -0
  22. package/dist/api/ProviderApi.d.ts.map +1 -0
  23. package/dist/api/ProviderApi.js +54 -0
  24. package/dist/api/ProviderApi.js.map +1 -0
  25. package/dist/api/handlers.d.ts +5 -0
  26. package/dist/api/handlers.d.ts.map +1 -0
  27. package/dist/api/handlers.js +14 -0
  28. package/dist/api/handlers.js.map +1 -0
  29. package/dist/api/index.d.ts +7 -0
  30. package/dist/api/index.d.ts.map +1 -0
  31. package/dist/api/index.js +25 -0
  32. package/dist/api/index.js.map +1 -0
  33. package/dist/index.d.ts +4 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +22 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/modules/ProsopoCaptchaApi.d.ts +16 -0
  38. package/dist/modules/ProsopoCaptchaApi.d.ts.map +1 -0
  39. package/dist/modules/ProsopoCaptchaApi.js +86 -0
  40. package/dist/modules/ProsopoCaptchaApi.js.map +1 -0
  41. package/dist/modules/ProsopoCaptchaClient.d.ts +26 -0
  42. package/dist/modules/ProsopoCaptchaClient.d.ts.map +1 -0
  43. package/dist/modules/ProsopoCaptchaClient.js +95 -0
  44. package/dist/modules/ProsopoCaptchaClient.js.map +1 -0
  45. package/dist/modules/ProsopoCaptchaStateClient.d.ts +17 -0
  46. package/dist/modules/ProsopoCaptchaStateClient.d.ts.map +1 -0
  47. package/dist/modules/ProsopoCaptchaStateClient.js +97 -0
  48. package/dist/modules/ProsopoCaptchaStateClient.js.map +1 -0
  49. package/dist/modules/client.d.ts +9 -0
  50. package/dist/modules/client.d.ts.map +1 -0
  51. package/dist/modules/client.js +40 -0
  52. package/dist/modules/client.js.map +1 -0
  53. package/dist/modules/contract.d.ts +7 -0
  54. package/dist/modules/contract.d.ts.map +1 -0
  55. package/dist/modules/contract.js +30 -0
  56. package/dist/modules/contract.js.map +1 -0
  57. package/dist/modules/extension.d.ts +3 -0
  58. package/dist/modules/extension.d.ts.map +1 -0
  59. package/dist/modules/extension.js +25 -0
  60. package/dist/modules/extension.js.map +1 -0
  61. package/dist/modules/index.d.ts +8 -0
  62. package/dist/modules/index.d.ts.map +1 -0
  63. package/dist/modules/index.js +26 -0
  64. package/dist/modules/index.js.map +1 -0
  65. package/dist/modules/storage.d.ts +14 -0
  66. package/dist/modules/storage.d.ts.map +1 -0
  67. package/dist/modules/storage.js +35 -0
  68. package/dist/modules/storage.js.map +1 -0
  69. package/dist/types/api.d.ts +41 -0
  70. package/dist/types/api.d.ts.map +1 -0
  71. package/dist/types/api.js +22 -0
  72. package/dist/types/api.js.map +1 -0
  73. package/dist/types/client.d.ts +60 -0
  74. package/dist/types/client.d.ts.map +1 -0
  75. package/dist/types/client.js +3 -0
  76. package/dist/types/client.js.map +1 -0
  77. package/dist/types/contract.d.ts +5 -0
  78. package/dist/types/contract.d.ts.map +1 -0
  79. package/dist/types/contract.js +3 -0
  80. package/dist/types/contract.js.map +1 -0
  81. package/dist/types/index.d.ts +4 -0
  82. package/dist/types/index.d.ts.map +1 -0
  83. package/dist/types/index.js +22 -0
  84. package/dist/types/index.js.map +1 -0
  85. package/package.json +1 -1
  86. package/src/modules/ProsopoCaptchaClient.ts +3 -2
  87. package/src/modules/contract.ts +5 -1
  88. package/src/types/api.ts +1 -0
@@ -0,0 +1,7 @@
1
+ export declare abstract class AsyncFactory {
2
+ constructor();
3
+ static create(...args: any[]): Promise<any>;
4
+ abstract init(...args: any[]): Promise<this>;
5
+ }
6
+ export default AsyncFactory;
7
+ //# sourceMappingURL=AsyncFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AsyncFactory.d.ts","sourceRoot":"","sources":["../../src/api/AsyncFactory.ts"],"names":[],"mappings":"AAeA,8BAAsB,YAAY;;WAMV,MAAM,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;aAIzB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAEtD;AAED,eAAe,YAAY,CAAC"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AsyncFactory = void 0;
4
+ // Copyright (C) 2021-2022 Prosopo (UK) Ltd.
5
+ // This file is part of procaptcha <https://github.com/prosopo-io/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
+ class AsyncFactory {
20
+ constructor() {
21
+ throw new Error("Use `create` factory method");
22
+ }
23
+ static async create(...args) {
24
+ return await Object.create(this.prototype).init(...args);
25
+ }
26
+ }
27
+ exports.AsyncFactory = AsyncFactory;
28
+ exports.default = AsyncFactory;
29
+ //# sourceMappingURL=AsyncFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AsyncFactory.js","sourceRoot":"","sources":["../../src/api/AsyncFactory.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AAC5C,8EAA8E;AAC9E,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,MAAsB,YAAY;IAE9B;QACI,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACnD,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,IAAW;QACrC,OAAO,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7D,CAAC;CAIJ;AAZD,oCAYC;AAED,kBAAe,YAAY,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { InjectedAccountWithMeta, InjectedExtension } from "@polkadot/extension-inject/types";
2
+ import { IExtensionInterface } from "../types/client";
3
+ import AsyncFactory from "./AsyncFactory";
4
+ export declare class Extension extends AsyncFactory implements IExtensionInterface {
5
+ private extension;
6
+ private account;
7
+ private accounts;
8
+ private injectedExtensions;
9
+ init(): Promise<this>;
10
+ checkExtension(): Promise<void>;
11
+ getExtension(): InjectedExtension;
12
+ private setExtension;
13
+ getAccounts(): InjectedAccountWithMeta[];
14
+ private setAccounts;
15
+ getAccount(): InjectedAccountWithMeta | undefined;
16
+ setAccount(address: string): void;
17
+ unsetAccount(): void;
18
+ getDefaultAccount(): InjectedAccountWithMeta | undefined;
19
+ setDefaultAccount(): void;
20
+ }
21
+ export default Extension;
22
+ //# sourceMappingURL=Extension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Extension.d.ts","sourceRoot":"","sources":["../../src/api/Extension.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AAG7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAG1C,qBAAa,SAAU,SAAQ,YAAa,YAAW,mBAAmB;IAEtE,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,OAAO,CAAsC;IACrD,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,kBAAkB,CAAsB;IAEnC,IAAI;IAOJ,cAAc;IAWpB,YAAY;YAIL,YAAY;IAYnB,WAAW;YAIJ,WAAW;IASlB,UAAU;IAIV,UAAU,CAAC,OAAO,EAAE,MAAM;IAY1B,YAAY;IAKZ,iBAAiB;IAKjB,iBAAiB;CAc3B;AAED,eAAe,SAAS,CAAC"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Extension = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Copyright (C) 2021-2022 Prosopo (UK) Ltd.
6
+ // This file is part of procaptcha <https://github.com/prosopo-io/procaptcha>.
7
+ //
8
+ // procaptcha is free software: you can redistribute it and/or modify
9
+ // it under the terms of the GNU General Public License as published by
10
+ // the Free Software Foundation, either version 3 of the License, or
11
+ // (at your option) any later version.
12
+ //
13
+ // procaptcha is distributed in the hope that it will be useful,
14
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ // GNU General Public License for more details.
17
+ //
18
+ // You should have received a copy of the GNU General Public License
19
+ // along with procaptcha. If not, see <http://www.gnu.org/licenses/>.
20
+ const extension_dapp_1 = require("@polkadot/extension-dapp");
21
+ const storage_1 = tslib_1.__importDefault(require("../modules/storage"));
22
+ const AsyncFactory_1 = tslib_1.__importDefault(require("./AsyncFactory"));
23
+ class Extension extends AsyncFactory_1.default {
24
+ extension;
25
+ account;
26
+ accounts;
27
+ injectedExtensions;
28
+ async init() {
29
+ await this.checkExtension();
30
+ await this.setAccounts();
31
+ await this.setExtension();
32
+ return this;
33
+ }
34
+ async checkExtension() {
35
+ try {
36
+ this.injectedExtensions = await (0, extension_dapp_1.web3Enable)('Prosopo');
37
+ }
38
+ catch (err) {
39
+ throw new Error(err);
40
+ }
41
+ if (!this.injectedExtensions.length) {
42
+ throw new Error("No extension found");
43
+ }
44
+ }
45
+ getExtension() {
46
+ return this.extension;
47
+ }
48
+ async setExtension() {
49
+ try {
50
+ // https://polkadot.js.org/docs/extension/cookbook/
51
+ this.extension = await (0, extension_dapp_1.web3FromSource)(this.accounts[0].meta.source);
52
+ }
53
+ catch (err) {
54
+ throw new Error(err);
55
+ }
56
+ if (!this.extension) {
57
+ throw new Error("Extension not found");
58
+ }
59
+ }
60
+ getAccounts() {
61
+ return this.accounts;
62
+ }
63
+ async setAccounts() {
64
+ try {
65
+ this.accounts = await (0, extension_dapp_1.web3Accounts)();
66
+ }
67
+ catch (err) {
68
+ throw new Error(err);
69
+ }
70
+ this.setDefaultAccount();
71
+ }
72
+ getAccount() {
73
+ return this.account;
74
+ }
75
+ setAccount(address) {
76
+ if (!this.accounts.length) {
77
+ throw new Error("No accounts found");
78
+ }
79
+ const account = this.accounts.find(acc => acc.address === address);
80
+ if (!account) {
81
+ throw new Error("Account not found");
82
+ }
83
+ this.account = account;
84
+ storage_1.default.setAccount(account.address);
85
+ }
86
+ unsetAccount() {
87
+ this.account = undefined;
88
+ storage_1.default.setAccount("");
89
+ }
90
+ getDefaultAccount() {
91
+ const defaultAccount = storage_1.default.getAccount();
92
+ return this.accounts.find(acc => acc.address === defaultAccount);
93
+ }
94
+ setDefaultAccount() {
95
+ const defaultAccount = storage_1.default.getAccount();
96
+ if (defaultAccount) {
97
+ this.setAccount(defaultAccount);
98
+ }
99
+ }
100
+ }
101
+ exports.Extension = Extension;
102
+ exports.default = Extension;
103
+ //# sourceMappingURL=Extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Extension.js","sourceRoot":"","sources":["../../src/api/Extension.ts"],"names":[],"mappings":";;;;AAAA,4CAA4C;AAC5C,8EAA8E;AAC9E,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,6DAAoF;AAGpF,yEAAyC;AAEzC,0EAA0C;AAG1C,MAAa,SAAU,SAAQ,sBAAY;IAE/B,SAAS,CAAoB;IAC7B,OAAO,CAAsC;IAC7C,QAAQ,CAA4B;IACpC,kBAAkB,CAAsB;IAEzC,KAAK,CAAC,IAAI;QACb,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAC5B,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QACzB,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,KAAK,CAAC,cAAc;QACvB,IAAI;YACA,IAAI,CAAC,kBAAkB,GAAG,MAAM,IAAA,2BAAU,EAAC,SAAS,CAAC,CAAC;SACzD;QAAC,OAAO,GAAG,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;SACxB;QACD,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE;YACjC,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;SACzC;IACL,CA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AC;IACxC,CAAC;IAEM,YAAY;QACf,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,iBAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC;IAEM,iBAAiB;QACpB,MAAM,cAAc,GAAG,iBAAO,CAAC,UAAU,EAAE,CAAC;QAC5C,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,KAAK,cAAc,CAAC,CAAC;IACrE,CAAC;IAEM,iBAAiB;QACpB,MAAM,cAAc,GAAG,iBAAO,CAAC,UAAU,EAAE,CAAC;QAC5C,IAAI,cAAc,EAAE;YAChB,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;SACnC;IACL,CAAC;CASJ;AA9FD,8BA8FC;AAED,kBAAe,SAAS,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { AxiosInstance, AxiosResponse } from "axios";
2
+ export declare class HttpClientBase {
3
+ protected readonly axios: AxiosInstance;
4
+ constructor(baseURL: string, prefix?: string);
5
+ protected responseHandler: (response: AxiosResponse) => any;
6
+ protected errorHandler: (error: any) => Promise<never>;
7
+ }
8
+ export default HttpClientBase;
9
+ //# sourceMappingURL=HttpClientBase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpClientBase.d.ts","sourceRoot":"","sources":["../../src/api/HttpClientBase.ts"],"names":[],"mappings":"AAeA,OAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE5D,qBAAa,cAAc;IAEzB,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;gBAE5B,OAAO,EAAE,MAAM,EAAE,MAAM,SAAK;IAMxC,SAAS,CAAC,eAAe,aAAc,aAAa,SAGnD;IAED,SAAS,CAAC,YAAY,UAAW,GAAG,oBAAoC;CAEzE;AAED,eAAe,cAAc,CAAC"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpClientBase = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Copyright (C) 2021-2022 Prosopo (UK) Ltd.
6
+ // This file is part of procaptcha <https://github.com/prosopo-io/procaptcha>.
7
+ //
8
+ // procaptcha is free software: you can redistribute it and/or modify
9
+ // it under the terms of the GNU General Public License as published by
10
+ // the Free Software Foundation, either version 3 of the License, or
11
+ // (at your option) any later version.
12
+ //
13
+ // procaptcha is distributed in the hope that it will be useful,
14
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ // GNU General Public License for more details.
17
+ //
18
+ // You should have received a copy of the GNU General Public License
19
+ // along with procaptcha. If not, see <http://www.gnu.org/licenses/>.
20
+ const axios_1 = tslib_1.__importDefault(require("axios"));
21
+ class HttpClientBase {
22
+ axios;
23
+ constructor(baseURL, prefix = "") {
24
+ baseURL = baseURL + prefix;
25
+ this.axios = axios_1.default.create({ baseURL });
26
+ this.axios.interceptors.response.use(this.responseHandler, this.errorHandler);
27
+ }
28
+ responseHandler = (response) => {
29
+ console.log("API REQUEST", response.request);
30
+ return response.data;
31
+ };
32
+ errorHandler = (error) => Promise.reject(error.response);
33
+ }
34
+ exports.HttpClientBase = HttpClientBase;
35
+ exports.default = HttpClientBase;
36
+ //# sourceMappingURL=HttpClientBase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpClientBase.js","sourceRoot":"","sources":["../../src/api/HttpClientBase.ts"],"names":[],"mappings":";;;;AAAA,4CAA4C;AAC5C,8EAA8E;AAC9E,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,0DAA4D;AAE5D,MAAa,cAAc;IAEN,KAAK,CAAgB;IAExC,YAAY,OAAe,EAAE,MAAM,GAAG,EAAE;QACtC,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,eAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAChF,CAAC;IAES,eAAe,GAAG,CAAC,QAAuB,EAAE,EAAE;QACtD,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC7C,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC,CAAA;IAES,YAAY,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;CAEzE;AAjBD,wCAiBC;AAED,kBAAe,cAAc,CAAC"}
@@ -0,0 +1,12 @@
1
+ import ProsopoContractBase from "./ProsopoContractBase";
2
+ import { Signer } from '@polkadot/api/types';
3
+ import { TransactionResponse } from '../types';
4
+ import { ProsopoRandomProviderResponse } from "../types";
5
+ import { CaptchaSolutionCommitment } from "@prosopo/contract";
6
+ export declare class ProsopoContract extends ProsopoContractBase {
7
+ getRandomProvider(): Promise<ProsopoRandomProviderResponse>;
8
+ getCaptchaSolutionCommitment(commitmentId: string): Promise<CaptchaSolutionCommitment>;
9
+ dappUserCommit(signer: Signer, captchaDatasetId: string, userMerkleTreeRoot: string, providerAddress: string): Promise<TransactionResponse>;
10
+ }
11
+ export default ProsopoContract;
12
+ //# sourceMappingURL=ProsopoContract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProsopoContract.d.ts","sourceRoot":"","sources":["../../src/api/ProsopoContract.ts"],"names":[],"mappings":"AAgBA,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAG9D,qBAAa,eAAgB,SAAQ,mBAAmB;IAEvC,iBAAiB,IAAI,OAAO,CAAC,6BAA6B,CAAC;IAI3D,4BAA4B,CAAC,YAAY,EAAE,MAAM;IAIjD,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAM3J;AAED,eAAe,eAAe,CAAC"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProsopoContract = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Copyright (C) 2021-2022 Prosopo (UK) Ltd.
6
+ // This file is part of procaptcha <https://github.com/prosopo-io/procaptcha>.
7
+ //
8
+ // procaptcha is free software: you can redistribute it and/or modify
9
+ // it under the terms of the GNU General Public License as published by
10
+ // the Free Software Foundation, either version 3 of the License, or
11
+ // (at your option) any later version.
12
+ //
13
+ // procaptcha is distributed in the hope that it will be useful,
14
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ // GNU General Public License for more details.
17
+ //
18
+ // You should have received a copy of the GNU General Public License
19
+ // along with procaptcha. If not, see <http://www.gnu.org/licenses/>.
20
+ // import {Hash} from '@polkadot/types/interfaces';
21
+ const ProsopoContractBase_1 = tslib_1.__importDefault(require("./ProsopoContractBase"));
22
+ // TODO: import return types from provider: separate types/common package.
23
+ class ProsopoContract extends ProsopoContractBase_1.default {
24
+ async getRandomProvider() {
25
+ return await this.query('getRandomActiveProvider', [this.account.address, this.dappAddress]);
26
+ }
27
+ async getCaptchaSolutionCommitment(commitmentId) {
28
+ return await this.query('getCaptchaSolutionCommitment', [commitmentId]);
29
+ }
30
+ async dappUserCommit(signer, captchaDatasetId, userMerkleTreeRoot, providerAddress) {
31
+ return await this.transaction(signer, 'dappUserCommit', [this.dappAddress, captchaDatasetId, userMerkleTreeRoot, providerAddress]);
32
+ }
33
+ }
34
+ exports.ProsopoContract = ProsopoContract;
35
+ exports.default = ProsopoContract;
36
+ //# sourceMappingURL=ProsopoContract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProsopoContract.js","sourceRoot":"","sources":["../../src/api/ProsopoContract.ts"],"names":[],"mappings":";;;;AAAA,4CAA4C;AAC5C,8EAA8E;AAC9E,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,mDAAmD;AACnD,wFAAwD;AAMxD,0EAA0E;AAC1E,MAAa,eAAgB,SAAQ,6BAAmB;IAE7C,KAAK,CAAC,iBAAiB;QAC1B,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,yBAAyB,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAkC,CAAC;IAClI,CAAC;IAEM,KAAK,CAAC,4BAA4B,CAAC,YAAoB;QAC1D,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,8BAA8B,EAAE,CAAC,YAAY,CAAC,CAA8B,CAAC;IACzG,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,MAAc,EAAE,gBAAwB,EAAE,kBAA0B,EAAE,eAAuB;QACrH,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,CAAC,CAAC,CAAC;IACvI,CAAC;CAIJ;AAhBD,0CAgBC;AAED,kBAAe,eAAe,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { ApiPromise } from "@polkadot/api";
2
+ import { Abi, ContractPromise } from "@polkadot/api-contract";
3
+ import { InjectedAccountWithMeta } from "@polkadot/extension-inject/types";
4
+ import { AnyJson } from "@polkadot/types/types/codec";
5
+ import { ProviderInterface } from "@polkadot/rpc-provider/types";
6
+ import { Signer } from "@polkadot/api/types";
7
+ import { TransactionResponse } from '../types';
8
+ import AsyncFactory from "./AsyncFactory";
9
+ export declare class ProsopoContractBase extends AsyncFactory {
10
+ protected api: ApiPromise;
11
+ protected abi: Abi;
12
+ protected contract: ContractPromise;
13
+ protected account: InjectedAccountWithMeta;
14
+ protected dappAddress: string;
15
+ address: string;
16
+ /**
17
+ * @param address
18
+ * @param dappAddress
19
+ * @param account
20
+ * @param providerInterface
21
+ */
22
+ init(address: string, dappAddress: string, account: InjectedAccountWithMeta, providerInterface: ProviderInterface): Promise<this>;
23
+ getApi(): ApiPromise;
24
+ getContract(): ContractPromise;
25
+ getAccount(): InjectedAccountWithMeta;
26
+ getDappAddress(): string;
27
+ query<T>(method: string, args: any[]): Promise<T | AnyJson | null>;
28
+ transaction(signer: Signer, method: string, args: any[]): Promise<TransactionResponse>;
29
+ }
30
+ export default ProsopoContractBase;
31
+ //# sourceMappingURL=ProsopoContractBase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProsopoContractBase.d.ts","sourceRoot":"","sources":["../../src/api/ProsopoContractBase.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAqB,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAG3E,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,qBAAa,mBAAoB,SAAQ,YAAY;IAEnD,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC;IAC1B,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;IACnB,SAAS,CAAC,QAAQ,EAAE,eAAe,CAAC;IACpC,SAAS,CAAC,OAAO,EAAE,uBAAuB,CAAC;IAC3C,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC;IAEvB,OAAO,EAAE,MAAM,CAAC;IAEvB;;;;;OAKG;IACU,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,iBAAiB;IAUvH,MAAM,IAAI,UAAU;IAIpB,WAAW,IAAI,eAAe;IAI9B,UAAU,IAAI,uBAAuB;IAIrC,cAAc,IAAI,MAAM;IAIlB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,OAAO,GAAG,IAAI,CAAC;IA0BlE,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAwEpG;AAED,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProsopoContractBase = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Copyright (C) 2021-2022 Prosopo (UK) Ltd.
6
+ // This file is part of procaptcha <https://github.com/prosopo-io/procaptcha>.
7
+ //
8
+ // procaptcha is free software: you can redistribute it and/or modify
9
+ // it under the terms of the GNU General Public License as published by
10
+ // the Free Software Foundation, either version 3 of the License, or
11
+ // (at your option) any later version.
12
+ //
13
+ // procaptcha is distributed in the hope that it will be useful,
14
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ // GNU General Public License for more details.
17
+ //
18
+ // You should have received a copy of the GNU General Public License
19
+ // along with procaptcha. If not, see <http://www.gnu.org/licenses/>.
20
+ const api_1 = require("@polkadot/api");
21
+ const api_contract_1 = require("@polkadot/api-contract");
22
+ const contract_1 = require("@prosopo/contract");
23
+ const AsyncFactory_1 = tslib_1.__importDefault(require("./AsyncFactory"));
24
+ class ProsopoContractBase extends AsyncFactory_1.default {
25
+ api;
26
+ abi;
27
+ contract;
28
+ account;
29
+ dappAddress;
30
+ address;
31
+ /**
32
+ * @param address
33
+ * @param dappAddress
34
+ * @param account
35
+ * @param providerInterface
36
+ */
37
+ async init(address, dappAddress, account, providerInterface) {
38
+ this.api = await api_1.ApiPromise.create({ provider: providerInterface });
39
+ this.abi = new api_contract_1.Abi(contract_1.abiJson, this.api.registry.getChainProperties());
40
+ this.contract = new api_contract_1.ContractPromise(this.api, this.abi, address);
41
+ this.address = address;
42
+ this.dappAddress = dappAddress;
43
+ this.account = account;
44
+ return this;
45
+ }
46
+ getApi() {
47
+ return this.api;
48
+ }
49
+ getContract() {
50
+ return this.contract;
51
+ }
52
+ getAccount() {
53
+ return this.account;
54
+ }
55
+ getDappAddress() {
56
+ return this.dappAddress;
57
+ }
58
+ async query(method, args) {
59
+ try {
60
+ const abiMessage = this.abi.findMessage(method);
61
+ const response = await this.contract.query[method](this.account.address, {}, ...(0, contract_1.encodeStringArgs)(abiMessage, args));
62
+ console.log("QUERY RESPONSE", method, args, response);
63
+ if (response.result.isOk) {
64
+ if (response.output) {
65
+ return (0, contract_1.unwrap)(response.output.toHuman());
66
+ }
67
+ else {
68
+ return null;
69
+ }
70
+ }
71
+ else {
72
+ throw new contract_1.ProsopoContractError(response.result.asErr);
73
+ }
74
+ }
75
+ catch (e) {
76
+ console.error("ERROR", e);
77
+ return null;
78
+ }
79
+ }
80
+ // https://polkadot.js.org/docs/api/cookbook/tx/
81
+ // https://polkadot.js.org/docs/api/start/api.tx.subs/
82
+ async transaction(signer, method, args) {
83
+ // TODO if DEBUG==true || env.development
84
+ const queryBeforeTx = await this.query(method, args);
85
+ console.log("QUERY BEFORE TX....................", queryBeforeTx);
86
+ const abiMessage = this.abi.findMessage(method);
87
+ const extrinsic = this.contract.tx[method]({}, ...(0, contract_1.encodeStringArgs)(abiMessage, args));
88
+ // this.api.setSigner(signer);
89
+ // const response = await buildTx(this.api.registry, extrinsic, this.account.address, { signer });
90
+ // console.log("buildTx RESPONSE", response);
91
+ // return;
92
+ return new Promise((resolve, reject) => {
93
+ extrinsic.signAndSend(this.account.address, { signer }, (result) => {
94
+ const { dispatchError, dispatchInfo, events, internalError, status, txHash, txIndex } = result;
95
+ console.log("TX STATUS", status.type);
96
+ console.log("IS FINALIZED", status?.isFinalized);
97
+ console.log("IN BLOCK", status?.isInBlock);
98
+ console.log("EVENTS", events);
99
+ if (internalError) {
100
+ console.error("internalError", internalError);
101
+ reject(internalError);
102
+ return;
103
+ }
104
+ if (dispatchError) {
105
+ console.error("dispatchError", dispatchError);
106
+ reject(dispatchError);
107
+ return;
108
+ }
109
+ // [Ready, InBlock, Finalized...]
110
+ // Instant seal ON.
111
+ if (status?.isInBlock) {
112
+ const blockHash = status.asInBlock.toHex();
113
+ resolve({ dispatchError, dispatchInfo, events, internalError, status, txHash, txIndex, blockHash });
114
+ }
115
+ // TODO
116
+ // Instant seal OFF.
117
+ // if (status?.isFinalized) {
118
+ // const blockHash = status.asFinalized.toHex();
119
+ // resolve({ dispatchError, dispatchInfo, events, internalError, status, txHash, txIndex, blockHash });
120
+ // }
121
+ })
122
+ .catch((e) => {
123
+ console.error("signAndSend ERROR", e);
124
+ reject(e);
125
+ });
126
+ });
127
+ }
128
+ }
129
+ exports.ProsopoContractBase = ProsopoContractBase;
130
+ exports.default = ProsopoContractBase;
131
+ //# sourceMappingURL=ProsopoContractBase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProsopoContractBase.js","sourceRoot":"","sources":["../../src/api/ProsopoContractBase.ts"],"names":[],"mappings":";;;;AAAA,4CAA4C;AAC5C,8EAA8E;AAC9E,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,uCAA8D;AAC9D,yDAA8D;AAG9D,gDAA4F;AAK5F,0EAA0C;AAE1C,MAAa,mBAAoB,SAAQ,sBAAY;IAEzC,GAAG,CAAa;IAChB,GAAG,CAAM;IACT,QAAQ,CAAkB;IAC1B,OAAO,CAA0B;IACjC,WAAW,CAAS;IAEvB,OAAO,CAAS;IAEvB;;;;;OAKG;IACI,KAAK,CAAC,IAAI,CAAC,OAAe,EAAE,WAAmB,EAAE,OAAgC,EAAE,iBAAoC;QAC5H,IAAI,CAAC,GAAG,GAAG,MAAM,gBAAU,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,iBAAiB,EAAE,CAAC,CAAC;QACpE,IAAI,CAAC,GAAG,GAAG,IAAI,kBAAG,CAAC,kBAAO,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;QACpE,IAAI,CAAC,QAAQ,GAAG,IAAI,8BAAe,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACjE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO,IA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E,aAAa,CAAC,CAAC;oBAC9C,MAAM,CAAC,aAAa,CAAC,CAAC;oBAEtB,OAAO;iBACR;gBAED,iCAAiC;gBAEjC,mBAAmB;gBACnB,IAAI,MAAM,EAAE,SAAS,EAAE;oBAErB,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;oBAE3C,OAAO,CAAC,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;iBAErG;gBAED,OAAO;gBACP,oBAAoB;gBACpB,6BAA6B;gBAE7B,kDAAkD;gBAElD,yGAAyG;gBAEzG,IAAI;YAEN,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBACX,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC;gBACtC,MAAM,CAAC,CAAC,CAAC,CAAC;YACZ,CAAC,CAAC,CAAC;QAEL,CAAC,CAAC,CAAC;IAEL,CAAC;CAEF;AA5ID,kDA4IC;AAED,kBAAe,mBAAmB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import HttpClientBase from "./HttpClientBase";
2
+ import { ProsopoCaptchaConfig, ProsopoRandomProviderResponse, GetCaptchaResponse, CaptchaSolution, CaptchaSolutionResponse } from '../types';
3
+ export declare class ProviderApi extends HttpClientBase {
4
+ protected config: ProsopoCaptchaConfig;
5
+ constructor(config: ProsopoCaptchaConfig);
6
+ /**
7
+ *
8
+ * @deprecated use ProsopoContract$getRandomProvider instead.
9
+ */
10
+ getRandomProvider(): Promise<import("axios").AxiosResponse<any, any>>;
11
+ getProviders(): Promise<{
12
+ accounts: string[];
13
+ }>;
14
+ getContractAddress(): Promise<{
15
+ contractAddress: string;
16
+ }>;
17
+ getCaptchaChallenge(randomProvider: ProsopoRandomProviderResponse): Promise<GetCaptchaResponse>;
18
+ submitCaptchaSolution(blockHash: string, captchas: CaptchaSolution[], requestHash: string, txHash: string, userAccount: string): Promise<CaptchaSolutionResponse>;
19
+ }
20
+ export default ProviderApi;
21
+ //# sourceMappingURL=ProviderApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProviderApi.d.ts","sourceRoot":"","sources":["../../src/api/ProviderApi.ts"],"names":[],"mappings":"AAeA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,oBAAoB,EAAE,6BAA6B,EAAE,kBAAkB,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAE7I,qBAAa,WAAY,SAAQ,cAAc;IAE7C,SAAS,CAAC,MAAM,EAAE,oBAAoB,CAAC;gBAE3B,MAAM,EAAE,oBAAoB;IAKxC;;;OAGG;IACI,iBAAiB;IAKjB,YAAY,IAAI,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAC,CAAC;IAI7C,kBAAkB,IAAI,OAAO,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAC,CAAC;IAIxD,mBAAmB,CAAC,cAAc,EAAE,6BAA6B,GAAI,OAAO,CAAC,kBAAkB,CAAC;IAOhG,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAI,OAAO,CAAC,uBAAuB,CAAC;CAI1K;AAED,eAAe,WAAW,CAAC"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProviderApi = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Copyright (C) 2021-2022 Prosopo (UK) Ltd.
6
+ // This file is part of procaptcha <https://github.com/prosopo-io/procaptcha>.
7
+ //
8
+ // procaptcha is free software: you can redistribute it and/or modify
9
+ // it under the terms of the GNU General Public License as published by
10
+ // the Free Software Foundation, either version 3 of the License, or
11
+ // (at your option) any later version.
12
+ //
13
+ // procaptcha is distributed in the hope that it will be useful,
14
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ // GNU General Public License for more details.
17
+ //
18
+ // You should have received a copy of the GNU General Public License
19
+ // along with procaptcha. If not, see <http://www.gnu.org/licenses/>.
20
+ const HttpClientBase_1 = tslib_1.__importDefault(require("./HttpClientBase"));
21
+ const storage_1 = tslib_1.__importDefault(require("../modules/storage"));
22
+ class ProviderApi extends HttpClientBase_1.default {
23
+ config;
24
+ constructor(config) {
25
+ super(config['providerApi.baseURL'], config['providerApi.prefix']);
26
+ this.config = config;
27
+ }
28
+ /**
29
+ *
30
+ * @deprecated use ProsopoContract$getRandomProvider instead.
31
+ */
32
+ getRandomProvider() {
33
+ const userAccount = storage_1.default.getAccount();
34
+ return this.axios.get(`/random_provider/${userAccount}/${this.config['dappAccount']}`);
35
+ }
36
+ getProviders() {
37
+ return this.axios.get(`/providers`);
38
+ }
39
+ getContractAddress() {
40
+ return this.axios.get(`/contract_address`);
41
+ }
42
+ getCaptchaChallenge(randomProvider) {
43
+ let { provider, blockNumber } = randomProvider;
44
+ blockNumber = blockNumber.replace(/,/g, ''); // TODO: middleware schema parser/validator.
45
+ const userAccount = storage_1.default.getAccount();
46
+ return this.axios.get(`/provider/captcha/${provider.captchaDatasetId}/${userAccount}/${this.config['dappAccount']}/${blockNumber}`);
47
+ }
48
+ submitCaptchaSolution(blockHash, captchas, requestHash, txHash, userAccount) {
49
+ return this.axios.post(`/provider/solution`, { blockHash, captchas, requestHash, txHash, userAccount, dappAccount: this.config['dappAccount'] });
50
+ }
51
+ }
52
+ exports.ProviderApi = ProviderApi;
53
+ exports.default = ProviderApi;
54
+ //# sourceMappingURL=ProviderApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProviderApi.js","sourceRoot":"","sources":["../../src/api/ProviderApi.ts"],"names":[],"mappings":";;;;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AAW,EAAE,CAAC,CAAC;IACtI,CAAC;IAEM,qBAAqB,CAAC,SAAiB,EAAE,QAA2B,EAAE,WAAmB,EAAE,MAAc,EAAE,WAAmB;QACnI,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,oBAAoB,EAAE,EAAC,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAC,CAAC,CAAC;IACjJ,CAAC;CAEF;AArCD,kCAqCC;AAED,kBAAe,WAAW,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { AxiosResponse } from "axios";
2
+ export declare class ProsopoApiError extends Error {
3
+ constructor(error: AxiosResponse, context?: string, ...params: any[]);
4
+ }
5
+ //# sourceMappingURL=handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/api/handlers.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAEpC,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,KAAK,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE;CAUrE"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProsopoApiError = void 0;
4
+ class ProsopoApiError extends Error {
5
+ constructor(error, context, ...params) {
6
+ super(`${error.data.message ? error.data.message : error.statusText}`);
7
+ this.name = context && `${ProsopoApiError.name}@${context}` || ProsopoApiError.name;
8
+ // TODO: if env.debug
9
+ console.error('\n********************* ERROR *********************\n');
10
+ console.error(this.cause, this.stack, ...params);
11
+ }
12
+ }
13
+ exports.ProsopoApiError = ProsopoApiError;
14
+ //# sourceMappingURL=handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/api/handlers.ts"],"names":[],"mappings":";;;AAiBA,MAAa,eAAgB,SAAQ,KAAK;IACxC,YAAY,KAAoB,EAAE,OAAgB,EAAE,GAAG,MAAa;QAElE,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAA;QAEtE,IAAI,CAAC,IAAI,GAAG,OAAO,IAAI,GAAG,eAAe,CAAC,IAAI,IAAI,OAAO,EAAE,IAAI,eAAe,CAAC,IAAI,CAAC;QAEpF,qBAAqB;QACrB,OAAO,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC;QACvE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,MAAM,CAAC,CAAC;IACnD,CAAC;CACF;AAXD,0CAWC"}
@@ -0,0 +1,7 @@
1
+ export * from './AsyncFactory';
2
+ export * from './Extension';
3
+ export * from './HttpClientBase';
4
+ export * from './ProsopoContract';
5
+ export * from './ProsopoContractBase';
6
+ export * from './ProviderApi';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAeA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ // Copyright (C) 2021-2022 Prosopo (UK) Ltd.
5
+ // This file is part of procaptcha <https://github.com/prosopo-io/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
+ tslib_1.__exportStar(require("./AsyncFactory"), exports);
20
+ tslib_1.__exportStar(require("./Extension"), exports);
21
+ tslib_1.__exportStar(require("./HttpClientBase"), exports);
22
+ tslib_1.__exportStar(require("./ProsopoContract"), exports);
23
+ tslib_1.__exportStar(require("./ProsopoContractBase"), exports);
24
+ tslib_1.__exportStar(require("./ProviderApi"), exports);
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AAC5C,8EAA8E;AAC9E,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,yDAA+B;AAC/B,sDAA4B;AAC5B,2DAAiC;AACjC,4DAAkC;AAClC,gEAAsC;AACtC,wDAA8B"}