@prosopo/procaptcha 0.1.0 → 0.1.3
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.
- package/README.md +13 -0
- package/dist/api/AsyncFactory.d.ts +7 -0
- package/dist/api/AsyncFactory.d.ts.map +1 -0
- package/{src/api/AsyncFactory.ts → dist/api/AsyncFactory.js} +8 -9
- package/dist/api/AsyncFactory.js.map +1 -0
- package/dist/api/Extension.d.ts +22 -0
- package/dist/api/Extension.d.ts.map +1 -0
- package/{src/api/Extension.ts → dist/api/Extension.js} +39 -56
- package/dist/api/Extension.js.map +1 -0
- package/dist/api/HttpClientBase.d.ts +9 -0
- package/dist/api/HttpClientBase.d.ts.map +1 -0
- package/dist/api/HttpClientBase.js +36 -0
- package/dist/api/HttpClientBase.js.map +1 -0
- package/dist/api/ProsopoContract.d.ts +13 -0
- package/dist/api/ProsopoContract.d.ts.map +1 -0
- package/{src/api/ProsopoContract.ts → dist/api/ProsopoContract.js} +18 -20
- package/dist/api/ProsopoContract.js.map +1 -0
- package/dist/api/ProsopoContractBase.d.ts +31 -0
- package/dist/api/ProsopoContractBase.d.ts.map +1 -0
- package/dist/api/ProsopoContractBase.js +131 -0
- package/dist/api/ProsopoContractBase.js.map +1 -0
- package/dist/api/ProviderApi.d.ts +21 -0
- package/dist/api/ProviderApi.d.ts.map +1 -0
- package/dist/api/ProviderApi.js +54 -0
- package/dist/api/ProviderApi.js.map +1 -0
- package/dist/api/handlers.d.ts +5 -0
- package/dist/api/handlers.d.ts.map +1 -0
- package/dist/api/handlers.js +14 -0
- package/dist/api/handlers.js.map +1 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.d.ts.map +1 -0
- package/{src/api/handlers.ts → dist/api/index.js} +10 -14
- package/dist/api/index.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/{src/modules/index.ts → dist/index.js} +7 -7
- package/dist/index.js.map +1 -0
- package/dist/modules/ProsopoCaptchaApi.d.ts +16 -0
- package/dist/modules/ProsopoCaptchaApi.d.ts.map +1 -0
- package/dist/modules/ProsopoCaptchaApi.js +86 -0
- package/dist/modules/ProsopoCaptchaApi.js.map +1 -0
- package/dist/modules/ProsopoCaptchaClient.d.ts +27 -0
- package/dist/modules/ProsopoCaptchaClient.d.ts.map +1 -0
- package/dist/modules/ProsopoCaptchaClient.js +97 -0
- package/dist/modules/ProsopoCaptchaClient.js.map +1 -0
- package/dist/modules/ProsopoCaptchaStateClient.d.ts +17 -0
- package/dist/modules/ProsopoCaptchaStateClient.d.ts.map +1 -0
- package/dist/modules/ProsopoCaptchaStateClient.js +104 -0
- package/dist/modules/ProsopoCaptchaStateClient.js.map +1 -0
- package/dist/modules/client.d.ts +9 -0
- package/dist/modules/client.d.ts.map +1 -0
- package/{src/modules/client.ts → dist/modules/client.js} +13 -12
- package/dist/modules/client.js.map +1 -0
- package/dist/modules/contract.d.ts +7 -0
- package/dist/modules/contract.d.ts.map +1 -0
- package/{src/api/HttpClientBase.ts → dist/modules/contract.js} +14 -21
- package/dist/modules/contract.js.map +1 -0
- package/dist/modules/extension.d.ts +3 -0
- package/dist/modules/extension.d.ts.map +1 -0
- package/{src/api/index.ts → dist/modules/extension.js} +10 -6
- package/dist/modules/extension.js.map +1 -0
- package/dist/modules/index.d.ts +8 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/{src/modules/contract.ts → dist/modules/index.js} +11 -8
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/storage.d.ts +14 -0
- package/dist/modules/storage.d.ts.map +1 -0
- package/{src/modules/storage.ts → dist/modules/storage.js} +7 -7
- package/dist/modules/storage.js.map +1 -0
- package/dist/types/api.d.ts +45 -0
- package/dist/types/api.d.ts.map +1 -0
- package/{src/types/index.ts → dist/types/api.js} +7 -3
- package/dist/types/api.js.map +1 -0
- package/{src/types/client.ts → dist/types/client.d.ts} +8 -36
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/client.js +3 -0
- package/dist/types/client.js.map +1 -0
- package/dist/types/contract.d.ts +5 -0
- package/dist/types/contract.d.ts.map +1 -0
- package/dist/types/contract.js +3 -0
- package/dist/types/contract.js.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/{src/modules/extension.ts → dist/types/index.js} +7 -5
- package/dist/types/index.js.map +1 -0
- package/img/contracts-page.png +0 -0
- package/package.json +2 -2
- package/tsconfig.tsbuildinfo +1 -0
- package/src/api/ProsopoContractBase.ts +0 -169
- package/src/api/ProviderApi.ts +0 -59
- package/src/index.ts +0 -18
- package/src/modules/ProsopoCaptchaApi.ts +0 -105
- package/src/modules/ProsopoCaptchaClient.ts +0 -131
- package/src/modules/ProsopoCaptchaStateClient.ts +0 -146
- package/src/types/api.ts +0 -79
- package/src/types/contract.ts +0 -21
- package/tests/mocks/browser.ts +0 -25
- package/tests/modules/client.test.ts +0 -56
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Procaptcha
|
|
2
|
+
|
|
3
|
+
Contains interfaces for accessing the Prosopo [protocol](https://github.com/prosopo-io/protocol/) contract, Prosopo [provider](https://github.com/prosopo-io/provider) API and the captcha client state via the `ProsopoCaptchaClient`, `ProsopoCaptchaApi` and `ProsopoCaptchaStateClient` classes.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
The Dapp smart contract account must be [registered](https://github.com/prosopo-io/protocol/blob/5cb282a911522bfbf29d34d1830badee3eecec83/contracts/lib.rs#L698-L737) in the Prosopo [protocol](https://github.com/prosopo-io/protocol/) contract in order to interact with the Prosopo protocol. You can complete Dapp registration by navigating to [polkadot-js apps](https://polkadot.js.org/apps/) and using the contracts page.
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
This repository can be imported into any JavaScript framework and used to create a CAPTCHA User Interface. See, for example, the [procaptcha-react](https://github.com/prosopo-io/procaptcha-react) repository.
|
|
@@ -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"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsyncFactory = void 0;
|
|
1
4
|
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
2
5
|
// This file is part of procaptcha <https://github.com/prosopo-io/procaptcha>.
|
|
3
6
|
//
|
|
@@ -13,18 +16,14 @@
|
|
|
13
16
|
//
|
|
14
17
|
// You should have received a copy of the GNU General Public License
|
|
15
18
|
// along with procaptcha. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
class AsyncFactory {
|
|
18
20
|
constructor() {
|
|
19
21
|
throw new Error("Use `create` factory method");
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
public static async create(...args: any[]) {
|
|
23
|
+
static async create(...args) {
|
|
23
24
|
return await Object.create(this.prototype).init(...args);
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
public abstract init(...args: any[]): Promise<this>;
|
|
27
|
-
|
|
28
26
|
}
|
|
29
|
-
|
|
30
|
-
|
|
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"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Extension = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
1
5
|
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
2
6
|
// This file is part of procaptcha <https://github.com/prosopo-io/procaptcha>.
|
|
3
7
|
//
|
|
@@ -13,73 +17,62 @@
|
|
|
13
17
|
//
|
|
14
18
|
// You should have received a copy of the GNU General Public License
|
|
15
19
|
// along with procaptcha. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
private extension: InjectedExtension;
|
|
27
|
-
private account: InjectedAccountWithMeta | undefined;
|
|
28
|
-
private accounts: InjectedAccountWithMeta[];
|
|
29
|
-
private injectedExtensions: InjectedExtension[];
|
|
30
|
-
|
|
31
|
-
public async init() {
|
|
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() {
|
|
32
29
|
await this.checkExtension();
|
|
33
30
|
await this.setAccounts();
|
|
34
31
|
await this.setExtension();
|
|
35
32
|
return this;
|
|
36
33
|
}
|
|
37
|
-
|
|
38
|
-
public async checkExtension() {
|
|
34
|
+
async checkExtension() {
|
|
39
35
|
try {
|
|
40
|
-
this.injectedExtensions = await web3Enable('Prosopo');
|
|
41
|
-
}
|
|
36
|
+
this.injectedExtensions = await (0, extension_dapp_1.web3Enable)('Prosopo');
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
42
39
|
throw new Error(err);
|
|
43
40
|
}
|
|
44
41
|
if (!this.injectedExtensions.length) {
|
|
45
42
|
throw new Error("No extension found");
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
|
-
|
|
49
|
-
public getExtension() {
|
|
45
|
+
getExtension() {
|
|
50
46
|
return this.extension;
|
|
51
47
|
}
|
|
52
|
-
|
|
53
|
-
private async setExtension() {
|
|
48
|
+
async setExtension() {
|
|
54
49
|
try {
|
|
55
50
|
// https://polkadot.js.org/docs/extension/cookbook/
|
|
56
|
-
this.extension = await web3FromSource(this.accounts[0].meta.source);
|
|
57
|
-
}
|
|
51
|
+
this.extension = await (0, extension_dapp_1.web3FromSource)(this.accounts[0].meta.source);
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
58
54
|
throw new Error(err);
|
|
59
55
|
}
|
|
60
56
|
if (!this.extension) {
|
|
61
57
|
throw new Error("Extension not found");
|
|
62
58
|
}
|
|
63
59
|
}
|
|
64
|
-
|
|
65
|
-
public getAccounts() {
|
|
60
|
+
getAccounts() {
|
|
66
61
|
return this.accounts;
|
|
67
62
|
}
|
|
68
|
-
|
|
69
|
-
private async setAccounts() {
|
|
63
|
+
async setAccounts() {
|
|
70
64
|
try {
|
|
71
|
-
this.accounts = await web3Accounts();
|
|
72
|
-
}
|
|
65
|
+
this.accounts = await (0, extension_dapp_1.web3Accounts)();
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
73
68
|
throw new Error(err);
|
|
74
69
|
}
|
|
75
70
|
this.setDefaultAccount();
|
|
76
71
|
}
|
|
77
|
-
|
|
78
|
-
public getAccount() {
|
|
72
|
+
getAccount() {
|
|
79
73
|
return this.account;
|
|
80
74
|
}
|
|
81
|
-
|
|
82
|
-
public setAccount(address: string) {
|
|
75
|
+
setAccount(address) {
|
|
83
76
|
if (!this.accounts.length) {
|
|
84
77
|
throw new Error("No accounts found");
|
|
85
78
|
}
|
|
@@ -88,33 +81,23 @@ export class Extension extends AsyncFactory implements IExtensionInterface {
|
|
|
88
81
|
throw new Error("Account not found");
|
|
89
82
|
}
|
|
90
83
|
this.account = account;
|
|
91
|
-
|
|
84
|
+
storage_1.default.setAccount(account.address);
|
|
92
85
|
}
|
|
93
|
-
|
|
94
|
-
public unsetAccount() {
|
|
86
|
+
unsetAccount() {
|
|
95
87
|
this.account = undefined;
|
|
96
|
-
|
|
88
|
+
storage_1.default.setAccount("");
|
|
97
89
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const defaultAccount = storage.getAccount();
|
|
90
|
+
getDefaultAccount() {
|
|
91
|
+
const defaultAccount = storage_1.default.getAccount();
|
|
101
92
|
return this.accounts.find(acc => acc.address === defaultAccount);
|
|
102
93
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const defaultAccount = storage.getAccount();
|
|
94
|
+
setDefaultAccount() {
|
|
95
|
+
const defaultAccount = storage_1.default.getAccount();
|
|
106
96
|
if (defaultAccount) {
|
|
107
97
|
this.setAccount(defaultAccount);
|
|
108
98
|
}
|
|
109
99
|
}
|
|
110
|
-
|
|
111
|
-
// public async signRaw(raw: SignerPayloadRaw) {
|
|
112
|
-
// if (!this.extension.signer) {
|
|
113
|
-
// throw new Error("No signer found");
|
|
114
|
-
// }
|
|
115
|
-
// return this.extension.signer?.signRaw!({ ...raw, address: this.account!.address });
|
|
116
|
-
// }
|
|
117
|
-
|
|
118
100
|
}
|
|
119
|
-
|
|
120
|
-
|
|
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;SAC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AAmB,CAAC,CAAC;SACxC;QACD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,iBAAO,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;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,13 @@
|
|
|
1
|
+
import ProsopoContractBase from "./ProsopoContractBase";
|
|
2
|
+
import { Signer } from '@polkadot/api/types';
|
|
3
|
+
import { ProsopoDappOperatorIsHumanUserResponse, 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
|
+
dappOperatorIsHumanUser(threshold: number): Promise<ProsopoDappOperatorIsHumanUserResponse>;
|
|
11
|
+
}
|
|
12
|
+
export default ProsopoContract;
|
|
13
|
+
//# 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,EAAC,sCAAsC,EAAE,mBAAmB,EAAC,MAAM,UAAU,CAAC;AACrF,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;IAI3I,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,sCAAsC,CAAC;CAO3G;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProsopoContract = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
1
5
|
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
2
6
|
// This file is part of procaptcha <https://github.com/prosopo-io/procaptcha>.
|
|
3
7
|
//
|
|
@@ -14,29 +18,23 @@
|
|
|
14
18
|
// You should have received a copy of the GNU General Public License
|
|
15
19
|
// along with procaptcha. If not, see <http://www.gnu.org/licenses/>.
|
|
16
20
|
// import {Hash} from '@polkadot/types/interfaces';
|
|
17
|
-
|
|
18
|
-
import { Signer } from '@polkadot/api/types';
|
|
19
|
-
import { TransactionResponse } from '../types';
|
|
20
|
-
import { ProsopoRandomProviderResponse } from "../types";
|
|
21
|
-
import { CaptchaSolutionCommitment } from "@prosopo/contract";
|
|
22
|
-
|
|
21
|
+
const ProsopoContractBase_1 = tslib_1.__importDefault(require("./ProsopoContractBase"));
|
|
23
22
|
// TODO: import return types from provider: separate types/common package.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return await this.query('getRandomActiveProvider', [this.account.address, this.dappAddress]) as ProsopoRandomProviderResponse;
|
|
23
|
+
class ProsopoContract extends ProsopoContractBase_1.default {
|
|
24
|
+
async getRandomProvider() {
|
|
25
|
+
return await this.query('getRandomActiveProvider', [this.account.address, this.dappAddress]);
|
|
28
26
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return await this.query('getCaptchaSolutionCommitment', [commitmentId]) as CaptchaSolutionCommitment;
|
|
27
|
+
async getCaptchaSolutionCommitment(commitmentId) {
|
|
28
|
+
return await this.query('getCaptchaSolutionCommitment', [commitmentId]);
|
|
32
29
|
}
|
|
33
|
-
|
|
34
|
-
public async dappUserCommit(signer: Signer, captchaDatasetId: string, userMerkleTreeRoot: string, providerAddress: string): Promise<TransactionResponse> {
|
|
30
|
+
async dappUserCommit(signer, captchaDatasetId, userMerkleTreeRoot, providerAddress) {
|
|
35
31
|
return await this.transaction(signer, 'dappUserCommit', [this.dappAddress, captchaDatasetId, userMerkleTreeRoot, providerAddress]);
|
|
36
32
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
async dappOperatorIsHumanUser(threshold) {
|
|
34
|
+
// TODO get threshold from dapp contract using getStorage or allow override in UI and fallback on contract protection layer?
|
|
35
|
+
return await this.query('dappOperatorIsHumanUser', [this.account.address, threshold]);
|
|
36
|
+
}
|
|
40
37
|
}
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
exports.ProsopoContract = ProsopoContract;
|
|
39
|
+
exports.default = ProsopoContract;
|
|
40
|
+
//# 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;IAEM,KAAK,CAAC,uBAAuB,CAAC,SAAiB;QAClD,4HAA4H;QAC5H,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,yBAAyB,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAA2C,CAAC;IACpI,CAAC;CAIJ;AArBD,0CAqBC;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,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, 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
|