How to use the rfc4648.base16.stringify function in rfc4648

To help you get started, we’ve selected a few rfc4648 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 EdgeApp / edge-core-js / src / core / scrypt / scrypt-pixie.js View on Github external
export function calcSnrpForTarget(
  salt: Uint8Array,
  benchMs: number,
  targetMs: number
): JsonSnrp {
  const snrp = {
    salt_hex: base16.stringify(salt),
    n: 16384,
    r: 8,
    p: 1
  }

  if (benchMs === 0) {
    snrp.n = 131072
    snrp.r = 8
    snrp.p = 64
    return snrp
  }

  let timeUsed = benchMs // Estimated time in ms the current setting will take on current device

  //
  // Add additional r value first. This increases memory usage
github EdgeApp / edge-login-ui / packages / edge-login-ui-web / src / frame / frame-state.js View on Github external
createCurrencyWallet (accountId: string, type: string) {
          // Hack in basic Ethereum support for Augur:
          if (type === 'wallet:ethereum') {
            return state.accounts[accountId]
              .createWallet(type, {
                ethereumKey: base16.stringify(makeRandom(32))
              })
              .then(walletId => {
                const walletInfos = getWalletInfos(state, accountId)
                return { walletId, walletInfos }
              })
          }

          return state.accounts[accountId]
            .createCurrencyWallet(type, {})
            .then(currencyWallet => {
              const walletInfos = getWalletInfos(state, accountId)
              return { walletId: currencyWallet.id, walletInfos }
            })
        },
github EdgeApp / edge-core-js / src / core / storage / repo.js View on Github external
).then(ourChanges => {
    // If we have local changes, we need to bundle those:
    const request = {}
    if (ourChanges.length > 0) {
      request.changes = {}
      for (const change of ourChanges) {
        request.changes[change.name] = change.json
      }
    }
    const method = request.changes ? 'POST' : 'GET'

    // Calculate the URI:
    let path = '/api/v2/store/' + base16.stringify(syncKey).toLowerCase()
    if (status.lastHash != null) {
      path += '/' + status.lastHash
    }

    // Make the request:
    return syncRequest(io, log, method, path, request).then(reply => {
      const { changes = {}, hash } = reply

      // Save the incoming changes into our `data` folder:
      return saveChanges(dataDisklet, changes)
        .then(
          // Delete any changed keys (since the upload is done):
          () => Promise.all(ourChanges.map(change => change.file.delete()))
        )
        .then(() => {
          // Update the repo status:
github EdgeApp / edge-core-js / src / core / login / keys.js View on Github external
export function makeKeysKit(
  ai: ApiInput,
  login: LoginTree,
  ...keyInfos: StorageWalletInfo[]
): LoginKit {
  const { io } = ai.props
  const keyBoxes = keyInfos.map(info =>
    encrypt(io, utf8.parse(JSON.stringify(info)), login.loginKey)
  )
  const newSyncKeys: string[] = []
  for (const info of keyInfos) {
    if (info.keys.syncKey != null) {
      const data = base64.parse(info.keys.syncKey)
      newSyncKeys.push(base16.stringify(data).toLowerCase())
    }
  }

  return {
    serverPath: '/v2/login/keys',
    server: { keyBoxes, newSyncKeys },
    stash: { keyBoxes },
    login: { keyInfos },
    loginId: login.loginId
  }
}
github EdgeApp / edge-core-js / src / core / swap / changelly-plugin.js View on Github external
async function call (json: any) {
    const body = JSON.stringify(json)
    const sign = base16
      .stringify(hmacSha512(utf8.parse(body), secret))
      .toLowerCase()

    io.console.info('changelly call:', json)
    const headers = {
      'Content-Type': 'application/json',
      'api-key': apiKey,
      sign
    }
    const reply = await io.fetch(uri, { method: 'POST', body, headers })
    if (!reply.ok) {
      throw new Error(`Changelly returned error code ${reply.status}`)
    }
    const out = await reply.json()
    io.console.info('changelly reply:', out)
    return out
github EdgeApp / react-native-fast-crypto / index.js View on Github external
async function pbkdf2DeriveAsync(key: Uint8Array, salt: Uint8Array, iter: number, len: number, alg: string) {
  if (alg !== 'sha512') {
    throw new Error('ErrorUnsupportedPbkdf2Algorithm: ' + alg)
  }
  const keyHex = base16.stringify(key)
  const saltHex = base16.stringify(salt)
  const resultHex = await RNFastCrypto.pbkdf2Sha512(keyHex, saltHex, iter, len)
  const outBuf = base16.parse(resultHex, { out: Buffer.allocUnsafe })
  return outBuf
}
github EdgeApp / react-native-fast-crypto / index.js View on Github external
async function publicKeyTweakAdd (publicKey: Uint8Array, tweak: Uint8Array, compressed: boolean) {
  const publicKeyHex = base16.stringify(publicKey)
  const tweakHex = base16.stringify(tweak)
  const publickKeyTweakedHex: string = await RNFastCrypto.secp256k1EcPubkeyTweakAdd(publicKeyHex, tweakHex, compressed)
  const outBuf = base16.parse(publickKeyTweakedHex, { out: Buffer.allocUnsafe })
  return outBuf
}
github EdgeApp / react-native-fast-crypto / index.js View on Github external
async function privateKeyTweakAdd (privateKey: Uint8Array, tweak: Uint8Array) {
  const privateKeyHex = base16.stringify(privateKey)
  const tweakHex = base16.stringify(tweak)
  const privateKeyTweakedHex: string = await RNFastCrypto.secp256k1EcPrivkeyTweakAdd(privateKeyHex, tweakHex)
  const outBuf = base16.parse(privateKeyTweakedHex, { out: Buffer.allocUnsafe })
  return outBuf
}