@t402/streaming-payments 1.0.0-beta.1

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,867 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Settlement state
5
+ */
6
+ declare const SettlementState: z.ZodEnum<["pending", "in_progress", "challenging", "disputed", "finalizing", "completed", "failed"]>;
7
+ type SettlementState = z.infer<typeof SettlementState>;
8
+ /**
9
+ * Checkpoint type
10
+ */
11
+ declare const CheckpointType: z.ZodEnum<["periodic", "manual", "balance", "pre_close", "dispute"]>;
12
+ type CheckpointType = z.infer<typeof CheckpointType>;
13
+ /**
14
+ * Settlement checkpoint - extends channel checkpoint with settlement data
15
+ */
16
+ declare const SettlementCheckpoint: z.ZodObject<{
17
+ id: z.ZodString;
18
+ channelId: z.ZodString;
19
+ sequence: z.ZodNumber;
20
+ type: z.ZodEnum<["periodic", "manual", "balance", "pre_close", "dispute"]>;
21
+ payerBalance: z.ZodString;
22
+ payeeBalance: z.ZodString;
23
+ totalStreamed: z.ZodString;
24
+ payerSignature: z.ZodString;
25
+ payeeSignature: z.ZodOptional<z.ZodString>;
26
+ stateHash: z.ZodString;
27
+ merkleRoot: z.ZodOptional<z.ZodString>;
28
+ createdAt: z.ZodNumber;
29
+ expiresAt: z.ZodOptional<z.ZodNumber>;
30
+ txHash: z.ZodOptional<z.ZodString>;
31
+ blockNumber: z.ZodOptional<z.ZodNumber>;
32
+ }, "strip", z.ZodTypeAny, {
33
+ type: "balance" | "dispute" | "periodic" | "manual" | "pre_close";
34
+ channelId: string;
35
+ sequence: number;
36
+ payerSignature: string;
37
+ id: string;
38
+ createdAt: number;
39
+ totalStreamed: string;
40
+ payerBalance: string;
41
+ payeeBalance: string;
42
+ stateHash: string;
43
+ payeeSignature?: string | undefined;
44
+ txHash?: string | undefined;
45
+ blockNumber?: number | undefined;
46
+ expiresAt?: number | undefined;
47
+ merkleRoot?: string | undefined;
48
+ }, {
49
+ type: "balance" | "dispute" | "periodic" | "manual" | "pre_close";
50
+ channelId: string;
51
+ sequence: number;
52
+ payerSignature: string;
53
+ id: string;
54
+ createdAt: number;
55
+ totalStreamed: string;
56
+ payerBalance: string;
57
+ payeeBalance: string;
58
+ stateHash: string;
59
+ payeeSignature?: string | undefined;
60
+ txHash?: string | undefined;
61
+ blockNumber?: number | undefined;
62
+ expiresAt?: number | undefined;
63
+ merkleRoot?: string | undefined;
64
+ }>;
65
+ type SettlementCheckpoint = z.infer<typeof SettlementCheckpoint>;
66
+ /**
67
+ * Settlement request
68
+ */
69
+ declare const SettlementRequest: z.ZodObject<{
70
+ channelId: z.ZodString;
71
+ initiator: z.ZodString;
72
+ finalCheckpoint: z.ZodObject<{
73
+ id: z.ZodString;
74
+ channelId: z.ZodString;
75
+ sequence: z.ZodNumber;
76
+ type: z.ZodEnum<["periodic", "manual", "balance", "pre_close", "dispute"]>;
77
+ payerBalance: z.ZodString;
78
+ payeeBalance: z.ZodString;
79
+ totalStreamed: z.ZodString;
80
+ payerSignature: z.ZodString;
81
+ payeeSignature: z.ZodOptional<z.ZodString>;
82
+ stateHash: z.ZodString;
83
+ merkleRoot: z.ZodOptional<z.ZodString>;
84
+ createdAt: z.ZodNumber;
85
+ expiresAt: z.ZodOptional<z.ZodNumber>;
86
+ txHash: z.ZodOptional<z.ZodString>;
87
+ blockNumber: z.ZodOptional<z.ZodNumber>;
88
+ }, "strip", z.ZodTypeAny, {
89
+ type: "balance" | "dispute" | "periodic" | "manual" | "pre_close";
90
+ channelId: string;
91
+ sequence: number;
92
+ payerSignature: string;
93
+ id: string;
94
+ createdAt: number;
95
+ totalStreamed: string;
96
+ payerBalance: string;
97
+ payeeBalance: string;
98
+ stateHash: string;
99
+ payeeSignature?: string | undefined;
100
+ txHash?: string | undefined;
101
+ blockNumber?: number | undefined;
102
+ expiresAt?: number | undefined;
103
+ merkleRoot?: string | undefined;
104
+ }, {
105
+ type: "balance" | "dispute" | "periodic" | "manual" | "pre_close";
106
+ channelId: string;
107
+ sequence: number;
108
+ payerSignature: string;
109
+ id: string;
110
+ createdAt: number;
111
+ totalStreamed: string;
112
+ payerBalance: string;
113
+ payeeBalance: string;
114
+ stateHash: string;
115
+ payeeSignature?: string | undefined;
116
+ txHash?: string | undefined;
117
+ blockNumber?: number | undefined;
118
+ expiresAt?: number | undefined;
119
+ merkleRoot?: string | undefined;
120
+ }>;
121
+ reason: z.ZodEnum<["mutual", "unilateral", "timeout", "dispute_resolution"]>;
122
+ signature: z.ZodString;
123
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
124
+ }, "strip", z.ZodTypeAny, {
125
+ channelId: string;
126
+ initiator: string;
127
+ reason: "mutual" | "unilateral" | "timeout" | "dispute_resolution";
128
+ finalCheckpoint: {
129
+ type: "balance" | "dispute" | "periodic" | "manual" | "pre_close";
130
+ channelId: string;
131
+ sequence: number;
132
+ payerSignature: string;
133
+ id: string;
134
+ createdAt: number;
135
+ totalStreamed: string;
136
+ payerBalance: string;
137
+ payeeBalance: string;
138
+ stateHash: string;
139
+ payeeSignature?: string | undefined;
140
+ txHash?: string | undefined;
141
+ blockNumber?: number | undefined;
142
+ expiresAt?: number | undefined;
143
+ merkleRoot?: string | undefined;
144
+ };
145
+ signature: string;
146
+ metadata?: Record<string, unknown> | undefined;
147
+ }, {
148
+ channelId: string;
149
+ initiator: string;
150
+ reason: "mutual" | "unilateral" | "timeout" | "dispute_resolution";
151
+ finalCheckpoint: {
152
+ type: "balance" | "dispute" | "periodic" | "manual" | "pre_close";
153
+ channelId: string;
154
+ sequence: number;
155
+ payerSignature: string;
156
+ id: string;
157
+ createdAt: number;
158
+ totalStreamed: string;
159
+ payerBalance: string;
160
+ payeeBalance: string;
161
+ stateHash: string;
162
+ payeeSignature?: string | undefined;
163
+ txHash?: string | undefined;
164
+ blockNumber?: number | undefined;
165
+ expiresAt?: number | undefined;
166
+ merkleRoot?: string | undefined;
167
+ };
168
+ signature: string;
169
+ metadata?: Record<string, unknown> | undefined;
170
+ }>;
171
+ type SettlementRequest = z.infer<typeof SettlementRequest>;
172
+ /**
173
+ * Settlement result
174
+ */
175
+ declare const SettlementResult: z.ZodObject<{
176
+ success: z.ZodBoolean;
177
+ settlementId: z.ZodOptional<z.ZodString>;
178
+ error: z.ZodOptional<z.ZodString>;
179
+ finalBalances: z.ZodOptional<z.ZodObject<{
180
+ payer: z.ZodString;
181
+ payee: z.ZodString;
182
+ }, "strip", z.ZodTypeAny, {
183
+ payer: string;
184
+ payee: string;
185
+ }, {
186
+ payer: string;
187
+ payee: string;
188
+ }>>;
189
+ txHash: z.ZodOptional<z.ZodString>;
190
+ timestamp: z.ZodNumber;
191
+ }, "strip", z.ZodTypeAny, {
192
+ timestamp: number;
193
+ success: boolean;
194
+ txHash?: string | undefined;
195
+ error?: string | undefined;
196
+ settlementId?: string | undefined;
197
+ finalBalances?: {
198
+ payer: string;
199
+ payee: string;
200
+ } | undefined;
201
+ }, {
202
+ timestamp: number;
203
+ success: boolean;
204
+ txHash?: string | undefined;
205
+ error?: string | undefined;
206
+ settlementId?: string | undefined;
207
+ finalBalances?: {
208
+ payer: string;
209
+ payee: string;
210
+ } | undefined;
211
+ }>;
212
+ type SettlementResult = z.infer<typeof SettlementResult>;
213
+ /**
214
+ * Dispute reason
215
+ */
216
+ declare const DisputeReason: z.ZodEnum<["invalid_checkpoint", "stale_state", "balance_mismatch", "unauthorized_close", "fraud", "other"]>;
217
+ type DisputeReason = z.infer<typeof DisputeReason>;
218
+ /**
219
+ * Dispute evidence
220
+ */
221
+ declare const DisputeEvidence: z.ZodObject<{
222
+ type: z.ZodEnum<["checkpoint", "signature", "transaction", "state_proof"]>;
223
+ data: z.ZodString;
224
+ description: z.ZodString;
225
+ timestamp: z.ZodNumber;
226
+ verified: z.ZodDefault<z.ZodBoolean>;
227
+ }, "strip", z.ZodTypeAny, {
228
+ type: "signature" | "checkpoint" | "transaction" | "state_proof";
229
+ timestamp: number;
230
+ data: string;
231
+ description: string;
232
+ verified: boolean;
233
+ }, {
234
+ type: "signature" | "checkpoint" | "transaction" | "state_proof";
235
+ timestamp: number;
236
+ data: string;
237
+ description: string;
238
+ verified?: boolean | undefined;
239
+ }>;
240
+ type DisputeEvidence = z.infer<typeof DisputeEvidence>;
241
+ /**
242
+ * Dispute record
243
+ */
244
+ declare const Dispute: z.ZodObject<{
245
+ id: z.ZodString;
246
+ channelId: z.ZodString;
247
+ initiator: z.ZodString;
248
+ respondent: z.ZodString;
249
+ reason: z.ZodEnum<["invalid_checkpoint", "stale_state", "balance_mismatch", "unauthorized_close", "fraud", "other"]>;
250
+ description: z.ZodString;
251
+ claimedPayerBalance: z.ZodString;
252
+ claimedPayeeBalance: z.ZodString;
253
+ claimedCheckpoint: z.ZodOptional<z.ZodObject<{
254
+ id: z.ZodString;
255
+ channelId: z.ZodString;
256
+ sequence: z.ZodNumber;
257
+ type: z.ZodEnum<["periodic", "manual", "balance", "pre_close", "dispute"]>;
258
+ payerBalance: z.ZodString;
259
+ payeeBalance: z.ZodString;
260
+ totalStreamed: z.ZodString;
261
+ payerSignature: z.ZodString;
262
+ payeeSignature: z.ZodOptional<z.ZodString>;
263
+ stateHash: z.ZodString;
264
+ merkleRoot: z.ZodOptional<z.ZodString>;
265
+ createdAt: z.ZodNumber;
266
+ expiresAt: z.ZodOptional<z.ZodNumber>;
267
+ txHash: z.ZodOptional<z.ZodString>;
268
+ blockNumber: z.ZodOptional<z.ZodNumber>;
269
+ }, "strip", z.ZodTypeAny, {
270
+ type: "balance" | "dispute" | "periodic" | "manual" | "pre_close";
271
+ channelId: string;
272
+ sequence: number;
273
+ payerSignature: string;
274
+ id: string;
275
+ createdAt: number;
276
+ totalStreamed: string;
277
+ payerBalance: string;
278
+ payeeBalance: string;
279
+ stateHash: string;
280
+ payeeSignature?: string | undefined;
281
+ txHash?: string | undefined;
282
+ blockNumber?: number | undefined;
283
+ expiresAt?: number | undefined;
284
+ merkleRoot?: string | undefined;
285
+ }, {
286
+ type: "balance" | "dispute" | "periodic" | "manual" | "pre_close";
287
+ channelId: string;
288
+ sequence: number;
289
+ payerSignature: string;
290
+ id: string;
291
+ createdAt: number;
292
+ totalStreamed: string;
293
+ payerBalance: string;
294
+ payeeBalance: string;
295
+ stateHash: string;
296
+ payeeSignature?: string | undefined;
297
+ txHash?: string | undefined;
298
+ blockNumber?: number | undefined;
299
+ expiresAt?: number | undefined;
300
+ merkleRoot?: string | undefined;
301
+ }>>;
302
+ evidence: z.ZodArray<z.ZodObject<{
303
+ type: z.ZodEnum<["checkpoint", "signature", "transaction", "state_proof"]>;
304
+ data: z.ZodString;
305
+ description: z.ZodString;
306
+ timestamp: z.ZodNumber;
307
+ verified: z.ZodDefault<z.ZodBoolean>;
308
+ }, "strip", z.ZodTypeAny, {
309
+ type: "signature" | "checkpoint" | "transaction" | "state_proof";
310
+ timestamp: number;
311
+ data: string;
312
+ description: string;
313
+ verified: boolean;
314
+ }, {
315
+ type: "signature" | "checkpoint" | "transaction" | "state_proof";
316
+ timestamp: number;
317
+ data: string;
318
+ description: string;
319
+ verified?: boolean | undefined;
320
+ }>, "many">;
321
+ responseEvidence: z.ZodOptional<z.ZodArray<z.ZodObject<{
322
+ type: z.ZodEnum<["checkpoint", "signature", "transaction", "state_proof"]>;
323
+ data: z.ZodString;
324
+ description: z.ZodString;
325
+ timestamp: z.ZodNumber;
326
+ verified: z.ZodDefault<z.ZodBoolean>;
327
+ }, "strip", z.ZodTypeAny, {
328
+ type: "signature" | "checkpoint" | "transaction" | "state_proof";
329
+ timestamp: number;
330
+ data: string;
331
+ description: string;
332
+ verified: boolean;
333
+ }, {
334
+ type: "signature" | "checkpoint" | "transaction" | "state_proof";
335
+ timestamp: number;
336
+ data: string;
337
+ description: string;
338
+ verified?: boolean | undefined;
339
+ }>, "many">>;
340
+ status: z.ZodEnum<["pending", "under_review", "resolved", "rejected", "timeout"]>;
341
+ resolution: z.ZodOptional<z.ZodObject<{
342
+ winner: z.ZodOptional<z.ZodString>;
343
+ finalPayerBalance: z.ZodString;
344
+ finalPayeeBalance: z.ZodString;
345
+ reason: z.ZodString;
346
+ timestamp: z.ZodNumber;
347
+ }, "strip", z.ZodTypeAny, {
348
+ timestamp: number;
349
+ reason: string;
350
+ finalPayerBalance: string;
351
+ finalPayeeBalance: string;
352
+ winner?: string | undefined;
353
+ }, {
354
+ timestamp: number;
355
+ reason: string;
356
+ finalPayerBalance: string;
357
+ finalPayeeBalance: string;
358
+ winner?: string | undefined;
359
+ }>>;
360
+ createdAt: z.ZodNumber;
361
+ responseDeadline: z.ZodNumber;
362
+ resolutionDeadline: z.ZodNumber;
363
+ }, "strip", z.ZodTypeAny, {
364
+ status: "timeout" | "pending" | "resolved" | "rejected" | "under_review";
365
+ channelId: string;
366
+ id: string;
367
+ createdAt: number;
368
+ initiator: string;
369
+ reason: "invalid_checkpoint" | "stale_state" | "balance_mismatch" | "unauthorized_close" | "fraud" | "other";
370
+ evidence: {
371
+ type: "signature" | "checkpoint" | "transaction" | "state_proof";
372
+ timestamp: number;
373
+ data: string;
374
+ description: string;
375
+ verified: boolean;
376
+ }[];
377
+ description: string;
378
+ respondent: string;
379
+ claimedPayerBalance: string;
380
+ claimedPayeeBalance: string;
381
+ responseDeadline: number;
382
+ resolutionDeadline: number;
383
+ resolution?: {
384
+ timestamp: number;
385
+ reason: string;
386
+ finalPayerBalance: string;
387
+ finalPayeeBalance: string;
388
+ winner?: string | undefined;
389
+ } | undefined;
390
+ claimedCheckpoint?: {
391
+ type: "balance" | "dispute" | "periodic" | "manual" | "pre_close";
392
+ channelId: string;
393
+ sequence: number;
394
+ payerSignature: string;
395
+ id: string;
396
+ createdAt: number;
397
+ totalStreamed: string;
398
+ payerBalance: string;
399
+ payeeBalance: string;
400
+ stateHash: string;
401
+ payeeSignature?: string | undefined;
402
+ txHash?: string | undefined;
403
+ blockNumber?: number | undefined;
404
+ expiresAt?: number | undefined;
405
+ merkleRoot?: string | undefined;
406
+ } | undefined;
407
+ responseEvidence?: {
408
+ type: "signature" | "checkpoint" | "transaction" | "state_proof";
409
+ timestamp: number;
410
+ data: string;
411
+ description: string;
412
+ verified: boolean;
413
+ }[] | undefined;
414
+ }, {
415
+ status: "timeout" | "pending" | "resolved" | "rejected" | "under_review";
416
+ channelId: string;
417
+ id: string;
418
+ createdAt: number;
419
+ initiator: string;
420
+ reason: "invalid_checkpoint" | "stale_state" | "balance_mismatch" | "unauthorized_close" | "fraud" | "other";
421
+ evidence: {
422
+ type: "signature" | "checkpoint" | "transaction" | "state_proof";
423
+ timestamp: number;
424
+ data: string;
425
+ description: string;
426
+ verified?: boolean | undefined;
427
+ }[];
428
+ description: string;
429
+ respondent: string;
430
+ claimedPayerBalance: string;
431
+ claimedPayeeBalance: string;
432
+ responseDeadline: number;
433
+ resolutionDeadline: number;
434
+ resolution?: {
435
+ timestamp: number;
436
+ reason: string;
437
+ finalPayerBalance: string;
438
+ finalPayeeBalance: string;
439
+ winner?: string | undefined;
440
+ } | undefined;
441
+ claimedCheckpoint?: {
442
+ type: "balance" | "dispute" | "periodic" | "manual" | "pre_close";
443
+ channelId: string;
444
+ sequence: number;
445
+ payerSignature: string;
446
+ id: string;
447
+ createdAt: number;
448
+ totalStreamed: string;
449
+ payerBalance: string;
450
+ payeeBalance: string;
451
+ stateHash: string;
452
+ payeeSignature?: string | undefined;
453
+ txHash?: string | undefined;
454
+ blockNumber?: number | undefined;
455
+ expiresAt?: number | undefined;
456
+ merkleRoot?: string | undefined;
457
+ } | undefined;
458
+ responseEvidence?: {
459
+ type: "signature" | "checkpoint" | "transaction" | "state_proof";
460
+ timestamp: number;
461
+ data: string;
462
+ description: string;
463
+ verified?: boolean | undefined;
464
+ }[] | undefined;
465
+ }>;
466
+ type Dispute = z.infer<typeof Dispute>;
467
+ /**
468
+ * Settlement configuration
469
+ */
470
+ declare const SettlementConfig: z.ZodObject<{
471
+ challengePeriod: z.ZodDefault<z.ZodNumber>;
472
+ disputeResponsePeriod: z.ZodDefault<z.ZodNumber>;
473
+ disputeResolutionPeriod: z.ZodDefault<z.ZodNumber>;
474
+ minCheckpointInterval: z.ZodDefault<z.ZodNumber>;
475
+ maxCheckpointsStored: z.ZodDefault<z.ZodNumber>;
476
+ settlementFee: z.ZodDefault<z.ZodString>;
477
+ disputeBond: z.ZodDefault<z.ZodString>;
478
+ }, "strip", z.ZodTypeAny, {
479
+ challengePeriod: number;
480
+ settlementFee: string;
481
+ disputeResponsePeriod: number;
482
+ disputeResolutionPeriod: number;
483
+ minCheckpointInterval: number;
484
+ maxCheckpointsStored: number;
485
+ disputeBond: string;
486
+ }, {
487
+ challengePeriod?: number | undefined;
488
+ settlementFee?: string | undefined;
489
+ disputeResponsePeriod?: number | undefined;
490
+ disputeResolutionPeriod?: number | undefined;
491
+ minCheckpointInterval?: number | undefined;
492
+ maxCheckpointsStored?: number | undefined;
493
+ disputeBond?: string | undefined;
494
+ }>;
495
+ type SettlementConfig = z.infer<typeof SettlementConfig>;
496
+ /**
497
+ * On-chain settlement data
498
+ */
499
+ declare const OnChainSettlement: z.ZodObject<{
500
+ channelId: z.ZodString;
501
+ settlementId: z.ZodString;
502
+ txHash: z.ZodString;
503
+ blockNumber: z.ZodNumber;
504
+ payerReceived: z.ZodString;
505
+ payeeReceived: z.ZodString;
506
+ fee: z.ZodString;
507
+ timestamp: z.ZodNumber;
508
+ finalized: z.ZodBoolean;
509
+ }, "strip", z.ZodTypeAny, {
510
+ channelId: string;
511
+ timestamp: number;
512
+ txHash: string;
513
+ blockNumber: number;
514
+ settlementId: string;
515
+ payerReceived: string;
516
+ payeeReceived: string;
517
+ fee: string;
518
+ finalized: boolean;
519
+ }, {
520
+ channelId: string;
521
+ timestamp: number;
522
+ txHash: string;
523
+ blockNumber: number;
524
+ settlementId: string;
525
+ payerReceived: string;
526
+ payeeReceived: string;
527
+ fee: string;
528
+ finalized: boolean;
529
+ }>;
530
+ type OnChainSettlement = z.infer<typeof OnChainSettlement>;
531
+
532
+ /**
533
+ * Checkpoint manager configuration
534
+ */
535
+ interface CheckpointManagerConfig {
536
+ autoCheckpoint?: boolean;
537
+ intervalSeconds?: number;
538
+ balanceThreshold?: string;
539
+ onCheckpoint?: (checkpoint: SettlementCheckpoint) => void;
540
+ }
541
+ /**
542
+ * Checkpoint creation request
543
+ */
544
+ interface CheckpointRequest {
545
+ channelId: string;
546
+ sequence: number;
547
+ payerBalance: string;
548
+ payeeBalance: string;
549
+ totalStreamed: string;
550
+ type?: CheckpointType;
551
+ payerSignature: string;
552
+ payeeSignature?: string;
553
+ }
554
+ /**
555
+ * Checkpoint manager for creating and validating checkpoints
556
+ */
557
+ declare class CheckpointManager {
558
+ private checkpoints;
559
+ private config;
560
+ private settlementConfig;
561
+ private lastCheckpointTime;
562
+ constructor(settlementConfig: SettlementConfig, config?: CheckpointManagerConfig);
563
+ /**
564
+ * Create a new checkpoint
565
+ */
566
+ create(request: CheckpointRequest): SettlementCheckpoint;
567
+ /**
568
+ * Get latest checkpoint for channel
569
+ */
570
+ getLatest(channelId: string): SettlementCheckpoint | undefined;
571
+ /**
572
+ * Get checkpoint by sequence
573
+ */
574
+ getBySequence(channelId: string, sequence: number): SettlementCheckpoint | undefined;
575
+ /**
576
+ * Get all checkpoints for channel
577
+ */
578
+ getAll(channelId: string): SettlementCheckpoint[];
579
+ /**
580
+ * Validate checkpoint
581
+ */
582
+ validate(checkpoint: SettlementCheckpoint): {
583
+ valid: boolean;
584
+ errors: string[];
585
+ };
586
+ /**
587
+ * Compare two checkpoints
588
+ */
589
+ compare(a: SettlementCheckpoint, b: SettlementCheckpoint): {
590
+ isNewer: boolean;
591
+ balanceDifference: {
592
+ payer: string;
593
+ payee: string;
594
+ };
595
+ };
596
+ /**
597
+ * Check if checkpoint is needed
598
+ */
599
+ needsCheckpoint(channelId: string, currentPayeeBalance: string): {
600
+ needed: boolean;
601
+ reason: string;
602
+ };
603
+ /**
604
+ * Build merkle root from checkpoint history
605
+ */
606
+ buildMerkleRoot(channelId: string): string;
607
+ /**
608
+ * Verify checkpoint is in merkle tree
609
+ */
610
+ verifyMerkleProof(checkpoint: SettlementCheckpoint, merkleRoot: string, _proof: string[]): boolean;
611
+ /**
612
+ * Export checkpoints for backup
613
+ */
614
+ export(channelId: string): string;
615
+ /**
616
+ * Import checkpoints from backup
617
+ */
618
+ import(data: string): {
619
+ success: boolean;
620
+ imported: number;
621
+ };
622
+ /**
623
+ * Clear checkpoints for channel
624
+ */
625
+ clear(channelId: string): void;
626
+ private generateCheckpointId;
627
+ private generateStateHash;
628
+ private hashArray;
629
+ private pruneCheckpoints;
630
+ }
631
+ /**
632
+ * Sign checkpoint data
633
+ */
634
+ declare function signCheckpoint(checkpoint: SettlementCheckpoint, _privateKey: string): string;
635
+ /**
636
+ * Verify checkpoint signature
637
+ */
638
+ declare function verifyCheckpointSignature(_checkpoint: SettlementCheckpoint, signature: string, _publicKey: string): boolean;
639
+
640
+ /**
641
+ * Final settlement manager configuration
642
+ */
643
+ interface FinalSettlementConfig {
644
+ autoFinalize?: boolean;
645
+ retryAttempts?: number;
646
+ retryDelayMs?: number;
647
+ }
648
+ /**
649
+ * Settlement status
650
+ */
651
+ interface SettlementStatus {
652
+ state: SettlementState;
653
+ channelId: string;
654
+ initiator: string;
655
+ checkpoint: SettlementCheckpoint;
656
+ challengeDeadline: number;
657
+ finalizedAt?: number;
658
+ txHash?: string;
659
+ error?: string;
660
+ }
661
+ /**
662
+ * Final settlement manager
663
+ */
664
+ declare class FinalSettlementManager {
665
+ private settlements;
666
+ private checkpointManager;
667
+ private settlementConfig;
668
+ private onChainSettlements;
669
+ constructor(checkpointManager: CheckpointManager, settlementConfig: SettlementConfig, _config?: FinalSettlementConfig);
670
+ /**
671
+ * Initiate settlement
672
+ */
673
+ initiate(request: SettlementRequest): SettlementResult;
674
+ /**
675
+ * Process mutual settlement (both parties agree)
676
+ */
677
+ processMutual(channelId: string, payerSignature: string, payeeSignature: string, finalCheckpoint: SettlementCheckpoint): SettlementResult;
678
+ /**
679
+ * Check if challenge period has elapsed
680
+ */
681
+ canFinalize(channelId: string): {
682
+ canFinalize: boolean;
683
+ timeRemaining: number;
684
+ };
685
+ /**
686
+ * Finalize settlement after challenge period
687
+ */
688
+ finalize(channelId: string): SettlementResult;
689
+ /**
690
+ * Get settlement status
691
+ */
692
+ getStatus(channelId: string): SettlementStatus | undefined;
693
+ /**
694
+ * Get on-chain settlement
695
+ */
696
+ getOnChainSettlement(channelId: string): OnChainSettlement | undefined;
697
+ /**
698
+ * Cancel pending settlement (before challenge period ends)
699
+ */
700
+ cancel(channelId: string, canceller: string, reason: string): {
701
+ success: boolean;
702
+ error?: string;
703
+ };
704
+ /**
705
+ * Calculate settlement amounts
706
+ */
707
+ calculateSettlementAmounts(checkpoint: SettlementCheckpoint): {
708
+ payerReceives: string;
709
+ payeeReceives: string;
710
+ fee: string;
711
+ total: string;
712
+ };
713
+ /**
714
+ * Build settlement transaction data
715
+ */
716
+ buildSettlementTransaction(channelId: string): {
717
+ to: string;
718
+ data: string;
719
+ value: string;
720
+ } | null;
721
+ private validateRequest;
722
+ private transitionState;
723
+ private generateSettlementId;
724
+ private generateMockTxHash;
725
+ }
726
+ /**
727
+ * Estimate settlement gas cost
728
+ */
729
+ declare function estimateSettlementGas(hasDispute: boolean, checkpointCount: number): string;
730
+ /**
731
+ * Verify settlement transaction on-chain
732
+ */
733
+ declare function verifySettlementOnChain(settlement: OnChainSettlement): {
734
+ verified: boolean;
735
+ error?: string;
736
+ };
737
+
738
+ /**
739
+ * Dispute manager configuration
740
+ */
741
+ interface DisputeManagerConfig {
742
+ requireBond?: boolean;
743
+ autoResolve?: boolean;
744
+ notifyParties?: (dispute: Dispute, event: string) => void;
745
+ }
746
+ /**
747
+ * Dispute creation request
748
+ */
749
+ interface DisputeRequest {
750
+ channelId: string;
751
+ initiator: string;
752
+ respondent: string;
753
+ reason: DisputeReason;
754
+ description: string;
755
+ claimedPayerBalance: string;
756
+ claimedPayeeBalance: string;
757
+ claimedCheckpoint?: SettlementCheckpoint;
758
+ evidence: DisputeEvidence[];
759
+ bond?: string;
760
+ }
761
+ /**
762
+ * Dispute response
763
+ */
764
+ interface DisputeResponse {
765
+ disputeId: string;
766
+ responder: string;
767
+ counterClaim?: {
768
+ payerBalance: string;
769
+ payeeBalance: string;
770
+ };
771
+ evidence: DisputeEvidence[];
772
+ signature: string;
773
+ }
774
+ /**
775
+ * Dispute manager for handling payment disputes
776
+ */
777
+ declare class DisputeManager {
778
+ private disputes;
779
+ private config;
780
+ private settlementConfig;
781
+ private checkpointManager;
782
+ constructor(checkpointManager: CheckpointManager, settlementConfig: SettlementConfig, config?: DisputeManagerConfig);
783
+ /**
784
+ * Raise a dispute
785
+ */
786
+ raise(request: DisputeRequest): {
787
+ success: boolean;
788
+ dispute?: Dispute;
789
+ error?: string;
790
+ };
791
+ /**
792
+ * Respond to a dispute
793
+ */
794
+ respond(response: DisputeResponse): {
795
+ success: boolean;
796
+ error?: string;
797
+ };
798
+ /**
799
+ * Resolve a dispute
800
+ */
801
+ resolve(disputeId: string, winner: string, finalPayerBalance: string, finalPayeeBalance: string, reason: string): {
802
+ success: boolean;
803
+ error?: string;
804
+ };
805
+ /**
806
+ * Reject a dispute
807
+ */
808
+ reject(disputeId: string, reason: string): {
809
+ success: boolean;
810
+ error?: string;
811
+ };
812
+ /**
813
+ * Handle timeout (no response)
814
+ */
815
+ handleTimeout(disputeId: string): {
816
+ success: boolean;
817
+ resolution?: Dispute['resolution'];
818
+ };
819
+ /**
820
+ * Get dispute by ID
821
+ */
822
+ get(disputeId: string): Dispute | undefined;
823
+ /**
824
+ * Get dispute by channel ID
825
+ */
826
+ getByChannel(channelId: string): Dispute | undefined;
827
+ /**
828
+ * Get all disputes
829
+ */
830
+ getAll(): Dispute[];
831
+ /**
832
+ * Get disputes by status
833
+ */
834
+ getByStatus(status: Dispute['status']): Dispute[];
835
+ /**
836
+ * Add evidence to existing dispute
837
+ */
838
+ addEvidence(disputeId: string, party: string, evidence: DisputeEvidence): {
839
+ success: boolean;
840
+ error?: string;
841
+ };
842
+ /**
843
+ * Evaluate dispute based on evidence
844
+ */
845
+ evaluateEvidence(disputeId: string): {
846
+ initiatorScore: number;
847
+ respondentScore: number;
848
+ recommendation: string;
849
+ };
850
+ private validateRequest;
851
+ private getEvidenceWeight;
852
+ private generateDisputeId;
853
+ }
854
+ /**
855
+ * Create evidence from checkpoint
856
+ */
857
+ declare function createCheckpointEvidence(checkpoint: SettlementCheckpoint, description: string): DisputeEvidence;
858
+ /**
859
+ * Create evidence from signature
860
+ */
861
+ declare function createSignatureEvidence(signature: string, signedData: string, description: string): DisputeEvidence;
862
+ /**
863
+ * Create evidence from transaction
864
+ */
865
+ declare function createTransactionEvidence(txHash: string, description: string): DisputeEvidence;
866
+
867
+ export { CheckpointManager, type CheckpointManagerConfig, type CheckpointRequest, CheckpointType, Dispute, DisputeEvidence, DisputeManager, type DisputeManagerConfig, DisputeReason, type DisputeRequest, type DisputeResponse, type FinalSettlementConfig, FinalSettlementManager, OnChainSettlement, SettlementCheckpoint, SettlementConfig, SettlementRequest, SettlementResult, SettlementState, type SettlementStatus, createCheckpointEvidence, createSignatureEvidence, createTransactionEvidence, estimateSettlementGas, signCheckpoint, verifyCheckpointSignature, verifySettlementOnChain };