@subwallet/extension-base 0.6.7-1 → 0.6.7-2
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/background/KoniTypes.d.ts +64 -22
- package/background/KoniTypes.js +13 -23
- package/background/RequestBytesSign.js +1 -2
- package/background/RequestExtrinsicSign.js +1 -2
- package/background/handlers/Extension.js +28 -122
- package/background/handlers/State.js +28 -71
- package/background/handlers/Tabs.js +9 -45
- package/background/handlers/helpers.js +1 -1
- package/background/handlers/index.js +4 -2
- package/background/handlers/subscriptions.js +5 -2
- package/bundle.js +1 -0
- package/cjs/background/KoniTypes.js +15 -24
- package/cjs/background/RequestBytesSign.js +1 -6
- package/cjs/background/RequestExtrinsicSign.js +1 -4
- package/cjs/background/handlers/Extension.js +27 -174
- package/cjs/background/handlers/State.js +28 -82
- package/cjs/background/handlers/Tabs.js +9 -60
- package/cjs/background/handlers/helpers.js +1 -2
- package/cjs/background/handlers/index.js +4 -10
- package/cjs/background/handlers/subscriptions.js +5 -4
- package/cjs/bundle.js +0 -1
- package/cjs/defaults.js +1 -0
- package/cjs/detectOther.js +0 -4
- package/cjs/detectPackage.js +2 -4
- package/cjs/errors/SubWalletProviderError.js +1 -3
- package/cjs/index.js +0 -2
- package/cjs/packageInfo.js +3 -1
- package/cjs/page/Accounts.js +3 -6
- package/cjs/page/Injected.js +1 -8
- package/cjs/page/Metadata.js +1 -5
- package/cjs/page/PostMessageProvider.js +22 -38
- package/cjs/page/Signer.js +11 -11
- package/cjs/page/index.js +6 -13
- package/cjs/signers/substrates/LedgerSigner.js +1 -7
- package/cjs/signers/substrates/QrSigner.js +1 -10
- package/cjs/signers/web3/QrSigner.js +1 -12
- package/cjs/stores/Accounts.js +1 -8
- package/cjs/stores/Base.js +1 -15
- package/cjs/stores/Metadata.js +1 -6
- package/cjs/stores/index.js +0 -3
- package/cjs/utils/canDerive.js +1 -1
- package/cjs/utils/getId.js +1 -3
- package/cjs/utils/index.js +0 -1
- package/defaults.js +1 -0
- package/detectOther.js +1 -0
- package/detectPackage.js +2 -0
- package/errors/SubWalletProviderError.js +1 -1
- package/index.js +2 -0
- package/package.json +4 -4
- package/packageInfo.js +3 -1
- package/page/Accounts.js +3 -4
- package/page/Injected.js +1 -1
- package/page/Metadata.js +1 -3
- package/page/PostMessageProvider.js +22 -33
- package/page/Signer.js +11 -9
- package/page/index.js +8 -6
- package/signers/substrates/LedgerSigner.js +1 -3
- package/signers/substrates/QrSigner.js +1 -5
- package/signers/web3/QrSigner.js +1 -5
- package/stores/Accounts.js +1 -3
- package/stores/Base.js +1 -13
- package/stores/Metadata.js +1 -1
- package/stores/index.js +1 -0
- package/utils/canDerive.js +1 -0
- package/utils/getId.js +1 -0
- package/utils/index.js +1 -0
|
@@ -1,28 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = handler;
|
|
9
|
-
|
|
10
8
|
var _util = require("@polkadot/util");
|
|
11
|
-
|
|
12
9
|
var _defaults = require("../../defaults");
|
|
13
|
-
|
|
14
10
|
var _Extension = _interopRequireDefault(require("./Extension"));
|
|
15
|
-
|
|
16
11
|
var _State = _interopRequireDefault(require("./State"));
|
|
17
|
-
|
|
18
12
|
var _Tabs = _interopRequireDefault(require("./Tabs"));
|
|
19
|
-
|
|
20
13
|
// Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
21
14
|
// SPDX-License-Identifier: Apache-2.0
|
|
15
|
+
|
|
22
16
|
const state = new _State.default();
|
|
23
17
|
const extension = new _Extension.default(state);
|
|
24
18
|
const tabs = new _Tabs.default(state);
|
|
25
|
-
|
|
26
19
|
function handler(_ref, port) {
|
|
27
20
|
let {
|
|
28
21
|
id,
|
|
@@ -39,17 +32,18 @@ function handler(_ref, port) {
|
|
|
39
32
|
const promise = isExtension ? extension.handle(id, message, request, port) : tabs.handle(id, message, request, from, port);
|
|
40
33
|
promise.then(response => {
|
|
41
34
|
console.log(`[out] ${source}`); // :: ${JSON.stringify(response)}`);
|
|
35
|
+
|
|
42
36
|
// between the start and the end of the promise, the user may have closed
|
|
43
37
|
// the tab, in which case port will be undefined
|
|
44
|
-
|
|
45
38
|
(0, _util.assert)(port, 'Port has been disconnected');
|
|
46
39
|
port.postMessage({
|
|
47
40
|
id,
|
|
48
41
|
response
|
|
49
42
|
});
|
|
50
43
|
}).catch(error => {
|
|
51
|
-
console.log(`[err] ${source}:: ${error.message}`);
|
|
44
|
+
console.log(`[err] ${source}:: ${error.message}`);
|
|
52
45
|
|
|
46
|
+
// only send message back to port if it's still connected
|
|
53
47
|
if (port) {
|
|
54
48
|
port.postMessage({
|
|
55
49
|
error: error.message,
|
|
@@ -8,8 +8,10 @@ exports.isSubscriptionRunning = isSubscriptionRunning;
|
|
|
8
8
|
exports.unsubscribe = unsubscribe;
|
|
9
9
|
// Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
10
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
-
const subscriptions = {}; // return a subscription callback, that will send the data to the caller via the port
|
|
12
11
|
|
|
12
|
+
const subscriptions = {};
|
|
13
|
+
|
|
14
|
+
// return a subscription callback, that will send the data to the caller via the port
|
|
13
15
|
function createSubscription(id, port) {
|
|
14
16
|
subscriptions[id] = port;
|
|
15
17
|
return subscription => {
|
|
@@ -21,12 +23,11 @@ function createSubscription(id, port) {
|
|
|
21
23
|
}
|
|
22
24
|
};
|
|
23
25
|
}
|
|
24
|
-
|
|
25
26
|
function isSubscriptionRunning(id) {
|
|
26
27
|
return !!subscriptions[id];
|
|
27
|
-
}
|
|
28
|
-
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
+
// clear a previous subscriber
|
|
30
31
|
function unsubscribe(id) {
|
|
31
32
|
if (subscriptions[id]) {
|
|
32
33
|
console.log(`Unsubscribing from ${id}`);
|
package/cjs/bundle.js
CHANGED
package/cjs/defaults.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.PORT_EXTENSION = exports.PORT_CONTENT = exports.PHISHING_PAGE_REDIRECT = exports.PASSWORD_EXPIRY_MS = exports.PASSWORD_EXPIRY_MIN = exports.MESSAGE_ORIGIN_PAGE = exports.MESSAGE_ORIGIN_CONTENT = exports.EXTENSION_PREFIX = exports.ALLOWED_PATH = void 0;
|
|
7
7
|
// Copyright 2019-2022 @polkadot/extension-base authors & contributors
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
9
10
|
const ALLOWED_PATH = ['/', '/account/import-ledger', '/account/restore-json', '/account/create', '/account/settings'];
|
|
10
11
|
exports.ALLOWED_PATH = ALLOWED_PATH;
|
|
11
12
|
const PHISHING_PAGE_REDIRECT = '/phishing-page-detected';
|
package/cjs/detectOther.js
CHANGED
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _packageInfo = require("@subwallet/extension-chains/cjs/packageInfo");
|
|
9
|
-
|
|
10
8
|
var _packageInfo2 = require("@subwallet/extension-dapp/cjs/packageInfo");
|
|
11
|
-
|
|
12
9
|
var _packageInfo3 = require("@subwallet/extension-inject/cjs/packageInfo");
|
|
13
|
-
|
|
14
10
|
// Copyright 2017-2022 @subwallet/extension-base authors & contributors
|
|
15
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
16
12
|
var _default = [_packageInfo.packageInfo, _packageInfo2.packageInfo, _packageInfo3.packageInfo];
|
package/cjs/detectPackage.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _util = require("@polkadot/util");
|
|
6
|
-
|
|
7
5
|
var _detectOther = _interopRequireDefault(require("./detectOther"));
|
|
8
|
-
|
|
9
6
|
var _packageInfo = require("./packageInfo");
|
|
10
|
-
|
|
11
7
|
// Copyright 2017-2022 @subwallet/extension-base authors & contributors
|
|
12
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
13
10
|
// Do not edit, auto-generated by @polkadot/dev
|
|
11
|
+
|
|
14
12
|
(0, _util.detectPackage)(_packageInfo.packageInfo, null, _detectOther.default);
|
|
@@ -4,16 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.SubWalletProviderError = void 0;
|
|
7
|
-
|
|
8
7
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
9
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
10
10
|
class SubWalletProviderError extends Error {
|
|
11
11
|
constructor(message, code, data) {
|
|
12
12
|
super(message);
|
|
13
13
|
this.code = code;
|
|
14
14
|
this.data = data;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
exports.SubWalletProviderError = SubWalletProviderError;
|
package/cjs/index.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _bundle = require("./bundle");
|
|
8
|
-
|
|
9
7
|
Object.keys(_bundle).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _bundle[key]) return;
|
package/cjs/packageInfo.js
CHANGED
|
@@ -6,11 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.packageInfo = void 0;
|
|
7
7
|
// Copyright 2017-2022 @subwallet/extension-base authors & contributors
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
9
10
|
// Do not edit, auto-generated by @polkadot/dev
|
|
11
|
+
|
|
10
12
|
const packageInfo = {
|
|
11
13
|
name: '@subwallet/extension-base',
|
|
12
14
|
path: typeof __dirname === 'string' ? __dirname : 'auto',
|
|
13
15
|
type: 'cjs',
|
|
14
|
-
version: '0.6.7-
|
|
16
|
+
version: '0.6.7-2'
|
|
15
17
|
};
|
|
16
18
|
exports.packageInfo = packageInfo;
|
package/cjs/page/Accounts.js
CHANGED
|
@@ -6,29 +6,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
// Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
9
10
|
// External to class, this.# is not private enough (yet)
|
|
10
11
|
let sendRequest;
|
|
11
|
-
|
|
12
12
|
class Accounts {
|
|
13
13
|
constructor(_sendRequest) {
|
|
14
14
|
sendRequest = _sendRequest;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
16
|
get(anyType) {
|
|
18
17
|
return sendRequest('pub(accounts.listV2)', {
|
|
19
18
|
anyType,
|
|
20
19
|
accountAuthType: 'substrate'
|
|
21
20
|
});
|
|
22
21
|
}
|
|
23
|
-
|
|
24
22
|
subscribe(cb) {
|
|
25
23
|
sendRequest('pub(accounts.subscribeV2)', {
|
|
26
24
|
accountAuthType: 'substrate'
|
|
27
25
|
}, cb).catch(error => console.error(error));
|
|
28
|
-
return () => {
|
|
26
|
+
return () => {
|
|
27
|
+
// FIXME we need the ability to unsubscribe
|
|
29
28
|
};
|
|
30
29
|
}
|
|
31
|
-
|
|
32
30
|
}
|
|
33
|
-
|
|
34
31
|
exports.default = Accounts;
|
package/cjs/page/Injected.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _Accounts = _interopRequireDefault(require("./Accounts"));
|
|
11
|
-
|
|
12
9
|
var _Metadata = _interopRequireDefault(require("./Metadata"));
|
|
13
|
-
|
|
14
10
|
var _PostMessageProvider = _interopRequireDefault(require("./PostMessageProvider"));
|
|
15
|
-
|
|
16
11
|
var _Signer = _interopRequireDefault(require("./Signer"));
|
|
17
|
-
|
|
18
12
|
// Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
19
13
|
// SPDX-License-Identifier: Apache-2.0
|
|
14
|
+
|
|
20
15
|
class _default {
|
|
21
16
|
constructor(sendRequest) {
|
|
22
17
|
this.accounts = new _Accounts.default(sendRequest);
|
|
@@ -24,7 +19,5 @@ class _default {
|
|
|
24
19
|
this.provider = new _PostMessageProvider.default(sendRequest);
|
|
25
20
|
this.signer = new _Signer.default(sendRequest);
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
}
|
|
29
|
-
|
|
30
23
|
exports.default = _default;
|
package/cjs/page/Metadata.js
CHANGED
|
@@ -6,22 +6,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
// Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
9
10
|
// External to class, this.# is not private enough (yet)
|
|
10
11
|
let sendRequest;
|
|
11
|
-
|
|
12
12
|
class Metadata {
|
|
13
13
|
constructor(_sendRequest) {
|
|
14
14
|
sendRequest = _sendRequest;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
16
|
get() {
|
|
18
17
|
return sendRequest('pub(metadata.list)');
|
|
19
18
|
}
|
|
20
|
-
|
|
21
19
|
provide(definition) {
|
|
22
20
|
return sendRequest('pub(metadata.provide)', definition);
|
|
23
21
|
}
|
|
24
|
-
|
|
25
22
|
}
|
|
26
|
-
|
|
27
23
|
exports.default = Metadata;
|
|
@@ -1,111 +1,102 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _eventemitter = _interopRequireDefault(require("eventemitter3"));
|
|
11
|
-
|
|
12
9
|
var _util = require("@polkadot/util");
|
|
13
|
-
|
|
14
10
|
// Copyright 2019-2022 @polkadot/extension-base authors & contributors
|
|
15
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
16
13
|
const l = (0, _util.logger)('PostMessageProvider');
|
|
17
14
|
// External to class, this.# is not private enough (yet)
|
|
18
15
|
let sendRequest;
|
|
16
|
+
|
|
19
17
|
/**
|
|
20
18
|
* @name PostMessageProvider
|
|
21
19
|
*
|
|
22
20
|
* @description Extension provider to be used by dapps
|
|
23
21
|
*/
|
|
24
|
-
|
|
25
22
|
class PostMessageProvider {
|
|
26
|
-
#eventemitter;
|
|
23
|
+
#eventemitter;
|
|
24
|
+
|
|
25
|
+
// Whether or not the actual extension background provider is connected
|
|
26
|
+
#isConnected = false;
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
// Subscription IDs are (historically) not guaranteed to be globally unique;
|
|
29
29
|
// only unique for a given subscription method; which is why we identify
|
|
30
30
|
// the subscriptions based on subscription id + type
|
|
31
|
-
|
|
32
31
|
#subscriptions = {}; // {[(type,subscriptionId)]: callback}
|
|
33
32
|
|
|
34
33
|
/**
|
|
35
34
|
* @param {function} sendRequest The function to be called to send requests to the node
|
|
36
35
|
* @param {function} subscriptionNotificationHandler Channel for receiving subscription messages
|
|
37
36
|
*/
|
|
38
|
-
|
|
39
37
|
constructor(_sendRequest) {
|
|
40
38
|
this.#eventemitter = new _eventemitter.default();
|
|
41
39
|
sendRequest = _sendRequest;
|
|
42
40
|
}
|
|
41
|
+
|
|
43
42
|
/**
|
|
44
43
|
* @description Returns a clone of the object
|
|
45
44
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
45
|
clone() {
|
|
49
46
|
return new PostMessageProvider(sendRequest);
|
|
50
47
|
}
|
|
48
|
+
|
|
51
49
|
/**
|
|
52
50
|
* @description Manually disconnect from the connection, clearing autoconnect logic
|
|
53
51
|
*/
|
|
54
52
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
55
|
-
|
|
56
|
-
|
|
57
53
|
async connect() {
|
|
58
54
|
// FIXME This should see if the extension's state's provider can disconnect
|
|
59
55
|
console.error('PostMessageProvider.disconnect() is not implemented.');
|
|
60
56
|
}
|
|
57
|
+
|
|
61
58
|
/**
|
|
62
59
|
* @description Manually disconnect from the connection, clearing autoconnect logic
|
|
63
60
|
*/
|
|
64
61
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
65
|
-
|
|
66
|
-
|
|
67
62
|
async disconnect() {
|
|
68
63
|
// FIXME This should see if the extension's state's provider can disconnect
|
|
69
64
|
console.error('PostMessageProvider.disconnect() is not implemented.');
|
|
70
65
|
}
|
|
66
|
+
|
|
71
67
|
/**
|
|
72
68
|
* @summary `true` when this provider supports subscriptions
|
|
73
69
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
70
|
get hasSubscriptions() {
|
|
77
71
|
// FIXME This should see if the extension's state's provider has subscriptions
|
|
78
72
|
return true;
|
|
79
73
|
}
|
|
74
|
+
|
|
80
75
|
/**
|
|
81
76
|
* @summary Whether the node is connected or not.
|
|
82
77
|
* @return {boolean} true if connected
|
|
83
78
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
79
|
get isConnected() {
|
|
87
80
|
return this.#isConnected;
|
|
88
81
|
}
|
|
89
|
-
|
|
90
82
|
listProviders() {
|
|
91
83
|
return sendRequest('pub(rpc.listProviders)', undefined);
|
|
92
84
|
}
|
|
85
|
+
|
|
93
86
|
/**
|
|
94
87
|
* @summary Listens on events after having subscribed using the [[subscribe]] function.
|
|
95
88
|
* @param {ProviderInterfaceEmitted} type Event
|
|
96
89
|
* @param {ProviderInterfaceEmitCb} sub Callback
|
|
97
90
|
* @return unsubscribe function
|
|
98
91
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
92
|
on(type, sub) {
|
|
102
93
|
this.#eventemitter.on(type, sub);
|
|
103
94
|
return () => {
|
|
104
95
|
this.#eventemitter.removeListener(type, sub);
|
|
105
96
|
};
|
|
106
|
-
}
|
|
107
|
-
|
|
97
|
+
}
|
|
108
98
|
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
109
100
|
async send(method, params, _, subscription) {
|
|
110
101
|
if (subscription) {
|
|
111
102
|
const {
|
|
@@ -122,63 +113,56 @@ class PostMessageProvider {
|
|
|
122
113
|
this.#subscriptions[`${type}::${id}`] = callback;
|
|
123
114
|
return id;
|
|
124
115
|
}
|
|
125
|
-
|
|
126
116
|
return sendRequest('pub(rpc.send)', {
|
|
127
117
|
method,
|
|
128
118
|
params
|
|
129
119
|
});
|
|
130
120
|
}
|
|
121
|
+
|
|
131
122
|
/**
|
|
132
123
|
* @summary Spawn a provider on the extension background.
|
|
133
124
|
*/
|
|
134
|
-
|
|
135
|
-
|
|
136
125
|
async startProvider(key) {
|
|
137
126
|
// Disconnect from the previous provider
|
|
138
127
|
this.#isConnected = false;
|
|
139
128
|
this.#eventemitter.emit('disconnected');
|
|
140
|
-
const meta = await sendRequest('pub(rpc.startProvider)', key);
|
|
129
|
+
const meta = await sendRequest('pub(rpc.startProvider)', key);
|
|
141
130
|
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
142
132
|
sendRequest('pub(rpc.subscribeConnected)', null, connected => {
|
|
143
133
|
this.#isConnected = connected;
|
|
144
|
-
|
|
145
134
|
if (connected) {
|
|
146
135
|
this.#eventemitter.emit('connected');
|
|
147
136
|
} else {
|
|
148
137
|
this.#eventemitter.emit('disconnected');
|
|
149
138
|
}
|
|
150
|
-
|
|
151
139
|
return true;
|
|
152
140
|
});
|
|
153
141
|
return meta;
|
|
154
142
|
}
|
|
155
|
-
|
|
156
143
|
subscribe(type, method, params, callback) {
|
|
157
144
|
return this.send(method, params, false, {
|
|
158
145
|
callback,
|
|
159
146
|
type
|
|
160
147
|
});
|
|
161
148
|
}
|
|
149
|
+
|
|
162
150
|
/**
|
|
163
151
|
* @summary Allows unsubscribing to subscriptions made with [[subscribe]].
|
|
164
152
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
167
153
|
async unsubscribe(type, method, id) {
|
|
168
|
-
const subscription = `${type}::${id}`;
|
|
154
|
+
const subscription = `${type}::${id}`;
|
|
155
|
+
|
|
156
|
+
// FIXME This now could happen with re-subscriptions. The issue is that with a re-sub
|
|
169
157
|
// the assigned id now does not match what the API user originally received. It has
|
|
170
158
|
// a slight complication in solving - since we cannot rely on the send id, but rather
|
|
171
159
|
// need to find the actual subscription id to map it
|
|
172
|
-
|
|
173
160
|
if ((0, _util.isUndefined)(this.#subscriptions[subscription])) {
|
|
174
161
|
l.debug(() => `Unable to find active subscription=${subscription}`);
|
|
175
162
|
return false;
|
|
176
163
|
}
|
|
177
|
-
|
|
178
164
|
delete this.#subscriptions[subscription];
|
|
179
165
|
return this.send(method, [id]);
|
|
180
166
|
}
|
|
181
|
-
|
|
182
167
|
}
|
|
183
|
-
|
|
184
168
|
exports.default = PostMessageProvider;
|
package/cjs/page/Signer.js
CHANGED
|
@@ -6,39 +6,39 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
// Copyright 2019-2022 @polkadot/extension-base authors & contributors
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
9
10
|
// External to class, this.# is not private enough (yet)
|
|
10
11
|
let sendRequest;
|
|
11
12
|
let nextId = 0;
|
|
12
|
-
|
|
13
13
|
class Signer {
|
|
14
14
|
constructor(_sendRequest) {
|
|
15
15
|
sendRequest = _sendRequest;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
17
|
async signPayload(payload) {
|
|
19
18
|
const id = ++nextId;
|
|
20
|
-
const result = await sendRequest('pub(extrinsic.sign)', payload);
|
|
19
|
+
const result = await sendRequest('pub(extrinsic.sign)', payload);
|
|
20
|
+
|
|
21
|
+
// we add an internal id (number) - should have a mapping from the
|
|
21
22
|
// extension id (string) -> internal id (number) if we wish to provide
|
|
22
23
|
// updated via the update functionality (noop at this point)
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
return {
|
|
25
|
+
...result,
|
|
25
26
|
id
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
|
-
|
|
29
29
|
async signRaw(payload) {
|
|
30
30
|
const id = ++nextId;
|
|
31
31
|
const result = await sendRequest('pub(bytes.sign)', payload);
|
|
32
|
-
return {
|
|
32
|
+
return {
|
|
33
|
+
...result,
|
|
33
34
|
id
|
|
34
35
|
};
|
|
35
|
-
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// NOTE We don't listen to updates at all, if we do we can interpret the
|
|
36
39
|
// resuklt as provided by the API here
|
|
37
40
|
// public update (id: number, status: Hash | SubmittableResult): void {
|
|
38
41
|
// // ignore
|
|
39
42
|
// }
|
|
40
|
-
|
|
41
|
-
|
|
42
43
|
}
|
|
43
|
-
|
|
44
44
|
exports.default = Signer;
|
package/cjs/page/index.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.enable = enable;
|
|
9
8
|
exports.handleResponse = handleResponse;
|
|
10
9
|
exports.sendMessage = sendMessage;
|
|
11
|
-
|
|
12
10
|
var _SubWalletProviderError = require("@subwallet/extension-base/errors/SubWalletProviderError");
|
|
13
|
-
|
|
14
11
|
var _defaults = require("../defaults");
|
|
15
|
-
|
|
16
12
|
var _getId = require("../utils/getId");
|
|
17
|
-
|
|
18
13
|
var _Injected = _interopRequireDefault(require("./Injected"));
|
|
19
|
-
|
|
20
14
|
// Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
21
15
|
// SPDX-License-Identifier: Apache-2.0
|
|
22
|
-
|
|
16
|
+
|
|
17
|
+
const handlers = {};
|
|
18
|
+
|
|
19
|
+
// a generic message sender that creates an event, returning a promise that will
|
|
23
20
|
// resolve once the event is resolved (by the response listener just below this)
|
|
24
21
|
|
|
25
22
|
function sendMessage(message, request, subscriber) {
|
|
@@ -38,28 +35,24 @@ function sendMessage(message, request, subscriber) {
|
|
|
38
35
|
};
|
|
39
36
|
window.postMessage(transportRequestMessage, '*');
|
|
40
37
|
});
|
|
41
|
-
}
|
|
42
|
-
|
|
38
|
+
}
|
|
43
39
|
|
|
40
|
+
// the enable function, called by the dapp to allow access
|
|
44
41
|
async function enable(origin) {
|
|
45
42
|
await sendMessage('pub(authorize.tabV2)', {
|
|
46
43
|
origin
|
|
47
44
|
});
|
|
48
45
|
return new _Injected.default(sendMessage);
|
|
49
46
|
}
|
|
50
|
-
|
|
51
47
|
function handleResponse(data) {
|
|
52
48
|
const handler = handlers[data.id];
|
|
53
|
-
|
|
54
49
|
if (!handler) {
|
|
55
50
|
console.error(`Unknown response: ${JSON.stringify(data)}`);
|
|
56
51
|
return;
|
|
57
52
|
}
|
|
58
|
-
|
|
59
53
|
if (!handler.subscriber) {
|
|
60
54
|
delete handlers[data.id];
|
|
61
55
|
}
|
|
62
|
-
|
|
63
56
|
if (data.subscription) {
|
|
64
57
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
65
58
|
handler.subscriber(data.subscription);
|
|
@@ -4,26 +4,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
9
|
-
|
|
10
8
|
var _util = require("@polkadot/util");
|
|
11
|
-
|
|
12
9
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
13
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
14
12
|
class LedgerSigner {
|
|
15
13
|
#registry;
|
|
16
14
|
#callback;
|
|
17
15
|
#setState;
|
|
18
16
|
#id;
|
|
19
|
-
|
|
20
17
|
constructor(registry, callback, id, setState) {
|
|
21
18
|
this.#registry = registry;
|
|
22
19
|
this.#callback = callback;
|
|
23
20
|
this.#id = id;
|
|
24
21
|
this.#setState = setState;
|
|
25
22
|
}
|
|
26
|
-
|
|
27
23
|
async signPayload(payload) {
|
|
28
24
|
return new Promise((resolve, reject) => {
|
|
29
25
|
const raw = this.#registry.createType('ExtrinsicPayload', payload, {
|
|
@@ -44,7 +40,5 @@ class LedgerSigner {
|
|
|
44
40
|
});
|
|
45
41
|
});
|
|
46
42
|
}
|
|
47
|
-
|
|
48
43
|
}
|
|
49
|
-
|
|
50
44
|
exports.default = LedgerSigner;
|
|
@@ -4,22 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
9
|
-
|
|
10
8
|
var _util = require("@polkadot/util");
|
|
11
|
-
|
|
12
9
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
13
|
-
|
|
14
10
|
// Copyright 2017-2022 @polkadot/react-signer authors & contributors
|
|
15
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
16
13
|
class QrSigner {
|
|
17
14
|
#callback;
|
|
18
15
|
#id;
|
|
19
16
|
#registry;
|
|
20
17
|
#resolver;
|
|
21
18
|
#setState;
|
|
22
|
-
|
|
23
19
|
constructor(_ref) {
|
|
24
20
|
let {
|
|
25
21
|
callback,
|
|
@@ -34,7 +30,6 @@ class QrSigner {
|
|
|
34
30
|
this.#resolver = resolver;
|
|
35
31
|
this.#setState = setState;
|
|
36
32
|
}
|
|
37
|
-
|
|
38
33
|
async signPayload(payload) {
|
|
39
34
|
return new Promise((resolve, reject) => {
|
|
40
35
|
// limit size of the transaction
|
|
@@ -43,12 +38,10 @@ class QrSigner {
|
|
|
43
38
|
version: payload.version
|
|
44
39
|
});
|
|
45
40
|
const qrPayload = isQrHashed ? (0, _utilCrypto.blake2AsU8a)(wrapper.toU8a(true)) : wrapper.toU8a();
|
|
46
|
-
|
|
47
41
|
const resolver = result => {
|
|
48
42
|
this.#resolver();
|
|
49
43
|
resolve(result);
|
|
50
44
|
};
|
|
51
|
-
|
|
52
45
|
this.#setState({
|
|
53
46
|
reject: reject,
|
|
54
47
|
resolve: resolver,
|
|
@@ -66,7 +59,5 @@ class QrSigner {
|
|
|
66
59
|
});
|
|
67
60
|
});
|
|
68
61
|
}
|
|
69
|
-
|
|
70
62
|
}
|
|
71
|
-
|
|
72
63
|
exports.default = QrSigner;
|