Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const validate = value => {
Joi.assert(value, Joi.any().invalid(Infinity, -Infinity), new TypeError(`Value is not a finite number: ${value}`))
Joi.assert(value, Joi.number().required(), new TypeError(`Value is not a number: ${value}`))
const parsed = parseFloat(value)
Joi.assert(parsed, Joi.number().positive(), new TypeError(`Value is not a positive number: ${parsed}`))
Joi.assert(parsed, Joi.number().greater(0), new TypeError(`Value is not greater than 0: ${parsed}`))
return parsed
}
async sendTransaction ({
fromAddress,
fromUtxos,
fromPrivateKeys,
payment,
fee,
metadata = null,
verifyingContract
}) {
Joi.assert({
fromAddress,
fromUtxos,
fromPrivateKeys,
payment,
fee,
metadata,
verifyingContract
}, sendTransactionSchema)
const txBody = transaction.createTransactionBody({
fromAddress,
fromUtxos,
payment,
fee,
metadata
})
const typedData = transaction.getTypedData(txBody, verifyingContract)
server.auth.scheme('nuisance', function nuisanceScheme (server, options) {
Joi.assert(options, schema);
return {
authenticate: async function (request, h) {
const credentials = {};
let scope = [];
for (let i = 0; i < options.strategies.length; i++) {
let strategy = options.strategies[i];
let failureCredentials = null;
if (typeof strategy === 'object') {
failureCredentials = strategy.failureCredentials;
strategy = strategy.name;
}
let creds = null;
const validate = value => {
Joi.assert(value, Joi.any().invalid(Infinity, -Infinity), new TypeError(`Value is not a finite number: ${value}`))
Joi.assert(value, Joi.number().required(), new TypeError(`Value is not a number: ${value}`))
const parsed = parseInt(value, 10)
Joi.assert(parsed, Joi.number().integer(), new TypeError(`Value is not an integer: ${parsed}`))
Joi.assert(parsed, Joi.number().max(0), new TypeError(`Value is not a non-positive number: ${parsed}`))
Joi.assert(parsed, Joi.number().negative().allow(0), new TypeError(`Value is not a negative number: ${parsed}`))
return parsed
}
const validate = value => {
Joi.assert(value, Joi.string(), new TypeError(`Value is not string: ${value}`))
Joi.assert(value, Joi.string().regex(/^(?:[0-9A-Fa-f]{2}([:-]?)[0-9A-Fa-f]{2})(?:(?:\1|\.)(?:[0-9A-Fa-f]{2}([:-]?)[0-9A-Fa-f]{2})){2}$/),
new TypeError(`Value is not a valid MAC address: ${value}`))
return value
}
static validateDefinition() {
assertValidCategory(this.category, `Category for ${this.name}`)
assertValidRoute(this.route, `Route for ${this.name}`)
Joi.assert(
this.defaultBadgeData,
defaultBadgeDataSchema,
`Default badge data for ${this.name}`
)
this.examples.forEach((example, index) =>
validateExample(example, index, this)
)
}
async getInFlightExitId ({ txBytes }) {
Joi.assert({ txBytes }, getInFlightExitIdSchema)
const { contract } = await this.getPaymentExitGame()
return contract.methods.getInFlightExitId(txBytes).call()
}
const validate = value => {
Joi.assert(value, Joi.string(), new TypeError(`Value is not string: ${value}`))
Joi.assert(value, Joi.string().regex(/^rgba\(\s*(-?\d+|-?\d*\.\d+(?=%))(%?)\s*,\s*(-?\d+|-?\d*\.\d+(?=%))(\2)\s*,\s*(-?\d+|-?\d*\.\d+(?=%))(\2)\s*,\s*(-?\d+|-?\d*.\d+)\s*\)$/),
new TypeError(`Value is not a valid RGBA color: ${value}`))
return value
}
const validate = value => {
Joi.assert(value, Joi.string(), new TypeError(`Value is not string: ${value}`))
Joi.assert(value, Joi.string().regex(/^hsla\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)\s*\)$/),
new TypeError(`Value is not a valid HSLA color: ${value}`))
return value
}
async getExitTime ({
exitRequestBlockNumber,
submissionBlockNumber,
retries = 10
}) {
Joi.assert({ exitRequestBlockNumber, submissionBlockNumber }, getExitTimeSchema)
const bufferSeconds = 5
const retryInterval = 5000
const _minExitPeriodSeconds = await this.plasmaContract.methods.minExitPeriod().call()
const minExitPeriodSeconds = Number(_minExitPeriodSeconds)
const exitBlock = await this.web3.eth.getBlock(exitRequestBlockNumber)
if (!exitBlock) {
if (retries > 0) {
setTimeout(() => {
return this.getExitTime({ exitRequestBlockNumber, submissionBlockNumber, retries: retries - 1 })
}, retryInterval)
} else {
throw Error(`Could not get exit request block data: ${exitRequestBlockNumber}`)
}
}