How to use the @walletconnect/utils.convertArrayBufferToHex 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 / browser / src / webCrypto.ts View on Github external
export async function verifyHmac (
  payload: IEncryptionPayload,
  key: ArrayBuffer
): Promise {
  const cipherText: ArrayBuffer = convertHexToArrayBuffer(payload.data)
  const iv: ArrayBuffer = convertHexToArrayBuffer(payload.iv)
  const hmac: ArrayBuffer = convertHexToArrayBuffer(payload.hmac)
  const hmacHex: string = convertArrayBufferToHex(hmac, true)

  const unsigned: ArrayBuffer = concatArrayBuffers(cipherText, iv)
  const chmac: ArrayBuffer = await createHmac(unsigned, key)
  const chmacHex: string = convertArrayBufferToHex(chmac, true)

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

  return false
}
github WalletConnect / walletconnect-monorepo / packages / core / src / index.ts View on Github external
get key (): string {
    if (this._key) {
      const key: string = convertArrayBufferToHex(this._key, true)
      return key
    }
    return ''
  }
github WalletConnect / walletconnect-monorepo / packages / browser / src / webCrypto.ts View on Github external
export async function verifyHmac (
  payload: IEncryptionPayload,
  key: ArrayBuffer
): Promise {
  const cipherText: ArrayBuffer = convertHexToArrayBuffer(payload.data)
  const iv: ArrayBuffer = convertHexToArrayBuffer(payload.iv)
  const hmac: ArrayBuffer = convertHexToArrayBuffer(payload.hmac)
  const hmacHex: string = convertArrayBufferToHex(hmac, true)

  const unsigned: ArrayBuffer = concatArrayBuffers(cipherText, iv)
  const chmac: ArrayBuffer = await createHmac(unsigned, key)
  const chmacHex: string = convertArrayBufferToHex(chmac, true)

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

  return false
}
github WalletConnect / walletconnect-monorepo / packages / browser / src / webCrypto.ts View on Github external
if (!key) {
    throw new Error('Missing key: required for encryption')
  }

  const iv: ArrayBuffer = await generateKey(128)
  const ivHex: string = convertArrayBufferToHex(iv, true)

  const contentString: string = JSON.stringify(data)
  const content: ArrayBuffer = convertUtf8ToArrayBuffer(contentString)

  const cipherText: ArrayBuffer = await aesCbcEncrypt(content, key, iv)
  const cipherTextHex: string = convertArrayBufferToHex(cipherText, true)

  const unsigned: ArrayBuffer = concatArrayBuffers(cipherText, iv)
  const hmac: ArrayBuffer = await createHmac(unsigned, key)
  const hmacHex: string = convertArrayBufferToHex(hmac, true)

  return {
    data: cipherTextHex,
    hmac: hmacHex,
    iv: ivHex
  }
}
github WalletConnect / walletconnect-monorepo / packages / browser / src / webCrypto.ts View on Github external
export async function encrypt (
  data: IJsonRpcRequest | IJsonRpcResponseSuccess | IJsonRpcResponseError,
  key: ArrayBuffer
): Promise {
  if (!key) {
    throw new Error('Missing key: required for encryption')
  }

  const iv: ArrayBuffer = await generateKey(128)
  const ivHex: string = convertArrayBufferToHex(iv, true)

  const contentString: string = JSON.stringify(data)
  const content: ArrayBuffer = convertUtf8ToArrayBuffer(contentString)

  const cipherText: ArrayBuffer = await aesCbcEncrypt(content, key, iv)
  const cipherTextHex: string = convertArrayBufferToHex(cipherText, true)

  const unsigned: ArrayBuffer = concatArrayBuffers(cipherText, iv)
  const hmac: ArrayBuffer = await createHmac(unsigned, key)
  const hmacHex: string = convertArrayBufferToHex(hmac, true)

  return {
    data: cipherTextHex,
    hmac: hmacHex,
    iv: ivHex
  }
github WalletConnect / walletconnect-monorepo / packages / browser / src / webCrypto.ts View on Github external
export async function encrypt (
  data: IJsonRpcRequest | IJsonRpcResponseSuccess | IJsonRpcResponseError,
  key: ArrayBuffer
): Promise {
  if (!key) {
    throw new Error('Missing key: required for encryption')
  }

  const iv: ArrayBuffer = await generateKey(128)
  const ivHex: string = convertArrayBufferToHex(iv, true)

  const contentString: string = JSON.stringify(data)
  const content: ArrayBuffer = convertUtf8ToArrayBuffer(contentString)

  const cipherText: ArrayBuffer = await aesCbcEncrypt(content, key, iv)
  const cipherTextHex: string = convertArrayBufferToHex(cipherText, true)

  const unsigned: ArrayBuffer = concatArrayBuffers(cipherText, iv)
  const hmac: ArrayBuffer = await createHmac(unsigned, key)
  const hmacHex: string = convertArrayBufferToHex(hmac, true)

  return {
    data: cipherTextHex,
    hmac: hmacHex,
    iv: ivHex
  }
}
github WalletConnect / walletconnect-monorepo / packages / core / src / index.ts View on Github external
get nextKey (): string {
    if (this._nextKey) {
      const nextKey: string = convertArrayBufferToHex(this._nextKey)
      return nextKey
    }
    return ''
  }