import { Env , Guard , MessageSender , Message } from "@keplr-wallet/router" ; export class ExtensionGuards { static readonly checkOriginIsValid : Guard = ( _ , msg , sender ) : Promise < void > => { if ( ! sender . url ) { throw new Error ( "url is empty" ) ; } if ( ! msg . origin ) { throw new Error ( "origin is empty" ) ; } const url = new URL ( sender . url ) ; if ( url . origin !== msg . origin ) { throw new Error ( "Invalid origin" ) ; } return Promise . resolve ( ) ; } ; static readonly checkMessageIsInternal : Guard = ( env , msg , sender ) : Promise < void > => { if ( ! env . isInternalMsg && ! msg . approveExternal ( env , sender ) ) { throw new Error ( "Permission rejected" ) ; } return Promise . resolve ( ) ; } ; }