How to use the fluture.encaseP function in fluture

To help you get started, we’ve selected a few fluture examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Bannerets / tdl / examples / using-fluture.js View on Github external
// 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)
github ahdinosaur / gyne / bin.js View on Github external
.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)
      })
    })
}
github zerobias / telegram-mtproto / packages / telegram-mtproto / src / service / authorizer / index.js View on Github external
    .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))
github zerobias / telegram-mtproto / packages / telegram-mtproto / src / service / authorizer / index.js View on Github external
.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 })
github zerobias / telegram-mtproto / packages / telegram-mtproto / src / service / authorizer / index.js View on Github external
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)