import { Message } from "@keplr-wallet/router" ; import { ChainInfo , KeplrSignOptions , Key } from "@keplr-wallet/types" ; import { AminoSignResponse , StdSignature , StdSignDoc } from "@cosmjs/launchpad" ; export class EnableAccessMsg extends Message < void > { public static type ( ) { return "enable-access" ; } constructor ( public readonly chainIds ) { super ( ) ; } validateBasic ( ) { if ( ! this . chainIds || this . chainIds . length === 0 ) { throw new Error ( "chain id not set" ) ; } } route ( ) { return "permission" ; } type ( ) { return EnableAccessMsg . type ( ) ; } } export class GetKeyMsg extends Message < Key > { public static type ( ) { return "get-key" ; } constructor ( public readonly chainId ) { super ( ) ; } validateBasic ( ) { if ( ! this . chainId ) { throw new Error ( "chain id not set" ) ; } } route ( ) { return "keyring" ; } type ( ) { return GetKeyMsg . type ( ) ; } } export class SuggestChainInfoMsg extends Message < void > { public static type ( ) { return "suggest-chain-info" ; } constructor ( public readonly chainInfo ) { super ( ) ; } validateBasic ( ) { if ( ! this . chainInfo ) { throw new Error ( "chain info not set" ) ; } } route ( ) { return "chains" ; } type ( ) { return SuggestChainInfoMsg . type ( ) ; } } export class SuggestTokenMsg extends Message < void > { public static type ( ) { return "suggest-token" ; } constructor ( public readonly chainId , public readonly contractAddress , public readonly viewingKey ? ) { super ( ) ; } validateBasic ( ) { if ( ! this . chainId ) { throw new Error ( "Chain id is empty" ) ; } if ( ! this . contractAddress ) { throw new Error ( "Contract address is empty" ) ; } } route ( ) { return "tokens" ; } type ( ) { return SuggestTokenMsg . type ( ) ; } } export class SendTxMsg extends Message < Uint8Array > { public static type ( ) { return "send-tx-to-background" ; } constructor ( public readonly chainId , public readonly tx , public readonly mode ) { super ( ) ; } validateBasic ( ) { if ( ! this . chainId ) { throw new Error ( "chain id is empty" ) ; } if ( ! this . tx ) { throw new Error ( "tx is empty" ) ; } if ( ! this . mode || ( this . mode !== "sync" && this . mode !== "async" && this . mode !== "block" ) ) { throw new Error ( "invalid mode" ) ; } } route ( ) { return "background-tx" ; } type ( ) { return SendTxMsg . type ( ) ; } } export class GetSecret20ViewingKey extends Message < string > { public static type ( ) { return "get-secret20-viewing-key" ; } constructor ( public readonly chainId , public readonly contractAddress ) { super ( ) ; } validateBasic ( ) { if ( ! this . chainId ) { throw new Error ( "Chain id is empty" ) ; } if ( ! this . contractAddress ) { throw new Error ( "Contract address is empty" ) ; } } route ( ) { return "tokens" ; } type ( ) { return GetSecret20ViewingKey . type ( ) ; } } export class RequestSignAminoMsg extends Message < AminoSignResponse > { public static type ( ) { return "request-sign-amino" ; } constructor ( public readonly chainId , public readonly signer , public readonly signDoc , public readonly signOptions = { } ) { super ( ) ; } validateBasic ( ) { if ( ! this . chainId ) { throw new Error ( "chain id not set" ) ; } if ( ! this . signer ) { throw new Error ( "signer not set" ) ; } const signDoc = this . signDoc ; const hasOnlyMsgSignData = ( ( ) => { if ( signDoc && signDoc . msgs && Array . isArray ( signDoc . msgs ) && signDoc . msgs . length === 1 ) { const msg = signDoc . msgs [ 0 ] ; return msg . type === "sign/MsgSignData" ; } else { return false ; } } ) ( ) ; if ( ! hasOnlyMsgSignData && signDoc . chain_id !== this . chainId ) { throw new Error ( "Chain id in the message is not matched with the requested chain id" ) ; } if ( ! this . signOptions ) { throw new Error ( "Sign options are null" ) ; } } route ( ) { return "keyring" ; } type ( ) { return RequestSignAminoMsg . type ( ) ; } } export class RequestVerifyADR36AminoSignDoc extends Message < boolean > { public static type ( ) { return "request-verify-adr-36-amino-doc" ; } constructor ( public readonly chainId , public readonly signer , public readonly data , public readonly signature ) { super ( ) ; } validateBasic ( ) { if ( ! this . chainId ) { throw new Error ( "chain id not set" ) ; } if ( ! this . signer ) { throw new Error ( "signer not set" ) ; } if ( ! this . signature ) { throw new Error ( "Signature not set" ) ; } } route ( ) { return "keyring" ; } type ( ) { return RequestVerifyADR36AminoSignDoc . type ( ) ; } } export class RequestSignDirectMsg extends Message < { readonly signed : { bodyBytes : Uint8Array ; authInfoBytes : Uint8Array ; chainId : string ; accountNumber : string ; } ; readonly signature : StdSignature ; } > { public static type ( ) { return "request-sign-direct" ; } constructor ( public readonly chainId , public readonly signer , public readonly signDoc , public readonly signOptions = { } ) { super ( ) ; } validateBasic ( ) { if ( ! this . chainId ) { throw new Error ( "chain id not set" ) ; } if ( ! this . signer ) { throw new Error ( "signer not set" ) ; } if ( ! this . signOptions ) { throw new Error ( "Sign options are null" ) ; } } route ( ) { return "keyring" ; } type ( ) { return RequestSignDirectMsg . type ( ) ; } } export class GetPubkeyMsg extends Message < Uint8Array > { public static type ( ) { return "get-pubkey-msg" ; } constructor ( public readonly chainId ) { super ( ) ; } validateBasic ( ) { if ( ! this . chainId ) { throw new Error ( "chain id not set" ) ; } } route ( ) { return "secret-wasm" ; } type ( ) { return GetPubkeyMsg . type ( ) ; } } export class ReqeustEncryptMsg extends Message < Uint8Array > { public static type ( ) { return "request-encrypt-msg" ; } constructor ( public readonly chainId , public readonly contractCodeHash , public readonly msg ) { super ( ) ; } validateBasic ( ) { if ( ! this . chainId ) { throw new Error ( "chain id not set" ) ; } if ( ! this . contractCodeHash ) { throw new Error ( "contract code hash not set" ) ; } if ( ! this . msg ) { throw new Error ( "msg not set" ) ; } } route ( ) { return "secret-wasm" ; } type ( ) { return ReqeustEncryptMsg . type ( ) ; } } export class RequestDecryptMsg extends Message < Uint8Array > { public static type ( ) { return "request-decrypt-msg" ; } constructor ( public readonly chainId , public readonly cipherText , public readonly nonce ) { super ( ) ; } validateBasic ( ) { if ( ! this . chainId ) { throw new Error ( "chain id not set" ) ; } if ( ! this . cipherText || this . cipherText . length === 0 ) { throw new Error ( "ciphertext not set" ) ; } if ( ! this . nonce || this . nonce . length === 0 ) { throw new Error ( "nonce not set" ) ; } } route ( ) { return "secret-wasm" ; } type ( ) { return RequestDecryptMsg . type ( ) ; } } export class GetTxEncryptionKeyMsg extends Message < Uint8Array > { public static type ( ) { return "get-tx-encryption-key-msg" ; } constructor ( public readonly chainId , public readonly nonce ) { super ( ) ; } validateBasic ( ) { if ( ! this . chainId ) { throw new Error ( "chain id not set" ) ; } if ( ! this . nonce ) { throw new Error ( "nonce is null" ) ; } } route ( ) { return "secret-wasm" ; } type ( ) { return GetTxEncryptionKeyMsg . type ( ) ; } }