Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
contract('MintableController', accounts => {
if (web3.version.network <= 100) return;
const owner = accounts[0];
const system = accounts[9];
let controller;
beforeEach("setup mintable controller", async () => {
controller = await MintableController.deployed();
await controller.addSystemAccount(system);
});
const key = Buffer.from("23f2ee33c522046e80b67e96ceb84a05b60b9434b0ee2e3ae4b1311b9f5dcc46", "hex");
const address = `0x${EthUtil.privateToAddress(key).toString("hex")}`;
it("should start with zero tokens", async () => {
const supply = await controller.totalSupply();
assert.equal(supply.valueOf(), 0, "initial supply is not 0");
});
it("should fail to mint 666 new tokens from non-system account", async () => {
await truffleAssert.reverts(
controller.mintTo_withCaller(accounts[0], accounts[0], 666, {from: accounts[0]})
);
});
it("should fail to burnFrom 888 new tokens from non-system account", async () => {
const wallet = wallets["trust wallet"];
const balance0 = await controller.balanceOf(wallet.address);
await controller.mintTo_withCaller(system, wallet.address, 888, {from: system});
function addTransaction(privateKey, name, transaction, signature) {
var rawTransaction = new ethereumTx(transaction);
transaction.chainId = 5;
var rawTransactionEip155 = new ethereumTx(transaction);
delete transaction['chainId'];
console.log(rawTransaction, rawTransaction.serialize().toString('hex'));
console.log(rawTransactionEip155, rawTransactionEip155.serialize().toString('hex'));
console.log(rawTransactionEip155.serialize().toString('hex') === rawTransaction.serialize().toString('hex'));
console.log('------');
var test = {
accountAddress: '0x' + ethereumUtil.privateToAddress(privateKey).toString('hex'),
name: name,
privateKey: '0x' + privateKey.toString('hex'),
unsignedTransaction: '0x' + rawTransaction.serializeUnsigned().toString('hex'),
unsignedTransactionChainId5: '0x' + rawTransactionEip155.serializeUnsigned().toString('hex'),
}
rawTransaction.sign(privateKey);
test.signedTransaction = '0x' + rawTransaction.serialize().toString('hex');
rawTransactionEip155.sign(privateKey);
test.signedTransactionChainId5 = '0x' + rawTransactionEip155.serialize().toString('hex');
for (var k in transaction) {
test[k] = transaction[k];
}
function randomAccount() {
const key = crypto.randomBytes(32);
const address = ethjs.toChecksumAddress(
ethjs.bufferToHex(ethjs.privateToAddress(key)));
return {
key: ethjs.bufferToHex(key),
address: address
};
}
Web3KeyPair.prototype.onPropertyChanged = async function(name, value){
this.properties[name] = value;
try{
if(this.properties.privateKey){
//console.log("PK this.properties.privateKey")
this.publicKey = "0x"+EthUtil.privateToPublic(this.properties.privateKey).toString('hex')
this.address = "0x"+EthUtil.privateToAddress(this.properties.privateKey).toString('hex')
}else{
//console.log("NO this.properties.privateKey")
}
}catch(e){
console.error(e)
}
return true;
};
Wallet.generate = function(icapDirect) {
if (icapDirect) {
while (true) {
var privKey = ethUtil.crypto.randomBytes(32)
if (ethUtil.privateToAddress(privKey)[0] === 0) {
return new Wallet(privKey)
}
}
} else {
return new Wallet(ethUtil.crypto.randomBytes(32))
}
}
Wallet.prototype.getPrivateKey = function() {
return currentState.findIndex(key => {
return ethUtil.bufferToHex(ethUtil.privateToAddress(ethUtil.toBuffer(key))) === address.toLowerCase();
}) !== -1;
}
deriveAddress (wallet) {
if (typeof wallet.pubKey === 'undefined') {
return ethUtil.privateToAddress(wallet.privKey).toString('hex')
} else {
return ethUtil.publicToAddress(wallet.pubKey, true).toString('hex')
}
}
Wallet.generate = function (icapDirect) {
if (icapDirect) {
while (true) {
const privKey = crypto.randomBytes(32)
if (util.privateToAddress(privKey)[0] === 0) {
return new Wallet(privKey)
}
}
} else {
return new Wallet(crypto.randomBytes(32))
}
}
EtherSigner.prototype.getAddress = function () {
let privateKey = Buffer.from(this.privateKey, 'hex');
return '0x' + EthereumUtil.privateToAddress(privateKey).toString('hex');
};
createUserFromCredentials(mnemonicInstance, hashedPassword) {
const mnemonic = mnemonicInstance.toString()
const privateKey = mnemonicInstance.toHDPrivateKey()
const privateKeyBuffer = privateKey.privateKey.toBuffer()
const ethAddress = ethUtil.privateToAddress(privateKeyBuffer)
const address = ethAddress.toString('hex')
return new User(
mnemonic,
hashedPassword,
privateKey,
privateKeyBuffer,
ethAddress,
address
)
}