@subwallet/extension-base 1.0.9-1 → 1.0.10-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 (54) hide show
  1. package/background/KoniTypes.d.ts +5 -1
  2. package/background/types.d.ts +2 -1
  3. package/cjs/koni/api/dotsama/transfer.js +16 -7
  4. package/cjs/koni/api/staking/bonding/paraChain.js +3 -2
  5. package/cjs/koni/api/staking/bonding/relayChain.js +3 -2
  6. package/cjs/koni/api/staking/bonding/utils.js +1 -1
  7. package/cjs/koni/api/xcm/polkadotXcm.js +5 -4
  8. package/cjs/koni/api/xcm/xTokens.js +1 -1
  9. package/cjs/koni/api/xcm/xcmPallet.js +1 -1
  10. package/cjs/koni/background/handlers/Extension.js +57 -18
  11. package/cjs/koni/background/handlers/State.js +3 -3
  12. package/cjs/packageInfo.js +1 -1
  13. package/cjs/services/chain-service/constants.js +2 -1
  14. package/cjs/services/chain-service/helper/api-helper/spec/dataavail.js +152 -0
  15. package/cjs/services/chain-service/helper/api-helper/spec/index.js +2 -0
  16. package/cjs/services/chain-service/index.js +1 -1
  17. package/cjs/services/migration-service/scripts/MigrateLedgerAccount.js +42 -0
  18. package/cjs/services/migration-service/scripts/index.js +3 -1
  19. package/cjs/services/transaction-service/index.js +15 -15
  20. package/cjs/signers/web3/QrSigner.js +14 -6
  21. package/cjs/utils/eth/mergeTransactionAndSignature.js +22 -13
  22. package/cjs/utils/eth/parseTransaction/base.js +6 -6
  23. package/cjs/utils/eth/parseTransaction/index.js +4 -5
  24. package/cjs/utils/eth.js +14 -18
  25. package/koni/api/dotsama/transfer.js +16 -7
  26. package/koni/api/staking/bonding/paraChain.js +3 -2
  27. package/koni/api/staking/bonding/relayChain.js +3 -2
  28. package/koni/api/staking/bonding/utils.js +1 -1
  29. package/koni/api/xcm/polkadotXcm.js +5 -4
  30. package/koni/api/xcm/xTokens.js +1 -1
  31. package/koni/api/xcm/xcmPallet.js +1 -1
  32. package/koni/background/handlers/Extension.d.ts +0 -1
  33. package/koni/background/handlers/Extension.js +57 -18
  34. package/koni/background/handlers/State.js +3 -3
  35. package/package.json +17 -8
  36. package/packageInfo.js +1 -1
  37. package/services/chain-service/constants.d.ts +1 -0
  38. package/services/chain-service/constants.js +2 -1
  39. package/services/chain-service/helper/api-helper/spec/dataavail.d.ts +3 -0
  40. package/services/chain-service/helper/api-helper/spec/dataavail.js +145 -0
  41. package/services/chain-service/helper/api-helper/spec/index.js +2 -0
  42. package/services/chain-service/index.js +1 -1
  43. package/services/migration-service/scripts/MigrateLedgerAccount.d.ts +4 -0
  44. package/services/migration-service/scripts/MigrateLedgerAccount.js +33 -0
  45. package/services/migration-service/scripts/index.js +3 -1
  46. package/services/transaction-service/index.js +17 -17
  47. package/signers/types.d.ts +1 -1
  48. package/signers/web3/QrSigner.js +14 -5
  49. package/utils/eth/mergeTransactionAndSignature.d.ts +1 -1
  50. package/utils/eth/mergeTransactionAndSignature.js +20 -10
  51. package/utils/eth/parseTransaction/base.js +6 -6
  52. package/utils/eth/parseTransaction/index.js +4 -5
  53. package/utils/eth.d.ts +2 -3
  54. package/utils/eth.js +14 -17
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.0.9-1",
20
+ "version": "1.0.10-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -705,6 +705,11 @@
705
705
  "require": "./cjs/services/chain-service/helper/api-helper/spec/darwinia.js",
706
706
  "default": "./services/chain-service/helper/api-helper/spec/darwinia.js"
