Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@harmony-js/transaction

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@harmony-js/transaction - npm Package Compare versions

Comparing version 0.0.54 to 0.0.60

tsconfig.tsbuildinfo

151

dist/index.cjs.js

@@ -143,4 +143,4 @@ /**

from: '0x',
txnHash: '0x',
unsignedTxnHash: '0x',
rawTransaction: '0x',
unsignedRawTransaction: '0x',
nonce: new crypto.BN(utils.strip0x(handleNumber(transaction[0]))).toNumber(),

@@ -151,3 +151,5 @@ gasPrice: new crypto.BN(utils.strip0x(handleNumber(transaction[1]))),

toShardID: new crypto.BN(utils.strip0x(handleNumber(transaction[4]))).toNumber(),
to: handleAddress(transaction[5]),
to: handleAddress(transaction[5]) !== '0x'
? crypto.getAddress(handleAddress(transaction[5])).checksum
: '0x',
value: new crypto.BN(utils.strip0x(handleNumber(transaction[6]))),

@@ -165,3 +167,3 @@ data: transaction[7],

if (transaction.length === 8) {
tx.unsignedTxnHash = rawTransaction;
tx.unsignedRawTransaction = rawTransaction;
return tx;

@@ -199,3 +201,3 @@ }

try {
tx.from = crypto.recoverAddress(digest, {
var recoveredFrom = crypto.recoverAddress(digest, {
r: crypto.hexlify(tx.signature.r),

@@ -205,2 +207,4 @@ s: crypto.hexlify(tx.signature.s),

});
tx.from =
recoveredFrom === '0x' ? '0x' : crypto.getAddress(recoveredFrom).checksum;
}

@@ -210,3 +214,3 @@ catch (error) {

}
tx.txnHash = crypto.keccak256(rawTransaction);
tx.rawTransaction = crypto.keccak256(rawTransaction);
}

@@ -223,4 +227,4 @@ return tx;

from: '0x',
txnHash: '0x',
unsignedTxnHash: '0x',
rawTransaction: '0x',
unsignedRawTransaction: '0x',
nonce: new crypto.BN(utils.strip0x(handleNumber(transaction[0]))).toNumber(),

@@ -231,3 +235,5 @@ gasPrice: new crypto.BN(utils.strip0x(handleNumber(transaction[1]))),

toShardID: 0,
to: handleAddress(transaction[3]),
to: handleAddress(transaction[3]) !== '0x'
? crypto.getAddress(handleAddress(transaction[3])).checksum
: '0x',
value: new crypto.BN(utils.strip0x(handleNumber(transaction[4]))),

@@ -245,3 +251,3 @@ data: transaction[5],

if (transaction.length === 6) {
tx.unsignedTxnHash = rawTransaction;
tx.unsignedRawTransaction = rawTransaction;
return tx;

@@ -279,3 +285,3 @@ }

try {
tx.from = crypto.recoverAddress(digest, {
var recoveredFrom = crypto.recoverAddress(digest, {
r: crypto.hexlify(tx.signature.r),

@@ -285,2 +291,4 @@ s: crypto.hexlify(tx.signature.s),

});
tx.from =
recoveredFrom === '0x' ? '0x' : crypto.getAddress(recoveredFrom).checksum;
}

@@ -290,3 +298,3 @@ catch (error) {

}
tx.txnHash = crypto.keccak256(rawTransaction);
tx.rawTransaction = crypto.keccak256(rawTransaction);
}

@@ -310,6 +318,6 @@ return tx;

var RLPSign = function (transaction, prv) {
var _a = __read(transaction.getRLPUnsigned(), 2), unsignedTxnHash = _a[0], raw = _a[1];
var regroup = __assign({}, transaction.txParams, { unsignedTxnHash: unsignedTxnHash });
var _a = __read(transaction.getRLPUnsigned(), 2), unsignedRawTransaction = _a[0], raw = _a[1];
var regroup = __assign({}, transaction.txParams, { unsignedRawTransaction: unsignedRawTransaction });
transaction.setParams(regroup);
var signature = crypto.sign(crypto.keccak256(unsignedTxnHash), prv);
var signature = crypto.sign(crypto.keccak256(unsignedRawTransaction), prv);
var signed = transaction.getRLPSigned(raw, signature);

@@ -331,25 +339,31 @@ return [signature, signed];

// intialize transaction
this.id = params ? params.id : '0x';
this.from = params ? params.from : '0x';
this.nonce = params ? params.nonce : 0;
this.gasPrice = params ? params.gasPrice : new crypto.BN(0);
this.gasLimit = params ? params.gasLimit : new crypto.BN(0);
this.shardID = params ? params.shardID : 0;
this.toShardID = params ? params.toShardID : 0;
this.to = params ? this.normalizeAddress(params.to) : '0x';
this.value = params ? params.value : new crypto.BN(0);
this.data = params ? params.data : '0x';
this.id = params && params.id ? params.id : '0x';
this.from = params && params.from ? params.from : '0x';
this.nonce = params && params.nonce ? params.nonce : 0;
this.gasPrice = params && params.gasPrice ? params.gasPrice : new crypto.BN(0);
this.gasLimit = params && params.gasLimit ? params.gasLimit : new crypto.BN(0);
this.shardID = params && params.shardID ? params.shardID : 0;
this.toShardID = params && params.toShardID ? params.toShardID : 0;
this.to = params && params.to ? this.normalizeAddress(params.to) : '0x';
this.value = params && params.value ? params.value : new crypto.BN(0);
this.data = params && params.data ? params.data : '0x';
// chainid should change with different network settings
this.chainId = params ? params.chainId : this.messenger.chainId;
this.txnHash = params ? params.txnHash : '0x';
this.unsignedTxnHash = params ? params.unsignedTxnHash : '0x';
this.signature = params
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
this.receipt = params ? params.receipt : undefined;
this.chainId =
params && params.chainId ? params.chainId : this.messenger.chainId;
this.rawTransaction =
params && params.rawTransaction ? params.rawTransaction : '0x';
this.unsignedRawTransaction =
params && params.unsignedRawTransaction
? params.unsignedRawTransaction
: '0x';
this.signature =
params && params.signature
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
this.receipt = params && params.receipt ? params.receipt : undefined;
}

@@ -408,7 +422,7 @@ Transaction.prototype.setMessenger = function (messenger) {

};
Transaction.prototype.recover = function (txnHash) {
Transaction.prototype.recover = function (rawTransaction) {
// temp setting to be compatible with eth
var recovered = this.messenger.chainType === "hmy" /* Harmony */
? recover(txnHash)
: recoverETH(txnHash);
? recover(rawTransaction)
: recoverETH(rawTransaction);
this.setParams(recovered);

