diff --git a/examples/stellar-solid-receive/.env.example b/examples/stellar-solid-receive/.env.example new file mode 100644 index 0000000..d89572f --- /dev/null +++ b/examples/stellar-solid-receive/.env.example @@ -0,0 +1,2 @@ +# Optional: pre-fill the secret key input (128 hex chars / 64 bytes). +# VITE_STELLAR_SECRET_KEY=aabbcc... diff --git a/examples/stellar-solid-receive/index.html b/examples/stellar-solid-receive/index.html new file mode 100644 index 0000000..bcfc26a --- /dev/null +++ b/examples/stellar-solid-receive/index.html @@ -0,0 +1,12 @@ + + + + + + Wraith Stellar — Solid.js Receive + + +
+ + + diff --git a/examples/stellar-solid-receive/package.json b/examples/stellar-solid-receive/package.json new file mode 100644 index 0000000..9bd9b1c --- /dev/null +++ b/examples/stellar-solid-receive/package.json @@ -0,0 +1,21 @@ +{ + "name": "@wraith-protocol/example-stellar-solid-receive", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc && vite build", + "preview": "vite preview" + }, + "dependencies": { + "@wraith-protocol/sdk": "workspace:*", + "@wraith-protocol/sdk-solid": "workspace:*", + "solid-js": "^1.9.0" + }, + "devDependencies": { + "typescript": "^5.7.0", + "vite": "^6.1.0", + "vite-plugin-solid": "^2.11.0" + } +} diff --git a/examples/stellar-solid-receive/src/App.tsx b/examples/stellar-solid-receive/src/App.tsx new file mode 100644 index 0000000..f1a83cf --- /dev/null +++ b/examples/stellar-solid-receive/src/App.tsx @@ -0,0 +1,208 @@ +import { createSignal, createMemo, Show, For } from 'solid-js'; +import { createStealthKeys, createScanner } from '@wraith-protocol/sdk-solid'; +import { + bytesToHex, + scanAnnouncements as stellarScanAnnouncements, + type Announcement, +} from '@wraith-protocol/sdk/chains/stellar'; + +// Canned announcement fixture — used in dev/demo without a live Horizon node. +const CANNED_ANNOUNCEMENTS: Announcement[] = []; + +function parseHex(hex: string): Uint8Array | null { + const clean = hex.replace(/^0x/i, '').trim(); + if (!/^[0-9a-fA-F]+$/.test(clean) || clean.length % 2 !== 0) return null; + return new Uint8Array(clean.match(/.{1,2}/g)!.map((b) => parseInt(b, 16))); +} + +export default function App() { + const [input, setInput] = createSignal((import.meta as any).env?.VITE_STELLAR_SECRET_KEY ?? ''); + + // Primitives + const stealthKeys = createStealthKeys(); + const scanner = createScanner(); + + const metaAddress = createMemo(() => stealthKeys.metaAddress()); + + function handleDerive() { + const bytes = parseHex(input()); + if (!bytes) return; + if (bytes.length !== 64) return; + + const k = stealthKeys.deriveKeys(bytes); + stealthKeys.encodeMetaAddress(k.spendingPubKey, k.viewingPubKey); + } + + function handleScan() { + const k = stealthKeys.keys(); + if (!k) return; + + // Scan the canned fixture (in a real app, call scanner.scan({ chain: 'testnet' })) + scanner.match(CANNED_ANNOUNCEMENTS, k.viewingKey, k.spendingPubKey, k.spendingScalar); + } + + return ( +
+

Wraith Stellar — Receive Stealth Payments (Solid.js)

+

+ Enter your 64-byte hex secret key to derive your stealth keys and meta-address. Share the + meta-address with senders. +

+ +
+ +