Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should give proper information about the TX input', async () => {
const tx = createTransaction(TxTypeSplit, 0,
[{
blockNumber: 1,
txNumberInBlock: 200,
outputNumberInTransaction: 0,
amount: 10
}],
[{
amount: 10,
to: alice
}],
aliceKey
)
const reencodedTX = tx.serialize();
const info = await txTester.getInputInfo(ethUtil.bufferToHex(reencodedTX), 0);
const blockNumber = info[0].toNumber();
const txNumberInBlock = info[1].toNumber();
const outputNumber = info[2].toNumber();
const amount = info[3].toString(10);
assert(blockNumber === 1);
// assert(txNumberInBlock === 200);
assert(outputNumber === 0);
assert(amount === ""+10);
});
export function signAddress(privKey, address) {
const msg = new Buffer(address)
const addressHash = eutil.hashPersonalMessage(Buffer.from(address)) // address+prefix, hashed
const sig = eutil.ecsign(addressHash, Buffer.from(eutil.stripHexPrefix(privKey), 'hex'))
return {
h: eutil.bufferToHex(addressHash),
r: eutil.bufferToHex(sig.r),
s: eutil.bufferToHex(sig.s),
v: sig.v
}
}
continue;
}
if (indexFilterValues[eventInput.name] === undefined) {
// Null is a wildcard topic in a JSON-RPC call
topics.push(null);
} else {
// tslint:disable: no-unnecessary-type-assertion
let value = indexFilterValues[eventInput.name] as any;
if (BigNumber.isBigNumber(value)) {
// tslint:disable-next-line custom-no-magic-numbers
value = ethUtil.fromSigned(value.toString(10) as any);
}
// tslint:enable: no-unnecessary-type-assertion
const buffer = ethUtil.toBuffer(value);
const paddedBuffer = ethUtil.setLengthLeft(buffer, TOPIC_LENGTH);
const topic = ethUtil.bufferToHex(paddedBuffer);
topics.push(topic);
}
}
return topics;
},
matchesFilter(log: LogEntry, filter: FilterObject): boolean {
return function validate(signed) {
console.log(signed)
let txBuf = toBuffer(signed.raw)
let tx = new EthTx(txBuf)
return norm(bufferToHex(tx.getSenderAddress())) === norm(account)
}
}
outputNumberInTransaction: 0,
amount: 0
}],
[{
amount: 10,
to: alice
}],
operatorKey
)
let block = createBlock(1, 1, firstHash, [tx], operatorKey)
let blockArray = block.serialize();
let blockHeader = Buffer.concat(blockArray).slice(0,137);
let deserialization = ethUtil.rlp.decode(blockArray[7]);
let lastBlockNumber = await plasma.lastBlockNumber()
assert(lastBlockNumber.toString() == "0");
let submissionReceipt = await plasma.submitBlockHeaders(ethUtil.bufferToHex(blockHeader));
lastBlockNumber = await plasma.lastBlockNumber();
assert(lastBlockNumber.toString() == "1");
let allEvents = storage.allEvents({fromBlock: submissionReceipt.receipt.blockNumber, toBlock: submissionReceipt.receipt.blockNumber});
let get = util.promisify(allEvents.get.bind(allEvents))
let evs = await get()
assert.web3Event({logs: evs}, {
event: 'BlockHeaderSubmitted',
args: {_blockNumber: 1,
_merkleRoot: ethUtil.bufferToHex(block.header.merkleRootHash)}
}, 'The event is emitted');
let bl = await storage.blocks(1);
assert(bl[2] == ethUtil.bufferToHex(block.header.merkleRootHash));
const newHash = await plasma.hashOfLastSubmittedBlock();
tx = createTransaction(TxTypeSplit, 0,
[{
function _parseSignatureHexAsRSV(signatureHex: string) {
const { v, r, s } = ethUtil.fromRpcSig(signatureHex)
const ecSignature = {
v,
r: ethUtil.bufferToHex(r),
s: ethUtil.bufferToHex(s),
}
return ecSignature
}
}
_normalize (buf) {
return this._padLeftEven(ethUtil.bufferToHex(buf).toLowerCase())
}
function getPeriodRoot(consensus, cas, data, rest) {
let buf = Buffer.alloc(64, 0);
toBuffer(data).copy(buf);
toBuffer(rest).copy(buf, 32);
const dataBuf = keccak256(buf);
buf = Buffer.alloc(64, 0);
toBuffer(cas).copy(buf);
dataBuf.copy(buf, 32);
const casBuf = keccak256(buf);
buf = Buffer.alloc(64, 0);
toBuffer(consensus).copy(buf);
casBuf.copy(buf, 32);
return bufferToHex(keccak256(buf));
}
export function hashPersonalMessage(message: string): { rawMessage: string; messageHash: Hex } {
const rawMessage = SIGN_PREFFIX + message.length.toString() + message;
return {
rawMessage,
messageHash: bufferToHex(sha3(rawMessage)),
};
}