Skip to content

Commit 0c5fb8d

Browse files
committed
Fix issue: keyconv can not handle TRON private key
1 parent 13ca827 commit 0c5fb8d

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

pattern.c

-7
Original file line numberDiff line numberDiff line change
@@ -578,13 +578,6 @@ vg_output_match_console(vg_context_t *vcp, EC_KEY *pkey, const char *pattern)
578578
tickerlength=(strlen(ticker)-1);
579579
}
580580

581-
if (strncmp(ticker, "TRX", 3) == 0) {
582-
// For tron, output hex string for private key
583-
char *buf = BN_bn2hex(EC_KEY_get0_private_key(pkey));
584-
strcpy(privkey_buf, buf);
585-
if (buf) OPENSSL_free(buf);
586-
}
587-
588581
if (!vcp->vc_result_file || (vcp->vc_verbose > 0)) {
589582
if (vcp->vc_csv) {
590583
printf("\r%79s\r%.*s,%s,", "", tickerlength, ticker, pattern);

util.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "util.h"
4242
#include "sph_groestl.h"
4343
#include "sha3.h"
44+
#include "ticker.h"
4445

4546
const char *vg_b58_alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
4647

@@ -399,6 +400,13 @@ vg_encode_privkey(const EC_KEY *pkey, int privtype, char *result)
399400
result[len+2] = '\0';
400401
return;
401402
}
403+
if (strncmp(ticker, "TRX", 3) == 0) {
404+
// For tron, private key is just hex string without prefix 0x
405+
char *buf = BN_bn2hex(bn); // Must be freed later using OPENSSL_free
406+
strcpy(result, buf);
407+
if (buf) OPENSSL_free(buf);
408+
return;
409+
}
402410

403411
vg_b58_encode_check(eckey_buf, 33, result);
404412
}
@@ -989,8 +997,9 @@ vg_decode_privkey_any(EC_KEY *pkey, int *addrtype, const char *input,
989997
{
990998
int res;
991999

992-
// For ETH
993-
if (*addrtype == ADDR_TYPE_ETH) {
1000+
// For ETH, private key is just hex string
1001+
// For TRON, private key is just hex string
1002+
if (*addrtype == ADDR_TYPE_ETH || strncmp(ticker, "TRX", 3) == 0) {
9941003
BIGNUM * bnpriv = BN_new();
9951004

9961005
uint8_t bin[64];

0 commit comments

Comments
 (0)