@sidhujag/sysweb3-keyring 1.0.547 → 1.0.548

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 (210) hide show
  1. package/package.json +2 -27
  2. package/coverage/clover.xml +0 -2875
  3. package/coverage/coverage-final.json +0 -29468
  4. package/coverage/lcov-report/base.css +0 -354
  5. package/coverage/lcov-report/block-navigation.js +0 -85
  6. package/coverage/lcov-report/favicon.png +0 -0
  7. package/coverage/lcov-report/index.html +0 -320
  8. package/coverage/lcov-report/prettify.css +0 -101
  9. package/coverage/lcov-report/prettify.js +0 -1008
  10. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  11. package/coverage/lcov-report/sorter.js +0 -191
  12. package/coverage/lcov-report/src/index.html +0 -276
  13. package/coverage/lcov-report/src/index.ts.html +0 -114
  14. package/coverage/lcov-report/src/initial-state.ts.html +0 -558
  15. package/coverage/lcov-report/src/keyring-manager.ts.html +0 -6279
  16. package/coverage/lcov-report/src/ledger/bitcoin_client/index.html +0 -178
  17. package/coverage/lcov-report/src/ledger/bitcoin_client/index.ts.html +0 -144
  18. package/coverage/lcov-report/src/ledger/bitcoin_client/lib/appClient.ts.html +0 -1560
  19. package/coverage/lcov-report/src/ledger/bitcoin_client/lib/bip32.ts.html +0 -276
  20. package/coverage/lcov-report/src/ledger/bitcoin_client/lib/buffertools.ts.html +0 -495
  21. package/coverage/lcov-report/src/ledger/bitcoin_client/lib/clientCommands.ts.html +0 -1138
  22. package/coverage/lcov-report/src/ledger/bitcoin_client/lib/index.html +0 -363
  23. package/coverage/lcov-report/src/ledger/bitcoin_client/lib/merkelizedPsbt.ts.html +0 -289
  24. package/coverage/lcov-report/src/ledger/bitcoin_client/lib/merkle.ts.html +0 -486
  25. package/coverage/lcov-report/src/ledger/bitcoin_client/lib/merkleMap.ts.html +0 -240
  26. package/coverage/lcov-report/src/ledger/bitcoin_client/lib/policy.ts.html +0 -342
  27. package/coverage/lcov-report/src/ledger/bitcoin_client/lib/psbtv2.ts.html +0 -2388
  28. package/coverage/lcov-report/src/ledger/bitcoin_client/lib/varint.ts.html +0 -453
  29. package/coverage/lcov-report/src/ledger/consts.ts.html +0 -177
  30. package/coverage/lcov-report/src/ledger/index.html +0 -216
  31. package/coverage/lcov-report/src/ledger/index.ts.html +0 -1371
  32. package/coverage/lcov-report/src/ledger/utils.ts.html +0 -102
  33. package/coverage/lcov-report/src/signers.ts.html +0 -591
  34. package/coverage/lcov-report/src/storage.ts.html +0 -198
  35. package/coverage/lcov-report/src/transactions/ethereum.ts.html +0 -5826
  36. package/coverage/lcov-report/src/transactions/index.html +0 -216
  37. package/coverage/lcov-report/src/transactions/index.ts.html +0 -93
  38. package/coverage/lcov-report/src/transactions/syscoin.ts.html +0 -1521
  39. package/coverage/lcov-report/src/trezor/index.html +0 -176
  40. package/coverage/lcov-report/src/trezor/index.ts.html +0 -2655
  41. package/coverage/lcov-report/src/types.ts.html +0 -1443
  42. package/coverage/lcov-report/src/utils/derivation-paths.ts.html +0 -486
  43. package/coverage/lcov-report/src/utils/index.html +0 -196
  44. package/coverage/lcov-report/src/utils/psbt.ts.html +0 -159
  45. package/coverage/lcov-report/test/helpers/constants.ts.html +0 -627
  46. package/coverage/lcov-report/test/helpers/index.html +0 -176
  47. package/coverage/lcov.info +0 -4832
  48. package/dist/package.json +0 -50
  49. package/examples/basic-usage.js +0 -140
  50. package/jest.config.js +0 -32
  51. package/readme.md +0 -201
  52. package/src/declare.d.ts +0 -7
  53. package/src/errorUtils.ts +0 -83
  54. package/src/hardware-wallet-manager.ts +0 -655
  55. package/src/index.ts +0 -12
  56. package/src/initial-state.ts +0 -108
  57. package/src/keyring-manager.ts +0 -2698
  58. package/src/ledger/bitcoin_client/index.ts +0 -19
  59. package/src/ledger/bitcoin_client/lib/appClient.ts +0 -405
  60. package/src/ledger/bitcoin_client/lib/bip32.ts +0 -61
  61. package/src/ledger/bitcoin_client/lib/buffertools.ts +0 -134
  62. package/src/ledger/bitcoin_client/lib/clientCommands.ts +0 -356
  63. package/src/ledger/bitcoin_client/lib/constants.ts +0 -12
  64. package/src/ledger/bitcoin_client/lib/merkelizedPsbt.ts +0 -65
  65. package/src/ledger/bitcoin_client/lib/merkle.ts +0 -136
  66. package/src/ledger/bitcoin_client/lib/merkleMap.ts +0 -49
  67. package/src/ledger/bitcoin_client/lib/policy.ts +0 -91
  68. package/src/ledger/bitcoin_client/lib/psbtv2.ts +0 -768
  69. package/src/ledger/bitcoin_client/lib/varint.ts +0 -120
  70. package/src/ledger/consts.ts +0 -3
  71. package/src/ledger/index.ts +0 -685
  72. package/src/ledger/types.ts +0 -74
  73. package/src/network-utils.ts +0 -99
  74. package/src/providers.ts +0 -345
  75. package/src/signers.ts +0 -158
  76. package/src/storage.ts +0 -63
  77. package/src/transactions/__tests__/integration.test.ts +0 -303
  78. package/src/transactions/__tests__/syscoin.test.ts +0 -409
  79. package/src/transactions/ethereum.ts +0 -2503
  80. package/src/transactions/index.ts +0 -2
  81. package/src/transactions/syscoin.ts +0 -542
  82. package/src/trezor/index.ts +0 -1050
  83. package/src/types.ts +0 -366
  84. package/src/utils/derivation-paths.ts +0 -133
  85. package/src/utils/psbt.ts +0 -24
  86. package/src/utils.ts +0 -191
  87. package/test/README.md +0 -158
  88. package/test/__mocks__/ledger-mock.js +0 -20
  89. package/test/__mocks__/trezor-mock.js +0 -75
  90. package/test/cleanup-summary.md +0 -167
  91. package/test/helpers/README.md +0 -78
  92. package/test/helpers/constants.ts +0 -79
  93. package/test/helpers/setup.ts +0 -714
  94. package/test/integration/import-validation.spec.ts +0 -588
  95. package/test/unit/hardware/ledger.spec.ts +0 -869
  96. package/test/unit/hardware/trezor.spec.ts +0 -828
  97. package/test/unit/keyring-manager/account-management.spec.ts +0 -970
  98. package/test/unit/keyring-manager/import-watchonly.spec.ts +0 -181
  99. package/test/unit/keyring-manager/import-wif.spec.ts +0 -126
  100. package/test/unit/keyring-manager/initialization.spec.ts +0 -782
  101. package/test/unit/keyring-manager/key-derivation.spec.ts +0 -996
  102. package/test/unit/keyring-manager/security.spec.ts +0 -505
  103. package/test/unit/keyring-manager/state-management.spec.ts +0 -375
  104. package/test/unit/network/network-management.spec.ts +0 -372
  105. package/test/unit/transactions/ethereum-transactions.spec.ts +0 -382
  106. package/test/unit/transactions/syscoin-transactions.spec.ts +0 -615
  107. package/tsconfig.json +0 -14
  108. /package/{dist/README.md → README.md} +0 -0
  109. /package/{dist/cjs → cjs}/errorUtils.js +0 -0
  110. /package/{dist/cjs → cjs}/errorUtils.js.map +0 -0
  111. /package/{dist/cjs → cjs}/hardware-wallet-manager.js +0 -0
  112. /package/{dist/cjs → cjs}/hardware-wallet-manager.js.map +0 -0
  113. /package/{dist/cjs → cjs}/index.js +0 -0
  114. /package/{dist/cjs → cjs}/index.js.map +0 -0
  115. /package/{dist/cjs → cjs}/initial-state.js +0 -0
  116. /package/{dist/cjs → cjs}/initial-state.js.map +0 -0
  117. /package/{dist/cjs → cjs}/keyring-manager.js +0 -0
  118. /package/{dist/cjs → cjs}/keyring-manager.js.map +0 -0
  119. /package/{dist/cjs → cjs}/ledger/bitcoin_client/index.js +0 -0
  120. /package/{dist/cjs → cjs}/ledger/bitcoin_client/index.js.map +0 -0
  121. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/appClient.js +0 -0
  122. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/appClient.js.map +0 -0
  123. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/bip32.js +0 -0
  124. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/bip32.js.map +0 -0
  125. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/buffertools.js +0 -0
  126. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/buffertools.js.map +0 -0
  127. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/clientCommands.js +0 -0
  128. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/clientCommands.js.map +0 -0
  129. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/constants.js +0 -0
  130. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/constants.js.map +0 -0
  131. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/merkelizedPsbt.js +0 -0
  132. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/merkelizedPsbt.js.map +0 -0
  133. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/merkle.js +0 -0
  134. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/merkle.js.map +0 -0
  135. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/merkleMap.js +0 -0
  136. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/merkleMap.js.map +0 -0
  137. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/policy.js +0 -0
  138. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/policy.js.map +0 -0
  139. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/psbtv2.js +0 -0
  140. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/psbtv2.js.map +0 -0
  141. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/varint.js +0 -0
  142. /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/varint.js.map +0 -0
  143. /package/{dist/cjs → cjs}/ledger/consts.js +0 -0
  144. /package/{dist/cjs → cjs}/ledger/consts.js.map +0 -0
  145. /package/{dist/cjs → cjs}/ledger/index.js +0 -0
  146. /package/{dist/cjs → cjs}/ledger/index.js.map +0 -0
  147. /package/{dist/cjs → cjs}/ledger/types.js +0 -0
  148. /package/{dist/cjs → cjs}/ledger/types.js.map +0 -0
  149. /package/{dist/cjs → cjs}/network-utils.js +0 -0
  150. /package/{dist/cjs → cjs}/network-utils.js.map +0 -0
  151. /package/{dist/cjs → cjs}/providers.js +0 -0
  152. /package/{dist/cjs → cjs}/providers.js.map +0 -0
  153. /package/{dist/cjs → cjs}/signers.js +0 -0
  154. /package/{dist/cjs → cjs}/signers.js.map +0 -0
  155. /package/{dist/cjs → cjs}/storage.js +0 -0
  156. /package/{dist/cjs → cjs}/storage.js.map +0 -0
  157. /package/{dist/cjs → cjs}/transactions/__tests__/integration.test.js +0 -0
  158. /package/{dist/cjs → cjs}/transactions/__tests__/integration.test.js.map +0 -0
  159. /package/{dist/cjs → cjs}/transactions/__tests__/syscoin.test.js +0 -0
  160. /package/{dist/cjs → cjs}/transactions/__tests__/syscoin.test.js.map +0 -0
  161. /package/{dist/cjs → cjs}/transactions/ethereum.js +0 -0
  162. /package/{dist/cjs → cjs}/transactions/ethereum.js.map +0 -0
  163. /package/{dist/cjs → cjs}/transactions/index.js +0 -0
  164. /package/{dist/cjs → cjs}/transactions/index.js.map +0 -0
  165. /package/{dist/cjs → cjs}/transactions/syscoin.js +0 -0
  166. /package/{dist/cjs → cjs}/transactions/syscoin.js.map +0 -0
  167. /package/{dist/cjs → cjs}/trezor/index.js +0 -0
  168. /package/{dist/cjs → cjs}/trezor/index.js.map +0 -0
  169. /package/{dist/cjs → cjs}/types.js +0 -0
  170. /package/{dist/cjs → cjs}/types.js.map +0 -0
  171. /package/{dist/cjs → cjs}/utils/derivation-paths.js +0 -0
  172. /package/{dist/cjs → cjs}/utils/derivation-paths.js.map +0 -0
  173. /package/{dist/cjs → cjs}/utils/psbt.js +0 -0
  174. /package/{dist/cjs → cjs}/utils/psbt.js.map +0 -0
  175. /package/{dist/cjs → cjs}/utils.js +0 -0
  176. /package/{dist/cjs → cjs}/utils.js.map +0 -0
  177. /package/{dist/types → types}/errorUtils.d.ts +0 -0
  178. /package/{dist/types → types}/hardware-wallet-manager.d.ts +0 -0
  179. /package/{dist/types → types}/index.d.ts +0 -0
  180. /package/{dist/types → types}/initial-state.d.ts +0 -0
  181. /package/{dist/types → types}/keyring-manager.d.ts +0 -0
  182. /package/{dist/types → types}/ledger/bitcoin_client/index.d.ts +0 -0
  183. /package/{dist/types → types}/ledger/bitcoin_client/lib/appClient.d.ts +0 -0
  184. /package/{dist/types → types}/ledger/bitcoin_client/lib/bip32.d.ts +0 -0
  185. /package/{dist/types → types}/ledger/bitcoin_client/lib/buffertools.d.ts +0 -0
  186. /package/{dist/types → types}/ledger/bitcoin_client/lib/clientCommands.d.ts +0 -0
  187. /package/{dist/types → types}/ledger/bitcoin_client/lib/constants.d.ts +0 -0
  188. /package/{dist/types → types}/ledger/bitcoin_client/lib/merkelizedPsbt.d.ts +0 -0
  189. /package/{dist/types → types}/ledger/bitcoin_client/lib/merkle.d.ts +0 -0
  190. /package/{dist/types → types}/ledger/bitcoin_client/lib/merkleMap.d.ts +0 -0
  191. /package/{dist/types → types}/ledger/bitcoin_client/lib/policy.d.ts +0 -0
  192. /package/{dist/types → types}/ledger/bitcoin_client/lib/psbtv2.d.ts +0 -0
  193. /package/{dist/types → types}/ledger/bitcoin_client/lib/varint.d.ts +0 -0
  194. /package/{dist/types → types}/ledger/consts.d.ts +0 -0
  195. /package/{dist/types → types}/ledger/index.d.ts +0 -0
  196. /package/{dist/types → types}/ledger/types.d.ts +0 -0
  197. /package/{dist/types → types}/network-utils.d.ts +0 -0
  198. /package/{dist/types → types}/providers.d.ts +0 -0
  199. /package/{dist/types → types}/signers.d.ts +0 -0
  200. /package/{dist/types → types}/storage.d.ts +0 -0
  201. /package/{dist/types → types}/transactions/__tests__/integration.test.d.ts +0 -0
  202. /package/{dist/types → types}/transactions/__tests__/syscoin.test.d.ts +0 -0
  203. /package/{dist/types → types}/transactions/ethereum.d.ts +0 -0
  204. /package/{dist/types → types}/transactions/index.d.ts +0 -0
  205. /package/{dist/types → types}/transactions/syscoin.d.ts +0 -0
  206. /package/{dist/types → types}/trezor/index.d.ts +0 -0
  207. /package/{dist/types → types}/types.d.ts +0 -0
  208. /package/{dist/types → types}/utils/derivation-paths.d.ts +0 -0
  209. /package/{dist/types → types}/utils/psbt.d.ts +0 -0
  210. /package/{dist/types → types}/utils.d.ts +0 -0
