Skip to content

Commit a55d5e6

Browse files
author
Mark Toda
committed
[TRON-58] Add KRS Support for TRON
Adds @bitgo/account-lib dependency Adds signing helper for TRON Adds a test for signing a TRON tx
1 parent dba9fee commit a55d5e6

File tree

5 files changed

+448
-13
lines changed

5 files changed

+448
-13
lines changed

app/sign.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const utxoLib = require('bitgo-utxo-lib');
2+
const accountLib = require('@bitgo/account-lib');
23
const prova = require('prova-lib');
34
const fs = require('fs');
45
const _ = require('lodash');
@@ -28,6 +29,7 @@ const coinDecimals = {
2829
btc: 8,
2930
eth: 18,
3031
eos: 4,
32+
trx: 6,
3133
xrp: 6,
3234
bch: 8,
3335
bsv: 8,
@@ -38,6 +40,7 @@ const coinDecimals = {
3840
tbtc: 8,
3941
teth: 18,
4042
teos: 4,
43+
ttrx: 6,
4144
txrp: 6,
4245
tltc: 8,
4346
txlm: 7,
@@ -204,6 +207,38 @@ const handleSignEthereum = function(recoveryRequest, key, skipConfirm) {
204207
return transaction.serialize().toString('hex');
205208
};
206209

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+
207242
const handleSignEos = function(recoveryRequest, key, skipConfirm) {
208243
const EosJs = require('eosjs');
209244
const ecc = require('eosjs-ecc');
@@ -454,6 +489,9 @@ const handleSign = function(args) {
454489
case 'eos':
455490
txHex = handleSignEos(recoveryRequest, key, args.confirm);
456491
break;
492+
case 'trx':
493+
txHex = handleSignTrx(recoveryRequest, key, args.confirm);
494+
break;
457495
case 'xrp':
458496
txHex = handleSignXrp(recoveryRequest, key, args.confirm);
459497
break;
@@ -489,4 +527,4 @@ const handleSign = function(args) {
489527
return finalRecovery;
490528
};
491529

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

Comments
 (0)