// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
//   protoc-gen-ts_proto  v2.11.4
//   protoc               unknown
// source: cheqd/did/v2/tx.proto

/* eslint-disable */
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
import { Coin } from "../../../cosmos/base/v1beta1/coin.js";
import { DidDocWithMetadata, Service, VerificationMethod } from "./diddoc.js";
import { FeeParams } from "./fee.js";

/**
 * MsgCreateDidDoc defines the Msg/CreateDidDoc request type.
 * It describes the parameters of a request for creating a new DID document.
 */
export interface MsgCreateDidDoc {
  /** Payload containing the DID Document to be created */
  payload:
    | MsgCreateDidDocPayload
    | undefined;
  /** Signatures of the DID Document's controller(s) */
  signatures: SignInfo[];
}

/**
 * MsgUpdateDidDoc defines the Msg/UpdateDidDoc request type.
 * It describes the parameters of a request for updating an existing DID document.
 */
export interface MsgUpdateDidDoc {
  /** Payload containing the DID Document to be updated. This should be updated the DID Document. */
  payload:
    | MsgUpdateDidDocPayload
    | undefined;
  /** Signatures of the DID Document's controller(s) */
  signatures: SignInfo[];
}

/**
 * MsgDeactivateDidDoc defines the Msg/DeactivateDidDoc request type.
 * It describes the parameters of a request for deactivating an existing DID document.
 */
export interface MsgDeactivateDidDoc {
  /** Payload containing the DID Document to be deactivated */
  payload:
    | MsgDeactivateDidDocPayload
    | undefined;
  /** Signatures of the DID Document's controller(s) */
  signatures: SignInfo[];
}

/** SignInfo defines the structure of a DID Document controller's signature */
export interface SignInfo {
  /** Verification method ID of the DID Controller */
  verificationMethodId: string;
  /** Signature of the DID Document controller */
  signature: Uint8Array;
}

/** MsgCreateDidDocPayload defines the structure of the payload for creating a new DID document */
export interface MsgCreateDidDocPayload {
  /**
   * context is a list of URIs used to identify the context of the DID document.
   * Default: https://www.w3.org/ns/did/v1
   */
  context: string[];
  /**
   * id is the DID of the DID document.
   * Format: did:cheqd:<namespace>:<unique-identifier>
   */
  id: string;
  /** controller is a list of DIDs that are allowed to control the DID document. */
  controller: string[];
  /**
   * verificationMethod is a list of verification methods that can be used to
   * verify a digital signature or cryptographic proof.
   * Documentation: https://www.w3.org/TR/did-core/#verification-methods
   *
   * Required fields:
   * - id: A unique identifier for the verification method
   * - type: A supported verification method type (supported: Ed25519VerificationKey2018, Ed25519VerificationKey2020, JsonWebKey2020)
   * - controller: DID of the controller of the verification method
   * - verification_material: Public key of the verification method (supported: publicJwk, publicKeyBase58, publicKeyMultibase)
   */
  verificationMethod: VerificationMethod[];
  /**
   * authentication is a list of verification methods that can be used to
   * authenticate as the DID subject.
   */
  authentication: string[];
  /**
   * assertionMethod is a list of verification methods that can be used to
   * assert statements as the DID subject.
   */
  assertionMethod: string[];
  /**
   * capabilityInvocation is a list of verification methods that can be used to
   * invoke capabilities as the DID subject.
   */
  capabilityInvocation: string[];
  /**
   * capabilityDelegation is a list of verification methods that can be used to
   * delegate capabilities as the DID subject.
   */
  capabilityDelegation: string[];
  /**
   * keyAgreement is a list of verification methods that can be used to perform
   * key agreement as the DID subject.
   */
  keyAgreement: string[];
  /**
   * service is a list of services that can be used to interact with the DID subject.
   * Documentation: https://www.w3.org/TR/did-core/#services
   *
   * Required fields:
   * - id: A unique identifier for the service
   * - type: A service type defined in DID Specification Registries
   * - service_endpoint: Service endpoint(s), provided as a URI or set of URIs
   */
  service: Service[];
  /** alsoKnownAs is a list of DIDs that are known to refer to the same DID subject. */
  alsoKnownAs: string[];
  /**
   * Version ID of the DID Document to be created
   *
   * Format: <uuid>
   */
  versionId: string;
}

/** MsgCreateDidDocResponse defines response type for Msg/CreateDidDoc. */
export interface MsgCreateDidDocResponse {
  /** Return the created DID Document with metadata */
  value: DidDocWithMetadata | undefined;
}

/** MsgUpdateDidDocPayload defines the structure of the payload for updating an existing DID document */
export interface MsgUpdateDidDocPayload {
  /**
   * context is a list of URIs used to identify the context of the DID document.
   * Default: https://www.w3.org/ns/did/v1
   */
  context: string[];
  /**
   * id is the DID of the DID document.
   * Format: did:cheqd:<namespace>:<unique-identifier>
   */
  id: string;
  /** controller is a list of DIDs that are allowed to control the DID document. */
  controller: string[];
  /**
   * verificationMethod is a list of verification methods that can be used to
   * verify a digital signature or cryptographic proof.
   * Documentation: https://www.w3.org/TR/did-core/#verification-methods
   *
   * Required fields:
   * - id: A unique identifier for the verification method
   * - type: A supported verification method type (supported: Ed25519VerificationKey2018, Ed25519VerificationKey2020, JsonWebKey2020)
   * - controller: DID of the controller of the verification method
   * - verification_material: Public key of the verification method (supported: publicJwk, publicKeyBase58, publicKeyMultibase)
   */
  verificationMethod: VerificationMethod[];
  /**
   * authentication is a list of verification methods that can be used to
   * authenticate as the DID subject.
   */
  authentication: string[];
  /**
   * assertionMethod is a list of verification methods that can be used to
   * assert statements as the DID subject.
   */
  assertionMethod: string[];
  /**
   * capabilityInvocation is a list of verification methods that can be used to
   * invoke capabilities as the DID subject.
   */
  capabilityInvocation: string[];
  /**
   * capabilityDelegation is a list of verification methods that can be used to
   * delegate capabilities as the DID subject.
   */
  capabilityDelegation: string[];
  /**
   * keyAgreement is a list of verification methods that can be used to perform
   * key agreement as the DID subject.
   */
  keyAgreement: string[];
  /**
   * service is a list of services that can be used to interact with the DID subject.
   * Documentation: https://www.w3.org/TR/did-core/#services
   *
   * Required fields:
   * - id: A unique identifier for the service
   * - type: A service type defined in DID Specification Registries
   * - service_endpoint: Service endpoint(s), provided as a URI or set of URIs
   */
  service: Service[];
  /** alsoKnownAs is a list of DIDs that are known to refer to the same DID subject. */
  alsoKnownAs: string[];
  /**
   * Updated version ID of the DID Document.
   * Links to next/previous versions of the DID Document will be automatically updated.
   *
   * Format: <uuid>
   */
  versionId: string;
}

