Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
chainId: 0
};
// Legacy unsigned transaction
if (transaction.length === 6) {
return tx;
}
try {
tx.v = BigNumber.from(transaction[6]).toNumber();
}
catch (error) {
console.log(error);
return tx;
}
tx.r = hexZeroPad(transaction[7], 32);
tx.s = hexZeroPad(transaction[8], 32);
if (BigNumber.from(tx.r).isZero() && BigNumber.from(tx.s).isZero()) {
// EIP-155 unsigned transaction
tx.chainId = tx.v;
tx.v = 0;
}
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");
}
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;
}
try {
tx.v = BigNumber.from(transaction[6]).toNumber();
}
catch (error) {
console.log(error);
return tx;
}
tx.r = hexZeroPad(transaction[7], 32);
tx.s = hexZeroPad(transaction[8], 32);
if (BigNumber.from(tx.r).isZero() && BigNumber.from(tx.s).isZero()) {
// EIP-155 unsigned transaction
tx.chainId = tx.v;
tx.v = 0;
}
else {
// Signed Tranasaction
tx.chainId = Math.floor((tx.v - 35) / 2);
if (tx.chainId < 0) {
number(number) {
return BigNumber.from(number).toNumber();
}
// Strict! Used on input.
// Data += ser_32(i)
for (let i = 24; i >= 0; i -= 8) { data[33 + (i >> 3)] = ((index >> (24 - i)) & 0xff); }
const I = arrayify(computeHmac(SupportedAlgorithms.sha512, this.chainCode, data));
const IL = I.slice(0, 32);
const IR = I.slice(32);
// The private key
let ki: string = null
// The public key
let Ki: string = null;
if (this.privateKey) {
ki = bytes32(BigNumber.from(IL).add(this.privateKey).mod(N));
} else {
const ek = new SigningKey(hexlify(IL));
Ki = ek._addPoint(this.publicKey);
}
return new HDNode(_constructorGuard, ki, Ki, this.fingerprint, bytes32(IR), index, this.depth + 1, this.mnemonic, path);
}
set value(value) {
this.properties.value = BigNumber.from(value).toString();
}
function handleNumber(value) {
if (value === "0x") {
return Zero;
}
return BigNumber.from(value);
}
const transactionFields = [
public set gas(gas) {
if (gas) {
this.properties.gas = BigNumber.from(gas).toString();
}
this.properties.gas = gas;
}
const toUint = (val: PrimativeType, bytes: BytesNumber) =>
hexZeroPad(BigNumber.from(val).toHexString(), bytes)