fiberprobe 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,256 @@
1
+ /**
2
+ * FiberEventEmitter — event-driven payment and invoice lifecycle for Fiber Network.
3
+ *
4
+ * The Fiber RPC does not expose a push-based subscription interface over the
5
+ * standard JSON-RPC port. This module bridges that gap with per-item adaptive
6
+ * polling: each watched payment, invoice, or channel gets its own backoff
7
+ * schedule so recently-started items are checked frequently while long-running
8
+ * ones are polled progressively less often.
9
+ *
10
+ * This is architecturally cleaner than a single global polling loop because:
11
+ * - Items at different lifecycle stages don't share a tick
12
+ * - Backoff is independent per item — a stale payment doesn't slow invoice checks
13
+ * - Callers receive a cancel function, giving them explicit lifecycle control
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const emitter = new FiberEventEmitter(client)
18
+ *
19
+ * // Watch a payment until it settles
20
+ * const cancel = emitter.watchPayment('0xabc...', {
21
+ * onSettled: (payment) => console.log('Payment settled:', payment.status),
22
+ * onFailed: (err) => console.error('Payment failed:', err.suggestion),
23
+ * })
24
+ *
25
+ * // Watch an invoice until it's paid
26
+ * emitter.watchInvoice('0xdef...', {
27
+ * onPaid: (invoice) => console.log('Paid!', invoice.invoice_address),
28
+ * onExpired: (invoice) => console.warn('Invoice expired'),
29
+ * })
30
+ *
31
+ * // Clean up everything at once
32
+ * emitter.destroy()
33
+ * ```
34
+ */
35
+ import { FiberError } from '../client/errors.js';
36
+ const DEFAULT_BACKOFF = {
37
+ initialMs: 500,
38
+ multiplier: 1.5,
39
+ maxMs: 10_000,
40
+ maxAttempts: 60,
41
+ };
42
+ // ── FiberEventEmitter ─────────────────────────────────────────────────────────
43
+ export class FiberEventEmitter {
44
+ client;
45
+ watchers = new Map();
46
+ watcherCount = 0;
47
+ constructor(client) {
48
+ this.client = client;
49
+ }
50
+ // ── Payment watcher ─────────────────────────────────────────────────────────
51
+ /**
52
+ * Polls get_payment until the payment reaches a terminal status (Success/Failed)
53
+ * or maxAttempts is exhausted.
54
+ *
55
+ * @param paymentHash - The payment hash to watch
56
+ * @param options - Callbacks and optional backoff overrides
57
+ * @returns A cancel function — call it to stop polling immediately
58
+ */
59
+ watchPayment(paymentHash, options = {}) {
60
+ const profile = this.resolveProfile(options.backoff);
61
+ const watchId = `payment:${paymentHash}:${++this.watcherCount}`;
62
+ let interval = profile.initialMs;
63
+ let attempts = 0;
64
+ let lastPayment = null;
65
+ const poll = async () => {
66
+ if (!this.watchers.has(watchId))
67
+ return;
68
+ attempts++;
69
+ try {
70
+ const payment = await this.client.getPayment(paymentHash);
71
+ lastPayment = payment;
72
+ if (payment.status === 'Success') {
73
+ options.onSettled?.(payment);
74
+ this.cleanup(watchId);
75
+ return;
76
+ }
77
+ if (payment.status === 'Failed') {
78
+ const raw = payment.failed_error ?? 'Payment failed with no error detail';
79
+ const err = FiberError.parse(raw);
80
+ options.onFailed?.(err, payment);
81
+ options.onSettled?.(payment);
82
+ this.cleanup(watchId);
83
+ return;
84
+ }
85
+ // Still Inflight or Created
86
+ options.onProgress?.(payment, attempts);
87
+ }
88
+ catch (err) {
89
+ // RPC errors are non-fatal during polling — the node may be briefly busy
90
+ // We continue polling until maxAttempts, then surface via onTimeout
91
+ }
92
+ if (attempts >= profile.maxAttempts) {
93
+ options.onTimeout?.(lastPayment);
94
+ this.cleanup(watchId);
95
+ return;
96
+ }
97
+ // Schedule next poll with backoff
98
+ interval = Math.min(interval * profile.multiplier, profile.maxMs);
99
+ const watcher = this.watchers.get(watchId);
100
+ if (watcher) {
101
+ watcher.timer = setTimeout(() => { void poll(); }, interval);
102
+ }
103
+ };
104
+ const timer = setTimeout(() => { void poll(); }, interval);
105
+ const cancel = () => this.cleanup(watchId);
106
+ this.watchers.set(watchId, { id: watchId, timer, cancel });
107
+ return cancel;
108
+ }
109
+ // ── Invoice watcher ─────────────────────────────────────────────────────────
110
+ /**
111
+ * Polls get_invoice until the invoice is Paid, Expired, or Cancelled,
112
+ * or maxAttempts is exhausted.
113
+ *
114
+ * @param paymentHash - The payment hash identifying the invoice to watch
115
+ * @param options - Callbacks and optional backoff overrides
116
+ * @returns A cancel function
117
+ */
118
+ watchInvoice(paymentHash, options = {}) {
119
+ const profile = this.resolveProfile(options.backoff);
120
+ const watchId = `invoice:${paymentHash}:${++this.watcherCount}`;
121
+ let interval = profile.initialMs;
122
+ let attempts = 0;
123
+ let lastInvoice = null;
124
+ const poll = async () => {
125
+ if (!this.watchers.has(watchId))
126
+ return;
127
+ attempts++;
128
+ try {
129
+ const invoice = await this.client.getInvoice(paymentHash);
130
+ lastInvoice = invoice;
131
+ if (invoice.status === 'Paid') {
132
+ options.onPaid?.(invoice);
133
+ this.cleanup(watchId);
134
+ return;
135
+ }
136
+ if (invoice.status === 'Expired' || invoice.status === 'Cancelled') {
137
+ options.onExpired?.(invoice);
138
+ this.cleanup(watchId);
139
+ return;
140
+ }
141
+ // Still Open or Received
142
+ options.onProgress?.(invoice, attempts);
143
+ }
144
+ catch {
145
+ // Continue polling on transient RPC errors
146
+ }
147
+ if (attempts >= profile.maxAttempts) {
148
+ options.onTimeout?.(lastInvoice);
149
+ this.cleanup(watchId);
150
+ return;
151
+ }
152
+ interval = Math.min(interval * profile.multiplier, profile.maxMs);
153
+ const watcher = this.watchers.get(watchId);
154
+ if (watcher) {
155
+ watcher.timer = setTimeout(() => { void poll(); }, interval);
156
+ }
157
+ };
158
+ const timer = setTimeout(() => { void poll(); }, interval);
159
+ const cancel = () => this.cleanup(watchId);
160
+ this.watchers.set(watchId, { id: watchId, timer, cancel });
161
+ return cancel;
162
+ }
163
+ // ── Channel watcher ─────────────────────────────────────────────────────────
164
+ /**
165
+ * Polls list_channels filtered to a specific channel_id until the channel
166
+ * reaches ChannelReady or Closed, or maxAttempts is exhausted.
167
+ *
168
+ * Useful for giving users feedback during the channel-opening flow without
169
+ * requiring them to poll manually.
170
+ *
171
+ * @param channelId - The channel_id to watch
172
+ * @param options - Callbacks and optional backoff overrides
173
+ * @returns A cancel function
174
+ */
175
+ watchChannel(channelId, options = {}) {
176
+ const profile = this.resolveProfile(options.backoff);
177
+ const watchId = `channel:${channelId}:${++this.watcherCount}`;
178
+ let interval = profile.initialMs;
179
+ let attempts = 0;
180
+ let lastChannel = null;
181
+ const poll = async () => {
182
+ if (!this.watchers.has(watchId))
183
+ return;
184
+ attempts++;
185
+ try {
186
+ const channels = await this.client.listChannels({ include_closed: true });
187
+ const channel = channels.find((c) => c.channel_id === channelId);
188
+ if (!channel) {
189
+ // Channel not yet visible — keep polling
190
+ options.onProgress?.(null, attempts);
191
+ }
192
+ else {
193
+ lastChannel = channel;
194
+ if (channel.state.state_name === 'ChannelReady') {
195
+ options.onReady?.(channel);
196
+ this.cleanup(watchId);
197
+ return;
198
+ }
199
+ if (channel.state.state_name === 'Closed') {
200
+ options.onClosed?.(channel);
201
+ this.cleanup(watchId);
202
+ return;
203
+ }
204
+ options.onProgress?.(channel, attempts);
205
+ }
206
+ }
207
+ catch {
208
+ // Continue on transient errors
209
+ }
210
+ if (attempts >= profile.maxAttempts) {
211
+ options.onTimeout?.(lastChannel);
212
+ this.cleanup(watchId);
213
+ return;
214
+ }
215
+ interval = Math.min(interval * profile.multiplier, profile.maxMs);
216
+ const watcher = this.watchers.get(watchId);
217
+ if (watcher) {
218
+ watcher.timer = setTimeout(() => { void poll(); }, interval);
219
+ }
220
+ };
221
+ const timer = setTimeout(() => { void poll(); }, interval);
222
+ const cancel = () => this.cleanup(watchId);
223
+ this.watchers.set(watchId, { id: watchId, timer, cancel });
224
+ return cancel;
225
+ }
226
+ // ── Lifecycle ────────────────────────────────────────────────────────────────
227
+ /**
228
+ * Returns the number of currently active watchers.
229
+ * Useful for debugging and testing.
230
+ */
231
+ get activeWatcherCount() {
232
+ return this.watchers.size;
233
+ }
234
+ /**
235
+ * Cancels all active watchers and clears all timers.
236
+ * Call this when tearing down the application or component.
237
+ */
238
+ destroy() {
239
+ for (const watcher of this.watchers.values()) {
240
+ if (watcher.timer !== null)
241
+ clearTimeout(watcher.timer);
242
+ }
243
+ this.watchers.clear();
244
+ }
245
+ // ── Private ──────────────────────────────────────────────────────────────────
246
+ cleanup(watchId) {
247
+ const watcher = this.watchers.get(watchId);
248
+ if (watcher?.timer !== null)
249
+ clearTimeout(watcher.timer);
250
+ this.watchers.delete(watchId);
251
+ }
252
+ resolveProfile(override) {
253
+ return { ...DEFAULT_BACKOFF, ...override };
254
+ }
255
+ }
256
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/payment/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAc,qBAAqB,CAAA;AAmBxD,MAAM,eAAe,GAAmB;IACtC,SAAS,EAAI,GAAG;IAChB,UAAU,EAAG,GAAG;IAChB,KAAK,EAAQ,MAAM;IACnB,WAAW,EAAE,EAAE;CAChB,CAAA;AAuDD,iFAAiF;AAEjF,MAAM,OAAO,iBAAiB;IAIC,MAAM;IAHlB,QAAQ,GAAG,IAAI,GAAG,EAAyB,CAAA;IACpD,YAAY,GAAQ,CAAC,CAAA;IAE7B,YAA6B,MAAmB;sBAAnB,MAAM;IAAgB,CAAC;IAEpD,+EAA+E;IAE/E;;;;;;;OAOG;IACH,YAAY,CAAC,WAAmB,EAAE,OAAO,GAAwB,EAAE;QACjE,MAAM,OAAO,GAAI,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QACrD,MAAM,OAAO,GAAI,WAAW,WAAW,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,CAAA;QAChE,IAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAA;QAClC,IAAM,QAAQ,GAAG,CAAC,CAAA;QAClB,IAAM,WAAW,GAAmB,IAAI,CAAA;QAExC,MAAM,IAAI,GAAG,KAAK,IAAmB,EAAE;YACrC,IAAI,CAAC,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C,CAAA;QAC3D,MAAM,MAAM,GAAI,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC3C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;QAE1D,OAAO,MAAM,CAAA;IACf,CAAC;IAED,gFAAgF;IAEhF;;;OAGG;IACH,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAA;IAC3B,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;YAC7C,IAAI,OAAO,CAAC,KAAK,KAAK,IAAI;gBAAE,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QACzD,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;IACvB,CAAC;IAED,gFAAgF;IAExE,OAAO,CAAC,OAAe;QAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAC1C,IAAI,OAAO,EAAE,KAAK,KAAK,IAAI;YAAE,YAAY,CAAC,OAAQ,CAAC,KAAK,CAAC,CAAA;QACzD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAC/B,CAAC;IAEO,cAAc,CAAC,QAAkC;QACvD,OAAO,EAAE,GAAG,eAAe,EAAE,GAAG,QAAQ,EAAE,CAAA;IAC5C,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Isomorphic Web Crypto helpers for payment probing.
3
+ * Uses globalThis.crypto so this works unchanged in the browser (Vite/React
4
+ * demo) and in Node 19+, with no extra dependency.
5
+ */
6
+ /** Generates a random 32-byte value and its SHA-256 hash, both as 0x-prefixed hex. */
7
+ export declare function generateFakePaymentHash(): Promise<{
8
+ preimage: string;
9
+ paymentHash: string;
10
+ }>;
11
+ //# sourceMappingURL=probe-crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probe-crypto.d.ts","sourceRoot":"","sources":["../../src/payment/probe-crypto.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,sFAAsF;AACtF,wBAAsB,uBAAuB,IAAI,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,CAQlG"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Isomorphic Web Crypto helpers for payment probing.
3
+ * Uses globalThis.crypto so this works unchanged in the browser (Vite/React
4
+ * demo) and in Node 19+, with no extra dependency.
5
+ */
6
+ function toHex(buf) {
7
+ return Array.from(new Uint8Array(buf))
8
+ .map((b) => b.toString(16).padStart(2, '0'))
9
+ .join('');
10
+ }
11
+ /** Generates a random 32-byte value and its SHA-256 hash, both as 0x-prefixed hex. */
12
+ export async function generateFakePaymentHash() {
13
+ const bytes = new Uint8Array(32);
14
+ globalThis.crypto.getRandomValues(bytes);
15
+ const digest = await globalThis.crypto.subtle.digest('SHA-256', bytes);
16
+ return {
17
+ preimage: '0x' + toHex(bytes.buffer),
18
+ paymentHash: '0x' + toHex(digest),
19
+ };
20
+ }
21
+ //# sourceMappingURL=probe-crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probe-crypto.js","sourceRoot":"","sources":["../../src/payment/probe-crypto.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,SAAS,KAAK,CAAC,GAAgB;IAC7B,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;SACnC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAC3C,IAAI,CAAC,EAAE,CAAC,CAAA;AACb,CAAC;AAED,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,uBAAuB;IAC3C,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAA;IAChC,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;IACxC,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;IACtE,OAAO;QACL,QAAQ,EAAK,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC;QACvC,WAAW,EAAE,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC;KAClC,CAAA;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "fiberprobe",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript SDK for Fiber Network Node (FNN) — typed RPC client, static route estimation, live HTLC-based liquidity probing, inbound capacity checks, and event-driven payment lifecycle.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "typecheck": "tsc --noEmit",
20
+ "lint": "tsc --noEmit"
21
+ },
22
+ "keywords": [
23
+ "fiber",
24
+ "ckb",
25
+ "nervos",
26
+ "fnn",
27
+ "payment-channel",
28
+ "lightning",
29
+ "htlc",
30
+ "typescript",
31
+ "sdk",
32
+ "probing"
33
+ ],
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/Linnnetteseven/fnn-ts.git"
37
+ },
38
+ "homepage": "https://github.com/Linnnetteseven/fnn-ts#readme",
39
+ "bugs": {
40
+ "url": "https://github.com/Linnnetteseven/fnn-ts/issues"
41
+ },
42
+ "author": "Linnette Mugwanja",
43
+ "license": "MIT",
44
+ "devDependencies": {
45
+ "@types/node": "^26.1.1",
46
+ "typescript": "^7.0.2"
47
+ }
48
+ }