@subwallet/extension-base 1.2.10-0 → 1.2.11-0

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 (41) hide show
  1. package/background/KoniTypes.d.ts +19 -0
  2. package/background/types.d.ts +42 -0
  3. package/cjs/koni/background/handlers/Extension.js +47 -15
  4. package/cjs/koni/background/handlers/State.js +3 -1
  5. package/cjs/packageInfo.js +1 -1
  6. package/cjs/services/balance-service/helpers/subscribe/index.js +8 -4
  7. package/cjs/services/chain-service/handler/SubstrateApi.js +20 -14
  8. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +31 -16
  9. package/cjs/services/migration-service/scripts/ClearMetadataDatabase.js +19 -0
  10. package/cjs/services/migration-service/scripts/MigrateLedgerAccountV2.js +51 -0
  11. package/cjs/services/migration-service/scripts/index.js +5 -1
  12. package/cjs/services/transaction-service/index.js +15 -4
  13. package/cjs/types/index.js +22 -11
  14. package/cjs/types/metadata.js +1 -0
  15. package/cjs/utils/index.js +12 -0
  16. package/cjs/utils/metadata.js +48 -0
  17. package/cjs/utils/registry.js +4 -3
  18. package/koni/background/handlers/Extension.js +48 -16
  19. package/koni/background/handlers/State.d.ts +2 -0
  20. package/koni/background/handlers/State.js +3 -1
  21. package/package.json +26 -5
  22. package/packageInfo.js +1 -1
  23. package/services/balance-service/helpers/subscribe/index.js +8 -4
  24. package/services/chain-service/handler/SubstrateApi.js +20 -14
  25. package/services/chain-service/handler/SubstrateChainHandler.js +31 -16
  26. package/services/migration-service/scripts/ClearMetadataDatabase.d.ts +4 -0
  27. package/services/migration-service/scripts/ClearMetadataDatabase.js +11 -0
  28. package/services/migration-service/scripts/MigrateLedgerAccountV2.d.ts +4 -0
  29. package/services/migration-service/scripts/MigrateLedgerAccountV2.js +42 -0
  30. package/services/migration-service/scripts/index.js +5 -1
  31. package/services/transaction-service/index.js +16 -5
  32. package/types/index.d.ts +2 -1
  33. package/types/index.js +2 -1
  34. package/types/metadata.d.ts +6 -0
  35. package/types/metadata.js +1 -0
  36. package/utils/index.d.ts +1 -0
  37. package/utils/index.js +1 -0
  38. package/utils/metadata.d.ts +3 -0
  39. package/utils/metadata.js +39 -0
  40. package/utils/registry.d.ts +2 -2
  41. package/utils/registry.js +4 -3
@@ -212,6 +212,18 @@ Object.keys(_lazy).forEach(function (key) {
212
212
  }
213
213
  });
214
214
  });
215
+ var _metadata = require("./metadata");
216
+ Object.keys(_metadata).forEach(function (key) {
217
+ if (key === "default" || key === "__esModule") return;
218
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
219
+ if (key in exports && exports[key] === _metadata[key]) return;
220
+ Object.defineProperty(exports, key, {
221
+ enumerable: true,
222
+ get: function () {
223
+ return _metadata[key];
224
+ }
225
+ });
226
+ });
215
227
  var _number = require("./number");