@@ -451,4 +465,4 @@ return this;

chainId: this.chainId || 0,
txnHash: this.txnHash || '0x',
unsignedTxnHash: this.unsignedTxnHash || '0x',
rawTransaction: this.rawTransaction || '0x',
unsignedRawTransaction: this.unsignedRawTransaction || '0x',
signature: this.signature || '0x',

@@ -461,24 +475,29 @@ };

Transaction.prototype.setParams = function (params) {
this.id = params ? params.id : '0x';
this.from = params ? params.from : '0x';
this.nonce = params ? params.nonce : 0;
this.gasPrice = params ? params.gasPrice : new crypto.BN(0);
this.gasLimit = params ? params.gasLimit : new crypto.BN(0);
this.shardID = params ? params.shardID : 0;
this.toShardID = params ? params.toShardID : 0;
this.to = params ? this.normalizeAddress(params.to) : '0x';
this.value = params ? params.value : new crypto.BN(0);
this.data = params ? params.data : '0x';
this.chainId = params ? params.chainId : 0;
this.txnHash = params ? params.txnHash : '0x';
this.unsignedTxnHash = params ? params.unsignedTxnHash : '0x';
this.signature = params
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
if (this.txnHash !== '0x') {
this.id = params && params.id ? params.id : '0x';
this.from = params && params.from ? params.from : '0x';
this.nonce = params && params.nonce ? params.nonce : 0;
this.gasPrice = params && params.gasPrice ? params.gasPrice : new crypto.BN(0);
this.gasLimit = params && params.gasLimit ? params.gasLimit : new crypto.BN(0);
this.shardID = params && params.shardID ? params.shardID : 0;
this.toShardID = params && params.toShardID ? params.toShardID : 0;
this.to = params && params.to ? this.normalizeAddress(params.to) : '0x';
this.value = params && params.value ? params.value : new crypto.BN(0);
this.data = params && params.data ? params.data : '0x';
this.chainId = params && params.chainId ? params.chainId : 0;
this.rawTransaction =
params && params.rawTransaction ? params.rawTransaction : '0x';
this.unsignedRawTransaction =
params && params.unsignedRawTransaction
? params.unsignedRawTransaction
: '0x';
this.signature =
params && params.signature
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
if (this.rawTransaction !== '0x') {
this.setTxStatus("SIGNED" /* SIGNED */);

@@ -527,3 +546,3 @@ }

// TODO: we use eth RPC setting for now, incase we have other params, we should add here
if (this.txnHash === 'tx' || this.txnHash === undefined) {
if (this.rawTransaction === 'tx' || this.rawTransaction === undefined) {
throw new Error('Transaction not signed');

@@ -534,3 +553,3 @@ }

}
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.txnHash)];
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.rawTransaction)];
case 1:

@@ -537,0 +556,0 @@ res = _a.sent();

