@routstr/sdk 0.3.5 → 0.3.7
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.
- package/package.json +2 -2
- package/dist/client/index.d.mts +0 -411
- package/dist/client/index.d.ts +0 -411
- package/dist/client/index.js +0 -4819
- package/dist/client/index.js.map +0 -1
- package/dist/client/index.mjs +0 -4813
- package/dist/client/index.mjs.map +0 -1
- package/dist/discovery/index.d.mts +0 -196
- package/dist/discovery/index.d.ts +0 -196
- package/dist/discovery/index.js +0 -616
- package/dist/discovery/index.js.map +0 -1
- package/dist/discovery/index.mjs +0 -613
- package/dist/discovery/index.mjs.map +0 -1
- package/dist/index.d.mts +0 -190
- package/dist/index.d.ts +0 -190
- package/dist/index.js +0 -6114
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -6065
- package/dist/index.mjs.map +0 -1
- package/dist/interfaces-Bp0Ngmqv.d.mts +0 -176
- package/dist/interfaces-CIfd_phZ.d.ts +0 -112
- package/dist/interfaces-Cxi8R4TT.d.mts +0 -112
- package/dist/interfaces-D2FDCLyP.d.ts +0 -176
- package/dist/storage/index.d.mts +0 -87
- package/dist/storage/index.d.ts +0 -87
- package/dist/storage/index.js +0 -1734
- package/dist/storage/index.js.map +0 -1
- package/dist/storage/index.mjs +0 -1712
- package/dist/storage/index.mjs.map +0 -1
- package/dist/store-BD5zF9Hp.d.ts +0 -172
- package/dist/store-CBSyK2qg.d.mts +0 -172
- package/dist/types-DPQM6tIG.d.mts +0 -234
- package/dist/types-DPQM6tIG.d.ts +0 -234
- package/dist/wallet/index.d.mts +0 -245
- package/dist/wallet/index.d.ts +0 -245
- package/dist/wallet/index.js +0 -1329
- package/dist/wallet/index.js.map +0 -1
- package/dist/wallet/index.mjs +0 -1326
- package/dist/wallet/index.mjs.map +0 -1
package/dist/wallet/index.d.mts
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import { W as WalletAdapter, S as StorageAdapter, P as ProviderRegistry } from '../interfaces-Bp0Ngmqv.mjs';
|
|
2
|
-
export { A as ApiKeyEntry, C as ChildKeyEntry, R as RoutstrClientOptions, a as StreamingCallbacks, X as XCashuTokenEntry } from '../interfaces-Bp0Ngmqv.mjs';
|
|
3
|
-
import { S as SdkLogger, R as RefundResult, n as TopUpResult, l as SpendResult } from '../types-DPQM6tIG.mjs';
|
|
4
|
-
export { P as ProviderInfo } from '../types-DPQM6tIG.mjs';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* BalanceManager - Handles refunding and topping up tokens from providers
|
|
8
|
-
*
|
|
9
|
-
* Handles:
|
|
10
|
-
* - Fetching refund tokens from provider API
|
|
11
|
-
* - Receiving/storing refunded tokens
|
|
12
|
-
* - Topping up API key balances with cashu tokens
|
|
13
|
-
* - Error handling for various refund/topup failure modes
|
|
14
|
-
*
|
|
15
|
-
* Extracted from utils/cashuUtils.ts
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Options for refunding API key balance
|
|
20
|
-
*/
|
|
21
|
-
interface RefundApiKeyOptions {
|
|
22
|
-
/** The mint URL (for NIP-60 wallet operations) */
|
|
23
|
-
mintUrl: string;
|
|
24
|
-
/** The provider base URL */
|
|
25
|
-
baseUrl: string;
|
|
26
|
-
/** The API key to use for authentication */
|
|
27
|
-
apiKey: string;
|
|
28
|
-
/** If true, forces refund even if the API key was used recently */
|
|
29
|
-
forceRefund?: boolean;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Options for topping up API key balance
|
|
33
|
-
*/
|
|
34
|
-
interface TopUpOptions {
|
|
35
|
-
/** The mint URL to spend from */
|
|
36
|
-
mintUrl: string;
|
|
37
|
-
/** The provider base URL */
|
|
38
|
-
baseUrl: string;
|
|
39
|
-
/** Amount to top up in sats */
|
|
40
|
-
amount: number;
|
|
41
|
-
/** Optional specific API key to top up (if not provided, uses stored token) */
|
|
42
|
-
token?: string;
|
|
43
|
-
}
|
|
44
|
-
interface CreateProviderTokenOptions {
|
|
45
|
-
mintUrl: string;
|
|
46
|
-
baseUrl: string;
|
|
47
|
-
amount: number;
|
|
48
|
-
p2pkPubkey?: string;
|
|
49
|
-
excludeMints?: string[];
|
|
50
|
-
retryCount?: number;
|
|
51
|
-
}
|
|
52
|
-
interface ProviderTokenResult {
|
|
53
|
-
success: boolean;
|
|
54
|
-
token?: string;
|
|
55
|
-
error?: string;
|
|
56
|
-
selectedMintUrl?: string;
|
|
57
|
-
amountSpent?: number;
|
|
58
|
-
}
|
|
59
|
-
interface BalanceState {
|
|
60
|
-
totalBalance: number;
|
|
61
|
-
providerBalances: Record<string, number>;
|
|
62
|
-
mintBalances: Record<string, number>;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* BalanceManager handles token refunds and topups from providers
|
|
66
|
-
*/
|
|
67
|
-
declare class BalanceManager {
|
|
68
|
-
private walletAdapter;
|
|
69
|
-
private storageAdapter;
|
|
70
|
-
private providerRegistry?;
|
|
71
|
-
private cashuSpender;
|
|
72
|
-
/** In-memory guard for per-provider wallet mutations (topup / refund) */
|
|
73
|
-
private providerWalletOps;
|
|
74
|
-
/** Cooldown (ms) between opposite operations on the same provider */
|
|
75
|
-
private static readonly PROVIDER_WALLET_COOLDOWN_MS;
|
|
76
|
-
private readonly logger;
|
|
77
|
-
constructor(walletAdapter: WalletAdapter, storageAdapter: StorageAdapter, providerRegistry?: ProviderRegistry | undefined, cashuSpender?: CashuSpender, logger?: SdkLogger);
|
|
78
|
-
/**
|
|
79
|
-
* Check whether a wallet operation (topup/refund) may run for a provider.
|
|
80
|
-
* Returns the reason when blocked.
|
|
81
|
-
*/
|
|
82
|
-
private _canRunProviderWalletOperation;
|
|
83
|
-
private _beginProviderWalletOperation;
|
|
84
|
-
private _endProviderWalletOperation;
|
|
85
|
-
getBalanceState(): Promise<BalanceState>;
|
|
86
|
-
/**
|
|
87
|
-
* Refund API key balance - convert remaining API key balance to cashu token
|
|
88
|
-
* @param options - Refund options including forceRefund flag
|
|
89
|
-
* @returns Refund result
|
|
90
|
-
*/
|
|
91
|
-
refundApiKey(options: RefundApiKeyOptions): Promise<RefundResult>;
|
|
92
|
-
private _refundApiKeyImpl;
|
|
93
|
-
/**
|
|
94
|
-
* Fetch refund token from provider API using API key (or xcashu token) authentication
|
|
95
|
-
*/
|
|
96
|
-
fetchRefundToken(baseUrl: string, apiKeyOrToken: string, xCashu?: boolean): Promise<{
|
|
97
|
-
success: boolean;
|
|
98
|
-
token?: string;
|
|
99
|
-
requestId?: string;
|
|
100
|
-
error?: string;
|
|
101
|
-
}>;
|
|
102
|
-
/**
|
|
103
|
-
* Top up API key balance with a cashu token
|
|
104
|
-
*/
|
|
105
|
-
topUp(options: TopUpOptions): Promise<TopUpResult>;
|
|
106
|
-
private _topUpImpl;
|
|
107
|
-
createProviderToken(options: CreateProviderTokenOptions): Promise<ProviderTokenResult>;
|
|
108
|
-
private _selectCandidateMints;
|
|
109
|
-
private _refundOtherProvidersForTopUp;
|
|
110
|
-
/**
|
|
111
|
-
* Post topup request to provider API
|
|
112
|
-
*/
|
|
113
|
-
private _postTopUp;
|
|
114
|
-
/**
|
|
115
|
-
* Attempt to receive token back after failed top up
|
|
116
|
-
*/
|
|
117
|
-
private _recoverFailedTopUp;
|
|
118
|
-
/**
|
|
119
|
-
* Handle refund errors with specific error types
|
|
120
|
-
*/
|
|
121
|
-
private _handleRefundError;
|
|
122
|
-
/**
|
|
123
|
-
* Get token balance from provider
|
|
124
|
-
*/
|
|
125
|
-
getTokenBalance(token: string, baseUrl: string): Promise<{
|
|
126
|
-
amount: number;
|
|
127
|
-
reserved: number;
|
|
128
|
-
unit: "sat" | "msat";
|
|
129
|
-
apiKey: string;
|
|
130
|
-
isInvalidApiKey?: boolean;
|
|
131
|
-
}>;
|
|
132
|
-
/**
|
|
133
|
-
* Handle topup errors with specific error types
|
|
134
|
-
*/
|
|
135
|
-
private _handleTopUpError;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* CashuSpender - Core spending logic for Cashu tokens
|
|
140
|
-
*
|
|
141
|
-
* Handles:
|
|
142
|
-
* - Mint selection with sufficient balance
|
|
143
|
-
* - Provider mint compatibility checks
|
|
144
|
-
* - Retry logic with alternate mints
|
|
145
|
-
* - Critical section management (busy state)
|
|
146
|
-
*
|
|
147
|
-
* Extracted from hooks/useCashuWithXYZ.ts
|
|
148
|
-
*/
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Options for spending cashu tokens
|
|
152
|
-
*/
|
|
153
|
-
interface SpendOptions {
|
|
154
|
-
/** The mint URL to send from (can be overridden if insufficient balance) */
|
|
155
|
-
mintUrl: string;
|
|
156
|
-
/** The amount to spend in sats */
|
|
157
|
-
amount: number;
|
|
158
|
-
/** The provider base URL (for token storage and provider mint checks) */
|
|
159
|
-
baseUrl: string;
|
|
160
|
-
/** Whether to reuse an existing token if available */
|
|
161
|
-
reuseToken?: boolean;
|
|
162
|
-
/** Optional P2PK public key */
|
|
163
|
-
p2pkPubkey?: string;
|
|
164
|
-
/** Array of mint URLs to exclude (for retry logic) */
|
|
165
|
-
excludeMints?: string[];
|
|
166
|
-
/** Current retry count (for internal recursion) */
|
|
167
|
-
retryCount?: number;
|
|
168
|
-
/** Specific provider baseUrls to refund (if not provided, refunds all except current) */
|
|
169
|
-
refundBaseUrls?: string[];
|
|
170
|
-
}
|
|
171
|
-
type DebugLevel = "DEBUG" | "WARN" | "ERROR";
|
|
172
|
-
/**
|
|
173
|
-
* CashuSpender manages the spending of Cashu tokens
|
|
174
|
-
*/
|
|
175
|
-
declare class CashuSpender {
|
|
176
|
-
private walletAdapter;
|
|
177
|
-
private storageAdapter;
|
|
178
|
-
private _providerRegistry?;
|
|
179
|
-
private balanceManager?;
|
|
180
|
-
private _isBusy;
|
|
181
|
-
private debugLevel;
|
|
182
|
-
private readonly logger;
|
|
183
|
-
constructor(walletAdapter: WalletAdapter, storageAdapter: StorageAdapter, _providerRegistry?: unknown | undefined, balanceManager?: BalanceManager | undefined, logger?: SdkLogger);
|
|
184
|
-
receiveToken(token: string): Promise<{
|
|
185
|
-
success: boolean;
|
|
186
|
-
amount: number;
|
|
187
|
-
unit: "sat" | "msat";
|
|
188
|
-
message?: string;
|
|
189
|
-
}>;
|
|
190
|
-
private _decodeTokenAmount;
|
|
191
|
-
private _getBalanceState;
|
|
192
|
-
private _logTransaction;
|
|
193
|
-
/**
|
|
194
|
-
* Check if the spender is currently in a critical operation
|
|
195
|
-
*/
|
|
196
|
-
get isBusy(): boolean;
|
|
197
|
-
getDebugLevel(): DebugLevel;
|
|
198
|
-
setDebugLevel(level: DebugLevel): void;
|
|
199
|
-
private _log;
|
|
200
|
-
/**
|
|
201
|
-
* Spend Cashu tokens with automatic mint selection and retry logic
|
|
202
|
-
* Throws errors on failure instead of returning failed SpendResult
|
|
203
|
-
*/
|
|
204
|
-
spend(options: SpendOptions): Promise<SpendResult>;
|
|
205
|
-
/**
|
|
206
|
-
* Check if error message indicates a network error
|
|
207
|
-
*/
|
|
208
|
-
private _isNetworkError;
|
|
209
|
-
/**
|
|
210
|
-
* Internal spending logic
|
|
211
|
-
*/
|
|
212
|
-
private _spendInternal;
|
|
213
|
-
/**
|
|
214
|
-
* Try to reuse an existing API key
|
|
215
|
-
*/
|
|
216
|
-
private _tryReuseToken;
|
|
217
|
-
/**
|
|
218
|
-
* Refund all xcashu tokens from storage by calling the provider's refund endpoint.
|
|
219
|
-
* The xcashu token acts as an API key to claim the refund, and the response contains
|
|
220
|
-
* the actual refunded Cashu token which is then received into the wallet.
|
|
221
|
-
* @param mintUrl - The mint URL for receiving tokens
|
|
222
|
-
* @param excludeBaseUrls - Base URLs to exclude from refund (optional)
|
|
223
|
-
* @returns Results for each xcashu token refund attempt
|
|
224
|
-
*/
|
|
225
|
-
refundXcashuTokens(mintUrl: string, excludeBaseUrls?: string[]): Promise<{
|
|
226
|
-
baseUrl: string;
|
|
227
|
-
token: string;
|
|
228
|
-
success: boolean;
|
|
229
|
-
error?: string;
|
|
230
|
-
}[]>;
|
|
231
|
-
/**
|
|
232
|
-
* Refund specific providers without retrying spend
|
|
233
|
-
*/
|
|
234
|
-
refundProviders(mintUrl: string, forceRefund?: boolean): Promise<{
|
|
235
|
-
baseUrl: string;
|
|
236
|
-
success: boolean;
|
|
237
|
-
}[]>;
|
|
238
|
-
/**
|
|
239
|
-
* Create an insufficient balance error result
|
|
240
|
-
*/
|
|
241
|
-
private _createInsufficientBalanceError;
|
|
242
|
-
private _getProviderTokenBalance;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
export { BalanceManager, type BalanceState, CashuSpender, type CreateProviderTokenOptions, ProviderRegistry, type ProviderTokenResult, type RefundApiKeyOptions, type SpendOptions, StorageAdapter, type TopUpOptions, WalletAdapter };
|
package/dist/wallet/index.d.ts
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import { W as WalletAdapter, S as StorageAdapter, P as ProviderRegistry } from '../interfaces-D2FDCLyP.js';
|
|
2
|
-
export { A as ApiKeyEntry, C as ChildKeyEntry, R as RoutstrClientOptions, a as StreamingCallbacks, X as XCashuTokenEntry } from '../interfaces-D2FDCLyP.js';
|
|
3
|
-
import { S as SdkLogger, R as RefundResult, n as TopUpResult, l as SpendResult } from '../types-DPQM6tIG.js';
|
|
4
|
-
export { P as ProviderInfo } from '../types-DPQM6tIG.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* BalanceManager - Handles refunding and topping up tokens from providers
|
|
8
|
-
*
|
|
9
|
-
* Handles:
|
|
10
|
-
* - Fetching refund tokens from provider API
|
|
11
|
-
* - Receiving/storing refunded tokens
|
|
12
|
-
* - Topping up API key balances with cashu tokens
|
|
13
|
-
* - Error handling for various refund/topup failure modes
|
|
14
|
-
*
|
|
15
|
-
* Extracted from utils/cashuUtils.ts
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Options for refunding API key balance
|
|
20
|
-
*/
|
|
21
|
-
interface RefundApiKeyOptions {
|
|
22
|
-
/** The mint URL (for NIP-60 wallet operations) */
|
|
23
|
-
mintUrl: string;
|
|
24
|
-
/** The provider base URL */
|
|
25
|
-
baseUrl: string;
|
|
26
|
-
/** The API key to use for authentication */
|
|
27
|
-
apiKey: string;
|
|
28
|
-
/** If true, forces refund even if the API key was used recently */
|
|
29
|
-
forceRefund?: boolean;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Options for topping up API key balance
|
|
33
|
-
*/
|
|
34
|
-
interface TopUpOptions {
|
|
35
|
-
/** The mint URL to spend from */
|
|
36
|
-
mintUrl: string;
|
|
37
|
-
/** The provider base URL */
|
|
38
|
-
baseUrl: string;
|
|
39
|
-
/** Amount to top up in sats */
|
|
40
|
-
amount: number;
|
|
41
|
-
/** Optional specific API key to top up (if not provided, uses stored token) */
|
|
42
|
-
token?: string;
|
|
43
|
-
}
|
|
44
|
-
interface CreateProviderTokenOptions {
|
|
45
|
-
mintUrl: string;
|
|
46
|
-
baseUrl: string;
|
|
47
|
-
amount: number;
|
|
48
|
-
p2pkPubkey?: string;
|
|
49
|
-
excludeMints?: string[];
|
|
50
|
-
retryCount?: number;
|
|
51
|
-
}
|
|
52
|
-
interface ProviderTokenResult {
|
|
53
|
-
success: boolean;
|
|
54
|
-
token?: string;
|
|
55
|
-
error?: string;
|
|
56
|
-
selectedMintUrl?: string;
|
|
57
|
-
amountSpent?: number;
|
|
58
|
-
}
|
|
59
|
-
interface BalanceState {
|
|
60
|
-
totalBalance: number;
|
|
61
|
-
providerBalances: Record<string, number>;
|
|
62
|
-
mintBalances: Record<string, number>;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* BalanceManager handles token refunds and topups from providers
|
|
66
|
-
*/
|
|
67
|
-
declare class BalanceManager {
|
|
68
|
-
private walletAdapter;
|
|
69
|
-
private storageAdapter;
|
|
70
|
-
private providerRegistry?;
|
|
71
|
-
private cashuSpender;
|
|
72
|
-
/** In-memory guard for per-provider wallet mutations (topup / refund) */
|
|
73
|
-
private providerWalletOps;
|
|
74
|
-
/** Cooldown (ms) between opposite operations on the same provider */
|
|
75
|
-
private static readonly PROVIDER_WALLET_COOLDOWN_MS;
|
|
76
|
-
private readonly logger;
|
|
77
|
-
constructor(walletAdapter: WalletAdapter, storageAdapter: StorageAdapter, providerRegistry?: ProviderRegistry | undefined, cashuSpender?: CashuSpender, logger?: SdkLogger);
|
|
78
|
-
/**
|
|
79
|
-
* Check whether a wallet operation (topup/refund) may run for a provider.
|
|
80
|
-
* Returns the reason when blocked.
|
|
81
|
-
*/
|
|
82
|
-
private _canRunProviderWalletOperation;
|
|
83
|
-
private _beginProviderWalletOperation;
|
|
84
|
-
private _endProviderWalletOperation;
|
|
85
|
-
getBalanceState(): Promise<BalanceState>;
|
|
86
|
-
/**
|
|
87
|
-
* Refund API key balance - convert remaining API key balance to cashu token
|
|
88
|
-
* @param options - Refund options including forceRefund flag
|
|
89
|
-
* @returns Refund result
|
|
90
|
-
*/
|
|
91
|
-
refundApiKey(options: RefundApiKeyOptions): Promise<RefundResult>;
|
|
92
|
-
private _refundApiKeyImpl;
|
|
93
|
-
/**
|
|
94
|
-
* Fetch refund token from provider API using API key (or xcashu token) authentication
|
|
95
|
-
*/
|
|
96
|
-
fetchRefundToken(baseUrl: string, apiKeyOrToken: string, xCashu?: boolean): Promise<{
|
|
97
|
-
success: boolean;
|
|
98
|
-
token?: string;
|
|
99
|
-
requestId?: string;
|
|
100
|
-
error?: string;
|
|
101
|
-
}>;
|
|
102
|
-
/**
|
|
103
|
-
* Top up API key balance with a cashu token
|
|
104
|
-
*/
|
|
105
|
-
topUp(options: TopUpOptions): Promise<TopUpResult>;
|
|
106
|
-
private _topUpImpl;
|
|
107
|
-
createProviderToken(options: CreateProviderTokenOptions): Promise<ProviderTokenResult>;
|
|
108
|
-
private _selectCandidateMints;
|
|
109
|
-
private _refundOtherProvidersForTopUp;
|
|
110
|
-
/**
|
|
111
|
-
* Post topup request to provider API
|
|
112
|
-
*/
|
|
113
|
-
private _postTopUp;
|
|
114
|
-
/**
|
|
115
|
-
* Attempt to receive token back after failed top up
|
|
116
|
-
*/
|
|
117
|
-
private _recoverFailedTopUp;
|
|
118
|
-
/**
|
|
119
|
-
* Handle refund errors with specific error types
|
|
120
|
-
*/
|
|
121
|
-
private _handleRefundError;
|
|
122
|
-
/**
|
|
123
|
-
* Get token balance from provider
|
|
124
|
-
*/
|
|
125
|
-
getTokenBalance(token: string, baseUrl: string): Promise<{
|
|
126
|
-
amount: number;
|
|
127
|
-
reserved: number;
|
|
128
|
-
unit: "sat" | "msat";
|
|
129
|
-
apiKey: string;
|
|
130
|
-
isInvalidApiKey?: boolean;
|
|
131
|
-
}>;
|
|
132
|
-
/**
|
|
133
|
-
* Handle topup errors with specific error types
|
|
134
|
-
*/
|
|
135
|
-
private _handleTopUpError;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* CashuSpender - Core spending logic for Cashu tokens
|
|
140
|
-
*
|
|
141
|
-
* Handles:
|
|
142
|
-
* - Mint selection with sufficient balance
|
|
143
|
-
* - Provider mint compatibility checks
|
|
144
|
-
* - Retry logic with alternate mints
|
|
145
|
-
* - Critical section management (busy state)
|
|
146
|
-
*
|
|
147
|
-
* Extracted from hooks/useCashuWithXYZ.ts
|
|
148
|
-
*/
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Options for spending cashu tokens
|
|
152
|
-
*/
|
|
153
|
-
interface SpendOptions {
|
|
154
|
-
/** The mint URL to send from (can be overridden if insufficient balance) */
|
|
155
|
-
mintUrl: string;
|
|
156
|
-
/** The amount to spend in sats */
|
|
157
|
-
amount: number;
|
|
158
|
-
/** The provider base URL (for token storage and provider mint checks) */
|
|
159
|
-
baseUrl: string;
|
|
160
|
-
/** Whether to reuse an existing token if available */
|
|
161
|
-
reuseToken?: boolean;
|
|
162
|
-
/** Optional P2PK public key */
|
|
163
|
-
p2pkPubkey?: string;
|
|
164
|
-
/** Array of mint URLs to exclude (for retry logic) */
|
|
165
|
-
excludeMints?: string[];
|
|
166
|
-
/** Current retry count (for internal recursion) */
|
|
167
|
-
retryCount?: number;
|
|
168
|
-
/** Specific provider baseUrls to refund (if not provided, refunds all except current) */
|
|
169
|
-
refundBaseUrls?: string[];
|
|
170
|
-
}
|
|
171
|
-
type DebugLevel = "DEBUG" | "WARN" | "ERROR";
|
|
172
|
-
/**
|
|
173
|
-
* CashuSpender manages the spending of Cashu tokens
|
|
174
|
-
*/
|
|
175
|
-
declare class CashuSpender {
|
|
176
|
-
private walletAdapter;
|
|
177
|
-
private storageAdapter;
|
|
178
|
-
private _providerRegistry?;
|
|
179
|
-
private balanceManager?;
|
|
180
|
-
private _isBusy;
|
|
181
|
-
private debugLevel;
|
|
182
|
-
private readonly logger;
|
|
183
|
-
constructor(walletAdapter: WalletAdapter, storageAdapter: StorageAdapter, _providerRegistry?: unknown | undefined, balanceManager?: BalanceManager | undefined, logger?: SdkLogger);
|
|
184
|
-
receiveToken(token: string): Promise<{
|
|
185
|
-
success: boolean;
|
|
186
|
-
amount: number;
|
|
187
|
-
unit: "sat" | "msat";
|
|
188
|
-
message?: string;
|
|
189
|
-
}>;
|
|
190
|
-
private _decodeTokenAmount;
|
|
191
|
-
private _getBalanceState;
|
|
192
|
-
private _logTransaction;
|
|
193
|
-
/**
|
|
194
|
-
* Check if the spender is currently in a critical operation
|
|
195
|
-
*/
|
|
196
|
-
get isBusy(): boolean;
|
|
197
|
-
getDebugLevel(): DebugLevel;
|
|
198
|
-
setDebugLevel(level: DebugLevel): void;
|
|
199
|
-
private _log;
|
|
200
|
-
/**
|
|
201
|
-
* Spend Cashu tokens with automatic mint selection and retry logic
|
|
202
|
-
* Throws errors on failure instead of returning failed SpendResult
|
|
203
|
-
*/
|
|
204
|
-
spend(options: SpendOptions): Promise<SpendResult>;
|
|
205
|
-
/**
|
|
206
|
-
* Check if error message indicates a network error
|
|
207
|
-
*/
|
|
208
|
-
private _isNetworkError;
|
|
209
|
-
/**
|
|
210
|
-
* Internal spending logic
|
|
211
|
-
*/
|
|
212
|
-
private _spendInternal;
|
|
213
|
-
/**
|
|
214
|
-
* Try to reuse an existing API key
|
|
215
|
-
*/
|
|
216
|
-
private _tryReuseToken;
|
|
217
|
-
/**
|
|
218
|
-
* Refund all xcashu tokens from storage by calling the provider's refund endpoint.
|
|
219
|
-
* The xcashu token acts as an API key to claim the refund, and the response contains
|
|
220
|
-
* the actual refunded Cashu token which is then received into the wallet.
|
|
221
|
-
* @param mintUrl - The mint URL for receiving tokens
|
|
222
|
-
* @param excludeBaseUrls - Base URLs to exclude from refund (optional)
|
|
223
|
-
* @returns Results for each xcashu token refund attempt
|
|
224
|
-
*/
|
|
225
|
-
refundXcashuTokens(mintUrl: string, excludeBaseUrls?: string[]): Promise<{
|
|
226
|
-
baseUrl: string;
|
|
227
|
-
token: string;
|
|
228
|
-
success: boolean;
|
|
229
|
-
error?: string;
|
|
230
|
-
}[]>;
|
|
231
|
-
/**
|
|
232
|
-
* Refund specific providers without retrying spend
|
|
233
|
-
*/
|
|
234
|
-
refundProviders(mintUrl: string, forceRefund?: boolean): Promise<{
|
|
235
|
-
baseUrl: string;
|
|
236
|
-
success: boolean;
|
|
237
|
-
}[]>;
|
|
238
|
-
/**
|
|
239
|
-
* Create an insufficient balance error result
|
|
240
|
-
*/
|
|
241
|
-
private _createInsufficientBalanceError;
|
|
242
|
-
private _getProviderTokenBalance;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
export { BalanceManager, type BalanceState, CashuSpender, type CreateProviderTokenOptions, ProviderRegistry, type ProviderTokenResult, type RefundApiKeyOptions, type SpendOptions, StorageAdapter, type TopUpOptions, WalletAdapter };
|