Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const middleware = (ctx, next) => {
if (!isValid(ctx.request.body)) {
// eslint-disable-next-line no-console
console.error(ctx.request.body, isValid.errors)
return Future.reject(new ValidationError(isValid.errors))
}
return next()
}
function dhSwitch(uid: string, url: string, auth, response, keys) {
switch (response._) {
case 'dh_gen_ok': return /*::joinChain(*/dhGenOk(response, keys, auth)/*::)*/
case 'dh_gen_retry': return /*::joinChain(*/dhGenRetry(uid, url, response, keys, auth)/*::)*/
case 'dh_gen_fail': return /*::joinChain(*/dhGenFail(response, keys, auth)/*::)*/
default: return reject(new Error('Unknown case'))/*::.mapRej(dhAnswerFail)*/
}
}
function refineResPQ(nonce, response) {
if (
typeof response !== 'object'
|| response == null
|| response instanceof Uint8Array
|| Array.isArray(response)
) return reject(ERR.sendPQ.noResponse())
if (response._ !== 'resPQ') {
return reject(ERR.sendPQ.response(response._))
}
const resp: ResPQ = (response: any)
if (!bytesCmp(nonce, resp.nonce)) {
return reject(ERR.sendPQ.nonce())
}
return of(resp)
}
const assertDhResponse = ({ nonce, serverNonce, newNonce }) => (
response: Server_DH_Params
)/*:: : Fluture<*, *> */ => {
if (response._ === 'server_DH_params_fail') {
const newNonceHash = sha1BytesSync(newNonce).slice(-16)
if (!bytesCmp(newNonceHash, response.new_nonce_hash)) {
return reject(ERR.sendDH.hash())/*::.mapRej(assertFail)*/
}
return reject(ERR.sendDH.fail())/*::.mapRej(assertFail)*/
}
if (response._ !== 'server_DH_params_ok') {
return reject(ERR.sendDH.invalid(response._))/*::.mapRej(assertFail)*/
}
if (!bytesCmp(nonce, response.nonce)) {
return reject(ERR.sendDH.nonce())/*::.mapRej(assertFail)*/
}
if (!bytesCmp(serverNonce, response.server_nonce)) {
return reject(ERR.sendDH.serverNonce())/*::.mapRej(assertFail)*/
}
return of(response)/*::.mapRej(assertFail)*/
}
const assertDhParams = (nonce, serverNonce) => (
response: Set_client_DH_params_answer
)/*::: Fluture */=> {
if (checkDhGen(response._)) {
return reject(ERR.dh.responseInvalid(response._))/*::.mapRej(assertFail)*/
} else if (!bytesCmp(nonce, response.nonce)) {
return reject(ERR.dh.nonce.mismatch())/*::.mapRej(assertFail)*/
} else if (!bytesCmp(serverNonce, response.server_nonce)) {
return reject(ERR.dh.nonce.server())/*::.mapRej(assertFail)*/
}
return of(response)/*::.mapRej(assertFail)*/
}
sub_(dhDec, one)
const case1 = !greater(gALeemon, one)
const case2 = !greater(dhDec, gALeemon)
if (case1)
return reject(ERR.verify.case1())/*::.mapRej(verifyFail)*/
if (case2)
return reject(ERR.verify.case2())/*::.mapRej(verifyFail)*/
const case3 = !!greater(leemonTwoPow, gALeemon)
const dhSubPow = dup(dhPrimeLeemon)
sub(dhSubPow, leemonTwoPow)
const case4 = !greater(dhSubPow, gALeemon)
if (case3)
return reject(ERR.verify.case3())/*::.mapRej(verifyFail)*/
if (case4)
return reject(ERR.verify.case4())/*::.mapRej(verifyFail)*/
innerLog('2^{2048-64} < gA < dhPrime-2^{2048-64} OK')
const offset = deserializer.getOffset()
if (!bytesCmp(hash, sha1BytesSync(answerWithPadding.slice(0, offset))))
return reject(ERR.decrypt.sha1())/*::.mapRej(decryptFail)*/
return of(response)/*::.mapRej(verifyFail)*/
}
export function safeImport(
fileName: string
): Future.FutureInstance {
let moduleObj = null
try {
moduleObj = require(fileName)
} catch (e) {
return e.code === 'MODULE_NOT_FOUND' ? Future.of(fileName) : Future.reject(e)
}
return Future.of(moduleObj)
}
export const userRegister = (registerData) => {
const usersWithEmail = models.Users.chain().find({
email: registerData.email,
})
if (usersWithEmail.count() > 0) {
return Future.reject("email_already_exists")
}
const createdUser = models.Users.insert({
email: registerData.email,
password: registerData.password,
})
return Future.of({ userId: createdUser.$loki })
}