@@ -6,3 +6,3 @@ /**

import { hexToNumber, isHex, isAddress, strip0x, add0xToString, numberToHex } from '@harmony-js/utils';
import { decode, encode, keccak256, hexlify, BN, hexZeroPad, recoverAddress, sign, arrayify, stripZeros, splitSignature, getAddress, HarmonyAddress, getContractAddress } from '@harmony-js/crypto';
import { decode, encode, keccak256, hexlify, BN, hexZeroPad, recoverAddress, getAddress, sign, arrayify, stripZeros, splitSignature, HarmonyAddress, getContractAddress } from '@harmony-js/crypto';
import { HttpProvider, Messenger, Emitter, NewHeaders } from '@harmony-js/network';

@@ -140,4 +140,4 @@

from: '0x',
txnHash: '0x',
unsignedTxnHash: '0x',
rawTransaction: '0x',
unsignedRawTransaction: '0x',
nonce: new BN(strip0x(handleNumber(transaction[0]))).toNumber(),

@@ -148,3 +148,5 @@ gasPrice: new BN(strip0x(handleNumber(transaction[1]))),

toShardID: new BN(strip0x(handleNumber(transaction[4]))).toNumber(),
to: handleAddress(transaction[5]),
to: handleAddress(transaction[5]) !== '0x'
? getAddress(handleAddress(transaction[5])).checksum
: '0x',
value: new BN(strip0x(handleNumber(transaction[6]))),

@@ -162,3 +164,3 @@ data: transaction[7],

if (transaction.length === 8) {
tx.unsignedTxnHash = rawTransaction;
tx.unsignedRawTransaction = rawTransaction;
return tx;

@@ -196,3 +198,3 @@ }

try {
tx.from = recoverAddress(digest, {
var recoveredFrom = recoverAddress(digest, {
r: hexlify(tx.signature.r),

@@ -202,2 +204,4 @@ s: hexlify(tx.signature.s),

});
tx.from =
recoveredFrom === '0x' ? '0x' : getAddress(recoveredFrom).checksum;
}

@@ -207,3 +211,3 @@ catch (error) {

}
tx.txnHash = keccak256(rawTransaction);
tx.rawTransaction = keccak256(rawTransaction);
}

@@ -220,4 +224,4 @@ return tx;

from: '0x',
txnHash: '0x',
unsignedTxnHash: '0x',
rawTransaction: '0x',
unsignedRawTransaction: '0x',
nonce: new BN(strip0x(handleNumber(transaction[0]))).toNumber(),

@@ -228,3 +232,5 @@ gasPrice: new BN(strip0x(handleNumber(transaction[1]))),

toShardID: 0,
to: handleAddress(transaction[3]),
to: handleAddress(transaction[3]) !== '0x'
? getAddress(handleAddress(transaction[3])).checksum
: '0x',
value: new BN(strip0x(handleNumber(transaction[4]))),

@@ -242,3 +248,3 @@ data: transaction[5],

if (transaction.length === 6) {
tx.unsignedTxnHash = rawTransaction;
tx.unsignedRawTransaction = rawTransaction;
return tx;

@@ -276,3 +282,3 @@ }

try {
tx.from = recoverAddress(digest, {
var recoveredFrom = recoverAddress(digest, {
r: hexlify(tx.signature.r),

@@ -282,2 +288,4 @@ s: hexlify(tx.signature.s),

});
tx.from =
recoveredFrom === '0x' ? '0x' : getAddress(recoveredFrom).checksum;
}

@@ -287,3 +295,3 @@ catch (error) {

}
tx.txnHash = keccak256(rawTransaction);
tx.rawTransaction = keccak256(rawTransaction);
}

@@ -308,6 +316,6 @@ return tx;

var RLPSign = function (transaction, prv) {
var _a = __read(transaction.getRLPUnsigned(), 2), unsignedTxnHash = _a[0], raw = _a[1];
var regroup = __assign({}, transaction.txParams, { unsignedTxnHash: unsignedTxnHash });
var _a = __read(transaction.getRLPUnsigned(), 2), unsignedRawTransaction = _a[0], raw = _a[1];
var regroup = __assign({}, transaction.txParams, { unsignedRawTransaction: unsignedRawTransaction });
transaction.setParams(regroup);
var signature = sign(keccak256(unsignedTxnHash), prv);
var signature = sign(keccak256(unsignedRawTransaction), prv);
var signed = transaction.getRLPSigned(raw, signature);

@@ -329,25 +337,31 @@ return [signature, signed];

// intialize transaction
this.id = params ? params.id : '0x';
this.from = params ? params.from : '0x';
this.nonce = params ? params.nonce : 0;
this.gasPrice = params ? params.gasPrice : new BN(0);
this.gasLimit = params ? params.gasLimit : new BN(0);
this.shardID = params ? params.shardID : 0;
this.toShardID = params ? params.toShardID : 0;
this.to = params ? this.normalizeAddress(params.to) : '0x';
this.value = params ? params.value : new BN(0);
this.data = params ? params.data : '0x';
this.id = params && params.id ? params.id : '0x';
this.from = params && params.from ? params.from : '0x';
this.nonce = params && params.nonce ? params.nonce : 0;
this.gasPrice = params && params.gasPrice ? params.gasPrice : new BN(0);
this.gasLimit = params && params.gasLimit ? params.gasLimit : new BN(0);
this.shardID = params && params.shardID ? params.shardID : 0;
this.toShardID = params && params.toShardID ? params.toShardID : 0;
this.to = params && params.to ? this.normalizeAddress(params.to) : '0x';
this.value = params && params.value ? params.value : new BN(0);
this.data = params && params.data ? params.data : '0x';
// chainid should change with different network settings
this.chainId = params ? params.chainId : this.messenger.chainId;
this.txnHash = params ? params.txnHash : '0x';
this.unsignedTxnHash = params ? params.unsignedTxnHash : '0x';
this.signature = params
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
this.receipt = params ? params.receipt : undefined;
this.chainId =
params && params.chainId ? params.chainId : this.messenger.chainId;
this.rawTransaction =
params && params.rawTransaction ? params.rawTransaction : '0x';
this.unsignedRawTransaction =
params && params.unsignedRawTransaction
? params.unsignedRawTransaction
: '0x';
this.signature =
params && params.signature
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
this.receipt = params && params.receipt ? params.receipt : undefined;
}

@@ -406,7 +420,7 @@ Transaction.prototype.setMessenger = function (messenger) {

};
Transaction.prototype.recover = function (txnHash) {
Transaction.prototype.recover = function (rawTransaction) {
// temp setting to be compatible with eth
var recovered = this.messenger.chainType === "hmy" /* Harmony */
? recover(txnHash)
: recoverETH(txnHash);
? recover(rawTransaction)
: recoverETH(rawTransaction);
this.setParams(recovered);

@@ -449,4 +463,4 @@ return this;

chainId: this.chainId || 0,
txnHash: this.txnHash || '0x',
unsignedTxnHash: this.unsignedTxnHash || '0x',
rawTransaction: this.rawTransaction || '0x',
unsignedRawTransaction: this.unsignedRawTransaction || '0x',
signature: this.signature || '0x',

@@ -459,24 +473,29 @@ };

Transaction.prototype.setParams = function (params) {
this.id = params ? params.id : '0x';
this.from = params ? params.from : '0x';
this.nonce = params ? params.nonce : 0;
this.gasPrice = params ? params.gasPrice : new BN(0);
this.gasLimit = params ? params.gasLimit : new BN(0);
this.shardID = params ? params.shardID : 0;
this.toShardID = params ? params.toShardID : 0;
this.to = params ? this.normalizeAddress(params.to) : '0x';
this.value = params ? params.value : new BN(0);
this.data = params ? params.data : '0x';
this.chainId = params ? params.chainId : 0;
this.txnHash = params ? params.txnHash : '0x';
this.unsignedTxnHash = params ? params.unsignedTxnHash : '0x';
this.signature = params
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
if (this.txnHash !== '0x') {
this.id = params && params.id ? params.id : '0x';
this.from = params && params.from ? params.from : '0x';
this.nonce = params && params.nonce ? params.nonce : 0;
this.gasPrice = params && params.gasPrice ? params.gasPrice : new BN(0);
this.gasLimit = params && params.gasLimit ? params.gasLimit : new BN(0);
this.shardID = params && params.shardID ? params.shardID : 0;
this.toShardID = params && params.toShardID ? params.toShardID : 0;
this.to = params && params.to ? this.normalizeAddress(params.to) : '0x';
this.value = params && params.value ? params.value : new BN(0);
this.data = params && params.data ? params.data : '0x';
this.chainId = params && params.chainId ? params.chainId : 0;
this.rawTransaction =
params && params.rawTransaction ? params.rawTransaction : '0x';
this.unsignedRawTransaction =
params && params.unsignedRawTransaction
? params.unsignedRawTransaction
: '0x';
this.signature =
params && params.signature
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
if (this.rawTransaction !== '0x') {
this.setTxStatus("SIGNED" /* SIGNED */);

@@ -525,3 +544,3 @@ }

// TODO: we use eth RPC setting for now, incase we have other params, we should add here
if (this.txnHash === 'tx' || this.txnHash === undefined) {
if (this.rawTransaction === 'tx' || this.rawTransaction === undefined) {
throw new Error('Transaction not signed');

@@ -532,3 +551,3 @@ }

}
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.txnHash)];
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.rawTransaction)];
case 1:

@@ -535,0 +554,0 @@ res = _a.sent();

