How to use the @walletconnect/utils.convertHexToBuffer function in @walletconnect/utils

To help you get started, we’ve selected a few @walletconnect/utils 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 WalletConnect / walletconnect-monorepo / packages / react-native / src / rnCrypto.ts View on Github external
export async function createHmac (data: Buffer, key: Buffer): Promise {
  const hmac = crypto.createHmac(HMAC_ALGORITHM, key)
  hmac.update(data)
  const hex = hmac.digest('hex')
  const result = convertHexToBuffer(hex)

  return result
}
github WalletConnect / walletconnect-monorepo / packages / react-native / src / rnCrypto.ts View on Github external
): Promise<
  IJsonRpcRequest | IJsonRpcResponseSuccess | IJsonRpcResponseError | null
> {
  const _key: Buffer = convertArrayBufferToBuffer(key)

  if (!_key) {
    throw new Error('Missing key: required for decryption')
  }

  const verified: boolean = await verifyHmac(payload, _key)
  if (!verified) {
    return null
  }

  const cipherText: Buffer = convertHexToBuffer(payload.data)
  const iv: Buffer = convertHexToBuffer(payload.iv)
  const buffer: Buffer = await aesCbcDecrypt(cipherText, _key, iv)
  const utf8: string = convertBufferToUtf8(buffer)
  let data: IJsonRpcRequest
  try {
    data = JSON.parse(utf8)
  } catch (error) {
    return null
  }

  return data
}
github WalletConnect / walletconnect-monorepo / packages / react-native / src / rnCrypto.ts View on Github external
export async function verifyHmac (
  payload: IEncryptionPayload,
  key: Buffer
): Promise {
  const cipherText: Buffer = convertHexToBuffer(payload.data)
  const iv: Buffer = convertHexToBuffer(payload.iv)
  const hmac: Buffer = convertHexToBuffer(payload.hmac)
  const hmacHex: string = convertBufferToHex(hmac, true)
  const unsigned: Buffer = concatBuffers(cipherText, iv)
  const chmac: Buffer = await createHmac(unsigned, key)
  const chmacHex: string = convertBufferToHex(chmac, true)

  if (removeHexPrefix(hmacHex) === removeHexPrefix(chmacHex)) {
    return true
  }

  return false
}
github WalletConnect / walletconnect-monorepo / packages / react-native / src / rnCrypto.ts View on Github external
export async function verifyHmac (
  payload: IEncryptionPayload,
  key: Buffer
): Promise {
  const cipherText: Buffer = convertHexToBuffer(payload.data)
  const iv: Buffer = convertHexToBuffer(payload.iv)
  const hmac: Buffer = convertHexToBuffer(payload.hmac)
  const hmacHex: string = convertBufferToHex(hmac, true)
  const unsigned: Buffer = concatBuffers(cipherText, iv)
  const chmac: Buffer = await createHmac(unsigned, key)
  const chmacHex: string = convertBufferToHex(chmac, true)

  if (removeHexPrefix(hmacHex) === removeHexPrefix(chmacHex)) {
    return true
  }

  return false
}
github WalletConnect / walletconnect-monorepo / packages / react-native / src / rnCrypto.ts View on Github external
export async function verifyHmac (
  payload: IEncryptionPayload,
  key: Buffer
): Promise {
  const cipherText: Buffer = convertHexToBuffer(payload.data)
  const iv: Buffer = convertHexToBuffer(payload.iv)
  const hmac: Buffer = convertHexToBuffer(payload.hmac)
  const hmacHex: string = convertBufferToHex(hmac, true)
  const unsigned: Buffer = concatBuffers(cipherText, iv)
  const chmac: Buffer = await createHmac(unsigned, key)
  const chmacHex: string = convertBufferToHex(chmac, true)

  if (removeHexPrefix(hmacHex) === removeHexPrefix(chmacHex)) {
    return true
  }

  return false
}
github WalletConnect / walletconnect-monorepo / packages / react-native / src / rnCrypto.ts View on Github external
key: ArrayBuffer
): Promise<
  IJsonRpcRequest | IJsonRpcResponseSuccess | IJsonRpcResponseError | null
> {
  const _key: Buffer = convertArrayBufferToBuffer(key)

  if (!_key) {
    throw new Error('Missing key: required for decryption')
  }

  const verified: boolean = await verifyHmac(payload, _key)
  if (!verified) {
    return null
  }

  const cipherText: Buffer = convertHexToBuffer(payload.data)
  const iv: Buffer = convertHexToBuffer(payload.iv)
  const buffer: Buffer = await aesCbcDecrypt(cipherText, _key, iv)
  const utf8: string = convertBufferToUtf8(buffer)
  let data: IJsonRpcRequest
  try {
    data = JSON.parse(utf8)
  } catch (error) {
    return null
  }

  return data
}