How to use the @walletconnect/utils.concatBuffers 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 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
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 aesCbcDecrypt (
  data: Buffer,
  key: Buffer,
  iv: Buffer
): Promise {
  const decipher = crypto.createDecipheriv(AES_ALGORITHM, key, iv)
  let decrypted = decipher.update(data)
  decrypted = concatBuffers(decrypted, decipher.final())
  const result = decrypted
  return result
}