@@ -158,6 +158,10 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
158
158
return txBuilder . build ( ) . toHex ( ) ;
159
159
} ;
160
160
161
+ const handleHalfSignEth = function ( recoveryRequest , key , skipConfirm ) {
162
+ return utils . halfSignEthTransaction ( recoveryRequest . coin , recoveryRequest . txPrebuild , key ) ;
163
+ }
164
+
161
165
const handleSignEthereum = function ( recoveryRequest , key , skipConfirm ) {
162
166
const EthTx = require ( 'ethereumjs-tx' ) ;
163
167
@@ -330,6 +334,11 @@ const parseKey = function(rawkey, coin, path) {
330
334
331
335
}
332
336
// if it doesn't have commas, we expect it is an xprv or xlmsecret properly formatted
337
+ if ( path ) {
338
+ let node = utxoLib . HDNode . fromPrivateKeyBuffer ( Buffer . from ( rawkey , 'hex' ) ) ;
339
+ node = node . derivePath ( path ) ;
340
+ return node . toBase58 ( ) ;
341
+ }
333
342
return rawkey ;
334
343
}
335
344
@@ -363,36 +372,56 @@ const handleSign = function(args) {
363
372
364
373
const key = parseKey ( args . key , coin , args . path ) ;
365
374
366
- let txHex ;
375
+ let txHex , halfSignedInfo ;
367
376
368
377
switch ( coin ) {
369
378
case 'eth' : case 'teth' :
370
- txHex = handleSignEthereum ( recoveryRequest , key , args . confirm ) ;
379
+ if ( recoveryRequest . txPrebuild ) {
380
+ halfSignedInfo = handleHalfSignEth ( recoveryRequest , key , args . confirm ) ;
381
+ } else {
382
+ txHex = handleSignEthereum ( recoveryRequest , key , args . confirm ) ;
383
+ }
371
384
break ;
372
385
case 'xrp' : case 'txrp' :
373
386
txHex = handleSignXrp ( recoveryRequest , key , args . confirm ) ;
374
387
break ;
375
388
case 'xlm' : case 'txlm' :
376
389
txHex = handleSignXlm ( recoveryRequest , key , args . confirm ) ;
377
390
break ;
378
- case 'erc20' :
379
- txHex = handleSignErc20 ( recoveryRequest , key , args . confirm ) ;
391
+ case 'erc20' : case 'terc20' : case 'terc' : case 'erc' :
392
+ if ( recoveryRequest . txPrebuild ) {
393
+ halfSignedInfo = handleHalfSignEth ( recoveryRequest , key , args . confirm ) ;
394
+ } else {
395
+ txHex = handleSignErc20 ( recoveryRequest , key , args . confirm ) ;
396
+ }
380
397
break ;
381
398
default :
382
399
txHex = handleSignUtxo ( recoveryRequest , key , args . confirm ) ;
383
400
break ;
384
401
}
385
402
386
- console . log ( `Signed transaction hex: ${ txHex } ` ) ;
403
+ if ( txHex ) {
404
+ console . log ( `Signed transaction hex: ${ txHex } ` ) ;
405
+ }
387
406
388
407
const filename = file . replace ( / \. [ ^ / . ] + $ / , '' ) + '.signed.json' ;
389
408
console . log ( `Writing signed transaction to file: ${ filename } ` ) ;
390
409
391
- const finalRecovery = _ . pick ( recoveryRequest , [ 'backupKey' , 'coin' , 'recoveryAmount' ] ) ;
392
- finalRecovery . txHex = txHex ;
410
+ let finalRecovery ;
411
+
412
+ if ( txHex ) {
413
+ finalRecovery = _ . pick ( recoveryRequest , [ 'backupKey' , 'coin' , 'recoveryAmount' ] ) ;
414
+ finalRecovery . txHex = txHex ;
415
+ } else {
416
+ finalRecovery = halfSignedInfo ;
417
+ }
393
418
394
- fs . writeFileSync ( filename , JSON . stringify ( finalRecovery , null , 2 ) ) ;
395
- console . log ( 'Done' ) ;
419
+ const fileStr = JSON . stringify ( finalRecovery , null , 2 ) ;
420
+ if ( ! args . noWrite ) {
421
+ fs . writeFileSync ( filename , fileStr ) ;
422
+ console . log ( 'Done' ) ;
423
+ }
424
+ return finalRecovery ;
396
425
} ;
397
426
398
427
module . exports = { handleSign, handleSignUtxo, handleSignEthereum, handleSignXrp, handleSignXlm, handleSignErc20, parseKey } ;
0 commit comments