@subwallet/extension-base 0.6.7-2wr → 0.6.8-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.
Files changed (67) hide show
  1. package/background/KoniTypes.d.ts +51 -67
  2. package/background/KoniTypes.js +13 -23
  3. package/background/RequestBytesSign.js +1 -2
  4. package/background/RequestExtrinsicSign.js +1 -2
  5. package/background/handlers/Extension.js +28 -122
  6. package/background/handlers/State.js +28 -71
  7. package/background/handlers/Tabs.js +9 -45
  8. package/background/handlers/helpers.js +1 -1
  9. package/background/handlers/index.js +4 -2
  10. package/background/handlers/subscriptions.js +5 -2
  11. package/bundle.js +1 -0
  12. package/cjs/background/KoniTypes.js +15 -24
  13. package/cjs/background/RequestBytesSign.js +1 -6
  14. package/cjs/background/RequestExtrinsicSign.js +1 -4
  15. package/cjs/background/handlers/Extension.js +27 -174
  16. package/cjs/background/handlers/State.js +28 -82
  17. package/cjs/background/handlers/Tabs.js +9 -60
  18. package/cjs/background/handlers/helpers.js +1 -2
  19. package/cjs/background/handlers/index.js +4 -10
  20. package/cjs/background/handlers/subscriptions.js +5 -4
  21. package/cjs/bundle.js +0 -1
  22. package/cjs/defaults.js +2 -3
  23. package/cjs/detectOther.js +0 -4
  24. package/cjs/detectPackage.js +2 -4
  25. package/cjs/errors/SubWalletProviderError.js +1 -3
  26. package/cjs/index.js +0 -2
  27. package/cjs/packageInfo.js +3 -1
  28. package/cjs/page/Accounts.js +3 -6
  29. package/cjs/page/Injected.js +1 -8
  30. package/cjs/page/Metadata.js +1 -5
  31. package/cjs/page/PostMessageProvider.js +22 -38
  32. package/cjs/page/Signer.js +11 -11
  33. package/cjs/page/index.js +6 -13
  34. package/cjs/signers/substrates/LedgerSigner.js +1 -7
  35. package/cjs/signers/substrates/QrSigner.js +1 -10
  36. package/cjs/signers/web3/QrSigner.js +1 -12
  37. package/cjs/stores/Accounts.js +1 -8
  38. package/cjs/stores/Base.js +1 -15
  39. package/cjs/stores/Metadata.js +1 -6
  40. package/cjs/stores/index.js +0 -3
  41. package/cjs/utils/canDerive.js +1 -1
  42. package/cjs/utils/getId.js +1 -3
  43. package/cjs/utils/index.js +0 -1
  44. package/defaults.d.ts +1 -2
  45. package/defaults.js +2 -2
  46. package/detectOther.js +1 -0
  47. package/detectPackage.js +2 -0
  48. package/errors/SubWalletProviderError.js +1 -1
  49. package/index.js +2 -0
  50. package/package.json +5 -5
  51. package/packageInfo.js +3 -1
  52. package/page/Accounts.js +3 -4
  53. package/page/Injected.js +1 -1
  54. package/page/Metadata.js +1 -3
  55. package/page/PostMessageProvider.js +22 -33
  56. package/page/Signer.js +11 -9
  57. package/page/index.js +8 -6
  58. package/signers/substrates/LedgerSigner.js +1 -3
  59. package/signers/substrates/QrSigner.js +1 -5
  60. package/signers/web3/QrSigner.js +1 -5
  61. package/stores/Accounts.js +1 -3
  62. package/stores/Base.js +1 -13
  63. package/stores/Metadata.js +1 -1
  64. package/stores/index.js +1 -0
  65. package/utils/canDerive.js +1 -0
  66. package/utils/getId.js +1 -0
  67. package/utils/index.js +1 -0
