1
1
const utxoLib = require ( 'bitgo-utxo-lib' ) ;
2
+ const accountLib = require ( '@bitgo/account-lib' ) ;
2
3
const prova = require ( 'prova-lib' ) ;
3
4
const fs = require ( 'fs' ) ;
4
5
const _ = require ( 'lodash' ) ;
@@ -28,6 +29,7 @@ const coinDecimals = {
28
29
btc : 8 ,
29
30
eth : 18 ,
30
31
eos : 4 ,
32
+ trx : 6 ,
31
33
xrp : 6 ,
32
34
bch : 8 ,
33
35
bsv : 8 ,
@@ -38,6 +40,7 @@ const coinDecimals = {
38
40
tbtc : 8 ,
39
41
teth : 18 ,
40
42
teos : 4 ,
43
+ ttrx : 6 ,
41
44
txrp : 6 ,
42
45
tltc : 8 ,
43
46
txlm : 7 ,
@@ -204,6 +207,38 @@ const handleSignEthereum = function(recoveryRequest, key, skipConfirm) {
204
207
return transaction . serialize ( ) . toString ( 'hex' ) ;
205
208
} ;
206
209
210
+ const handleSignTrx = function ( recoveryRequest , key , skipConfirm ) {
211
+ const coin = recoveryRequest . coin ;
212
+
213
+ const txHex = getTransactionHexFromRequest ( recoveryRequest ) ;
214
+ const builder = new accountLib . TransactionBuilder ( { coinName : coin } ) ;
215
+ builder . from ( txHex ) ;
216
+
217
+ const customMessage = recoveryRequest . custom ? recoveryRequest . custom . message : 'None' ;
218
+
219
+ const outputs = builder . build ( ) . destinations . map ( d => {
220
+ return {
221
+ address : d . address ,
222
+ amount : d . value . toString ( 10 )
223
+ } ;
224
+ } ) ;
225
+
226
+ confirmRecovery ( recoveryRequest . backupKey , outputs , customMessage , skipConfirm ) ;
227
+
228
+ if ( ! key ) {
229
+ console . log ( 'Please enter the xprv of the wallet for signing: ' ) ;
230
+ key = prompt ( ) ;
231
+ }
232
+
233
+ const backupKeyNode = getHDNodeAndVerify ( key , recoveryRequest . backupKey ) ;
234
+ try {
235
+ builder . sign ( { key : backupKeyNode . keyPair . getPrivateKeyBuffer ( ) } ) ;
236
+ } catch ( e ) {
237
+ console . log ( e ) ;
238
+ }
239
+ return JSON . stringify ( builder . build ( ) . toJson ( ) ) ;
240
+ } ;
241
+
207
242
const handleSignEos = function ( recoveryRequest , key , skipConfirm ) {
208
243
const EosJs = require ( 'eosjs' ) ;
209
244
const ecc = require ( 'eosjs-ecc' ) ;
@@ -454,6 +489,9 @@ const handleSign = function(args) {
454
489
case 'eos' :
455
490
txHex = handleSignEos ( recoveryRequest , key , args . confirm ) ;
456
491
break ;
492
+ case 'trx' :
493
+ txHex = handleSignTrx ( recoveryRequest , key , args . confirm ) ;
494
+ break ;
457
495
case 'xrp' :
458
496
txHex = handleSignXrp ( recoveryRequest , key , args . confirm ) ;
459
497
break ;
@@ -489,4 +527,4 @@ const handleSign = function(args) {
489
527
return finalRecovery ;
490
528
} ;
491
529
492
- module . exports = { handleSign, handleSignUtxo, handleSignEthereum, handleSignXrp, handleSignXlm, handleSignErc20, handleSignEos, parseKey } ;
530
+ module . exports = { handleSign, handleSignUtxo, handleSignEthereum, handleSignXrp, handleSignXlm, handleSignErc20, handleSignEos, handleSignTrx , parseKey } ;
0 commit comments