XMR native

This commit is contained in:
2026-10-20 12:09:58 -04:00
parent 558427545f
commit a1de67ea14
9 changed files with 341 additions and 12 deletions
+3 -3
View File
@@ -1,4 +1,5 @@
import { keccak } from 'hash-wasm';
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};
@@ -21,10 +22,9 @@ export async function validateXmrAddress(address:string):Promise<string>{
return address;
}
export function atomicXmr(value:string):bigint{
if(typeof value!=='string'||!/^(0|[1-9]\d{0,9})(\.\d{1,12})?$/.test(value))throw new Error('Invalid bounded XMR decimal');
const [whole,fraction='']=value.split('.');return BigInt(whole)*1_000_000_000_000n+BigInt(fraction.padEnd(12,'0'));
return parseXmr(value);
}
export function fiatCents(value:string):number{
if(typeof value!=='string'||!/^(0|[1-9]\d{0,6})(\.\d{1,2})?$/.test(value))throw new Error('Invalid USD decimal');
if(typeof value!=='string'||value.length>10||!/^(0|[1-9]\d{0,6})(\.\d{1,2})?(?![\s\S])/.test(value))throw new Error('Invalid USD decimal');
const [whole,fraction='']=value.split('.');return Number(whole)*100+Number(fraction.padEnd(2,'0'));
}