66 nagaLocalEnvironment ,
77 type NagaLocalSignatures ,
88} from './naga-local.env' ;
9+ import { signatures as defaultSignatures } from './generated/naga-develop' ;
910import type { ExpectedAccountOrWalletClient } from '../../shared/managers/contract-manager/createContractsManager' ;
1011
1112type NagaLocalContextOptions = {
@@ -14,6 +15,32 @@ type NagaLocalContextOptions = {
1415 rpcUrlOverride ?: string ;
1516} ;
1617
18+ const REQUIRED_SIGNATURE_KEYS = Object . keys (
19+ defaultSignatures
20+ ) as ( keyof NagaLocalSignatures ) [ ] ;
21+
22+ function assertIsNagaLocalSignatures (
23+ value : unknown
24+ ) : asserts value is NagaLocalSignatures {
25+ if ( typeof value !== 'object' || value === null ) {
26+ throw new Error ( 'Generated signatures is not an object' ) ;
27+ }
28+
29+ for ( const key of REQUIRED_SIGNATURE_KEYS ) {
30+ const contract = ( value as Record < string , unknown > ) [ key ] ;
31+ if (
32+ typeof contract !== 'object' ||
33+ contract === null ||
34+ typeof ( contract as { address ?: unknown } ) . address !== 'string' ||
35+ typeof ( contract as { methods ?: unknown } ) . methods !== 'object'
36+ ) {
37+ throw new Error (
38+ `Generated signatures missing required contract metadata for ${ key as string } `
39+ ) ;
40+ }
41+ }
42+ }
43+
1744const createChainManager = (
1845 env : NagaLocalEnvironment ,
1946 account : ExpectedAccountOrWalletClient
@@ -48,12 +75,12 @@ const buildModule = (env: NagaLocalEnvironment) => {
4875 networkName : networkName ?? 'naga-develop' ,
4976 } ) ;
5077
51- const resolvedSignatures = signatures as unknown as NagaLocalSignatures ;
78+ assertIsNagaLocalSignatures ( signatures ) ;
5279
5380 return createWithEnv (
5481 new NagaLocalEnvironment ( {
5582 rpcUrlOverride : rpcUrlOverride ?? env . getConfig ( ) . rpcUrl ,
56- signatures : resolvedSignatures ,
83+ signatures,
5784 } )
5885 ) ;
5986 } ;
0 commit comments