@@ -41,6 +41,7 @@ import {
4141 validateInterfaceContext ,
4242} from './utils' ;
4343import type { GetSnap } from '../snaps' ;
44+ import { HasPermission } from '@metamask/permission-controller' ;
4445
4546const MAX_UI_CONTENT_SIZE = 10_000_000 ; // 10 mb
4647
@@ -114,7 +115,8 @@ export type SnapInterfaceControllerAllowedActions =
114115 | MultichainAssetsControllerGetStateAction
115116 | AccountsControllerGetSelectedMultichainAccountAction
116117 | AccountsControllerGetAccountByAddressAction
117- | AccountsControllerListMultichainAccountsAction ;
118+ | AccountsControllerListMultichainAccountsAction
119+ | HasPermission ;
118120
119121export type SnapInterfaceControllerActions =
120122 | CreateInterface
@@ -282,7 +284,7 @@ export class SnapInterfaceController extends BaseController<
282284 contentType ?: ContentType ,
283285 ) {
284286 const element = getJsxInterface ( content ) ;
285- this . #validateContent( element ) ;
287+ this . #validateContent( snapId , element ) ;
286288 validateInterfaceContext ( context ) ;
287289
288290 const id = nanoid ( ) ;
@@ -339,7 +341,7 @@ export class SnapInterfaceController extends BaseController<
339341 ) {
340342 this . #validateArgs( snapId , id ) ;
341343 const element = getJsxInterface ( content ) ;
342- this . #validateContent( element ) ;
344+ this . #validateContent( snapId , element ) ;
343345 validateInterfaceContext ( context ) ;
344346
345347 const oldState = this . state . interfaces [ id ] . state ;
@@ -530,13 +532,22 @@ export class SnapInterfaceController extends BaseController<
530532 return this . messenger . call ( 'SnapController:get' , id ) ;
531533 }
532534
535+ #hasPermission( snapId : SnapId , permission : string ) {
536+ return this . messenger . call (
537+ 'PermissionController:hasPermission' ,
538+ snapId ,
539+ permission ,
540+ ) ;
541+ }
542+
533543 /**
534544 * Utility function to validate the components of an interface.
535545 * Throws if something is invalid.
536546 *
547+ * @param snapId - The Snap ID.
537548 * @param element - The JSX element to verify.
538549 */
539- #validateContent( element : JSXElement ) {
550+ #validateContent( snapId : SnapId , element : JSXElement ) {
540551 // We assume the validity of this JSON to be validated by the caller.
541552 // E.g., in the RPC method implementation.
542553 const size = getJsonSizeUnsafe ( element ) ;
@@ -549,6 +560,7 @@ export class SnapInterfaceController extends BaseController<
549560 isOnPhishingList : this . #checkPhishingList. bind ( this ) ,
550561 getSnap : this . #getSnap. bind ( this ) ,
551562 getAccountByAddress : this . #getAccountByAddress. bind ( this ) ,
563+ hasPermission : this . #hasPermission. bind ( this , snapId ) ,
552564 } ) ;
553565 }
554566
0 commit comments