707
707
  },
708
+ "./services/chain-service/helper/api-helper/spec/dataavail": {
709
+ "types": "./services/chain-service/helper/api-helper/spec/dataavail.d.ts",
710
+ "require": "./cjs/services/chain-service/helper/api-helper/spec/dataavail.js",
711
+ "default": "./services/chain-service/helper/api-helper/spec/dataavail.js"
712
+ },
708
713
  "./services/chain-service/helper/api-helper/spec/datahighway": {
709
714
  "types": "./services/chain-service/helper/api-helper/spec/datahighway.d.ts",
710
715
  "require": "./cjs/services/chain-service/helper/api-helper/spec/datahighway.js",
@@ -1260,6 +1265,11 @@
1260
1265
  "require": "./cjs/services/migration-service/scripts/MigrateImportedToken.js",
1261
1266
  "default": "./services/migration-service/scripts/MigrateImportedToken.js"
1262
1267
  },
1268
+ "./services/migration-service/scripts/MigrateLedgerAccount": {
1269
+ "types": "./services/migration-service/scripts/MigrateLedgerAccount.d.ts",
1270
+ "require": "./cjs/services/migration-service/scripts/MigrateLedgerAccount.js",
1271
+ "default": "./services/migration-service/scripts/MigrateLedgerAccount.js"
1272
+ },
1263
1273
  "./services/migration-service/scripts/MigrateNetworkSettings": {
1264
1274
  "types": "./services/migration-service/scripts/MigrateNetworkSettings.d.ts",
1265
1275
  "require": "./cjs/services/migration-service/scripts/MigrateNetworkSettings.js",
@@ -1707,11 +1717,11 @@
1707
1717
  "@sora-substrate/type-definitions": "^1.17.7",
1708
1718
  "@subsocial/types": "^0.6.8",
1709
1719
  "@substrate/connect": "^0.7.26",
1710
- "@subwallet/chain-list": "0.1.11-beta.1",
1711
- "@subwallet/extension-base": "^1.0.9-1",
1712
- "@subwallet/extension-chains": "^1.0.9-1",
1713
- "@subwallet/extension-dapp": "^1.0.9-1",
1714
- "@subwallet/extension-inject": "^1.0.9-1",
1720
+ "@subwallet/chain-list": "0.2.1",
1721
+ "@subwallet/extension-base": "^1.0.10-0",
1722
+ "@subwallet/extension-chains": "^1.0.10-0",
1723
+ "@subwallet/extension-dapp": "^1.0.10-0",
1724
+ "@subwallet/extension-inject": "^1.0.10-0",
1715
1725
  "@subwallet/keyring": "^0.0.10",
1716
1726
  "@subwallet/ui-keyring": "^0.0.10",
1717
1727
  "@unique-nft/types": "^0.6.0-4",
@@ -1729,7 +1739,7 @@
1729
1739
  "eth-simple-keyring": "^4.2.0",
1730
1740
  "ethereumjs-tx": "^2.1.2",
1731
1741
  "ethereumjs-util": "^7.1.5",
1732
- "ethers": "^5.7.2",
1742
+ "ethers": "^6.4.2",
1733
1743
  "eventemitter3": "^5.0.0",
1734
1744
  "file-saver": "^2.0.5",
1735
1745
  "graphql": "^16.6.0",
@@ -1741,7 +1751,6 @@
1741
1751
  "phosphor-react": "^1.4.1",
1742
1752
  "pontem-types-bundle": "^1.0.15",
1743
1753
  "protobufjs": "^7.1.2",
1744
- "rlp": "^3.0.0",
1745
1754
  "rxjs": "^7.8.0",
1746
1755
  "web3": "^1.10.0",
1747
1756
  "web3-core": "^1.10.0",
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.0.9-1'
10
+ version: '1.0.10-0'
11
11
  };
@@ -64,6 +64,7 @@ export declare const _TRANSFER_CHAIN_GROUP: {
64
64
  statemine: string[];
65
65
  riochain: string[];
66
66
  sora_substrate: string[];
67
+ avail: string[];
67
68
  };
