Skip to content

Commit

Permalink
Merge pull request #111 from tronprotocol/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
unicornonea authored Sep 28, 2020
2 parents 97b5529 + 947146e commit f64f390
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ In order to contribute you can

## Recent History

__3.1.0__
- Update `elliptic` to the latest version 6.5.3
- Update `ethers` to the latest version 5.0.8
- Fix `loadAbi()`

__3.0.0__
- Support sidechain for SunNetwork
- Set feeLimit default value as 20 TRX
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tronweb",
"version": "3.0.0",
"version": "3.1.0",
"description": "JavaScript SDK that encapsulates the TRON HTTP API",
"main": "dist/TronWeb.node.js",
"scripts": {
Expand All @@ -25,8 +25,8 @@
"axios": "^0.19.0",
"babel-runtime": "^6.26.0",
"bignumber.js": "^7.2.1",
"elliptic": "^6.4.1",
"ethers": "^4.0.7",
"elliptic": "^6.5.3",
"ethers": "^5.0.8",
"eventemitter3": "^3.1.0",
"injectpromise": "^1.0.0",
"lodash": "^4.17.14",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/contract/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export default class Contract {
this.bytecode = contract.bytecode;
this.deployed = true;

this.loadAbi(contract.abi ? contract.abi.entrys : []);
this.loadAbi(contract.abi ? contract.abi.entrys ? contract.abi.entrys : [] : []);

return callback(null, this);
} catch (ex) {
Expand Down
11 changes: 7 additions & 4 deletions src/lib/trx.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,22 +710,25 @@ export default class Trx {

static signString(message, privateKey, useTronHeader = true) {
message = message.replace(/^0x/, '');
const signingKey = new SigningKey(privateKey);
const value ={
toHexString: function() {
return '0x' + privateKey
},
value: privateKey
}
const signingKey = new SigningKey(value);
const messageBytes = [
...toUtf8Bytes(useTronHeader ? TRX_MESSAGE_HEADER : ETH_MESSAGE_HEADER),
...utils.code.hexStr2byteArray(message)
];

const messageDigest = keccak256(messageBytes);
const signature = signingKey.signDigest(messageDigest);

const signatureHex = [
'0x',
signature.r.substring(2),
signature.s.substring(2),
Number(signature.v).toString(16)
].join('');

return signatureHex
}

Expand Down
2 changes: 1 addition & 1 deletion test/lib/transactionBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ describe('TronWeb.transactionBuilder', function () {
const tx = await tronWeb.transactionBuilder.createSmartContract(options)
assert.equal(tx.raw_data.contract[0].parameter.value.new_contract.consume_user_resource_percent, 100);
assert.equal(tx.raw_data.contract[0].parameter.value.new_contract.origin_energy_limit, 1e7);
assert.equal(tx.raw_data.fee_limit, 1e9);
assert.equal(tx.raw_data.fee_limit, 2e7);
assert.equal(tx.raw_data.contract[0].Permission_id || 0, options.permissionId || 0);
}
});
Expand Down
5 changes: 2 additions & 3 deletions test/utils/abi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ describe('TronWeb.utils.abi', function () {
const types = ['string', 'string', 'uint8', 'bytes32', 'uint256'];
const output =
'00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000012dc03b7993bad736ad595eb9e3ba51877ac17ecc31d2355f8f270125b9427ece700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011506920446179204e30306220546f6b656e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035049450000000000000000000000000000000000000000000000000000000000';

assert.throws(() => {
tronWeb.utils.abi.decodeParams(types, output)
}, 'hex string must have 0x prefix');
}, 'invalid arrayify value');
});

it('should throw if the output format is wrong', function () {
Expand All @@ -70,7 +69,7 @@ describe('TronWeb.utils.abi', function () {

assert.throws(() => {
tronWeb.utils.abi.decodeParams(types, output)
}, 'dynamic bytes count too large');
}, 'overflow');
});

it('should throw if the output is invalid', function () {
Expand Down

0 comments on commit f64f390

Please sign in to comment.