@bitpay-labs/crypto-wallet-core 11.11.4 → 11.11.6

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 (91) hide show
  1. package/package.json +9 -3
  2. package/ts_build/src/constants/index.d.ts +18 -1
  3. package/ts_build/src/constants/index.d.ts.map +1 -1
  4. package/ts_build/src/constants/tokens.d.ts +14 -2
  5. package/ts_build/src/constants/tokens.d.ts.map +1 -1
  6. package/ts_build/src/constants/tokens.js +8 -2
  7. package/ts_build/src/constants/tokens.js.map +1 -1
  8. package/ts_build/src/constants/units.d.ts +11 -0
  9. package/ts_build/src/constants/units.d.ts.map +1 -1
  10. package/ts_build/src/constants/units.js +11 -0
  11. package/ts_build/src/constants/units.js.map +1 -1
  12. package/ts_build/src/transactions/index.d.ts +1 -1
  13. package/ts_build/src/transactions/index.d.ts.map +1 -1
  14. package/ts_build/src/transactions/index.js.map +1 -1
  15. package/ts_build/src/types/derivation.d.ts +1 -0
  16. package/ts_build/src/types/derivation.d.ts.map +1 -1
  17. package/.mocharc.json +0 -6
  18. package/LICENSE +0 -21
  19. package/mcr.config.js +0 -17
  20. package/src/constants/address.ts +0 -7
  21. package/src/constants/algorithms.ts +0 -9
  22. package/src/constants/arc.ts +0 -4
  23. package/src/constants/chains.ts +0 -68
  24. package/src/constants/feeMinimums.ts +0 -23
  25. package/src/constants/index.ts +0 -40
  26. package/src/constants/tokens.ts +0 -227
  27. package/src/constants/units.ts +0 -300
  28. package/src/derivation/arb/index.ts +0 -3
  29. package/src/derivation/base/index.ts +0 -3
  30. package/src/derivation/bch/index.ts +0 -11
  31. package/src/derivation/btc/index.ts +0 -68
  32. package/src/derivation/doge/index.ts +0 -6
  33. package/src/derivation/eth/index.ts +0 -86
  34. package/src/derivation/index.ts +0 -140
  35. package/src/derivation/ltc/index.ts +0 -6
  36. package/src/derivation/matic/index.ts +0 -3
  37. package/src/derivation/op/index.ts +0 -3
  38. package/src/derivation/paths.ts +0 -45
  39. package/src/derivation/sol/index.ts +0 -81
  40. package/src/derivation/xrp/index.ts +0 -63
  41. package/src/index.ts +0 -48
  42. package/src/message/btc.ts +0 -28
  43. package/src/message/eth.ts +0 -47
  44. package/src/message/index.ts +0 -71
  45. package/src/message/sol.ts +0 -3
  46. package/src/message/xrp.ts +0 -4
  47. package/src/transactions/arb/index.ts +0 -14
  48. package/src/transactions/base/index.ts +0 -13
  49. package/src/transactions/bch/index.ts +0 -25
  50. package/src/transactions/btc/index.ts +0 -316
  51. package/src/transactions/doge/index.ts +0 -31
  52. package/src/transactions/erc20/abi.ts +0 -418
  53. package/src/transactions/erc20/index.ts +0 -57
  54. package/src/transactions/eth/index.ts +0 -192
  55. package/src/transactions/eth-multisig/abi.ts +0 -724
  56. package/src/transactions/eth-multisig/index.ts +0 -172
  57. package/src/transactions/index.ts +0 -85
  58. package/src/transactions/ltc/index.ts +0 -31
  59. package/src/transactions/matic/index.ts +0 -14
  60. package/src/transactions/matic-multisig/index.ts +0 -172
  61. package/src/transactions/op/index.ts +0 -14
  62. package/src/transactions/sol/index.ts +0 -306
  63. package/src/transactions/spl/index.ts +0 -192
  64. package/src/transactions/xrp/index.ts +0 -167
  65. package/src/types/derivation.ts +0 -34
  66. package/src/types/index.ts +0 -3
  67. package/src/types/message.ts +0 -15
  68. package/src/types/utils.ts +0 -1
  69. package/src/types/validation.ts +0 -4
  70. package/src/utils/bigint.ts +0 -238
  71. package/src/utils/index.ts +0 -188
  72. package/src/validation/arb/index.ts +0 -8
  73. package/src/validation/arc/index.ts +0 -8
  74. package/src/validation/base/index.ts +0 -8
  75. package/src/validation/bch/index.ts +0 -17
  76. package/src/validation/btc/index.ts +0 -17
  77. package/src/validation/doge/index.ts +0 -16
  78. package/src/validation/eth/index.ts +0 -29
  79. package/src/validation/index.ts +0 -45
  80. package/src/validation/ltc/index.ts +0 -16
  81. package/src/validation/matic/index.ts +0 -8
  82. package/src/validation/op/index.ts +0 -8
  83. package/src/validation/sol/index.ts +0 -34
  84. package/src/validation/xrp/index.ts +0 -50
  85. package/test/address.test.ts +0 -190
  86. package/test/bigint.test.ts +0 -373
  87. package/test/deriver.test.ts +0 -126
  88. package/test/transactions.test.ts +0 -2103
  89. package/test/utils.test.ts +0 -446
  90. package/test/validation.test.ts +0 -282
  91. package/tsconfig.json +0 -29