68
69
  export declare const _BALANCE_PARSING_CHAIN_GROUP: {
69
70
  bobabeam: string[];
@@ -182,7 +182,8 @@ export const _TRANSFER_CHAIN_GROUP = {
182
182
  bitcountry: ['pioneer', 'bitcountry', 'bifrost', 'bifrost_dot'],
183
183
  statemine: ['statemint', 'statemine', 'darwinia2', 'astar', 'shiden', 'shibuya', 'parallel'],
184
184
  riochain: ['riochain'],
185
- sora_substrate: ['sora_substrate']
185
+ sora_substrate: ['sora_substrate'],
186
+ avail: ['kate']
186
187
  };
187
188
  export const _BALANCE_PARSING_CHAIN_GROUP = {
188
189
  bobabeam: ['bobabeam', 'bobabase']
@@ -0,0 +1,3 @@
1
+ import type { OverrideBundleDefinition } from '@polkadot/types/types';
2
+ declare const definitions: OverrideBundleDefinition;
3
+ export default definitions;
@@ -0,0 +1,145 @@
1
+ // Copyright 2017-2021 @polkadot/apps-config authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // import type {H256} from '@polkadot/types/interfaces';
4
+ // eslint-disable-next-line header/header
5
+
6
+ // structs need to be in order
7
+ /* eslint-disable sort-keys */
8
+
9
+ const definitions = {
10
+ rpc: {
11
+ kate: {
12
+ blockLength: {
13
+ description: 'Get Block Length',
14
+ params: [{
15
+ name: 'at',
16
+ type: 'Hash',
17
+ isOptional: true
18
+ }],
19
+ type: 'BlockLength'
20
+ },
21
+ queryProof: {
22
+ description: 'Generate the kate proof for the given `cells`',
23
+ params: [{
24
+ name: 'cells',
25
+ type: 'Vec<Cell>'
26
+ }, {
27
+ name: 'at',
28
+ type: 'Hash',
29
+ isOptional: true
30
+ }],
31
+ type: 'Vec<u8>'
32
+ },
33
+ queryAppData: {
34
+ description: 'Fetches app data rows for the given app',
35
+ params: [{
36
+ name: 'app_id',
37
+ type: 'AppId'
38
+ }, {
39
+ name: 'at',
40
+ type: 'Hash',
41
+ isOptional: true
42
+ }],
43
+ type: 'Vec<Option<Vec<u8>>>'
44
+ },
45
+ queryDataProof: {
46
+ description: 'Generate the data proof for the given `index`',
47
+ params: [{
48
+ name: 'data_index',
49
+ type: 'u32'
50
+ }, {
51
+ name: 'at',
52
+ type: 'Hash',
53
+ isOptional: true
54
+ }],
55
+ type: 'DataProof'
56
+ }
57
+ }
58
+ },
59
+ types: [{
60
+ // on all versions
61
+ minmax: [0, undefined],
62
+ types: {
63
+ AppId: 'Compact<u32>',
64
+ DataLookupIndexItem: {
65
+ appId: 'AppId',
66
+ start: 'Compact<u32>'
67
+ },
68
+ DataLookup: {
69
+ size: 'Compact<u32>',
70
+ index: 'Vec<DataLookupIndexItem>'
71
+ },
72
+ KateCommitment: {
73
+ rows: 'Compact<u16>',
74
+ cols: 'Compact<u16>',
75
+ dataRoot: 'H256',
76
+ commitment: 'Vec<u8>'
77
+ },
78
+ V1HeaderExtension: {
79
+ commitment: 'KateCommitment',
80
+ appLookup: 'DataLookup'
81
+ },
82
+ VTHeaderExtension: {
83
+ newField: 'Vec<u8>',
84
+ commitment: 'KateCommitment',
85
+ appLookup: 'DataLookup'
86
+ },
87
+ HeaderExtension: {
88
+ _enum: {
89
+ V1: 'V1HeaderExtension',
90
+ VTest: 'VTHeaderExtension'
91
+ }
92
+ },
93
+ DaHeader: {
94
+ parentHash: 'Hash',
95
+ number: 'Compact<BlockNumber>',
96
+ stateRoot: 'Hash',
97
+ extrinsicsRoot: 'Hash',
98
+ digest: 'Digest',
99
+ extension: 'HeaderExtension'
100
+ },
101
+ Header: 'DaHeader',
102
+ CheckAppIdExtra: {
103
+ appId: 'AppId'
104
+ },
105
+ CheckAppIdTypes: {},
106
+ CheckAppId: {
107
+ extra: 'CheckAppIdExtra',
108
+ types: 'CheckAppIdTypes'
109
+ },
110
+ BlockLengthColumns: 'Compact<u32>',
111
+ BlockLengthRows: 'Compact<u32>',
112
+ BlockLength: {
113
+ max: 'PerDispatchClass',
114
+ cols: 'BlockLengthColumns',
115
+ rows: 'BlockLengthRows',
116
+ chunkSize: 'Compact<u32>'
117
+ },
118
+ PerDispatchClass: {
119
+ normal: 'u32',
120
+ operational: 'u32',
121
+ mandatory: 'u32'
122
+ },
123
+ DataProof: {
124
+ root: 'H256',
125
+ proof: 'Vec<H256>',
126
+ numberOfLeaves: 'Compact<u32>',
127
+ leaf_index: 'Compact<u32>',
128
+ leaf: 'H256'
129
+ },
130
+ Cell: {
131
+ row: 'BlockLengthRows',
132
+ col: 'BlockLengthColumns'
133
+ }
134
+ }
135
+ }],
136
+ signedExtensions: {
137
+ CheckAppId: {
138
+ extrinsic: {
139
+ appId: 'AppId'
140
+ },
141
+ payload: {}
142
+ }
143
+ }
144
+ };
145
+ export default definitions;
@@ -30,6 +30,7 @@ import crownSterlingChain from "./crown-sterling.js";
30
30
  import crust from "./crust.js";
31
31
  import testPara from "./cumulus-test-parachain.js";
32
32
  import darwinia from "./darwinia.js";
33
+ import dataavail from "./dataavail.js";
33
34
  import datahighwayParachain from "./datahighway.js";
34
35
  import dockMainnet from "./dock-mainnet.js";
35
36
  import dockTestnet from "./dock-testnet.js";
@@ -162,6 +163,7 @@ const spec = {
162
163
  'crust-parachain': crust,
163
164
  'cumulus-subsocial-parachain': subsocial,
164
165
  'cumulus-test-parachain': testPara,
166
+ 'data-avail': dataavail,
165
167
  datahighway: westlake,
166
168
  'datahighway-parachain': datahighwayParachain,
167
169
  dawn: eave,
@@ -547,7 +547,7 @@ export class ChainService {
547
547
  mergedChainInfoMap[storedSlug].providers = {
548
548
  ...storedChainInfo.providers,
549
549
  ...mergedChainInfoMap[storedSlug].providers
550
- };
550
+ }; // TODO: review merging providers
551
551
  this.dataMap.chainStateMap[storedSlug] = {
552
552
  currentProvider: storedChainInfo.currentProvider,
553
553
  slug: storedSlug,
@@ -0,0 +1,4 @@
1
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
2
+ export default class MigrateLedgerAccount extends BaseMigrationJob {
3
+ run(): Promise<void>;
4
+ }
@@ -0,0 +1,33 @@
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
+ import { AccountsStore } from '@subwallet/extension-base/stores';
6
+ import { isString } from '@polkadot/util';
7
+ export default class MigrateLedgerAccount extends BaseMigrationJob {
8
+ async run() {
9
+ try {
10
+ return new Promise(resolve => {
11
+ const store = new AccountsStore();
12
+ const update = (key, value) => {
13
+ var _value$meta;
14
+ if (key.startsWith('account:') && value.meta && isString((_value$meta = value.meta) === null || _value$meta === void 0 ? void 0 : _value$meta.originGenesisHash)) {
15
+ const newValue = {
16
+ ...value
17
+ };
18
+ newValue.meta.availableGenesisHashes = [value.meta.originGenesisHash];
19
+ store.set(key, newValue);
20
+ }
21
+ };
22
+ store.allMap(map => {
23
+ Object.entries(map).forEach(([key, value]) => {
24
+ update(key, value);
25
+ });
26
+ resolve();
27
+ });
28
+ });
29
+ } catch (e) {
30
+ console.error(e);
31
+ }
32
+ }
33
+ }
@@ -6,6 +6,7 @@ import MigrateAuthUrls from '@subwallet/extension-base/services/migration-servic
6
6
  import MigrateAutoLock from '@subwallet/extension-base/services/migration-service/scripts/MigrateAutoLock';
7
7
  import MigrateChainPatrol from '@subwallet/extension-base/services/migration-service/scripts/MigrateChainPatrol';
8
8
  import MigrateImportedToken from '@subwallet/extension-base/services/migration-service/scripts/MigrateImportedToken';
9
+ import MigrateLedgerAccount from '@subwallet/extension-base/services/migration-service/scripts/MigrateLedgerAccount';
9
10
  import MigrateNetworkSettings from '@subwallet/extension-base/services/migration-service/scripts/MigrateNetworkSettings';
10
11
  import MigrateSettings from '@subwallet/extension-base/services/migration-service/scripts/MigrateSettings';
11
12
  import MigrateTransactionHistory from '@subwallet/extension-base/services/migration-service/scripts/MigrateTransactionHistory';
@@ -18,6 +19,7 @@ export default {
18
19
  '1.0.1-50': MigrateSettings,
19
20
  '1.0.1-60': MigrateAuthUrls,
20
21
  '1.0.3-01': MigrateAutoLock,
21
- '1.0.3-02': MigrateChainPatrol
22
+ '1.0.3-02': MigrateChainPatrol,
23
+ '1.0.9-01': MigrateLedgerAccount
22
24
  // [`${EVERYTIME}-1`]: AutoEnableChainsTokens
23
25
  };
@@ -14,13 +14,14 @@ import { parseTransferEventLogs, parseXcmEventLogs } from '@subwallet/extension-
14
14
  import { getBaseTransactionInfo, getTransactionId, isSubstrateTransaction } from '@subwallet/extension-base/services/transaction-service/helpers';
15
15
  import { getExplorerLink, parseTransactionData } from '@subwallet/extension-base/services/transaction-service/utils';
16
16
  import { anyNumberToBN } from '@subwallet/extension-base/utils/eth';
17
- import { parseTxAndSignature } from '@subwallet/extension-base/utils/eth/mergeTransactionAndSignature';
17
+ import { mergeTransactionAndSignature } from '@subwallet/extension-base/utils/eth/mergeTransactionAndSignature';
18
18
  import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
19
19
  import keyring from '@subwallet/ui-keyring';
20
+ import { addHexPrefix } from 'ethereumjs-util';
21
+ import { ethers } from 'ethers';
20
22
  import EventEmitter from 'eventemitter3';
21
- import RLP from 'rlp';
22
23
  import { BehaviorSubject } from 'rxjs';
23
- import { isHex, u8aToHex } from '@polkadot/util';
24
+ import { isHex } from '@polkadot/util';
24
25
  export default class TransactionService {
25
26
  transactionSubject = new BehaviorSubject({});
26
27
  get transactions() {
@@ -39,7 +40,7 @@ export default class TransactionService {
39
40
  return Object.values(this.transactions);
40
41
  }
41
42
  get processingTransactions() {
42
- return this.allTransactions.filter(t => t.status === ExtrinsicStatus.QUEUED || t.status === ExtrinsicStatus.PROCESSING);
43
+ return this.allTransactions.filter(t => t.status === ExtrinsicStatus.QUEUED || t.status === ExtrinsicStatus.SUBMITTING);
43
44
  }
44
45
  getTransaction(id) {
45
46
  return this.transactions[id];
@@ -317,7 +318,7 @@ export default class TransactionService {
317
318
  // Will be added in next step
318
319
  blockHash: '',
319
320
  // Will be added in next step
320
- nonce: nonce || 0,
321
+ nonce: nonce !== null && nonce !== void 0 ? nonce : 0,
321
322
  startBlock: startBlock || 0
322
323
  };
323
324
  const chainInfo = this.chainService.getChainInfoByKey(transaction.chain);
@@ -622,20 +623,18 @@ export default class TransactionService {
622
623
  this.eventService.emit('transaction.failed', transaction);
623
624
  }
624
625
  generateHashPayload(chain, transaction) {
626
+ var _transaction$nonce;
625
627
  const chainInfo = this.chainService.getChainInfoByKey(chain);
626
628
  const txObject = {
627
- nonce: transaction.nonce || 1,
628
- from: transaction.from,
629
- gasPrice: anyNumberToBN(transaction.gasPrice).toNumber(),
630
- gasLimit: anyNumberToBN(transaction.gas).toNumber(),
629
+ nonce: (_transaction$nonce = transaction.nonce) !== null && _transaction$nonce !== void 0 ? _transaction$nonce : 0,
630
+ gasPrice: addHexPrefix(anyNumberToBN(transaction.gasPrice).toString(16)),
631
+ gasLimit: addHexPrefix(anyNumberToBN(transaction.gas).toString(16)),
631
632
  to: transaction.to !== undefined ? transaction.to : '',
632
- value: anyNumberToBN(transaction.value).toNumber(),
633
- data: transaction.data ? transaction.data : '',
633
+ value: addHexPrefix(anyNumberToBN(transaction.value).toString(16)),
634
+ data: transaction.data,
634
635
  chainId: _getEvmChainId(chainInfo)
635
636
  };
636
- const data = [txObject.nonce, txObject.gasPrice, txObject.gasLimit, txObject.to, txObject.value, txObject.data, txObject.chainId, new Uint8Array([0x00]), new Uint8Array([0x00])];
637
- const encoded = RLP.encode(data);
638
- return u8aToHex(encoded);
637
+ return ethers.Transaction.from(txObject).unsignedSerialized;
639
638
  }
640
639
  async signAndSendEvmTransaction({
641
640
  address,
@@ -644,6 +643,7 @@ export default class TransactionService {
644
643
  transaction,
645
644
  url
646
645
  }) {
646
+ var _payload$nonce;
647
647
  const payload = transaction;
648
648
  const evmApi = this.chainService.getEvmApi(chain);
649
649
  const chainInfo = this.chainService.getChainInfoByKey(chain);
@@ -694,13 +694,13 @@ export default class TransactionService {
694
694
  payload.hashPayload = this.generateHashPayload(chain, payload);
695
695
  const emitter = new EventEmitter();
696
696
  const txObject = {
697
- nonce: payload.nonce || 1,
697
+ nonce: (_payload$nonce = payload.nonce) !== null && _payload$nonce !== void 0 ? _payload$nonce : 0,
698
698
  from: payload.from,
699
699
  gasPrice: anyNumberToBN(payload.gasPrice).toNumber(),
700
700
  gasLimit: anyNumberToBN(payload.gas).toNumber(),
701
701
  to: payload.to !== undefined ? payload.to : '',
702
702
  value: anyNumberToBN(payload.value).toNumber(),
703
- data: payload.data ? payload.data : '',
703
+ data: payload.data,
704
704
  chainId: payload.chainId
705
705
  };
706
706
  const eventData = {
@@ -722,7 +722,7 @@ export default class TransactionService {
722
722
  if (!isExternal) {
723
723
  signedTransaction = payload;
724
724
  } else {
725
- const signed = parseTxAndSignature(txObject, payload);
725
+ const signed = mergeTransactionAndSignature(txObject, payload);
726
726
  const recover = web3Api.eth.accounts.recoverTransaction(signed);
727
727
  if (recover.toLowerCase() !== account.address.toLowerCase()) {
728
728
  throw new EvmProviderError(EvmProviderErrorType.UNAUTHORIZED, 'Bad signature');
@@ -11,7 +11,7 @@ export interface Web3TransactionBase {
11
11
  gasLimit: number;
12
12
  nonce: number;
13
13
  chainId: number;
14
- data: string;
14
+ data?: string;
15
15
  value: number;
16
16
  }
17
17
  export interface Web3Transaction extends Web3TransactionBase {
@@ -2,8 +2,8 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { ExternalRequestPromiseStatus } from '@subwallet/extension-base/background/KoniTypes';
5
- import RLP from 'rlp';
6
- import { u8aToHex } from '@polkadot/util';
5
+ import { addHexPrefix } from 'ethereumjs-util';
6
+ import { ethers } from 'ethers';
7
7
  export default class QrSigner {
8
8
  #callback;
9
9
  #id;
@@ -22,8 +22,17 @@ export default class QrSigner {
22
22
  }
23
23
  async signTransaction(tx) {
24
24
  return new Promise((resolve, reject) => {
25
- const data = [tx.nonce, tx.gasPrice, tx.gasLimit, tx.to, tx.value, tx.data, tx.chainId, new Uint8Array([0x00]), new Uint8Array([0x00])];
26
- const qrPayload = RLP.encode(data);
25
+ var _tx$nonce;
26
+ const txObject = {
27
+ nonce: (_tx$nonce = tx.nonce) !== null && _tx$nonce !== void 0 ? _tx$nonce : 0,
28
+ gasPrice: addHexPrefix(tx.gasPrice.toString(16)),
29
+ gasLimit: addHexPrefix(tx.gasLimit.toString(16)),
30
+ to: tx.to !== undefined ? tx.to : '',
31
+ value: addHexPrefix(tx.value.toString(16)),
32
+ data: tx.data,
33
+ chainId: tx.chainId
34
+ };
35
+ const qrPayload = ethers.Transaction.from(txObject).unsignedSerialized;
27
36
  const resolver = result => {
28
37
  this.#resolver();
29
38
  resolve(result);
@@ -38,7 +47,7 @@ export default class QrSigner {
38
47
  qrState: {
39
48
  isQrHashed: false,
40
49
  qrAddress: tx.from,
41
- qrPayload: u8aToHex(qrPayload),
50
+ qrPayload: qrPayload,
42
51
  qrId: this.#id,
43
52
  isEthereum: true
44
53
  }
@@ -1,2 +1,2 @@
1
1
  import { Web3Transaction } from '@subwallet/extension-base/signers/types';
2
- export declare const parseTxAndSignature: (tx: Web3Transaction, _signature: `0x${string}`) => `0x${string}`;
2
+ export declare const mergeTransactionAndSignature: (tx: Web3Transaction, _rawSignature: `0x${string}`) => `0x${string}`;
@@ -1,14 +1,24 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import RLP from 'rlp';
5
- import { u8aToHex } from '@polkadot/util';
6
- export const parseTxAndSignature = (tx, _signature) => {
7
- const signature = _signature.slice(2);
8
- const r = `0x${signature.substring(0, 64)}`;
9
- const s = `0x${signature.substring(64, 128)}`;
10
- const v = `0x${signature.substring(128)}`;
11
- const data = [tx.nonce, tx.gasPrice, tx.gasLimit, tx.to, tx.value, tx.data, v, r, s];
12
- const encoded = RLP.encode(data);
13
- return u8aToHex(encoded);
4
+ import { addHexPrefix } from 'ethereumjs-util';
5
+ import { ethers } from 'ethers';
6
+ export const mergeTransactionAndSignature = (tx, _rawSignature) => {
7
+ const _signature = _rawSignature.slice(2);
8
+ const signature = {
9
+ r: `0x${_signature.substring(0, 64)}`,
10
+ s: `0x${_signature.substring(64, 128)}`,
11
+ v: parseInt(`0x${_signature.substring(128)}`)
12
+ };
13
+ const transaction = {
14
+ nonce: tx.nonce,
15
+ gasPrice: addHexPrefix(tx.gasPrice.toString(16)),
16
+ gasLimit: addHexPrefix(tx.gasLimit.toString(16)),
17
+ to: tx.to,
18
+ value: addHexPrefix(tx.value.toString(16)),
19
+ data: tx.data,
20
+ chainId: tx.chainId,
21
+ signature: signature
22
+ };
23
+ return ethers.Transaction.from(transaction).serialized;
14
24
  };
@@ -121,7 +121,7 @@ export class InputDataDecoder {
121
121
  if (data.indexOf('0x') !== 0) {
122
122
  data = `0x${data}`;
123
123
  }
124
- const _inputs = ethers.utils.defaultAbiCoder.decode(types, data);
124
+ const _inputs = ethers.AbiCoder.defaultAbiCoder().decode(types, data);
125
125
  const inputs = deepRemoveUnwantedArrayProperties(_inputs);
126
126
  return {
127
127
  methodName,
@@ -180,11 +180,11 @@ export class InputDataDecoder {
180
180
  let inputs = [];
181
181
  try {
182
182
  // @ts-ignore
183
- inputs = ethers.utils.defaultAbiCoder.decode(types, inputsBuf);
183
+ inputs = ethers.AbiCoder.defaultAbiCoder().decode(types, inputsBuf);
184
184
  } catch (err) {
185
185
  try {
186
- const ifc = new ethers.utils.Interface([]);
187
- inputs = ifc.decodeFunctionData(ethers.utils.FunctionFragment.fromObject(abi), data);
186
+ const ifc = new ethers.Interface([]);
187
+ inputs = ifc.decodeFunctionData(ethers.FunctionFragment.from(abi), data);
188
188
  } catch (err) {}
189
189
  }
190
190
 
@@ -235,8 +235,8 @@ export class InputDataDecoder {
235
235
  }
236
236
  const method = obj.name || null;
237
237
  try {
238
- const ifc = new ethers.utils.Interface([]);
239
- const _result = ifc.decodeFunctionData(ethers.utils.FunctionFragment.fromObject(obj), data);
238
+ const ifc = new ethers.Interface([]);
239
+ const _result = ifc.decodeFunctionData(ethers.FunctionFragment.from(obj), data);
240
240
  const inputs = deepRemoveUnwantedArrayProperties(_result);
241
241
  result.method = method;
242
242
  result.methodName = getMethodName(obj);
@@ -127,7 +127,6 @@ export const parseContractInput = async (input, contractAddress, network) => {
127
127
  }
128
128
  }
129
129
  if (contractAddress && network) {
130
- console.log('parseOnline');
131
130
  if (_getEvmAbiExplorer(network)) {
132
131
  try {
133
132
  const res = await axios.get(_getEvmAbiExplorer(network), {
@@ -189,7 +188,7 @@ export const parseEvmRlp = async (data, networkMap, evmApiMap) => {
189
188
  data: tx.data,
190
189
  gasPrice: new BigN(tx.gasPrice).toNumber(),
191
190
  gas: new BigN(tx.gas).toNumber(),
192
- to: tx.action,
191
+ to: tx.to,
193
192
  value: new BigN(tx.value).toNumber(),
194
193
  nonce: new BigN(tx.nonce).toNumber()
195
194
  };
@@ -201,13 +200,13 @@ export const parseEvmRlp = async (data, networkMap, evmApiMap) => {
201
200
  return result;
202
201
  }
203
202
  }
204
- if (tx.action && network) {
205
- if (await isContractAddress(tx.action, evmApiMap[network.slug])) {
203
+ if (tx.to && network) {
204
+ if (await isContractAddress(tx.to, evmApiMap[network.slug])) {
206
205
  if (_getEvmAbiExplorer(network) !== '') {
207
206
  try {
208
207
  const res = await axios.get(_getEvmAbiExplorer(network), {
209
208
  params: {
210
- address: tx.action
209
+ address: tx.to
211
210
  },
212
211
  timeout: 2000
213
212
  });
package/utils/eth.d.ts CHANGED
@@ -5,14 +5,13 @@ export declare class Transaction {
5
5
  readonly nonce: string;
6
6
  readonly gasPrice: string;
7
7
  readonly gas: string;
8
- readonly action: string;
8
+ readonly to: string;
9
9
  readonly value: string;
10
10
  readonly data: string;
11
11
  readonly ethereumChainId: string;
12
12
  readonly isSafe: boolean;
13
- constructor(nonce: string, gasPrice: string, gas: string, action: string, value: string, data: string, ethereumChainId: string);
13
+ constructor(nonce: string, gasPrice: string, gas: string, to: string, value: string, data: string, ethereumChainId: string);
14
14
  }
15
15
  export declare const anyNumberToBN: (value?: string | number | BNEther) => BigN;
16
- export declare const rlpItem: (rlp: string, position: number) => `0x${string}`;
17
16
  export declare const createTransactionFromRLP: (rlp: string) => Transaction | null;
18
17
  export declare const signatureToHex: (sig: SignedTransaction) => string;