216
228
  Object.keys(_number).forEach(function (key) {
217
229
  if (key === "default" || key === "__esModule") return;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getShortMetadata = exports.getMetadataHash = exports._isRuntimeUpdated = void 0;
7
+ // Copyright 2019-2022 @subwallet/extension-base
8
+ // SPDX-License-Identifier: Apache-2.0
9
+
10
+ const LEDGER_API_URL = 'https://ledger-api.subwallet.app';
11
+ const createUrl = path => `${LEDGER_API_URL}/${path}`;
12
+ const _isRuntimeUpdated = signedExtensions => {
13
+ return signedExtensions.includes('CheckMetadataHash');
14
+ };
15
+ exports._isRuntimeUpdated = _isRuntimeUpdated;
16
+ const getMetadataHash = async chain => {
17
+ const data = {
18
+ id: chain
19
+ };
20
+ const resp = await fetch(createUrl('node/metadata/hash'), {
21
+ method: 'POST',
22
+ headers: {
23
+ 'Content-Type': 'application/json'
24
+ },
25
+ body: JSON.stringify(data)
26
+ });
27
+ const rs = await resp.json();
28
+ return rs.metadataHash;
29
+ };
30
+ exports.getMetadataHash = getMetadataHash;
31
+ const getShortMetadata = async (chain, blob) => {
32
+ const data = {
33
+ chain: {
34
+ id: chain
35
+ },
36
+ txBlob: blob
37
+ };
38
+ const resp = await fetch(createUrl('transaction/metadata'), {
39
+ method: 'POST',
40
+ headers: {
41
+ 'Content-Type': 'application/json'
42
+ },
43
+ body: JSON.stringify(data)
44
+ });
45
+ const rs = await resp.json();
46
+ return rs.txMetadata;
47
+ };
48
+ exports.getShortMetadata = getShortMetadata;
@@ -9,12 +9,13 @@ var _types = require("@polkadot/types");
9
9
  // Copyright 2019-2022 @subwallet/extension-base
10
10
  // SPDX-License-Identifier: Apache-2.0
11
11
 
12
- const createRegistry = (chain, rawMetadata) => {
12
+ const createRegistry = (chain, data) => {
13
13
  var _chain$substrateInfo;
14
14
  const registry = new _types.TypeRegistry();
15
- const metadata = new _types.Metadata(registry, rawMetadata);
16
- registry.setMetadata(metadata);
15
+ const metadata = new _types.Metadata(registry, data.rawMetadata);
17
16
  const tokenInfo = (0, _utils._getChainNativeTokenBasicInfo)(chain);
17
+ registry.register(data.types);
18
+ registry.setMetadata(metadata, undefined, data.userExtensions);
18
19
  registry.setChainProperties(registry.createType('ChainProperties', {
19
20
  ss58Format: ((_chain$substrateInfo = chain.substrateInfo) === null || _chain$substrateInfo === void 0 ? void 0 : _chain$substrateInfo.addressPrefix) || 42,
20
21
  tokenDecimals: tokenInfo.decimals,
@@ -35,13 +35,14 @@ import { AccountsStore } from '@subwallet/extension-base/stores';
35
35
  import { YieldPoolType } from '@subwallet/extension-base/types';
36
36
  import { BN_ZERO, convertSubjectInfoToAddresses, createTransactionFromRLP, isSameAddress, MODULE_SUPPORT, reformatAddress, signatureToHex, uniqueStringArray } from '@subwallet/extension-base/utils';
37
37
  import { parseContractInput, parseEvmRlp } from '@subwallet/extension-base/utils/eth/parseTransaction';
38
+ import { metadataExpand } from '@subwallet/extension-chains';
38
39
  import { createPair } from '@subwallet/keyring';
39
40
  import { keyring } from '@subwallet/ui-keyring';
40
41
  import { getSdkError } from '@walletconnect/utils';
41
42
  import BigN from 'bignumber.js';
42
43
  import { t } from 'i18next';
43
44
  import { Subject } from 'rxjs';
44
- import { TypeRegistry } from '@polkadot/types';
45
+ import { Metadata, TypeRegistry } from '@polkadot/types';
45
46
  import { assert, hexStripPrefix, hexToU8a, isAscii, isHex, u8aToHex, u8aToString } from '@polkadot/util';
46
47
  import { base64Decode, decodeAddress, isAddress, isEthereumAddress, jsonDecrypt, keyExtractSuri, mnemonicGenerate, mnemonicValidate } from '@polkadot/util-crypto';
47
48
  const ETH_DERIVE_DEFAULT = '/m/44\'/60\'/0\'/0/0';
@@ -347,7 +348,8 @@ export default class KoniExtension {
347
348
  // TODO: move to request service
348
349
  signingApproveSignature({
349
350
  id,
350
- signature
351
+ signature,
352
+ signedTransaction
351
353
  }) {
352
354
  const queued = this.#koniState.getSignRequest(id);
353
355
  assert(queued, t('Unable to proceed. Please try again'));
@@ -356,7 +358,8 @@ export default class KoniExtension {
356
358
  } = queued;
357
359
  resolve({
358
360
  id,
359
- signature
361
+ signature,
362
+ signedTransaction
360
363
  });
361
364
  return true;
362
365
  }
@@ -2148,6 +2151,7 @@ export default class KoniExtension {
2148
2151
  genesisHash,
2149
2152
  hardwareType,
2150
2153
  isEthereum,
2154
+ isGeneric,
2151
2155
  name
2152
2156
  } = account;
2153
2157
  let result;
@@ -2157,7 +2161,8 @@ export default class KoniExtension {
2157
2161
  accountIndex,
2158
2162
  addressOffset,
2159
2163
  genesisHash,
2160
- originGenesisHash: genesisHash
2164
+ originGenesisHash: genesisHash,
2165
+ isGeneric
2161
2166
  };
2162
2167
  if (isEthereum) {
2163
2168
  result = keyring.keyring.addFromAddress(address, {
@@ -2898,7 +2903,7 @@ export default class KoniExtension {
2898
2903
  }
2899
2904
 
2900
2905
  /// Signing substrate request
2901
- signingApprovePasswordV2({
2906
+ async signingApprovePasswordV2({
2902
2907
  id
2903
2908
  }) {
2904
2909
  const queued = this.#koniState.getSignRequest(id);
@@ -2926,22 +2931,42 @@ export default class KoniExtension {
2926
2931
  const {
2927
2932
  payload
2928
2933
  } = request;
2929
- let registry = new TypeRegistry();
2934
+ let registry;
2930
2935
  let isEvm = false;
2931
2936
  if (isJsonPayload(payload)) {
2937
+ const [, chainInfo] = this.#koniState.findNetworkKeyByGenesisHash(payload.genesisHash);
2938
+ let metadata;
2939
+
2932
2940
  /**
2933
2941
  * Get the metadata for the genesisHash
2934
2942
  * @todo: need to handle case metadata store in db
2935
2943
  */
2936
- const currentMetadata = this.#koniState.knownMetadata.find(meta => meta.genesisHash === payload.genesisHash);
2937
-
2938
- // set the registry before calling the sign function
2939
- registry.setSignedExtensions(payload.signedExtensions, currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.userExtensions);
2940
- if (currentMetadata) {
2941
- registry.register(currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.types);
2944
+ metadata = this.#koniState.knownMetadata.find(meta => meta.genesisHash === payload.genesisHash);
2945
+ if (metadata) {
2946
+ // we have metadata, expand it and extract the info/registry
2947
+ const expanded = metadataExpand(metadata, false);
2948
+ registry = expanded.registry;
2949
+ registry.setSignedExtensions(payload.signedExtensions, expanded.definition.userExtensions);
2950
+ } else {
2951
+ metadata = await this.#koniState.chainService.getMetadataByHash(payload.genesisHash);
2952
+ if (metadata) {
2953
+ var _chainInfo$substrateI, _chainInfo$substrateI2, _chainInfo$substrateI3;
2954
+ registry = new TypeRegistry();
2955
+ const _metadata = new Metadata(registry, metadata.hexValue);
2956
+ registry.register(metadata.types);
2957
+ registry.setChainProperties(registry.createType('ChainProperties', {
2958
+ ss58Format: (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI = chainInfo.substrateInfo) === null || _chainInfo$substrateI === void 0 ? void 0 : _chainInfo$substrateI.addressPrefix) || 42,
2959
+ tokenDecimals: chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI2 = chainInfo.substrateInfo) === null || _chainInfo$substrateI2 === void 0 ? void 0 : _chainInfo$substrateI2.decimals,
2960
+ tokenSymbol: chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI3 = chainInfo.substrateInfo) === null || _chainInfo$substrateI3 === void 0 ? void 0 : _chainInfo$substrateI3.symbol
2961
+ }));
2962
+ registry.setMetadata(_metadata, payload.signedExtensions, metadata.userExtensions);
2963
+ } else {
2964
+ // we have no metadata, create a new registry
2965
+ registry = new TypeRegistry();
2966
+ registry.setSignedExtensions(payload.signedExtensions);
2967
+ }
2942
2968
  }
2943
- const [, chainInfo] = this.#koniState.findNetworkKeyByGenesisHash(payload.genesisHash);
2944
- if (!currentMetadata) {
2969
+ if (!metadata) {
2945
2970
  /*
2946
2971
  * Some networks must have metadata to signing,
2947
2972
  * so if the chain not active (cannot use metadata from api), it must be rejected
@@ -2964,6 +2989,9 @@ export default class KoniExtension {
2964
2989
  if (chainInfo) {
2965
2990
  isEvm = _isChainEvmCompatible(chainInfo);
2966
2991
  }
2992
+ } else {
2993
+ // for non-payload, just create a registry to use
2994
+ registry = new TypeRegistry();
2967
2995
  }
2968
2996
  const result = request.sign(registry, pair);
2969
2997
  resolve({
@@ -3603,11 +3631,15 @@ export default class KoniExtension {
3603
3631
  }) {
3604
3632
  const {
3605
3633
  metadata,
3606
- specVersion
3634
+ specVersion,
3635
+ types,
3636
+ userExtensions
3607
3637
  } = await this.#koniState.findMetadata(genesisHash);
3608
3638
  return {
3609
3639
  rawMetadata: metadata,
3610
- specVersion
3640
+ specVersion,
3641
+ types,
3642
+ userExtensions
3611
3643
  };
3612
3644
  }
3613
3645
  async resolveDomainByAddress(request) {
@@ -255,6 +255,8 @@ export default class KoniState {
255
255
  findMetadata(hash: string): Promise<{
256
256
  metadata: string;
257
257
  specVersion: number;
258
+ types: Record<string, string | Record<string, string>>;
259
+ userExtensions: import("@polkadot/types/extrinsic/signedExtensions/types").ExtDef | undefined;
258
260
  }>;
259
261
  getCrowdloanContributions({ address, page, relayChain }: RequestCrowdloanContributions): Promise<import("../../../services/subscan-service/types").CrowdloanContributionsResponse>;
260
262
  }
@@ -1791,7 +1791,9 @@ export default class KoniState {
1791
1791
  const metadata = await this.chainService.getMetadataByHash(hash);
1792
1792
  return {
1793
1793
  metadata: (metadata === null || metadata === void 0 ? void 0 : metadata.hexValue) || '',
1794
- specVersion: parseInt((metadata === null || metadata === void 0 ? void 0 : metadata.specVersion) || '0')
1794
+ specVersion: parseInt((metadata === null || metadata === void 0 ? void 0 : metadata.specVersion) || '0'),
1795
+ types: (metadata === null || metadata === void 0 ? void 0 : metadata.types) || {},
1796
+ userExtensions: metadata === null || metadata === void 0 ? void 0 : metadata.userExtensions
1795
1797
  };
1796
1798
  }
1797
1799
  getCrowdloanContributions({
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.2.10-0",
20
+ "version": "1.2.11-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -956,6 +956,11 @@
956
956
  "require": "./cjs/services/migration-service/scripts/AutoEnableChainsTokens.js",
957
957
  "default": "./services/migration-service/scripts/AutoEnableChainsTokens.js"
958
958
  },
959
+ "./services/migration-service/scripts/ClearMetadataDatabase": {
960
+ "types": "./services/migration-service/scripts/ClearMetadataDatabase.d.ts",
961
+ "require": "./cjs/services/migration-service/scripts/ClearMetadataDatabase.js",
962
+ "default": "./services/migration-service/scripts/ClearMetadataDatabase.js"
963
+ },
959
964
  "./services/migration-service/scripts/ClearOldStorage": {
960
965
  "types": "./services/migration-service/scripts/ClearOldStorage.d.ts",
961
966
  "require": "./cjs/services/migration-service/scripts/ClearOldStorage.js",
@@ -1036,6 +1041,11 @@
1036
1041
  "require": "./cjs/services/migration-service/scripts/MigrateLedgerAccount.js",
1037
1042
  "default": "./services/migration-service/scripts/MigrateLedgerAccount.js"
1038
1043
  },
1044
+ "./services/migration-service/scripts/MigrateLedgerAccountV2": {
1045
+ "types": "./services/migration-service/scripts/MigrateLedgerAccountV2.d.ts",
1046
+ "require": "./cjs/services/migration-service/scripts/MigrateLedgerAccountV2.js",
1047
+ "default": "./services/migration-service/scripts/MigrateLedgerAccountV2.js"
1048
+ },
1039
1049
  "./services/migration-service/scripts/MigrateNetworkSettings": {
1040
1050
  "types": "./services/migration-service/scripts/MigrateNetworkSettings.d.ts",
1041
1051
  "require": "./cjs/services/migration-service/scripts/MigrateNetworkSettings.js",
@@ -1636,6 +1646,11 @@
1636
1646
  "require": "./cjs/types/fee/fee.js",
1637
1647
  "default": "./types/fee/fee.js"
1638
1648
  },
1649
+ "./types/metadata": {
1650
+ "types": "./types/metadata.d.ts",
1651
+ "require": "./cjs/types/metadata.js",
1652
+ "default": "./types/metadata.js"
1653
+ },
1639
1654
  "./types/ordinal": {
1640
1655
  "types": "./types/ordinal.d.ts",
1641
1656
  "require": "./cjs/types/ordinal.js",
@@ -1836,6 +1851,11 @@
1836
1851
  "require": "./cjs/utils/lazy.js",
1837
1852
  "default": "./utils/lazy.js"
1838
1853
  },
1854
+ "./utils/metadata": {
1855
+ "types": "./utils/metadata.d.ts",
1856
+ "require": "./cjs/utils/metadata.js",
1857
+ "default": "./utils/metadata.js"
1858
+ },
1839
1859
  "./utils/mv3": {
1840
1860
  "types": "./utils/mv3.d.ts",
1841
1861
  "require": "./cjs/utils/mv3.js",
@@ -1920,6 +1940,7 @@
1920
1940
  "@polkadot/rpc-provider": "^11.0.3",
1921
1941
  "@polkadot/types": "^11.0.3",
1922
1942
  "@polkadot/types-augment": "^11.0.3",
1943
+ "@polkadot/types-known": "^10.12.4",
1923
1944
  "@polkadot/ui-settings": "^3.6.6",
1924
1945
  "@polkadot/util": "^12.6.2",
1925
1946
  "@polkadot/util-crypto": "^12.6.2",
@@ -1928,10 +1949,10 @@
1928
1949
  "@sora-substrate/type-definitions": "^1.17.7",
1929
1950
  "@substrate/connect": "^0.8.9",
1930
1951
  "@subwallet/chain-list": "0.2.70",
1931
- "@subwallet/extension-base": "^1.2.10-0",
1932
- "@subwallet/extension-chains": "^1.2.10-0",
1933
- "@subwallet/extension-dapp": "^1.2.10-0",
1934
- "@subwallet/extension-inject": "^1.2.10-0",
1952
+ "@subwallet/extension-base": "^1.2.11-0",
1953
+ "@subwallet/extension-chains": "^1.2.11-0",
1954
+ "@subwallet/extension-dapp": "^1.2.11-0",
1955
+ "@subwallet/extension-inject": "^1.2.11-0",
1935
1956
  "@subwallet/keyring": "^0.1.5",
1936
1957
  "@subwallet/ui-keyring": "^0.1.5",
1937
1958
  "@walletconnect/keyvaluestorage": "^1.1.1",
package/packageInfo.js CHANGED
@@ -7,5 +7,5 @@ export const packageInfo = {
7
7
  name: '@subwallet/extension-base',
8
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
9
9
  type: 'esm',
10
- version: '1.2.10-0'
10
+ version: '1.2.11-0'
11
11
  };
@@ -49,12 +49,16 @@ const filterAddress = (addresses, chainInfo) => {
49
49
  const account = getAccountJsonByAddress(address);
50
50
  if (account) {
51
51
  if (account.isHardware) {
52
- const availGen = account.availableGenesisHashes || [];
53
- const gen = _getSubstrateGenesisHash(chainInfo);
54
- if (availGen.includes(gen)) {
52
+ if (account.isGeneric) {
55
53
  fetchList.push(address);
56
54
  } else {
57
- unfetchList.push(address);
55
+ const availGen = account.availableGenesisHashes || [];
56
+ const gen = _getSubstrateGenesisHash(chainInfo);
57
+ if (availGen.includes(gen)) {
58
+ fetchList.push(address);
59
+ } else {
60
+ unfetchList.push(address);
61
+ }
58
62
  }
59
63
  } else {
60
64
  fetchList.push(address);
@@ -13,10 +13,21 @@ import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
13
13
  import { goldbergRpc, goldbergTypes, spec as availSpec } from 'avail-js-sdk';
14
14
  import { BehaviorSubject } from 'rxjs';
15
15
  import { ApiPromise, WsProvider } from '@polkadot/api';
16
- import { typesBundle } from '@polkadot/apps-config/api';
16
+ import { typesBundle as _typesBundle } from '@polkadot/apps-config/api';
17
17
  import { TypeRegistry } from '@polkadot/types/create';
18
18
  import { formatBalance } from '@polkadot/util';
19
19
  import { defaults as addressDefaults } from '@polkadot/util-crypto/address/defaults';
20
+ const typesBundle = {
21
+ ..._typesBundle
22
+ };
23
+
24
+ // Override avail spec for signedExtensions
25
+ const _availSpec = {
26
+ signedExtensions: availSpec.signedExtensions
27
+ };
28
+ if (typesBundle.spec) {
29
+ typesBundle.spec.avail = _availSpec;
30
+ }
20
31
  export class SubstrateApi {
21
32
  useLightClient = false;
22
33
  isApiReady = false;
@@ -58,6 +69,7 @@ export class SubstrateApi {
58
69
  provider,
59
70
  typesBundle,
60
71
  registry: this.registry,
72
+ // This line makes this object registry to be the same as the api registry
61
73
  noInitWarn: true
62
74
  };
63
75
  if (this.metadata) {
@@ -71,32 +83,26 @@ export class SubstrateApi {
71
83
  if (externalApiPromise) {
72
84
  api = externalApiPromise;
73
85
  } else if (_API_OPTIONS_CHAIN_GROUP.acala.includes(this.chainSlug)) {
74
- api = new ApiPromise(acalaOptions({
75
- provider,
76
- noInitWarn: true
77
- }));
86
+ api = new ApiPromise(acalaOptions(apiOption));
78
87
  } else if (_API_OPTIONS_CHAIN_GROUP.turing.includes(this.chainSlug)) {
79
88
  api = new ApiPromise({
80
- provider,
89
+ ...apiOption,
81
90
  rpc: oakRpc,
82
- types: oakTypes,
83
- noInitWarn: true
91
+ types: oakTypes
84
92
  });
85
93
  } else if (_API_OPTIONS_CHAIN_GROUP.avail.includes(this.chainSlug)) {
86
94
  api = new ApiPromise({
87
- provider,
95
+ ...apiOption,
88
96
  rpc: availSpec.rpc,
89
97
  types: availSpec.types,
90
- signedExtensions: availSpec.signedExtensions,
91
- noInitWarn: true
98
+ signedExtensions: availSpec.signedExtensions
92
99
  });
93
100
  } else if (_API_OPTIONS_CHAIN_GROUP.goldberg.includes(this.chainSlug)) {
94
101
  api = new ApiPromise({
95
- provider,
102
+ ...apiOption,
96
103
  rpc: goldbergRpc,
97
104
  types: goldbergTypes,
98
- signedExtensions: availSpec.signedExtensions,
99
- noInitWarn: true
105
+ signedExtensions: availSpec.signedExtensions
100
106
  });
101
107
  } else if (_API_OPTIONS_CHAIN_GROUP.gear.includes(this.chainSlug)) {
102
108
  api = new GearApi({
@@ -8,6 +8,7 @@ import { AbstractChainHandler } from '@subwallet/extension-base/services/chain-s
8
8
  import { SubstrateApi } from '@subwallet/extension-base/services/chain-service/handler/SubstrateApi';
9
9
  import { DEFAULT_GEAR_ADDRESS, getGRC20ContractPromise } from '@subwallet/extension-base/utils';
10
10
  import { ContractPromise } from '@polkadot/api-contract';
11
+ import { getSpecExtensions, getSpecTypes } from '@polkadot/types-known';
11
12
  import { BN } from '@polkadot/util';
12
13
  import { logger as createLogger } from '@polkadot/util/logger';
13
14
  import { _PSP22_ABI, _PSP34_ABI } from "../../../koni/api/contract-handler/utils/index.js";
@@ -198,6 +199,32 @@ export class SubstrateChainHandler extends AbstractChainHandler {
198
199
  } = {}) {
199
200
  var _this$parent2;
200
201
  const existed = this.substrateApiMap[chainSlug];
202
+ const metadata = await ((_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.getMetadata(chainSlug));
203
+ const updateMetadata = substrateApi => {
204
+ // Update metadata to database with async methods
205
+ substrateApi.api.isReady.then(async api => {
206
+ var _this$parent3;
207
+ const currentSpecVersion = api.runtimeVersion.specVersion.toString();
208
+ const genesisHash = api.genesisHash.toHex();
209
+
210
+ // Avoid date existed metadata
211
+ if (metadata && metadata.specVersion === currentSpecVersion && metadata.genesisHash === genesisHash) {
212
+ return;
213
+ }
214
+ const systemChain = await api.rpc.system.chain();
215
+ // const _metadata: Option<OpaqueMetadata> = await api.call.metadata.metadataAtVersion(15);
216
+ // const metadataHex = _metadata.isSome ? _metadata.unwrap().toHex().slice(2) : ''; // Need unwrap to create metadata object
217
+
218
+ (_this$parent3 = this.parent) === null || _this$parent3 === void 0 ? void 0 : _this$parent3.upsertMetadata(chainSlug, {
219
+ chain: chainSlug,
220
+ genesisHash: genesisHash,
221
+ specVersion: currentSpecVersion,
222
+ hexValue: api.runtimeMetadata.toHex(),
223
+ types: getSpecTypes(api.registry, systemChain, api.runtimeVersion.specName, api.runtimeVersion.specVersion),
224
+ userExtensions: getSpecExtensions(api.registry, systemChain, api.runtimeVersion.specName)
225
+ }).catch(console.error);
226
+ }).catch(console.error);
227
+ };
201
228
 
202
229
  // Return existed to avoid re-init metadata
203
230
  if (existed) {
@@ -205,9 +232,11 @@ export class SubstrateChainHandler extends AbstractChainHandler {
205
232
  if (apiUrl !== existed.apiUrl) {
206
233
  await existed.updateApiUrl(apiUrl);
207
234
  }
235
+
236
+ // Update data in case of existed api (if needed - old provider cannot connect)
237
+ updateMetadata(existed);
208
238
  return existed;
209
239
  }
210
- const metadata = await ((_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.getMetadata(chainSlug));
211
240
  const apiObject = new SubstrateApi(chainSlug, apiUrl, {
212
241
  providerName,
213
242
  metadata,
@@ -215,21 +244,7 @@ export class SubstrateChainHandler extends AbstractChainHandler {
215
244
  });
216
245
  apiObject.connectionStatusSubject.subscribe(this.handleConnection.bind(this, chainSlug));
217
246
  onUpdateStatus && apiObject.connectionStatusSubject.subscribe(onUpdateStatus);
218
-
219
- // Update metadata to database with async methods
220
- apiObject.isReady.then(api => {
221
- var _this$parent3;
222
- // Avoid date existed metadata
223
- if (metadata && metadata.specVersion === api.specVersion && metadata.genesisHash === api.api.genesisHash.toHex()) {
224
- return;
225
- }
226
- (_this$parent3 = this.parent) === null || _this$parent3 === void 0 ? void 0 : _this$parent3.upsertMetadata(chainSlug, {
227
- chain: chainSlug,
228
- genesisHash: api.api.genesisHash.toHex(),
229
- specVersion: api.specVersion,
230
- hexValue: api.api.runtimeMetadata.toHex()
231
- }).catch(console.error);
232
- }).catch(console.error);
247
+ updateMetadata(apiObject);
233
248
  return apiObject;
234
249
  }
235
250
  }
@@ -0,0 +1,4 @@
1
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
2
+ export default class ClearMetadataDatabase extends BaseMigrationJob {
3
+ run(): Promise<void>;
4
+ }
@@ -0,0 +1,11 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
5
+ export default class ClearMetadataDatabase extends BaseMigrationJob {
6
+ async run() {
7
+ // Clear all old metadata data
8
+ await this.state.dbService.stores.metadata.clear();
9
+ return Promise.resolve();
10
+ }
11
+ }
@@ -0,0 +1,4 @@
1
+ import BaseMigrationJob from '../Base';
2
+ export default class MigrateLedgerAccountV2 extends BaseMigrationJob {
3
+ run(): Promise<void>;
4
+ }
@@ -0,0 +1,42 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { AccountsStore } from '@subwallet/extension-base/stores';
5
+ import { isString } from '@polkadot/util';
6
+ import { isEthereumAddress } from '@polkadot/util-crypto';
7
+ import BaseMigrationJob from "../Base.js";
8
+ export default class MigrateLedgerAccountV2 extends BaseMigrationJob {
9
+ async run() {
10
+ try {
11
+ return new Promise(resolve => {
12
+ const store = new AccountsStore();
13
+ const update = (key, value) => {
14
+ var _value$meta;
15
+ if (key.startsWith('account:') && value.meta && isString((_value$meta = value.meta) === null || _value$meta === void 0 ? void 0 : _value$meta.originGenesisHash)) {
16
+ const newValue = {
17
+ ...value
18
+ };
19
+ if (value.meta.isHardware) {
20
+ const isEther = isEthereumAddress(value.address);
21
+ if (isEther) {
22
+ newValue.meta.isGeneric = true;
23
+ } else {
24
+ newValue.meta.isGeneric = !newValue.meta.originGenesisHash;
25
+ }
26
+ }
27
+ newValue.meta.availableGenesisHashes = [value.meta.originGenesisHash];
28
+ store.set(key, newValue);
29
+ }
30
+ };
31
+ store.allMap(map => {
32
+ Object.entries(map).forEach(([key, value]) => {
33
+ update(key, value);
34
+ });
35
+ resolve();
36
+ });
37
+ });
38
+ } catch (e) {
39
+ console.error(e);
40
+ }
41
+ }
42
+ }
@@ -12,6 +12,7 @@ import MigratePioneerProvider from "./providers/MigratePioneerProvider.js";
12
12
  import MigrateProvidersV1M1P24 from "./providers/MigrateProvidersV1M1P24.js";
13
13
  import MigratePolygonUSDCProvider from "./tokens/MigratePolygonUSDCProvider.js";
14
14
  import AutoEnableChainsTokens from "./AutoEnableChainsTokens.js";
15
+ import ClearMetadataDatabase from "./ClearMetadataDatabase.js";
15
16
  import DeleteChain from "./DeleteChain.js";
16
17
  import DeleteChainStaking from "./DeleteChainStaking.js";
17
18
  import EnableVaraChain from "./EnableVaraChain.js";
@@ -20,6 +21,7 @@ import MigrateAutoLock from "./MigrateAutoLock.js";
20
21
  import MigrateChainPatrol from "./MigrateChainPatrol.js";
21
22
  import MigrateImportedToken from "./MigrateImportedToken.js";
22
23
  import MigrateLedgerAccount from "./MigrateLedgerAccount.js";
24
+ import MigrateLedgerAccountV2 from "./MigrateLedgerAccountV2.js";
23
25
  import MigrateNetworkSettings from "./MigrateNetworkSettings.js";
24
26
  import MigrateSettings from "./MigrateSettings.js";
25
27
  import MigrateTokenDecimals from "./MigrateTokenDecimals.js";
@@ -47,11 +49,13 @@ export default {
47
49
  '1.1.24-01': MigrateProvidersV1M1P24,
48
50
  '1.1.26-01': MigratePolygonUSDCProvider,
49
51
  '1.1.28-01': MigrateEarningVersion,
52
+ '1.1.33-01': MigrateLedgerAccountV2,
50
53
  '1.1.41-01': DeleteChainStaking,
51
54
  '1.1.46-01': AutoEnableSomeTokens,
52
55
  '1.1.69-03': MigrateAssetSetting,
53
56
  '1.1.69-02': MigrateTransactionHistoryBySymbol,
54
- '1.2.69-01': MigrateRemoveGenesisHash
57
+ '1.2.69-01': MigrateRemoveGenesisHash,
58
+ '1.2.1-01': ClearMetadataDatabase
55
59
  // [`${EVERYTIME}-1.1.42-02`]: MigrateTransactionHistoryBySymbol
56
60
  // [`${EVERYTIME}-1`]: AutoEnableChainsTokens
57
61
  };
@@ -14,7 +14,7 @@ import { getBaseTransactionInfo, getTransactionId, isSubstrateTransaction } from
14
14
  import { getExplorerLink, parseTransactionData } from '@subwallet/extension-base/services/transaction-service/utils';
15
15
  import { isWalletConnectRequest } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
16
16
  import { YieldPoolType } from '@subwallet/extension-base/types';
17
- import { anyNumberToBN, reformatAddress } from '@subwallet/extension-base/utils';
17
+ import { _isRuntimeUpdated, anyNumberToBN, getMetadataHash, reformatAddress } from '@subwallet/extension-base/utils';
18
18
  import { mergeTransactionAndSignature } from '@subwallet/extension-base/utils/eth/mergeTransactionAndSignature';
19
19
  import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
20
20
  import { BN_ZERO } from '@subwallet/extension-base/utils/number';
@@ -189,7 +189,7 @@ export default class TransactionService {
189
189
  }
190
190
  async sendTransaction(transaction) {
191
191
  // Send Transaction
192
- const emitter = transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) : await this.signAndSendEvmTransaction(transaction);
192
+ const emitter = await (transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) : this.signAndSendEvmTransaction(transaction));
193
193
  const {
194
194
  eventsHandler
195
195
  } = transaction;
@@ -1010,7 +1010,7 @@ export default class TransactionService {
1010
1010
  }
1011
1011
  return emitter;
1012
1012
  }
1013
- signAndSendSubstrateTransaction({
1013
+ async signAndSendSubstrateTransaction({
1014
1014
  address,
1015
1015
  chain,
1016
1016
  id,
@@ -1024,7 +1024,10 @@ export default class TransactionService {
1024
1024
  warnings: [],
1025
1025
  extrinsicHash: id
1026
1026
  };
1027
- transaction.signAsync(address, {
1027
+ const extrinsic = transaction;
1028
+ const registry = extrinsic.registry;
1029
+ const signedExtensions = registry.signedExtensions;
1030
+ const signerOption = {
1028
1031
  signer: {
1029
1032
  signPayload: async payload => {
1030
1033
  const signing = await this.state.requestService.signInternalTransaction(id, address, url || EXTENSION_REQUEST_URL, payload);
@@ -1034,7 +1037,15 @@ export default class TransactionService {
1034
1037
  };
1035
1038
  }
1036
1039
  }
1037
- }).then(async rs => {
1040
+ };
1041
+ if (_isRuntimeUpdated(signedExtensions)) {
1042
+ try {
1043
+ const metadataHash = await getMetadataHash(chain);
1044
+ signerOption.mode = 1;
1045
+ signerOption.metadataHash = `0x${metadataHash}`;
1046
+ } catch (e) {}
1047
+ }
1048
+ extrinsic.signAsync(address, signerOption).then(async rs => {
1038
1049
  // Emit signed event
1039
1050
  emitter.emit('signed', eventData);
1040
1051