Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Fluture: https://github.com/fluture-js/Fluture
const { Client } = require('tdl')
const Future = require('fluture')
const client = new Client({
apiId: 2222, // Your api_id
apiHash: 'YOUR_API_HASH'
})
const searchChat = username =>
client.invokeFuture({ _: 'searchPublicChat', username })
.map(chat => `Chat: ${chat.title}, id: ${chat.id}`)
.mapRej(err => `Error: ${err.message}`)
const login = Future.encaseP(client.login)
Future
.tryP(client.connect)
.chain(() => login(() => ({
phoneNumber: 'YOUR_PHONE_NUMBER'
})))
.chain(() => searchChat('username'))
.fork(console.error, console.log)
.chain(diff => {
const prompt = new Confirm(
'Do you want to patch your system with these changes?'
)
const runPrompt = Future.encaseP(() => prompt.run())
return runPrompt().chain(shouldRun => {
return shouldRun ? gyne.patch(diff) : Future.of(null)
})
})
}
bytes => encaseP(sha1HashPlain, bytes)
.map(msgKeyFromHash)
.chain(res => encaseP(async res => {
const setter = Config.storageAdapter.set
await setter.salt(uid, dc, res.serverSalt)
await setter.authKey(uid, dc, res.authKey)
await setter.authID(uid, dc, res.authKeyID)
return res
}, res))
.map(res => (dispatch(MAIN.AUTH.RESOLVE(res), uid), res))
.map(res => (dispatch(MAIN.AUTH.RESOLVE(res), uid), res))
const future = cache(runThread)
Config.authRequest.set(uid, dc, future)
return future
}
const failureHandler = (uid: UID, dc: DCNumber) => (err) => {
log`authChain, error`(err)
Config.authRequest.remove(uid, dc)
return err
}
const modPowF = encaseP(Config.common.Crypto.modPow)
const modPowPartial = (b, dhPrime) => x => modPowF({ x, y: b, m: dhPrime })/*::.mapRej(cryptoErr)*/
const factorize = encaseP(Config.common.Crypto.factorize)
const normalizeResPQ = (res: ResPQ) => ({
serverNonce : res.server_nonce,
pq : res.pq,
fingerprints: res.server_public_key_fingerprints,
...res
})
const makePqBlock = (uid: string) => (ctx) => {
const { serverNonce, fingerprints, pq, it } = ctx
log`PQ factorization done`(it)
log`Got ResPQ`(bytesToHex(serverNonce), bytesToHex(pq), fingerprints)
try {
const publicKey = Config.publicKeys.select(uid, fingerprints)
return of({ ...ctx, publicKey })
await setter.authID(uid, dc, res.authKeyID)
return res
}, res))
.map(res => (dispatch(MAIN.AUTH.RESOLVE(res), uid), res))
const future = cache(runThread)
Config.authRequest.set(uid, dc, future)
return future
}
const failureHandler = (uid: UID, dc: DCNumber) => (err) => {
log`authChain, error`(err)
Config.authRequest.remove(uid, dc)
return err
}
const modPowF = encaseP(Config.common.Crypto.modPow)
const modPowPartial = (b, dhPrime) => x => modPowF({ x, y: b, m: dhPrime })/*::.mapRej(cryptoErr)*/
const factorize = encaseP(Config.common.Crypto.factorize)
const normalizeResPQ = (res: ResPQ) => ({
serverNonce : res.server_nonce,
pq : res.pq,
fingerprints: res.server_public_key_fingerprints,
...res
})
const makePqBlock = (uid: string) => (ctx) => {
const { serverNonce, fingerprints, pq, it } = ctx
log`PQ factorization done`(it)
log`Got ResPQ`(bytesToHex(serverNonce), bytesToHex(pq), fingerprints)