Skip to content

Commit 9555c61

Browse files
committed
Merge branch 'main' into p2p-v3
# Conflicts: # package-lock.json
2 parents a701ce4 + a107cda commit 9555c61

File tree

5 files changed

+43
-10
lines changed

5 files changed

+43
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,4 @@
159159
"publish": false
160160
}
161161
}
162-
}
162+
}

src/@types/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface GetP2PNetworkStatsCommand extends Command {}
3737
export interface AdminCommand extends Command {
3838
expiryTimestamp: number
3939
signature: string
40+
address?: string
4041
}
4142

4243
export interface AdminCollectFeesHandlerResponse {

src/components/core/admin/adminHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export abstract class AdminCommandHandler
4343
}
4444
const signatureValidation: CommonValidation = await validateAdminSignature(
4545
command.expiryTimestamp,
46-
command.signature
46+
command.signature,
47+
command.address
4748
)
4849
if (!signatureValidation.valid) {
4950
return buildInvalidRequestMessage(

src/components/core/utils/nonceHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ async function validateNonceAndSignature(
245245
}
246246

247247
// Smart account validation
248-
async function isERC1271Valid(
248+
export async function isERC1271Valid(
249249
address: string,
250250
hash: string | Uint8Array,
251251
signature: string,

src/utils/auth.ts

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,39 @@ import { getAccountsFromAccessList } from '../utils/credentials.js'
88
import { OceanNodeConfig } from '../@types/OceanNode.js'
99
import { LOG_LEVELS_STR } from './logging/Logger.js'
1010
import { CommonValidation } from './validators.js'
11+
import { isERC1271Valid } from '../components/core/utils/nonceHandler.js'
12+
1113
export 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

Comments
 (0)