Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
else {
// Signed Tranasaction
tx.chainId = Math.floor((tx.v - 35) / 2);
if (tx.chainId < 0) {
tx.chainId = 0;
}
let recoveryParam = tx.v - 27;
const raw = transaction.slice(0, 6);
if (tx.chainId !== 0) {
raw.push(hexlify(tx.chainId));
raw.push("0x");
raw.push("0x");
recoveryParam -= tx.chainId * 2 + 8;
}
const digest = keccak256(RLP.encode(raw));
try {
tx.from = recoverAddress(digest, { r: hexlify(tx.r), s: hexlify(tx.s), recoveryParam: recoveryParam });
}
catch (error) {
console.log(error);
}
tx.hash = keccak256(rawTransaction);
}
return tx;
}
}
// The splitSignature will ensure the transaction has a recoveryParam in the
// case that the signTransaction function only adds a v.
const sig = splitSignature(signature);
// We pushed a chainId and null r, s on for hashing only; remove those
let v = 27 + sig.recoveryParam;
if (raw.length === 9) {
raw.pop();
raw.pop();
raw.pop();
v += transaction.chainId * 2 + 8;
}
raw.push(hexlify(v));
raw.push(stripZeros(arrayify(sig.r)));
raw.push(stripZeros(arrayify(sig.s)));
return RLP.encode(raw);
}
export function parse(rawTransaction) {
}
// Variable-width (with a maximum)
if (fieldInfo.maxLength) {
value = stripZeros(value);
if (value.length > fieldInfo.maxLength) {
logger.throwArgumentError("invalid length for " + fieldInfo.name, ("transaction:" + fieldInfo.name), value);
}
}
raw.push(hexlify(value));
});
if (transaction.chainId != null && transaction.chainId !== 0) {
raw.push(hexlify(transaction.chainId));
raw.push("0x");
raw.push("0x");
}
const unsignedTransaction = RLP.encode(raw);
// Requesting an unsigned transation
if (!signature) {
return unsignedTransaction;
}
// The splitSignature will ensure the transaction has a recoveryParam in the
// case that the signTransaction function only adds a v.
const sig = splitSignature(signature);
// We pushed a chainId and null r, s on for hashing only; remove those
let v = 27 + sig.recoveryParam;
if (raw.length === 9) {
raw.pop();
raw.pop();
raw.pop();
v += transaction.chainId * 2 + 8;
}
raw.push(hexlify(v));
export function parse(rawTransaction) {
const transaction = RLP.decode(rawTransaction);
if (transaction.length !== 9 && transaction.length !== 6) {
logger.throwArgumentError("invalid raw transaction", "rawTransactin", rawTransaction);
}
const tx = {
nonce: handleNumber(transaction[0]).toNumber(),
gasPrice: handleNumber(transaction[1]),
gasLimit: handleNumber(transaction[2]),
to: handleAddress(transaction[3]),
value: handleNumber(transaction[4]),
data: transaction[5],
chainId: 0
};
// Legacy unsigned transaction
if (transaction.length === 6) {
return tx;
}
function getContractAddress(transaction) {
var from = null;
try {
from = getAddress(transaction.from);
}
catch (error) {
logger.throwArgumentError("missing from address", "transaction", transaction);
}
var nonce = bytes_1.stripZeros(bytes_1.arrayify(bignumber_1.BigNumber.from(transaction.nonce).toHexString()));
return getAddress(bytes_1.hexDataSlice(keccak256_1.keccak256(rlp_1.encode([from, nonce])), 12));
}
exports.getContractAddress = getContractAddress;
export function getContractAddress(transaction: { from: string, nonce: BigNumberish }) {
let from: string = null;
try {
from = getAddress(transaction.from);
} catch (error) {
logger.throwArgumentError("missing from address", "transaction", transaction);
}
const nonce = stripZeros(arrayify(BigNumber.from(transaction.nonce).toHexString()));
return getAddress(hexDataSlice(keccak256(encode([ from, nonce ])), 12));
}
export function getContractAddress(transaction) {
let from = null;
try {
from = getAddress(transaction.from);
}
catch (error) {
logger.throwArgumentError("missing from address", "transaction", transaction);
}
const nonce = stripZeros(arrayify(BigNumber.from(transaction.nonce).toHexString()));
return getAddress(hexDataSlice(keccak256(encode([from, nonce])), 12));
}