@@ -1,2103 +0,0 @@
1
- import { expect } from 'chai';
2
- import { ethers } from 'ethers';
3
- import bitcoreLib from '@bitpay-labs/bitcore-lib';
4
- import bitcoreLibCash from '@bitpay-labs/bitcore-lib-cash';
5
- import bitcoreLibDoge from '@bitpay-labs/bitcore-lib-doge';
6
- import bitcoreLibLtc from '@bitpay-labs/bitcore-lib-ltc';
7
- import { Constants, Transactions } from '../src';
8
-
9
- describe('Transaction', function () {
10
- const libs = {
11
- BTC: bitcoreLib,
12
- BCH: bitcoreLibCash,
13
- DOGE: bitcoreLibDoge,
14
- LTC: bitcoreLibLtc
15
- };
16
- describe('create', () => {
17
- it('should create a BTC tx', () => {
18
- const recipients = [{ address: 'mpNpzMoprLnSBu8CWDunNCYeJq3Mzdk59V', amount: 1e8 }];
19
- const change = 'msnAsQcCdtzDyiSWb4ZnNxFwUy3P9ogQvY';
20
- const utxos = [
21
- {
22
- mintTxid: '643ec66d6c4cad4cbdb8ed2166b8078975e0af9bb7ff7e30d394f43b0d9f18ab',
23
- mintIndex: 1,
24
- value: 0.02503422 * 1e8,
25
- script: '76a91457884dcfe2ab46d3354a42d97333c95e5b80cf0188ac',
26
- address: 'moVnNJpHHfssYJEnMTS5xXyGV8RhRQNRz5',
27
- sequenceNumber: 4294967294
28
- },
29
- {
30
- mintTxid: '643ec66d6c4cad4cbdb8ed2166b8078975e0af9bb7ff7e30d394f43b0d9f18ab',
31
- mintIndex: 0,
32
- value: 1e8,
33
- script: '76a9144e744a19a009a9dd43a23a7c12045c83e82ac9d288ac',
34
- address: 'mnfnJx2xWWptYmBzck3rdE851Dtu9GaZ3F',
35
- sequenceNumber: 4294967294
36
- }
37
- ];
38
- const fee = 7440;
39
- const tx = Transactions.create({ chain: 'BTC', recipients, change, utxos, fee, rbf: true });
40
-
41
- const keys = [
42
- {
43
- address: 'mnfnJx2xWWptYmBzck3rdE851Dtu9GaZ3F',
44
- privKey: 'cSFjiifSbZ2hU4jTFwE993LCe2rkZGULCTGWTDWXzHvuXRKxpnc1'
45
- },
46
- { address: 'moVnNJpHHfssYJEnMTS5xXyGV8RhRQNRz5', privKey: 'cUWVirwp5vh1D6WWbYci3tuGniyf28ERpgU4uL5VSiFDfvNEhJqy' }
47
- ];
48
- const signed = Transactions.sign({ chain: 'BTC', tx, keys, utxos });
49
- const expected =
50
- '0200000002ab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e64010000006a47304402202eeb967801c0aad4f8241d8f90e2a9e2236f95c189165ba6b2ba4dc6b17bacbe02201b5d4dc0c32f6aa134d93698f85bf4c098d15fcbaada0b6ca2b8076fd8aa2741012102c8f8fa438666cbd287e28fb384b99555e4acce610e8141e887c9c458bba5db5cffffffffab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e64000000006a473044022072bdde2c0b413fc42d15d93e768a26f818dc5b225b9359235c09fd0452d6121a022007c00afa396d60d5b7919f2ba31e638817561cab4e2afed7a86dd636ee293c1001210321f2f13aed42db7257b64f77d574071a6e81e460ab3693eefb7482c12d1ff697ffffffff0200e1f505000000001976a914612fb4d5e27a28f5c54018d8948ca3a650741c4188acee152600000000001976a91486823ef7c8e210184cc8675189d37c4c9d8e1e0288ac00000000';
51
- expect(signed).to.eq(expected);
52
- });
53
-
54
- describe('every utxo type: bitcore-node, UnspentOutput, and UnspentOutput.toObject', () => {
55
- const keys = [{
56
- address: 'mnfnJx2xWWptYmBzck3rdE851Dtu9GaZ3F',
57
- privKey: 'cSFjiifSbZ2hU4jTFwE993LCe2rkZGULCTGWTDWXzHvuXRKxpnc1'
58
- }];
59
-
60
- const bitcoreNodeUtxos =
61
- [
62
- {
63
- mintTxid: '643ec66d6c4cad4cbdb8ed2166b8078975e0af9bb7ff7e30d394f43b0d9f18ab',
64
- mintIndex: 1,
65
- mintHeight: 100,
66
- value: 90_000,
67
- script: '76a9144e744a19a009a9dd43a23a7c12045c83e82ac9d288ac',
68
- address: 'mnfnJx2xWWptYmBzck3rdE851Dtu9GaZ3F',
69
- sequenceNumber: 4294967294
70
- },
71
- {
72
- mintTxid: '643ec66d6c4cad4cbdb8ed2166b8078975e0af9bb7ff7e30d394f43b0d9f18ab',
73
- mintIndex: 0,
74
- mintHeight: 100,
75
- value: 30_000,
76
- script: '76a9144e744a19a009a9dd43a23a7c12045c83e82ac9d288ac',
77
- address: 'mnfnJx2xWWptYmBzck3rdE851Dtu9GaZ3F',
78
- sequenceNumber: 4294967294
79
- }
80
- ];
81
-
82
- const unspentOutputToObjectUtxos = [
83
- {
84
- txid: '643ec66d6c4cad4cbdb8ed2166b8078975e0af9bb7ff7e30d394f43b0d9f18ab',
85
- outputIndex: 1,
86
- amount: 0.0009,
87
- scriptPubKey: '76a9144e744a19a009a9dd43a23a7c12045c83e82ac9d288ac'
88
- },
89
- {
90
- txid: '643ec66d6c4cad4cbdb8ed2166b8078975e0af9bb7ff7e30d394f43b0d9f18ab',
91
- vout: 0,
92
- amount: 0.0003,
93
- scriptPubKey: '76a9144e744a19a009a9dd43a23a7c12045c83e82ac9d288ac'
94
- }
95
- ];
96
-
97
- const recipients = [{ address: 'moVnNJpHHfssYJEnMTS5xXyGV8RhRQNRz5', amount: 100_000 }];
98
- for (const chain of ['BTC', 'BCH', 'DOGE', 'LTC']) {
99
- const unspentOutputUtxos = [
100
- new libs[chain].Transaction.UnspentOutput({
101
- txId: '643ec66d6c4cad4cbdb8ed2166b8078975e0af9bb7ff7e30d394f43b0d9f18ab',
102
- outputIndex: 1,
103
- satoshis: 90_000,
104
- script: '76a9144e744a19a009a9dd43a23a7c12045c83e82ac9d288ac'
105
- }),
106
- new libs[chain].Transaction.UnspentOutput({
107
- txId: '643ec66d6c4cad4cbdb8ed2166b8078975e0af9bb7ff7e30d394f43b0d9f18ab',
108
- outputIndex: 0,
109
- satoshis: 30_000,
110
- script: '76a9144e744a19a009a9dd43a23a7c12045c83e82ac9d288ac'
111
- })
112
- ];
113
- const utxoSet = [
114
- bitcoreNodeUtxos,
115
- unspentOutputUtxos,
116
- unspentOutputToObjectUtxos
117
- ];
118
- let tx: string;
119
- const lib = libs[chain];
120
- it(`should create a tx with every utxo type for ${chain}`, () => {
121
- const txs = utxoSet.map(utxos => Transactions.create({
122
- chain,
123
- recipients,
124
- utxos
125
- }));
126
-
127
- tx = txs[0];
128
- for (const _tx of txs.slice(1)) {
129
- expect(tx, 'all transactions should be the same regardless of the utxo format').to.equal(_tx);
130
- }
131
-
132
- let expectedTx: string;
133
- if (chain === 'DOGE') {
134
- expectedTx = '0100000002ab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e640100000000ffffffffab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e640000000000ffffffff01a0860100000000001976a91457884dcfe2ab46d3354a42d97333c95e5b80cf0188ac00000000';
135
- } else {
136
- expectedTx = '0200000002ab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e640100000000ffffffffab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e640000000000ffffffff01a0860100000000001976a91457884dcfe2ab46d3354a42d97333c95e5b80cf0188ac00000000';
137
- }
138
- expect(tx).to.equal(expectedTx);
139
- });
140
-
141
- it(`should sign a tx with every utxo type ${chain}`, () => {
142
- const signedTxs = utxoSet.map(utxos => Transactions.sign({
143
- chain,
144
- tx,
145
- utxos,
146
- keys,
147
- sigtype: lib.crypto.Signature.SIGHASH_ALL
148
- }));
149
- const signedTx = signedTxs[0];
150
- for (const _signedTx of signedTxs.slice(1)) {
151
- expect(signedTx, 'signed transactions should all be the same regardless of utxo type').to.equal(_signedTx);
152
- }
153
-
154
- let expectedTx: string;
155
- if (chain === 'DOGE') {
156
- expectedTx = '0100000002ab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e64010000006a473044022015ceee1da23792e26cd1215c8327a35978c8b0494de9e69bab6d31ab3d0b56ad02205f9299162591672c6cde3d92d5819a11e1ad9f353a25d7a3ce494877ef27468901210321f2f13aed42db7257b64f77d574071a6e81e460ab3693eefb7482c12d1ff697ffffffffab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e64000000006b4830450221009f0b5dd0b4c0bd9bcf804e71020705eb9bda99a31cb2a4d123c364bdd394adeb022016939a51fb03c9efea4b7d53a7b90d7a3667fff71cd8365e366c81b1fdd0d3e001210321f2f13aed42db7257b64f77d574071a6e81e460ab3693eefb7482c12d1ff697ffffffff01a0860100000000001976a91457884dcfe2ab46d3354a42d97333c95e5b80cf0188ac00000000';
157
- } else {
158
- expectedTx = '0200000002ab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e64010000006b483045022100c74ab4fe359e8efc73fc28dce989e28da47d3b45eb06ee305dfc0e675da8700802201076a067337a3c6b90fad2077a55154aa150460cb842bc86373026eb071a7ac901210321f2f13aed42db7257b64f77d574071a6e81e460ab3693eefb7482c12d1ff697ffffffffab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e64000000006b483045022100ed22907cc96b5367ef469225f7f718efa8fb4eb2dc5fbf3909777c5f024cf5e902206480082ad9b413a8a76128ab147287da30d907cfb1a159be814392fa1138012801210321f2f13aed42db7257b64f77d574071a6e81e460ab3693eefb7482c12d1ff697ffffffff01a0860100000000001976a91457884dcfe2ab46d3354a42d97333c95e5b80cf0188ac00000000';
159
- }
160
- expect(signedTx).to.equal(expectedTx);
161
- });
162
-
163
- it(`should create valid sighashes for all utxo types ${chain}`, () => {
164
- const bitcoreTx = lib.Transaction()
165
- .from(unspentOutputUtxos)
166
- .to(recipients[0].address, recipients[0].amount);
167
- const signedTx = lib.Transaction()
168
- .from(unspentOutputUtxos)
169
- .to(recipients[0].address, recipients[0].amount);
170
-
171
- for (let index = 0; index < unspentOutputUtxos.length; index++) {
172
- const sighashes: string[] = [];
173
- for (const utxos of utxoSet) {
174
- sighashes.push(Transactions.getSighash({
175
- chain,
176
- tx,
177
- utxos,
178
- index,
179
- sigtype: lib.crypto.Signature.SIGHASH_ALL
180
- }));
181
- }
182
-
183
- // getSighash should work without utxos if a complete lib transaction is provided
184
- sighashes.push(Transactions.getSighash({
185
- chain,
186
- tx: bitcoreTx,
187
- index,
188
- sigtype: lib.crypto.Signature.SIGHASH_ALL
189
- }));
190
-
191
- const sighash = sighashes[0];
192
- for (const hash of sighashes) {
193
- expect(sighash).to.equal(hash);
194
- }
195
- expect(sighash.length).to.equal(64);
196
- const privateKey = new lib.PrivateKey(keys[0].privKey);
197
- const publicKey = privateKey.toPublicKey();
198
- const signature = lib.crypto.ECDSA.sign(Buffer.from(sighash, 'hex'), privateKey);
199
- signature.pubKey = publicKey;
200
-
201
- Transactions.applySignature({
202
- chain,
203
- tx: signedTx,
204
- signature,
205
- index
206
- });
207
- }
208
- if (chain === 'DOGE') {
209
- const serializedSignedTx = '0100000002ab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e64010000006a473044022015ceee1da23792e26cd1215c8327a35978c8b0494de9e69bab6d31ab3d0b56ad02205f9299162591672c6cde3d92d5819a11e1ad9f353a25d7a3ce494877ef27468901210321f2f13aed42db7257b64f77d574071a6e81e460ab3693eefb7482c12d1ff697ffffffffab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e64000000006b4830450221009f0b5dd0b4c0bd9bcf804e71020705eb9bda99a31cb2a4d123c364bdd394adeb022016939a51fb03c9efea4b7d53a7b90d7a3667fff71cd8365e366c81b1fdd0d3e001210321f2f13aed42db7257b64f77d574071a6e81e460ab3693eefb7482c12d1ff697ffffffff01a0860100000000001976a91457884dcfe2ab46d3354a42d97333c95e5b80cf0188ac00000000';
210
- expect(signedTx.serialize({ disableSmallFees: true, disableDustOutputs: true })).to.equal(serializedSignedTx);
211
- } else {
212
- const serializedSignedTx = '0200000002ab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e64010000006b483045022100c74ab4fe359e8efc73fc28dce989e28da47d3b45eb06ee305dfc0e675da8700802201076a067337a3c6b90fad2077a55154aa150460cb842bc86373026eb071a7ac901210321f2f13aed42db7257b64f77d574071a6e81e460ab3693eefb7482c12d1ff697ffffffffab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e64000000006b483045022100ed22907cc96b5367ef469225f7f718efa8fb4eb2dc5fbf3909777c5f024cf5e902206480082ad9b413a8a76128ab147287da30d907cfb1a159be814392fa1138012801210321f2f13aed42db7257b64f77d574071a6e81e460ab3693eefb7482c12d1ff697ffffffff01a0860100000000001976a91457884dcfe2ab46d3354a42d97333c95e5b80cf0188ac00000000';
213
- expect(signedTx.serialize()).to.equal(serializedSignedTx);
214
- }
215
- });
216
- }
217
- });
218
-
219
- it('should sign a BTC opreturn tx', () => {
220
- const tx =
221
- '0200000001ab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e640100000000ffffffff0200000000000000000b6a096a07696f6e3a61626340420f00000000001976a91457884dcfe2ab46d3354a42d97333c95e5b80cf0188ac00000000';
222
- const utxos = [
223
- {
224
- mintTxid: '643ec66d6c4cad4cbdb8ed2166b8078975e0af9bb7ff7e30d394f43b0d9f18ab',
225
- mintIndex: 1,
226
- value: 0.02503422 * 1e8,
227
- script: '76a91457884dcfe2ab46d3354a42d97333c95e5b80cf0188ac',
228
- address: 'moVnNJpHHfssYJEnMTS5xXyGV8RhRQNRz5',
229
- sequenceNumber: 4294967294
230
- }
231
- ];
232
- const keys = [
233
- {
234
- address: 'mnfnJx2xWWptYmBzck3rdE851Dtu9GaZ3F',
235
- privKey: 'cSFjiifSbZ2hU4jTFwE993LCe2rkZGULCTGWTDWXzHvuXRKxpnc1'
236
- },
237
- { address: 'moVnNJpHHfssYJEnMTS5xXyGV8RhRQNRz5', privKey: 'cUWVirwp5vh1D6WWbYci3tuGniyf28ERpgU4uL5VSiFDfvNEhJqy' }
238
- ];
239
- const signed = Transactions.sign({ chain: 'BTC', tx, keys, utxos });
240
- const expected =
241
- '0200000001ab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e64010000006b483045022100a3e6e04d311930ec19b11033e77d973ae37181ead6b2db582ec1c21028c469350220602faacf6f6753b271571452e4597205971ab1d790e60080d50c206c8c327f86012102c8f8fa438666cbd287e28fb384b99555e4acce610e8141e887c9c458bba5db5cffffffff0200000000000000000b6a096a07696f6e3a61626340420f00000000001976a91457884dcfe2ab46d3354a42d97333c95e5b80cf0188ac00000000';
242
- expect(signed).to.eq(expected);
243
- });
244
-
245
- it('should sign a BTC tx with uncompressed pubkey inputs', () => {
246
- const uncompPk = new bitcoreLib.PrivateKey({ bn: '86d32c754853c7d5788d101f0aa5c3ea4da69c0f42ffc3f7403aafba23112b0c', network: 'mainnet', compressed: false });
247
- const uncompAddy = uncompPk.publicKey.toAddress();
248
- const compPk = new bitcoreLib.PrivateKey('86d32c754853c7d5788d101f0aa5c3ea4da69c0f42ffc3f7403aafba23112b0c');
249
- const compAddy = compPk.publicKey.toAddress();
250
-
251
- const tx = new bitcoreLib.Transaction();
252
- const utxos = [{
253
- mintTxid: '643ec66d6c4cad4cbdb8ed2166b8078975e0af9bb7ff7e30d394f43b0d9f18ab',
254
- mintIndex: 0,
255
- value: 1e8,
256
- address: uncompAddy,
257
- script: bitcoreLib.Script.fromAddress(uncompAddy)
258
- }, {
259
- mintTxid: '643ec66d6c4cad4cbdb8ed2166b8078975e0af9bb7ff7e30d394f43b0d9f18ab',
260
- mintIndex: 1,
261
- value: 1e8,
262
- address: compAddy,
263
- script: bitcoreLib.Script.fromAddress(compAddy)
264
- }];
265
- const bitcoreUtxos = utxos.map(utxo => new bitcoreLib.Transaction.UnspentOutput({ txid: utxo.mintTxid, vout: utxo.mintIndex, satoshis: utxo.value, ...utxo }));
266
- tx.from(bitcoreUtxos);
267
- tx.change('mpNpzMoprLnSBu8CWDunNCYeJq3Mzdk59V');
268
- expect(tx.inputs.every(input => input._scriptBuffer?.length === 0)).to.be.true;
269
-
270
- const keys = [{ privKey: uncompPk, address: uncompAddy.toString() }, { privKey: compPk, address: compAddy.toString() }];
271
- const signed = Transactions.sign({ chain: 'BTC', tx: tx.uncheckedSerialize(), utxos, keys });
272
- const signedTx = new bitcoreLib.Transaction(signed);
273
- expect(signedTx.inputs.every(input => input._scriptBuffer?.length > 0)).to.be.true;
274
- });
275
-
276
- it.skip('should fail to get signatures on a BTC txs', () => {
277
- // TODO !!
278
- });
279
-
280
- it('should be able to create a livenet ETH tx', () => {
281
- const rawEthTx = {
282
- network: 'livenet',
283
- value: 3896000000000000,
284
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
285
- data:
286
- '0xb6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
287
- gasPrice: 20000000000
288
- };
289
- const { value, to } = rawEthTx;
290
- const recipients = [{ address: to, amount: value }];
291
- const cryptoTx = Transactions.create({
292
- ...rawEthTx,
293
- chain: 'ETH',
294
- recipients,
295
- nonce: 0
296
- });
297
- const expectedTx =
298
- '0xf9014f808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000018080';
299
- expect(cryptoTx).to.equal(expectedTx);
300
- });
301
-
302
- it('should be able to create a livenet ETH type 1 tx', () => {
303
- const rawEthTx = {
304
- network: 'livenet',
305
- value: 3896000000000000,
306
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
307
- data:
308
- '0xb6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
309
- gasPrice: 20000000000
310
- };
311
- const { value, to } = rawEthTx;
312
- const recipients = [{ address: to, amount: value }];
313
- const cryptoTx = Transactions.create({
314
- ...rawEthTx,
315
- chain: 'ETH',
316
- recipients,
317
- nonce: 0,
318
- txType: 1
319
- });
320
- const expectedTx =
321
- '0x01f9014e01808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000c0';
322
- expect(cryptoTx).to.equal(expectedTx);
323
- });
324
-
325
- it('should be able to create a livenet ETH type 2 tx', () => {
326
- const rawEthTx = {
327
- network: 'livenet',
328
- value: 3896000000000000,
329
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
330
- data:
331
- '0xb6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
332
- maxGasFee: 20000000000
333
- };
334
- const { value, to } = rawEthTx;
335
- const recipients = [{ address: to, amount: value }];
336
- const cryptoTx = Transactions.create({
337
- ...rawEthTx,
338
- chain: 'ETH',
339
- recipients,
340
- nonce: 0
341
- });
342
- const expectedTx =
343
- '0x02f9014f0180018504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000c0';
344
- expect(cryptoTx).to.equal(expectedTx);
345
- });
346
-
347
- it('should be able to create a testnet ETH tx', () => {
348
- const rawEthTx = {
349
- network: 'testnet',
350
- value: 3896000000000000,
351
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
352
- data:
353
- '0xb6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
354
- gasPrice: 20000000000
355
- };
356
- const { value, to } = rawEthTx;
357
- const recipients = [{ address: to, amount: value }];
358
- const cryptoTx = Transactions.create({
359
- ...rawEthTx,
360
- chain: 'ETH',
361
- recipients,
362
- nonce: 0
363
- });
364
- const expectedTx =
365
- '0xf90152808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead14680563000000000000000000000000000000000000000000000000000000000000000083aa36a78080';
366
- expect(cryptoTx).to.equal(expectedTx);
367
- });
368
-
369
- it('should be able to create a testnet ETH type 2 tx', () => {
370
- const rawEthTx = {
371
- network: 'sepolia',
372
- value: 3896000000000000,
373
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
374
- data:
375
- '0xf9014f808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000058080',
376
- maxGasFee: 20000000000
377
- };
378
- const { value, to } = rawEthTx;
379
- const recipients = [{ address: to, amount: value }];
380
- const cryptoTx = Transactions.create({
381
- ...rawEthTx,
382
- chain: 'ETH',
383
- recipients,
384
- nonce: 0
385
- });
386
- const expectedTx =
387
- '0x02f9018083aa36a780018504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90152f9014f808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000058080c0';
388
- expect(cryptoTx).to.equal(expectedTx);
389
- });
390
-
391
- it('should be able to create a sepolia ETH tx', () => {
392
- const rawEthTx = {
393
- network: 'sepolia',
394
- value: 3896000000000000,
395
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
396
- data:
397
- '0xb6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
398
- gasPrice: 20000000000
399
- };
400
- const { value, to } = rawEthTx;
401
- const recipients = [{ address: to, amount: value }];
402
- const cryptoTx = Transactions.create({
403
- ...rawEthTx,
404
- chain: 'ETH',
405
- recipients,
406
- nonce: 0
407
- });
408
- const expectedTx =
409
- '0xf90152808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead14680563000000000000000000000000000000000000000000000000000000000000000083aa36a78080';
410
- expect(cryptoTx).to.equal(expectedTx);
411
- });
412
- it('should be able to create a holesky ETH tx', () => {
413
- const rawEthTx = {
414
- network: 'holesky',
415
- value: 3896000000000000,
416
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
417
- data:
418
- '0xb6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
419
- gasPrice: 20000000000
420
- };
421
- const { value, to } = rawEthTx;
422
- const recipients = [{ address: to, amount: value }];
423
- const cryptoTx = Transactions.create({
424
- ...rawEthTx,
425
- chain: 'ETH',
426
- recipients,
427
- nonce: 0
428
- });
429
- const expectedTx =
430
- '0xf90151808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead1468056300000000000000000000000000000000000000000000000000000000000000008242688080';
431
- expect(cryptoTx).to.equal(expectedTx);
432
- });
433
-
434
- it('should be able to create a livenet ERC20 tx', () => {
435
- const rawEthTx = {
436
- network: 'livenet',
437
- value: 3896000000000000,
438
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
439
- gasPrice: 20000000000,
440
- tokenAddress: '0x692a70d2e424a56d2c6c27aa97d1a86395877b3a'
441
- };
442
- const { value, to } = rawEthTx;
443
- const recipients = [{ address: to, amount: value }];
444
- const cryptoTx = Transactions.create({
445
- ...rawEthTx,
446
- chain: 'ETHERC20',
447
- recipients,
448
- nonce: 0
449
- });
450
- const expectedTx =
451
- '0xf867808504a817c8008094692a70d2e424a56d2c6c27aa97d1a86395877b3a80b844a9059cbb00000000000000000000000037d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a000000000000000000000000000000000000000000000000000dd764300b8000018080';
452
-
453
- expect(cryptoTx).to.equal(expectedTx);
454
- });
455
-
456
- it('should be able to create a livenet ERC20 type 2 tx', () => {
457
- const rawEthTx = {
458
- network: 'livenet',
459
- value: 3896000000000000,
460
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
461
- maxGasFee: 20000000000,
462
- tokenAddress: '0x692a70d2e424a56d2c6c27aa97d1a86395877b3a'
463
- };
464
- const { value, to } = rawEthTx;
465
- const recipients = [{ address: to, amount: value }];
466
- const cryptoTx = Transactions.create({
467
- ...rawEthTx,
468
- chain: 'ETHERC20',
469
- recipients,
470
- nonce: 0
471
- });
472
- const expectedTx =
473
- '0x02f8670180018504a817c8008094692a70d2e424a56d2c6c27aa97d1a86395877b3a80b844a9059cbb00000000000000000000000037d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a000000000000000000000000000000000000000000000000000dd764300b8000c0';
474
-
475
- expect(cryptoTx).to.equal(expectedTx);
476
- });
477
-
478
- it('should be able to create a testnet ERC20 tx', () => {
479
- const rawEthTx = {
480
- network: 'testnet',
481
- value: 3896000000000000,
482
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
483
- gasPrice: 20000000000,
484
- tokenAddress: '0x692a70d2e424a56d2c6c27aa97d1a86395877b3a'
485
- };
486
- const { value, to } = rawEthTx;
487
- const recipients = [{ address: to, amount: value }];
488
- const cryptoTx = Transactions.create({
489
- ...rawEthTx,
490
- chain: 'ETHERC20',
491
- recipients,
492
- nonce: 0
493
- });
494
- const expectedTx =
495
- '0xf86a808504a817c8008094692a70d2e424a56d2c6c27aa97d1a86395877b3a80b844a9059cbb00000000000000000000000037d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a000000000000000000000000000000000000000000000000000dd764300b800083aa36a78080';
496
-
497
- expect(cryptoTx).to.equal(expectedTx);
498
- });
499
-
500
- it('should be able to create a testnet ERC20 type 2 tx', () => {
501
- const rawEthTx = {
502
- network: 'sepolia',
503
- value: 3896000000000000,
504
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
505
- maxGasFee: 20000000000,
506
- tokenAddress: '0x692a70d2e424a56d2c6c27aa97d1a86395877b3a'
507
- };
508
- const { value, to } = rawEthTx;
509
- const recipients = [{ address: to, amount: value }];
510
- const cryptoTx = Transactions.create({
511
- ...rawEthTx,
512
- chain: 'ETHERC20',
513
- recipients,
514
- nonce: 0
515
- });
516
- const expectedTx =
517
- '0x02f86a83aa36a780018504a817c8008094692a70d2e424a56d2c6c27aa97d1a86395877b3a80b844a9059cbb00000000000000000000000037d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a000000000000000000000000000000000000000000000000000dd764300b8000c0';
518
-
519
- expect(cryptoTx).to.equal(expectedTx);
520
- });
521
-
522
- it('should be able to create a sepolia ERC20 tx', () => {
523
- const rawEthTx = {
524
- network: 'sepolia',
525
- value: 3896000000000000,
526
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
527
- gasPrice: 20000000000,
528
- tokenAddress: '0x692a70d2e424a56d2c6c27aa97d1a86395877b3a'
529
- };
530
- const { value, to } = rawEthTx;
531
- const recipients = [{ address: to, amount: value }];
532
- const cryptoTx = Transactions.create({
533
- ...rawEthTx,
534
- chain: 'ETHERC20',
535
- recipients,
536
- nonce: 0
537
- });
538
- const expectedTx =
539
- '0xf86a808504a817c8008094692a70d2e424a56d2c6c27aa97d1a86395877b3a80b844a9059cbb00000000000000000000000037d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a000000000000000000000000000000000000000000000000000dd764300b800083aa36a78080';
540
-
541
- expect(cryptoTx).to.equal(expectedTx);
542
- });
543
-
544
- it('should be able to create a holesky ERC20 tx', () => {
545
- const rawEthTx = {
546
- network: 'holesky',
547
- value: 3896000000000000,
548
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
549
- gasPrice: 20000000000,
550
- tokenAddress: '0x692a70d2e424a56d2c6c27aa97d1a86395877b3a'
551
- };
552
- const { value, to } = rawEthTx;
553
- const recipients = [{ address: to, amount: value }];
554
- const cryptoTx = Transactions.create({
555
- ...rawEthTx,
556
- chain: 'ETHERC20',
557
- recipients,
558
- nonce: 0
559
- });
560
- const expectedTx =
561
- '0xf869808504a817c8008094692a70d2e424a56d2c6c27aa97d1a86395877b3a80b844a9059cbb00000000000000000000000037d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a000000000000000000000000000000000000000000000000000dd764300b80008242688080';
562
-
563
- expect(cryptoTx).to.equal(expectedTx);
564
- });
565
-
566
- it('should be able to create a livenet MATIC tx', () => {
567
- const rawMaticTx = {
568
- network: 'livenet',
569
- value: 3896000000000000,
570
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
571
- data:
572
- '0xb6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
573
- gasPrice: 20000000000
574
- };
575
- const { value, to } = rawMaticTx;
576
- const recipients = [{ address: to, amount: value }];
577
- const cryptoTx = Transactions.create({
578
- ...rawMaticTx,
579
- chain: 'MATIC',
580
- recipients,
581
- nonce: 0
582
- });
583
- const expectedTx =
584
- '0xf90150808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead14680563000000000000000000000000000000000000000000000000000000000000000081898080';
585
- expect(cryptoTx).to.equal(expectedTx);
586
- });
587
-
588
- it('should be able to create a livenet MATIC tx an amount in scientific notation', () => {
589
- const rawMaticTx = {
590
- network: 'livenet',
591
- value: 4.279756e+21,
592
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
593
- data:
594
- '0xb6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
595
- gasPrice: 20000000000
596
- };
597
- const { value, to } = rawMaticTx;
598
- const recipients = [{ address: to, amount: value }];
599
- const cryptoTx = Transactions.create({
600
- ...rawMaticTx,
601
- chain: 'MATIC',
602
- recipients,
603
- nonce: 0
604
- });
605
- const expectedTx =
606
- '0xf90152808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a89e8018baee182ae0000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead14680563000000000000000000000000000000000000000000000000000000000000000081898080';
607
- expect(cryptoTx).to.equal(expectedTx);
608
- });
609
-
610
- it('should be able to create a livenet MATIC type 2 tx', () => {
611
- const rawMaticTx = {
612
- network: 'livenet',
613
- value: 3896000000000000,
614
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
615
- data:
616
- '0xb6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
617
- maxGasFee: 30000000000
618
- };
619
- const { value, to } = rawMaticTx;
620
- const recipients = [{ address: to, amount: value }];
621
- const cryptoTx = Transactions.create({
622
- ...rawMaticTx,
623
- chain: 'MATIC',
624
- recipients,
625
- nonce: 0
626
- });
627
- const expectedTx =
628
- '0x02f901558189808506fc23ac008506fc23ac00809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000c0';
629
- expect(cryptoTx).to.equal(expectedTx);
630
- });
631
-
632
- it('should be able to create a testnet MATIC tx', () => {
633
- const rawMaticTx = {
634
- network: 'testnet',
635
- value: 3896000000000000,
636
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
637
- data:
638
- '0xb6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
639
- gasPrice: 20000000000
640
- };
641
- const { value, to } = rawMaticTx;
642
- const recipients = [{ address: to, amount: value }];
643
- const cryptoTx = Transactions.create({
644
- ...rawMaticTx,
645
- chain: 'MATIC',
646
- recipients,
647
- nonce: 0
648
- });
649
- const expectedTx =
650
- '0xf90152808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000830138828080';
651
- expect(cryptoTx).to.equal(expectedTx);
652
- });
653
-
654
- it('should be able to create a testnet MATIC type 2 tx', () => {
655
- const rawMaticTx = {
656
- network: 'testnet',
657
- value: 3896000000000000,
658
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
659
- data:
660
- '0xb6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
661
- maxGasPrice: 20000000000
662
- };
663
- const { value, to } = rawMaticTx;
664
- const recipients = [{ address: to, amount: value }];
665
- const cryptoTx = Transactions.create({
666
- ...rawMaticTx,
667
- chain: 'MATIC',
668
- recipients,
669
- nonce: 0
670
- });
671
- const expectedTx =
672
- '0xf9014d8080809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000830138828080';
673
- expect(cryptoTx).to.equal(expectedTx);
674
- });
675
-
676
- it('should be able to create a mumbai MATIC tx', () => {
677
- const rawMaticTx = {
678
- network: 'mumbai',
679
- value: 3896000000000000,
680
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
681
- data:
682
- '0xb6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
683
- gasPrice: 20000000000
684
- };
685
- const { value, to } = rawMaticTx;
686
- const recipients = [{ address: to, amount: value }];
687
- const cryptoTx = Transactions.create({
688
- ...rawMaticTx,
689
- chain: 'MATIC',
690
- recipients,
691
- nonce: 0
692
- });
693
- const expectedTx =
694
- '0xf90152808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000830138818080';
695
- expect(cryptoTx).to.equal(expectedTx);
696
- });
697
-
698
- it('should be able to create a mumbai MATIC type 2 tx', () => {
699
- const rawMaticTx = {
700
- network: 'mumbai',
701
- value: 3896000000000000,
702
- to: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A',
703
- data:
704
- '0xb6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
705
- maxGasFee: 30000000000
706
- };
707
- const { value, to } = rawMaticTx;
708
- const recipients = [{ address: to, amount: value }];
709
- const cryptoTx = Transactions.create({
710
- ...rawMaticTx,
711
- chain: 'MATIC',
712
- recipients,
713
- nonce: 0
714
- });
715
- const expectedTx =
716
- '0x02f9015783013881808506fc23ac008506fc23ac00809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000c0';
717
- expect(cryptoTx).to.equal(expectedTx);
718
- });
719
-
720
- it('should be able to encode Data in ERC20 tx', () => {
721
- const recipients = [{ address: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A', amount: 3896000000000000 }];
722
- const tokenAddress = '0x692a70d2e424a56d2c6c27aa97d1a86395877b3a';
723
- const data = Transactions.get({ chain: 'ETHERC20' }).encodeData({ recipients, tokenAddress });
724
- const expectedData =
725
- '0xa9059cbb00000000000000000000000037d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a000000000000000000000000000000000000000000000000000dd764300b8000';
726
-
727
- expect(data).to.equal(expectedData);
728
- });
729
-
730
- it('should be able to send ETH to multiple using multisend contract', () => {
731
- const wallet = {
732
- address: '0xb4b9be3062b6dB6eDa78fa4b5EA80595Cfa7E655',
733
- privateKey: '0x733d4cddb30d33f324def2bb80c6a844f7ba342a60bed06d838afb6b37ab1972',
734
- index: 0
735
- };
736
- const rawEthTx = {
737
- value: '3896000000000000',
738
- to: '0xf514e00E20373f6366C9AF966fF5F8be587595E9',
739
- };
740
- const rawEthTx2 = {
741
- value: 20407919369583210,
742
- to: '0x3428F3Eb7df7D4a16f9e4A5098574Cea2CFBbdc6',
743
- };
744
- const recipients = [{ address: rawEthTx.to, amount: rawEthTx.value }, { address: rawEthTx2.to, amount: rawEthTx2.value }];
745
- const cryptoTx = Transactions.create({
746
- network: 'testnet',
747
- chain: 'ETH',
748
- recipients,
749
- nonce: 3,
750
- contractAddress: '0x44dfceb88f24c738d8ae9b7d4bb898cbca06db0e',
751
- gasPrice: 1000000008,
752
- gasLimit: 71994
753
- });
754
- const expectedTx =
755
- '0xf9013403843b9aca088301193a9444dfceb88f24c738d8ae9b7d4bb898cbca06db0e8756584930ac7a6ab9010425245b26000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000f514e00e20373f6366c9af966ff5f8be587595e90000000000000000000000003428f3eb7df7d4a16f9e4a5098574cea2cfbbdc60000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000dd764300b8000000000000000000000000000000000000000000000000000004880e500a0fa6a83aa36a78080';
756
- expect(cryptoTx).to.equal(expectedTx);
757
-
758
- const signedTx = Transactions.sign({ chain: 'ETH', tx: cryptoTx, key: { address: wallet.address, privKey: wallet.privateKey } });
759
- const expectedSignedTx =
760
- '0xf9017503843b9aca088301193a9444dfceb88f24c738d8ae9b7d4bb898cbca06db0e8756584930ac7a6ab9010425245b26000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000f514e00e20373f6366c9af966ff5f8be587595e90000000000000000000000003428f3eb7df7d4a16f9e4a5098574cea2cfbbdc60000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000dd764300b8000000000000000000000000000000000000000000000000000004880e500a0fa6a8401546d71a0f9e7f0a170d7f145899042c938e7f0eb4ecdbdc0a5453b6524fcc2b9aea427b2a01477ff7e9379952b26237bead1e7835eef0e5768673c9da4ca7410cd7b57e8c4';
761
- expect(expectedSignedTx).to.equal(signedTx);
762
- });
763
-
764
- it('should be able to send ERC20 to multiple using multisend contract', () => {
765
- const wallet = {
766
- address: '0xb4b9be3062b6dB6eDa78fa4b5EA80595Cfa7E655',
767
- privateKey: '0x733d4cddb30d33f324def2bb80c6a844f7ba342a60bed06d838afb6b37ab1972',
768
- index: 0
769
- };
770
- const rawEthTx = {
771
- value: '3823',
772
- to: '0xf514e00E20373f6366C9AF966fF5F8be587595E9'
773
- };
774
- const rawEthTx2 = {
775
- value: '900',
776
- to: '0x3428F3Eb7df7D4a16f9e4A5098574Cea2CFBbdc6'
777
- };
778
- const recipients = [{ address: rawEthTx.to, amount: rawEthTx.value }, { address: rawEthTx2.to, amount: rawEthTx2.value }];
779
- const cryptoTx = Transactions.create({
780
- network: 'sepolia',
781
- chain: 'ETHERC20',
782
- recipients,
783
- nonce: 48,
784
- gasPrice: 1806667388,
785
- gasLimit: 56209,
786
- contractAddress: '0x328cab2bd398a6e577d8ab1d0ae0b969fd70969c',
787
- tokenAddress: '0x75c87615ffc0bb34a24ed4ac62c26a1d8ea75336'
788
- });
789
- const expectedTx =
790
- '0xf9014c30846baf8e7c82db9194328cab2bd398a6e577d8ab1d0ae0b969fd70969c80b90124aee2561300000000000000000000000075c87615ffc0bb34a24ed4ac62c26a1d8ea75336000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000f514e00e20373f6366c9af966ff5f8be587595e90000000000000000000000003428f3eb7df7d4a16f9e4a5098574cea2cfbbdc600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000eef000000000000000000000000000000000000000000000000000000000000038483aa36a78080';
791
- expect(cryptoTx).to.equal(expectedTx);
792
-
793
- const signedTx = Transactions.sign({ chain: 'ETHERC20', tx: cryptoTx, key: { address: wallet.address, privKey: wallet.privateKey } });
794
- const expectedSignedTx =
795
- '0xf9018d30846baf8e7c82db9194328cab2bd398a6e577d8ab1d0ae0b969fd70969c80b90124aee2561300000000000000000000000075c87615ffc0bb34a24ed4ac62c26a1d8ea75336000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000f514e00e20373f6366c9af966ff5f8be587595e90000000000000000000000003428f3eb7df7d4a16f9e4a5098574cea2cfbbdc600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000eef00000000000000000000000000000000000000000000000000000000000003848401546d71a0fb3b5eb6c629245291d729b2f9150ad4a61fe5f040b4eac84510cb1da7bccf0ca068af98a86fcb1184851bbf51667b37777a4d6049d1ca5cc9521691cda42cc75f';
796
- expect(expectedSignedTx).to.equal(signedTx);
797
- });
798
-
799
- it('should be able to send MATIC to multiple using multisend contract', () => {
800
- const wallet = {
801
- address: '0xb4b9be3062b6dB6eDa78fa4b5EA80595Cfa7E655',
802
- privateKey: '0x733d4cddb30d33f324def2bb80c6a844f7ba342a60bed06d838afb6b37ab1972',
803
- index: 0
804
- };
805
- const rawMaticTx = {
806
- value: BigInt(3896000000000000),
807
- to: '0xf514e00E20373f6366C9AF966fF5F8be587595E9',
808
- };
809
- const rawMaticTx2 = {
810
- value: 20407919369583210,
811
- to: '0x3428F3Eb7df7D4a16f9e4A5098574Cea2CFBbdc6',
812
- };
813
- const recipients = [{ address: rawMaticTx.to, amount: rawMaticTx.value }, { address: rawMaticTx2.to, amount: rawMaticTx2.value }];
814
- const cryptoTx = Transactions.create({
815
- network: 'testnet',
816
- chain: 'MATIC',
817
- recipients,
818
- nonce: 3,
819
- contractAddress: '0x44dfceb88f24c738d8ae9b7d4bb898cbca06db0e',
820
- gasPrice: 1000000008,
821
- gasLimit: 71994
822
- });
823
- const expectedTx = '0xf9013403843b9aca088301193a9444dfceb88f24c738d8ae9b7d4bb898cbca06db0e8756584930ac7a6ab9010425245b26000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000f514e00e20373f6366c9af966ff5f8be587595e90000000000000000000000003428f3eb7df7d4a16f9e4a5098574cea2cfbbdc60000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000dd764300b8000000000000000000000000000000000000000000000000000004880e500a0fa6a830138828080';
824
- expect(cryptoTx).to.equal(expectedTx);
825
-
826
- const signedTx = Transactions.sign({ chain: 'MATIC', tx: cryptoTx, key: { address: wallet.address, privKey: wallet.privateKey } });
827
- const expectedSignedTx =
828
- '0xf9017403843b9aca088301193a9444dfceb88f24c738d8ae9b7d4bb898cbca06db0e8756584930ac7a6ab9010425245b26000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000f514e00e20373f6366c9af966ff5f8be587595e90000000000000000000000003428f3eb7df7d4a16f9e4a5098574cea2cfbbdc60000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000dd764300b8000000000000000000000000000000000000000000000000000004880e500a0fa6a83027127a007e38abe47de10fc653ed198900e219f3d2e1b8ecad05c442fbd4d37ce2dad4fa027506463182caadd2728cba17ffcd3adb67b9043397480d39f1d3a2740692c8f';
829
- expect(expectedSignedTx).to.equal(signedTx);
830
- });
831
-
832
- it('should be able to create a XRP tx', () => {
833
- const recipients = [{ address: 'rEqj9WKSH7wEkPvWf6b4gCi26Y3F7HbKUF', amount: '123456' }];
834
- const xrpParams = {
835
- chain: 'XRP',
836
- recipients,
837
- from: 'rEqj9WKSH7wEkPvWf6b4gCi26Y3F7HbKUF',
838
- tag: 123456,
839
- fee: 12,
840
- nonce: 1,
841
- invoiceID: '1012345678901234567890123456710123456789012345678901567890123456'
842
- };
843
- const cryptoTx = Transactions.create(xrpParams);
844
- const expectedTx =
845
- '120000228000000024000000012E0001E2405011101234567890123456789012345671012345678901234567890156789012345661400000000001E24068400000000000000C8114A2C8E8CD9A9133CAD90F2668159AAF572612A5028314A2C8E8CD9A9133CAD90F2668159AAF572612A502';
846
- expect(xrpParams.invoiceID.length).to.equal(64);
847
- expect(cryptoTx).to.equal(expectedTx);
848
- });
849
-
850
- it('should fail to create a XRP tx with invalid invoiceID', () => {
851
- try {
852
- const recipients = [{ address: 'rEqj9WKSH7wEkPvWf6b4gCi26Y3F7HbKUF', amount: '123456' }];
853
- const xrpParams = {
854
- chain: 'XRP',
855
- recipients,
856
- from: 'rEqj9WKSH7wEkPvWf6b4gCi26Y3F7HbKUF',
857
- tag: 123456,
858
- fee: 12,
859
- nonce: 1,
860
- invoiceID: '78901234567890123456710123456789012345678901567890123456'
861
- };
862
- Transactions.create(xrpParams);
863
- } catch (err) {
864
- expect(err).to.exist;
865
- expect(err.message).to.equal('Invalid Hash length 28');
866
- }
867
- });
868
-
869
- it('should fail to create a XRP tx with invalid address', () => {
870
- try {
871
- const recipients = [{ address: 'rEqj9WKSH7wEkPvWf6b4gCi26Y3F7HbKUF', amount: '123456' }];
872
- const xrpParams = {
873
- chain: 'XRP',
874
- recipients,
875
- from: 'rEqj9WKSH7wEkPvWf6b4gCF',
876
- tag: 123456,
877
- fee: 12,
878
- nonce: 1,
879
- invoiceID: '1012345678901234567890123456710123456789012345678901567890123456'
880
- };
881
- Transactions.create(xrpParams);
882
- } catch (err) {
883
- expect(err).to.exist;
884
- expect(err.message).to.equal('checksum_invalid');
885
- }
886
- });
887
-
888
- it('should create an AccountSet tx with string flag', () => {
889
- const xrpParams = {
890
- chain: 'XRP',
891
- network: 'testnet',
892
- from: 'rMmUqMZRzKKnzrTnN3B6Zcz4qQQvmHowt8',
893
- fee: 10,
894
- nonce: 11876358,
895
- txType: 'accountset',
896
- flags: 'tfRequireDestTag'
897
- };
898
- const cryptoTx = Transactions.create(xrpParams);
899
- const expectedTx = '12000322000100002400B5380668400000000000000A8114E3BEB23E9931CEE681B8CBFDA2F9203EFC18C5BA';
900
- expect(cryptoTx).to.equal(expectedTx);
901
- });
902
-
903
- it('should create an AccountSet tx with comma-delimited string flags', () => {
904
- const xrpParams = {
905
- chain: 'XRP',
906
- network: 'testnet',
907
- from: 'rMmUqMZRzKKnzrTnN3B6Zcz4qQQvmHowt8',
908
- fee: 10,
909
- nonce: 11876358,
910
- txType: 'accountset',
911
- flags: 'tfRequireDestTag,tfDisallowXRP'
912
- };
913
- const cryptoTx = Transactions.create(xrpParams);
914
- const expectedTx = '12000322001100002400B5380668400000000000000A8114E3BEB23E9931CEE681B8CBFDA2F9203EFC18C5BA';
915
- expect(cryptoTx).to.equal(expectedTx);
916
- });
917
-
918
- it('should create an AccountSet tx with number flag', () => {
919
- const xrpParams = {
920
- chain: 'XRP',
921
- network: 'testnet',
922
- from: 'rMmUqMZRzKKnzrTnN3B6Zcz4qQQvmHowt8',
923
- fee: 10,
924
- nonce: 11876358,
925
- txType: 'accountset',
926
- flags: 65536 // tfRequireDestTag
927
- };
928
- const cryptoTx = Transactions.create(xrpParams);
929
- const expectedTx = '12000322000100002400B5380668400000000000000A8114E3BEB23E9931CEE681B8CBFDA2F9203EFC18C5BA';
930
- expect(cryptoTx).to.equal(expectedTx);
931
- });
932
-
933
- it('should throw on invalid flag(s)', () => {
934
- const xrpParams = {
935
- chain: 'XRP',
936
- network: 'testnet',
937
- from: 'rMmUqMZRzKKnzrTnN3B6Zcz4qQQvmHowt8',
938
- fee: 10,
939
- nonce: 11876358,
940
- txType: 'accountset'
941
- };
942
- expect(() => Transactions.create({ ...xrpParams, flags: undefined })).to.throw('No XRP flag(s) provided');
943
- expect(() => Transactions.create({ ...xrpParams, flags: null })).to.throw('No XRP flag(s) provided');
944
- expect(() => Transactions.create({ ...xrpParams, flags: 'tfInvalidFlag' })).to.throw('Invalid XRP flag: tfInvalidFlag');
945
- expect(() => Transactions.create({ ...xrpParams, flags: 'tfRequireDestTag,tfInvalidFlag' })).to.throw('Invalid XRP flag: tfInvalidFlag');
946
- });
947
-
948
- it('should create a DOGE tx', () => {
949
- const recipients = [{ address: 'mpNpzMoprLnSBu8CWDunNCYeJq3Mzdk59V', amount: 1e8 }];
950
- const change = 'msnAsQcCdtzDyiSWb4ZnNxFwUy3P9ogQvY';
951
- const utxos = [
952
- {
953
- mintTxid: '643ec66d6c4cad4cbdb8ed2166b8078975e0af9bb7ff7e30d394f43b0d9f18ab',
954
- mintIndex: 1,
955
- value: 0.02503422 * 1e8,
956
- script: '76a91457884dcfe2ab46d3354a42d97333c95e5b80cf0188ac',
957
- address: 'moVnNJpHHfssYJEnMTS5xXyGV8RhRQNRz5',
958
- sequenceNumber: 4294967294
959
- },
960
- {
961
- mintTxid: '643ec66d6c4cad4cbdb8ed2166b8078975e0af9bb7ff7e30d394f43b0d9f18ab',
962
- mintIndex: 0,
963
- value: 1e8,
964
- script: '76a9144e744a19a009a9dd43a23a7c12045c83e82ac9d288ac',
965
- address: 'mnfnJx2xWWptYmBzck3rdE851Dtu9GaZ3F',
966
- sequenceNumber: 4294967294
967
- }
968
- ];
969
- const fee = 7440;
970
- const tx = Transactions.create({ chain: 'DOGE', recipients, change, utxos, fee, rbf: true });
971
-
972
- const keys = [
973
- {
974
- address: 'mnfnJx2xWWptYmBzck3rdE851Dtu9GaZ3F',
975
- privKey: 'cSFjiifSbZ2hU4jTFwE993LCe2rkZGULCTGWTDWXzHvuXRKxpnc1'
976
- },
977
- { address: 'moVnNJpHHfssYJEnMTS5xXyGV8RhRQNRz5', privKey: 'cUWVirwp5vh1D6WWbYci3tuGniyf28ERpgU4uL5VSiFDfvNEhJqy' }
978
- ];
979
- const signed = Transactions.sign({ chain: 'DOGE', tx, keys, utxos });
980
- const expected =
981
- '0100000002ab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e64010000006b483045022100b4fb37f92fb4ec7007166c415d59d888c9526b4550e3ed111e615cfe0e63ba9a022003381d0c43cf3e0762926f4fdff05a2d16fc0e62d59d79a9ca69646d1595b887012102c8f8fa438666cbd287e28fb384b99555e4acce610e8141e887c9c458bba5db5cffffffffab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e64000000006a47304402207b4a0deed6371e8ad46bcae7a9a098d99f2210d44600bab72bccba747ef7554c02207678fb99e91275c4fc7d5665371fb935cb789b4e0ad5a880780513368cca8b4b01210321f2f13aed42db7257b64f77d574071a6e81e460ab3693eefb7482c12d1ff697ffffffff0200e1f505000000001976a914612fb4d5e27a28f5c54018d8948ca3a650741c4188acee152600000000001976a91486823ef7c8e210184cc8675189d37c4c9d8e1e0288ac00000000';
982
- expect(signed).to.eq(expected);
983
- });
984
-
985
- it('should create a LTC tx', () => {
986
- const recipients = [{ address: 'mpNpzMoprLnSBu8CWDunNCYeJq3Mzdk59V', amount: 1e8 }];
987
- const change = 'msnAsQcCdtzDyiSWb4ZnNxFwUy3P9ogQvY';
988
- const utxos = [
989
- {
990
- mintTxid: '643ec66d6c4cad4cbdb8ed2166b8078975e0af9bb7ff7e30d394f43b0d9f18ab',
991
- mintIndex: 1,
992
- value: 0.02503422 * 1e8,
993
- script: '76a91457884dcfe2ab46d3354a42d97333c95e5b80cf0188ac',
994
- address: 'moVnNJpHHfssYJEnMTS5xXyGV8RhRQNRz5',
995
- sequenceNumber: 4294967294
996
- },
997
- {
998
- mintTxid: '643ec66d6c4cad4cbdb8ed2166b8078975e0af9bb7ff7e30d394f43b0d9f18ab',
999
- mintIndex: 0,
1000
- value: 1e8,
1001
- script: '76a9144e744a19a009a9dd43a23a7c12045c83e82ac9d288ac',
1002
- address: 'mnfnJx2xWWptYmBzck3rdE851Dtu9GaZ3F',
1003
- sequenceNumber: 4294967294
1004
- }
1005
- ];
1006
- const fee = 7440;
1007
- const tx = Transactions.create({ chain: 'LTC', recipients, change, utxos, fee, rbf: true });
1008
-
1009
- const keys = [
1010
- {
1011
- address: 'mnfnJx2xWWptYmBzck3rdE851Dtu9GaZ3F',
1012
- privKey: 'cSFjiifSbZ2hU4jTFwE993LCe2rkZGULCTGWTDWXzHvuXRKxpnc1'
1013
- },
1014
- { address: 'moVnNJpHHfssYJEnMTS5xXyGV8RhRQNRz5', privKey: 'cUWVirwp5vh1D6WWbYci3tuGniyf28ERpgU4uL5VSiFDfvNEhJqy' }
1015
- ];
1016
- const signed = Transactions.sign({ chain: 'LTC', tx, keys, utxos });
1017
- const expected =
1018
- '0200000002ab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e64010000006a47304402202eeb967801c0aad4f8241d8f90e2a9e2236f95c189165ba6b2ba4dc6b17bacbe02201b5d4dc0c32f6aa134d93698f85bf4c098d15fcbaada0b6ca2b8076fd8aa2741012102c8f8fa438666cbd287e28fb384b99555e4acce610e8141e887c9c458bba5db5cffffffffab189f0d3bf494d3307effb79bafe0758907b86621edb8bd4cad4c6c6dc63e64000000006a473044022072bdde2c0b413fc42d15d93e768a26f818dc5b225b9359235c09fd0452d6121a022007c00afa396d60d5b7919f2ba31e638817561cab4e2afed7a86dd636ee293c1001210321f2f13aed42db7257b64f77d574071a6e81e460ab3693eefb7482c12d1ff697ffffffff0200e1f505000000001976a914612fb4d5e27a28f5c54018d8948ca3a650741c4188acee152600000000001976a91486823ef7c8e210184cc8675189d37c4c9d8e1e0288ac00000000';
1019
- expect(signed).to.eq(expected);
1020
- });
1021
-
1022
- it('should be able to create a livenet SOL tx', () => {
1023
- const rawMaticTx = {
1024
- network: 'livenet',
1025
- value: 3896000000000000,
1026
- to: 'F7FknkRckx4yvA3Gexnx1H3nwPxndMxVt58BwAzEQhcY',
1027
- from: '8WyoNvKsmfdG6zrbzNBVN8DETyLra3ond61saU9C52YR',
1028
- category: 'transfer',
1029
- blockHash: 'GtV1Hb3FvP3HURHAsj8mGwEqCumvP3pv3i6CVCzYNj3d',
1030
- blockHeight: 531575,
1031
- };
1032
- const { value, to } = rawMaticTx;
1033
- const recipients = [{ address: to, amount: value }];
1034
- const cryptoTx = Transactions.create({
1035
- ...rawMaticTx,
1036
- chain: 'SOL',
1037
- recipients,
1038
- });
1039
- const expectedTx =
1040
- 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDb6/gH5XxrVl86CZd+DpqA1jN8YSz91e8yXxOlyeS8tLRnckLdZVIkhi0iAExccvYpTw5tIfPZ8z/OJGQtnvg9QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA7A+XJrI4siFXUreDo+M94DBeuJwm0Oq5kHqeWuAw7xgBAgIAAQwCAAAAAIALMGTXDQA=';
1041
- expect(cryptoTx).to.equal(expectedTx);
1042
- });
1043
-
1044
-
1045
- });
1046
-
1047
- describe('getMutableFields', () => {
1048
- it('recovers the SOL recent blockhash only (not blockHeight)', () => {
1049
- const blockHash = 'GtV1Hb3FvP3HURHAsj8mGwEqCumvP3pv3i6CVCzYNj3d';
1050
- const raw = Transactions.create({
1051
- chain: 'SOL',
1052
- category: 'transfer',
1053
- from: '8WyoNvKsmfdG6zrbzNBVN8DETyLra3ond61saU9C52YR',
1054
- recipients: [{ address: 'F7FknkRckx4yvA3Gexnx1H3nwPxndMxVt58BwAzEQhcY', amount: 3896000000000000 }],
1055
- blockHash,
1056
- blockHeight: 531575
1057
- });
1058
- const fields = (Transactions.get({ chain: 'SOL' }) as any).getMutableFields(raw);
1059
- expect(fields).to.deep.equal({ blockHash });
1060
- });
1061
-
1062
- it('recovers the EVM nonce', () => {
1063
- const raw = Transactions.create({
1064
- chain: 'ETH',
1065
- network: 'livenet',
1066
- recipients: [{ address: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A', amount: 1000 }],
1067
- nonce: 7,
1068
- gasLimit: 21000,
1069
- gasPrice: 20000000000,
1070
- data: '0x'
1071
- });
1072
- const fields = (Transactions.get({ chain: 'ETH' }) as any).getMutableFields(raw);
1073
- expect(fields).to.deep.equal({ nonce: 7 });
1074
- });
1075
-
1076
- it('recovers the XRP sequence (nonce)', () => {
1077
- const raw = Transactions.create({
1078
- chain: 'XRP',
1079
- recipients: [{ address: 'rEqj9WKSH7wEkPvWf6b4gCi26Y3F7HbKUF', amount: '123456' }],
1080
- from: 'rEqj9WKSH7wEkPvWf6b4gCi26Y3F7HbKUF',
1081
- fee: 12,
1082
- nonce: 4
1083
- });
1084
- const fields = (Transactions.get({ chain: 'XRP' }) as any).getMutableFields(raw);
1085
- expect(fields).to.deep.equal({ nonce: 4 });
1086
- });
1087
- });
1088
-
1089
- describe('sign', () => {
1090
- it('should sign an ETH tx', () => {
1091
- const signedTx = Transactions.sign({
1092
- chain: 'ETH',
1093
- tx:
1094
- '0xf9014c808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
1095
- key: {
1096
- privKey: '0x29a1271a8214ccf499b99070115adc43539d4e086b5babab57c4c7a88f959cc2'
1097
- }
1098
- });
1099
- const expectedSignedTx =
1100
- '0xf9018f808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead1468056300000000000000000000000000000000000000000000000000000000000000001ba0db427c4dddcfc816581d657d9f30f8287bdebd9b9cbabc7a535fc67cde9f2b3da02eafc2d79ef47fe045c47f08af54736caf797c27f2e25266d6320243104834f7';
1101
- expect(signedTx).to.equal(expectedSignedTx);
1102
- });
1103
-
1104
- it('should sign an MATIC tx', () => {
1105
- const signedTx = Transactions.sign({
1106
- chain: 'MATIC',
1107
- tx:
1108
- '0xf9014c808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
1109
- key: {
1110
- privKey: '0x29a1271a8214ccf499b99070115adc43539d4e086b5babab57c4c7a88f959cc2'
1111
- }
1112
- });
1113
- const expectedSignedTx =
1114
- '0xf9018f808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead1468056300000000000000000000000000000000000000000000000000000000000000001ba0db427c4dddcfc816581d657d9f30f8287bdebd9b9cbabc7a535fc67cde9f2b3da02eafc2d79ef47fe045c47f08af54736caf797c27f2e25266d6320243104834f7';
1115
- expect(signedTx).to.equal(expectedSignedTx);
1116
- });
1117
-
1118
- it('should sign a XRP tx', () => {
1119
- const signedTx = Transactions.sign({
1120
- chain: 'XRP',
1121
- tx:
1122
- '120000228000000024000000012E0001E2405011101234567890123456789012345671012345678901234567890156789012345661400000000001E24068400000000000000C8114A2C8E8CD9A9133CAD90F2668159AAF572612A5028314A2C8E8CD9A9133CAD90F2668159AAF572612A502',
1123
- key: {
1124
- privKey: 'D02C6801D8F328FF2EAD51D01F9580AF36C8D74E2BD463963AC4ADBE51AE5F2C',
1125
- pubKey: '03DBEEC5E9E76DA09C5B502A67136BC2D73423E8902A7C35A8CBC0C5A6AC0469E8'
1126
- }
1127
- });
1128
- const expectedSignedTx =
1129
- '120000228000000024000000012E0001E2405011101234567890123456789012345671012345678901234567890156789012345661400000000001E24068400000000000000C732103DBEEC5E9E76DA09C5B502A67136BC2D73423E8902A7C35A8CBC0C5A6AC0469E874473045022100D5C19360E77D691A11CA693F6E8D8472DA6749D16A06E072ED1110EB3FD9E2C80220169F95E55943C3575CEAA46413FE660E4F8F2E7158FAC235DC3CB9C9F26918098114A2C8E8CD9A9133CAD90F2668159AAF572612A5028314A2C8E8CD9A9133CAD90F2668159AAF572612A502';
1130
- expect(signedTx).to.equal(expectedSignedTx);
1131
- });
1132
-
1133
- it('should sign a SOL tx', async () => {
1134
- const signedTx = await Transactions.sign({
1135
- chain: 'SOL',
1136
- tx:
1137
- 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDb6/gH5XxrVl86CZd+DpqA1jN8YSz91e8yXxOlyeS8tLRnckLdZVIkhi0iAExccvYpTw5tIfPZ8z/OJGQtnvg9QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA7A+XJrI4siFXUreDo+M94DBeuJwm0Oq5kHqeWuAw7xgBAgIAAQwCAAAAAIALMGTXDQA=',
1138
- key: {
1139
- privKey: '2L4P42HQHDGBCvMpbtL1D5SQL5NJXqcz3pWNYSN8rjUP',
1140
- pubKey: '8WyoNvKsmfdG6zrbzNBVN8DETyLra3ond61saU9C52YR'
1141
- }
1142
- });
1143
- const expectedSignedTx =
1144
- 'AQe68soLnMZOcMIGS3G8SL2L3Maee5wfkL5dw9ixDXKxD+uPteddRItdR3G3qIkOnfZKQ6LaUufTMQioJblEZAIBAAEDb6/gH5XxrVl86CZd+DpqA1jN8YSz91e8yXxOlyeS8tLRnckLdZVIkhi0iAExccvYpTw5tIfPZ8z/OJGQtnvg9QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA7A+XJrI4siFXUreDo+M94DBeuJwm0Oq5kHqeWuAw7xgBAgIAAQwCAAAAAIALMGTXDQA=';
1145
- expect(signedTx).to.equal(expectedSignedTx);
1146
- });
1147
-
1148
- it('should not fail to sign a XRP tx with lowercase key', () => {
1149
- const signedTx = Transactions.sign({
1150
- chain: 'XRP',
1151
- tx:
1152
- '120000228000000024000000012E0001E2405011101234567890123456789012345671012345678901234567890156789012345661400000000001E24068400000000000000C8114A2C8E8CD9A9133CAD90F2668159AAF572612A5028314A2C8E8CD9A9133CAD90F2668159AAF572612A502',
1153
- key: {
1154
- privKey: 'd02c6801d8f328ff2ead51d01f9580af36c8d74e2bd463963ac4adbe51ae5f2c',
1155
- pubKey: '03dbeec5e9e76da09c5b502a67136bc2d73423e8902a7c35a8cbc0c5a6ac0469e8'
1156
- }
1157
- });
1158
- const expectedSignedTx =
1159
- '120000228000000024000000012E0001E2405011101234567890123456789012345671012345678901234567890156789012345661400000000001E24068400000000000000C732103DBEEC5E9E76DA09C5B502A67136BC2D73423E8902A7C35A8CBC0C5A6AC0469E874473045022100D5C19360E77D691A11CA693F6E8D8472DA6749D16A06E072ED1110EB3FD9E2C80220169F95E55943C3575CEAA46413FE660E4F8F2E7158FAC235DC3CB9C9F26918098114A2C8E8CD9A9133CAD90F2668159AAF572612A5028314A2C8E8CD9A9133CAD90F2668159AAF572612A502';
1160
- expect(signedTx).to.equal(expectedSignedTx);
1161
- });
1162
-
1163
- it('should throw using wrong privKey to sign an ETH tx', () => {
1164
- let error;
1165
- try {
1166
- Transactions.sign({
1167
- chain: 'ETH',
1168
- tx:
1169
- '0xf9014c808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
1170
- key: {
1171
- privKey: 'wrongPrivateKey'
1172
- }
1173
- });
1174
- } catch (err) {
1175
- error = err;
1176
- }
1177
- expect(error.message).to.include('invalid BytesLike value');
1178
- expect(error).to.not.equal(undefined);
1179
- });
1180
-
1181
- it('should throw using wrong privKey to sign an MATIC tx', () => {
1182
- let error;
1183
- try {
1184
- Transactions.sign({
1185
- chain: 'MATIC',
1186
- tx:
1187
- '0xf9014c808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
1188
- key: {
1189
- privKey: 'wrongPrivateKey'
1190
- }
1191
- });
1192
- } catch (err) {
1193
- error = err;
1194
- }
1195
- expect(error.message).to.include('invalid BytesLike value');
1196
- expect(error).to.not.equal(undefined);
1197
- });
1198
- });
1199
-
1200
- describe('getSignature', function() {
1201
- it('should be able to getSignature an ETH tx', () => {
1202
- const signature = Transactions.getSignature({
1203
- chain: 'ETH',
1204
- tx:
1205
- '0xf9014c808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
1206
- key: {
1207
- privKey: '0x29a1271a8214ccf499b99070115adc43539d4e086b5babab57c4c7a88f959cc2'
1208
- }
1209
- });
1210
- const expectedSignature =
1211
- '0xdb427c4dddcfc816581d657d9f30f8287bdebd9b9cbabc7a535fc67cde9f2b3d2eafc2d79ef47fe045c47f08af54736caf797c27f2e25266d6320243104834f71b';
1212
- expect(signature).to.equal(expectedSignature);
1213
- });
1214
-
1215
- it('should be able to getSignature an MATIC tx', () => {
1216
- const signature = Transactions.getSignature({
1217
- chain: 'MATIC',
1218
- tx:
1219
- '0xf9014c808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
1220
- key: {
1221
- privKey: '0x29a1271a8214ccf499b99070115adc43539d4e086b5babab57c4c7a88f959cc2'
1222
- }
1223
- });
1224
- const expectedSignature =
1225
- '0xdb427c4dddcfc816581d657d9f30f8287bdebd9b9cbabc7a535fc67cde9f2b3d2eafc2d79ef47fe045c47f08af54736caf797c27f2e25266d6320243104834f71b';
1226
- expect(signature).to.equal(expectedSignature);
1227
- });
1228
- });
1229
-
1230
- describe('applyTransaction', function() {
1231
- describe('BTC', function() {
1232
- const chain = 'BTC';
1233
- const network = 'regtest';
1234
- const lib = bitcoreLib;
1235
- const privkey = new lib.PrivateKey('65a1c4421a01e07355a59aa4d7d2b2ebd4d14e3c3ce0c239b9081a523c5d69ba', network);
1236
- const pubkey = privkey.toPublicKey();
1237
- const to = 'bcrt1qxerc45n2rv360s8z3wj67fdq93h22m5gstud4z';
1238
- const change = pubkey.toAddress(network, 'p2pkh');
1239
-
1240
- it('should apply signature to a P2PK tx', function() {
1241
- const tx = new lib.Transaction()
1242
- .from({
1243
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1244
- vout: 0,
1245
- satoshis: 1e9,
1246
- script: lib.Script.buildPublicKeyOut(pubkey).toString()
1247
- })
1248
- .to(to, 1234)
1249
- .change(change);
1250
-
1251
- const signature = tx.inputs[0].getSignatures(tx, privkey, 0)[0];
1252
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1253
- const signed = Transactions.applySignature({ chain, tx, signature, index: 0 });
1254
- expect(signed).to.equal(tx);
1255
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1256
- expect(() => tx.serialize()).to.not.throw();
1257
- });
1258
-
1259
- it('should apply signature to a P2PKH tx', function() {
1260
- const addy = pubkey.toAddress(network, 'p2pkh');
1261
- const tx = new lib.Transaction()
1262
- .from({
1263
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1264
- vout: 0,
1265
- satoshis: 1e9,
1266
- script: lib.Script.fromAddress(addy)
1267
- })
1268
- .to(to, 1234)
1269
- .change(change);
1270
-
1271
- const signature = tx.inputs[0].getSignatures(tx, privkey, 0)[0];
1272
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1273
- const signed = Transactions.applySignature({ chain, tx, signature, index: 0 });
1274
- expect(signed).to.equal(tx);
1275
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1276
- expect(() => tx.serialize()).to.not.throw();
1277
- });
1278
-
1279
- it('should apply signature to a P2SH tx', function() {
1280
- const addy = pubkey.toAddress(network, 'p2sh');
1281
- const tx = new lib.Transaction()
1282
- .from({
1283
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1284
- vout: 0,
1285
- satoshis: 1e9,
1286
- script: lib.Script.fromAddress(addy)
1287
- })
1288
- .to(to, 1234)
1289
- .change(change);
1290
-
1291
- const signature = tx.inputs[0].getSignatures(tx, privkey, 0)[0];
1292
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1293
- const signed = Transactions.applySignature({ chain, tx, signature, index: 0 });
1294
- expect(signed).to.equal(tx);
1295
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1296
- expect(() => tx.serialize()).to.not.throw();
1297
- });
1298
-
1299
- it('should apply signature to a P2WPKH tx', function() {
1300
- const addy = pubkey.toAddress(network, 'p2wpkh');
1301
- const tx = new lib.Transaction()
1302
- .from({
1303
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1304
- vout: 0,
1305
- satoshis: 1e9,
1306
- script: lib.Script.fromAddress(addy)
1307
- })
1308
- .to(to, 1234)
1309
- .change(change);
1310
-
1311
- const signature = tx.inputs[0].getSignatures(tx, privkey, 0)[0];
1312
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1313
- const signed = Transactions.applySignature({ chain, tx, signature, index: 0 });
1314
- expect(signed).to.equal(tx);
1315
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1316
- expect(() => tx.serialize()).to.not.throw();
1317
- });
1318
-
1319
- it('should apply signature to a multisig P2SH tx', function() {
1320
- const privkey2 = new lib.PrivateKey('61059599ffc27072ccb7a7ddbe32c031433bf3b7bf1e128b0b4e80a6c68c027e', network);
1321
- const pubkey2 = privkey2.toPublicKey();
1322
- const privkey3 = new lib.PrivateKey('4fac3c5338abc4cd27ef98ad1122215dc4651c4f30c9c59ebe7b33dc416ec33e', network);
1323
- const pubkey3 = privkey3.toPublicKey();
1324
- const addy = lib.Address.createMultisig([pubkey, pubkey2, pubkey3], 2, network, false); // p2sh
1325
- const tx = new lib.Transaction()
1326
- .from({
1327
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1328
- vout: 0,
1329
- satoshis: 1e9,
1330
- script: lib.Script.fromAddress(addy).toString()
1331
- }, [pubkey, pubkey2, pubkey3], 2)
1332
- .to(to, 1234)
1333
- .change(change);
1334
-
1335
- const signature2 = tx.inputs[0].getSignatures(tx, privkey2, 0)[0];
1336
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1337
- const signed2 = Transactions.applySignature({ chain, tx, signature: signature2, index: 0 });
1338
- expect(signed2).to.equal(tx);
1339
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1340
- const signature3 = tx.inputs[0].getSignatures(tx, privkey3, 0)[0];
1341
- const signed3 = Transactions.applySignature({ chain, tx, signature: signature3, index: 0 });
1342
- expect(signed3).to.equal(tx);
1343
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1344
- expect(() => tx.serialize()).to.not.throw();
1345
- });
1346
-
1347
- it('should apply signature to a multisig P2WSH tx', function() {
1348
- const privkey2 = new lib.PrivateKey('61059599ffc27072ccb7a7ddbe32c031433bf3b7bf1e128b0b4e80a6c68c027e', network);
1349
- const pubkey2 = privkey2.toPublicKey();
1350
- const privkey3 = new lib.PrivateKey('4fac3c5338abc4cd27ef98ad1122215dc4651c4f30c9c59ebe7b33dc416ec33e', network);
1351
- const pubkey3 = privkey3.toPublicKey();
1352
- const addy = lib.Address.createMultisig([pubkey, pubkey2, pubkey3], 2, network, true); // p2wsh
1353
- const tx = new lib.Transaction()
1354
- .from({
1355
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1356
- vout: 0,
1357
- satoshis: 1e9,
1358
- script: lib.Script.fromAddress(addy).toString()
1359
- }, [pubkey, pubkey2, pubkey3], 2)
1360
- .to(to, 1234)
1361
- .change(change);
1362
-
1363
- const signature2 = tx.inputs[0].getSignatures(tx, privkey2, 0)[0];
1364
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1365
- const signed2 = Transactions.applySignature({ chain, tx, signature: signature2, index: 0 });
1366
- expect(signed2).to.equal(tx);
1367
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1368
- const signature3 = tx.inputs[0].getSignatures(tx, privkey3, 0)[0];
1369
- const signed3 = Transactions.applySignature({ chain, tx, signature: signature3, index: 0 });
1370
- expect(signed3).to.equal(tx);
1371
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1372
- expect(() => tx.serialize()).to.not.throw();
1373
- });
1374
-
1375
- it('should apply signature to a P2TR tx', function() {
1376
- const addy = pubkey.toAddress(network, 'p2tr');
1377
- const tx = new lib.Transaction()
1378
- .from({
1379
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1380
- vout: 0,
1381
- satoshis: 1e9,
1382
- script: lib.Script.fromAddress(addy).toString()
1383
- })
1384
- .to(to, 1234)
1385
- .change(change);
1386
-
1387
- const signature = tx.inputs[0].getSignatures(tx, privkey, 0)[0];
1388
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1389
- const signed = Transactions.applySignature({ chain, tx, signature, index: 0 });
1390
- expect(signed).to.equal(tx);
1391
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1392
- expect(() => tx.serialize()).to.not.throw();
1393
- });
1394
- });
1395
-
1396
- describe('BCH', function() {
1397
- const chain = 'BCH';
1398
- const network = 'regtest';
1399
- const lib = bitcoreLibCash;
1400
- const privkey = new lib.PrivateKey('65a1c4421a01e07355a59aa4d7d2b2ebd4d14e3c3ce0c239b9081a523c5d69ba', network);
1401
- const pubkey = privkey.toPublicKey();
1402
- const to = 'qzpjx6cvau7tunx0hxvr4czrrllm0ecd95gz8y5euh';
1403
- const change = pubkey.toAddress(network, 'p2pkh');
1404
-
1405
- it('should apply signature to a P2PK tx', function() {
1406
- const tx = new lib.Transaction()
1407
- .from({
1408
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1409
- vout: 0,
1410
- satoshis: 1e9,
1411
- script: lib.Script.buildPublicKeyOut(pubkey).toString()
1412
- })
1413
- .to(to, 1234)
1414
- .change(change);
1415
-
1416
- const signature = tx.inputs[0].getSignatures(tx, privkey, 0)[0];
1417
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1418
- const signed = Transactions.applySignature({ chain, tx, signature, index: 0 });
1419
- expect(signed).to.equal(tx);
1420
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1421
- expect(() => tx.serialize()).to.not.throw();
1422
- });
1423
-
1424
- it('should apply signature to a P2PKH tx', function() {
1425
- const addy = pubkey.toAddress(network, 'p2pkh');
1426
- const tx = new lib.Transaction()
1427
- .from({
1428
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1429
- vout: 0,
1430
- satoshis: 1e9,
1431
- script: lib.Script.fromAddress(addy)
1432
- })
1433
- .to(to, 1234)
1434
- .change(change);
1435
-
1436
- const signature = tx.inputs[0].getSignatures(tx, privkey, 0)[0];
1437
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1438
- const signed = Transactions.applySignature({ chain, tx, signature, index: 0 });
1439
- expect(signed).to.equal(tx);
1440
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1441
- expect(() => tx.serialize()).to.not.throw();
1442
- });
1443
-
1444
- it.skip('should apply signature to a P2SH tx', function() {
1445
- // single-sig P2SH is not completely supported in bitcore-lib-cash due to it's unusual usage, unlike BTC and LTC
1446
- // skipping this test for now but leaving it as a possibility if/when we add full P2SH support in bitcore-lib-cash
1447
- const addy = pubkey.toAddress(network, 'p2sh');
1448
- const tx = new lib.Transaction()
1449
- .from({
1450
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1451
- vout: 0,
1452
- satoshis: 1e9,
1453
- script: lib.Script.fromAddress(addy)
1454
- })
1455
- .to(to, 1234)
1456
- .change(change);
1457
-
1458
- const signature = tx.inputs[0].getSignatures(tx, privkey, 0)[0];
1459
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1460
- const signed = Transactions.applySignature({ chain, tx, signature, index: 0 });
1461
- expect(signed).to.equal(tx);
1462
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1463
- expect(() => tx.serialize()).to.not.throw();
1464
- });
1465
-
1466
- it('should apply signature to a multisig P2SH tx', function() {
1467
- const privkey2 = new lib.PrivateKey('61059599ffc27072ccb7a7ddbe32c031433bf3b7bf1e128b0b4e80a6c68c027e', network);
1468
- const pubkey2 = privkey2.toPublicKey();
1469
- const privkey3 = new lib.PrivateKey('4fac3c5338abc4cd27ef98ad1122215dc4651c4f30c9c59ebe7b33dc416ec33e', network);
1470
- const pubkey3 = privkey3.toPublicKey();
1471
- const addy = lib.Address.createMultisig([pubkey, pubkey2, pubkey3], 2, network, false); // p2sh
1472
- const tx = new lib.Transaction()
1473
- .from({
1474
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1475
- vout: 0,
1476
- satoshis: 1e9,
1477
- script: lib.Script.fromAddress(addy).toString()
1478
- }, [pubkey, pubkey2, pubkey3], 2)
1479
- .to(to, 1234)
1480
- .change(change);
1481
-
1482
- const signature2 = tx.inputs[0].getSignatures(tx, privkey2, 0)[0];
1483
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1484
- const signed2 = Transactions.applySignature({ chain, tx, signature: signature2, index: 0 });
1485
- expect(signed2).to.equal(tx);
1486
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1487
- const signature3 = tx.inputs[0].getSignatures(tx, privkey3, 0)[0];
1488
- const signed3 = Transactions.applySignature({ chain, tx, signature: signature3, index: 0 });
1489
- expect(signed3).to.equal(tx);
1490
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1491
- expect(() => tx.serialize()).to.not.throw();
1492
- });
1493
-
1494
- it('should apply signature to an escrow tx', function() {
1495
- const privkey2 = new lib.PrivateKey('61059599ffc27072ccb7a7ddbe32c031433bf3b7bf1e128b0b4e80a6c68c027e', network);
1496
- const pubkey2 = privkey2.toPublicKey();
1497
- const privkey3 = new lib.PrivateKey('4fac3c5338abc4cd27ef98ad1122215dc4651c4f30c9c59ebe7b33dc416ec33e', network);
1498
- const pubkey3 = privkey3.toPublicKey();
1499
- const addy = lib.Address.createMultisig([pubkey, pubkey2, pubkey3], 2, network, false); // p2sh
1500
- const tx = new lib.Transaction()
1501
- .from({
1502
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1503
- vout: 0,
1504
- satoshis: 1e9,
1505
- script: lib.Script.fromAddress(addy).toString()
1506
- }, [pubkey, pubkey2, pubkey3], 2)
1507
- .to(to, 1234)
1508
- .change(change);
1509
-
1510
- const signature2 = tx.inputs[0].getSignatures(tx, privkey2, 0)[0];
1511
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1512
- const signed2 = Transactions.applySignature({ chain, tx, signature: signature2, index: 0 });
1513
- expect(signed2).to.equal(tx);
1514
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1515
- const signature3 = tx.inputs[0].getSignatures(tx, privkey3, 0)[0];
1516
- const signed3 = Transactions.applySignature({ chain, tx, signature: signature3, index: 0 });
1517
- expect(signed3).to.equal(tx);
1518
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1519
- expect(() => tx.serialize()).to.not.throw();
1520
- });
1521
- });
1522
-
1523
- describe('DOGE', function() {
1524
- const chain = 'DOGE';
1525
- const network = 'regtest';
1526
- const lib = bitcoreLibDoge;
1527
- const privkey = new lib.PrivateKey('65a1c4421a01e07355a59aa4d7d2b2ebd4d14e3c3ce0c239b9081a523c5d69ba', network);
1528
- const pubkey = privkey.toPublicKey();
1529
- const to = 'mwHPw7Vtty66L9znjDY2NhFB2wJG7Lw42v';
1530
- const change = pubkey.toAddress(network, 'p2pkh');
1531
-
1532
- it('should apply signature to a P2PK tx', function() {
1533
- const tx = new lib.Transaction()
1534
- .from({
1535
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1536
- vout: 0,
1537
- satoshis: 1e9,
1538
- script: lib.Script.buildPublicKeyOut(pubkey).toString()
1539
- })
1540
- .to(to, 1e7)
1541
- .change(change);
1542
-
1543
- const signature = tx.inputs[0].getSignatures(tx, privkey, 0)[0];
1544
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1545
- const signed = Transactions.applySignature({ chain, tx, signature, index: 0 });
1546
- expect(signed).to.equal(tx);
1547
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1548
- expect(() => tx.serialize()).to.not.throw();
1549
- });
1550
-
1551
- it('should apply signature to a P2PKH tx', function() {
1552
- const addy = pubkey.toAddress(network, 'p2pkh');
1553
- const tx = new lib.Transaction()
1554
- .from({
1555
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1556
- vout: 0,
1557
- satoshis: 1e9,
1558
- script: lib.Script.fromAddress(addy)
1559
- })
1560
- .to(to, 1e7)
1561
- .change(change);
1562
-
1563
- const signature = tx.inputs[0].getSignatures(tx, privkey, 0)[0];
1564
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1565
- const signed = Transactions.applySignature({ chain, tx, signature, index: 0 });
1566
- expect(signed).to.equal(tx);
1567
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1568
- expect(() => tx.serialize()).to.not.throw();
1569
- });
1570
-
1571
- it.skip('should apply signature to a P2SH tx', function() {
1572
- // single-sig P2SH is not completely supported in bitcore-lib-doge due to it's unusual usage, unlike BTC and LTC
1573
- // skipping this test for now but leaving it as a possibility if/when we add full P2SH support in bitcore-lib-doge
1574
- const addy = pubkey.toAddress(network, 'p2sh');
1575
- const tx = new lib.Transaction()
1576
- .from({
1577
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1578
- vout: 0,
1579
- satoshis: 1e9,
1580
- script: lib.Script.fromAddress(addy)
1581
- })
1582
- .to(to, 1e7)
1583
- .change(change);
1584
-
1585
- const signature = tx.inputs[0].getSignatures(tx, privkey, 0)[0];
1586
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1587
- const signed = Transactions.applySignature({ chain, tx, signature, index: 0 });
1588
- expect(signed).to.equal(tx);
1589
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1590
- expect(() => tx.serialize()).to.not.throw();
1591
- });
1592
-
1593
- it('should apply signature to a multisig P2SH tx', function() {
1594
- const privkey2 = new lib.PrivateKey('61059599ffc27072ccb7a7ddbe32c031433bf3b7bf1e128b0b4e80a6c68c027e', network);
1595
- const pubkey2 = privkey2.toPublicKey();
1596
- const privkey3 = new lib.PrivateKey('4fac3c5338abc4cd27ef98ad1122215dc4651c4f30c9c59ebe7b33dc416ec33e', network);
1597
- const pubkey3 = privkey3.toPublicKey();
1598
- const addy = lib.Address.createMultisig([pubkey, pubkey2, pubkey3], 2, network, false); // p2sh
1599
- const tx = new lib.Transaction()
1600
- .from({
1601
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1602
- vout: 0,
1603
- satoshis: 1e9,
1604
- script: lib.Script.fromAddress(addy).toString()
1605
- }, [pubkey, pubkey2, pubkey3], 2)
1606
- .to(to, 1e7)
1607
- .change(change);
1608
-
1609
- const signature2 = tx.inputs[0].getSignatures(tx, privkey2, 0)[0];
1610
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1611
- const signed2 = Transactions.applySignature({ chain, tx, signature: signature2, index: 0 });
1612
- expect(signed2).to.equal(tx);
1613
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1614
- const signature3 = tx.inputs[0].getSignatures(tx, privkey3, 0)[0];
1615
- const signed3 = Transactions.applySignature({ chain, tx, signature: signature3, index: 0 });
1616
- expect(signed3).to.equal(tx);
1617
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1618
- expect(() => tx.serialize()).to.not.throw();
1619
- });
1620
- });
1621
-
1622
- describe('LTC', function() {
1623
- const chain = 'LTC';
1624
- const network = 'regtest';
1625
- const lib = bitcoreLibLtc;
1626
- const privkey = new lib.PrivateKey('65a1c4421a01e07355a59aa4d7d2b2ebd4d14e3c3ce0c239b9081a523c5d69ba', network);
1627
- const pubkey = privkey.toPublicKey();
1628
- const to = 'rltc1q6tvvdn702mmfnu0ujdkw97qw9aac9xm2c6wgk6';
1629
- const change = pubkey.toAddress(network, 'p2pkh');
1630
-
1631
- it('should apply signature to a P2PK tx', function() {
1632
- const tx = new lib.Transaction()
1633
- .from({
1634
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1635
- vout: 0,
1636
- satoshis: 1e9,
1637
- script: lib.Script.buildPublicKeyOut(pubkey).toString()
1638
- })
1639
- .to(to, 1e4)
1640
- .change(change);
1641
-
1642
- const signature = tx.inputs[0].getSignatures(tx, privkey, 0)[0];
1643
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1644
- const signed = Transactions.applySignature({ chain, tx, signature, index: 0 });
1645
- expect(signed).to.equal(tx);
1646
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1647
- expect(() => tx.serialize()).to.not.throw();
1648
- });
1649
-
1650
- it('should apply signature to a P2PKH tx', function() {
1651
- const addy = pubkey.toAddress(network, 'p2pkh');
1652
- const tx = new lib.Transaction()
1653
- .from({
1654
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1655
- vout: 0,
1656
- satoshis: 1e9,
1657
- script: lib.Script.fromAddress(addy)
1658
- })
1659
- .to(to, 1e4)
1660
- .change(change);
1661
-
1662
- const signature = tx.inputs[0].getSignatures(tx, privkey, 0)[0];
1663
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1664
- const signed = Transactions.applySignature({ chain, tx, signature, index: 0 });
1665
- expect(signed).to.equal(tx);
1666
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1667
- expect(() => tx.serialize()).to.not.throw();
1668
- });
1669
-
1670
- it('should apply signature to a P2SH tx', function() {
1671
- const addy = pubkey.toAddress(network, 'p2sh');
1672
- const tx = new lib.Transaction()
1673
- .from({
1674
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1675
- vout: 0,
1676
- satoshis: 1e9,
1677
- script: lib.Script.fromAddress(addy)
1678
- })
1679
- .to(to, 1e4)
1680
- .change(change);
1681
-
1682
- const signature = tx.inputs[0].getSignatures(tx, privkey, 0)[0];
1683
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1684
- const signed = Transactions.applySignature({ chain, tx, signature, index: 0 });
1685
- expect(signed).to.equal(tx);
1686
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1687
- expect(() => tx.serialize()).to.not.throw();
1688
- });
1689
-
1690
- it('should apply signature to a P2WPKH tx', function() {
1691
- const addy = pubkey.toAddress(network, 'p2wpkh');
1692
- const tx = new lib.Transaction()
1693
- .from({
1694
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1695
- vout: 0,
1696
- satoshis: 1e9,
1697
- script: lib.Script.fromAddress(addy)
1698
- })
1699
- .to(to, 1e4)
1700
- .change(change);
1701
-
1702
- const signature = tx.inputs[0].getSignatures(tx, privkey, 0)[0];
1703
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1704
- const signed = Transactions.applySignature({ chain, tx, signature, index: 0 });
1705
- expect(signed).to.equal(tx);
1706
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1707
- expect(() => tx.serialize()).to.not.throw();
1708
- });
1709
-
1710
- it('should apply signature to a multisig P2SH tx', function() {
1711
- const privkey2 = new lib.PrivateKey('61059599ffc27072ccb7a7ddbe32c031433bf3b7bf1e128b0b4e80a6c68c027e', network);
1712
- const pubkey2 = privkey2.toPublicKey();
1713
- const privkey3 = new lib.PrivateKey('4fac3c5338abc4cd27ef98ad1122215dc4651c4f30c9c59ebe7b33dc416ec33e', network);
1714
- const pubkey3 = privkey3.toPublicKey();
1715
- const addy = lib.Address.createMultisig([pubkey, pubkey2, pubkey3], 2, network, false); // p2sh
1716
- const tx = new lib.Transaction()
1717
- .from({
1718
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1719
- vout: 0,
1720
- satoshis: 1e9,
1721
- script: lib.Script.fromAddress(addy).toString()
1722
- }, [pubkey, pubkey2, pubkey3], 2)
1723
- .to(to, 1e4)
1724
- .change(change);
1725
-
1726
- const signature2 = tx.inputs[0].getSignatures(tx, privkey2, 0)[0];
1727
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1728
- const signed2 = Transactions.applySignature({ chain, tx, signature: signature2, index: 0 });
1729
- expect(signed2).to.equal(tx);
1730
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1731
- const signature3 = tx.inputs[0].getSignatures(tx, privkey3, 0)[0];
1732
- const signed3 = Transactions.applySignature({ chain, tx, signature: signature3, index: 0 });
1733
- expect(signed3).to.equal(tx);
1734
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1735
- expect(() => tx.serialize()).to.not.throw();
1736
- });
1737
-
1738
- it('should apply signature to a multisig P2WSH tx', function() {
1739
- const privkey2 = new lib.PrivateKey('61059599ffc27072ccb7a7ddbe32c031433bf3b7bf1e128b0b4e80a6c68c027e', network);
1740
- const pubkey2 = privkey2.toPublicKey();
1741
- const privkey3 = new lib.PrivateKey('4fac3c5338abc4cd27ef98ad1122215dc4651c4f30c9c59ebe7b33dc416ec33e', network);
1742
- const pubkey3 = privkey3.toPublicKey();
1743
- const addy = lib.Address.createMultisig([pubkey, pubkey2, pubkey3], 2, network, true); // p2wsh
1744
- const tx = new lib.Transaction()
1745
- .from({
1746
- txid: 'ba50b12d89162134c31a89ae1f289a1c86fe0a2e7c1861768296408090e30864',
1747
- vout: 0,
1748
- satoshis: 1e9,
1749
- script: lib.Script.fromAddress(addy).toString()
1750
- }, [pubkey, pubkey2, pubkey3], 2)
1751
- .to(to, 1e4)
1752
- .change(change);
1753
-
1754
- const signature2 = tx.inputs[0].getSignatures(tx, privkey2, 0)[0];
1755
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1756
- const signed2 = Transactions.applySignature({ chain, tx, signature: signature2, index: 0 });
1757
- expect(signed2).to.equal(tx);
1758
- expect(tx.inputs[0].isFullySigned()).to.equal(false);
1759
- const signature3 = tx.inputs[0].getSignatures(tx, privkey3, 0)[0];
1760
- const signed3 = Transactions.applySignature({ chain, tx, signature: signature3, index: 0 });
1761
- expect(signed3).to.equal(tx);
1762
- expect(tx.inputs[0].isFullySigned()).to.equal(true);
1763
- expect(() => tx.serialize()).to.not.throw();
1764
- });
1765
- });
1766
-
1767
-
1768
- it('should apply signatures to an ETH tx', () => {
1769
- const signedTx = Transactions.applySignature({
1770
- chain: 'ETH',
1771
- tx:
1772
- '0xf9014c808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
1773
- signature:
1774
- '0xdb427c4dddcfc816581d657d9f30f8287bdebd9b9cbabc7a535fc67cde9f2b3d2eafc2d79ef47fe045c47f08af54736caf797c27f2e25266d6320243104834f71b'
1775
- });
1776
-
1777
- const expectedSignedTx =
1778
- '0xf9018f808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead1468056300000000000000000000000000000000000000000000000000000000000000001ba0db427c4dddcfc816581d657d9f30f8287bdebd9b9cbabc7a535fc67cde9f2b3da02eafc2d79ef47fe045c47f08af54736caf797c27f2e25266d6320243104834f7';
1779
- expect(signedTx).to.equal(expectedSignedTx);
1780
- });
1781
-
1782
- it('should apply signatures to an ETH tx type 2', () => {
1783
- const expectedTx =
1784
- '0x02f9017d0580808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90152f9014f808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000058080c0';
1785
- const parsedTx = ethers.Transaction.from(expectedTx);
1786
- expect(parsedTx.type).to.equal(2);
1787
- expect(parsedTx.maxFeePerGas).to.not.equal(null);
1788
- expect(parsedTx.gasPrice).to.equal(null);
1789
-
1790
- const signedTx = Transactions.applySignature({
1791
- chain: 'ETH',
1792
- tx: expectedTx,
1793
- signature:
1794
- '0xdb427c4dddcfc816581d657d9f30f8287bdebd9b9cbabc7a535fc67cde9f2b3d2eafc2d79ef47fe045c47f08af54736caf797c27f2e25266d6320243104834f71b'
1795
- });
1796
-
1797
- const expectedSignedTx =
1798
- '0x02f901c00580808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90152f9014f808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000058080c080a0db427c4dddcfc816581d657d9f30f8287bdebd9b9cbabc7a535fc67cde9f2b3da02eafc2d79ef47fe045c47f08af54736caf797c27f2e25266d6320243104834f7';
1799
- const parsedSignedTx = ethers.Transaction.from(expectedSignedTx);
1800
- expect(signedTx).to.equal(expectedSignedTx);
1801
- expect(parsedSignedTx.type).to.equal(2);
1802
- expect(parsedSignedTx.maxFeePerGas).to.not.equal(null);
1803
- expect(parsedSignedTx.gasPrice).to.equal(null);
1804
- });
1805
-
1806
- it('should fail to apply signatures to an ETH tx type 2 with insufficient gasPrice or maxGasFee', () => {
1807
- const expectedTx =
1808
- '0xf866018082520894423163e58aabec5daa3dd1130b759d24bef0f6ea8711c37937e080008025a06852e54c99c14b47d64a5c2791d76f2b9694f6b2d925f881793bec474315897ea0116f3a4ac81642aaac3bcb33fefb46fab24608dfdfaba5cc56e8c0e6022b020a';
1809
- const parsedTx = ethers.Transaction.from(expectedTx);
1810
- expect(!!parsedTx.maxFeePerGas).to.equal(false);
1811
- expect(!!parsedTx.gasPrice).to.equal(false);
1812
- let error;
1813
- try {
1814
- const signedTx = Transactions.applySignature({
1815
- chain: 'ETH',
1816
- tx: expectedTx,
1817
- signature:
1818
- '0xdb427c4dddcfc816581d657d9f30f8287bdebd9b9cbabc7a535fc67cde9f2b3d2eafc2d79ef47fe045c47f08af54736caf797c27f2e25266d6320243104834f71b'
1819
- });
1820
- } catch (err) {
1821
- error = err;
1822
- }
1823
- expect(error).to.not.equal(undefined);
1824
- expect(error.message).to.include('either gasPrice or maxFeePerGas is required');
1825
- });
1826
-
1827
- it('should fail to apply signatures to an ETH tx if signature is invalid', () => {
1828
- expect(() => {
1829
- Transactions.applySignature({
1830
- chain: 'ETH',
1831
- tx:
1832
- '0xf9014c808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
1833
- signature: '0xdb'
1834
- });
1835
- }).to.throw('invalid signature');
1836
- });
1837
-
1838
- it('should apply signatures to an MATIC tx', () => {
1839
- const signedTx = Transactions.applySignature({
1840
- chain: 'MATIC',
1841
- tx:
1842
- '0xf9014c808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
1843
- signature:
1844
- '0xdb427c4dddcfc816581d657d9f30f8287bdebd9b9cbabc7a535fc67cde9f2b3d2eafc2d79ef47fe045c47f08af54736caf797c27f2e25266d6320243104834f71b'
1845
- });
1846
-
1847
- const expectedSignedTx =
1848
- '0xf9018f808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead1468056300000000000000000000000000000000000000000000000000000000000000001ba0db427c4dddcfc816581d657d9f30f8287bdebd9b9cbabc7a535fc67cde9f2b3da02eafc2d79ef47fe045c47f08af54736caf797c27f2e25266d6320243104834f7';
1849
- expect(signedTx).to.equal(expectedSignedTx);
1850
- });
1851
-
1852
- it('should apply signatures to an MATIC tx type 2', () => {
1853
- const expectedTx =
1854
- '0x02f901528301388180808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000c0';
1855
- const parsedTx = ethers.Transaction.from(expectedTx);
1856
- expect(parsedTx.type).to.equal(2);
1857
- expect(parsedTx.maxFeePerGas).to.not.equal(null);
1858
- expect(parsedTx.gasPrice).to.equal(null);
1859
-
1860
- const signedTx = Transactions.applySignature({
1861
- chain: 'MATIC',
1862
- tx: expectedTx,
1863
- signature:
1864
- '0xdb427c4dddcfc816581d657d9f30f8287bdebd9b9cbabc7a535fc67cde9f2b3d2eafc2d79ef47fe045c47f08af54736caf797c27f2e25266d6320243104834f71b'
1865
- });
1866
-
1867
- const expectedSignedTx =
1868
- '0x02f901958301388180808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000c080a0db427c4dddcfc816581d657d9f30f8287bdebd9b9cbabc7a535fc67cde9f2b3da02eafc2d79ef47fe045c47f08af54736caf797c27f2e25266d6320243104834f7';
1869
- const parsedSignedTx = ethers.Transaction.from(expectedSignedTx);
1870
- expect(signedTx).to.equal(expectedSignedTx);
1871
- expect(parsedSignedTx.type).to.equal(2);
1872
- expect(parsedSignedTx.maxFeePerGas).to.not.equal(null);
1873
- expect(parsedSignedTx.gasPrice).to.equal(null);
1874
- });
1875
-
1876
- it('should fail to apply signatures to an MATIC tx type 2 with insufficient gasPrice or maxGasFee', () => {
1877
- const expectedTx =
1878
- '0xf867018082520894423163e58aabec5daa3dd1130b759d24bef0f6ea8711c37937e08000808194a00da3147299808e98b962c45ff89415c8e53cbc1572dc4f275ac4e090c4b5f7b7a02bf658e82ebf130889be5150658c9d13667e0ef9ead5710b8ee21a72490d0186';
1879
- const parsedTx = ethers.Transaction.from(expectedTx);
1880
- expect(!!parsedTx.maxFeePerGas).to.equal(false);
1881
- expect(!!parsedTx.gasPrice).to.equal(false);
1882
- let error;
1883
- try {
1884
- const signedTx = Transactions.applySignature({
1885
- chain: 'MATIC',
1886
- tx: expectedTx,
1887
- signature:
1888
- '0xdb427c4dddcfc816581d657d9f30f8287bdebd9b9cbabc7a535fc67cde9f2b3d2eafc2d79ef47fe045c47f08af54736caf797c27f2e25266d6320243104834f71b'
1889
- });
1890
- } catch (err) {
1891
- error = err;
1892
- }
1893
- expect(error).to.not.equal(undefined);
1894
- expect(error.message).to.include('either gasPrice or maxFeePerGas is required');
1895
- });
1896
-
1897
- it('should fail to apply signatures to an MATIC tx if signature is invalid', () => {
1898
- expect(() => {
1899
- Transactions.applySignature({
1900
- chain: 'MATIC',
1901
- tx:
1902
- '0xf9014c808504a817c800809437d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a870dd764300b8000b90124b6b4af05000000000000000000000000000000000000000000000000000dd764300b800000000000000000000000000000000000000000000000000000000004a817c8000000000000000000000000000000000000000000000000000000016ada606a26050bb49a5a8228599e0dd48c1368abd36f4f14d2b74a015b2d168dbcab0773ce399393220df874bb22ca961f351e038acd2ba5cc8c764385c9f23707622cc435000000000000000000000000000000000000000000000000000000000000001c7e247d684a635813267b10a63f7f3ba88b28ca2790c909110b28236cf1b9bba03451e83d5834189f28d4c77802fc76b7c760a42bc8bebf8dd15e6ead146805630000000000000000000000000000000000000000000000000000000000000000',
1903
- signature: '0xdb'
1904
- });
1905
- }).to.throw('invalid signature');
1906
- });
1907
-
1908
- it('should apply a signature to a SOL tx', () => {
1909
- const signedTx = Transactions.applySignature({
1910
- chain: 'SOL',
1911
- tx: 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDb6/gH5XxrVl86CZd+DpqA1jN8YSz91e8yXxOlyeS8tLRnckLdZVIkhi0iAExccvYpTw5tIfPZ8z/OJGQtnvg9QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA7A+XJrI4siFXUreDo+M94DBeuJwm0Oq5kHqeWuAw7xgBAgIAAQwCAAAAAIALMGTXDQA=',
1912
- signature:
1913
- '6Gpk3UnfTPqUYZWXKR7T6bd5uiPLa4VE6SWFDsVc6QQVeb3F49AEtwjcwUdgpkFyaBQxDonBsA2o95JkjWx7pJ2D'
1914
- });
1915
-
1916
- const expectedSignedTx =
1917
- 'AQEHuvLKC5zGTnDCBktxvEi9i9zGnnucH5C+XcPYsQ1ysQ/rj7XnXUSLXUdxt6iJDp32SkOi2lLn0zEIqCW5RGQBAAEDb6/gH5XxrVl86CZd+DpqA1jN8YSz91e8yXxOlyeS8tLRnckLdZVIkhi0iAExccvYpTw5tIfPZ8z/OJGQtnvg9QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA7A+XJrI4siFXUreDo+M94DBeuJwm0Oq5kHqeWuAw7xgBAgIAAQwCAAAAAIALMGTXDQA=';
1918
- expect(signedTx).to.equal(expectedSignedTx);
1919
- });
1920
-
1921
- });
1922
-
1923
- describe('getHash', function() {
1924
- it('should get ETH tx hash', () => {
1925
- // from https://ethereum.stackexchange.com/questions/31285/how-to-get-raw-ethereum-transaction-hash
1926
- const hash = Transactions.getHash({
1927
- chain: 'ETH',
1928
- tx:
1929
- '0xf86c258502540be40083035b609482e041e84074fc5f5947d4d27e3c44f824b7a1a187b1a2bc2ec500008078a04a7db627266fa9a4116e3f6b33f5d245db40983234eb356261f36808909d2848a0166fa098a2ce3bda87af6000ed0083e3bf7cc31c6686b670bd85cbc6da2d6e85'
1930
- });
1931
- const expectedHash = '0x58e5a0fc7fbc849eddc100d44e86276168a8c7baaa5604e44ba6f5eb8ba1b7eb';
1932
- expect(hash).to.equal(expectedHash);
1933
- });
1934
-
1935
- it('should get MATIC tx hash', () => {
1936
- // from https://ethereum.stackexchange.com/questions/31285/how-to-get-raw-ethereum-transaction-hash
1937
- const hash = Transactions.getHash({
1938
- chain: 'MATIC',
1939
- tx:
1940
- '0xf86c258502540be40083035b609482e041e84074fc5f5947d4d27e3c44f824b7a1a187b1a2bc2ec500008078a04a7db627266fa9a4116e3f6b33f5d245db40983234eb356261f36808909d2848a0166fa098a2ce3bda87af6000ed0083e3bf7cc31c6686b670bd85cbc6da2d6e85'
1941
- });
1942
- const expectedHash = '0x58e5a0fc7fbc849eddc100d44e86276168a8c7baaa5604e44ba6f5eb8ba1b7eb';
1943
- expect(hash).to.equal(expectedHash);
1944
- });
1945
-
1946
- it('should get XRP signed tx hash', () => {
1947
- const hash = Transactions.getHash({
1948
- chain: 'XRP',
1949
- tx:
1950
- '120000228000000024000000012E0001E2405011101234567890123456789012345671012345678901234567890156789012345661400000000001E24068400000000000000C732103DBEEC5E9E76DA09C5B502A67136BC2D73423E8902A7C35A8CBC0C5A6AC0469E874473045022100D5C19360E77D691A11CA693F6E8D8472DA6749D16A06E072ED1110EB3FD9E2C80220169F95E55943C3575CEAA46413FE660E4F8F2E7158FAC235DC3CB9C9F26918098114A2C8E8CD9A9133CAD90F2668159AAF572612A5028314A2C8E8CD9A9133CAD90F2668159AAF572612A502'
1951
- });
1952
- const expectedHash = '61EA6DF3BD1E435283BA0B06311C7BA683A32A80E465196D9F16A23A439EF6F4';
1953
- expect(hash.length).to.equal(64);
1954
- expect(hash).to.equal(expectedHash);
1955
- });
1956
-
1957
- it('should get XRP testnet signed tx hash', () => {
1958
- const hash = Transactions.getHash({
1959
- chain: 'XRP',
1960
- network: 'testnet',
1961
- tx:
1962
- '120000228000000024000000012E0001E2405011101234567890123456789012345671012345678901234567890156789012345661400000000001E24068400000000000000C732103DBEEC5E9E76DA09C5B502A67136BC2D73423E8902A7C35A8CBC0C5A6AC0469E874473045022100D5C19360E77D691A11CA693F6E8D8472DA6749D16A06E072ED1110EB3FD9E2C80220169F95E55943C3575CEAA46413FE660E4F8F2E7158FAC235DC3CB9C9F26918098114A2C8E8CD9A9133CAD90F2668159AAF572612A5028314A2C8E8CD9A9133CAD90F2668159AAF572612A502'
1963
- });
1964
- const expectedHash = '61EA6DF3BD1E435283BA0B06311C7BA683A32A80E465196D9F16A23A439EF6F4';
1965
- expect(hash.length).to.equal(64);
1966
- expect(hash).to.equal(expectedHash);
1967
- });
1968
-
1969
- it('should get XRP livenet signed tx hash', () => {
1970
- const hash = Transactions.getHash({
1971
- chain: 'XRP',
1972
- network: 'livenet',
1973
- tx:
1974
- '120000228000000024000000012E0001E2405011101234567890123456789012345671012345678901234567890156789012345661400000000001E24068400000000000000C732103DBEEC5E9E76DA09C5B502A67136BC2D73423E8902A7C35A8CBC0C5A6AC0469E874473045022100D5C19360E77D691A11CA693F6E8D8472DA6749D16A06E072ED1110EB3FD9E2C80220169F95E55943C3575CEAA46413FE660E4F8F2E7158FAC235DC3CB9C9F26918098114A2C8E8CD9A9133CAD90F2668159AAF572612A5028314A2C8E8CD9A9133CAD90F2668159AAF572612A502'
1975
- });
1976
- const expectedHash = '61EA6DF3BD1E435283BA0B06311C7BA683A32A80E465196D9F16A23A439EF6F4';
1977
- expect(hash.length).to.equal(64);
1978
- expect(hash).to.equal(expectedHash);
1979
- });
1980
- });
1981
-
1982
-
1983
- describe('ETH getChainId', () => {
1984
- it('should get the correct chainId per network', () => {
1985
- const mainnetId = Transactions.get({ chain: 'ETH' }).getChainId('mainnet');
1986
- expect(mainnetId).to.equal(1);
1987
-
1988
- const livenetId = Transactions.get({ chain: 'ETH' }).getChainId('livenet');
1989
- expect(livenetId).to.equal(1);
1990
-
1991
- const testId = Transactions.get({ chain: 'ETH' }).getChainId('testnet');
1992
- expect(testId).to.equal(11155111);
1993
-
1994
- const sepoliaId = Transactions.get({ chain: 'ETH' }).getChainId('sepolia');
1995
- expect(sepoliaId).to.equal(11155111);
1996
-
1997
- const holeskyId = Transactions.get({ chain: 'ETH' }).getChainId('holesky');
1998
- expect(holeskyId).to.equal(17000);
1999
-
2000
- const regtestId = Transactions.get({ chain: 'ETH' }).getChainId('regtest');
2001
- expect(regtestId).to.equal(1337);
2002
- });
2003
- });
2004
-
2005
- describe('MATIC getChainId', () => {
2006
- it('should get the correct chainId per network', () => {
2007
- const mainnetId = Transactions.get({ chain: 'MATIC' }).getChainId('mainnet');
2008
- expect(mainnetId).to.equal(137);
2009
-
2010
- const livenetId = Transactions.get({ chain: 'MATIC' }).getChainId('livenet');
2011
- expect(livenetId).to.equal(137);
2012
-
2013
- const testnetId = Transactions.get({ chain: 'MATIC' }).getChainId('testnet');
2014
- expect(testnetId).to.equal(80002);
2015
-
2016
- const testId = Transactions.get({ chain: 'MATIC' }).getChainId('mumbai');
2017
- expect(testId).to.equal(80001);
2018
-
2019
- const amoyId = Transactions.get({ chain: 'MATIC' }).getChainId('amoy');
2020
- expect(amoyId).to.equal(80002);
2021
-
2022
- const regtestId = Transactions.get({ chain: 'MATIC' }).getChainId('regtest');
2023
- expect(regtestId).to.equal(13375);
2024
- });
2025
- });
2026
-
2027
- describe('ARC EVM support', () => {
2028
- it('should get the correct testnet chainId', () => {
2029
- const testnetId = Transactions.get({ chain: 'ARC' }).getChainId('testnet');
2030
- expect(testnetId).to.equal(5042002);
2031
- });
2032
-
2033
- it('should create an ARC native transaction using 18-decimal base units', () => {
2034
- const tx = Transactions.create({
2035
- chain: 'ARC',
2036
- recipients: [{ address: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A', amount: '1000000000000000000' }],
2037
- nonce: 0,
2038
- gasPrice: 1,
2039
- gasLimit: 21000,
2040
- network: 'testnet',
2041
- data: '0x'
2042
- });
2043
- const parsed = ethers.Transaction.from(tx);
2044
- expect(parsed.chainId).to.equal(5042002n);
2045
- expect(parsed.value).to.equal(1000000000000000000n);
2046
- });
2047
-
2048
- it('should create an ARC ERC20 transaction using ARC testnet chainId', () => {
2049
- const tokenAddress = '0x3600000000000000000000000000000000000000';
2050
- const recipient = '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A';
2051
- const amount = '1000000';
2052
- const tx = Transactions.create({
2053
- chain: 'ARCERC20',
2054
- recipients: [{ address: recipient, amount }],
2055
- nonce: 0,
2056
- gasPrice: 1,
2057
- gasLimit: 200000,
2058
- network: 'testnet',
2059
- tokenAddress
2060
- });
2061
- const parsed = ethers.Transaction.from(tx);
2062
-
2063
- expect(parsed.chainId).to.equal(5042002n);
2064
- expect(parsed.to).to.equal(ethers.getAddress(tokenAddress));
2065
- expect(parsed.value).to.equal(0n);
2066
- expect(parsed.data).to.equal(
2067
- '0xa9059cbb' +
2068
- '00000000000000000000000037d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a' +
2069
- '00000000000000000000000000000000000000000000000000000000000f4240'
2070
- );
2071
- });
2072
-
2073
- it('should define ARC native units as 18 decimals', () => {
2074
- expect(Constants.UNITS.arc.toSatoshis).to.equal(1e18);
2075
- expect(Constants.UNITS.arc.full.maxDecimals).to.equal(6);
2076
- expect(Constants.UNITS.arc.full.minDecimals).to.equal(6);
2077
- });
2078
- });
2079
-
2080
- describe('ETH _toHex', function() {
2081
- it('should convert number to hex string', function() {
2082
- const ETHTxProvider = Transactions.get({ chain: 'ETH' });
2083
- const result = ETHTxProvider._toHex(200000);
2084
- expect(result).to.equal('0x30d40');
2085
- });
2086
- it('should convert number string to hex string', function() {
2087
- const ETHTxProvider = Transactions.get({ chain: 'ETH' });
2088
- const result = ETHTxProvider._toHex('200000');
2089
- expect(result).to.equal('0x30d40');
2090
- });
2091
- it('should convert bigint to hex string', function() {
2092
- const ETHTxProvider = Transactions.get({ chain: 'ETH' });
2093
- const result = ETHTxProvider._toHex(200000n);
2094
- expect(result).to.equal('0x30d40');
2095
- });
2096
- it('should leave 0x-prefix hex string unchanged', function() {
2097
- const ETHTxProvider = Transactions.get({ chain: 'ETH' });
2098
- const result = ETHTxProvider._toHex('0x200000');
2099
- expect(result).to.equal('0x200000');
2100
- });
2101
-
2102
- });
2103
- });