@@ -141,4 +141,4 @@ /**

from: '0x',
txnHash: '0x',
unsignedTxnHash: '0x',
rawTransaction: '0x',
unsignedRawTransaction: '0x',
nonce: new crypto.BN(utils.strip0x(handleNumber(transaction[0]))).toNumber(),

@@ -149,3 +149,5 @@ gasPrice: new crypto.BN(utils.strip0x(handleNumber(transaction[1]))),

toShardID: new crypto.BN(utils.strip0x(handleNumber(transaction[4]))).toNumber(),
to: handleAddress(transaction[5]),
to: handleAddress(transaction[5]) !== '0x'
? crypto.getAddress(handleAddress(transaction[5])).checksum
: '0x',
value: new crypto.BN(utils.strip0x(handleNumber(transaction[6]))),

@@ -163,3 +165,3 @@ data: transaction[7],

if (transaction.length === 8) {
tx.unsignedTxnHash = rawTransaction;
tx.unsignedRawTransaction = rawTransaction;
return tx;

@@ -197,3 +199,3 @@ }

try {
tx.from = crypto.recoverAddress(digest, {
var recoveredFrom = crypto.recoverAddress(digest, {
r: crypto.hexlify(tx.signature.r),

@@ -203,2 +205,4 @@ s: crypto.hexlify(tx.signature.s),

});
tx.from =
recoveredFrom === '0x' ? '0x' : crypto.getAddress(recoveredFrom).checksum;
}

@@ -208,3 +212,3 @@ catch (error) {

}
tx.txnHash = crypto.keccak256(rawTransaction);
tx.rawTransaction = crypto.keccak256(rawTransaction);
}

@@ -221,4 +225,4 @@ return tx;

from: '0x',
txnHash: '0x',
unsignedTxnHash: '0x',
rawTransaction: '0x',
unsignedRawTransaction: '0x',
nonce: new crypto.BN(utils.strip0x(handleNumber(transaction[0]))).toNumber(),

@@ -229,3 +233,5 @@ gasPrice: new crypto.BN(utils.strip0x(handleNumber(transaction[1]))),

toShardID: 0,
to: handleAddress(transaction[3]),
to: handleAddress(transaction[3]) !== '0x'
? crypto.getAddress(handleAddress(transaction[3])).checksum
: '0x',
value: new crypto.BN(utils.strip0x(handleNumber(transaction[4]))),

@@ -243,3 +249,3 @@ data: transaction[5],

if (transaction.length === 6) {
tx.unsignedTxnHash = rawTransaction;
tx.unsignedRawTransaction = rawTransaction;
return tx;

@@ -277,3 +283,3 @@ }

try {
tx.from = crypto.recoverAddress(digest, {
var recoveredFrom = crypto.recoverAddress(digest, {
r: crypto.hexlify(tx.signature.r),

@@ -283,2 +289,4 @@ s: crypto.hexlify(tx.signature.s),

});
tx.from =
recoveredFrom === '0x' ? '0x' : crypto.getAddress(recoveredFrom).checksum;
}

@@ -288,3 +296,3 @@ catch (error) {

}
tx.txnHash = crypto.keccak256(rawTransaction);
tx.rawTransaction = crypto.keccak256(rawTransaction);
}

@@ -308,6 +316,6 @@ return tx;

var RLPSign = function (transaction, prv) {
var _a = __read(transaction.getRLPUnsigned(), 2), unsignedTxnHash = _a[0], raw = _a[1];
var regroup = __assign({}, transaction.txParams, { unsignedTxnHash: unsignedTxnHash });
var _a = __read(transaction.getRLPUnsigned(), 2), unsignedRawTransaction = _a[0], raw = _a[1];
var regroup = __assign({}, transaction.txParams, { unsignedRawTransaction: unsignedRawTransaction });
transaction.setParams(regroup);
var signature = crypto.sign(crypto.keccak256(unsignedTxnHash), prv);
var signature = crypto.sign(crypto.keccak256(unsignedRawTransaction), prv);
var signed = transaction.getRLPSigned(raw, signature);

@@ -329,25 +337,31 @@ return [signature, signed];

// intialize transaction
this.id = params ? params.id : '0x';
this.from = params ? params.from : '0x';
this.nonce = params ? params.nonce : 0;
this.gasPrice = params ? params.gasPrice : new crypto.BN(0);
this.gasLimit = params ? params.gasLimit : new crypto.BN(0);
this.shardID = params ? params.shardID : 0;
this.toShardID = params ? params.toShardID : 0;
this.to = params ? this.normalizeAddress(params.to) : '0x';
this.value = params ? params.value : new crypto.BN(0);
this.data = params ? params.data : '0x';
this.id = params && params.id ? params.id : '0x';
this.from = params && params.from ? params.from : '0x';
this.nonce = params && params.nonce ? params.nonce : 0;
this.gasPrice = params && params.gasPrice ? params.gasPrice : new crypto.BN(0);
this.gasLimit = params && params.gasLimit ? params.gasLimit : new crypto.BN(0);
this.shardID = params && params.shardID ? params.shardID : 0;
this.toShardID = params && params.toShardID ? params.toShardID : 0;
this.to = params && params.to ? this.normalizeAddress(params.to) : '0x';
this.value = params && params.value ? params.value : new crypto.BN(0);
this.data = params && params.data ? params.data : '0x';
// chainid should change with different network settings
this.chainId = params ? params.chainId : this.messenger.chainId;
this.txnHash = params ? params.txnHash : '0x';
this.unsignedTxnHash = params ? params.unsignedTxnHash : '0x';
this.signature = params
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
this.receipt = params ? params.receipt : undefined;
this.chainId =
params && params.chainId ? params.chainId : this.messenger.chainId;
this.rawTransaction =
params && params.rawTransaction ? params.rawTransaction : '0x';
this.unsignedRawTransaction =
params && params.unsignedRawTransaction
? params.unsignedRawTransaction
: '0x';
this.signature =
params && params.signature
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
this.receipt = params && params.receipt ? params.receipt : undefined;
}

@@ -406,7 +420,7 @@ Transaction.prototype.setMessenger = function (messenger) {

};
Transaction.prototype.recover = function (txnHash) {
Transaction.prototype.recover = function (rawTransaction) {
// temp setting to be compatible with eth
var recovered = this.messenger.chainType === "hmy" /* Harmony */
? recover(txnHash)
: recoverETH(txnHash);
? recover(rawTransaction)
: recoverETH(rawTransaction);
this.setParams(recovered);

@@ -449,4 +463,4 @@ return this;

