import { Env , Handler , InternalHandler , Message } from "@keplr-wallet/router" ; import { GetPubkeyMsg , GetTxEncryptionKeyMsg , ReqeustEncryptMsg , RequestDecryptMsg , } from "./messages" ; import { SecretWasmService } from "./service" ; export const getHandler = ( service ) => { return ( env , msg ) => { switch ( msg . constructor ) { case GetPubkeyMsg : return handleGetPubkeyMsg ( service ) ( env , msg as GetPubkeyMsg ) ; case ReqeustEncryptMsg : return handleReqeustEncryptMsg ( service ) ( env , msg as ReqeustEncryptMsg ) ; case RequestDecryptMsg : return handleRequestDecryptMsg ( service ) ( env , msg as RequestDecryptMsg ) ; case GetTxEncryptionKeyMsg : return handleGetTxEncryptionKeyMsg ( service ) ( env , msg as GetTxEncryptionKeyMsg ) ; default : throw new Error ( "Unknown msg type" ) ; } } ; } ; const handleGetPubkeyMsg = ( service ) => { return async ( env , msg ) => { await service . permissionService . checkOrGrantBasicAccessPermission ( env , msg . chainId , msg . origin ) ; return await service . getPubkey ( env , msg . chainId ) ; } ; } ; const handleReqeustEncryptMsg = ( service ) => { return async ( env , msg ) => { await service . permissionService . checkOrGrantBasicAccessPermission ( env , msg . chainId , msg . origin ) ; return await service . encrypt ( env , msg . chainId , msg . contractCodeHash , msg . msg ) ; } ; } ; const handleRequestDecryptMsg = ( service ) => { return async ( env , msg ) => { await service . permissionService . checkOrGrantBasicAccessPermission ( env , msg . chainId , msg . origin ) ; return await service . decrypt ( env , msg . chainId , msg . cipherText , msg . nonce ) ; } ; } ; const handleGetTxEncryptionKeyMsg = ( service ) => { return async ( env , msg ) => { await service . permissionService . checkOrGrantBasicAccessPermission ( env , msg . chainId , msg . origin ) ; return await service . getTxEncryptionKey ( env , msg . chainId , msg . nonce ) ; } ; } ;