@polkadot/extension-base 0.44.9 → 0.45.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/RequestBytesSign.js +9 -11
- package/background/RequestExtrinsicSign.js +9 -11
- package/background/handlers/Extension.js +456 -611
- package/background/handlers/State.js +374 -421
- package/background/handlers/Tabs.js +174 -211
- package/background/handlers/helpers.js +8 -10
- package/background/handlers/index.js +29 -39
- package/background/handlers/subscriptions.js +13 -22
- package/bundle.js +1 -4
- package/cjs/background/RequestBytesSign.js +11 -18
- package/cjs/background/RequestExtrinsicSign.js +9 -16
- package/cjs/background/handlers/Extension.js +468 -658
- package/cjs/background/handlers/State.js +389 -460
- package/cjs/background/handlers/Tabs.js +185 -242
- package/cjs/background/handlers/helpers.js +12 -16
- package/cjs/background/handlers/index.js +37 -52
- package/cjs/background/handlers/subscriptions.js +17 -28
- package/cjs/background/types.js +2 -1
- package/cjs/bundle.js +4 -11
- package/cjs/defaults.js +3 -12
- package/cjs/detectOther.js +5 -12
- package/cjs/detectPackage.js +6 -11
- package/cjs/index.js +3 -15
- package/cjs/packageInfo.js +2 -16
- package/cjs/page/Accounts.js +19 -28
- package/cjs/page/Injected.js +19 -26
- package/cjs/page/Metadata.js +10 -18
- package/cjs/page/PostMessageProvider.js +127 -160
- package/cjs/page/Signer.js +23 -38
- package/cjs/page/index.js +44 -61
- package/cjs/page/types.js +2 -1
- package/cjs/stores/Accounts.js +17 -22
- package/cjs/stores/Base.js +56 -63
- package/cjs/stores/Metadata.js +10 -15
- package/cjs/stores/index.js +9 -19
- package/cjs/types.js +2 -1
- package/cjs/utils/canDerive.js +5 -10
- package/cjs/utils/getId.js +6 -11
- package/cjs/utils/index.js +4 -11
- package/defaults.js +1 -8
- package/detectOther.js +0 -3
- package/detectPackage.js +2 -7
- package/index.js +1 -7
- package/package.json +20 -17
- package/packageInfo.js +1 -11
- package/page/Accounts.js +18 -23
- package/page/Injected.js +19 -18
- package/page/Metadata.js +9 -13
- package/page/PostMessageProvider.js +118 -149
- package/page/Signer.js +22 -33
- package/page/index.js +36 -59
- package/stores/Accounts.js +14 -15
- package/stores/Base.js +51 -56
- package/stores/Metadata.js +7 -8
- package/stores/index.js +2 -5
- package/utils/canDerive.js +1 -4
- package/utils/getId.js +2 -5
- package/utils/index.js +1 -4
package/cjs/defaults.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
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
|
-
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
|
|
10
|
-
// this _must_ be changed for each extension
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MESSAGE_ORIGIN_CONTENT = exports.MESSAGE_ORIGIN_PAGE = exports.PORT_EXTENSION = exports.PORT_CONTENT = exports.EXTENSION_PREFIX = exports.PHISHING_PAGE_REDIRECT = exports.PASSWORD_EXPIRY_MS = exports.PASSWORD_EXPIRY_MIN = exports.ALLOWED_PATH = void 0;
|
|
11
4
|
const EXTENSION_PREFIX = process.env.EXTENSION_PREFIX || '';
|
|
12
5
|
exports.EXTENSION_PREFIX = EXTENSION_PREFIX;
|
|
13
6
|
if (!EXTENSION_PREFIX && !process.env.PORT_PREFIX) {
|
|
14
|
-
|
|
7
|
+
throw new Error('CRITICAL: The extension does not define an own EXTENSION_PREFIX environment variable as part of the build, this is required to ensure that messages are not shared between extensions. Failure to do so will yield messages sent to multiple extensions.');
|
|
15
8
|
}
|
|
16
9
|
const PORT_PREFIX = `${EXTENSION_PREFIX || 'unknown'}-${process.env.PORT_PREFIX || 'unknown'}`;
|
|
17
10
|
const PORT_CONTENT = `${PORT_PREFIX}-content`;
|
|
@@ -29,6 +22,4 @@ exports.PHISHING_PAGE_REDIRECT = PHISHING_PAGE_REDIRECT;
|
|
|
29
22
|
const PASSWORD_EXPIRY_MIN = 15;
|
|
30
23
|
exports.PASSWORD_EXPIRY_MIN = PASSWORD_EXPIRY_MIN;
|
|
31
24
|
const PASSWORD_EXPIRY_MS = PASSWORD_EXPIRY_MIN * 60 * 1000;
|
|
32
|
-
|
|
33
|
-
// console.log(`Extension is sending and receiving messages on ${PORT_PREFIX}-*`);
|
|
34
25
|
exports.PASSWORD_EXPIRY_MS = PASSWORD_EXPIRY_MS;
|
package/cjs/detectOther.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.default =
|
|
7
|
-
var _packageInfo = require("@polkadot/extension-chains/cjs/packageInfo");
|
|
8
|
-
var _packageInfo2 = require("@polkadot/extension-dapp/cjs/packageInfo");
|
|
9
|
-
var _packageInfo3 = require("@polkadot/extension-inject/cjs/packageInfo");
|
|
10
|
-
// Copyright 2017-2023 @polkadot/extension-base authors & contributors
|
|
11
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
-
var _default = [_packageInfo.packageInfo, _packageInfo2.packageInfo, _packageInfo3.packageInfo];
|
|
13
|
-
exports.default = _default;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const packageInfo_1 = require("@polkadot/extension-chains/cjs/packageInfo");
|
|
4
|
+
const packageInfo_2 = require("@polkadot/extension-dapp/cjs/packageInfo");
|
|
5
|
+
const packageInfo_3 = require("@polkadot/extension-inject/cjs/packageInfo");
|
|
6
|
+
exports.default = [packageInfo_1.packageInfo, packageInfo_2.packageInfo, packageInfo_3.packageInfo];
|
package/cjs/detectPackage.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
|
|
10
|
-
// Do not edit, auto-generated by @polkadot/dev
|
|
11
|
-
|
|
12
|
-
(0, _util.detectPackage)(_packageInfo.packageInfo, null, _detectOther.default);
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const util_1 = require("@polkadot/util");
|
|
5
|
+
const detectOther_1 = tslib_1.__importDefault(require("./detectOther"));
|
|
6
|
+
const packageInfo_1 = require("./packageInfo");
|
|
7
|
+
(0, util_1.detectPackage)(packageInfo_1.packageInfo, null, detectOther_1.default);
|
package/cjs/index.js
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
var _bundle = require("./bundle");
|
|
7
|
-
Object.keys(_bundle).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _bundle[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _bundle[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./bundle"), exports);
|
package/cjs/packageInfo.js
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.packageInfo = void 0;
|
|
7
|
-
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
|
|
10
|
-
// Do not edit, auto-generated by @polkadot/dev
|
|
11
|
-
|
|
12
|
-
const packageInfo = {
|
|
13
|
-
name: '@polkadot/extension-base',
|
|
14
|
-
path: typeof __dirname === 'string' ? __dirname : 'auto',
|
|
15
|
-
type: 'cjs',
|
|
16
|
-
version: '0.44.9'
|
|
17
|
-
};
|
|
18
|
-
exports.packageInfo = packageInfo;
|
|
4
|
+
exports.packageInfo = { name: '@polkadot/extension-base', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '0.45.1' };
|
package/cjs/page/Accounts.js
CHANGED
|
@@ -1,33 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
// Copyright 2019-2023 @polkadot/extension authors & contributors
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
|
|
10
|
-
// External to class, this.# is not private enough (yet)
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
3
|
let sendRequest;
|
|
12
4
|
class Accounts {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
}
|
|
5
|
+
constructor(_sendRequest) {
|
|
6
|
+
sendRequest = _sendRequest;
|
|
7
|
+
}
|
|
8
|
+
get(anyType) {
|
|
9
|
+
return sendRequest('pub(accounts.list)', { anyType });
|
|
10
|
+
}
|
|
11
|
+
subscribe(cb) {
|
|
12
|
+
let id = null;
|
|
13
|
+
sendRequest('pub(accounts.subscribe)', null, cb)
|
|
14
|
+
.then((subId) => {
|
|
15
|
+
id = subId;
|
|
16
|
+
})
|
|
17
|
+
.catch(console.error);
|
|
18
|
+
return () => {
|
|
19
|
+
id && sendRequest('pub(accounts.unsubscribe)', { id })
|
|
20
|
+
.catch(console.error);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
32
23
|
}
|
|
33
24
|
exports.default = Accounts;
|
package/cjs/page/Injected.js
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.signer = new _Signer.default(sendRequest);
|
|
21
|
-
setInterval(() => {
|
|
22
|
-
sendRequest('pub(ping)', null).catch(() => {
|
|
23
|
-
console.error('Extension unavailable, ping failed');
|
|
24
|
-
});
|
|
25
|
-
}, 5000 + Math.floor(Math.random() * 5000));
|
|
26
|
-
}
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const Accounts_1 = tslib_1.__importDefault(require("./Accounts"));
|
|
5
|
+
const Metadata_1 = tslib_1.__importDefault(require("./Metadata"));
|
|
6
|
+
const PostMessageProvider_1 = tslib_1.__importDefault(require("./PostMessageProvider"));
|
|
7
|
+
const Signer_1 = tslib_1.__importDefault(require("./Signer"));
|
|
8
|
+
class default_1 {
|
|
9
|
+
constructor(sendRequest) {
|
|
10
|
+
this.accounts = new Accounts_1.default(sendRequest);
|
|
11
|
+
this.metadata = new Metadata_1.default(sendRequest);
|
|
12
|
+
this.provider = new PostMessageProvider_1.default(sendRequest);
|
|
13
|
+
this.signer = new Signer_1.default(sendRequest);
|
|
14
|
+
setInterval(() => {
|
|
15
|
+
sendRequest('pub(ping)', null).catch(() => {
|
|
16
|
+
console.error('Extension unavailable, ping failed');
|
|
17
|
+
});
|
|
18
|
+
}, 5000 + Math.floor(Math.random() * 5000));
|
|
19
|
+
}
|
|
27
20
|
}
|
|
28
|
-
exports.default =
|
|
21
|
+
exports.default = default_1;
|
package/cjs/page/Metadata.js
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
// Copyright 2019-2023 @polkadot/extension authors & contributors
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
|
|
10
|
-
// External to class, this.# is not private enough (yet)
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
3
|
let sendRequest;
|
|
12
4
|
class Metadata {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
5
|
+
constructor(_sendRequest) {
|
|
6
|
+
sendRequest = _sendRequest;
|
|
7
|
+
}
|
|
8
|
+
get() {
|
|
9
|
+
return sendRequest('pub(metadata.list)');
|
|
10
|
+
}
|
|
11
|
+
provide(definition) {
|
|
12
|
+
return sendRequest('pub(metadata.provide)', definition);
|
|
13
|
+
}
|
|
22
14
|
}
|
|
23
15
|
exports.default = Metadata;
|
|
@@ -1,171 +1,138 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _eventemitter = _interopRequireDefault(require("eventemitter3"));
|
|
9
|
-
var _util = require("@polkadot/util");
|
|
10
|
-
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
|
|
11
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
-
|
|
13
|
-
const l = (0, _util.logger)('PostMessageProvider');
|
|
14
|
-
// External to class, this.# is not private enough (yet)
|
|
2
|
+
var _PostMessageProvider_eventemitter, _PostMessageProvider_isConnected, _PostMessageProvider_subscriptions;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const eventemitter3_1 = tslib_1.__importDefault(require("eventemitter3"));
|
|
6
|
+
const util_1 = require("@polkadot/util");
|
|
7
|
+
const l = (0, util_1.logger)('PostMessageProvider');
|
|
15
8
|
let sendRequest;
|
|
16
|
-
|
|
17
9
|
/**
|
|
18
10
|
* @name PostMessageProvider
|
|
19
11
|
*
|
|
20
12
|
* @description Extension provider to be used by dapps
|
|
21
13
|
*/
|
|
22
14
|
class PostMessageProvider {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
constructor(_sendRequest) {
|
|
38
|
-
this.#eventemitter = new _eventemitter.default();
|
|
39
|
-
sendRequest = _sendRequest;
|
|
40
|
-
}
|
|
41
|
-
get isClonable() {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @description Returns a clone of the object
|
|
47
|
-
*/
|
|
48
|
-
clone() {
|
|
49
|
-
return new PostMessageProvider(sendRequest);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @description Manually disconnect from the connection, clearing autoconnect logic
|
|
54
|
-
*/
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
56
|
-
async connect() {
|
|
57
|
-
// FIXME This should see if the extension's state's provider can disconnect
|
|
58
|
-
console.error('PostMessageProvider.disconnect() is not implemented.');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* @description Manually disconnect from the connection, clearing autoconnect logic
|
|
63
|
-
*/
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
65
|
-
async disconnect() {
|
|
66
|
-
// FIXME This should see if the extension's state's provider can disconnect
|
|
67
|
-
console.error('PostMessageProvider.disconnect() is not implemented.');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @summary `true` when this provider supports subscriptions
|
|
72
|
-
*/
|
|
73
|
-
get hasSubscriptions() {
|
|
74
|
-
// FIXME This should see if the extension's state's provider has subscriptions
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @summary Whether the node is connected or not.
|
|
80
|
-
* @return {boolean} true if connected
|
|
81
|
-
*/
|
|
82
|
-
get isConnected() {
|
|
83
|
-
return this.#isConnected;
|
|
84
|
-
}
|
|
85
|
-
listProviders() {
|
|
86
|
-
return sendRequest('pub(rpc.listProviders)', undefined);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @summary Listens on events after having subscribed using the [[subscribe]] function.
|
|
91
|
-
* @param {ProviderInterfaceEmitted} type Event
|
|
92
|
-
* @param {ProviderInterfaceEmitCb} sub Callback
|
|
93
|
-
* @return unsubscribe function
|
|
94
|
-
*/
|
|
95
|
-
on(type, sub) {
|
|
96
|
-
this.#eventemitter.on(type, sub);
|
|
97
|
-
return () => {
|
|
98
|
-
this.#eventemitter.removeListener(type, sub);
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
|
-
async send(method, params, _, subscription) {
|
|
104
|
-
if (subscription) {
|
|
105
|
-
const {
|
|
106
|
-
callback,
|
|
107
|
-
type
|
|
108
|
-
} = subscription;
|
|
109
|
-
const id = await sendRequest('pub(rpc.subscribe)', {
|
|
110
|
-
method,
|
|
111
|
-
params,
|
|
112
|
-
type
|
|
113
|
-
}, res => {
|
|
114
|
-
subscription.callback(null, res);
|
|
115
|
-
});
|
|
116
|
-
this.#subscriptions[`${type}::${id}`] = callback;
|
|
117
|
-
return id;
|
|
15
|
+
/**
|
|
16
|
+
* @param {function} sendRequest The function to be called to send requests to the node
|
|
17
|
+
* @param {function} subscriptionNotificationHandler Channel for receiving subscription messages
|
|
18
|
+
*/
|
|
19
|
+
constructor(_sendRequest) {
|
|
20
|
+
_PostMessageProvider_eventemitter.set(this, void 0);
|
|
21
|
+
// Whether or not the actual extension background provider is connected
|
|
22
|
+
_PostMessageProvider_isConnected.set(this, false);
|
|
23
|
+
// Subscription IDs are (historically) not guaranteed to be globally unique;
|
|
24
|
+
// only unique for a given subscription method; which is why we identify
|
|
25
|
+
// the subscriptions based on subscription id + type
|
|
26
|
+
_PostMessageProvider_subscriptions.set(this, {}); // {[(type,subscriptionId)]: callback}
|
|
27
|
+
tslib_1.__classPrivateFieldSet(this, _PostMessageProvider_eventemitter, new eventemitter3_1.default(), "f");
|
|
28
|
+
sendRequest = _sendRequest;
|
|
118
29
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
30
|
+
get isClonable() {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @description Returns a clone of the object
|
|
35
|
+
*/
|
|
36
|
+
clone() {
|
|
37
|
+
return new PostMessageProvider(sendRequest);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @description Manually disconnect from the connection, clearing autoconnect logic
|
|
41
|
+
*/
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
43
|
+
async connect() {
|
|
44
|
+
// FIXME This should see if the extension's state's provider can disconnect
|
|
45
|
+
console.error('PostMessageProvider.disconnect() is not implemented.');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @description Manually disconnect from the connection, clearing autoconnect logic
|
|
49
|
+
*/
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
51
|
+
async disconnect() {
|
|
52
|
+
// FIXME This should see if the extension's state's provider can disconnect
|
|
53
|
+
console.error('PostMessageProvider.disconnect() is not implemented.');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @summary `true` when this provider supports subscriptions
|
|
57
|
+
*/
|
|
58
|
+
get hasSubscriptions() {
|
|
59
|
+
// FIXME This should see if the extension's state's provider has subscriptions
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @summary Whether the node is connected or not.
|
|
64
|
+
* @return {boolean} true if connected
|
|
65
|
+
*/
|
|
66
|
+
get isConnected() {
|
|
67
|
+
return tslib_1.__classPrivateFieldGet(this, _PostMessageProvider_isConnected, "f");
|
|
68
|
+
}
|
|
69
|
+
listProviders() {
|
|
70
|
+
return sendRequest('pub(rpc.listProviders)', undefined);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @summary Listens on events after having subscribed using the [[subscribe]] function.
|
|
74
|
+
* @param {ProviderInterfaceEmitted} type Event
|
|
75
|
+
* @param {ProviderInterfaceEmitCb} sub Callback
|
|
76
|
+
* @return unsubscribe function
|
|
77
|
+
*/
|
|
78
|
+
on(type, sub) {
|
|
79
|
+
tslib_1.__classPrivateFieldGet(this, _PostMessageProvider_eventemitter, "f").on(type, sub);
|
|
80
|
+
return () => {
|
|
81
|
+
tslib_1.__classPrivateFieldGet(this, _PostMessageProvider_eventemitter, "f").removeListener(type, sub);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
|
+
async send(method, params, _, subscription) {
|
|
86
|
+
if (subscription) {
|
|
87
|
+
const { callback, type } = subscription;
|
|
88
|
+
const id = await sendRequest('pub(rpc.subscribe)', { method, params, type }, (res) => {
|
|
89
|
+
subscription.callback(null, res);
|
|
90
|
+
});
|
|
91
|
+
tslib_1.__classPrivateFieldGet(this, _PostMessageProvider_subscriptions, "f")[`${type}::${id}`] = callback;
|
|
92
|
+
return id;
|
|
93
|
+
}
|
|
94
|
+
return sendRequest('pub(rpc.send)', { method, params });
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* @summary Spawn a provider on the extension background.
|
|
98
|
+
*/
|
|
99
|
+
async startProvider(key) {
|
|
100
|
+
// Disconnect from the previous provider
|
|
101
|
+
tslib_1.__classPrivateFieldSet(this, _PostMessageProvider_isConnected, false, "f");
|
|
102
|
+
tslib_1.__classPrivateFieldGet(this, _PostMessageProvider_eventemitter, "f").emit('disconnected');
|
|
103
|
+
const meta = await sendRequest('pub(rpc.startProvider)', key);
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
105
|
+
sendRequest('pub(rpc.subscribeConnected)', null, (connected) => {
|
|
106
|
+
tslib_1.__classPrivateFieldSet(this, _PostMessageProvider_isConnected, connected, "f");
|
|
107
|
+
if (connected) {
|
|
108
|
+
tslib_1.__classPrivateFieldGet(this, _PostMessageProvider_eventemitter, "f").emit('connected');
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
tslib_1.__classPrivateFieldGet(this, _PostMessageProvider_eventemitter, "f").emit('disconnected');
|
|
112
|
+
}
|
|
113
|
+
return true;
|
|
114
|
+
});
|
|
115
|
+
return meta;
|
|
116
|
+
}
|
|
117
|
+
subscribe(type, method, params, callback) {
|
|
118
|
+
return this.send(method, params, false, { callback, type });
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @summary Allows unsubscribing to subscriptions made with [[subscribe]].
|
|
122
|
+
*/
|
|
123
|
+
async unsubscribe(type, method, id) {
|
|
124
|
+
const subscription = `${type}::${id}`;
|
|
125
|
+
// FIXME This now could happen with re-subscriptions. The issue is that with a re-sub
|
|
126
|
+
// the assigned id now does not match what the API user originally received. It has
|
|
127
|
+
// a slight complication in solving - since we cannot rely on the send id, but rather
|
|
128
|
+
// need to find the actual subscription id to map it
|
|
129
|
+
if ((0, util_1.isUndefined)(tslib_1.__classPrivateFieldGet(this, _PostMessageProvider_subscriptions, "f")[subscription])) {
|
|
130
|
+
l.debug(() => `Unable to find active subscription=${subscription}`);
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
delete tslib_1.__classPrivateFieldGet(this, _PostMessageProvider_subscriptions, "f")[subscription];
|
|
134
|
+
return this.send(method, [id]);
|
|
166
135
|
}
|
|
167
|
-
delete this.#subscriptions[subscription];
|
|
168
|
-
return this.send(method, [id]);
|
|
169
|
-
}
|
|
170
136
|
}
|
|
171
|
-
exports.default = PostMessageProvider;
|
|
137
|
+
exports.default = PostMessageProvider;
|
|
138
|
+
_PostMessageProvider_eventemitter = new WeakMap(), _PostMessageProvider_isConnected = new WeakMap(), _PostMessageProvider_subscriptions = new WeakMap();
|
package/cjs/page/Signer.js
CHANGED
|
@@ -1,44 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
|
|
10
|
-
// External to class, this.# is not private enough (yet)
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
3
|
let sendRequest;
|
|
12
4
|
let nextId = 0;
|
|
13
5
|
class Signer {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// NOTE We don't listen to updates at all, if we do we can interpret the
|
|
39
|
-
// result as provided by the API here
|
|
40
|
-
// public update (id: number, status: Hash | SubmittableResult): void {
|
|
41
|
-
// // ignore
|
|
42
|
-
// }
|
|
6
|
+
constructor(_sendRequest) {
|
|
7
|
+
sendRequest = _sendRequest;
|
|
8
|
+
}
|
|
9
|
+
async signPayload(payload) {
|
|
10
|
+
const id = ++nextId;
|
|
11
|
+
const result = await sendRequest('pub(extrinsic.sign)', payload);
|
|
12
|
+
// we add an internal id (number) - should have a mapping from the
|
|
13
|
+
// extension id (string) -> internal id (number) if we wish to provide
|
|
14
|
+
// updated via the update functionality (noop at this point)
|
|
15
|
+
return {
|
|
16
|
+
...result,
|
|
17
|
+
id
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
async signRaw(payload) {
|
|
21
|
+
const id = ++nextId;
|
|
22
|
+
const result = await sendRequest('pub(bytes.sign)', payload);
|
|
23
|
+
return {
|
|
24
|
+
...result,
|
|
25
|
+
id
|
|
26
|
+
};
|
|
27
|
+
}
|
|
43
28
|
}
|
|
44
29
|
exports.default = Signer;
|