chainId: this.chainId || 0,
txnHash: this.txnHash || '0x',
unsignedTxnHash: this.unsignedTxnHash || '0x',
rawTransaction: this.rawTransaction || '0x',
unsignedRawTransaction: this.unsignedRawTransaction || '0x',
signature: this.signature || '0x',

@@ -459,24 +473,29 @@ };

Transaction.prototype.setParams = function (params) {
this.id = params ? params.id : '0x';
this.from = params ? params.from : '0x';
this.nonce = params ? params.nonce : 0;
this.gasPrice = params ? params.gasPrice : new crypto.BN(0);
this.gasLimit = params ? params.gasLimit : new crypto.BN(0);
this.shardID = params ? params.shardID : 0;
this.toShardID = params ? params.toShardID : 0;
this.to = params ? this.normalizeAddress(params.to) : '0x';
this.value = params ? params.value : new crypto.BN(0);
this.data = params ? params.data : '0x';
this.chainId = params ? params.chainId : 0;
this.txnHash = params ? params.txnHash : '0x';
this.unsignedTxnHash = params ? params.unsignedTxnHash : '0x';
this.signature = params
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
if (this.txnHash !== '0x') {
this.id = params && params.id ? params.id : '0x';
this.from = params && params.from ? params.from : '0x';
this.nonce = params && params.nonce ? params.nonce : 0;
this.gasPrice = params && params.gasPrice ? params.gasPrice : new crypto.BN(0);
this.gasLimit = params && params.gasLimit ? params.gasLimit : new crypto.BN(0);
this.shardID = params && params.shardID ? params.shardID : 0;
this.toShardID = params && params.toShardID ? params.toShardID : 0;
this.to = params && params.to ? this.normalizeAddress(params.to) : '0x';
this.value = params && params.value ? params.value : new crypto.BN(0);
this.data = params && params.data ? params.data : '0x';
this.chainId = params && params.chainId ? params.chainId : 0;
this.rawTransaction =
params && params.rawTransaction ? params.rawTransaction : '0x';
this.unsignedRawTransaction =
params && params.unsignedRawTransaction
? params.unsignedRawTransaction
: '0x';
this.signature =
params && params.signature
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
if (this.rawTransaction !== '0x') {
this.setTxStatus("SIGNED" /* SIGNED */);

@@ -525,3 +544,3 @@ }

// TODO: we use eth RPC setting for now, incase we have other params, we should add here
if (this.txnHash === 'tx' || this.txnHash === undefined) {
if (this.rawTransaction === 'tx' || this.rawTransaction === undefined) {
throw new Error('Transaction not signed');

@@ -532,3 +551,3 @@ }

}
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.txnHash)];
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.rawTransaction)];
case 1:

@@ -535,0 +554,0 @@ res = _a.sent();

@@ -24,4 +24,4 @@ /// <reference types="bn.js" />

private chainId;
private txnHash;
private unsignedTxnHash;
private rawTransaction;
private unsignedRawTransaction;
private signature;

@@ -32,3 +32,3 @@ constructor(params?: TxParams | any, messenger?: Messenger, txStatus?: TxStatus);

getRLPSigned(raw: any[], signature: Signature): string;
recover(txnHash: string): Transaction;
recover(rawTransaction: string): Transaction;
readonly txPayload: {

@@ -35,0 +35,0 @@ from: string;

@@ -20,25 +20,31 @@ "use strict";

// intialize transaction
this.id = params ? params.id : '0x';
this.from = params ? params.from : '0x';
this.nonce = params ? params.nonce : 0;
this.gasPrice = params ? params.gasPrice : new crypto_1.BN(0);
this.gasLimit = params ? params.gasLimit : new crypto_1.BN(0);
this.shardID = params ? params.shardID : 0;
this.toShardID = params ? params.toShardID : 0;
this.to = params ? this.normalizeAddress(params.to) : '0x';
this.value = params ? params.value : new crypto_1.BN(0);
this.data = params ? params.data : '0x';
this.id = params && params.id ? params.id : '0x';
this.from = params && params.from ? params.from : '0x';
this.nonce = params && params.nonce ? params.nonce : 0;
this.gasPrice = params && params.gasPrice ? params.gasPrice : new crypto_1.BN(0);
this.gasLimit = params && params.gasLimit ? params.gasLimit : new crypto_1.BN(0);
this.shardID = params && params.shardID ? params.shardID : 0;
this.toShardID = params && params.toShardID ? params.toShardID : 0;
this.to = params && params.to ? this.normalizeAddress(params.to) : '0x';
this.value = params && params.value ? params.value : new crypto_1.BN(0);
this.data = params && params.data ? params.data : '0x';
// chainid should change with different network settings
this.chainId = params ? params.chainId : this.messenger.chainId;
this.txnHash = params ? params.txnHash : '0x';
this.unsignedTxnHash = params ? params.unsignedTxnHash : '0x';
this.signature = params
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
this.receipt = params ? params.receipt : undefined;
this.chainId =
params && params.chainId ? params.chainId : this.messenger.chainId;
this.rawTransaction =
params && params.rawTransaction ? params.rawTransaction : '0x';
this.unsignedRawTransaction =
params && params.unsignedRawTransaction
? params.unsignedRawTransaction
: '0x';
this.signature =
params && params.signature
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
this.receipt = params && params.receipt ? params.receipt : undefined;
}

