Implemented PostgreSQL v3 allocation-registry groundwork

This commit is contained in:
2026-10-21 14:59:15 -04:00
parent ee5dc35330
commit e70199ecb0
6 changed files with 360 additions and 9 deletions
+9 -1
View File
@@ -4,7 +4,7 @@ import { parseXmr } from '../../shared/xmr-amount.ts';
const alphabet='123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
const decodedSizes:Record<number,number>={2:1,3:2,5:3,6:4,7:5,9:6,10:7,11:8};
/** Support only mainnet standard/subaddresses. Integrated/payment-ID addresses need a separate policy. */
export async function validateXmrAddress(address:string):Promise<string>{
async function validateMainnetAddressPrefix(address:string):Promise<number>{
if(typeof address!=='string'||address.length!==95)throw new Error('Expected a mainnet standard XMR address or subaddress');
const bytes:number[]=[];
for(let start=0;start<address.length;start+=11){
@@ -19,6 +19,14 @@ export async function validateXmrAddress(address:string):Promise<string>{
if(bytes.length!==69||![18,42].includes(bytes[0]))throw new Error('XMR address network/type is not supported');
const decoded=Uint8Array.from(bytes),expected=(await keccak(decoded.slice(0,-4),256)).slice(0,8);
if(Buffer.from(decoded.slice(-4)).toString('hex')!==expected)throw new Error('XMR checksum mismatch');
return bytes[0];
}
export async function validateXmrAddress(address:string):Promise<string>{
await validateMainnetAddressPrefix(address);
return address;
}
export async function validateXmrSubaddress(address:string):Promise<string>{
if(await validateMainnetAddressPrefix(address)!==42)throw new Error('Expected a Monero mainnet subaddress');
return address;
}
export function atomicXmr(value:string):bigint{