@@ -1,382 +0,0 @@
1
- import { encrypt, SignTypedDataVersion } from '@metamask/eth-sig-util';
2
- import { INetworkType } from '@sidhujag/sysweb3-network';
3
-
4
- import { KeyringManager, KeyringAccountType } from '../../../src';
5
- import { FAKE_PASSWORD, PEACE_SEED_PHRASE } from '../../helpers/constants';
6
- import { setupMocks } from '../../helpers/setup';
7
-
8
- describe('Ethereum Transactions', () => {
9
- let keyringManager: KeyringManager;
10
- let mockVaultStateGetter: jest.Mock;
11
- let currentVaultState: any;
12
-
13
- beforeEach(async () => {
14
- setupMocks();
15
- // Set up vault-keys that would normally be created by Pali's MainController
16
- await setupTestVault(FAKE_PASSWORD);
17
-
18
- // Set up EVM vault state
19
- currentVaultState = createMockVaultState({
20
- activeAccountId: 0,
21
- activeAccountType: KeyringAccountType.HDAccount,
22
- networkType: INetworkType.Ethereum,
23
- chainId: 1,
24
- });
25
- mockVaultStateGetter = jest.fn(() => currentVaultState);
26
-
27
- keyringManager = await KeyringManager.createInitialized(
28
- PEACE_SEED_PHRASE,
29
- FAKE_PASSWORD,
30
- mockVaultStateGetter
31
- );
32
- });
33
-
34
- describe('Transaction Signing', () => {
35
- it('should sign a transaction', async () => {
36
- const tx = {
37
- from: keyringManager.getActiveAccount().activeAccount.address,
38
- to: '0x2c7536E3605D9C16a7a3D7b1898e529396a65c23', // Valid checksummed address
39
- value: '0x0',
40
- gasLimit: '0x5208',
41
- maxFeePerGas: '0x4a817c800', // 20 gwei
42
- maxPriorityFeePerGas: '0x77359400', // 2 gwei
43
- nonce: '0x0',
44
- chainId: 1,
45
- };
46
-
47
- const result =
48
- await keyringManager.ethereumTransaction.sendFormattedTransaction(tx);
49
- expect(result).toBeDefined();
50
- expect(result.hash).toBeDefined();
51
- });
52
-
53
- it('should get recommended nonce', async () => {
54
- const nonce =
55
- await keyringManager.ethereumTransaction.getRecommendedNonce(
56
- keyringManager.getActiveAccount().activeAccount.address
57
- );
58
- expect(nonce).toBe(0); // Updated to match mock return value
59
- });
60
-
61
- it('should get fee data with dynamic max priority fee', async () => {
62
- const feeData =
63
- await keyringManager.ethereumTransaction.getFeeDataWithDynamicMaxPriorityFeePerGas();
64
- expect(feeData).toBeDefined();
65
- expect(feeData.maxFeePerGas).toBeDefined();
66
- expect(feeData.maxPriorityFeePerGas).toBeDefined();
67
- });
68
-
69
- it('should estimate gas limit', async () => {
70
- const tx = {
71
- from: keyringManager.getActiveAccount().activeAccount.address,
72
- to: '0x742d35Cc6634C0532925a3b844Bc9e7595f8b2bc',
73
- value: '0x0',
74
- chainId: 1,
75
- maxFeePerGas: '0x4a817c800',
76
- maxPriorityFeePerGas: '0x77359400',
77
- };
78
-
79
- const gasLimit = await keyringManager.ethereumTransaction.getTxGasLimit(
80
- tx
81
- );
82
- expect(gasLimit).toBeDefined();
83
- expect(gasLimit._isBigNumber).toBe(true);
84
- });
85
- });
86
-
87
- describe('Message Signing', () => {
88
- it('should sign a message with eth_sign', async () => {
89
- const message =
90
- '0x' + Buffer.from('Hello World').toString('hex').padStart(64, '0'); // 32-byte hash
91
- const signature = await keyringManager.ethereumTransaction.ethSign([
92
- keyringManager.getActiveAccount().activeAccount.address,
93
- message,
94
- ]);
95
-
96
- expect(signature).toBeDefined();
97
- expect(signature.startsWith('0x')).toBe(true);
98
- expect(signature.length).toBe(132); // 0x + 130 hex chars
99
- });
100
-
101
- it('should sign a personal message', async () => {
102
- const message =
103
- '0x4578616d706c652060706572736f6e616c5f7369676e60206d657373616765';
104
- const signature =
105
- await keyringManager.ethereumTransaction.signPersonalMessage([
106
- message,
107
- keyringManager.getActiveAccount().activeAccount.address,
108
- ]);
109
-
110
- expect(signature).toBeDefined();
111
- expect(signature.startsWith('0x')).toBe(true);
112
- });
113
-
114
- it('should verify personal message signature', () => {
115
- const message = 'Example `personal_sign` message';
116
- const signature =
117
- '0x1e4c47c96d285648db99bf2bdf691aae354d2beb80ceeeaaffa643d37900bf510ea0f5cd06518fcfc67e607898308de1497b6036ccd343ab17e3f59eb87567e41c';
118
- const address = '0x6a92eF94F6Db88098625a30396e0fde7255E97d5';
119
-
120
- const recovered =
121
- keyringManager.ethereumTransaction.verifyPersonalMessage(
122
- message,
123
- signature
124
- );
125
-
126
- expect(recovered.toLowerCase()).toBe(address.toLowerCase());
127
- });
128
-
129
- it('should parse personal message from hex', () => {
130
- const hexMessage =
131
- '0x4578616d706c652060706572736f6e616c5f7369676e60206d657373616765';
132
- const parsed =
133
- keyringManager.ethereumTransaction.parsePersonalMessage(hexMessage);
134
-
135
- expect(parsed).toBe('Example `personal_sign` message');
136
- });
137
- });
138
-
139
- describe('Typed Data Signing', () => {
140
- const typedDataV1 = [
141
- {
142
- type: 'string',
143
- name: 'Message',
144
- value: 'Hi, Alice!',
145
- },
146
- {
147
- type: 'uint32',
148
- name: 'A number',
149
- value: '1337',
150
- },
151
- ];
152
-
153
- const typedDataV3V4 = {
154
- types: {
155
- EIP712Domain: [
156
- { name: 'name', type: 'string' },
157
- { name: 'version', type: 'string' },
158
- { name: 'chainId', type: 'uint256' },
159
- { name: 'verifyingContract', type: 'address' },
160
- ],
161
- Person: [
162
- { name: 'name', type: 'string' },
163
- { name: 'wallet', type: 'address' },
164
- ],
165
- Mail: [
166
- { name: 'from', type: 'Person' },
167
- { name: 'to', type: 'Person' },
168
- { name: 'contents', type: 'string' },
169
- ],
170
- },
171
- primaryType: 'Mail',
172
- domain: {
173
- name: 'Ether Mail',
174
- version: '1',
175
- chainId: 1,
176
- verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
177
- },
178
- message: {
179
- from: {
180
- name: 'Cow',
181
- wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
182
- },
183
- to: {
184
- name: 'Bob',
185
- wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
186
- },
187
- contents: 'Hello, Bob!',
188
- },
189
- };
190
-
191
- it('should sign typed data V1', async () => {
192
- const signature = await keyringManager.ethereumTransaction.signTypedData(
193
- keyringManager.getActiveAccount().activeAccount.address,
194
- typedDataV1,
195
- SignTypedDataVersion.V1
196
- );
197
-
198
- expect(signature).toBeDefined();
199
- expect(signature.startsWith('0x')).toBe(true);
200
- });
201
-
202
- it('should sign typed data V3', async () => {
203
- const signature = await keyringManager.ethereumTransaction.signTypedData(
204
- keyringManager.getActiveAccount().activeAccount.address,
205
- typedDataV3V4,
206
- SignTypedDataVersion.V3
207
- );
208
-
209
- expect(signature).toBeDefined();
210
- expect(signature.startsWith('0x')).toBe(true);
211
- });
212
-
213
- it('should sign typed data V4', async () => {
214
- const signature = await keyringManager.ethereumTransaction.signTypedData(
215
- keyringManager.getActiveAccount().activeAccount.address,
216
- typedDataV3V4,
217
- SignTypedDataVersion.V4
218
- );
219
-
220
- expect(signature).toBeDefined();
221
- expect(signature.startsWith('0x')).toBe(true);
222
- });
223
-
224
- it('should verify typed signature', () => {
225
- const signature =
226
- '0x6fd4f93623d151b487656cd3a0aaaec16aee409c353bad7c1f8eecbbab07b06f51ac8be73d7a2d4bba579505aff7c5a62f91141fee75ff2cbb0c111dcfe589c01b';
227
- const recovered = keyringManager.ethereumTransaction.verifyTypedSignature(
228
- typedDataV1,
229
- signature,
230
- SignTypedDataVersion.V1
231
- );
232
-
233
- expect(recovered.toLowerCase()).toBe(
234
- '0x6a92eF94F6Db88098625a30396e0fde7255E97d5'.toLowerCase()
235
- );
236
- });
237
- });
238
-
239
- describe('Encryption/Decryption', () => {
240
- it('should get encrypted public key', () => {
241
- const pubKey = keyringManager.ethereumTransaction.getEncryptedPubKey();
242
-
243
- expect(pubKey).toBeDefined();
244
- expect(pubKey).toBe('KxnDhpzCBCj23z8ZcMr/+2yibUVUa/87wS+7uw59dyY='); // Updated to match actual generated key
245
- });
246
-
247
- it('should decrypt message', () => {
248
- // Create a proper roundtrip test: encrypt then decrypt
249
- const originalMessage = 'Hello, World!';
250
-
251
- // Get the public key for encryption
252
- const encryptionPublicKey =
253
- keyringManager.ethereumTransaction.getEncryptedPubKey();
254
- expect(encryptionPublicKey).toBeDefined();
255
-
256
- // Use eth-sig-util to encrypt the message
257
- const encryptedData = encrypt({
258
- publicKey: encryptionPublicKey,
259
- data: originalMessage,
260
- version: 'x25519-xsalsa20-poly1305',
261
- });
262
-
263
- // Convert encrypted data to the hex format that decryptMessage expects
264
- const encryptedHex = Buffer.from(JSON.stringify(encryptedData)).toString(
265
- 'hex'
266
- );
267
-
268
- // Now decrypt using decryptMessage
269
- const decrypted = keyringManager.ethereumTransaction.decryptMessage([
270
- encryptedHex,
271
- keyringManager.getActiveAccount().activeAccount.address,
272
- ]);
273
-
274
- expect(decrypted).toBe(originalMessage);
275
- });
276
- });
277
-
278
- describe('Account Management', () => {
279
- it('should import account from private key', () => {
280
- const privateKey =
281
- '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318';
282
- const account =
283
- keyringManager.ethereumTransaction.importAccount(privateKey);
284
-
285
- expect(account.address).toBe(
286
- '0x2c7536E3605D9C16a7a3D7b1898e529396a65c23'
287
- );
288
- expect(account.privateKey).toBe(privateKey);
289
- });
290
-
291
- it('should get account balance', async () => {
292
- const balance = await keyringManager.ethereumTransaction.getBalance(
293
- keyringManager.getActiveAccount().activeAccount.address
294
- );
295
-
296
- expect(balance).toBe(1); // Updated to match mock return value
297
- });
298
- });
299
-
300
- describe('Utility Functions', () => {
301
- it('should convert to BigNumber', () => {
302
- const value = 1000;
303
- const bigNumber = keyringManager.ethereumTransaction.toBigNumber(value);
304
-
305
- expect(bigNumber._isBigNumber).toBe(true);
306
- expect(bigNumber._hex).toBe('0x03e8'); // Updated to match actual format
307
- });
308
- });
309
-
310
- describe('Multiple Account Signing', () => {
311
- it('should sign with different accounts', async () => {
312
- // Add a second account
313
- const account2 = await keyringManager.addNewAccount();
314
-
315
- // Update vault state with the new account (in stateless keyring, this would be done by Pali/Redux)
316
- currentVaultState.accounts[KeyringAccountType.HDAccount][account2.id] = {
317
- id: account2.id,
318
- address: account2.address,
319
- xpub: account2.xpub,
320
- xprv: account2.xprv,
321
- label: account2.label,
322
- balances: account2.balances,
323
- isImported: account2.isImported,
324
- isTrezorWallet: account2.isTrezorWallet,
325
- isLedgerWallet: account2.isLedgerWallet,
326
- };
327
-
328
- // Sign with first account
329
- const signature1 =
330
- await keyringManager.ethereumTransaction.signPersonalMessage([
331
- '0x48656c6c6f',
332
- keyringManager.getActiveAccount().activeAccount.address,
333
- ]);
334
-
335
- // Switch to second account
336
- currentVaultState.activeAccount = {
337
- id: account2.id,
338
- type: KeyringAccountType.HDAccount,
339
- };
340
-
341
- // Sign with second account
342
- const signature2 =
343
- await keyringManager.ethereumTransaction.signPersonalMessage([
344
- '0x48656c6c6f',
345
- account2.address,
346
- ]);
347
-
348
- // Signatures should be different
349
- expect(signature1).not.toBe(signature2);
350
- });
351
- });
352
-
353
- describe('Error Handling', () => {
354
- it('should handle transaction parameters', async () => {
355
- const tx = {
356
- from: keyringManager.getActiveAccount().activeAccount.address,
357
- to: '0x2c7536E3605D9C16a7a3D7b1898e529396a65c23', // Valid checksummed address
358
- value: '0x0',
359
- chainId: 1,
360
- maxFeePerGas: '0x4a817c800',
361
- maxPriorityFeePerGas: '0x77359400',
362
- gasLimit: '0x5208',
363
- };
364
-
365
- const result =
366
- await keyringManager.ethereumTransaction.sendFormattedTransaction(tx);
367
- expect(result).toBeDefined();
368
- expect(result.hash).toBeDefined();
369
- });
370
-
371
- it('should handle signing with locked wallet', async () => {
372
- keyringManager.lockWallet();
373
-
374
- await expect(async () => {
375
- await keyringManager.ethereumTransaction.signPersonalMessage([
376
- '0x48656c6c6f',
377
- '0x0000000000000000000000000000000000000000',
378
- ]);
379
- }).rejects.toThrow();
380
- });
381
- });
382
- });