StealthChain può essere utilizzato in due modalità:
1. Modalità Off-chain
// Inizializzazione senza provider
const stealthChain = new StealthChain();
// Operazioni base disponibili
const stealthInfo = await stealthChain.generateStealthAddress(
receiverViewingKey,
receiverSpendingKey
);
const announcement = stealthChain.createStealthAnnouncement(
stealthInfo.stealthAddress,
stealthInfo.senderEphemeralPublicKey,
receiverViewingKey,
receiverSpendingKey
);
2. Modalità On-chain
// Inizializzazione con provider
const provider = new ethers.JsonRpcProvider("RPC_URL");
const stealthChain = new StealthChain(provider, "polygon");
// Verifica modalità
if (stealthChain.isOnChainEnabled()) {
// Annuncia pagamento on-chain
await stealthChain.announcePaymentOnChain(
stealthInfo.stealthAddress,
stealthInfo.senderEphemeralKey,
receiverViewingKey,
receiverSpendingKey
);
// Ottieni fee corrente
const fee = await stealthChain.getCurrentFee();
// Monitora nuovi annunci
stealthChain.listenToNewAnnouncements((announcement) => {
console.log("Nuovo annuncio:", announcement);
});
}
Funzionalità Disponibili
generateStealthAddress: Genera un nuovo indirizzo stealthderiveStealthAddress: Deriva un indirizzo stealth dai parametricreateStealthAnnouncement: Crea un annuncio di pagamentocreateRecoveryData: Prepara i dati per il recupero fondiannouncePaymentOnChain: Annuncia pagamento sulla blockchaingetAnnouncementsInRange: Recupera annunci in un rangegetTotalAnnouncements: Ottiene numero totale annuncigetCurrentFee: Recupera fee correntelistenToNewAnnouncements: Ascolta nuovi annunciisStealthAddressAnnounced: Verifica se indirizzo è stato annunciatogetExplorerUrl: Ottiene URL explorer per transazione