MaxMind IP database & region approvals

This commit is contained in:
tim
2024-12-19 20:18:56 -04:00
parent 8835ad5272
commit 65c4e08e84
7 changed files with 623 additions and 6 deletions

46
approval.js Normal file
View File

@@ -0,0 +1,46 @@
import {countryForIP} from "./maxmind.js";
const bannedCountries = [
'US', // FFS
'PR', // FFS (different country?!)
// OFAC country bans
'CU', // Cuba
'IR', // Iran
'KP', // North Korea
'SY', // Syria
'RU', // Russia
'BY', // Belarus
]
export function approveWallet(walletAddress) {
// todo OFAC lookup
return true
}
function approveIP(ipAddress) {
try {
const country = countryForIP(ipAddress)
if (!country) return false
const approved = !bannedCountries.includes(country)
if (!approved)
// todo log ban & report
console.warn(`IP ${ipAddress} from ${country} is banned`)
return approved
}
catch (e) {
console.warn(`IP lookup failed for ${ipAddress}: ${e.message}`)
return false
}
}
export function approveRegion(socket, bypass) {
const ipAddress = socket.handshake.address
const approved = bypass === '6ehWWH98diqv39gWZcPo' || approveIP(ipAddress)
socket.emit('approvedRegion', approved)
}