Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
checkIsValidSignature(message, signature) {
const contractAddr = cache.get(message)
const walletContract = new this.web3Eth.Contract(ABI, contractAddr)
const prefixMessage = web3Utils.utf8ToHex(this.options.prefix + message)
return walletContract.methods.isValidSignature(prefixMessage, signature).call()
.then((magicValue) => {
if (magicValue === '0x20c13b0b') { // '0x1626ba7e' for bytes32
cache.del(message)
return contractAddr
}
return false
})
.catch(err => {
console.log(err)
return false
})
}
// Construct params for executing tx
const createEventParams = [
name,
cloneDeep(results),
betEndTime,
resultSetStartTime,
centralizedOracle,
arbitrationOptionIndex,
arbitrationRewardPercentage,
];
// Format results to bytes32 types
for (let i = 0; i < 3; i++) {
if (createEventParams[1][i]) {
createEventParams[1][i] = padRight(utf8ToHex(createEventParams[1][i]), 64);
} else {
createEventParams[1][i] = padRight(utf8ToHex(''), 64);
}
}
// Execute tx
const { network } = this.app.naka;
const nbotMethods = window.naka.eth.contract(NakaBodhiToken().abi)
.at(NakaBodhiToken()[network.toLowerCase()]);
const txid = await this.createEvent({
nbotMethods,
eventParams: createEventParams,
eventFactoryAddr: EventFactory()[network.toLowerCase()],
escrowAmt: amountSatoshi,
gas: 3000000,
});
// TODO: remove after mobile apps are done debugging
console.log('Returned to dapp after create event');
async initiateSubscription(
{provider, endpoint, endpointParams, blocks, publicKey, from, gas}) {
try {
// Make sure we could parse it correctly
if (endpointParams instanceof Error) {
throw endpointParams;
}
for (let i in endpointParams){
endpointParams[i] = utf8ToHex(endpointParams[i]);
}
return await this.contract.methods.initiateSubscription(
provider,
utf8ToHex(endpoint),
endpointParams,
toBN(publicKey),
toBN(blocks)).send({from: from, gas: gas});
} catch (err) {
throw err;
}
}
async initiateSubscription(
{provider, endpoint, endpointParams, blocks, publicKey, from, gas}) {
try {
// Make sure we could parse it correctly
if (endpointParams instanceof Error) {
throw endpointParams;
}
for (let i in endpointParams){
endpointParams[i] = utf8ToHex(endpointParams[i]);
}
return await this.contract.methods.initiateSubscription(
provider,
utf8ToHex(endpoint),
endpointParams,
toBN(publicKey),
toBN(blocks)).send({from: from, gas: gas});
} catch (err) {
throw err;
}
}
async loadSelf(bootstrapAddress: ?string): Promise {
if (this.ready()) return;
await this._networkContract.loadContract(bootstrapAddress);
// TODO: Find out version here
const VERSION = 0;
const result = await this._networkContract.functions.getColony(
utf8ToHex(this.name),
);
const [address] = result;
await this._colonyContract.loadContract(address, VERSION);
this.version = VERSION;
this.address = address;
}
}
convertInput(value: string) {
return isHexStrict(value) ? value : utf8ToHex(value);
},
};
static parseParamsValue(value: *, type: ParamTypes) {
switch (type) {
case 'string':
return utf8ToHex(value);
default:
return value;
}
}
static parseParams(params: Params) {
_preprocessors = preprocessors.map (p => web3Utils.utf8ToHex (p));
}
async calcBondRate({provider, endpoint, numZap}){
return await this.contract.methods.calcBondRate(
provider,
utf8ToHex(endpoint),
toBN(numZap)
).call();
}
confirmPersonalSignMessage(message, signature) {
const recoveredAddress = sigUtil.recoverPersonalSignature({
data: web3Utils.utf8ToHex(this.options.prefix + message),
sig: signature
})
const storedMessage = cache.get(recoveredAddress.toLowerCase())
if (storedMessage === message) {
cache.del(recoveredAddress.toLowerCase())
return recoveredAddress
}
return false
}