@@ -1,26 +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 = void 0;
9
-
10
8
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
11
-
12
9
  var _rlp = _interopRequireDefault(require("rlp"));
13
-
14
10
  var _util = require("@polkadot/util");
15
-
16
11
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
17
12
  // SPDX-License-Identifier: Apache-2.0
13
+
18
14
  class QrSigner {
19
15
  #callback;
20
16
  #id;
21
17
  #resolver;
22
18
  #setState;
23
-
24
19
  constructor(_ref) {
25
20
  let {
26
21
  callback,
@@ -33,18 +28,14 @@ class QrSigner {
33
28
  this.#resolver = resolver;
34
29
  this.#setState = setState;
35
30
  }
36
-
37
31
  async signTransaction(tx) {
38
32
  return new Promise((resolve, reject) => {
39
33
  const data = [tx.nonce, tx.gasPrice, tx.gasLimit, tx.to, tx.value, tx.data, tx.chainId, new Uint8Array([0x00]), new Uint8Array([0x00])];
40
-
41
34
  const qrPayload = _rlp.default.encode(data);
42
-
43
35
  const resolver = result => {
44
36
  this.#resolver();
45
37
  resolve(result);
46
38
  };
47
-
48
39
  this.#setState({
49
40
  reject: reject,
50
41
  resolve: resolver,
@@ -62,7 +53,5 @@ class QrSigner {
62
53
  });
63
54
  });
64
55
  }
65
-
66
56
  }
67
-
68
57
  exports.default = QrSigner;
@@ -1,33 +1,26 @@
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 _defaults = require("../defaults");
11
-
12
9
  var _Base = _interopRequireDefault(require("./Base"));
13
-
14
10
  // Copyright 2019-2022 @polkadot/extension-base authors & contributors
15
11
  // SPDX-License-Identifier: Apache-2.0
12
+
16
13
  class AccountsStore extends _Base.default {
17
14
  constructor() {
18
15
  super(_defaults.EXTENSION_PREFIX ? `${_defaults.EXTENSION_PREFIX}accounts` : null);
19
16
  }
20
-
21
17
  set(key, value, update) {
22
18
  // shortcut, don't save testing accounts in extension storage
23
19
  if (key.startsWith('account:') && value.meta && value.meta.isTesting) {
24
20
  update && update();
25
21
  return;
26
22
  }
27
-
28
23
  super.set(key, value, update);
29
24
  }
30
-
31
25
  }
32
-
33
26
  exports.default = AccountsStore;
@@ -4,28 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  // Copyright 2019-2022 @polkadot/extension-base authors & contributors
9
8
  // SPDX-License-Identifier: Apache-2.0
9
+
10
10
  const lastError = type => {
11
11
  const error = chrome.runtime.lastError;
12
-
13
12
  if (error) {
14
13
  console.error(`BaseStore.${type}:: runtime.lastError:`, error);
15
14
  }
16
15
  };
17
-
18
16
  class BaseStore {
19
17
  #prefix;
20
-
21
18
  constructor(prefix) {
22
19
  this.#prefix = prefix ? `${prefix}:` : '';
23
20
  }
24
-
25
21
  getPrefix() {
26
22
  return this.#prefix;
27
23
  }
28
-
29
24
  all(update) {
30
25
  this.allMap(map => {
31
26
  Object.entries(map).forEach(_ref => {
@@ -34,25 +29,20 @@ class BaseStore {
34
29
  });
35
30
  });
36
31
  }
37
-
38
32
  allMap(update) {
39
33
  chrome.storage.local.get(null, result => {
40
34
  lastError('all');
41
35
  const entries = Object.entries(result);
42
36
  const map = {};
43
-
44
37
  for (let i = 0; i < entries.length; i++) {
45
38
  const [key, value] = entries[i];
46
-
47
39
  if (key.startsWith(this.#prefix)) {
48
40
  map[key.replace(this.#prefix, '')] = value;
49
41
  }
50
42
  }
51
-
52
43
  update(map);
53
44
  });
54
45
  }
55
-
56
46
  get(_key, update) {
57
47
  const key = `${this.#prefix}${_key}`;
58
48
  chrome.storage.local.get([key], result => {
@@ -60,7 +50,6 @@ class BaseStore {
60
50
  update(result[key]);
61
51
  });
62
52
  }
63
-
64
53
  remove(_key, update) {
65
54
  const key = `${this.#prefix}${_key}`;
66
55
  chrome.storage.local.remove(key, () => {
@@ -68,7 +57,6 @@ class BaseStore {
68
57
  update && update();
69
58
  });
70
59
  }
71
-
72
60
  set(_key, value, update) {
73
61
  const key = `${this.#prefix}${_key}`;
74
62
  chrome.storage.local.set({
@@ -78,7 +66,5 @@ class BaseStore {
78
66
  update && update();
79
67
  });
80
68
  }
81
-
82
69
  }
83
-
84
70
  exports.default = BaseStore;
@@ -1,23 +1,18 @@
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 _defaults = require("../defaults");
11
-
12
9
  var _Base = _interopRequireDefault(require("./Base"));
13
-
14
10
  // Copyright 2019-2022 @polkadot/extension-base authors & contributors
15
11
  // SPDX-License-Identifier: Apache-2.0
12
+
16
13
  class MetadataStore extends _Base.default {
17
14
  constructor() {
18
15
  super(`${_defaults.EXTENSION_PREFIX}metadata`);
19
16
  }
20
-
21
17
  }
22
-
23
18
  exports.default = MetadataStore;
@@ -1,7 +1,6 @@
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
  });
@@ -17,7 +16,5 @@ Object.defineProperty(exports, "MetadataStore", {
17
16
  return _Metadata.default;
18
17
  }
19
18
  });
20
-
21
19
  var _Accounts = _interopRequireDefault(require("./Accounts"));
22
-
23
20
  var _Metadata = _interopRequireDefault(require("./Metadata"));
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.canDerive = canDerive;
7
-
8
7
  // Copyright 2019-2022 @polkadot/extension authors & contributors
9
8
  // SPDX-License-Identifier: Apache-2.0
9
+
10
10
  function canDerive(type) {
11
11
  return !!type && ['ed25519', 'sr25519', 'ecdsa', 'ethereum'].includes(type);
12
12
  }
@@ -4,13 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getId = getId;
7
-
8
7
  var _defaults = require("../defaults");
9
-
10
8
  // Copyright 2019-2022 @polkadot/extension authors & contributors
11
9
  // SPDX-License-Identifier: Apache-2.0
12
- let counter = 0;
13
10
 
11
+ let counter = 0;
14
12
  function getId() {
15
13
  return `${_defaults.EXTENSION_PREFIX}.${Date.now()}.${++counter}`;
16
14
  }
@@ -9,5 +9,4 @@ Object.defineProperty(exports, "canDerive", {
9
9
  return _canDerive.canDerive;
10
10
  }
11
11
  });
12
-
13
12
  var _canDerive = require("./canDerive");
package/defaults.d.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  declare const ALLOWED_PATH: readonly ["/", "/account/import-ledger", "/account/restore-json", "/account/create", "/account/settings"];
2
2
  declare const PHISHING_PAGE_REDIRECT = "/phishing-page-detected";
3
3
  declare const EXTENSION_PREFIX: string;
4
- declare const PORT_MOBILE: string;
5
4
  declare const PORT_CONTENT: string;
6
5
  declare const PORT_EXTENSION: string;
7
6
  declare const MESSAGE_ORIGIN_PAGE: string;
8
7
  declare const MESSAGE_ORIGIN_CONTENT: string;
9
8
  declare const PASSWORD_EXPIRY_MIN = 15;
10
9
  declare const PASSWORD_EXPIRY_MS: number;
11
- export { ALLOWED_PATH, PASSWORD_EXPIRY_MIN, PASSWORD_EXPIRY_MS, PHISHING_PAGE_REDIRECT, EXTENSION_PREFIX, PORT_MOBILE, PORT_CONTENT, PORT_EXTENSION, MESSAGE_ORIGIN_PAGE, MESSAGE_ORIGIN_CONTENT };
10
+ export { ALLOWED_PATH, PASSWORD_EXPIRY_MIN, PASSWORD_EXPIRY_MS, PHISHING_PAGE_REDIRECT, EXTENSION_PREFIX, PORT_CONTENT, PORT_EXTENSION, MESSAGE_ORIGIN_PAGE, MESSAGE_ORIGIN_CONTENT };
package/defaults.js CHANGED
@@ -1,13 +1,13 @@
1
1
  // Copyright 2019-2022 @polkadot/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  const ALLOWED_PATH = ['/', '/account/import-ledger', '/account/restore-json', '/account/create', '/account/settings'];
4
5
  const PHISHING_PAGE_REDIRECT = '/phishing-page-detected';
5
6
  const EXTENSION_PREFIX = process.env.EXTENSION_PREFIX || '';
6
- const PORT_MOBILE = `${EXTENSION_PREFIX}mobile`;
7
7
  const PORT_CONTENT = `${EXTENSION_PREFIX}koni-content`;
8
8
  const PORT_EXTENSION = `${EXTENSION_PREFIX}koni-extension`;
9
9
  const MESSAGE_ORIGIN_PAGE = `${EXTENSION_PREFIX}koni-page`;
10
10
  const MESSAGE_ORIGIN_CONTENT = `${EXTENSION_PREFIX}koni-content`;
11
11
  const PASSWORD_EXPIRY_MIN = 15;
12
12
  const PASSWORD_EXPIRY_MS = PASSWORD_EXPIRY_MIN * 60 * 1000;
13
- export { ALLOWED_PATH, PASSWORD_EXPIRY_MIN, PASSWORD_EXPIRY_MS, PHISHING_PAGE_REDIRECT, EXTENSION_PREFIX, PORT_MOBILE, PORT_CONTENT, PORT_EXTENSION, MESSAGE_ORIGIN_PAGE, MESSAGE_ORIGIN_CONTENT };
13
+ export { ALLOWED_PATH, PASSWORD_EXPIRY_MIN, PASSWORD_EXPIRY_MS, PHISHING_PAGE_REDIRECT, EXTENSION_PREFIX, PORT_CONTENT, PORT_EXTENSION, MESSAGE_ORIGIN_PAGE, MESSAGE_ORIGIN_CONTENT };
package/detectOther.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // Copyright 2017-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  import { packageInfo as chainsInfo } from '@subwallet/extension-chains/packageInfo';
4
5
  import { packageInfo as dappInfo } from '@subwallet/extension-dapp/packageInfo';
5
6
  import { packageInfo as injectInfo } from '@subwallet/extension-inject/packageInfo';
package/detectPackage.js CHANGED
@@ -1,6 +1,8 @@
1
1
  // Copyright 2017-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  // Do not edit, auto-generated by @polkadot/dev
5
+
4
6
  import { detectPackage } from '@polkadot/util';
5
7
  import others from "./detectOther.js";
6
8
  import { packageInfo } from "./packageInfo.js";
@@ -1,10 +1,10 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  export class SubWalletProviderError extends Error {
4
5
  constructor(message, code, data) {
5
6
  super(message);
6
7
  this.code = code;
7
8
  this.data = data;
8
9
  }
9
-
10
10
  }
package/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // Copyright 2019-2022 @polkadot/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  // Since we inject into pages, we skip this
4
5
  // import './detectPackage';
6
+
5
7
  export * from "./bundle.js";
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "0.6.7-2wr",
20
+ "version": "0.6.8-1",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -224,9 +224,9 @@
224
224
  "@polkadot/ui-settings": "^2.9.10",
225
225
  "@polkadot/util": "^10.1.9",
226
226
  "@polkadot/util-crypto": "^10.1.9",
227
- "@subwallet/extension-chains": "^0.6.7-1",
228
- "@subwallet/extension-dapp": "^0.6.7-1",
229
- "@subwallet/extension-inject": "^0.6.7-1",
227
+ "@subwallet/extension-chains": "^0.6.8-1",
228
+ "@subwallet/extension-dapp": "^0.6.8-1",
229
+ "@subwallet/extension-inject": "^0.6.8-1",
230
230
  "ethereumjs-tx": "^2.1.2",
231
231
  "eventemitter3": "^4.0.7",
232
232
  "rlp": "^3.0.0",
@@ -235,4 +235,4 @@
235
235
  "web3-core": "^1.8.0",
236
236
  "web3-core-helpers": "^1.8.0"
237
237
  }
238
- }
238
+ }
package/packageInfo.js CHANGED
@@ -1,9 +1,11 @@
1
1
  // Copyright 2017-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  // Do not edit, auto-generated by @polkadot/dev
5
+
4
6
  export const packageInfo = {
5
7
  name: '@subwallet/extension-base',
6
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
7
9
  type: 'esm',
8
- version: '0.6.7-1'
10
+ version: '0.6.8-1'
9
11
  };
package/page/Accounts.js CHANGED
@@ -1,25 +1,24 @@
1
1
  // Copyright 2019-2022 @polkadot/extension authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  // External to class, this.# is not private enough (yet)
4
5
  let sendRequest;
5
6
  export default class Accounts {
6
7
  constructor(_sendRequest) {
7
8
  sendRequest = _sendRequest;
8
9
  }
9
-
10
10
  get(anyType) {
11
11
  return sendRequest('pub(accounts.listV2)', {
12
12
  anyType,
13
13
  accountAuthType: 'substrate'
14
14
  });
15
15
  }
16
-
17
16
  subscribe(cb) {
18
17
  sendRequest('pub(accounts.subscribeV2)', {
19
18
  accountAuthType: 'substrate'
20
19
  }, cb).catch(error => console.error(error));
21
- return () => {// FIXME we need the ability to unsubscribe
20
+ return () => {
21
+ // FIXME we need the ability to unsubscribe
22
22
  };
23
23
  }
24
-
25
24
  }
package/page/Injected.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // Copyright 2019-2022 @polkadot/extension authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  import Accounts from "./Accounts.js";
4
5
  import Metadata from "./Metadata.js";
5
6
  import PostMessageProvider from "./PostMessageProvider.js";
@@ -11,5 +12,4 @@ export default class {
11
12
  this.provider = new PostMessageProvider(sendRequest);
12
13
  this.signer = new Signer(sendRequest);
13
14
  }
14
-
15
15
  }
package/page/Metadata.js CHANGED
@@ -1,18 +1,16 @@
1
1
  // Copyright 2019-2022 @polkadot/extension authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  // External to class, this.# is not private enough (yet)
4
5
  let sendRequest;
5
6
  export default class Metadata {
6
7
  constructor(_sendRequest) {
7
8
  sendRequest = _sendRequest;
8
9
  }
9
-
10
10
  get() {
11
11
  return sendRequest('pub(metadata.list)');
12
12
  }
13
-
14
13
  provide(definition) {
15
14
  return sendRequest('pub(metadata.provide)', definition);
16
15
  }
17
-
18
16
  }
@@ -1,100 +1,95 @@
1
1
  // Copyright 2019-2022 @polkadot/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  import EventEmitter from 'eventemitter3';
4
5
  import { isUndefined, logger } from '@polkadot/util';
5
6
  const l = logger('PostMessageProvider');
6
7
  // External to class, this.# is not private enough (yet)
7
8
  let sendRequest;
9
+
8
10
  /**
9
11
  * @name PostMessageProvider
10
12
  *
11
13
  * @description Extension provider to be used by dapps
12
14
  */
13
-
14
15
  export default class PostMessageProvider {
15
- #eventemitter; // Whether or not the actual extension background provider is connected
16
+ #eventemitter;
16
17
 
17
- #isConnected = false; // Subscription IDs are (historically) not guaranteed to be globally unique;
18
+ // Whether or not the actual extension background provider is connected
19
+ #isConnected = false;
20
+
21
+ // Subscription IDs are (historically) not guaranteed to be globally unique;
18
22
  // only unique for a given subscription method; which is why we identify
19
23
  // the subscriptions based on subscription id + type
20
-
21
24
  #subscriptions = {}; // {[(type,subscriptionId)]: callback}
22
25
 
23
26
  /**
24
27
  * @param {function} sendRequest The function to be called to send requests to the node
25
28
  * @param {function} subscriptionNotificationHandler Channel for receiving subscription messages
26
29
  */
27
-
28
30
  constructor(_sendRequest) {
29
31
  this.#eventemitter = new EventEmitter();
30
32
  sendRequest = _sendRequest;
31
33
  }
34
+
32
35
  /**
33
36
  * @description Returns a clone of the object
34
37
  */
35
-
36
-
37
38
  clone() {
38
39
  return new PostMessageProvider(sendRequest);
39
40
  }
41
+
40
42
  /**
41
43
  * @description Manually disconnect from the connection, clearing autoconnect logic
42
44
  */
43
45
  // eslint-disable-next-line @typescript-eslint/require-await
44
-
45
-
46
46
  async connect() {
47
47
  // FIXME This should see if the extension's state's provider can disconnect
48
48
  console.error('PostMessageProvider.disconnect() is not implemented.');
49
49
  }
50
+
50
51
  /**
51
52
  * @description Manually disconnect from the connection, clearing autoconnect logic
52
53
  */
53
54
  // eslint-disable-next-line @typescript-eslint/require-await
54
-
55
-
56
55
  async disconnect() {
57
56
  // FIXME This should see if the extension's state's provider can disconnect
58
57
  console.error('PostMessageProvider.disconnect() is not implemented.');
59
58
  }
59
+
60
60
  /**
61
61
  * @summary `true` when this provider supports subscriptions
62
62
  */
63
-
64
-
65
63
  get hasSubscriptions() {
66
64
  // FIXME This should see if the extension's state's provider has subscriptions
67
65
  return true;
68
66
  }
67
+
69
68
  /**
70
69
  * @summary Whether the node is connected or not.
71
70
  * @return {boolean} true if connected
72
71
  */
73
-
74
-
75
72
  get isConnected() {
76
73
  return this.#isConnected;
77
74
  }
78
-
79
75
  listProviders() {
80
76
  return sendRequest('pub(rpc.listProviders)', undefined);
81
77
  }
78
+
82
79
  /**
83
80
  * @summary Listens on events after having subscribed using the [[subscribe]] function.
84
81
  * @param {ProviderInterfaceEmitted} type Event
85
82
  * @param {ProviderInterfaceEmitCb} sub Callback
86
83
  * @return unsubscribe function
87
84
  */
88
-
89
-
90
85
  on(type, sub) {
91
86
  this.#eventemitter.on(type, sub);
92
87
  return () => {
93
88
  this.#eventemitter.removeListener(type, sub);
94
89
  };
95
- } // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
-
90
+ }
97
91
 
92
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
93
  async send(method, params, _, subscription) {
99
94
  if (subscription) {
100
95
  const {
@@ -111,61 +106,55 @@ export default class PostMessageProvider {
111
106
  this.#subscriptions[`${type}::${id}`] = callback;
112
107
  return id;
113
108
  }
114
-
115
109
  return sendRequest('pub(rpc.send)', {
116
110
  method,
117
111
  params
118
112
  });
119
113
  }
114
+
120
115
  /**
121
116
  * @summary Spawn a provider on the extension background.
122
117
  */
123
-
124
-
125
118
  async startProvider(key) {
126
119
  // Disconnect from the previous provider
127
120
  this.#isConnected = false;
128
121
  this.#eventemitter.emit('disconnected');
129
- const meta = await sendRequest('pub(rpc.startProvider)', key); // eslint-disable-next-line @typescript-eslint/no-floating-promises
122
+ const meta = await sendRequest('pub(rpc.startProvider)', key);
130
123
 
124
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
131
125
  sendRequest('pub(rpc.subscribeConnected)', null, connected => {
132
126
  this.#isConnected = connected;
133
-
134
127
  if (connected) {
135
128
  this.#eventemitter.emit('connected');
136
129
  } else {
137
130
  this.#eventemitter.emit('disconnected');
138
131
  }
139
-
140
132
  return true;
141
133
  });
142
134
  return meta;
143
135
  }
144
-
145
136
  subscribe(type, method, params, callback) {
146
137
  return this.send(method, params, false, {
147
138
  callback,
148
139
  type
149
140
  });
150
141
  }
142
+
151
143
  /**
152
144
  * @summary Allows unsubscribing to subscriptions made with [[subscribe]].
153
145
  */
154
-
155
-
156
146
  async unsubscribe(type, method, id) {
157
- const subscription = `${type}::${id}`; // FIXME This now could happen with re-subscriptions. The issue is that with a re-sub
147
+ const subscription = `${type}::${id}`;
148
+
149
+ // FIXME This now could happen with re-subscriptions. The issue is that with a re-sub
158
150
  // the assigned id now does not match what the API user originally received. It has
159
151
  // a slight complication in solving - since we cannot rely on the send id, but rather
160
152
  // need to find the actual subscription id to map it
161
-
162
153
  if (isUndefined(this.#subscriptions[subscription])) {
163
154
  l.debug(() => `Unable to find active subscription=${subscription}`);
164
155
  return false;
165
156
  }
166
-
167
157
  delete this.#subscriptions[subscription];
168
158
  return this.send(method, [id]);
169
159
  }
170
-
171
160
  }
package/page/Signer.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // Copyright 2019-2022 @polkadot/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  // External to class, this.# is not private enough (yet)
4
5
  let sendRequest;
5
6
  let nextId = 0;
@@ -7,29 +8,30 @@ export default class Signer {
7
8
  constructor(_sendRequest) {
8
9
  sendRequest = _sendRequest;
9
10
  }
10
-
11
11
  async signPayload(payload) {
12
12
  const id = ++nextId;
13
- const result = await sendRequest('pub(extrinsic.sign)', payload); // we add an internal id (number) - should have a mapping from the
13
+ const result = await sendRequest('pub(extrinsic.sign)', payload);
14
+
15
+ // we add an internal id (number) - should have a mapping from the
14
16
  // extension id (string) -> internal id (number) if we wish to provide
15
17
  // updated via the update functionality (noop at this point)
16
-
17
- return { ...result,
18
+ return {
19
+ ...result,
18
20
  id
19
21
  };
20
22
  }
21
-
22
23
  async signRaw(payload) {
23
24
  const id = ++nextId;
24
25
  const result = await sendRequest('pub(bytes.sign)', payload);
25
- return { ...result,
26
+ return {
27
+ ...result,
26
28
  id
27
29
  };
28
- } // NOTE We don't listen to updates at all, if we do we can interpret the
30
+ }
31
+
32
+ // NOTE We don't listen to updates at all, if we do we can interpret the
29
33
  // resuklt as provided by the API here
30
34
  // public update (id: number, status: Hash | SubmittableResult): void {
31
35
  // // ignore
32
36
  // }
33
-
34
-
35
37
  }