@@ -97,7 +103,7 @@ Transaction.prototype.setMessenger = function (messenger) {

};
Transaction.prototype.recover = function (txnHash) {
Transaction.prototype.recover = function (rawTransaction) {
// temp setting to be compatible with eth
var recovered = this.messenger.chainType === "hmy" /* Harmony */
? utils_2.recover(txnHash)
: utils_2.recoverETH(txnHash);
? utils_2.recover(rawTransaction)
: utils_2.recoverETH(rawTransaction);
this.setParams(recovered);

@@ -140,4 +146,4 @@ return this;

chainId: this.chainId || 0,
txnHash: this.txnHash || '0x',
unsignedTxnHash: this.unsignedTxnHash || '0x',
rawTransaction: this.rawTransaction || '0x',
unsignedRawTransaction: this.unsignedRawTransaction || '0x',
signature: this.signature || '0x',

@@ -150,24 +156,29 @@ };

Transaction.prototype.setParams = function (params) {
this.id = params ? params.id : '0x';
this.from = params ? params.from : '0x';
this.nonce = params ? params.nonce : 0;
this.gasPrice = params ? params.gasPrice : new crypto_1.BN(0);
this.gasLimit = params ? params.gasLimit : new crypto_1.BN(0);
this.shardID = params ? params.shardID : 0;
this.toShardID = params ? params.toShardID : 0;
this.to = params ? this.normalizeAddress(params.to) : '0x';
this.value = params ? params.value : new crypto_1.BN(0);
this.data = params ? params.data : '0x';
this.chainId = params ? params.chainId : 0;
this.txnHash = params ? params.txnHash : '0x';
this.unsignedTxnHash = params ? params.unsignedTxnHash : '0x';
this.signature = params
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
if (this.txnHash !== '0x') {
this.id = params && params.id ? params.id : '0x';
this.from = params && params.from ? params.from : '0x';
this.nonce = params && params.nonce ? params.nonce : 0;
this.gasPrice = params && params.gasPrice ? params.gasPrice : new crypto_1.BN(0);
this.gasLimit = params && params.gasLimit ? params.gasLimit : new crypto_1.BN(0);
this.shardID = params && params.shardID ? params.shardID : 0;
this.toShardID = params && params.toShardID ? params.toShardID : 0;
this.to = params && params.to ? this.normalizeAddress(params.to) : '0x';
this.value = params && params.value ? params.value : new crypto_1.BN(0);
this.data = params && params.data ? params.data : '0x';
this.chainId = params && params.chainId ? params.chainId : 0;
this.rawTransaction =
params && params.rawTransaction ? params.rawTransaction : '0x';
this.unsignedRawTransaction =
params && params.unsignedRawTransaction
? params.unsignedRawTransaction
: '0x';
this.signature =
params && params.signature
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
if (this.rawTransaction !== '0x') {
this.setTxStatus("SIGNED" /* SIGNED */);

@@ -216,3 +227,3 @@ }

// TODO: we use eth RPC setting for now, incase we have other params, we should add here
if (this.txnHash === 'tx' || this.txnHash === undefined) {
if (this.rawTransaction === 'tx' || this.rawTransaction === undefined) {
throw new Error('Transaction not signed');

@@ -223,3 +234,3 @@ }

}
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.txnHash)];
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.rawTransaction)];
case 1:

@@ -226,0 +237,0 @@ res = _a.sent();

@@ -15,4 +15,4 @@ /// <reference types="bn.js" />

chainId: number;
txnHash: string;
unsignedTxnHash: string;
rawTransaction: string;
unsignedRawTransaction: string;
signature: Signature;

@@ -19,0 +19,0 @@ receipt?: TransasctionReceipt;

@@ -41,3 +41,3 @@ import { Signature } from '@harmony-js/crypto';

