import { Keplr , KeplrIntereactionOptions , KeplrMode , KeplrSignOptions , Key , } from "@keplr-wallet/types" ; import { AminoSignResponse , BroadcastMode , makeCosmoshubPath , OfflineSigner , Secp256k1HdWallet , StdSignature , StdSignDoc , StdTx , } from "@cosmjs/launchpad" ; import { SecretUtils } from "secretjs/types/enigmautils" ; import { Bech32Address } from "@keplr-wallet/cosmos" ; import { OfflineDirectSigner } from "@cosmjs/proto-signing" ; import { CosmJSOfflineSigner } from "@keplr-wallet/provider" ; import { DirectSignResponse } from "@cosmjs/proto-signing/build/signer" ; export class MockKeplr implements Keplr { readonly version : string = "0.0.1" ; readonly mode : KeplrMode = "extension" ; public defaultOptions : KeplrIntereactionOptions = { } ; public readonly walletMap : { [ chainId ] : Secp256k1HdWallet | undefined ; } = { } ; async getHdWallet ( chainId ) { if ( ! this . walletMap [ chainId ] ) { const chainInfo = this . chainInfos . find ( ( info ) => info . chainId === chainId ) ; if ( ! chainInfo ) { throw new Error ( "Unknown chain" ) ; } this . walletMap [ chainId ] = await Secp256k1HdWallet . fromMnemonic ( this . mnemonic , makeCosmoshubPath ( 0 ) , chainInfo . bech32Config . bech32PrefixAccAddr ) ; } return this . walletMap [ chainId ] ! ; } constructor ( public readonly sendTxFn , public readonly chainInfos , public readonly mnemonic ) { } enable ( ) { return Promise . resolve ( undefined ) ; } enigmaDecrypt ( ) { throw new Error ( "Not implemented" ) ; } enigmaEncrypt ( ) { throw new Error ( "Not implemented" ) ; } experimentalSuggestChain ( ) { throw new Error ( "Not implemented" ) ; } getEnigmaPubKey ( ) { throw new Error ( "Not implemented" ) ; } getEnigmaUtils ( ) { throw new Error ( "Not implemented" ) ; } async getKey ( chainId ) { const cosmJsKeys = await ( await this . getHdWallet ( chainId ) ) . getAccounts ( ) ; return { name : "" , algo : "secp256k1" , pubKey : cosmJsKeys [ 0 ] . pubkey , address : Bech32Address . fromBech32 ( cosmJsKeys [ 0 ] . address ) . address , bech32Address : cosmJsKeys [ 0 ] . address , isNanoLedger : false , } ; } signArbitrary ( _chainId , _signer , _data ) { throw new Error ( "Not implemented" ) ; } verifyArbitrary ( _chainId , _signer , _data , _signature ) { throw new Error ( "Not implemented" ) ; } getOfflineSigner ( chainId ) { return new CosmJSOfflineSigner ( chainId , this ) ; } getSecret20ViewingKey ( ) { throw new Error ( "Not implemented" ) ; } sendTx ( chainId , stdTx , mode ) { return this . sendTxFn ( chainId , stdTx , mode ) ; } async signAmino ( chainId , signer , signDoc , _ ? ) { const hdWallet = await this . getHdWallet ( chainId ) ; const keys = await hdWallet . getAccounts ( ) ; if ( keys [ 0 ] . address !== signer ) { throw new Error ( "Unmatched signer" ) ; } return hdWallet . signAmino ( signer , signDoc ) ; } signDirect ( ) { throw new Error ( "Not implemented" ) ; } suggestToken ( ) { throw new Error ( "Not implemented" ) ; } getEnigmaTxEncryptionKey ( _chainId , _nonce ) { throw new Error ( "Not implemented" ) ; } getOfflineSignerAuto ( _chainId ) { throw new Error ( "Not implemented" ) ; } getOfflineSignerOnlyAmino ( _chainId ) { throw new Error ( "Not implemented" ) ; } }