// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
//   protoc-gen-ts_proto  v2.7.5
//   protoc               v6.30.2
// source: rekor/v2/hashedrekord.proto

/* eslint-disable */
import { HashOutput } from "../../sigstore_common";
import { Signature } from "./verifier";

/** A request to add a hashedrekord v0.0.2 to the log */
export interface HashedRekordRequestV002 {
  /** The hashed data */
  digest: Buffer;
  /** A single signature over the hashed data with the verifier needed to validate it */
  signature: Signature | undefined;
}

export interface HashedRekordLogEntryV002 {
  /** The hashed data */
  data:
    | HashOutput
    | undefined;
  /** A single signature over the hashed data with the verifier needed to validate it */
  signature: Signature | undefined;
}

export const HashedRekordRequestV002: MessageFns<HashedRekordRequestV002> = {
  fromJSON(object: any): HashedRekordRequestV002 {
    return {
      digest: isSet(object.digest) ? Buffer.from(bytesFromBase64(object.digest)) : Buffer.alloc(0),
      signature: isSet(object.signature) ? Signature.fromJSON(object.signature) : undefined,
    };
  },

  toJSON(message: HashedRekordRequestV002): unknown {
    const obj: any = {};
    if (message.digest.length !== 0) {
      obj.digest = base64FromBytes(message.digest);
    }
    if (message.signature !== undefined) {
      obj.signature = Signature.toJSON(message.signature);
    }
    return obj;
  },
};

export const HashedRekordLogEntryV002: MessageFns<HashedRekordLogEntryV002> = {
  fromJSON(object: any): HashedRekordLogEntryV002 {
    return {
      data: isSet(object.data) ? HashOutput.fromJSON(object.data) : undefined,
      signature: isSet(object.signature) ? Signature.fromJSON(object.signature) : undefined,
    };
  },

  toJSON(message: HashedRekordLogEntryV002): unknown {
    const obj: any = {};
    if (message.data !== undefined) {
      obj.data = HashOutput.toJSON(message.data);
    }
    if (message.signature !== undefined) {
      obj.signature = Signature.toJSON(message.signature);
    }
    return obj;
  },
};

function bytesFromBase64(b64: string): Uint8Array {
  return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
}

function base64FromBytes(arr: Uint8Array): string {
  return globalThis.Buffer.from(arr).toString("base64");
}

function isSet(value: any): boolean {
  return value !== null && value !== undefined;
}

interface MessageFns<T> {
  fromJSON(object: any): T;
  toJSON(message: T): unknown;
}
