@@ -8,16 +8,39 @@ import { getAccountsFromAccessList } from '../utils/credentials.js'
88import { OceanNodeConfig } from '../@types/OceanNode.js'
99import { LOG_LEVELS_STR } from './logging/Logger.js'
1010import { CommonValidation } from './validators.js'
11+ import { isERC1271Valid } from '../components/core/utils/nonceHandler.js'
12+
1113export async function validateAdminSignature (
1214 expiryTimestamp : number ,
13- signature : string
15+ signature : string ,
16+ address ?: string
1417) : Promise < CommonValidation > {
1518 const message = expiryTimestamp . toString ( )
16- const signerAddress = ethers . verifyMessage ( message , signature ) ?. toLowerCase ( )
17- CORE_LOGGER . logMessage ( `Resolved signer address: ${ signerAddress } ` )
19+ let signerAddress
20+
1821 try {
19- const allowedAdmins : string [ ] = await getAdminAddresses ( )
20- console . log ( `Allowed admins: ${ allowedAdmins } ` )
22+ const config = await getConfiguration ( )
23+ if ( address ) {
24+ const hexMessage = ethers . hashMessage ( message )
25+ const firstChainId = Object . keys ( config ?. supportedNetworks || { } ) [ 0 ]
26+ if ( firstChainId ) {
27+ const provider = new ethers . JsonRpcProvider (
28+ config . supportedNetworks [ firstChainId ] . rpc
29+ )
30+
31+ if ( ! ( await isERC1271Valid ( address , hexMessage , signature , provider ) ) ) {
32+ return { valid : false , error : 'Invalid ERC1271 signature' }
33+ }
34+ signerAddress = address
35+ } else {
36+ return { valid : false , error : 'No network configured in node config' }
37+ }
38+ } else {
39+ signerAddress = ethers . verifyMessage ( message , signature ) ?. toLowerCase ( )
40+ CORE_LOGGER . logMessage ( `Resolved signer address: ${ signerAddress } ` )
41+ }
42+
43+ const allowedAdmins : string [ ] = await getAdminAddresses ( config )
2144
2245 if ( allowedAdmins . length === 0 ) {
2346 const errorMsg = "Allowed admins list is empty. Please add admins' addresses."
@@ -48,8 +71,16 @@ export async function validateAdminSignature(
4871 }
4972}
5073
51- export async function getAdminAddresses ( ) : Promise < string [ ] > {
52- const config : OceanNodeConfig = await getConfiguration ( )
74+ export async function getAdminAddresses (
75+ existingConfig ?: OceanNodeConfig
76+ ) : Promise < string [ ] > {
77+ let config : OceanNodeConfig
78+ if ( ! existingConfig ) {
79+ config = await getConfiguration ( )
80+ } else {
81+ config = existingConfig
82+ }
83+
5384 const validAddresses : string [ ] = [ ]
5485 if ( config . allowedAdmins && config . allowedAdmins . length > 0 ) {
5586 for ( const admin of config . allowedAdmins ) {
0 commit comments