Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions examples/multichain-scan/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import { deriveStealthKeys as stellarDerive } from '@wraith-protocol/sdk/chains/stellar';
import { fetchAnnouncements as stellarFetch } from '@wraith-protocol/sdk/chains/stellar';
import { fetchAnnouncementsStream as stellarFetch } from '@wraith-protocol/sdk/chains/stellar';
import { scanAnnouncements as stellarScan } from '@wraith-protocol/sdk/chains/stellar';
import { bytesToHex as stellarHex } from '@wraith-protocol/sdk/chains/stellar';

Expand Down Expand Up @@ -35,8 +35,11 @@ function hexToBytes(hex: string): Uint8Array {
async function scanStellar(sigHex: string): Promise<ScanResult> {
const sig = hexToBytes(sigHex);
const keys = stellarDerive(sig);
const announcements = await stellarFetch('stellar');
const matches = stellarScan(
const announcements = [];
for await (const ann of stellarFetch('stellar')) {
announcements.push(ann);
}
const matches = await stellarScan(
announcements,
keys.viewingKey,
keys.spendingPubKey,
Expand Down
21 changes: 13 additions & 8 deletions examples/stellar-cli-scan/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
import {
deriveStealthKeys,
fetchAnnouncements,
fetchAnnouncementsStream,
scanAnnouncements,
bytesToHex,
STEALTH_SIGNING_MESSAGE,
Expand All @@ -21,7 +21,9 @@ async function main() {
console.error('Copy .env.example to .env and fill in the values.');
process.exit(1);
}
const secretKeyBytes = new Uint8Array(secretKeyHex.match(/.{1,2}/g)!.map((b) => parseInt(b, 16)));
const secretKeyBytes = new Uint8Array(
secretKeyHex.match(/.{1,2}/g)!.map((b) => parseInt(b, 16)),
);
const keys = deriveStealthKeys(secretKeyBytes);
console.log('Viewing key:', bytesToHex(keys.viewingKey));
console.log('Spending pub key:', bytesToHex(keys.spendingPubKey));
Expand All @@ -37,17 +39,17 @@ async function main() {
console.log('Scanning announcements from:', fromTimestamp?.toISOString() ?? 'beginning of time');
console.log('');

// 3. Fetch announcements from Soroban RPC
// 3. Collect announcements from the streaming API
console.log('Fetching announcements...');
const { announcements, nextCursor } = await fetchAnnouncements('stellar', {
fromTimestamp,
});
const announcements = [];
for await (const ann of fetchAnnouncementsStream('stellar', { fromTimestamp })) {
announcements.push(ann);
}
console.log(`Found ${announcements.length} total announcements`);
console.log(`Next scan cursor: ${nextCursor ?? 'none'}`);
console.log('');

// 4. Scan for payments addressed to us
const payments = scanAnnouncements(
const payments = await scanAnnouncements(
announcements,
keys.viewingKey,
keys.spendingPubKey,
Expand All @@ -62,6 +64,9 @@ async function main() {
console.log('Stealth address:', payment.stealthAddress);
console.log('Stealth pub key:', bytesToHex(payment.stealthPubKeyBytes));
console.log('Stealth private scalar:', payment.stealthPrivateScalar.toString());
if (payment.memo) {
console.log(`Memo [${payment.memo.type}]:`, payment.memo.value);
}
console.log('');
}

Expand Down
Loading