Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
54 changes: 51 additions & 3 deletions bindings/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Remote connect to major Lightning node implementations with one TypeScript inter
- Supports major nodes: CLN, LND, Phoenixd
- Supports protocols: BOLT11, BOLT12, NWC
- Includes custodial APIs: Strike, Speed, Blink
- Includes Spark (`SparkNode`) with pure TypeScript signer patching (no UniFFI bindings)
- LNURL + Lightning Address support (`user@domain.com`, `lnurl1...`)
- Frontend-capable TypeScript runtime (`fetch`-based)

Expand Down Expand Up @@ -59,6 +60,52 @@ const status = await node.lookupInvoice({ paymentHash: invoice.paymentHash });
const txs = await node.listTransactions({ from: 0, limit: 10 });
```

### Spark (browser + Expo Go oriented)

```ts
import { createNode, installSparkRuntime } from '@sunnyln/lni';

// One-time runtime setup for browser / React Native / Expo Go.
// - Adds Buffer + atob/btoa polyfills when missing
// - Wraps fetch for gRPC-web body reader compatibility
// - Optionally injects API key header into same-origin Spark HTTP calls
const sparkRuntime = installSparkRuntime({
apiKey: 'optional-api-key',
apiKeyHeader: 'x-api-key',
apiKeySameOriginOnly: true, // default true; safer for browser CORS
});

const sparkNode = createNode({
kind: 'spark',
config: {
mnemonic: 'abandon ...', // store securely in production
network: 'mainnet', // or regtest/testnet/signet/local
// optional:
// passphrase: '...',
// defaultMaxFeeSats: 20,
// sparkOptions: { ...sdk options... },
// sdkEntry: 'auto' | 'bare' | 'native' | 'default'
},
});

const sparkInfo = await sparkNode.getInfo();
const sparkInvoice = await sparkNode.createInvoice({
amountMsats: 25_000,
description: 'Spark invoice',
});

// Optional cleanup (restores original global fetch if installSparkRuntime changed it)
sparkRuntime.restore();
```

Spark entrypoint behavior:
- `sdkEntry: 'auto'` (default) uses a browser-safe bundled Spark bare runtime in browser/Expo and falls back to the default SDK entry in Node.
- `sdkEntry: 'bare'` forces the browser-safe bundled no-WASM/no-native path.
- `sdkEntry: 'default'` uses the standard SDK export (may load WASM).
- `sdkEntry: 'native'` uses the React Native native SDK entry.

Node-only note: use `sdkEntry: 'default'` for Node environments.

For NWC specifically, `createNode` returns `NwcNode` when `kind: 'nwc'`, so you can close it:

```ts
Expand Down Expand Up @@ -104,14 +151,15 @@ await node.onInvoiceEvents(
- `StrikeNode`
- `SpeedNode`
- `BlinkNode`
- `SparkNode`
- LNURL helpers (`detectPaymentType`, `needsResolution`, `resolveToBolt11`, `getPaymentInfo`)

Not included yet:
- `SparkNode` (planned)

## Frontend Runtime Notes

- Uses `fetch`, no Node-native runtime dependency required.
- Spark no longer requires project-level Spark shims/vendor bundles; those are packaged in `@sunnyln/lni`.
- For local `file:` package development with Expo, build the package first (`bindings/typescript`: `npm run build`) and use the Expo example `metro.config.js` pattern for `./dist/*` resolution.
- If Expo shows `Invalid call ... import(specifier)` in `dist/nodes/spark.js`, rebuild `bindings/typescript` and restart Metro with cache clear (`npx expo start --clear`).
- You can inject custom fetch via constructor options:
- `new LndNode(config, { fetch: customFetch })`
- Most backends require secrets (API keys, macaroons, runes, passwords). For production web apps, use a backend proxy/BFF to protect credentials.
Expand Down
41 changes: 41 additions & 0 deletions bindings/typescript/examples/spark-expo-go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files

# dependencies
node_modules/

# Expo
.expo/
dist/
web-build/
expo-env.d.ts

# Native
.kotlin/
*.orig.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision

# Metro
.metro-health-check*

# debug
npm-debug.*
yarn-debug.*
yarn-error.*

# macOS
.DS_Store
*.pem

# local env files
.env*.local

# typescript
*.tsbuildinfo

# generated native folders
/ios
/android
Loading