import { OfflineSigner , AccountData , AminoSignResponse , StdSignDoc , } from "@cosmjs/launchpad" ; import { Keplr } from "@keplr-wallet/types" ; import { OfflineDirectSigner } from "@cosmjs/proto-signing" ; import { DirectSignResponse } from "@cosmjs/proto-signing/build/signer" ; import { SignDoc } from "@cosmjs/proto-signing/build/codec/cosmos/tx/v1beta1/tx" ; export class CosmJSOfflineSignerOnlyAmino implements OfflineSigner { constructor ( protected readonly chainId , protected readonly keplr ) { } async getAccounts ( ) { const key = await this . keplr . getKey ( this . chainId ) ; return [ { address : key . bech32Address , algo : "secp256k1" , pubkey : key . pubKey , } , ] ; } async signAmino ( signerAddress , signDoc ) { if ( this . chainId !== signDoc . chain_id ) { throw new Error ( "Unmatched chain id with the offline signer" ) ; } const key = await this . keplr . getKey ( signDoc . chain_id ) ; if ( key . bech32Address !== signerAddress ) { throw new Error ( "Unknown signer address" ) ; } return await this . keplr . signAmino ( this . chainId , signerAddress , signDoc ) ; } async sign ( signerAddress , signDoc ) { return await this . signAmino ( signerAddress , signDoc ) ; } } export class CosmJSOfflineSigner extends CosmJSOfflineSignerOnlyAmino implements OfflineSigner , OfflineDirectSigner { constructor ( protected readonly chainId , protected readonly keplr ) { super ( chainId , keplr ) ; } async signDirect ( signerAddress , signDoc ) { if ( this . chainId !== signDoc . chainId ) { throw new Error ( "Unmatched chain id with the offline signer" ) ; } const key = await this . keplr . getKey ( signDoc . chainId ) ; if ( key . bech32Address !== signerAddress ) { throw new Error ( "Unknown signer address" ) ; } return await this . keplr . signDirect ( this . chainId , signerAddress , signDoc ) ; } }