export interface MsgUpdateDidDocResponse {
  /** Return the updated DID Document with metadata */
  value: DidDocWithMetadata | undefined;
}

/** MsgDeactivateDidDocPayload defines the structure of the payload for deactivating an existing DID document */
export interface MsgDeactivateDidDocPayload {
  /** Unique identifier of the DID Document to be deactivated */
  id: string;
  /**
   * Version ID of the DID Document to be deactivated
   * This is primarily used as a sanity check to ensure that the correct DID Document is being deactivated.
   */
  versionId: string;
}

/** MsgDeactivateDidDocResponse defines response type for Msg/DeactivateDidDoc. */
export interface MsgDeactivateDidDocResponse {
  /** Return the deactivated DID Document with metadata */
  value: DidDocWithMetadata | undefined;
}

/** MsgBurn represents a message to burn coins from the message signer account */
export interface MsgBurn {
  fromAddress: string;
  amount: Coin[];
}

export interface MsgBurnResponse {
}

/**
 * MsgMint is the sdk.Msg type for allowing an admin account to mint
 * more of a token.
 * Only the admin of the token factory denom has permission to mint unless
 * the denom does not have any admin.
 */
export interface MsgMint {
  authority: string;
  toAddress: string;
  amount: Coin[];
}

export interface MsgMintResponse {
}

export interface MsgUpdateParams {
  /** authority is the address that controls the module (defaults to x/gov unless overwritten). */
  authority: string;
  /**
   * params defines the x/did parameters to update.
   *
   * NOTE: All parameters must be supplied.
   */
  params: FeeParams | undefined;
}

/**
 * MsgUpdateParamsResponse defines the response structure for executing a
 * MsgUpdateParams message.
 *
 * Since: cosmos-sdk 0.47
 */
export interface MsgUpdateParamsResponse {
}

function createBaseMsgCreateDidDoc(): MsgCreateDidDoc {
  return { payload: undefined, signatures: [] };
}

