decrypt = (data, key) => {
  if (!key) {
    return /** @type {PromiseLike<Uint8Array>} */ (promise.resolve(data));
  }
  const dataDecoder = decoding.createDecoder(data);
  const algorithm = decoding.readVarString(dataDecoder);
  if (algorithm !== "AES-GCM") {
    promise.reject(error.create("Unknown encryption algorithm"));
  }
  const iv = decoding.readVarUint8Array(dataDecoder);
  const cipher = decoding.readVarUint8Array(dataDecoder);
  return crypto.subtle
    .decrypt(
      {
        name: "AES-GCM",
        iv,
      },
      key,
      cipher
    )
    .then((data) => new Uint8Array(data));
}
@param {Uint8Array} data
@param {CryptoKey?} key
@return {PromiseLike<Uint8Array>} decrypted buffer