How to use the @walletconnect/utils.convertBufferToHex 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 encrypt (
  data: IJsonRpcRequest | IJsonRpcResponseSuccess | IJsonRpcResponseError,
  key: ArrayBuffer
): Promise {
  const _key: Buffer = convertArrayBufferToBuffer(key)

  const ivArrayBuffer: ArrayBuffer = await generateKey(128)
  const iv: Buffer = convertArrayBufferToBuffer(ivArrayBuffer)
  const ivHex: string = convertBufferToHex(iv, true)

  const contentString: string = JSON.stringify(data)
  const content: Buffer = convertUtf8ToBuffer(contentString)

  const cipherText: Buffer = await aesCbcEncrypt(content, _key, iv)
  const cipherTextHex: string = convertBufferToHex(cipherText, true)

  const unsigned: Buffer = concatBuffers(cipherText, iv)
  const hmac: Buffer = await createHmac(unsigned, _key)
  const hmacHex: string = convertBufferToHex(hmac, true)

  return {
    data: cipherTextHex,
    hmac: hmacHex,
    iv: ivHex
  }
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 encrypt (
  data: IJsonRpcRequest | IJsonRpcResponseSuccess | IJsonRpcResponseError,
  key: ArrayBuffer
): Promise {
  const _key: Buffer = convertArrayBufferToBuffer(key)

  const ivArrayBuffer: ArrayBuffer = await generateKey(128)
  const iv: Buffer = convertArrayBufferToBuffer(ivArrayBuffer)
  const ivHex: string = convertBufferToHex(iv, true)

  const contentString: string = JSON.stringify(data)
  const content: Buffer = convertUtf8ToBuffer(contentString)

  const cipherText: Buffer = await aesCbcEncrypt(content, _key, iv)
  const cipherTextHex: string = convertBufferToHex(cipherText, true)

  const unsigned: Buffer = concatBuffers(cipherText, iv)
  const hmac: Buffer = await createHmac(unsigned, _key)
  const hmacHex: string = convertBufferToHex(hmac, true)

  return {
    data: cipherTextHex,
    hmac: hmacHex,
    iv: ivHex
  }
}
github WalletConnect / walletconnect-monorepo / packages / react-native / src / rnCrypto.ts View on Github external
): Promise {
  const _key: Buffer = convertArrayBufferToBuffer(key)

  const ivArrayBuffer: ArrayBuffer = await generateKey(128)
  const iv: Buffer = convertArrayBufferToBuffer(ivArrayBuffer)
  const ivHex: string = convertBufferToHex(iv, true)

  const contentString: string = JSON.stringify(data)
  const content: Buffer = convertUtf8ToBuffer(contentString)

  const cipherText: Buffer = await aesCbcEncrypt(content, _key, iv)
  const cipherTextHex: string = convertBufferToHex(cipherText, true)

  const unsigned: Buffer = concatBuffers(cipherText, iv)
  const hmac: Buffer = await createHmac(unsigned, _key)
  const hmacHex: string = convertBufferToHex(hmac, true)

  return {
    data: cipherTextHex,
    hmac: hmacHex,
    iv: ivHex
  }
}
github WalletConnect / walletconnect-monorepo / packages / react-native / src / rnCrypto.ts View on Github external
export async function generateKey (length?: number): Promise {
  const _length = (length || 256) / 8
  const buffer: Buffer = await randomBytes(_length)
  const hex = convertBufferToHex(buffer, true)
  const result = convertHexToArrayBuffer(hex)

  return result
}
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
}