How to use the rfc4648.base64.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 / core / login / lobby.js View on Github external
return authRequest(ai, 'GET', '/v2/lobby/' + lobbyId, {}).then(reply => {
    const lobbyRequest = reply.request

    // Verify the public key:
    const pubkey = base64.parse(lobbyRequest.publicKey)
    const checksum = sha256(sha256(pubkey))
    base58.parse(lobbyId).forEach((value, index) => {
      if (value !== checksum[index]) {
        throw new Error('Lobby ECDH integrity error')
      }
    })

    return lobbyRequest
  })
}
github EdgeApp / edge-core-js / src / core / login / login.js View on Github external
login.otpResetDate = stash.otpResetDate
  login.otpTimeout = stash.otpTimeout

  // Password:
  if (stash.userId != null) {
    login.userId = stash.userId
  } else if (stash.passwordAuthBox != null) {
    login.userId = login.loginId
  }
  if (stash.passwordAuthBox != null) {
    login.passwordAuth = decrypt(stash.passwordAuthBox, loginKey)
  }

  // PIN v2:
  if (stash.pin2Key != null) {
    login.pin2Key = base64.parse(stash.pin2Key)
  }
  if (stash.pin2TextBox != null) {
    login.pin = utf8.stringify(decrypt(stash.pin2TextBox, loginKey))
  }

  // Recovery v2:
  if (stash.recovery2Key != null) {
    login.recovery2Key = base64.parse(stash.recovery2Key)
  }

  const legacyKeys = []

  // BitID wallet:
  const { mnemonicBox, rootKeyBox } = stash
  if (mnemonicBox != null && rootKeyBox != null) {
    const rootKey = decrypt(rootKeyBox, loginKey)
github EdgeApp / edge-core-js / src / core / login / login.js View on Github external
}
  if (stash.passwordAuthBox != null) {
    login.passwordAuth = decrypt(stash.passwordAuthBox, loginKey)
  }

  // PIN v2:
  if (stash.pin2Key != null) {
    login.pin2Key = base64.parse(stash.pin2Key)
  }
  if (stash.pin2TextBox != null) {
    login.pin = utf8.stringify(decrypt(stash.pin2TextBox, loginKey))
  }

  // Recovery v2:
  if (stash.recovery2Key != null) {
    login.recovery2Key = base64.parse(stash.recovery2Key)
  }

  const legacyKeys = []

  // BitID wallet:
  const { mnemonicBox, rootKeyBox } = stash
  if (mnemonicBox != null && rootKeyBox != null) {
    const rootKey = decrypt(rootKeyBox, loginKey)
    const infoKey = hmacSha256(rootKey, utf8.parse('infoKey'))
    const keys = {
      mnemonic: utf8.stringify(decrypt(mnemonicBox, infoKey)),
      rootKey: base64.stringify(rootKey)
    }
    legacyKeys.push(makeKeyInfo('wallet:bitid', keys, rootKey))
  }
github EdgeApp / edge-core-js / src / core / login / keys.js View on Github external
newWalletType: string
): EdgeWalletInfo {
  const { id, type, keys } = walletInfo
  if (!keys.dataKey || !keys.syncKey) {
    throw new Error(`Wallet ${id} is not a splittable type`)
  }

  const dataKey = base64.parse(keys.dataKey)
  const syncKey = base64.parse(keys.syncKey)
  const xorKey = xorData(
    hmacSha256(utf8.parse(type), dataKey),
    hmacSha256(utf8.parse(newWalletType), dataKey)
  )

  // Fix the id:
  const newWalletId = xorData(base64.parse(id), xorKey)
  const newSyncKey = xorData(syncKey, xorKey.subarray(0, syncKey.length))

  // Fix the keys:
  const networkName = type.replace(/wallet:/, '').replace('-', '')
  const newNetworkName = newWalletType.replace(/wallet:/, '').replace('-', '')
  const newKeys = {}
  for (const key of Object.keys(keys)) {
    if (key === networkName + 'Key') {
      newKeys[newNetworkName + 'Key'] = keys[key]
    } else {
      newKeys[key] = keys[key]
    }
  }

  return {
    id: base64.stringify(newWalletId),
github EdgeApp / edge-core-js / src / core / login / split.js View on Github external
function deriveXorKey (
  newWalletType: string,
  walletInfo: EdgeWalletInfo
): Uint8Array {
  const { keys, type } = walletInfo
  const dataKey = base64.parse(keys.dataKey)
  return xorData(
    hmacSha256(utf8.parse(type), dataKey),
    hmacSha256(utf8.parse(newWalletType), dataKey)
  )
}
github EdgeApp / edge-core-js / src / core / login / pin2.js View on Github external
export function getPin2Key(stashTree: LoginStash, appId: string) {
  const stash =
    stashTree.pin2Key != null
      ? stashTree
      : searchTree(stashTree, stash => stash.appId === appId)
  return stash != null && stash.pin2Key != null
    ? { pin2Key: base64.parse(stash.pin2Key), appId: stash.appId }
    : { pin2Key: undefined, appId: undefined }
}
github EdgeApp / edge-core-js / src / core / login / keys.js View on Github external
export function makeStorageKeyInfo(
  ai: ApiInput,
  type: string,
  keys: StorageKeys = {}
) {
  const { io } = ai.props
  if (keys.dataKey == null) keys.dataKey = base64.stringify(io.random(32))
  if (keys.syncKey == null) keys.syncKey = base64.stringify(io.random(20))

  return makeKeyInfo(type, keys, base64.parse(keys.dataKey))
}
github EdgeApp / edge-core-js / src / core / login / split.js View on Github external
function splitStorageKeys (
  newWalletType: string,
  walletInfo: EdgeWalletInfo
): Object {
  const { keys } = walletInfo
  const xorKey = deriveXorKey(newWalletType, walletInfo)
  const syncKey = base64.parse(keys.syncKey)

  return {
    dataKey: keys.dataKey,
    syncKey: base64.stringify(
      xorData(syncKey, xorKey.subarray(0, syncKey.length))
    )
  }
}
github EdgeApp / edge-core-js / src / core / login / split.js View on Github external
function splitWalletId (
  newWalletType: string,
  walletInfo: EdgeWalletInfo
): string {
  const { id } = walletInfo
  const xorKey = deriveXorKey(newWalletType, walletInfo)
  return base64.stringify(xorData(base64.parse(id), xorKey))
}