@@ -27,6 +27,7 @@ const utxoNetworks = {
27
27
const coinDecimals = {
28
28
btc : 8 ,
29
29
eth : 18 ,
30
+ eos : 4 ,
30
31
xrp : 6 ,
31
32
bch : 8 ,
32
33
bsv : 8 ,
@@ -36,6 +37,7 @@ const coinDecimals = {
36
37
xlm : 7 ,
37
38
tbtc : 8 ,
38
39
teth : 18 ,
40
+ teos : 4 ,
39
41
txrp : 6 ,
40
42
tltc : 8 ,
41
43
txlm : 7 ,
@@ -48,6 +50,9 @@ const coinDecimals = {
48
50
const BCH_COINS = [ 'bch' , 'tbch' , 'bsv' , 'tbsv' ] ;
49
51
const TEN = new BN ( 10 ) ;
50
52
53
+ const EOS_MAINNET_CHAIN_ID = 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906' ;
54
+ const EOS_TESTNET_CHAIN_ID = 'e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473' ;
55
+
51
56
const confirmRecovery = function ( backupKey , outputs , customMessage , skipConfirm ) {
52
57
console . log ( 'Sign Recovery Transaction' ) ;
53
58
console . log ( '=========================' ) ;
@@ -199,6 +204,49 @@ const handleSignEthereum = function(recoveryRequest, key, skipConfirm) {
199
204
return transaction . serialize ( ) . toString ( 'hex' ) ;
200
205
} ;
201
206
207
+ const handleSignEos = function ( recoveryRequest , key , skipConfirm ) {
208
+ const EosJs = require ( 'eosjs' ) ;
209
+ const ecc = require ( 'eosjs-ecc' ) ;
210
+ let chainId ;
211
+ if ( recoveryRequest . coin === 'eos' ) {
212
+ chainId = EOS_MAINNET_CHAIN_ID ;
213
+ } else {
214
+ chainId = EOS_TESTNET_CHAIN_ID ;
215
+ }
216
+
217
+ const sendableTxJsonString = getTransactionHexFromRequest ( recoveryRequest ) ;
218
+ const eosTx = JSON . parse ( sendableTxJsonString ) ;
219
+ const packed_trx = eosTx . packed_trx ;
220
+
221
+ const { recipient, amount } = utils . deserializeEOSTransaction ( EosJs , packed_trx ) ;
222
+
223
+ const customMessage = recoveryRequest . custom ? recoveryRequest . custom . message : 'None' ;
224
+
225
+ const outputs = [ {
226
+ address : recipient ,
227
+ amount : new BN ( amount )
228
+ } ] ;
229
+
230
+ confirmRecovery ( recoveryRequest . backupKey , outputs , customMessage , skipConfirm ) ;
231
+
232
+ if ( ! key ) {
233
+ console . log ( 'Please enter the xprv of the wallet for signing: ' ) ;
234
+ key = prompt ( ) ;
235
+ }
236
+
237
+ const backupKeyNode = getHDNodeAndVerify ( key , recoveryRequest . backupKey ) ;
238
+
239
+ const dataToSign = utils . getEOSSignatureData ( packed_trx , chainId ) ;
240
+ const signBuffer = Buffer . from ( dataToSign , 'hex' ) ;
241
+ const privateKeyBuffer = backupKeyNode . keyPair . getPrivateKeyBuffer ( ) ;
242
+ const signature = ecc . Signature . sign ( signBuffer , privateKeyBuffer ) . toString ( ) ;
243
+
244
+ eosTx . signatures . push ( signature ) ;
245
+
246
+ // EOS txHex is a stringified JSON containing the signatures array
247
+ return JSON . stringify ( eosTx ) ;
248
+ } ;
249
+
202
250
const handleSignXrp = function ( recoveryRequest , key , skipConfirm ) {
203
251
const rippleLib = require ( 'ripple-lib' ) ;
204
252
const rippleApi = new rippleLib . RippleAPI ( ) ;
@@ -403,6 +451,9 @@ const handleSign = function(args) {
403
451
}
404
452
}
405
453
break ;
454
+ case 'eos' :
455
+ txHex = handleSignEos ( recoveryRequest , key , args . confirm ) ;
456
+ break ;
406
457
case 'xrp' :
407
458
txHex = handleSignXrp ( recoveryRequest , key , args . confirm ) ;
408
459
break ;
@@ -438,4 +489,4 @@ const handleSign = function(args) {
438
489
return finalRecovery ;
439
490
} ;
440
491
441
- module . exports = { handleSign, handleSignUtxo, handleSignEthereum, handleSignXrp, handleSignXlm, handleSignErc20, parseKey } ;
492
+ module . exports = { handleSign, handleSignUtxo, handleSignEthereum, handleSignXrp, handleSignXlm, handleSignErc20, handleSignEos , parseKey } ;
0 commit comments