export declare const recoverETH: (rawTransaction: string) => TxParams;
export declare const sleep: (ms: number) => Promise<{}>;
export declare const sleep: (ms: number) => Promise<unknown>;
export declare enum TransactionEvents {

@@ -44,0 +44,0 @@ transactionHash = "transactionHash",

@@ -57,4 +57,4 @@ "use strict";

from: '0x',
txnHash: '0x',
unsignedTxnHash: '0x',
rawTransaction: '0x',
unsignedRawTransaction: '0x',
nonce: new crypto_1.BN(utils_1.strip0x(exports.handleNumber(transaction[0]))).toNumber(),

@@ -65,3 +65,5 @@ gasPrice: new crypto_1.BN(utils_1.strip0x(exports.handleNumber(transaction[1]))),

toShardID: new crypto_1.BN(utils_1.strip0x(exports.handleNumber(transaction[4]))).toNumber(),
to: exports.handleAddress(transaction[5]),
to: exports.handleAddress(transaction[5]) !== '0x'
? crypto_1.getAddress(exports.handleAddress(transaction[5])).checksum
: '0x',
value: new crypto_1.BN(utils_1.strip0x(exports.handleNumber(transaction[6]))),

@@ -79,3 +81,3 @@ data: transaction[7],

if (transaction.length === 8) {
tx.unsignedTxnHash = rawTransaction;
tx.unsignedRawTransaction = rawTransaction;
return tx;

@@ -113,3 +115,3 @@ }

try {
tx.from = crypto_1.recoverAddress(digest, {
var recoveredFrom = crypto_1.recoverAddress(digest, {
r: crypto_1.hexlify(tx.signature.r),

@@ -119,2 +121,4 @@ s: crypto_1.hexlify(tx.signature.s),

});
tx.from =
recoveredFrom === '0x' ? '0x' : crypto_1.getAddress(recoveredFrom).checksum;
}

@@ -124,3 +128,3 @@ catch (error) {

}
tx.txnHash = crypto_1.keccak256(rawTransaction);
tx.rawTransaction = crypto_1.keccak256(rawTransaction);
}

@@ -137,4 +141,4 @@ return tx;

from: '0x',
txnHash: '0x',
unsignedTxnHash: '0x',
rawTransaction: '0x',
unsignedRawTransaction: '0x',
nonce: new crypto_1.BN(utils_1.strip0x(exports.handleNumber(transaction[0]))).toNumber(),

@@ -145,3 +149,5 @@ gasPrice: new crypto_1.BN(utils_1.strip0x(exports.handleNumber(transaction[1]))),

toShardID: 0,
to: exports.handleAddress(transaction[3]),
to: exports.handleAddress(transaction[3]) !== '0x'
? crypto_1.getAddress(exports.handleAddress(transaction[3])).checksum
: '0x',
value: new crypto_1.BN(utils_1.strip0x(exports.handleNumber(transaction[4]))),

@@ -159,3 +165,3 @@ data: transaction[5],

if (transaction.length === 6) {
tx.unsignedTxnHash = rawTransaction;
tx.unsignedRawTransaction = rawTransaction;
return tx;

@@ -193,3 +199,3 @@ }

try {
tx.from = crypto_1.recoverAddress(digest, {
var recoveredFrom = crypto_1.recoverAddress(digest, {
r: crypto_1.hexlify(tx.signature.r),

@@ -199,2 +205,4 @@ s: crypto_1.hexlify(tx.signature.s),

});
tx.from =
recoveredFrom === '0x' ? '0x' : crypto_1.getAddress(recoveredFrom).checksum;
}

@@ -204,3 +212,3 @@ catch (error) {

}
tx.txnHash = crypto_1.keccak256(rawTransaction);
tx.rawTransaction = crypto_1.keccak256(rawTransaction);
}

@@ -225,6 +233,6 @@ return tx;

exports.RLPSign = function (transaction, prv) {
var _a = tslib_1.__read(transaction.getRLPUnsigned(), 2), unsignedTxnHash = _a[0], raw = _a[1];
var regroup = tslib_1.__assign({}, transaction.txParams, { unsignedTxnHash: unsignedTxnHash });
var _a = tslib_1.__read(transaction.getRLPUnsigned(), 2), unsignedRawTransaction = _a[0], raw = _a[1];
var regroup = tslib_1.__assign({}, transaction.txParams, { unsignedRawTransaction: unsignedRawTransaction });
transaction.setParams(regroup);
var signature = crypto_1.sign(crypto_1.keccak256(unsignedTxnHash), prv);
var signature = crypto_1.sign(crypto_1.keccak256(unsignedRawTransaction), prv);
var signed = transaction.getRLPSigned(raw, signature);

@@ -231,0 +239,0 @@ return [signature, signed];

{
"name": "@harmony-js/transaction",
"version": "0.0.54",
"version": "0.0.60",
"description": "transaction package for harmony",

@@ -21,8 +21,8 @@ "main": "dist/index.js",

"dependencies": {
"@harmony-js/core": "0.0.54",
"@harmony-js/crypto": "0.0.54",
"@harmony-js/network": "0.0.54",
"@harmony-js/utils": "0.0.54"
"@harmony-js/core": "0.0.60",
"@harmony-js/crypto": "0.0.60",
"@harmony-js/network": "0.0.60",
"@harmony-js/utils": "0.0.60"
},
"gitHead": "dfdde42131a9fd0df5ed9d008e5bf251cad8a69e"
"gitHead": "dce1b4d29ea5261dea16799fccde857c8ae365eb"
}

@@ -52,4 +52,4 @@ import {

private chainId: number;
private txnHash: string;
private unsignedTxnHash: string;
private rawTransaction: string;
private unsignedRawTransaction: string;
private signature: Signature;

@@ -68,26 +68,32 @@

// intialize transaction
this.id = params ? params.id : '0x';
this.from = params ? params.from : '0x';
this.nonce = params ? params.nonce : 0;
this.gasPrice = params ? params.gasPrice : new BN(0);
this.gasLimit = params ? params.gasLimit : new BN(0);
this.shardID = params ? params.shardID : 0;
this.toShardID = params ? params.toShardID : 0;
this.id = params && params.id ? params.id : '0x';
this.from = params && params.from ? params.from : '0x';
this.nonce = params && params.nonce ? params.nonce : 0;
this.gasPrice = params && params.gasPrice ? params.gasPrice : new BN(0);
this.gasLimit = params && params.gasLimit ? params.gasLimit : new BN(0);
this.shardID = params && params.shardID ? params.shardID : 0;
this.toShardID = params && params.toShardID ? params.toShardID : 0;
this.to = params ? this.normalizeAddress(params.to) : '0x';
this.value = params ? params.value : new BN(0);
this.data = params ? params.data : '0x';
this.to = params && params.to ? this.normalizeAddress(params.to) : '0x';
this.value = params && params.value ? params.value : new BN(0);
this.data = params && params.data ? params.data : '0x';
// chainid should change with different network settings
this.chainId = params ? params.chainId : this.messenger.chainId;
this.txnHash = params ? params.txnHash : '0x';
this.unsignedTxnHash = params ? params.unsignedTxnHash : '0x';
this.signature = params
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
this.receipt = params ? params.receipt : undefined;
this.chainId =
params && params.chainId ? params.chainId : this.messenger.chainId;
this.rawTransaction =
params && params.rawTransaction ? params.rawTransaction : '0x';
this.unsignedRawTransaction =
params && params.unsignedRawTransaction
? params.unsignedRawTransaction
: '0x';
this.signature =
params && params.signature
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
this.receipt = params && params.receipt ? params.receipt : undefined;
}

@@ -164,8 +170,9 @@

recover(txnHash: string): Transaction {
recover(rawTransaction: string): Transaction {
// temp setting to be compatible with eth
const recovered =
this.messenger.chainType === ChainType.Harmony
? recover(txnHash)
: recoverETH(txnHash);
? recover(rawTransaction)
: recoverETH(rawTransaction);
this.setParams(recovered);

@@ -204,4 +211,4 @@ return this;

chainId: this.chainId || 0,
txnHash: this.txnHash || '0x',
unsignedTxnHash: this.unsignedTxnHash || '0x',
rawTransaction: this.rawTransaction || '0x',
unsignedRawTransaction: this.unsignedRawTransaction || '0x',
signature: this.signature || '0x',

@@ -211,24 +218,29 @@ };

setParams(params: TxParams) {
this.id = params ? params.id : '0x';
this.from = params ? params.from : '0x';
this.nonce = params ? params.nonce : 0;
this.gasPrice = params ? params.gasPrice : new BN(0);
this.gasLimit = params ? params.gasLimit : new BN(0);
this.shardID = params ? params.shardID : 0;
this.toShardID = params ? params.toShardID : 0;
this.to = params ? this.normalizeAddress(params.to) : '0x';
this.value = params ? params.value : new BN(0);
this.data = params ? params.data : '0x';
this.chainId = params ? params.chainId : 0;
this.txnHash = params ? params.txnHash : '0x';
this.unsignedTxnHash = params ? params.unsignedTxnHash : '0x';
this.signature = params
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
if (this.txnHash !== '0x') {
this.id = params && params.id ? params.id : '0x';
this.from = params && params.from ? params.from : '0x';
this.nonce = params && params.nonce ? params.nonce : 0;
this.gasPrice = params && params.gasPrice ? params.gasPrice : new BN(0);
this.gasLimit = params && params.gasLimit ? params.gasLimit : new BN(0);
this.shardID = params && params.shardID ? params.shardID : 0;
this.toShardID = params && params.toShardID ? params.toShardID : 0;
this.to = params && params.to ? this.normalizeAddress(params.to) : '0x';
this.value = params && params.value ? params.value : new BN(0);
this.data = params && params.data ? params.data : '0x';
this.chainId = params && params.chainId ? params.chainId : 0;
this.rawTransaction =
params && params.rawTransaction ? params.rawTransaction : '0x';
this.unsignedRawTransaction =
params && params.unsignedRawTransaction
? params.unsignedRawTransaction
: '0x';
this.signature =
params && params.signature
? params.signature
: {
r: '',
s: '',
recoveryParam: 0,
v: 0,
};
if (this.rawTransaction !== '0x') {
this.setTxStatus(TxStatus.SIGNED);

@@ -278,3 +290,3 @@ } else {

// TODO: we use eth RPC setting for now, incase we have other params, we should add here
if (this.txnHash === 'tx' || this.txnHash === undefined) {
if (this.rawTransaction === 'tx' || this.rawTransaction === undefined) {
throw new Error('Transaction not signed');

@@ -287,3 +299,3 @@ }

RPCMethod.SendRawTransaction,
this.txnHash,
this.rawTransaction,
);

@@ -290,0 +302,0 @@

@@ -14,4 +14,4 @@ import { BN, Signature } from '@harmony-js/crypto';

chainId: number;
txnHash: string;
unsignedTxnHash: string;
rawTransaction: string;
unsignedRawTransaction: string;
signature: Signature;

@@ -18,0 +18,0 @@ receipt?: TransasctionReceipt;

@@ -17,2 +17,3 @@ import {

Signature,
getAddress,
sign,

@@ -74,4 +75,4 @@ } from '@harmony-js/crypto';

from: '0x',
txnHash: '0x',
unsignedTxnHash: '0x',
rawTransaction: '0x',
unsignedRawTransaction: '0x',
nonce: new BN(strip0x(handleNumber(transaction[0]))).toNumber(),

@@ -82,3 +83,6 @@ gasPrice: new BN(strip0x(handleNumber(transaction[1]))),

toShardID: new BN(strip0x(handleNumber(transaction[4]))).toNumber(),
to: handleAddress(transaction[5]),
to:
handleAddress(transaction[5]) !== '0x'
? getAddress(handleAddress(transaction[5])).checksum
: '0x',
value: new BN(strip0x(handleNumber(transaction[6]))),

@@ -97,3 +101,3 @@ data: transaction[7],

if (transaction.length === 8) {
tx.unsignedTxnHash = rawTransaction;
tx.unsignedRawTransaction = rawTransaction;
return tx;

@@ -139,3 +143,3 @@ }

try {
tx.from = recoverAddress(digest, {
const recoveredFrom = recoverAddress(digest, {
r: hexlify(tx.signature.r),

@@ -145,2 +149,4 @@ s: hexlify(tx.signature.s),

});
tx.from =
recoveredFrom === '0x' ? '0x' : getAddress(recoveredFrom).checksum;
} catch (error) {

@@ -150,3 +156,3 @@ throw error;

tx.txnHash = keccak256(rawTransaction);
tx.rawTransaction = keccak256(rawTransaction);
}

@@ -166,4 +172,4 @@

from: '0x',
txnHash: '0x',
unsignedTxnHash: '0x',
rawTransaction: '0x',
unsignedRawTransaction: '0x',
nonce: new BN(strip0x(handleNumber(transaction[0]))).toNumber(),

@@ -174,3 +180,6 @@ gasPrice: new BN(strip0x(handleNumber(transaction[1]))),

toShardID: 0,
to: handleAddress(transaction[3]),
to:
handleAddress(transaction[3]) !== '0x'
? getAddress(handleAddress(transaction[3])).checksum
: '0x',
value: new BN(strip0x(handleNumber(transaction[4]))),

@@ -189,3 +198,3 @@ data: transaction[5],

if (transaction.length === 6) {
tx.unsignedTxnHash = rawTransaction;
tx.unsignedRawTransaction = rawTransaction;
return tx;

@@ -231,3 +240,3 @@ }

try {
tx.from = recoverAddress(digest, {
const recoveredFrom = recoverAddress(digest, {
r: hexlify(tx.signature.r),

@@ -237,2 +246,4 @@ s: hexlify(tx.signature.s),

});
tx.from =
recoveredFrom === '0x' ? '0x' : getAddress(recoveredFrom).checksum;
} catch (error) {

@@ -242,3 +253,3 @@ throw error;

tx.txnHash = keccak256(rawTransaction);
tx.rawTransaction = keccak256(rawTransaction);
}

@@ -270,11 +281,11 @@

): [Signature, string] => {
const [unsignedTxnHash, raw] = transaction.getRLPUnsigned();
const [unsignedRawTransaction, raw] = transaction.getRLPUnsigned();
const regroup: TxParams = {
...transaction.txParams,
unsignedTxnHash,
unsignedRawTransaction,
};
transaction.setParams(regroup);
const signature = sign(keccak256(unsignedTxnHash), prv);
const signature = sign(keccak256(unsignedRawTransaction), prv);
const signed = transaction.getRLPSigned(raw, signature);
return [signature, signed];
};

@@ -5,4 +5,4 @@ import { Transaction } from '../src/transaction';

import { HttpProvider, Messenger } from '@harmony-js/network';
import { isAddress, ChainType, hexToBN } from '@harmony-js/utils';
import { getAddressFromPrivateKey, BN } from '@harmony-js/crypto';
import { isAddress, ChainType, hexToBN, ChainID } from '@harmony-js/utils';
import { getAddressFromPrivateKey, BN, getAddress } from '@harmony-js/crypto';

@@ -34,3 +34,6 @@ import txnVectors from './transactions.fixture.json';

: new BN(0),
to: vector.to || '0x',
to:
vector.to && vector.to !== '0x'
? getAddress(vector.to).checksum
: '0x',
value:

@@ -58,3 +61,7 @@ vector.value && vector.value !== '0x'

it('should test recover from ETHSignedtransaction', () => {
const ethMessenger = new Messenger(provider, ChainType.Ethereum);
const ethMessenger = new Messenger(
provider,
ChainType.Ethereum,
ChainID.Default,
);
// tslint:disable-next-line: prefer-for-of

@@ -71,2 +78,3 @@ for (let i = 0; i < txnVectors.length; i += 1) {

transaction.recover(vector.signedTransaction);
if (vector.gasLimit && vector.gasLimit !== '0x') {

@@ -96,7 +104,9 @@ expect(transaction.txParams.gasLimit.toString()).toEqual(

if (vector.to && vector.to !== '0x') {
expect(transaction.txParams.to).toEqual(vector.to);
expect(transaction.txParams.to).toEqual(getAddress(vector.to).checksum);
}
expect(transaction.txParams.from).toEqual(vector.accountAddress);
expect(transaction.txParams.from.toLowerCase()).toEqual(
vector.accountAddress.toLowerCase(),
);
}
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc