-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
214 lines (212 loc) · 7.57 KB
/
index.d.ts
File metadata and controls
214 lines (212 loc) · 7.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/* tslint:disable */
/* eslint-disable */
/* auto-generated by NAPI-RS */
export declare function setLogListener(
callback?: (...args: any[]) => any | undefined | null,
minLevel?: string | undefined | null,
): void
export declare function generateMnemonic(): string
/**
* Derive the node public key from a mnemonic and network without building the full node.
* This replicates the exact derivation path used in `build_with_store_internal()`:
* mnemonic -> BIP39 seed -> BIP32 master xprv -> 32-byte secret -> KeysManager -> node_id
* Runs in ~1ms vs ~4s for full node construction.
*/
export declare function deriveNodeId(mnemonicStr: string, networkStr: string): string
export interface ScoringParamOverrides {
basePenaltyMsat?: number
basePenaltyAmountMultiplierMsat?: number
liquidityPenaltyMultiplierMsat?: number
liquidityPenaltyAmountMultiplierMsat?: number
historicalLiquidityPenaltyMultiplierMsat?: number
historicalLiquidityPenaltyAmountMultiplierMsat?: number
antiProbingPenaltyMsat?: number
consideredImpossiblePenaltyMsat?: number
linearSuccessProbability?: boolean
probingDiversityPenaltyMsat?: number
liquidityOffsetHalfLifeSecs?: number
historicalNoUpdatesHalfLifeSecs?: number
manualNodePenalties?: Record<string, number>
}
export interface MdkNodeOptions {
network: string
mdkApiKey: string
vssUrl: string
esploraUrl: string
rgsUrl: string
mnemonic: string
lspNodeId: string
lspAddress: string
scoringParamOverrides?: ScoringParamOverrides
}
export interface PaymentMetadata {
bolt11: string
paymentHash: string
expiresAt: number
scid: string
}
export interface ReceivedPayment {
paymentHash: string
amount: number
}
/** Result of a successful outbound payment. */
export interface PaymentResult {
/** Opaque payment identifier. Always present - can be used to correlate async BOLT12 payments. */
paymentId: string
/**
* The payment hash from the invoice/offer (identifies the HTLC).
* Available immediately for BOLT11; populated from the PaymentSuccessful event for BOLT12.
*/
paymentHash?: string
/** The payment preimage (proof of payment). Available after the payment succeeds. */
preimage?: string
}
export interface PaymentEvent {
eventType: PaymentEventType
paymentHash: string
amountMsat?: number
reason?: string
payerNote?: string
/** Opaque payment identifier. Present for Sent and Failed (outbound) events. */
paymentId?: string
/** Payment preimage (proof of payment). Present for Sent events. */
preimage?: string
}
export const enum PaymentEventType {
Claimable = 0,
Received = 1,
Failed = 2,
Sent = 3
}
export interface NodeChannel {
channelId: string
counterpartyNodeId: string
shortChannelId?: string
inboundCapacityMsat: number
outboundCapacityMsat: number
isChannelReady: boolean
isUsable: boolean
isPublic: boolean
}
export declare class MdkNode {
constructor(options: MdkNodeOptions)
/**
* Destroy the node, dropping the inner Rust Node and its tokio runtime immediately.
* This prevents zombie processes on serverless platforms where GC is non-deterministic.
* After calling destroy(), any further method calls on this node will panic.
*
* Always disconnects all peers first to close TCP connections. This is critical on
* serverless platforms (e.g., Vercel) where the execution context may freeze after the
* handler returns — a lingering TCP connection tricks the LSP into thinking the peer
* is still reachable, causing it to forward HTLCs directly instead of intercepting
* them and sending a webhook.
*/
destroy(): void
getNodeId(): string
start(): void
stop(): void
/** Start the node and sync wallets. Call once before polling for events. */
startReceiving(): void
/**
* Get the next payment event without ACKing it.
* Returns None if no events are available.
* Call ack_event() after successfully handling the event.
*/
nextEvent(): PaymentEvent | null
/**
* ACK the current event after successfully handling it.
* Must be called after next_event() returns an event, before calling next_event() again.
*/
ackEvent(): void
/** Stop the node. Call when done polling. */
stopReceiving(): void
syncWallets(): void
getBalance(): number
/**
* Get balance without starting/stopping the node.
* Use this when the node is already running via start_receiving().
*/
getBalanceWhileRunning(): number
listChannels(): Array<NodeChannel>
/**
* Manually sync the RGS snapshot.
*
* If `do_full_sync` is true, the RGS snapshot will be updated from scratch. Otherwise, the
* snapshot will be updated from the last known sync point.
*/
syncRgs(doFullSync: boolean): number
receivePayment(minThresholdMs: number, quietThresholdMs: number): Array<ReceivedPayment>
getInvoice(amount: number, description: string, expirySecs: number): PaymentMetadata
/**
* Get invoice without starting/stopping the node.
* Use this when the node is already running via start_receiving().
*/
getInvoiceWhileRunning(amount: number, description: string, expirySecs: number): PaymentMetadata
/**
* Get variable amount invoice without starting/stopping the node.
* Use this when the node is already running via start_receiving().
*/
getVariableAmountJitInvoiceWhileRunning(description: string, expirySecs: number): PaymentMetadata
getInvoiceWithScid(
humanReadableScid: string,
amount: number,
description: string,
expirySecs: number,
): PaymentMetadata
getVariableAmountJitInvoice(description: string, expirySecs: number): PaymentMetadata
getVariableAmountJitInvoiceWithScid(
humanReadableScid: string,
description: string,
expirySecs: number,
): PaymentMetadata
/**
* Get a BOLT12 offer for receiving via LSPS4 JIT channel.
* Use this when the node is already running via start_receiving().
*/
getBolt12OfferWhileRunning(amount: number, description: string, expirySecs?: number | undefined | null): string
/**
* Get a variable amount BOLT12 offer for receiving via LSPS4 JIT channel.
* Use this when the node is already running via start_receiving().
*/
getVariableAmountBolt12OfferWhileRunning(description: string, expirySecs?: number | undefined | null): string
/**
* Register LSPS4 and sync gossip for BOLT12 receive.
* Call this on startup if you want to accept payments for existing offers.
*/
setupBolt12Receive(): void
/**
* Unified payment method that auto-detects the destination type.
*
* Only supports variable-amount destinations where we set the amount:
* - BOLT12 offers (lno...)
* - LNURL (lnurl...)
* - Lightning addresses (user@domain)
* - Zero-amount BOLT11 invoices
*
* For fixed-amount BOLT11 invoices, amount_msat can be omitted (the invoice amount is used).
* For variable-amount destinations, amount_msat is required.
*/
pay(
destination: string,
amountMsat?: number | undefined | null,
waitForPaymentSecs?: number | undefined | null,
): PaymentResult
/**
* Unified payment method that auto-detects the destination type.
* Use this when the node is already running via start_receiving().
*
* Supports all destination types:
* - BOLT11 invoices (fixed or variable amount)
* - BOLT12 offers (lno...)
* - LNURL (lnurl...)
* - Lightning addresses (user@domain)
*
* For fixed-amount BOLT11 invoices, amount_msat can be omitted (the invoice amount is used).
* For variable-amount destinations, amount_msat is required.
*/
payWhileRunning(
destination: string,
amountMsat?: number | undefined | null,
waitForPaymentSecs?: number | undefined | null,
): PaymentResult
}