@prosopo/procaptcha 0.1.9 → 0.1.13
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/assets/contracts-page.png +0 -0
- package/dist/api/Extension.d.ts +16 -0
- package/dist/api/Extension.d.ts.map +1 -0
- package/dist/api/Extension.js +9 -0
- package/dist/api/Extension.js.map +1 -0
- package/dist/api/ExtensionWeb2.d.ts +11 -25
- package/dist/api/ExtensionWeb2.d.ts.map +1 -1
- package/dist/api/ExtensionWeb2.js +89 -94
- package/dist/api/ExtensionWeb2.js.map +1 -1
- package/dist/api/ExtensionWeb3.d.ts +6 -52
- package/dist/api/ExtensionWeb3.d.ts.map +1 -1
- package/dist/api/ExtensionWeb3.js +24 -142
- package/dist/api/ExtensionWeb3.js.map +1 -1
- package/dist/api/HttpClientBase.d.ts +1 -1
- package/dist/api/HttpClientBase.d.ts.map +1 -1
- package/dist/api/HttpClientBase.js +2 -2
- package/dist/api/HttpClientBase.js.map +1 -1
- package/dist/api/errors.d.ts +16 -0
- package/dist/api/errors.d.ts.map +1 -0
- package/dist/api/errors.js +34 -0
- package/dist/api/errors.js.map +1 -0
- package/dist/api/handlers.d.ts +2 -2
- package/dist/api/handlers.d.ts.map +1 -1
- package/dist/api/handlers.js +2 -10
- package/dist/api/handlers.js.map +1 -1
- package/dist/api/index.d.ts +0 -4
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +0 -4
- package/dist/api/index.js.map +1 -1
- package/dist/api/sign.d.ts +5 -0
- package/dist/api/sign.d.ts.map +1 -0
- package/dist/api/sign.js +16 -0
- package/dist/api/sign.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/modules/Manager.d.ts +22 -0
- package/dist/modules/Manager.d.ts.map +1 -0
- package/dist/modules/Manager.js +419 -0
- package/dist/modules/Manager.js.map +1 -0
- package/dist/modules/ProsopoCaptchaApi.d.ts +15 -15
- package/dist/modules/ProsopoCaptchaApi.d.ts.map +1 -1
- package/dist/modules/ProsopoCaptchaApi.js +60 -60
- package/dist/modules/ProsopoCaptchaApi.js.map +1 -1
- package/dist/modules/canvas.d.ts.map +1 -1
- package/dist/modules/canvas.js +84 -21
- package/dist/modules/canvas.js.map +1 -1
- package/dist/modules/index.d.ts +1 -6
- package/dist/modules/index.d.ts.map +1 -1
- package/dist/modules/index.js +1 -6
- package/dist/modules/index.js.map +1 -1
- package/dist/modules/storage.d.ts +10 -0
- package/dist/modules/storage.d.ts.map +1 -1
- package/dist/modules/storage.js +18 -3
- package/dist/modules/storage.js.map +1 -1
- package/dist/types/api.d.ts +8 -26
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/client.d.ts +4 -60
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/contract.d.ts +1 -1
- package/dist/types/contract.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/manager.d.ts +60 -0
- package/dist/types/manager.d.ts.map +1 -0
- package/dist/types/manager.js +3 -0
- package/dist/types/manager.js.map +1 -0
- package/dist/types/utils.d.ts +2 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/utils.js +3 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/utils.d.ts +2 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +8 -0
- package/dist/utils/utils.js.map +1 -0
- package/package.json +21 -23
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -37
- package/LICENSE +0 -201
- package/dist/api/AccountCreator.d.ts +0 -19
- package/dist/api/AccountCreator.d.ts.map +0 -1
- package/dist/api/AccountCreator.js +0 -88
- package/dist/api/AccountCreator.js.map +0 -1
- package/dist/api/AsyncFactory.d.ts +0 -7
- package/dist/api/AsyncFactory.d.ts.map +0 -1
- package/dist/api/AsyncFactory.js +0 -30
- package/dist/api/AsyncFactory.js.map +0 -1
- package/dist/api/ProsopoContract.d.ts +0 -13
- package/dist/api/ProsopoContract.d.ts.map +0 -1
- package/dist/api/ProsopoContract.js +0 -38
- package/dist/api/ProsopoContract.js.map +0 -1
- package/dist/api/ProsopoContractBase.d.ts +0 -32
- package/dist/api/ProsopoContractBase.d.ts.map +0 -1
- package/dist/api/ProsopoContractBase.js +0 -132
- package/dist/api/ProsopoContractBase.js.map +0 -1
- package/dist/api/ProviderApi.d.ts +0 -14
- package/dist/api/ProviderApi.d.ts.map +0 -1
- package/dist/api/ProviderApi.js +0 -53
- package/dist/api/ProviderApi.js.map +0 -1
- package/dist/modules/ProsopoCaptchaClient.d.ts +0 -26
- package/dist/modules/ProsopoCaptchaClient.d.ts.map +0 -1
- package/dist/modules/ProsopoCaptchaClient.js +0 -112
- package/dist/modules/ProsopoCaptchaClient.js.map +0 -1
- package/dist/modules/ProsopoCaptchaStateClient.d.ts +0 -18
- package/dist/modules/ProsopoCaptchaStateClient.d.ts.map +0 -1
- package/dist/modules/ProsopoCaptchaStateClient.js +0 -111
- package/dist/modules/ProsopoCaptchaStateClient.js.map +0 -1
- package/dist/modules/client.d.ts +0 -9
- package/dist/modules/client.d.ts.map +0 -1
- package/dist/modules/client.js +0 -40
- package/dist/modules/client.js.map +0 -1
- package/dist/modules/contract.d.ts +0 -7
- package/dist/modules/contract.d.ts.map +0 -1
- package/dist/modules/contract.js +0 -42
- package/dist/modules/contract.js.map +0 -1
- package/dist/modules/extension.d.ts +0 -4
- package/dist/modules/extension.d.ts.map +0 -1
- package/dist/modules/extension.js +0 -31
- package/dist/modules/extension.js.map +0 -1
- package/tsconfig.json +0 -24
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Account } from '../types';
|
|
2
|
+
import { ProcaptchaClientConfig } from '@prosopo/types';
|
|
3
|
+
/**
|
|
4
|
+
* Class to interface with accounts.
|
|
5
|
+
*/
|
|
6
|
+
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
|
+
abstract getAccount(config: ProcaptchaClientConfig): Promise<Account>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=Extension.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Extension.d.ts","sourceRoot":"","sources":["../../src/api/Extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAEvD;;GAEG;AACH,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,SAAS;IACnC;;;;;;OAMG;aACa,UAAU,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC;CAC/E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Extension.js","sourceRoot":"","sources":["../../src/api/Extension.ts"],"names":[],"mappings":";;AAGA;;GAEG;AACH,MAA8B,SAAS;CAStC;AATD,4BASC"}
|
|
@@ -1,27 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
protected wsProvider: WsProvider;
|
|
13
|
-
init(wsProvider: WsProvider, accountCreatorConfig: AccountCreatorConfig, source: string): Promise<this>;
|
|
14
|
-
checkExtension(): Promise<void>;
|
|
15
|
-
getExtension(): InjectedExtension | undefined;
|
|
16
|
-
private setExtension;
|
|
17
|
-
getAccounts(): InjectedAccountWithMeta[];
|
|
18
|
-
private setAccounts;
|
|
19
|
-
getAccount(): InjectedAccountWithMeta | undefined;
|
|
20
|
-
setAccount(address: string): void;
|
|
21
|
-
unsetAccount(): void;
|
|
22
|
-
getDefaultAccount(): InjectedAccountWithMeta | undefined;
|
|
23
|
-
setDefaultAccount(): void;
|
|
24
|
-
createAccount(): Promise<any>;
|
|
1
|
+
import { Account } from '../types';
|
|
2
|
+
import { ProcaptchaClientConfig } from '@prosopo/types';
|
|
3
|
+
import Extension from './Extension';
|
|
4
|
+
/**
|
|
5
|
+
* Class for interfacing with web3 accounts.
|
|
6
|
+
*/
|
|
7
|
+
export default class ExtWeb2 extends Extension {
|
|
8
|
+
getAccount(config: ProcaptchaClientConfig): Promise<Account>;
|
|
9
|
+
private createExtension;
|
|
10
|
+
private createAccount;
|
|
11
|
+
private getFingerprint;
|
|
25
12
|
}
|
|
26
|
-
export default ExtensionWeb2;
|
|
27
13
|
//# sourceMappingURL=ExtensionWeb2.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionWeb2.d.ts","sourceRoot":"","sources":["../../src/api/ExtensionWeb2.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ExtensionWeb2.d.ts","sourceRoot":"","sources":["../../src/api/ExtensionWeb2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAMlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAQvD,OAAO,SAAS,MAAM,aAAa,CAAA;AAMnC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,SAAS;IAC7B,UAAU,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC;YAa3D,eAAe;YAiCf,aAAa;YAmCb,cAAc;CAU/B"}
|
|
@@ -1,106 +1,101 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExtensionWeb2 = void 0;
|
|
4
3
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
4
|
+
const api_1 = require("@polkadot/api");
|
|
5
|
+
const ws_1 = require("@polkadot/rpc-provider/ws");
|
|
6
|
+
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
7
|
+
const bip39_1 = require("@polkadot/util-crypto/mnemonic/bip39");
|
|
8
|
+
const Manager_1 = require("../modules/Manager");
|
|
9
|
+
const common_1 = require("@prosopo/common");
|
|
10
|
+
const canvas_1 = require("../modules/canvas");
|
|
11
|
+
const util_1 = require("@polkadot/util");
|
|
12
|
+
const Extension_1 = tslib_1.__importDefault(require("./Extension"));
|
|
13
|
+
const fingerprintjs_1 = tslib_1.__importStar(require("@fingerprintjs/fingerprintjs"));
|
|
9
14
|
const Signer_1 = tslib_1.__importDefault(require("@polkadot/extension-base/page/Signer"));
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
async checkExtension() {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
getExtension() {
|
|
28
|
-
return this.extension;
|
|
15
|
+
/**
|
|
16
|
+
* Class for interfacing with web3 accounts.
|
|
17
|
+
*/
|
|
18
|
+
class ExtWeb2 extends Extension_1.default {
|
|
19
|
+
async getAccount(config) {
|
|
20
|
+
const network = (0, Manager_1.getNetwork)(config);
|
|
21
|
+
const wsProvider = new ws_1.WsProvider(network.endpoint);
|
|
22
|
+
const account = await this.createAccount(wsProvider);
|
|
23
|
+
const extension = await this.createExtension(account);
|
|
24
|
+
return {
|
|
25
|
+
account,
|
|
26
|
+
extension,
|
|
27
|
+
};
|
|
29
28
|
}
|
|
30
|
-
async
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
async createExtension(account) {
|
|
30
|
+
const signer = new Signer_1.default(async () => {
|
|
31
|
+
return;
|
|
32
|
+
});
|
|
33
|
+
// 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.
|
|
34
|
+
signer.signRaw = async (payload) => {
|
|
35
|
+
const signature = account.keypair.sign(payload.data);
|
|
36
|
+
return {
|
|
37
|
+
id: 1,
|
|
38
|
+
signature: (0, util_1.u8aToHex)(signature),
|
|
39
|
+
};
|
|
39
40
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
return {
|
|
42
|
+
accounts: {
|
|
43
|
+
get: async () => {
|
|
44
|
+
// there is only ever 1 account
|
|
45
|
+
return [account];
|
|
46
|
+
},
|
|
47
|
+
subscribe: () => {
|
|
48
|
+
// do nothing, there will never be account changes
|
|
49
|
+
return () => {
|
|
50
|
+
return;
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
name: 'procaptcha-web2',
|
|
55
|
+
version: '0.1.11',
|
|
56
|
+
signer,
|
|
52
57
|
};
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
getAccounts() {
|
|
56
|
-
return this.accounts;
|
|
57
|
-
}
|
|
58
|
-
async setAccounts(accounts) {
|
|
59
|
-
try {
|
|
60
|
-
this.accounts = accounts;
|
|
61
|
-
}
|
|
62
|
-
catch (err) {
|
|
63
|
-
throw new contract_1.ProsopoEnvError(err);
|
|
64
|
-
}
|
|
65
|
-
this.setDefaultAccount();
|
|
66
|
-
}
|
|
67
|
-
getAccount() {
|
|
68
|
-
return this.account;
|
|
69
58
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
59
|
+
async createAccount(wsProvider) {
|
|
60
|
+
const params = {
|
|
61
|
+
area: { width: 300, height: 300 },
|
|
62
|
+
offsetParameter: 2001000001,
|
|
63
|
+
multiplier: 15000,
|
|
64
|
+
fontSizeFactor: 1.5,
|
|
65
|
+
maxShadowBlur: 50,
|
|
66
|
+
numberOfRounds: 5,
|
|
67
|
+
seed: 42,
|
|
68
|
+
};
|
|
69
|
+
const browserEntropy = await this.getFingerprint();
|
|
70
|
+
const canvasEntropy = (0, canvas_1.picassoCanvas)(params.numberOfRounds, params.seed, params);
|
|
71
|
+
const entropy = (0, common_1.hexHash)([canvasEntropy, browserEntropy].join(''), 128).slice(2);
|
|
72
|
+
const u8Entropy = (0, util_1.stringToU8a)(entropy);
|
|
73
|
+
const mnemonic = (0, bip39_1.entropyToMnemonic)(u8Entropy);
|
|
74
|
+
const api = await api_1.ApiPromise.create({ provider: wsProvider });
|
|
75
|
+
const type = 'sr25519';
|
|
76
|
+
const keyring = new api_1.Keyring({ type, ss58Format: api.registry.chainSS58 });
|
|
77
|
+
await (0, util_crypto_1.cryptoWaitReady)();
|
|
78
|
+
const keypair = keyring.addFromMnemonic(mnemonic);
|
|
79
|
+
const address = keypair.address.length === 42
|
|
80
|
+
? keypair.address
|
|
81
|
+
: (0, util_crypto_1.encodeAddress)((0, util_crypto_1.decodeAddress)(keypair.address), api.registry.chainSS58);
|
|
82
|
+
return {
|
|
83
|
+
address,
|
|
84
|
+
type,
|
|
85
|
+
name: address,
|
|
86
|
+
keypair,
|
|
87
|
+
};
|
|
94
88
|
}
|
|
95
|
-
async
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
await
|
|
100
|
-
|
|
101
|
-
|
|
89
|
+
async getFingerprint() {
|
|
90
|
+
// Initialize an agent at application startup.
|
|
91
|
+
const fpPromise = fingerprintjs_1.default.load();
|
|
92
|
+
// Get the visitor identifier when you need it.
|
|
93
|
+
const fp = await fpPromise;
|
|
94
|
+
const result = await fp.get();
|
|
95
|
+
// strip out the components that change in incognito mode
|
|
96
|
+
const { screenFrame, ...componentsReduced } = result.components;
|
|
97
|
+
return (0, fingerprintjs_1.hashComponents)(componentsReduced);
|
|
102
98
|
}
|
|
103
99
|
}
|
|
104
|
-
exports.
|
|
105
|
-
exports.default = ExtensionWeb2;
|
|
100
|
+
exports.default = ExtWeb2;
|
|
106
101
|
//# sourceMappingURL=ExtensionWeb2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionWeb2.js","sourceRoot":"","sources":["../../src/api/ExtensionWeb2.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ExtensionWeb2.js","sourceRoot":"","sources":["../../src/api/ExtensionWeb2.ts"],"names":[],"mappings":";;;AACA,uCAAmD;AAMnD,kDAAsD;AACtD,uDAAqF;AACrF,gEAAwE;AACxE,gDAA+C;AAC/C,4CAAyC;AACzC,8CAAiD;AACjD,yCAAsD;AACtD,oEAAmC;AACnC,sFAA4E;AAC5E,0FAAyD;AAIzD;;GAEG;AACH,MAAqB,OAAQ,SAAQ,mBAAS;IACnC,KAAK,CAAC,UAAU,CAAC,MAA8B;QAClD,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,MAAM,CAAC,CAAA;QAClC,MAAM,UAAU,GAAG,IAAI,eAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CA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AAC,IAAI,EAAE,CAAA;QACtC,+CAA+C;QAC/C,MAAM,EAAE,GAAG,MAAM,SAAS,CAAA;QAC1B,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,EAAE,CAAA;QAC7B,yDAAyD;QACzD,MAAM,EAAE,WAAW,EAAE,GAAG,iBAAiB,EAAE,GAAG,MAAM,CAAC,UAAU,CAAA;QAC/D,OAAO,IAAA,8BAAc,EAAC,iBAAiB,CAAC,CAAA;IAC5C,CAAC;CACJ;AA5FD,0BA4FC"}
|
|
@@ -1,56 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { Account } from '../types';
|
|
2
|
+
import { ProcaptchaClientConfig } from '@prosopo/types';
|
|
3
|
+
import Extension from './Extension';
|
|
4
4
|
/**
|
|
5
|
-
* Class
|
|
5
|
+
* Class for interfacing with web3 accounts.
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
private account;
|
|
10
|
-
private accounts;
|
|
11
|
-
private injectedExtensions;
|
|
12
|
-
private source;
|
|
13
|
-
init(source: string): Promise<this>;
|
|
14
|
-
checkExtension(): Promise<void>;
|
|
15
|
-
/**
|
|
16
|
-
* Get the extension for the selected account.
|
|
17
|
-
* @returns the extension holding the selected account. Undefined if no account selected.
|
|
18
|
-
*/
|
|
19
|
-
getExtension(): InjectedExtension | undefined;
|
|
20
|
-
/**
|
|
21
|
-
* Set the extension for the selected account.
|
|
22
|
-
*/
|
|
23
|
-
private setExtension;
|
|
24
|
-
/**
|
|
25
|
-
* Get all accounts across all extensions.
|
|
26
|
-
* @returns all accounts across all extensions.
|
|
27
|
-
*/
|
|
28
|
-
getAccounts(): InjectedAccountWithMeta[];
|
|
29
|
-
/**
|
|
30
|
-
* Discover accounts across all extensions.
|
|
31
|
-
*/
|
|
32
|
-
private setAccounts;
|
|
33
|
-
/**
|
|
34
|
-
* Get the selected account.
|
|
35
|
-
* @returns the selected account.
|
|
36
|
-
*/
|
|
37
|
-
getAccount(): InjectedAccountWithMeta | undefined;
|
|
38
|
-
/**
|
|
39
|
-
* Set the selected account.
|
|
40
|
-
* @param address the address of the account to be selected.
|
|
41
|
-
*/
|
|
42
|
-
setAccount(address: string): void;
|
|
43
|
-
unsetAccount(): void;
|
|
44
|
-
/**
|
|
45
|
-
* Get the last used account via the address held in local storage.
|
|
46
|
-
* @returns the account associated with the address held in storage.
|
|
47
|
-
*/
|
|
48
|
-
getDefaultAccount(): InjectedAccountWithMeta | undefined;
|
|
49
|
-
/**
|
|
50
|
-
* Select the account using the last used account address held in local storage.
|
|
51
|
-
*/
|
|
52
|
-
setDefaultAccount(): void;
|
|
53
|
-
createAccount(): Promise<undefined>;
|
|
7
|
+
export default class ExtWeb3 extends Extension {
|
|
8
|
+
getAccount(config: ProcaptchaClientConfig): Promise<Account>;
|
|
54
9
|
}
|
|
55
|
-
export default ExtensionWeb3;
|
|
56
10
|
//# sourceMappingURL=ExtensionWeb3.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionWeb3.d.ts","sourceRoot":"","sources":["../../src/api/ExtensionWeb3.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ExtensionWeb3.d.ts","sourceRoot":"","sources":["../../src/api/ExtensionWeb3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAGlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAEvD,OAAO,SAAS,MAAM,aAAa,CAAA;AAEnC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,SAAS;IAC7B,UAAU,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC;CAwB5E"}
|
|
@@ -1,151 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExtensionWeb3 = void 0;
|
|
4
3
|
const tslib_1 = require("tslib");
|
|
5
|
-
|
|
6
|
-
// This file is part of procaptcha <https://github.com/prosopo/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/>.
|
|
4
|
+
const errors_1 = require("./errors");
|
|
20
5
|
const extension_dapp_1 = require("@polkadot/extension-dapp");
|
|
21
|
-
const
|
|
22
|
-
const AsyncFactory_1 = tslib_1.__importDefault(require("./AsyncFactory"));
|
|
23
|
-
const contract_1 = require("@prosopo/contract");
|
|
6
|
+
const Extension_1 = tslib_1.__importDefault(require("./Extension"));
|
|
24
7
|
/**
|
|
25
|
-
* Class
|
|
8
|
+
* Class for interfacing with web3 accounts.
|
|
26
9
|
*/
|
|
27
|
-
class
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
catch (err) {
|
|
49
|
-
throw new contract_1.ProsopoEnvError(err);
|
|
50
|
-
}
|
|
51
|
-
if (!this.injectedExtensions.length) {
|
|
52
|
-
throw new contract_1.ProsopoEnvError("WIDGET.NO_EXTENSION_FOUND");
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Get the extension for the selected account.
|
|
57
|
-
* @returns the extension holding the selected account. Undefined if no account selected.
|
|
58
|
-
*/
|
|
59
|
-
getExtension() {
|
|
60
|
-
return this.extension;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Set the extension for the selected account.
|
|
64
|
-
*/
|
|
65
|
-
async setExtension() {
|
|
66
|
-
try {
|
|
67
|
-
// https://polkadot.js.org/docs/extension/cookbook/
|
|
68
|
-
this.extension = await (0, extension_dapp_1.web3FromSource)(this.accounts[0].meta.source);
|
|
69
|
-
}
|
|
70
|
-
catch (err) {
|
|
71
|
-
throw new contract_1.ProsopoEnvError(err);
|
|
72
|
-
}
|
|
73
|
-
if (!this.extension) {
|
|
74
|
-
throw new contract_1.ProsopoEnvError("WIDGET.EXTENSION_NOT_FOUND");
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Get all accounts across all extensions.
|
|
79
|
-
* @returns all accounts across all extensions.
|
|
80
|
-
*/
|
|
81
|
-
getAccounts() {
|
|
82
|
-
return this.accounts;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Discover accounts across all extensions.
|
|
86
|
-
*/
|
|
87
|
-
async setAccounts() {
|
|
88
|
-
this.accounts = await (0, extension_dapp_1.web3Accounts)();
|
|
89
|
-
// get the last used account address from storage
|
|
90
|
-
const lastUsedAccountAddress = storage_1.default.getAccount();
|
|
91
|
-
// lookup this account in the discovered accounts
|
|
92
|
-
const account = this.accounts.find(acc => acc.address === lastUsedAccountAddress);
|
|
93
|
-
// if found then set it
|
|
94
|
-
if (account) {
|
|
95
|
-
this.account = account;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
this.account = undefined;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Get the selected account.
|
|
103
|
-
* @returns the selected account.
|
|
104
|
-
*/
|
|
105
|
-
getAccount() {
|
|
106
|
-
return this.account;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Set the selected account.
|
|
110
|
-
* @param address the address of the account to be selected.
|
|
111
|
-
*/
|
|
112
|
-
setAccount(address) {
|
|
113
|
-
if (!this.accounts.length) {
|
|
114
|
-
throw new contract_1.ProsopoEnvError("WIDGET.NO_ACCOUNTS_FOUND");
|
|
115
|
-
}
|
|
116
|
-
const account = this.accounts.find(acc => acc.address === address);
|
|
117
|
-
if (!account) {
|
|
118
|
-
throw new contract_1.ProsopoEnvError("WIDGET.ACCOUNT_NOT_FOUND");
|
|
119
|
-
}
|
|
120
|
-
this.account = account;
|
|
121
|
-
storage_1.default.setAccount(account.address);
|
|
122
|
-
}
|
|
123
|
-
unsetAccount() {
|
|
124
|
-
this.account = undefined;
|
|
125
|
-
// update the last used account to empty
|
|
126
|
-
storage_1.default.setAccount("");
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Get the last used account via the address held in local storage.
|
|
130
|
-
* @returns the account associated with the address held in storage.
|
|
131
|
-
*/
|
|
132
|
-
getDefaultAccount() {
|
|
133
|
-
const defaultAccount = storage_1.default.getAccount();
|
|
134
|
-
return this.accounts.find(acc => acc.address === defaultAccount);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Select the account using the last used account address held in local storage.
|
|
138
|
-
*/
|
|
139
|
-
setDefaultAccount() {
|
|
140
|
-
const defaultAccount = storage_1.default.getAccount();
|
|
141
|
-
if (defaultAccount) {
|
|
142
|
-
this.setAccount(defaultAccount);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
async createAccount() {
|
|
146
|
-
return undefined;
|
|
10
|
+
class ExtWeb3 extends Extension_1.default {
|
|
11
|
+
async getAccount(config) {
|
|
12
|
+
const { dappName, userAccountAddress: address } = config;
|
|
13
|
+
if (!address) {
|
|
14
|
+
throw new errors_1.AccountNotFoundError('No account address provided');
|
|
15
|
+
}
|
|
16
|
+
// enable access to all extensions
|
|
17
|
+
const extensions = await (0, extension_dapp_1.web3Enable)(dappName);
|
|
18
|
+
if (extensions.length === 0) {
|
|
19
|
+
throw new errors_1.ExtensionNotFoundError();
|
|
20
|
+
}
|
|
21
|
+
// search through all extensions for the one that has the account
|
|
22
|
+
for (const extension of extensions) {
|
|
23
|
+
const accounts = await extension.accounts.get();
|
|
24
|
+
const account = accounts.find((account) => account.address === address);
|
|
25
|
+
if (account) {
|
|
26
|
+
return { account, extension };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
throw new errors_1.AccountNotFoundError('No account found matching ' + address);
|
|
147
30
|
}
|
|
148
31
|
}
|
|
149
|
-
exports.
|
|
150
|
-
exports.default = ExtensionWeb3;
|
|
32
|
+
exports.default = ExtWeb3;
|
|
151
33
|
//# sourceMappingURL=ExtensionWeb3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionWeb3.js","sourceRoot":"","sources":["../../src/api/ExtensionWeb3.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ExtensionWeb3.js","sourceRoot":"","sources":["../../src/api/ExtensionWeb3.ts"],"names":[],"mappings":";;;AACA,qCAAuE;AAGvE,6DAAqD;AACrD,oEAAmC;AAEnC;;GAEG;AACH,MAAqB,OAAQ,SAAQ,mBAAS;IACnC,KAAK,CAAC,UAAU,CAAC,MAA8B;QAClD,MAAM,EAAE,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;QAExD,IAAI,CAAC,OAAO,EAAE;YACV,MAAM,IAAI,6BAAoB,CAAC,6BAA6B,CAAC,CAAA;SAChE;QAED,kCAAkC;QAClC,MAAM,UAAU,GAAwB,MAAM,IAAA,2BAAU,EAAC,QAAQ,CAAC,CAAA;QAClE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;YACzB,MAAM,IAAI,+BAAsB,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,6BAAoB,CAAC,4BAA4B,GAAG,OAAO,CAAC,CAAA;IAC1E,CAAC;CACJ;AAzBD,0BAyBC"}
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"HttpClientBase.d.ts","sourceRoot":"","sources":["../../src/api/HttpClientBase.ts"],"names":[],"mappings":"AAeA,OAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAE3D,qBAAa,cAAc;IACvB,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAA;gBAE3B,OAAO,EAAE,MAAM,EAAE,MAAM,SAAK;IAMxC,SAAS,CAAC,eAAe,aAAc,aAAa,SAGnD;IAED,SAAS,CAAC,YAAY,UAAW,GAAG,oBAAmC;CAC1E;AAED,eAAe,cAAc,CAAA"}
|
|
@@ -20,13 +20,13 @@ const tslib_1 = require("tslib");
|
|
|
20
20
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
21
21
|
class HttpClientBase {
|
|
22
22
|
axios;
|
|
23
|
-
constructor(baseURL, prefix =
|
|
23
|
+
constructor(baseURL, prefix = '') {
|
|
24
24
|
baseURL = baseURL + prefix;
|
|
25
25
|
this.axios = axios_1.default.create({ baseURL });
|
|
26
26
|
this.axios.interceptors.response.use(this.responseHandler, this.errorHandler);
|
|
27
27
|
}
|
|
28
28
|
responseHandler = (response) => {
|
|
29
|
-
console.log(
|
|
29
|
+
console.log('API REQUEST', response.request);
|
|
30
30
|
return response.data;
|
|
31
31
|
};
|
|
32
32
|
errorHandler = (error) => Promise.reject(error.response);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClientBase.js","sourceRoot":"","sources":["../../src/api/HttpClientBase.ts"],"names":[],"mappings":";;;;AAAA,4CAA4C;AAC5C,2EAA2E;AAC3E,EAAE;AACF,qEAAqE;AACrE,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,gEAAgE;AAChE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,sEAAsE;AACtE,
|
|
1
|
+
{"version":3,"file":"HttpClientBase.js","sourceRoot":"","sources":["../../src/api/HttpClientBase.ts"],"names":[],"mappings":";;;;AAAA,4CAA4C;AAC5C,2EAA2E;AAC3E,EAAE;AACF,qEAAqE;AACrE,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,gEAAgE;AAChE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,sEAAsE;AACtE,0DAA2D;AAE3D,MAAa,cAAc;IACJ,KAAK,CAAe;IAEvC,YAAY,OAAe,EAAE,MAAM,GAAG,EAAE;QACpC,OAAO,GAAG,OAAO,GAAG,MAAM,CAAA;QAC1B,IAAI,CAAC,KAAK,GAAG,eAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;QACtC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;IACjF,CAAC;IAES,eAAe,GAAG,CAAC,QAAuB,EAAE,EAAE;QACpD,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;QAC5C,OAAO,QAAQ,CAAC,IAAI,CAAA;IACxB,CAAC,CAAA;IAES,YAAY,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;CAC1E;AAfD,wCAeC;AAED,kBAAe,cAAc,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class NoExtensionsFoundError extends Error {
|
|
2
|
+
constructor(msg?: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class AccountCreationUnsupportedError extends Error {
|
|
5
|
+
constructor(msg?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class AccountNotFoundError extends Error {
|
|
8
|
+
constructor(msg?: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class ExtensionNotFoundError extends Error {
|
|
11
|
+
constructor(msg?: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class ExpiredError extends Error {
|
|
14
|
+
constructor(msg?: string);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/api/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,sBAAuB,SAAQ,KAAK;gBACjC,GAAG,CAAC,EAAE,MAAM;CAG3B;AAED,qBAAa,+BAAgC,SAAQ,KAAK;gBAC1C,GAAG,CAAC,EAAE,MAAM;CAG3B;AAED,qBAAa,oBAAqB,SAAQ,KAAK;gBAC/B,GAAG,CAAC,EAAE,MAAM;CAG3B;AAED,qBAAa,sBAAuB,SAAQ,KAAK;gBACjC,GAAG,CAAC,EAAE,MAAM;CAG3B;AAED,qBAAa,YAAa,SAAQ,KAAK;gBACvB,GAAG,CAAC,EAAE,MAAM;CAG3B"}
|