@prosopo/procaptcha 0.1.8 → 0.1.10
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/.eslintrc.js +32 -17
- package/.prettierrc.js +7 -0
- package/dist/api/AsyncFactory.d.ts +7 -0
- package/dist/api/AsyncFactory.d.ts.map +1 -0
- package/dist/api/AsyncFactory.js +30 -0
- package/dist/api/AsyncFactory.js.map +1 -0
- package/dist/api/Extension.d.ts +15 -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 +10 -22
- package/dist/api/ExtensionWeb2.d.ts.map +1 -1
- package/dist/api/ExtensionWeb2.js +79 -86
- package/dist/api/ExtensionWeb2.js.map +1 -1
- package/dist/api/ExtensionWeb3.d.ts +5 -51
- package/dist/api/ExtensionWeb3.d.ts.map +1 -1
- package/dist/api/ExtensionWeb3.js +24 -140
- package/dist/api/ExtensionWeb3.js.map +1 -1
- 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/dist/api/ProsopoContract.js +59 -0
- package/dist/api/ProsopoContract.js.map +1 -0
- package/dist/api/ProsopoContractBase.d.ts +30 -0
- package/dist/api/ProsopoContractBase.d.ts.map +1 -0
- package/dist/api/ProsopoContractBase.js +139 -0
- package/dist/api/ProsopoContractBase.js.map +1 -0
- package/dist/api/errors.d.ts +13 -0
- package/dist/api/errors.d.ts.map +1 -0
- package/dist/api/errors.js +28 -0
- package/dist/api/errors.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 +13 -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/dist/api/index.js +25 -0
- package/dist/api/index.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/Manager.d.ts +13 -0
- package/dist/modules/Manager.d.ts.map +1 -0
- package/dist/modules/Manager.js +346 -0
- package/dist/modules/Manager.js.map +1 -0
- package/dist/modules/ProsopoCaptchaApi.d.ts +19 -0
- package/dist/modules/ProsopoCaptchaApi.d.ts.map +1 -0
- package/dist/modules/ProsopoCaptchaApi.js +100 -0
- package/dist/modules/ProsopoCaptchaApi.js.map +1 -0
- package/dist/modules/ProsopoCaptchaStateClient.d.ts +1 -0
- package/dist/modules/ProsopoCaptchaStateClient.d.ts.map +1 -0
- package/dist/modules/ProsopoCaptchaStateClient.js +2 -0
- package/dist/modules/ProsopoCaptchaStateClient.js.map +1 -0
- package/dist/modules/canvas.d.ts +2 -0
- package/dist/modules/canvas.d.ts.map +1 -0
- package/dist/modules/canvas.js +349 -0
- package/dist/modules/canvas.js.map +1 -0
- package/dist/modules/index.d.ts +3 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/index.js +21 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/storage.d.ts +24 -0
- package/dist/modules/storage.d.ts.map +1 -0
- package/dist/modules/storage.js +35 -0
- package/dist/modules/storage.js.map +1 -0
- package/dist/types/api.d.ts +51 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +22 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/client.d.ts +11 -0
- 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 +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +23 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/manager.d.ts +67 -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/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 +9 -6
- package/tsconfig.json +5 -2
- package/dist/api/AccountCreator.d.ts +0 -16
- package/dist/api/AccountCreator.d.ts.map +0 -1
- package/dist/api/AccountCreator.js +0 -58
- package/dist/api/AccountCreator.js.map +0 -1
package/.eslintrc.js
CHANGED
|
@@ -1,21 +1,36 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
env: {
|
|
3
|
+
browser: true,
|
|
4
|
+
es2021: true,
|
|
5
5
|
},
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier', 'plugin:prettier/recommended'],
|
|
7
|
+
parser: '@typescript-eslint/parser',
|
|
8
|
+
parserOptions: {
|
|
9
|
+
ecmaVersion: 'latest',
|
|
10
|
+
sourceType: 'module',
|
|
11
|
+
},
|
|
12
|
+
plugins: ['unused-imports', '@typescript-eslint', 'prettier'],
|
|
13
|
+
rules: {
|
|
14
|
+
'no-unused-vars': 'off',
|
|
15
|
+
'unused-imports/no-unused-imports': 'error',
|
|
16
|
+
'unused-imports/no-unused-vars': [
|
|
17
|
+
'warn',
|
|
18
|
+
{
|
|
19
|
+
vars: 'all',
|
|
20
|
+
varsIgnorePattern: '^_',
|
|
21
|
+
args: 'after-used',
|
|
22
|
+
argsIgnorePattern: '^_',
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
//"indent": ["error", 4],
|
|
26
|
+
//"indent": "off",
|
|
27
|
+
'sort-imports': [
|
|
28
|
+
'error',
|
|
29
|
+
{
|
|
30
|
+
ignoreDeclarationSort: true,
|
|
31
|
+
allowSeparatedGroups: false,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
'prettier/prettier': ['error'],
|
|
14
35
|
},
|
|
15
|
-
"plugins": [
|
|
16
|
-
"@typescript-eslint"
|
|
17
|
-
],
|
|
18
|
-
"rules": {
|
|
19
|
-
"indent": ["error", 4],
|
|
20
|
-
}
|
|
21
36
|
}
|
package/.prettierrc.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AsyncFactory.d.ts","sourceRoot":"","sources":["../../src/api/AsyncFactory.ts"],"names":[],"mappings":"AAiBA,8BAAsB,YAAY;;WAKV,MAAM,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;aAIzB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CACtD;AAED,eAAe,YAAY,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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/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
|
+
const datasets_1 = require("@prosopo/datasets");
|
|
20
|
+
class AsyncFactory {
|
|
21
|
+
constructor() {
|
|
22
|
+
throw new datasets_1.ProsopoEnvError('GENERAL.ASYNC_FACTORY_CREATE');
|
|
23
|
+
}
|
|
24
|
+
static async create(...args) {
|
|
25
|
+
return await Object.create(this.prototype).init(...args);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.AsyncFactory = AsyncFactory;
|
|
29
|
+
exports.default = AsyncFactory;
|
|
30
|
+
//# sourceMappingURL=AsyncFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AsyncFactory.js","sourceRoot":"","sources":["../../src/api/AsyncFactory.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,gDAAmD;AAEnD,MAAsB,YAAY;IAC9B;QACI,MAAM,IAAI,0BAAe,CAAC,8BAA8B,CAAC,CAAA;IAC7D,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,CAAA;IAC5D,CAAC;CAGJ;AAVD,oCAUC;AAED,kBAAe,YAAY,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Account, ProcaptchaConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Class to interface with accounts.
|
|
4
|
+
*/
|
|
5
|
+
export default abstract class Extension {
|
|
6
|
+
/**
|
|
7
|
+
* Find an account given an address.
|
|
8
|
+
* @param address the address of the account
|
|
9
|
+
* @param dappName the name of the dapp wanting to gain access to accounts (e.g. "Prosopo")
|
|
10
|
+
* @returns the account
|
|
11
|
+
* @throws if the account is not found
|
|
12
|
+
*/
|
|
13
|
+
abstract getAccount(config: ProcaptchaConfig): Promise<Account>;
|
|
14
|
+
}
|
|
15
|
+
//# 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,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAEpD;;GAEG;AACH,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,SAAS;IACnC;;;;;;OAMG;aACa,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CACzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Extension.js","sourceRoot":"","sources":["../../src/api/Extension.ts"],"names":[],"mappings":";;AAEA;;GAEG;AACH,MAA8B,SAAS;CAStC;AATD,4BASC"}
|
|
@@ -1,24 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
private
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
checkExtension(): Promise<void>;
|
|
12
|
-
getExtension(): InjectedExtension | undefined;
|
|
13
|
-
private setExtension;
|
|
14
|
-
getAccounts(): InjectedAccountWithMeta[];
|
|
15
|
-
private setAccounts;
|
|
16
|
-
getAccount(): InjectedAccountWithMeta | undefined;
|
|
17
|
-
setAccount(address: string): void;
|
|
18
|
-
unsetAccount(): void;
|
|
19
|
-
getDefaultAccount(): InjectedAccountWithMeta | undefined;
|
|
20
|
-
setDefaultAccount(): void;
|
|
21
|
-
createAccount(): Promise<any>;
|
|
1
|
+
import Extension from './Extension';
|
|
2
|
+
import { Account, ProcaptchaConfig } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Class for interfacing with web3 accounts.
|
|
5
|
+
*/
|
|
6
|
+
export default class ExtWeb2 extends Extension {
|
|
7
|
+
getAccount(config: ProcaptchaConfig): Promise<Account>;
|
|
8
|
+
private createExtension;
|
|
9
|
+
private createAccount;
|
|
10
|
+
private getFingerprint;
|
|
22
11
|
}
|
|
23
|
-
export default ExtensionWeb2;
|
|
24
12
|
//# 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":"AAOA,OAAO,SAAS,MAAM,aAAa,CAAA;AAKnC,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAGpD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,SAAS;IAC7B,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;YAYrD,eAAe;YA+Bf,aAAa;YAkCb,cAAc;CAU/B"}
|
|
@@ -1,102 +1,95 @@
|
|
|
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 rpc_provider_1 = require("@polkadot/rpc-provider");
|
|
6
|
+
const util_1 = require("@polkadot/util");
|
|
7
|
+
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
8
|
+
const bip39_1 = require("@polkadot/util-crypto/mnemonic/bip39");
|
|
9
|
+
const datasets_1 = require("@prosopo/datasets");
|
|
10
|
+
const Extension_1 = tslib_1.__importDefault(require("./Extension"));
|
|
11
|
+
const fingerprintjs_1 = tslib_1.__importStar(require("@fingerprintjs/fingerprintjs"));
|
|
9
12
|
const Signer_1 = tslib_1.__importDefault(require("@polkadot/extension-base/page/Signer"));
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
async
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
getExtension() {
|
|
24
|
-
return this.extension;
|
|
25
|
-
}
|
|
26
|
-
async setExtension() {
|
|
27
|
-
/*
|
|
28
|
-
InjectedAccounts
|
|
29
|
-
get: (anyType?: boolean) => Promise<InjectedAccount[]>;
|
|
30
|
-
subscribe: (cb: (accounts: InjectedAccount[]) => void | Promise<void>) => Unsubcall;
|
|
31
|
-
*/
|
|
32
|
-
const injectedAccounts = {
|
|
33
|
-
get: () => Promise.resolve([]), subscribe: () => () => {
|
|
34
|
-
}
|
|
13
|
+
const canvas_1 = require("../modules/canvas");
|
|
14
|
+
/**
|
|
15
|
+
* Class for interfacing with web3 accounts.
|
|
16
|
+
*/
|
|
17
|
+
class ExtWeb2 extends Extension_1.default {
|
|
18
|
+
async getAccount(config) {
|
|
19
|
+
const wsProvider = new rpc_provider_1.WsProvider(config.network.endpoint);
|
|
20
|
+
const account = await this.createAccount(wsProvider);
|
|
21
|
+
const extension = await this.createExtension(account);
|
|
22
|
+
return {
|
|
23
|
+
account,
|
|
24
|
+
extension,
|
|
35
25
|
};
|
|
36
|
-
|
|
26
|
+
}
|
|
27
|
+
async createExtension(account) {
|
|
28
|
+
const sendMessage = async (message) => {
|
|
37
29
|
return new Promise((resolve, reject) => {
|
|
38
30
|
resolve();
|
|
39
31
|
});
|
|
40
|
-
}
|
|
32
|
+
};
|
|
41
33
|
await sendMessage('pub(authorize.tab)');
|
|
42
34
|
const signer = new Signer_1.default(sendMessage);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
35
|
+
return {
|
|
36
|
+
accounts: {
|
|
37
|
+
get: async () => {
|
|
38
|
+
// there is only ever 1 account
|
|
39
|
+
return [account];
|
|
40
|
+
},
|
|
41
|
+
subscribe: () => {
|
|
42
|
+
// do nothing, there will never be account changes
|
|
43
|
+
return () => {
|
|
44
|
+
return;
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
name: 'procaptcha-web2',
|
|
49
|
+
version: '0.1.10',
|
|
50
|
+
signer,
|
|
48
51
|
};
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
getAccounts() {
|
|
52
|
-
return this.accounts;
|
|
53
|
-
}
|
|
54
|
-
async setAccounts(accounts) {
|
|
55
|
-
try {
|
|
56
|
-
this.accounts = accounts;
|
|
57
|
-
}
|
|
58
|
-
catch (err) {
|
|
59
|
-
throw new contract_1.ProsopoEnvError(err);
|
|
60
|
-
}
|
|
61
|
-
this.setDefaultAccount();
|
|
62
52
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
53
|
+
async createAccount(wsProvider) {
|
|
54
|
+
const params = {
|
|
55
|
+
area: { width: 300, height: 300 },
|
|
56
|
+
offsetParameter: 2001000001,
|
|
57
|
+
multiplier: 15000,
|
|
58
|
+
fontSizeFactor: 1.5,
|
|
59
|
+
maxShadowBlur: 50,
|
|
60
|
+
numberOfRounds: 5,
|
|
61
|
+
seed: 42,
|
|
62
|
+
};
|
|
63
|
+
const browserEntropy = await this.getFingerprint();
|
|
64
|
+
const canvasEntropy = (0, canvas_1.picassoCanvas)(params.numberOfRounds, params.seed, params);
|
|
65
|
+
const entropy = (0, datasets_1.hexHash)([canvasEntropy, browserEntropy].join(''), 128).slice(2);
|
|
66
|
+
console.log('canvas entropy', canvasEntropy);
|
|
67
|
+
console.log('browserEntropy', browserEntropy);
|
|
68
|
+
console.log('entropy', entropy);
|
|
69
|
+
const u8Entropy = (0, util_1.stringToU8a)(entropy);
|
|
70
|
+
const mnemonic = (0, bip39_1.entropyToMnemonic)(u8Entropy);
|
|
71
|
+
const api = await api_1.ApiPromise.create({ provider: wsProvider });
|
|
72
|
+
const type = 'sr25519';
|
|
73
|
+
const keyring = new api_1.Keyring({ type, ss58Format: api.registry.chainSS58 });
|
|
74
|
+
await (0, util_crypto_1.cryptoWaitReady)();
|
|
75
|
+
const account = keyring.addFromMnemonic(mnemonic);
|
|
76
|
+
const address = account.address.length === 42 ? account.address : (0, util_crypto_1.encodeAddress)((0, util_crypto_1.decodeAddress)(account.address));
|
|
77
|
+
return {
|
|
78
|
+
address,
|
|
79
|
+
type,
|
|
80
|
+
name: address,
|
|
81
|
+
};
|
|
90
82
|
}
|
|
91
|
-
async
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
await
|
|
96
|
-
|
|
97
|
-
|
|
83
|
+
async getFingerprint() {
|
|
84
|
+
// Initialize an agent at application startup.
|
|
85
|
+
const fpPromise = fingerprintjs_1.default.load();
|
|
86
|
+
// Get the visitor identifier when you need it.
|
|
87
|
+
const fp = await fpPromise;
|
|
88
|
+
const result = await fp.get();
|
|
89
|
+
// strip out the components that change in incognito mode
|
|
90
|
+
const { screenFrame, ...componentsReduced } = result.components;
|
|
91
|
+
return (0, fingerprintjs_1.hashComponents)(componentsReduced);
|
|
98
92
|
}
|
|
99
93
|
}
|
|
100
|
-
exports.
|
|
101
|
-
exports.default = ExtensionWeb2;
|
|
94
|
+
exports.default = ExtWeb2;
|
|
102
95
|
//# 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":";;;AAAA,uCAAmD;AAEnD,yDAAmD;AACnD,yCAA4C;AAC5C,uDAAqF;AACrF,gEAAwE;AACxE,gDAA2C;AAC3C,oEAAmC;AACnC,sFAA4E;AAE5E,0FAAyD;AAGzD,8CAAiD;AAEjD;;GAEG;AACH,MAAqB,OAAQ,SAAQ,mBAAS;IACnC,KAAK,CAAC,UAAU,CAAC,MAAwB;QAC5C,MAAM,UAAU,GAAG,IAAI,yBAAU,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QAE1D,MAAM,OAAO,GAAoB,MAAM,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAA;QACrE,MAAM,SAAS,GAAsB,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;QAExE,OAAO;YACH,OAAO;YACP,SAAS;SACZ,CAAA;IACL,CAAC;IAEO,KAAK,CAAC,eAAe,CAAC,OAAwB;QAClD,MAAM,WAAW,GAAG,KAAK,EACrB,OAAqB,EACR,EAAE;YACf,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACzC,OAAO,EAAE,CAAA;YACb,CAAC,CAAC,CAAA;QACN,CAAC,CAAA;QAED,MAAM,WA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
3
|
-
import AsyncFactory from "./AsyncFactory";
|
|
1
|
+
import Extension from './Extension';
|
|
2
|
+
import { Account, ProcaptchaConfig } from '../types';
|
|
4
3
|
/**
|
|
5
|
-
* Class
|
|
4
|
+
* Class for interfacing with web3 accounts.
|
|
6
5
|
*/
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
private account;
|
|
10
|
-
private accounts;
|
|
11
|
-
private injectedExtensions;
|
|
12
|
-
init(): Promise<this>;
|
|
13
|
-
checkExtension(): Promise<void>;
|
|
14
|
-
/**
|
|
15
|
-
* Get the extension for the selected account.
|
|
16
|
-
* @returns the extension holding the selected account. Undefined if no account selected.
|
|
17
|
-
*/
|
|
18
|
-
getExtension(): InjectedExtension | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* Set the extension for the selected account.
|
|
21
|
-
*/
|
|
22
|
-
private setExtension;
|
|
23
|
-
/**
|
|
24
|
-
* Get all accounts across all extensions.
|
|
25
|
-
* @returns all accounts across all extensions.
|
|
26
|
-
*/
|
|
27
|
-
getAccounts(): InjectedAccountWithMeta[];
|
|
28
|
-
/**
|
|
29
|
-
* Discover accounts across all extensions.
|
|
30
|
-
*/
|
|
31
|
-
private setAccounts;
|
|
32
|
-
/**
|
|
33
|
-
* Get the selected account.
|
|
34
|
-
* @returns the selected account.
|
|
35
|
-
*/
|
|
36
|
-
getAccount(): InjectedAccountWithMeta | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* Set the selected account.
|
|
39
|
-
* @param address the address of the account to be selected.
|
|
40
|
-
*/
|
|
41
|
-
setAccount(address: string): void;
|
|
42
|
-
unsetAccount(): void;
|
|
43
|
-
/**
|
|
44
|
-
* Get the last used account via the address held in local storage.
|
|
45
|
-
* @returns the account associated with the address held in storage.
|
|
46
|
-
*/
|
|
47
|
-
getDefaultAccount(): InjectedAccountWithMeta | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Select the account using the last used account address held in local storage.
|
|
50
|
-
*/
|
|
51
|
-
setDefaultAccount(): void;
|
|
52
|
-
createAccount(): Promise<undefined>;
|
|
6
|
+
export default class ExtWeb3 extends Extension {
|
|
7
|
+
getAccount(config: ProcaptchaConfig): Promise<Account>;
|
|
53
8
|
}
|
|
54
|
-
export default ExtensionWeb3;
|
|
55
9
|
//# 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":"AAEA,OAAO,SAAS,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAGpD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,SAAS;IAC7B,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAwBtE"}
|
|
@@ -1,149 +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
|
-
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
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/>.
|
|
20
4
|
const extension_dapp_1 = require("@polkadot/extension-dapp");
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const contract_1 = require("@prosopo/contract");
|
|
5
|
+
const Extension_1 = tslib_1.__importDefault(require("./Extension"));
|
|
6
|
+
const errors_1 = require("./errors");
|
|
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
|
-
throw new contract_1.ProsopoEnvError(err);
|
|
48
|
-
}
|
|
49
|
-
if (!this.injectedExtensions.length) {
|
|
50
|
-
throw new contract_1.ProsopoEnvError("WIDGET.NO_EXTENSION_FOUND");
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Get the extension for the selected account.
|
|
55
|
-
* @returns the extension holding the selected account. Undefined if no account selected.
|
|
56
|
-
*/
|
|
57
|
-
getExtension() {
|
|
58
|
-
return this.extension;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Set the extension for the selected account.
|
|
62
|
-
*/
|
|
63
|
-
async setExtension() {
|
|
64
|
-
try {
|
|
65
|
-
// https://polkadot.js.org/docs/extension/cookbook/
|
|
66
|
-
this.extension = await (0, extension_dapp_1.web3FromSource)(this.accounts[0].meta.source);
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
throw new contract_1.ProsopoEnvError(err);
|
|
70
|
-
}
|
|
71
|
-
if (!this.extension) {
|
|
72
|
-
throw new contract_1.ProsopoEnvError("WIDGET.EXTENSION_NOT_FOUND");
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Get all accounts across all extensions.
|
|
77
|
-
* @returns all accounts across all extensions.
|
|
78
|
-
*/
|
|
79
|
-
getAccounts() {
|
|
80
|
-
return this.accounts;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Discover accounts across all extensions.
|
|
84
|
-
*/
|
|
85
|
-
async setAccounts() {
|
|
86
|
-
this.accounts = await (0, extension_dapp_1.web3Accounts)();
|
|
87
|
-
// get the last used account address from storage
|
|
88
|
-
const lastUsedAccountAddress = storage_1.default.getAccount();
|
|
89
|
-
// lookup this account in the discovered accounts
|
|
90
|
-
const account = this.accounts.find(acc => acc.address === lastUsedAccountAddress);
|
|
91
|
-
// if found then set it
|
|
92
|
-
if (account) {
|
|
93
|
-
this.account = account;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
this.account = undefined;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Get the selected account.
|
|
101
|
-
* @returns the selected account.
|
|
102
|
-
*/
|
|
103
|
-
getAccount() {
|
|
104
|
-
return this.account;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Set the selected account.
|
|
108
|
-
* @param address the address of the account to be selected.
|
|
109
|
-
*/
|
|
110
|
-
setAccount(address) {
|
|
111
|
-
if (!this.accounts.length) {
|
|
112
|
-
throw new contract_1.ProsopoEnvError("WIDGET.NO_ACCOUNTS_FOUND");
|
|
113
|
-
}
|
|
114
|
-
const account = this.accounts.find(acc => acc.address === address);
|
|
115
|
-
if (!account) {
|
|
116
|
-
throw new contract_1.ProsopoEnvError("WIDGET.ACCOUNT_NOT_FOUND");
|
|
117
|
-
}
|
|
118
|
-
this.account = account;
|
|
119
|
-
storage_1.default.setAccount(account.address);
|
|
120
|
-
}
|
|
121
|
-
unsetAccount() {
|
|
122
|
-
this.account = undefined;
|
|
123
|
-
// update the last used account to empty
|
|
124
|
-
storage_1.default.setAccount("");
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Get the last used account via the address held in local storage.
|
|
128
|
-
* @returns the account associated with the address held in storage.
|
|
129
|
-
*/
|
|
130
|
-
getDefaultAccount() {
|
|
131
|
-
const defaultAccount = storage_1.default.getAccount();
|
|
132
|
-
return this.accounts.find(acc => acc.address === defaultAccount);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Select the account using the last used account address held in local storage.
|
|
136
|
-
*/
|
|
137
|
-
setDefaultAccount() {
|
|
138
|
-
const defaultAccount = storage_1.default.getAccount();
|
|
139
|
-
if (defaultAccount) {
|
|
140
|
-
this.setAccount(defaultAccount);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
async createAccount() {
|
|
144
|
-
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);
|
|
145
30
|
}
|
|
146
31
|
}
|
|
147
|
-
exports.
|
|
148
|
-
exports.default = ExtensionWeb3;
|
|
32
|
+
exports.default = ExtWeb3;
|
|
149
33
|
//# sourceMappingURL=ExtensionWeb3.js.map
|