@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,615 +0,0 @@
1
- import { INetworkType } from '@sidhujag/sysweb3-network';
2
- import * as sjs from 'syscoinjs-lib';
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('Syscoin 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 UTXO testnet vault state
19
- currentVaultState = createMockVaultState({
20
- activeAccountId: 0,
21
- activeAccountType: KeyringAccountType.HDAccount,
22
- networkType: INetworkType.Syscoin,
23
- chainId: 5700,
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('Fee Estimation', () => {
35
- it('should get recommended fee from network', async () => {
36
- const fee = await keyringManager.syscoinTransaction.getRecommendedFee(
37
- keyringManager.getNetwork().url
38
- );
39
-
40
- expect(typeof fee).toBe('number');
41
- expect(fee).toBeGreaterThan(0);
42
- expect(fee).toBeLessThan(1); // Fee should be reasonable (less than 1 SYS/byte)
43
- });
44
-
45
- it('should estimate transaction fee for simple transfer', async () => {
46
- // Mock PsbtUtils.toPali to avoid toBase64 errors
47
- const PsbtUtils = require('../../../src/utils/psbt').PsbtUtils;
48
- const originalToPali = PsbtUtils.toPali;
49
- PsbtUtils.toPali = jest.fn().mockReturnValue({
50
- psbt: 'mock_psbt_base64',
51
- assets: [],
52
- });
53
-
54
- const result =
55
- await keyringManager.syscoinTransaction.getEstimateSysTransactionFee({
56
- txOptions: {},
57
- amount: 0.1, // 0.1 SYS
58
- receivingAddress: 'tsys1qdsvzmrxkq5uh0kwc6cyndsj7fluszcu3pl2wlv',
59
- feeRate: 0.000001, // 1 satoshi per byte
60
- token: null,
61
- });
62
-
63
- expect(result.fee).toBeGreaterThan(0);
64
- expect(result.psbt).toBeDefined();
65
- expect(typeof result.psbt).toBe('object');
66
-
67
- // Restore
68
- PsbtUtils.toPali = originalToPali;
69
- });
70
-
71
- it('should handle fee estimation with multiple outputs', async () => {
72
- // Mock PsbtUtils.toPali to avoid toBase64 errors
73
- const PsbtUtils = require('../../../src/utils/psbt').PsbtUtils;
74
- const originalToPali = PsbtUtils.toPali;
75
- PsbtUtils.toPali = jest.fn().mockReturnValue({
76
- psbt: 'mock_psbt_base64',
77
- assets: [],
78
- });
79
-
80
- const outputs = [
81
- {
82
- address: 'tsys1qdsvzmrxkq5uh0kwc6cyndsj7fluszcu3pl2wlv',
83
- value: 0.05,
84
- },
85
- {
86
- address: 'tsys1q4v8sagt0znwaxdscrzhvu8t33n7vj8j45czpv4',
87
- value: 0.05,
88
- },
89
- ];
90
-
91
- // Test with custom fee rate
92
- const feeRate = 0.000002; // 2 satoshis per byte
93
-
94
- // Note: This would need actual implementation in syscoinTransaction
95
- // For now, we're testing the interface
96
- const amount = outputs.reduce((sum, out) => sum + out.value, 0);
97
- const result =
98
- await keyringManager.syscoinTransaction.getEstimateSysTransactionFee({
99
- txOptions: {},
100
- amount,
101
- receivingAddress: outputs[0].address,
102
- feeRate,
103
- token: null,
104
- });
105
-
106
- expect(result.fee).toBeGreaterThan(0);
107
-
108
- // Restore
109
- PsbtUtils.toPali = originalToPali;
110
- });
111
- });
112
-
113
- describe('PSBT Operations', () => {
114
- it('should sign a valid PSBT', async () => {
115
- // Mock PsbtUtils to avoid Base64 validation
116
- const PsbtUtils = require('../../../src/utils/psbt').PsbtUtils;
117
- const originalFromPali = PsbtUtils.fromPali;
118
- const originalToPali = PsbtUtils.toPali;
119
-
120
- PsbtUtils.fromPali = jest.fn().mockReturnValue({
121
- txInputs: [{ hash: Buffer.alloc(32), index: 0, sequence: 0xffffffff }],
122
- txOutputs: [{ script: Buffer.alloc(25), value: 100000000 }],
123
- data: {
124
- inputs: [
125
- {
126
- witnessUtxo: { script: Buffer.alloc(25), value: 100000000 },
127
- nonWitnessUtxo: Buffer.alloc(100),
128
- },
129
- ],
130
- outputs: [{}],
131
- },
132
- getInputType: () => 'witnesspubkeyhash',
133
- signAllInputsHDAsync: jest.fn().mockResolvedValue(undefined),
134
- validateSignaturesOfAllInputs: jest.fn().mockReturnValue(true),
135
- finalizeAllInputs: jest.fn(),
136
- extractTransaction: jest.fn().mockReturnValue({
137
- getId: jest.fn().mockReturnValue('mock_txid'),
138
- }),
139
- });
140
-
141
- PsbtUtils.toPali = jest.fn().mockReturnValue({
142
- psbt: 'mock_signed_psbt',
143
- assets: [],
144
- });
145
-
146
- const mockPsbtData = {
147
- psbt: 'mocked_psbt_base64',
148
- assets: [],
149
- };
150
-
151
- const result = await keyringManager.syscoinTransaction.signPSBT({
152
- psbt: mockPsbtData,
153
- isTrezor: false,
154
- isLedger: false,
155
- });
156
-
157
- expect(result).toBeDefined();
158
- expect(typeof result).toBe('object');
159
-
160
- // Restore
161
- PsbtUtils.fromPali = originalFromPali;
162
- PsbtUtils.toPali = originalToPali;
163
- });
164
-
165
- it('should reject invalid PSBT format', async () => {
166
- await expect(
167
- keyringManager.syscoinTransaction.signPSBT({
168
- psbt: 'invalid-psbt-format',
169
- isTrezor: false,
170
- isLedger: false,
171
- })
172
- ).rejects.toThrow();
173
- });
174
-
175
- it('should handle PSBT signing with hardware wallet flags', async () => {
176
- // Mock PsbtUtils to avoid Base64 validation
177
- const PsbtUtils = require('../../../src/utils/psbt').PsbtUtils;
178
- const originalFromPali = PsbtUtils.fromPali;
179
- const originalToPali = PsbtUtils.toPali;
180
-
181
- // Mock the entire signPSBTWithMethod to bypass all Trezor validation
182
- const originalSignPSBTWithMethod = (
183
- keyringManager.syscoinTransaction as any
184
- ).signPSBTWithMethod;
185
- (keyringManager.syscoinTransaction as any).signPSBTWithMethod = jest
186
- .fn()
187
- .mockResolvedValue({
188
- txid: 'mock_trezor_txid',
189
- transaction: 'mock_trezor_transaction',
190
- });
191
-
192
- // Mock a proper PSBT object with required methods for Trezor conversion
193
- PsbtUtils.fromPali = jest.fn().mockReturnValue({
194
- txInputs: [{ hash: Buffer.alloc(32), index: 0, sequence: 0xffffffff }],
195
- txOutputs: [
196
- {
197
- script: Buffer.from('0014' + '0'.repeat(40), 'hex'), // Valid witness script
198
- value: 100000000,
199
- address:
200
- 'tsys1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq4k9aqm', // Valid testnet bech32
201
- },
202
- ],
203
- data: {
204
- inputs: [
205
- {
206
- witnessUtxo: { script: Buffer.alloc(25), value: 100000000 },
207
- nonWitnessUtxo: Buffer.alloc(100),
208
- },
209
- ],
210
- outputs: [{}],
211
- },
212
- getInputType: () => 'witnesspubkeyhash',
213
- finalizeAllInputs: jest.fn(),
214
- extractTransaction: jest.fn().mockReturnValue({
215
- getId: jest.fn().mockReturnValue('mock_txid'),
216
- }),
217
- });
218
-
219
- PsbtUtils.toPali = jest.fn().mockReturnValue({
220
- psbt: 'mock_signed_psbt',
221
- assets: [],
222
- });
223
-
224
- const mockPsbtData = {
225
- psbt: 'mocked_psbt_base64',
226
- assets: [],
227
- };
228
-
229
- // Test with Trezor flag
230
- const trezorResult = await keyringManager.syscoinTransaction.signPSBT({
231
- psbt: mockPsbtData,
232
- isTrezor: true,
233
- isLedger: false,
234
- });
235
-
236
- expect(trezorResult).toBeDefined();
237
-
238
- // Restore
239
- PsbtUtils.fromPali = originalFromPali;
240
- PsbtUtils.toPali = originalToPali;
241
- (keyringManager.syscoinTransaction as any).signPSBTWithMethod =
242
- originalSignPSBTWithMethod;
243
- });
244
- });
245
-
246
- describe('Transaction Creation', () => {
247
- it('should create a simple transaction', async () => {
248
- // Mock PsbtUtils throughout the entire flow
249
- const PsbtUtils = require('../../../src/utils/psbt').PsbtUtils;
250
- const originalFromPali = PsbtUtils.fromPali;
251
- const originalToPali = PsbtUtils.toPali;
252
-
253
- PsbtUtils.toPali = jest.fn().mockReturnValue({
254
- psbt: 'mock_unsigned_psbt',
255
- assets: [],
256
- });
257
-
258
- PsbtUtils.fromPali = jest.fn().mockReturnValue({
259
- txInputs: [{ hash: Buffer.alloc(32), index: 0, sequence: 0xffffffff }],
260
- txOutputs: [{ script: Buffer.alloc(25), value: 100000000 }],
261
- data: {
262
- inputs: [
263
- {
264
- witnessUtxo: { script: Buffer.alloc(25), value: 100000000 },
265
- nonWitnessUtxo: Buffer.alloc(100),
266
- },
267
- ],
268
- outputs: [{}],
269
- },
270
- getInputType: () => 'witnesspubkeyhash',
271
- signAllInputsHDAsync: jest.fn().mockResolvedValue(undefined),
272
- validateSignaturesOfAllInputs: jest.fn().mockReturnValue(true),
273
- finalizeAllInputs: jest.fn(),
274
- extractTransaction: jest.fn().mockReturnValue({
275
- getId: jest.fn().mockReturnValue('mock_transaction_id'),
276
- }),
277
- });
278
-
279
- // First create unsigned PSBT
280
- const feeEstimate =
281
- await keyringManager.syscoinTransaction.getEstimateSysTransactionFee({
282
- txOptions: {},
283
- amount: 0.1,
284
- receivingAddress: 'tsys1qdsvzmrxkq5uh0kwc6cyndsj7fluszcu3pl2wlv',
285
- feeRate: 0.0001,
286
- token: null,
287
- });
288
-
289
- // Mock signed PSBT for signing step
290
- PsbtUtils.toPali.mockReturnValue({
291
- psbt: 'mock_signed_psbt',
292
- assets: [],
293
- });
294
-
295
- // Sign the PSBT
296
- const signedPsbt = await keyringManager.syscoinTransaction.signPSBT({
297
- psbt: feeEstimate.psbt,
298
- isTrezor: false,
299
- isLedger: false,
300
- });
301
-
302
- // Mock sendTransaction to avoid network calls
303
- const originalSendTransaction =
304
- keyringManager.syscoinTransaction.sendTransaction;
305
- keyringManager.syscoinTransaction.sendTransaction = jest
306
- .fn()
307
- .mockResolvedValue({
308
- txid: 'mock_transaction_id',
309
- });
310
-
311
- // Now send the signed PSBT (current API signature)
312
- const result = await keyringManager.syscoinTransaction.sendTransaction(
313
- signedPsbt
314
- );
315
-
316
- expect(result.txid).toBeDefined();
317
- expect(typeof result.txid).toBe('string');
318
-
319
- // Restore
320
- keyringManager.syscoinTransaction.sendTransaction =
321
- originalSendTransaction;
322
-
323
- // Restore
324
- PsbtUtils.fromPali = originalFromPali;
325
- PsbtUtils.toPali = originalToPali;
326
- });
327
-
328
- it('should handle change address generation', async () => {
329
- const changeAddress = await keyringManager.getNewChangeAddress();
330
-
331
- expect(changeAddress).toBeDefined();
332
- expect(changeAddress.startsWith('tsys1')).toBe(true); // Testnet address
333
- expect(changeAddress.length).toBe(44); // Bech32 address length
334
- });
335
-
336
- it('should get current receiving address', async () => {
337
- const address = await keyringManager.updateReceivingAddress();
338
-
339
- expect(address).toBeDefined();
340
- expect(address.startsWith('tsys1')).toBe(true);
341
-
342
- // Verify it updated the account
343
- const account = keyringManager.getActiveAccount().activeAccount;
344
- expect(account.address).toBe(address);
345
- });
346
- });
347
-
348
- describe('UTXO Management', () => {
349
- it('should handle UTXO selection for transactions', async () => {
350
- // Mock PsbtUtils.toPali to avoid toBase64 errors
351
- const PsbtUtils = require('../../../src/utils/psbt').PsbtUtils;
352
- const originalToPali = PsbtUtils.toPali;
353
- PsbtUtils.toPali = jest.fn().mockReturnValue({
354
- psbt: 'mock_psbt_base64',
355
- assets: [],
356
- });
357
-
358
- // This tests the integration with coinselectsyscoin
359
- const amount = 0.5; // 0.5 SYS
360
- const feeRate = 0.000001; // 1 satoshi per byte
361
-
362
- const result =
363
- await keyringManager.syscoinTransaction.getEstimateSysTransactionFee({
364
- txOptions: { rbf: true }, // Replace-by-fee enabled
365
- amount,
366
- receivingAddress: 'tsys1qdsvzmrxkq5uh0kwc6cyndsj7fluszcu3pl2wlv',
367
- feeRate,
368
- token: null,
369
- });
370
-
371
- expect(result.fee).toBeGreaterThan(0);
372
- expect(result.fee).toBeLessThan(amount); // Fee should be less than amount
373
-
374
- // Restore
375
- PsbtUtils.toPali = originalToPali;
376
- });
377
-
378
- it('should handle insufficient balance', async () => {
379
- // Try to send more than available balance
380
- const hugeAmount = 1000000; // 1 million SYS
381
-
382
- // This should fail in a real implementation
383
- try {
384
- await keyringManager.syscoinTransaction.getEstimateSysTransactionFee({
385
- txOptions: {},
386
- amount: hugeAmount,
387
- receivingAddress: 'tsys1qdsvzmrxkq5uh0kwc6cyndsj7fluszcu3pl2wlv',
388
- feeRate: 0.000001,
389
- token: null,
390
- });
391
- } catch (error) {
392
- // Expected to fail with insufficient balance
393
- expect(error).toBeDefined();
394
- }
395
- });
396
- });
397
-
398
- describe('SPT Token Support', () => {
399
- it('should handle SPT token transactions', async () => {
400
- // Mock PsbtUtils throughout the entire flow
401
- const PsbtUtils = require('../../../src/utils/psbt').PsbtUtils;
402
- const originalFromPali = PsbtUtils.fromPali;
403
- const originalToPali = PsbtUtils.toPali;
404
-
405
- PsbtUtils.toPali = jest.fn().mockReturnValue({
406
- psbt: 'mock_token_psbt',
407
- assets: [],
408
- });
409
-
410
- PsbtUtils.fromPali = jest.fn().mockReturnValue({
411
- txInputs: [{ hash: Buffer.alloc(32), index: 0, sequence: 0xffffffff }],
412
- txOutputs: [{ script: Buffer.alloc(25), value: 100000000 }],
413
- data: {
414
- inputs: [
415
- {
416
- witnessUtxo: { script: Buffer.alloc(25), value: 100000000 },
417
- nonWitnessUtxo: Buffer.alloc(100),
418
- },
419
- ],
420
- outputs: [{}],
421
- },
422
- getInputType: () => 'witnesspubkeyhash',
423
- signAllInputsHDAsync: jest.fn().mockResolvedValue(undefined),
424
- validateSignaturesOfAllInputs: jest.fn().mockReturnValue(true),
425
- finalizeAllInputs: jest.fn(),
426
- extractTransaction: jest.fn().mockReturnValue({
427
- getId: jest.fn().mockReturnValue('mock_token_txid'),
428
- }),
429
- });
430
-
431
- // First create unsigned PSBT for token transaction
432
- const feeEstimate =
433
- await keyringManager.syscoinTransaction.getEstimateSysTransactionFee({
434
- txOptions: {},
435
- amount: 100, // 100 tokens
436
- receivingAddress: 'tsys1qdsvzmrxkq5uh0kwc6cyndsj7fluszcu3pl2wlv',
437
- feeRate: 0.0001,
438
- token: {
439
- guid: '123456789',
440
- symbol: 'TEST',
441
- },
442
- });
443
-
444
- // Mock signed PSBT for signing step
445
- PsbtUtils.toPali.mockReturnValue({
446
- psbt: 'mock_signed_token_psbt',
447
- assets: [],
448
- });
449
-
450
- // Sign the PSBT
451
- const signedPsbt = await keyringManager.syscoinTransaction.signPSBT({
452
- psbt: feeEstimate.psbt,
453
- isTrezor: false,
454
- isLedger: false,
455
- });
456
-
457
- // Mock sendTransaction to avoid network calls
458
- const originalSendTransaction =
459
- keyringManager.syscoinTransaction.sendTransaction;
460
- keyringManager.syscoinTransaction.sendTransaction = jest
461
- .fn()
462
- .mockResolvedValue({
463
- txid: 'mock_token_txid',
464
- });
465
-
466
- // Send the signed token transaction
467
- const result = await keyringManager.syscoinTransaction.sendTransaction(
468
- signedPsbt
469
- );
470
-
471
- expect(result.txid).toBeDefined();
472
-
473
- // Restore sendTransaction
474
- keyringManager.syscoinTransaction.sendTransaction =
475
- originalSendTransaction;
476
-
477
- // Restore
478
- PsbtUtils.fromPali = originalFromPali;
479
- PsbtUtils.toPali = originalToPali;
480
- });
481
- });
482
-
483
- describe('Multiple Account Support', () => {
484
- it('should sign transactions from different accounts', async () => {
485
- // Add a second account
486
- const account2 = await keyringManager.addNewAccount('Account 2');
487
-
488
- // Update vault state with the new account (in stateless keyring, this would be done by Pali/Redux)
489
- currentVaultState.accounts[KeyringAccountType.HDAccount][account2.id] = {
490
- id: account2.id,
491
- address: account2.address,
492
- xpub: account2.xpub,
493
- xprv: account2.xprv,
494
- label: account2.label,
495
- balances: account2.balances,
496
- isImported: account2.isImported,
497
- isTrezorWallet: account2.isTrezorWallet,
498
- isLedgerWallet: account2.isLedgerWallet,
499
- };
500
-
501
- // Get change address for account 1
502
- const changeAddress1 = await keyringManager.getChangeAddress(0);
503
-
504
- // Switch to account 2
505
- currentVaultState.activeAccount = {
506
- id: account2.id,
507
- type: KeyringAccountType.HDAccount,
508
- };
509
-
510
- // Get change address for account 2
511
- const changeAddress2 = await keyringManager.getChangeAddress(1);
512
-
513
- // Addresses should be different
514
- expect(changeAddress1).not.toBe(changeAddress2);
515
- expect(changeAddress1.startsWith('tsys1')).toBe(true);
516
- expect(changeAddress2.startsWith('tsys1')).toBe(true);
517
- });
518
- });
519
-
520
- describe('Network Compatibility', () => {
521
- it('should work with mainnet configuration', async () => {
522
- // Set up mainnet vault state
523
- const mainnetVaultState = createMockVaultState({
524
- activeAccountId: 0,
525
- activeAccountType: KeyringAccountType.HDAccount,
526
- networkType: INetworkType.Syscoin,
527
- chainId: 57,
528
- });
529
- const mainnetVaultStateGetter = jest.fn(() => mainnetVaultState);
530
-
531
- // Create mainnet keyring
532
- const mainnetKeyring = await KeyringManager.createInitialized(
533
- PEACE_SEED_PHRASE,
534
- FAKE_PASSWORD,
535
- mainnetVaultStateGetter
536
- );
537
-
538
- const address = mainnetKeyring.getActiveAccount().activeAccount.address;
539
- expect(address.startsWith('sys1')).toBe(true); // Mainnet prefix
540
-
541
- const fee = await mainnetKeyring.syscoinTransaction.getRecommendedFee(
542
- mainnetKeyring.getNetwork().url
543
- );
544
- expect(fee).toBeGreaterThan(0);
545
- });
546
- });
547
-
548
- describe('Error Handling', () => {
549
- it('should handle network errors gracefully', async () => {
550
- // Mock a network error
551
- const mockFetchEstimateFee = sjs.utils.fetchEstimateFee as jest.Mock;
552
- mockFetchEstimateFee.mockRejectedValueOnce(new Error('Network error'));
553
-
554
- try {
555
- await keyringManager.syscoinTransaction.getRecommendedFee(
556
- 'https://invalid-url.com'
557
- );
558
- } catch (error) {
559
- expect(error.message).toContain('Network error');
560
- }
561
- });
562
-
563
- it('should validate addresses before sending', async () => {
564
- // Mock address validation to throw for invalid addresses
565
- const syscoinjs = require('syscoinjs-lib');
566
- const originalValidateAddress = syscoinjs.utils.validateSyscoinAddress;
567
- syscoinjs.utils.validateSyscoinAddress = jest
568
- .fn()
569
- .mockImplementation((address) => {
570
- if (address === 'invalid_address') {
571
- throw new Error('Invalid address format');
572
- }
573
- return true;
574
- });
575
-
576
- // Should reject invalid addresses during fee estimation
577
- try {
578
- await keyringManager.syscoinTransaction.getEstimateSysTransactionFee({
579
- txOptions: {},
580
- amount: 0.1,
581
- receivingAddress: 'invalid_address',
582
- feeRate: 0.0001,
583
- token: null,
584
- });
585
- // If we get here, the test should fail
586
- expect(true).toBe(false);
587
- } catch (error) {
588
- // Expected to throw for invalid address
589
- expect(error).toBeDefined();
590
- }
591
-
592
- // Restore
593
- syscoinjs.utils.validateSyscoinAddress = originalValidateAddress;
594
- });
595
-
596
- it('should require unlock for transaction operations', async () => {
597
- keyringManager.lockWallet();
598
-
599
- try {
600
- await keyringManager.syscoinTransaction.getEstimateSysTransactionFee({
601
- txOptions: {},
602
- amount: 0.1,
603
- receivingAddress: 'tsys1qdsvzmrxkq5uh0kwc6cyndsj7fluszcu3pl2wlv',
604
- feeRate: 0.0001,
605
- token: null,
606
- });
607
- // If we get here, the test should fail
608
- expect(true).toBe(false);
609
- } catch (error) {
610
- // Expected to throw when wallet is locked
611
- expect(error).toBeDefined();
612
- }
613
- });
614
- });
615
- });
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "../../tsconfig-package.json",
3
- "compilerOptions": {
4
- "rootDir": "src",
5
- "baseUrl": "src",
6
- "allowJs": true,
7
- "outDir": "dist/cjs",
8
- "declarationDir": "dist/types",
9
- "resolveJsonModule": true,
10
- "noImplicitAny": false,
11
- "strictPropertyInitialization": false
12
- },
13
- "include": ["src"]
14
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes