How to use the rfc4648.base16.parse 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 / util / crypto / crypto.js View on Github external
export function decrypt (box: JsonBox, key: Uint8Array): Uint8Array {
  // Check JSON:
  if (box.encryptionType !== 0) {
    throw new Error('Unknown encryption type')
  }
  const iv = base16.parse(box.iv_hex)
  const ciphertext = base64.parse(box.data_base64)

  // Decrypt:
  const cipher = new AesCbc(key, iv)
  const raw = cipher.decrypt(ciphertext)
  // Alternative using node.js crypto:
  // const decipher = crypto.createDecipheriv('AES-256-CBC', key, iv);
  // let x = decipher.update(box.data_base64, 'base64', 'hex')
  // x += decipher.final('hex')
  // const data = base16.parse(x)

  // Calculate field locations:
  const headerSize = raw[0]
  const dataSize =
    (raw[1 + headerSize] << 24) |
    (raw[2 + headerSize] << 16) |
github EdgeApp / react-native-fast-crypto / index.js View on Github external
async function publicKeyCreate (privateKey: Uint8Array, compressed: boolean) {
  const privateKeyHex = base16.stringify(privateKey)
  const publicKeyHex: string = await RNFastCrypto.secp256k1EcPubkeyCreate(privateKeyHex, compressed)
  const outBuf = base16.parse(publicKeyHex, { 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
}
github EdgeApp / edge-core-js / src / core / account / account-files.js View on Github external
files.forEach(file => {
      const { SortIndex, Archived, BitcoinSeed, MK, SyncKey } = file.json

      const dataKey = base16.parse(MK)
      const bitcoinKey = base16.parse(BitcoinSeed)
      const syncKey = base16.parse(SyncKey)
      const keys = {
        bitcoinKey: base64.stringify(bitcoinKey),
        dataKey: base64.stringify(dataKey),
        format: 'bip32',
        syncKey: base64.stringify(syncKey)
      }

      const keyInfo = makeKeyInfo('wallet:bitcoin', keys, dataKey)
      walletInfos.push(keyInfo)
      walletStates[keyInfo.id] = {
        sortIndex: SortIndex,
        archived: Archived,
        deleted: false,
        hidden: false
github EdgeApp / edge-core-js / src / core / account / account-files.js View on Github external
files.forEach(file => {
      const { SortIndex, Archived, BitcoinSeed, MK, SyncKey } = file.json

      const dataKey = base16.parse(MK)
      const bitcoinKey = base16.parse(BitcoinSeed)
      const syncKey = base16.parse(SyncKey)
      const keys = {
        bitcoinKey: base64.stringify(bitcoinKey),
        dataKey: base64.stringify(dataKey),
        format: 'bip32',
        syncKey: base64.stringify(syncKey)
      }

      const keyInfo = makeKeyInfo('wallet:bitcoin', keys, dataKey)
      walletInfos.push(keyInfo)
      walletStates[keyInfo.id] = {
        sortIndex: SortIndex,
        archived: Archived,
        deleted: false,
        hidden: false
      }
github EdgeApp / edge-core-js / src / core / scrypt / scrypt-pixie.js View on Github external
function timeScrypt(
      data: Uint8Array,
      snrp: JsonSnrp,
      dklen: number = 32
    ): Promise<{ hash: Uint8Array, time: number }> {
      const salt = base16.parse(snrp.salt_hex)
      const startTime = getTime()
      log(`starting scrypt n=${snrp.n} r=${snrp.r} p=${snrp.p}`)
      return io.scrypt(data, salt, snrp.n, snrp.r, snrp.p, dklen).then(hash => {
        const time = getTime() - startTime
        log(`finished scrypt n=${snrp.n} r=${snrp.r} p=${snrp.p} in ${time}ms`)
        return { hash, time }
      })
    }
github EdgeApp / edge-core-js / src / core / account / account-files.js View on Github external
files.forEach(file => {
      const { SortIndex, Archived, BitcoinSeed, MK, SyncKey } = file.json

      const dataKey = base16.parse(MK)
      const bitcoinKey = base16.parse(BitcoinSeed)
      const syncKey = base16.parse(SyncKey)
      const keys = {
        bitcoinKey: base64.stringify(bitcoinKey),
        dataKey: base64.stringify(dataKey),
        format: 'bip32',
        syncKey: base64.stringify(syncKey)
      }

      const keyInfo = makeKeyInfo('wallet:bitcoin', keys, dataKey)
      walletInfos.push(keyInfo)
      walletStates[keyInfo.id] = {
        sortIndex: SortIndex,
        archived: Archived,
        deleted: false,
        hidden: false
      }
    })
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 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 / edge-core-js / src / core / fake / fake-world.js View on Github external
Object.keys(user.repos).map(async syncKey => {
      const paths = makeRepoPaths(io, base16.parse(syncKey), new Uint8Array(0))
      await saveChanges(paths.dataDisklet, user.repos[syncKey])
      await paths.baseDisklet.setText(
        'status.json',
        JSON.stringify({ lastSync: 1, lastHash: null })
      )
    })
  )