@@ -7,7 +7,7 @@ import { BaseController } from '@metamask/base-controller';
77import type { GetPermissions } from '@metamask/permission-controller' ;
88import { rpcErrors } from '@metamask/rpc-errors' ;
99import {
10- getProtocolCaveatChains ,
10+ getProtocolCaveatScopes ,
1111 SnapEndowments ,
1212} from '@metamask/snaps-rpc-methods' ;
1313import type {
@@ -136,7 +136,7 @@ export class MultichainRoutingController extends BaseController<
136136
137137 async #resolveRequestAddress(
138138 snapId : SnapId ,
139- chainId : CaipChainId ,
139+ scope : CaipChainId ,
140140 request : JsonRpcRequest ,
141141 ) {
142142 try {
@@ -148,7 +148,7 @@ export class MultichainRoutingController extends BaseController<
148148 request : {
149149 method : '' ,
150150 params : {
151- chainId ,
151+ scope ,
152152 request,
153153 } ,
154154 } ,
@@ -164,11 +164,11 @@ export class MultichainRoutingController extends BaseController<
164164
165165 async #getAccountSnap(
166166 connectedAddresses : CaipAccountId [ ] ,
167- chainId : CaipChainId ,
167+ scope : CaipChainId ,
168168 request : JsonRpcRequest ,
169169 ) {
170170 const accounts = this . messagingSystem
171- . call ( 'AccountsController:listMultichainAccounts' , chainId )
171+ . call ( 'AccountsController:listMultichainAccounts' , scope )
172172 . filter (
173173 ( account : InternalAccount ) =>
174174 account . metadata . snap ?. enabled &&
@@ -187,7 +187,7 @@ export class MultichainRoutingController extends BaseController<
187187 // Attempt to resolve the address that should be used for signing.
188188 const address = await this . #resolveRequestAddress(
189189 resolutionSnapId ,
190- chainId ,
190+ scope ,
191191 request ,
192192 ) ;
193193
@@ -214,7 +214,7 @@ export class MultichainRoutingController extends BaseController<
214214 } ;
215215 }
216216
217- #getProtocolSnaps( chainId : CaipChainId ) {
217+ #getProtocolSnaps( scope : CaipChainId ) {
218218 const allSnaps = this . messagingSystem . call ( 'SnapController:getAll' ) ;
219219 const filteredSnaps = getRunnableSnaps ( allSnaps ) ;
220220
@@ -225,11 +225,11 @@ export class MultichainRoutingController extends BaseController<
225225 ) ;
226226 if ( permissions && hasProperty ( permissions , SnapEndowments . Protocol ) ) {
227227 const permission = permissions [ SnapEndowments . Protocol ] ;
228- const chains = getProtocolCaveatChains ( permission ) ;
229- if ( chains && hasProperty ( chains , chainId ) ) {
228+ const scopes = getProtocolCaveatScopes ( permission ) ;
229+ if ( scopes && hasProperty ( scopes , scope ) ) {
230230 accumulator . push ( {
231231 snapId : snap . id ,
232- methods : chains [ chainId ] . methods ,
232+ methods : scopes [ scope ] . methods ,
233233 } ) ;
234234 }
235235 }
@@ -240,12 +240,12 @@ export class MultichainRoutingController extends BaseController<
240240
241241 async handleRequest ( {
242242 connectedAddresses,
243- chainId ,
243+ scope ,
244244 request,
245245 } : {
246246 connectedAddresses : CaipAccountId [ ] ;
247247 origin : string ;
248- chainId : CaipChainId ;
248+ scope : CaipChainId ;
249249 request : JsonRpcRequest ;
250250 } ) : Promise < unknown > {
251251 // TODO: Determine if the request is already validated here?
@@ -254,7 +254,7 @@ export class MultichainRoutingController extends BaseController<
254254 // If the RPC request can be serviced by an account Snap, route it there.
255255 const accountSnap = await this . #getAccountSnap(
256256 connectedAddresses ,
257- chainId ,
257+ scope ,
258258 request ,
259259 ) ;
260260 if ( accountSnap ) {
@@ -263,13 +263,13 @@ export class MultichainRoutingController extends BaseController<
263263 address : accountSnap . address ,
264264 method,
265265 params,
266- chainId,
266+ chainId : scope ,
267267 } ) ;
268268 }
269269
270270 // If the RPC request cannot be serviced by an account Snap,
271271 // but has a protocol Snap available, route it there.
272- const protocolSnaps = this . #getProtocolSnaps( chainId ) ;
272+ const protocolSnaps = this . #getProtocolSnaps( scope ) ;
273273 const protocolSnap = protocolSnaps . find ( ( snap ) =>
274274 snap . methods . includes ( method ) ,
275275 ) ;
@@ -281,7 +281,7 @@ export class MultichainRoutingController extends BaseController<
281281 method : '' ,
282282 params : {
283283 request,
284- chainId ,
284+ scope ,
285285 } ,
286286 } ,
287287 handler : HandlerType . OnProtocolRequest ,
0 commit comments