@@ -90,7 +90,8 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
90
90
throw new Error ( `Unsupported coin: ${ recoveryRequest . coin } ` ) ;
91
91
}
92
92
93
- const transaction = utxoLib . Transaction . fromHex ( recoveryRequest . transactionHex , network ) ;
93
+ const txHex = getTransactionHexFromRequest ( recoveryRequest ) ;
94
+ const transaction = utxoLib . Transaction . fromHex ( txHex , network ) ;
94
95
95
96
const outputs = transaction . outs . map ( out => ( {
96
97
address : utxoLib . address . fromOutputScript ( out . script , network ) ,
@@ -160,7 +161,8 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
160
161
const handleSignEthereum = function ( recoveryRequest , key , skipConfirm ) {
161
162
const EthTx = require ( 'ethereumjs-tx' ) ;
162
163
163
- const transaction = new EthTx ( recoveryRequest . tx ) ;
164
+ const txHex = getTransactionHexFromRequest ( recoveryRequest ) ;
165
+ const transaction = new EthTx ( txHex ) ;
164
166
const decimals = coinDecimals [ recoveryRequest . coin ] ;
165
167
166
168
const customMessage = recoveryRequest . custom ? recoveryRequest . custom . message : 'None' ;
@@ -192,8 +194,10 @@ const handleSignXrp = function(recoveryRequest, key, skipConfirm) {
192
194
const rippleKeypairs = require ( 'ripple-keypairs' ) ;
193
195
const rippleParse = require ( 'ripple-binary-codec' ) ;
194
196
197
+ const txHex = getTransactionHexFromRequest ( recoveryRequest ) ;
198
+
195
199
const decimals = coinDecimals [ recoveryRequest . coin ] ;
196
- const transaction = rippleParse . decode ( recoveryRequest . tx ) ;
200
+ const transaction = rippleParse . decode ( txHex ) ;
197
201
const customMessage = recoveryRequest . custom ? recoveryRequest . custom . message : 'None' ;
198
202
199
203
const outputs = [ {
@@ -212,9 +216,9 @@ const handleSignXrp = function(recoveryRequest, key, skipConfirm) {
212
216
213
217
const backupAddress = rippleKeypairs . deriveAddress ( backupKeyNode . keyPair . getPublicKeyBuffer ( ) . toString ( 'hex' ) ) ;
214
218
const privateKeyHex = backupKeyNode . keyPair . getPrivateKeyBuffer ( ) . toString ( 'hex' ) ;
215
- const cosignedTx = utils . signXrpWithPrivateKey ( recoveryRequest . txHex , privateKeyHex , { signAs : backupAddress } ) ;
219
+ const cosignedTx = utils . signXrpWithPrivateKey ( txHex , privateKeyHex , { signAs : backupAddress } ) ;
216
220
217
- return rippleApi . combine ( [ recoveryRequest . txHex , cosignedTx . signedTransaction ] ) . signedTransaction ;
221
+ return rippleApi . combine ( [ txHex , cosignedTx . signedTransaction ] ) . signedTransaction ;
218
222
} ;
219
223
220
224
const handleSignXlm = function ( recoveryRequest , key , skipConfirm ) {
@@ -228,7 +232,8 @@ const handleSignXlm = function(recoveryRequest, key, skipConfirm) {
228
232
229
233
const decimals = coinDecimals [ recoveryRequest . coin ] ;
230
234
231
- const transaction = new stellar . Transaction ( recoveryRequest . tx ) ;
235
+ const txHex = getTransactionHexFromRequest ( recoveryRequest ) ;
236
+ const transaction = new stellar . Transaction ( txHex ) ;
232
237
const customMessage = recoveryRequest . custom ? recoveryRequest . custom . message : 'None' ;
233
238
234
239
if ( transaction . operations . length !== 1 ) {
@@ -271,7 +276,8 @@ const handleSignXlm = function(recoveryRequest, key, skipConfirm) {
271
276
const handleSignErc20 = function ( recoveryRequest , key , skipConfirm ) {
272
277
const EthTx = require ( 'ethereumjs-tx' ) ;
273
278
274
- const transaction = new EthTx ( recoveryRequest . tx ) ;
279
+ const txHex = getTransactionHexFromRequest ( recoveryRequest ) ;
280
+ const transaction = new EthTx ( txHex ) ;
275
281
276
282
const customMessage = recoveryRequest . custom ? recoveryRequest . custom . message : 'None' ;
277
283
const txData = transaction . data ;
@@ -327,6 +333,23 @@ const parseKey = function(rawkey, coin, path) {
327
333
return rawkey ;
328
334
}
329
335
336
+ /**
337
+ Not all recoveryRequest files are formatted the same. Sometimes they have 'tx', 'txHex', or 'transactionHex'
338
+ This function gets and gets and returns the transaction hex in all of these cases
339
+ */
340
+ const getTransactionHexFromRequest = function ( recoveryRequest ) {
341
+ if ( recoveryRequest . txHex ) {
342
+ return recoveryRequest . txHex
343
+ }
344
+ if ( recoveryRequest . transactionHex ) {
345
+ return recoveryRequest . transactionHex
346
+ }
347
+ if ( recoveryRequest . tx ) {
348
+ return recoveryRequest . tx
349
+ }
350
+ throw new Error ( "The recovery request did not provide a transaction hex" ) ;
351
+ }
352
+
330
353
const handleSign = function ( args ) {
331
354
const file = args . file ;
332
355
0 commit comments