export const MsgCreateDidDoc: MessageFns<MsgCreateDidDoc> = {
  encode(message: MsgCreateDidDoc, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.payload !== undefined) {
      MsgCreateDidDocPayload.encode(message.payload, writer.uint32(10).fork()).join();
    }
    for (const v of message.signatures) {
      SignInfo.encode(v!, writer.uint32(18).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): MsgCreateDidDoc {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMsgCreateDidDoc();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.payload = MsgCreateDidDocPayload.decode(reader, reader.uint32());
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.signatures.push(SignInfo.decode(reader, reader.uint32()));
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): MsgCreateDidDoc {
    return {
      payload: isSet(object.payload) ? MsgCreateDidDocPayload.fromJSON(object.payload) : undefined,
      signatures: globalThis.Array.isArray(object?.signatures)
        ? object.signatures.map((e: any) => SignInfo.fromJSON(e))
        : [],
    };
  },

  toJSON(message: MsgCreateDidDoc): unknown {
    const obj: any = {};
    if (message.payload !== undefined) {
      obj.payload = MsgCreateDidDocPayload.toJSON(message.payload);
    }
    if (message.signatures?.length) {
      obj.signatures = message.signatures.map((e) => SignInfo.toJSON(e));
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<MsgCreateDidDoc>, I>>(base?: I): MsgCreateDidDoc {
    return MsgCreateDidDoc.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<MsgCreateDidDoc>, I>>(object: I): MsgCreateDidDoc {
    const message = createBaseMsgCreateDidDoc();
    message.payload = (object.payload !== undefined && object.payload !== null)
      ? MsgCreateDidDocPayload.fromPartial(object.payload)
      : undefined;
    message.signatures = object.signatures?.map((e) => SignInfo.fromPartial(e)) || [];
    return message;
  },
};

function createBaseMsgUpdateDidDoc(): MsgUpdateDidDoc {
  return { payload: undefined, signatures: [] };
}

export const MsgUpdateDidDoc: MessageFns<MsgUpdateDidDoc> = {
  encode(message: MsgUpdateDidDoc, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.payload !== undefined) {
      MsgUpdateDidDocPayload.encode(message.payload, writer.uint32(10).fork()).join();
    }
    for (const v of message.signatures) {
      SignInfo.encode(v!, writer.uint32(18).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): MsgUpdateDidDoc {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMsgUpdateDidDoc();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.payload = MsgUpdateDidDocPayload.decode(reader, reader.uint32());
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.signatures.push(SignInfo.decode(reader, reader.uint32()));
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): MsgUpdateDidDoc {
    return {
      payload: isSet(object.payload) ? MsgUpdateDidDocPayload.fromJSON(object.payload) : undefined,
      signatures: globalThis.Array.isArray(object?.signatures)
        ? object.signatures.map((e: any) => SignInfo.fromJSON(e))
        : [],
    };
  },

  toJSON(message: MsgUpdateDidDoc): unknown {
    const obj: any = {};
    if (message.payload !== undefined) {
      obj.payload = MsgUpdateDidDocPayload.toJSON(message.payload);
    }
    if (message.signatures?.length) {
      obj.signatures = message.signatures.map((e) => SignInfo.toJSON(e));
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<MsgUpdateDidDoc>, I>>(base?: I): MsgUpdateDidDoc {
    return MsgUpdateDidDoc.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<MsgUpdateDidDoc>, I>>(object: I): MsgUpdateDidDoc {
    const message = createBaseMsgUpdateDidDoc();
    message.payload = (object.payload !== undefined && object.payload !== null)
      ? MsgUpdateDidDocPayload.fromPartial(object.payload)
      : undefined;
    message.signatures = object.signatures?.map((e) => SignInfo.fromPartial(e)) || [];
    return message;
  },
};

function createBaseMsgDeactivateDidDoc(): MsgDeactivateDidDoc {
  return { payload: undefined, signatures: [] };
}

export const MsgDeactivateDidDoc: MessageFns<MsgDeactivateDidDoc> = {
  encode(message: MsgDeactivateDidDoc, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.payload !== undefined) {
      MsgDeactivateDidDocPayload.encode(message.payload, writer.uint32(10).fork()).join();
    }
    for (const v of message.signatures) {
      SignInfo.encode(v!, writer.uint32(18).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): MsgDeactivateDidDoc {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMsgDeactivateDidDoc();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.payload = MsgDeactivateDidDocPayload.decode(reader, reader.uint32());
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.signatures.push(SignInfo.decode(reader, reader.uint32()));
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): MsgDeactivateDidDoc {
    return {
      payload: isSet(object.payload) ? MsgDeactivateDidDocPayload.fromJSON(object.payload) : undefined,
      signatures: globalThis.Array.isArray(object?.signatures)
        ? object.signatures.map((e: any) => SignInfo.fromJSON(e))
        : [],
    };
  },

  toJSON(message: MsgDeactivateDidDoc): unknown {
    const obj: any = {};
    if (message.payload !== undefined) {
      obj.payload = MsgDeactivateDidDocPayload.toJSON(message.payload);
    }
    if (message.signatures?.length) {
      obj.signatures = message.signatures.map((e) => SignInfo.toJSON(e));
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<MsgDeactivateDidDoc>, I>>(base?: I): MsgDeactivateDidDoc {
    return MsgDeactivateDidDoc.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<MsgDeactivateDidDoc>, I>>(object: I): MsgDeactivateDidDoc {
    const message = createBaseMsgDeactivateDidDoc();
    message.payload = (object.payload !== undefined && object.payload !== null)
      ? MsgDeactivateDidDocPayload.fromPartial(object.payload)
      : undefined;
    message.signatures = object.signatures?.map((e) => SignInfo.fromPartial(e)) || [];
    return message;
  },
};

function createBaseSignInfo(): SignInfo {
  return { verificationMethodId: "", signature: new Uint8Array(0) };
}

export const SignInfo: MessageFns<SignInfo> = {
  encode(message: SignInfo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.verificationMethodId !== "") {
      writer.uint32(10).string(message.verificationMethodId);
    }
    if (message.signature.length !== 0) {
      writer.uint32(18).bytes(message.signature);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): SignInfo {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseSignInfo();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.verificationMethodId = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.signature = reader.bytes();
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): SignInfo {
    return {
      verificationMethodId: isSet(object.verificationMethodId)
        ? globalThis.String(object.verificationMethodId)
        : isSet(object.verification_method_id)
        ? globalThis.String(object.verification_method_id)
        : "",
      signature: isSet(object.signature) ? bytesFromBase64(object.signature) : new Uint8Array(0),
    };
  },

  toJSON(message: SignInfo): unknown {
    const obj: any = {};
    if (message.verificationMethodId !== "") {
      obj.verificationMethodId = message.verificationMethodId;
    }
    if (message.signature.length !== 0) {
      obj.signature = base64FromBytes(message.signature);
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<SignInfo>, I>>(base?: I): SignInfo {
    return SignInfo.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<SignInfo>, I>>(object: I): SignInfo {
    const message = createBaseSignInfo();
    message.verificationMethodId = object.verificationMethodId ?? "";
    message.signature = object.signature ?? new Uint8Array(0);
    return message;
  },
};

function createBaseMsgCreateDidDocPayload(): MsgCreateDidDocPayload {
  return {
    context: [],
    id: "",
    controller: [],
    verificationMethod: [],
    authentication: [],
    assertionMethod: [],
    capabilityInvocation: [],
    capabilityDelegation: [],
    keyAgreement: [],
    service: [],
    alsoKnownAs: [],
    versionId: "",
  };
}

export const MsgCreateDidDocPayload: MessageFns<MsgCreateDidDocPayload> = {
  encode(message: MsgCreateDidDocPayload, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    for (const v of message.context) {
      writer.uint32(10).string(v!);
    }
    if (message.id !== "") {
      writer.uint32(18).string(message.id);
    }
    for (const v of message.controller) {
      writer.uint32(26).string(v!);
    }
    for (const v of message.verificationMethod) {
      VerificationMethod.encode(v!, writer.uint32(34).fork()).join();
    }
    for (const v of message.authentication) {
      writer.uint32(42).string(v!);
    }
    for (const v of message.assertionMethod) {
      writer.uint32(50).string(v!);
    }
    for (const v of message.capabilityInvocation) {
      writer.uint32(58).string(v!);
    }
    for (const v of message.capabilityDelegation) {
      writer.uint32(66).string(v!);
    }
    for (const v of message.keyAgreement) {
      writer.uint32(74).string(v!);
    }
    for (const v of message.service) {
      Service.encode(v!, writer.uint32(82).fork()).join();
    }
    for (const v of message.alsoKnownAs) {
      writer.uint32(90).string(v!);
    }
    if (message.versionId !== "") {
      writer.uint32(98).string(message.versionId);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): MsgCreateDidDocPayload {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMsgCreateDidDocPayload();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.context.push(reader.string());
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.id = reader.string();
          continue;
        }
        case 3: {
          if (tag !== 26) {
            break;
          }

          message.controller.push(reader.string());
          continue;
        }
        case 4: {
          if (tag !== 34) {
            break;
          }

          message.verificationMethod.push(VerificationMethod.decode(reader, reader.uint32()));
          continue;
        }
        case 5: {
          if (tag !== 42) {
            break;
          }

          message.authentication.push(reader.string());
          continue;
        }
        case 6: {
          if (tag !== 50) {
            break;
          }

          message.assertionMethod.push(reader.string());
          continue;
        }
        case 7: {
          if (tag !== 58) {
            break;
          }

          message.capabilityInvocation.push(reader.string());
          continue;
        }
        case 8: {
          if (tag !== 66) {
            break;
          }

          message.capabilityDelegation.push(reader.string());
          continue;
        }
        case 9: {
          if (tag !== 74) {
            break;
          }

          message.keyAgreement.push(reader.string());
          continue;
        }
        case 10: {
          if (tag !== 82) {
            break;
          }

          message.service.push(Service.decode(reader, reader.uint32()));
          continue;
        }
        case 11: {
          if (tag !== 90) {
            break;
          }

          message.alsoKnownAs.push(reader.string());
          continue;
        }
        case 12: {
          if (tag !== 98) {
            break;
          }

          message.versionId = reader.string();
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): MsgCreateDidDocPayload {
    return {
      context: globalThis.Array.isArray(object?.context) ? object.context.map((e: any) => globalThis.String(e)) : [],
      id: isSet(object.id) ? globalThis.String(object.id) : "",
      controller: globalThis.Array.isArray(object?.controller)
        ? object.controller.map((e: any) => globalThis.String(e))
        : [],
      verificationMethod: globalThis.Array.isArray(object?.verificationMethod)
        ? object.verificationMethod.map((e: any) => VerificationMethod.fromJSON(e))
        : globalThis.Array.isArray(object?.verification_method)
        ? object.verification_method.map((e: any) => VerificationMethod.fromJSON(e))
        : [],
      authentication: globalThis.Array.isArray(object?.authentication)
        ? object.authentication.map((e: any) => globalThis.String(e))
        : [],
      assertionMethod: globalThis.Array.isArray(object?.assertionMethod)
        ? object.assertionMethod.map((e: any) => globalThis.String(e))
        : globalThis.Array.isArray(object?.assertion_method)
        ? object.assertion_method.map((e: any) => globalThis.String(e))
        : [],
      capabilityInvocation: globalThis.Array.isArray(object?.capabilityInvocation)
        ? object.capabilityInvocation.map((e: any) => globalThis.String(e))
        : globalThis.Array.isArray(object?.capability_invocation)
        ? object.capability_invocation.map((e: any) => globalThis.String(e))
        : [],
      capabilityDelegation: globalThis.Array.isArray(object?.capabilityDelegation)
        ? object.capabilityDelegation.map((e: any) => globalThis.String(e))
        : globalThis.Array.isArray(object?.capability_delegation)
        ? object.capability_delegation.map((e: any) => globalThis.String(e))
        : [],
      keyAgreement: globalThis.Array.isArray(object?.keyAgreement)
        ? object.keyAgreement.map((e: any) => globalThis.String(e))
        : globalThis.Array.isArray(object?.key_agreement)
        ? object.key_agreement.map((e: any) => globalThis.String(e))
        : [],
      service: globalThis.Array.isArray(object?.service) ? object.service.map((e: any) => Service.fromJSON(e)) : [],
      alsoKnownAs: globalThis.Array.isArray(object?.alsoKnownAs)
        ? object.alsoKnownAs.map((e: any) => globalThis.String(e))
        : globalThis.Array.isArray(object?.also_known_as)
        ? object.also_known_as.map((e: any) => globalThis.String(e))
        : [],
      versionId: isSet(object.versionId)
        ? globalThis.String(object.versionId)
        : isSet(object.version_id)
        ? globalThis.String(object.version_id)
        : "",
    };
  },

  toJSON(message: MsgCreateDidDocPayload): unknown {
    const obj: any = {};
    if (message.context?.length) {
      obj.context = message.context;
    }
    if (message.id !== "") {
      obj.id = message.id;
    }
    if (message.controller?.length) {
      obj.controller = message.controller;
    }
    if (message.verificationMethod?.length) {
      obj.verificationMethod = message.verificationMethod.map((e) => VerificationMethod.toJSON(e));
    }
    if (message.authentication?.length) {
      obj.authentication = message.authentication;
    }
    if (message.assertionMethod?.length) {
      obj.assertionMethod = message.assertionMethod;
    }
    if (message.capabilityInvocation?.length) {
      obj.capabilityInvocation = message.capabilityInvocation;
    }
    if (message.capabilityDelegation?.length) {
      obj.capabilityDelegation = message.capabilityDelegation;
    }
    if (message.keyAgreement?.length) {
      obj.keyAgreement = message.keyAgreement;
    }
    if (message.service?.length) {
      obj.service = message.service.map((e) => Service.toJSON(e));
    }
    if (message.alsoKnownAs?.length) {
      obj.alsoKnownAs = message.alsoKnownAs;
    }
    if (message.versionId !== "") {
      obj.versionId = message.versionId;
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<MsgCreateDidDocPayload>, I>>(base?: I): MsgCreateDidDocPayload {
    return MsgCreateDidDocPayload.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<MsgCreateDidDocPayload>, I>>(object: I): MsgCreateDidDocPayload {
    const message = createBaseMsgCreateDidDocPayload();
    message.context = object.context?.map((e) => e) || [];
    message.id = object.id ?? "";
    message.controller = object.controller?.map((e) => e) || [];
    message.verificationMethod = object.verificationMethod?.map((e) => VerificationMethod.fromPartial(e)) || [];
    message.authentication = object.authentication?.map((e) => e) || [];
    message.assertionMethod = object.assertionMethod?.map((e) => e) || [];
    message.capabilityInvocation = object.capabilityInvocation?.map((e) => e) || [];
    message.capabilityDelegation = object.capabilityDelegation?.map((e) => e) || [];
    message.keyAgreement = object.keyAgreement?.map((e) => e) || [];
    message.service = object.service?.map((e) => Service.fromPartial(e)) || [];
    message.alsoKnownAs = object.alsoKnownAs?.map((e) => e) || [];
    message.versionId = object.versionId ?? "";
    return message;
  },
};

function createBaseMsgCreateDidDocResponse(): MsgCreateDidDocResponse {
  return { value: undefined };
}

export const MsgCreateDidDocResponse: MessageFns<MsgCreateDidDocResponse> = {
  encode(message: MsgCreateDidDocResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.value !== undefined) {
      DidDocWithMetadata.encode(message.value, writer.uint32(10).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): MsgCreateDidDocResponse {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMsgCreateDidDocResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.value = DidDocWithMetadata.decode(reader, reader.uint32());
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): MsgCreateDidDocResponse {
    return { value: isSet(object.value) ? DidDocWithMetadata.fromJSON(object.value) : undefined };
  },

  toJSON(message: MsgCreateDidDocResponse): unknown {
    const obj: any = {};
    if (message.value !== undefined) {
      obj.value = DidDocWithMetadata.toJSON(message.value);
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<MsgCreateDidDocResponse>, I>>(base?: I): MsgCreateDidDocResponse {
    return MsgCreateDidDocResponse.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<MsgCreateDidDocResponse>, I>>(object: I): MsgCreateDidDocResponse {
    const message = createBaseMsgCreateDidDocResponse();
    message.value = (object.value !== undefined && object.value !== null)
      ? DidDocWithMetadata.fromPartial(object.value)
      : undefined;
    return message;
  },
};

function createBaseMsgUpdateDidDocPayload(): MsgUpdateDidDocPayload {
  return {
    context: [],
    id: "",
    controller: [],
    verificationMethod: [],
    authentication: [],
    assertionMethod: [],
    capabilityInvocation: [],
    capabilityDelegation: [],
    keyAgreement: [],
    service: [],
    alsoKnownAs: [],
    versionId: "",
  };
}

export const MsgUpdateDidDocPayload: MessageFns<MsgUpdateDidDocPayload> = {
  encode(message: MsgUpdateDidDocPayload, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    for (const v of message.context) {
      writer.uint32(10).string(v!);
    }
    if (message.id !== "") {
      writer.uint32(18).string(message.id);
    }
    for (const v of message.controller) {
      writer.uint32(26).string(v!);
    }
    for (const v of message.verificationMethod) {
      VerificationMethod.encode(v!, writer.uint32(34).fork()).join();
    }
    for (const v of message.authentication) {
      writer.uint32(42).string(v!);
    }
    for (const v of message.assertionMethod) {
      writer.uint32(50).string(v!);
    }
    for (const v of message.capabilityInvocation) {
      writer.uint32(58).string(v!);
    }
    for (const v of message.capabilityDelegation) {
      writer.uint32(66).string(v!);
    }
    for (const v of message.keyAgreement) {
      writer.uint32(74).string(v!);
    }
    for (const v of message.service) {
      Service.encode(v!, writer.uint32(82).fork()).join();
    }
    for (const v of message.alsoKnownAs) {
      writer.uint32(90).string(v!);
    }
    if (message.versionId !== "") {
      writer.uint32(98).string(message.versionId);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): MsgUpdateDidDocPayload {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMsgUpdateDidDocPayload();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.context.push(reader.string());
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.id = reader.string();
          continue;
        }
        case 3: {
          if (tag !== 26) {
            break;
          }

          message.controller.push(reader.string());
          continue;
        }
        case 4: {
          if (tag !== 34) {
            break;
          }

          message.verificationMethod.push(VerificationMethod.decode(reader, reader.uint32()));
          continue;
        }
        case 5: {
          if (tag !== 42) {
            break;
          }

          message.authentication.push(reader.string());
          continue;
        }
        case 6: {
          if (tag !== 50) {
            break;
          }

          message.assertionMethod.push(reader.string());
          continue;
        }
        case 7: {
          if (tag !== 58) {
            break;
          }

          message.capabilityInvocation.push(reader.string());
          continue;
        }
        case 8: {
          if (tag !== 66) {
            break;
          }

          message.capabilityDelegation.push(reader.string());
          continue;
        }
        case 9: {
          if (tag !== 74) {
            break;
          }

          message.keyAgreement.push(reader.string());
          continue;
        }
        case 10: {
          if (tag !== 82) {
            break;
          }

          message.service.push(Service.decode(reader, reader.uint32()));
          continue;
        }
        case 11: {
          if (tag !== 90) {
            break;
          }

          message.alsoKnownAs.push(reader.string());
          continue;
        }
        case 12: {
          if (tag !== 98) {
            break;
          }

          message.versionId = reader.string();
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): MsgUpdateDidDocPayload {
    return {
      context: globalThis.Array.isArray(object?.context) ? object.context.map((e: any) => globalThis.String(e)) : [],
      id: isSet(object.id) ? globalThis.String(object.id) : "",
      controller: globalThis.Array.isArray(object?.controller)
        ? object.controller.map((e: any) => globalThis.String(e))
        : [],
      verificationMethod: globalThis.Array.isArray(object?.verificationMethod)
        ? object.verificationMethod.map((e: any) => VerificationMethod.fromJSON(e))
        : globalThis.Array.isArray(object?.verification_method)
        ? object.verification_method.map((e: any) => VerificationMethod.fromJSON(e))
        : [],
      authentication: globalThis.Array.isArray(object?.authentication)
        ? object.authentication.map((e: any) => globalThis.String(e))
        : [],
      assertionMethod: globalThis.Array.isArray(object?.assertionMethod)
        ? object.assertionMethod.map((e: any) => globalThis.String(e))
        : globalThis.Array.isArray(object?.assertion_method)
        ? object.assertion_method.map((e: any) => globalThis.String(e))
        : [],
      capabilityInvocation: globalThis.Array.isArray(object?.capabilityInvocation)
        ? object.capabilityInvocation.map((e: any) => globalThis.String(e))
        : globalThis.Array.isArray(object?.capability_invocation)
        ? object.capability_invocation.map((e: any) => globalThis.String(e))
        : [],
      capabilityDelegation: globalThis.Array.isArray(object?.capabilityDelegation)
        ? object.capabilityDelegation.map((e: any) => globalThis.String(e))
        : globalThis.Array.isArray(object?.capability_delegation)
        ? object.capability_delegation.map((e: any) => globalThis.String(e))
        : [],
      keyAgreement: globalThis.Array.isArray(object?.keyAgreement)
        ? object.keyAgreement.map((e: any) => globalThis.String(e))
        : globalThis.Array.isArray(object?.key_agreement)
        ? object.key_agreement.map((e: any) => globalThis.String(e))
        : [],
      service: globalThis.Array.isArray(object?.service) ? object.service.map((e: any) => Service.fromJSON(e)) : [],
      alsoKnownAs: globalThis.Array.isArray(object?.alsoKnownAs)
        ? object.alsoKnownAs.map((e: any) => globalThis.String(e))
        : globalThis.Array.isArray(object?.also_known_as)
        ? object.also_known_as.map((e: any) => globalThis.String(e))
        : [],
      versionId: isSet(object.versionId)
        ? globalThis.String(object.versionId)
        : isSet(object.version_id)
        ? globalThis.String(object.version_id)
        : "",
    };
  },

  toJSON(message: MsgUpdateDidDocPayload): unknown {
    const obj: any = {};
    if (message.context?.length) {
      obj.context = message.context;
    }
    if (message.id !== "") {
      obj.id = message.id;
    }
    if (message.controller?.length) {
      obj.controller = message.controller;
    }
    if (message.verificationMethod?.length) {
      obj.verificationMethod = message.verificationMethod.map((e) => VerificationMethod.toJSON(e));
    }
    if (message.authentication?.length) {
      obj.authentication = message.authentication;
    }
    if (message.assertionMethod?.length) {
      obj.assertionMethod = message.assertionMethod;
    }
    if (message.capabilityInvocation?.length) {
      obj.capabilityInvocation = message.capabilityInvocation;
    }
    if (message.capabilityDelegation?.length) {
      obj.capabilityDelegation = message.capabilityDelegation;
    }
    if (message.keyAgreement?.length) {
      obj.keyAgreement = message.keyAgreement;
    }
    if (message.service?.length) {
      obj.service = message.service.map((e) => Service.toJSON(e));
    }
    if (message.alsoKnownAs?.length) {
      obj.alsoKnownAs = message.alsoKnownAs;
    }
    if (message.versionId !== "") {
      obj.versionId = message.versionId;
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<MsgUpdateDidDocPayload>, I>>(base?: I): MsgUpdateDidDocPayload {
    return MsgUpdateDidDocPayload.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<MsgUpdateDidDocPayload>, I>>(object: I): MsgUpdateDidDocPayload {
    const message = createBaseMsgUpdateDidDocPayload();
    message.context = object.context?.map((e) => e) || [];
    message.id = object.id ?? "";
    message.controller = object.controller?.map((e) => e) || [];
    message.verificationMethod = object.verificationMethod?.map((e) => VerificationMethod.fromPartial(e)) || [];
    message.authentication = object.authentication?.map((e) => e) || [];
    message.assertionMethod = object.assertionMethod?.map((e) => e) || [];
    message.capabilityInvocation = object.capabilityInvocation?.map((e) => e) || [];
    message.capabilityDelegation = object.capabilityDelegation?.map((e) => e) || [];
    message.keyAgreement = object.keyAgreement?.map((e) => e) || [];
    message.service = object.service?.map((e) => Service.fromPartial(e)) || [];
    message.alsoKnownAs = object.alsoKnownAs?.map((e) => e) || [];
    message.versionId = object.versionId ?? "";
    return message;
  },
};

function createBaseMsgUpdateDidDocResponse(): MsgUpdateDidDocResponse {
  return { value: undefined };
}

export const MsgUpdateDidDocResponse: MessageFns<MsgUpdateDidDocResponse> = {
  encode(message: MsgUpdateDidDocResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.value !== undefined) {
      DidDocWithMetadata.encode(message.value, writer.uint32(10).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): MsgUpdateDidDocResponse {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMsgUpdateDidDocResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.value = DidDocWithMetadata.decode(reader, reader.uint32());
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): MsgUpdateDidDocResponse {
    return { value: isSet(object.value) ? DidDocWithMetadata.fromJSON(object.value) : undefined };
  },

  toJSON(message: MsgUpdateDidDocResponse): unknown {
    const obj: any = {};
    if (message.value !== undefined) {
      obj.value = DidDocWithMetadata.toJSON(message.value);
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<MsgUpdateDidDocResponse>, I>>(base?: I): MsgUpdateDidDocResponse {
    return MsgUpdateDidDocResponse.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<MsgUpdateDidDocResponse>, I>>(object: I): MsgUpdateDidDocResponse {
    const message = createBaseMsgUpdateDidDocResponse();
    message.value = (object.value !== undefined && object.value !== null)
      ? DidDocWithMetadata.fromPartial(object.value)
      : undefined;
    return message;
  },
};

function createBaseMsgDeactivateDidDocPayload(): MsgDeactivateDidDocPayload {
  return { id: "", versionId: "" };
}

export const MsgDeactivateDidDocPayload: MessageFns<MsgDeactivateDidDocPayload> = {
  encode(message: MsgDeactivateDidDocPayload, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.id !== "") {
      writer.uint32(10).string(message.id);
    }
    if (message.versionId !== "") {
      writer.uint32(18).string(message.versionId);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): MsgDeactivateDidDocPayload {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMsgDeactivateDidDocPayload();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.id = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.versionId = reader.string();
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): MsgDeactivateDidDocPayload {
    return {
      id: isSet(object.id) ? globalThis.String(object.id) : "",
      versionId: isSet(object.versionId)
        ? globalThis.String(object.versionId)
        : isSet(object.version_id)
        ? globalThis.String(object.version_id)
        : "",
    };
  },

  toJSON(message: MsgDeactivateDidDocPayload): unknown {
    const obj: any = {};
    if (message.id !== "") {
      obj.id = message.id;
    }
    if (message.versionId !== "") {
      obj.versionId = message.versionId;
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<MsgDeactivateDidDocPayload>, I>>(base?: I): MsgDeactivateDidDocPayload {
    return MsgDeactivateDidDocPayload.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<MsgDeactivateDidDocPayload>, I>>(object: I): MsgDeactivateDidDocPayload {
    const message = createBaseMsgDeactivateDidDocPayload();
    message.id = object.id ?? "";
    message.versionId = object.versionId ?? "";
    return message;
  },
};

function createBaseMsgDeactivateDidDocResponse(): MsgDeactivateDidDocResponse {
  return { value: undefined };
}

export const MsgDeactivateDidDocResponse: MessageFns<MsgDeactivateDidDocResponse> = {
  encode(message: MsgDeactivateDidDocResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.value !== undefined) {
      DidDocWithMetadata.encode(message.value, writer.uint32(10).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): MsgDeactivateDidDocResponse {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMsgDeactivateDidDocResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.value = DidDocWithMetadata.decode(reader, reader.uint32());
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): MsgDeactivateDidDocResponse {
    return { value: isSet(object.value) ? DidDocWithMetadata.fromJSON(object.value) : undefined };
  },

  toJSON(message: MsgDeactivateDidDocResponse): unknown {
    const obj: any = {};
    if (message.value !== undefined) {
      obj.value = DidDocWithMetadata.toJSON(message.value);
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<MsgDeactivateDidDocResponse>, I>>(base?: I): MsgDeactivateDidDocResponse {
    return MsgDeactivateDidDocResponse.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<MsgDeactivateDidDocResponse>, I>>(object: I): MsgDeactivateDidDocResponse {
    const message = createBaseMsgDeactivateDidDocResponse();
    message.value = (object.value !== undefined && object.value !== null)
      ? DidDocWithMetadata.fromPartial(object.value)
      : undefined;
    return message;
  },
};

function createBaseMsgBurn(): MsgBurn {
  return { fromAddress: "", amount: [] };
}

export const MsgBurn: MessageFns<MsgBurn> = {
  encode(message: MsgBurn, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.fromAddress !== "") {
      writer.uint32(10).string(message.fromAddress);
    }
    for (const v of message.amount) {
      Coin.encode(v!, writer.uint32(18).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): MsgBurn {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMsgBurn();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.fromAddress = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.amount.push(Coin.decode(reader, reader.uint32()));
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): MsgBurn {
    return {
      fromAddress: isSet(object.fromAddress)
        ? globalThis.String(object.fromAddress)
        : isSet(object.from_address)
        ? globalThis.String(object.from_address)
        : "",
      amount: globalThis.Array.isArray(object?.amount) ? object.amount.map((e: any) => Coin.fromJSON(e)) : [],
    };
  },

  toJSON(message: MsgBurn): unknown {
    const obj: any = {};
    if (message.fromAddress !== "") {
      obj.fromAddress = message.fromAddress;
    }
    if (message.amount?.length) {
      obj.amount = message.amount.map((e) => Coin.toJSON(e));
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<MsgBurn>, I>>(base?: I): MsgBurn {
    return MsgBurn.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<MsgBurn>, I>>(object: I): MsgBurn {
    const message = createBaseMsgBurn();
    message.fromAddress = object.fromAddress ?? "";
    message.amount = object.amount?.map((e) => Coin.fromPartial(e)) || [];
    return message;
  },
};

function createBaseMsgBurnResponse(): MsgBurnResponse {
  return {};
}

export const MsgBurnResponse: MessageFns<MsgBurnResponse> = {
  encode(_: MsgBurnResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): MsgBurnResponse {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMsgBurnResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(_: any): MsgBurnResponse {
    return {};
  },

  toJSON(_: MsgBurnResponse): unknown {
    const obj: any = {};
    return obj;
  },

  create<I extends Exact<DeepPartial<MsgBurnResponse>, I>>(base?: I): MsgBurnResponse {
    return MsgBurnResponse.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<MsgBurnResponse>, I>>(_: I): MsgBurnResponse {
    const message = createBaseMsgBurnResponse();
    return message;
  },
};

function createBaseMsgMint(): MsgMint {
  return { authority: "", toAddress: "", amount: [] };
}

export const MsgMint: MessageFns<MsgMint> = {
  encode(message: MsgMint, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.authority !== "") {
      writer.uint32(10).string(message.authority);
    }
    if (message.toAddress !== "") {
      writer.uint32(18).string(message.toAddress);
    }
    for (const v of message.amount) {
      Coin.encode(v!, writer.uint32(26).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): MsgMint {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMsgMint();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.authority = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.toAddress = reader.string();
          continue;
        }
        case 3: {
          if (tag !== 26) {
            break;
          }

          message.amount.push(Coin.decode(reader, reader.uint32()));
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): MsgMint {
    return {
      authority: isSet(object.authority) ? globalThis.String(object.authority) : "",
      toAddress: isSet(object.toAddress)
        ? globalThis.String(object.toAddress)
        : isSet(object.to_address)
        ? globalThis.String(object.to_address)
        : "",
      amount: globalThis.Array.isArray(object?.amount) ? object.amount.map((e: any) => Coin.fromJSON(e)) : [],
    };
  },

  toJSON(message: MsgMint): unknown {
    const obj: any = {};
    if (message.authority !== "") {
      obj.authority = message.authority;
    }
    if (message.toAddress !== "") {
      obj.toAddress = message.toAddress;
    }
    if (message.amount?.length) {
      obj.amount = message.amount.map((e) => Coin.toJSON(e));
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<MsgMint>, I>>(base?: I): MsgMint {
    return MsgMint.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<MsgMint>, I>>(object: I): MsgMint {
    const message = createBaseMsgMint();
    message.authority = object.authority ?? "";
    message.toAddress = object.toAddress ?? "";
    message.amount = object.amount?.map((e) => Coin.fromPartial(e)) || [];
    return message;
  },
};

function createBaseMsgMintResponse(): MsgMintResponse {
  return {};
}

export const MsgMintResponse: MessageFns<MsgMintResponse> = {
  encode(_: MsgMintResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): MsgMintResponse {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMsgMintResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(_: any): MsgMintResponse {
    return {};
  },

  toJSON(_: MsgMintResponse): unknown {
    const obj: any = {};
    return obj;
  },

  create<I extends Exact<DeepPartial<MsgMintResponse>, I>>(base?: I): MsgMintResponse {
    return MsgMintResponse.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<MsgMintResponse>, I>>(_: I): MsgMintResponse {
    const message = createBaseMsgMintResponse();
    return message;
  },
};

function createBaseMsgUpdateParams(): MsgUpdateParams {
  return { authority: "", params: undefined };
}

export const MsgUpdateParams: MessageFns<MsgUpdateParams> = {
  encode(message: MsgUpdateParams, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.authority !== "") {
      writer.uint32(10).string(message.authority);
    }
    if (message.params !== undefined) {
      FeeParams.encode(message.params, writer.uint32(18).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): MsgUpdateParams {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMsgUpdateParams();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.authority = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.params = FeeParams.decode(reader, reader.uint32());
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): MsgUpdateParams {
    return {
      authority: isSet(object.authority) ? globalThis.String(object.authority) : "",
      params: isSet(object.params) ? FeeParams.fromJSON(object.params) : undefined,
    };
  },

  toJSON(message: MsgUpdateParams): unknown {
    const obj: any = {};
    if (message.authority !== "") {
      obj.authority = message.authority;
    }
    if (message.params !== undefined) {
      obj.params = FeeParams.toJSON(message.params);
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<MsgUpdateParams>, I>>(base?: I): MsgUpdateParams {
    return MsgUpdateParams.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<MsgUpdateParams>, I>>(object: I): MsgUpdateParams {
    const message = createBaseMsgUpdateParams();
    message.authority = object.authority ?? "";
    message.params = (object.params !== undefined && object.params !== null)
      ? FeeParams.fromPartial(object.params)
      : undefined;
    return message;
  },
};

function createBaseMsgUpdateParamsResponse(): MsgUpdateParamsResponse {
  return {};
}

export const MsgUpdateParamsResponse: MessageFns<MsgUpdateParamsResponse> = {
  encode(_: MsgUpdateParamsResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): MsgUpdateParamsResponse {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMsgUpdateParamsResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(_: any): MsgUpdateParamsResponse {
    return {};
  },

  toJSON(_: MsgUpdateParamsResponse): unknown {
    const obj: any = {};
    return obj;
  },

  create<I extends Exact<DeepPartial<MsgUpdateParamsResponse>, I>>(base?: I): MsgUpdateParamsResponse {
    return MsgUpdateParamsResponse.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<MsgUpdateParamsResponse>, I>>(_: I): MsgUpdateParamsResponse {
    const message = createBaseMsgUpdateParamsResponse();
    return message;
  },
};

/** Msg defines the Cosmos SDK Msg service for the cheqd.did.v2 module. */
export interface Msg {
  /** CreateDidDoc defines a method for creating a new DID document */
  CreateDidDoc(request: MsgCreateDidDoc): Promise<MsgCreateDidDocResponse>;
  /** UpdateDidDoc defines a method for updating an existing DID document */
  UpdateDidDoc(request: MsgUpdateDidDoc): Promise<MsgUpdateDidDocResponse>;
  /** DeactivateDidDoc defines a method for deactivating an existing DID document */
  DeactivateDidDoc(request: MsgDeactivateDidDoc): Promise<MsgDeactivateDidDocResponse>;
  Burn(request: MsgBurn): Promise<MsgBurnResponse>;
  /** Mint defines a method to mint tokens to the given address. */
  Mint(request: MsgMint): Promise<MsgMintResponse>;
  UpdateParams(request: MsgUpdateParams): Promise<MsgUpdateParamsResponse>;
}

export const MsgServiceName = "cheqd.did.v2.Msg";
export class MsgClientImpl implements Msg {
  private readonly rpc: Rpc;
  private readonly service: string;
  constructor(rpc: Rpc, opts?: { service?: string }) {
    this.service = opts?.service || MsgServiceName;
    this.rpc = rpc;
    this.CreateDidDoc = this.CreateDidDoc.bind(this);
    this.UpdateDidDoc = this.UpdateDidDoc.bind(this);
    this.DeactivateDidDoc = this.DeactivateDidDoc.bind(this);
    this.Burn = this.Burn.bind(this);
    this.Mint = this.Mint.bind(this);
    this.UpdateParams = this.UpdateParams.bind(this);
  }
  CreateDidDoc(request: MsgCreateDidDoc): Promise<MsgCreateDidDocResponse> {
    const data = MsgCreateDidDoc.encode(request).finish();
    const promise = this.rpc.request(this.service, "CreateDidDoc", data);
    return promise.then((data) => MsgCreateDidDocResponse.decode(new BinaryReader(data)));
  }

  UpdateDidDoc(request: MsgUpdateDidDoc): Promise<MsgUpdateDidDocResponse> {
    const data = MsgUpdateDidDoc.encode(request).finish();
    const promise = this.rpc.request(this.service, "UpdateDidDoc", data);
    return promise.then((data) => MsgUpdateDidDocResponse.decode(new BinaryReader(data)));
  }

  DeactivateDidDoc(request: MsgDeactivateDidDoc): Promise<MsgDeactivateDidDocResponse> {
    const data = MsgDeactivateDidDoc.encode(request).finish();
    const promise = this.rpc.request(this.service, "DeactivateDidDoc", data);
    return promise.then((data) => MsgDeactivateDidDocResponse.decode(new BinaryReader(data)));
  }

  Burn(request: MsgBurn): Promise<MsgBurnResponse> {
    const data = MsgBurn.encode(request).finish();
    const promise = this.rpc.request(this.service, "Burn", data);
    return promise.then((data) => MsgBurnResponse.decode(new BinaryReader(data)));
  }

  Mint(request: MsgMint): Promise<MsgMintResponse> {
    const data = MsgMint.encode(request).finish();
    const promise = this.rpc.request(this.service, "Mint", data);
    return promise.then((data) => MsgMintResponse.decode(new BinaryReader(data)));
  }

  UpdateParams(request: MsgUpdateParams): Promise<MsgUpdateParamsResponse> {
    const data = MsgUpdateParams.encode(request).finish();
    const promise = this.rpc.request(this.service, "UpdateParams", data);
    return promise.then((data) => MsgUpdateParamsResponse.decode(new BinaryReader(data)));
  }
}

interface Rpc {
  request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
}

function bytesFromBase64(b64: string): Uint8Array {
  if ((globalThis as any).Buffer) {
    return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
  } else {
    const bin = globalThis.atob(b64);
    const arr = new Uint8Array(bin.length);
    for (let i = 0; i < bin.length; ++i) {
      arr[i] = bin.charCodeAt(i);
    }
    return arr;
  }
}

function base64FromBytes(arr: Uint8Array): string {
  if ((globalThis as any).Buffer) {
    return globalThis.Buffer.from(arr).toString("base64");
  } else {
    const bin: string[] = [];
    arr.forEach((byte) => {
      bin.push(globalThis.String.fromCharCode(byte));
    });
    return globalThis.btoa(bin.join(""));
  }
}

type Builtin = Date | Function | Uint8Array | string | number | boolean | bigint | undefined;

type DeepPartial<T> = T extends Builtin ? T
  : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
  : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
  : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
  : Partial<T>;

type KeysOfUnion<T> = T extends T ? keyof T : never;
type Exact<P, I extends P> = P extends Builtin ? P
  : P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

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

interface MessageFns<T> {
  encode(message: T, writer?: BinaryWriter): BinaryWriter;
  decode(input: BinaryReader | Uint8Array, length?: number): T;
  fromJSON(object: any): T;
  toJSON(message: T): unknown;
  create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
  fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
}
