Skip to content

Commit d871b1f

Browse files
committed
switch to main net address format
1 parent feaa400 commit d871b1f

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tronscan/client",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"description": "Tronscan API Client",
55
"main": "src/index.js",
66
"homepage": "https://api.tronscan.org/",

src/utils/address.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
const ADDRESS_PREFIX = "a0";
2-
const ADDRESS_SIZE = 42;
1+
let isTestNet = process.env.NET === 'testnet';
32

3+
const ADDRESS_SIZE = 42;
4+
const ADDRESS_PREFIX = isTestNet ? "a0" : "41";
5+
const ADDRESS_PREFIX_BYTE = isTestNet ? 0xa0 : 0x41;
46

57
function isAddressValid(address) {
68

@@ -21,4 +23,7 @@ function isAddressValid(address) {
2123

2224
module.exports = {
2325
isAddressValid,
26+
ADDRESS_SIZE,
27+
ADDRESS_PREFIX,
28+
ADDRESS_PREFIX_BYTE,
2429
};

src/utils/crypto.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const {ADDRESS_PREFIX, ADDRESS_PREFIX_BYTE} = require("./address");
12
const base64EncodeToString = require("../lib/code").base64EncodeToString;
23
const {base64DecodeFromString, hexStr2byteArray} = require("../lib/code");
34
const {encode58, decode58} = require("../lib/base58");
@@ -6,10 +7,6 @@ const { keccak256 } = require('js-sha3');
67
const jsSHA = require("../lib/sha256");
78
const { byte2hexStr, byteArray2hexStr } = require("./bytes");
89

9-
const add_pre_fix = 'a0'; //a0 + address ,a0 is version
10-
const add_pre_fix_byte = 0xa0; //a0 + address ,a0 is version
11-
12-
1310
/**
1411
* Sign A Transaction by priKey.
1512
* signature is 65 bytes, r[32] || s[32] || id[1](<27)
@@ -84,7 +81,7 @@ function computeAddress(pubBytes) {
8481

8582
var hash = keccak256(pubBytes).toString();
8683
var addressHex = hash.substring(24);
87-
addressHex = add_pre_fix + addressHex;
84+
addressHex = ADDRESS_PREFIX + addressHex;
8885
var addressBytes = hexStr2byteArray(addressHex);
8986
return addressBytes;
9087
}
@@ -140,7 +137,7 @@ function isAddressValid(base58Sting) {
140137
if (address.length != 25) {
141138
return false;
142139
}
143-
if (address[0] != add_pre_fix_byte) {
140+
if (address[0] != ADDRESS_PREFIX_BYTE) {
144141
return false;
145142
}
146143
var checkSum = address.slice(21);

0 commit comments

Comments
 (0)