@buildonspark/spark-sdk 0.0.9 → 0.0.11

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.
Files changed (82) hide show
  1. package/dist/services/config.d.ts +20 -16
  2. package/dist/services/config.js +26 -18
  3. package/dist/services/config.js.map +1 -1
  4. package/dist/services/connection.js +1 -1
  5. package/dist/services/connection.js.map +1 -1
  6. package/dist/services/deposit.js +2 -2
  7. package/dist/services/deposit.js.map +1 -1
  8. package/dist/services/lightning.js +4 -4
  9. package/dist/services/lightning.js.map +1 -1
  10. package/dist/services/token-transactions.js +8 -7
  11. package/dist/services/token-transactions.js.map +1 -1
  12. package/dist/services/transfer.js +12 -10
  13. package/dist/services/transfer.js.map +1 -1
  14. package/dist/spark-sdk.d.ts +2 -3
  15. package/dist/spark-sdk.js +2 -7
  16. package/dist/spark-sdk.js.map +1 -1
  17. package/dist/tests/coop-exit.test.js +8 -5
  18. package/dist/tests/coop-exit.test.js.map +1 -1
  19. package/dist/tests/deposit.test.js +8 -10
  20. package/dist/tests/deposit.test.js.map +1 -1
  21. package/dist/tests/keys.test.js +0 -1
  22. package/dist/tests/keys.test.js.map +1 -1
  23. package/dist/tests/lightning.test.js +10 -7
  24. package/dist/tests/lightning.test.js.map +1 -1
  25. package/dist/tests/swap.test.js +8 -5
  26. package/dist/tests/swap.test.js.map +1 -1
  27. package/dist/tests/test-util.d.ts +8 -44
  28. package/dist/tests/test-util.js +10 -7
  29. package/dist/tests/test-util.js.map +1 -1
  30. package/dist/tests/transfer.test.js +30 -19
  31. package/dist/tests/transfer.test.js.map +1 -1
  32. package/package.json +2 -2
  33. package/dist/LightningSendRequest-CNJFhLVc.d.cts +0 -374
  34. package/dist/LightningSendRequest-CNJFhLVc.d.ts +0 -374
  35. package/dist/auto-bind.d.ts +0 -7
  36. package/dist/auto-bind.js +0 -41
  37. package/dist/auto-bind.js.map +0 -1
  38. package/dist/chunk-5SAJ52IV.js +0 -10309
  39. package/dist/chunk-COXVABEU.js +0 -1524
  40. package/dist/chunk-F4JW24C4.js +0 -78
  41. package/dist/chunk-H4A2WXR3.js +0 -331
  42. package/dist/chunk-HTNOFUHX.js +0 -1547
  43. package/dist/chunk-JQFHUW4I.js +0 -21
  44. package/dist/chunk-K3Y7DVLD.js +0 -19
  45. package/dist/chunk-NDKNVHGP.js +0 -127
  46. package/dist/chunk-PMVJGQCP.js +0 -627
  47. package/dist/chunk-QX3ZJH2S.js +0 -527
  48. package/dist/chunk-SL2YOBVM.js +0 -127
  49. package/dist/chunk-SWCOMKD6.js +0 -333
  50. package/dist/chunk-SWFFNBSR.js +0 -1244
  51. package/dist/chunk-WLK5POBV.js +0 -527
  52. package/dist/chunk-WZ74TD7N.js +0 -660
  53. package/dist/chunk-WZYVI3M3.js +0 -1244
  54. package/dist/chunk-ZGU3XW7W.js +0 -78
  55. package/dist/connection-BgWj7Hnd.d.cts +0 -77
  56. package/dist/connection-BgbVJtzh.d.ts +0 -77
  57. package/dist/connection-DX-9yFl8.d.ts +0 -77
  58. package/dist/connection-hITj9Mgk.d.cts +0 -77
  59. package/dist/graphql/objects/index.cjs +0 -626
  60. package/dist/graphql/objects/index.d.cts +0 -140
  61. package/dist/index.cjs +0 -17202
  62. package/dist/index.d.cts +0 -413
  63. package/dist/index.d.ts +0 -413
  64. package/dist/index.js +0 -3390
  65. package/dist/proto/spark.cjs +0 -10451
  66. package/dist/proto/spark.d.cts +0 -3
  67. package/dist/services/index.cjs +0 -12503
  68. package/dist/services/index.d.cts +0 -23
  69. package/dist/services/index.d.ts +0 -23
  70. package/dist/services/index.js +0 -17
  71. package/dist/signer/signer.cjs +0 -894
  72. package/dist/signer/signer.d.cts +0 -5
  73. package/dist/signer-BaC_ZP1g.d.ts +0 -138
  74. package/dist/signer-C6h1OnSQ.d.cts +0 -138
  75. package/dist/signer-CO4owhHI.d.ts +0 -154
  76. package/dist/signer-DDkpXvNZ.d.cts +0 -154
  77. package/dist/spark-BUTdOtMz.d.cts +0 -1170
  78. package/dist/spark-BUTdOtMz.d.ts +0 -1170
  79. package/dist/tests/test-util.cjs +0 -12269
  80. package/dist/tests/test-util.d.cts +0 -90
  81. package/dist/utils/index.cjs +0 -1825
  82. package/dist/utils/index.d.cts +0 -280
package/dist/index.d.ts DELETED
@@ -1,413 +0,0 @@
1
- import { p as LightningSendRequest, e as CoopExitRequest } from './LightningSendRequest-CNJFhLVc.js';
2
- import { a as Transfer, b as TreeNode, c as LeafRefundTxSigningResult, d as NodeSignatures, F as FinalizeNodeSignaturesResponse, Q as QueryPendingTransfersResponse, e as QueryAllTransfersResponse, L as LeafWithPreviousTransactionData } from './spark-BUTdOtMz.js';
3
- import { W as WalletConfigService, C as ConnectionManager, a as WalletConfig } from './connection-DX-9yFl8.js';
4
- import { Transaction } from '@scure/btc-signer';
5
- import { b as SigningCommitment, V as VerifiableSecretShare, N as Network, S as SparkSigner } from './signer-BaC_ZP1g.js';
6
- import '@lightsparkdev/core';
7
- import '@bufbuild/protobuf/wire';
8
- import 'nice-grpc-common';
9
-
10
- type LeafKeyTweak = {
11
- leaf: TreeNode;
12
- signingPubKey: Uint8Array;
13
- newSigningPubKey: Uint8Array;
14
- };
15
- type ClaimLeafData = {
16
- signingPubKey: Uint8Array;
17
- tx?: Transaction;
18
- refundTx?: Transaction;
19
- signingNonceCommitment: SigningCommitment;
20
- vout?: number;
21
- };
22
- type LeafRefundSigningData = {
23
- signingPubKey: Uint8Array;
24
- receivingPubkey: Uint8Array;
25
- tx: Transaction;
26
- refundTx?: Transaction;
27
- signingNonceCommitment: SigningCommitment;
28
- vout: number;
29
- };
30
- declare class BaseTransferService {
31
- protected readonly config: WalletConfigService;
32
- protected readonly connectionManager: ConnectionManager;
33
- constructor(config: WalletConfigService, connectionManager: ConnectionManager);
34
- sendTransferTweakKey(transfer: Transfer, leaves: LeafKeyTweak[], refundSignatureMap: Map<string, Uint8Array>): Promise<Transfer>;
35
- signRefunds(leafDataMap: Map<string, ClaimLeafData>, operatorSigningResults: LeafRefundTxSigningResult[], adaptorPubKey?: Uint8Array): Promise<NodeSignatures[]>;
36
- private prepareSendTransferKeyTweaks;
37
- private prepareSingleSendTransferKeyTweak;
38
- protected findShare(shares: VerifiableSecretShare[], operatorID: number): VerifiableSecretShare | undefined;
39
- private compareTransfers;
40
- }
41
- declare class TransferService extends BaseTransferService {
42
- constructor(config: WalletConfigService, connectionManager: ConnectionManager);
43
- sendTransfer(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array, expiryTime: Date): Promise<Transfer>;
44
- claimTransfer(transfer: Transfer, leaves: LeafKeyTweak[]): Promise<FinalizeNodeSignaturesResponse>;
45
- queryPendingTransfers(): Promise<QueryPendingTransfersResponse>;
46
- queryAllTransfers(limit: number, offset: number): Promise<QueryAllTransfersResponse>;
47
- verifyPendingTransfer(transfer: Transfer): Promise<Map<string, Uint8Array>>;
48
- sendSwapSignRefund(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array, expiryTime: Date, adaptorPubKey?: Uint8Array): Promise<{
49
- transfer: Transfer;
50
- signatureMap: Map<string, Uint8Array>;
51
- leafDataMap: Map<string, LeafRefundSigningData>;
52
- signingResults: LeafRefundTxSigningResult[];
53
- }>;
54
- sendTransferSignRefund(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array, expiryTime: Date): Promise<{
55
- transfer: Transfer;
56
- signatureMap: Map<string, Uint8Array>;
57
- leafDataMap: Map<string, LeafRefundSigningData>;
58
- }>;
59
- private prepareRefundSoSigningJobs;
60
- claimTransferTweakKeys(transfer: Transfer, leaves: LeafKeyTweak[]): Promise<void>;
61
- private prepareClaimLeavesKeyTweaks;
62
- private prepareClaimLeafKeyTweaks;
63
- claimTransferSignRefunds(transfer: Transfer, leafKeys: LeafKeyTweak[]): Promise<NodeSignatures[]>;
64
- private finalizeTransfer;
65
- cancelSendTransfer(transfer: Transfer): Promise<Transfer | undefined>;
66
- queryPendingTransfersBySender(): Promise<QueryPendingTransfersResponse>;
67
- refreshTimelockNodes(nodes: TreeNode[], parentNode: TreeNode, signingPubKey: Uint8Array): Promise<FinalizeNodeSignaturesResponse>;
68
- private extendTimelock;
69
- }
70
-
71
- type CreateLightningInvoiceParams = {
72
- amountSats: number;
73
- memo: string;
74
- expirySeconds?: number;
75
- };
76
- type PayLightningInvoiceParams = {
77
- invoice: string;
78
- };
79
- type SendTransferParams = {
80
- amount?: number;
81
- leaves?: TreeNode[];
82
- receiverPubKey: string;
83
- expiryTime?: Date;
84
- };
85
- type InitWalletResponse = {
86
- balance: bigint;
87
- tokenBalance: Map<string, {
88
- balance: bigint;
89
- }>;
90
- mnemonic?: string | undefined;
91
- };
92
- /**
93
- * The SparkWallet class is the primary interface for interacting with the Spark network.
94
- * It provides methods for creating and managing wallets, handling deposits, executing transfers,
95
- * and interacting with the Lightning Network.
96
- */
97
- declare class SparkWallet {
98
- protected config: WalletConfigService;
99
- protected connectionManager: ConnectionManager;
100
- private depositService;
101
- protected transferService: TransferService;
102
- private treeCreationService;
103
- private lightningService;
104
- private coopExitService;
105
- private tokenTransactionService;
106
- private claimTransferMutex;
107
- private leavesMutex;
108
- private optimizationInProgress;
109
- private sspClient;
110
- private wasmModule;
111
- protected leaves: TreeNode[];
112
- protected tokenLeaves: Map<string, LeafWithPreviousTransactionData[]>;
113
- constructor(network: Network, signer?: SparkSigner, config?: WalletConfig);
114
- private initWasm;
115
- private initializeWallet;
116
- private getLeaves;
117
- private selectLeaves;
118
- private selectLeavesForSwap;
119
- private areLeavesInefficient;
120
- private optimizeLeaves;
121
- private syncWallet;
122
- private withLeaves;
123
- private isInitialized;
124
- /**
125
- * Gets the identity public key of the wallet.
126
- *
127
- * @returns {Promise<string>} The identity public key as a hex string.
128
- */
129
- getIdentityPublicKey(): Promise<string>;
130
- /**
131
- * Gets the Spark address of the wallet.
132
- *
133
- * @returns {Promise<string>} The Spark address as a hex string.
134
- */
135
- getSparkAddress(): Promise<string>;
136
- /**
137
- * Initializes the wallet using either a mnemonic phrase or a raw seed.
138
- * initWallet will also claim any pending incoming lightning payment, spark transfer,
139
- * or bitcoin deposit.
140
- *
141
- * @param {Uint8Array | string} [mnemonicOrSeed] - (Optional) Either:
142
- * - A BIP-39 mnemonic phrase as string
143
- * - A raw seed as Uint8Array or hex string
144
- * If not provided, generates a new mnemonic and uses it to create a new wallet
145
- *
146
- * @returns {Promise<Object>} Object containing:
147
- * - mnemonic: The mnemonic if one was generated (undefined for raw seed)
148
- * - balance: The wallet's initial balance in satoshis
149
- * - tokenBalance: Map of token balances and leaf counts
150
- */
151
- initWallet(mnemonicOrSeed?: Uint8Array | string): Promise<InitWalletResponse>;
152
- private initWalletFromMnemonic;
153
- /**
154
- * Initializes a wallet from a seed.
155
- *
156
- * @param {Uint8Array | string} seed - The seed to initialize the wallet from
157
- * @returns {Promise<string>} The identity public key
158
- * @private
159
- */
160
- private initWalletFromSeed;
161
- /**
162
- * Requests a swap of leaves to optimize wallet structure.
163
- *
164
- * @param {Object} params - Parameters for the leaves swap
165
- * @param {number} [params.targetAmount] - Target amount for the swap
166
- * @param {TreeNode[]} [params.leaves] - Specific leaves to swap
167
- * @returns {Promise<Object>} The completed swap response
168
- * @private
169
- */
170
- private requestLeavesSwap;
171
- /**
172
- * Gets all transfers for the wallet.
173
- *
174
- * @param {number} [limit=20] - Maximum number of transfers to return
175
- * @param {number} [offset=0] - Offset for pagination
176
- * @returns {Promise<QueryAllTransfersResponse>} Response containing the list of transfers
177
- */
178
- getAllTransfers(limit?: number, offset?: number): Promise<QueryAllTransfersResponse>;
179
- /**
180
- * Gets the current balance of the wallet.
181
- * You can use the forceRefetch option to synchronize your wallet and claim any
182
- * pending incoming lightning payment, spark transfer, or bitcoin deposit before returning the balance.
183
- *
184
- * @param {boolean} [forceRefetch=true] - Synchronizes the wallet before returning the balance
185
- * @returns {Promise<Object>} Object containing:
186
- * - balance: The wallet's current balance in satoshis
187
- * - tokenBalances: Map of token balances and leaf counts
188
- */
189
- getBalance(forceRefetch?: boolean): Promise<{
190
- balance: bigint;
191
- tokenBalances: Map<string, {
192
- balance: bigint;
193
- }>;
194
- }>;
195
- /**
196
- * Generates a new deposit address for receiving bitcoin funds.
197
- * Note that this function returns a bitcoin address, not a spark address.
198
- * For Layer 1 Bitcoin deposits, Spark generates Pay to Taproot (P2TR) addresses.
199
- * These addresses start with "bc1p" and can be used to receive Bitcoin from any wallet.
200
- *
201
- * @returns {Promise<string>} A Bitcoin address for depositing funds
202
- */
203
- getDepositAddress(): Promise<string>;
204
- /**
205
- * Generates a deposit address for receiving funds.
206
- *
207
- * @returns {Promise<string>} A deposit address
208
- * @private
209
- */
210
- private generateDepositAddress;
211
- /**
212
- * Finalizes a deposit to the wallet.
213
- *
214
- * @param {DepositParams} params - Parameters for finalizing the deposit
215
- * @returns {Promise<TreeNode[] | undefined>} The nodes created from the deposit
216
- * @private
217
- */
218
- private finalizeDeposit;
219
- claimDeposit(txid: string): Promise<TreeNode[] | undefined>;
220
- /**
221
- * Queries the mempool for transactions associated with an address.
222
- *
223
- * @param {string} address - The address to query
224
- * @returns {Promise<{depositTx: Transaction, vout: number} | null>} Transaction details or null if none found
225
- * @private
226
- */
227
- private queryMempoolTxs;
228
- /**
229
- * Transfers deposit to self to claim ownership.
230
- *
231
- * @param {TreeNode[]} leaves - The leaves to transfer
232
- * @param {Uint8Array} signingPubKey - The signing public key
233
- * @returns {Promise<TreeNode[] | undefined>} The nodes resulting from the transfer
234
- * @private
235
- */
236
- private transferDepositToSelf;
237
- /**
238
- * Sends a transfer to another Spark user.
239
- *
240
- * @param {Object} params - Parameters for the transfer
241
- * @param {string} params.receiverSparkAddress - The recipient's Spark address
242
- * @param {number} params.amountSats - Amount to send in satoshis
243
- * @returns {Promise<Transfer>} The completed transfer details
244
- */
245
- sendSparkTransfer({ receiverSparkAddress, amountSats, }: {
246
- receiverSparkAddress: string;
247
- amountSats: number;
248
- }): Promise<Transfer>;
249
- /**
250
- * Internal method to send a transfer.
251
- *
252
- * @param {SendTransferParams} params - Parameters for the transfer
253
- * @returns {Promise<Transfer>} The completed transfer details
254
- * @private
255
- */
256
- private _sendTransfer;
257
- /**
258
- * Internal method to refresh timelock nodes.
259
- *
260
- * @param {string} nodeId - The optional ID of the node to refresh. If not provided, all nodes will be checked.
261
- * @returns {Promise<void>}
262
- */
263
- refreshTimelockNodes(nodeId?: string): Promise<void>;
264
- /**
265
- * Claims a specific transfer.
266
- *
267
- * @param {Transfer} transfer - The transfer to claim
268
- * @returns {Promise<Object>} The claim result
269
- * @private
270
- */
271
- private claimTransfer;
272
- /**
273
- * Claims all pending transfers.
274
- *
275
- * @returns {Promise<boolean>} True if any transfers were claimed
276
- * @private
277
- */
278
- private claimTransfers;
279
- /**
280
- * Cancels all sender-initiated transfers.
281
- *
282
- * @returns {Promise<void>}
283
- * @private
284
- */
285
- private cancelAllSenderInitiatedTransfers;
286
- /**
287
- * Creates a Lightning invoice for receiving payments.
288
- *
289
- * @param {Object} params - Parameters for the lightning invoice
290
- * @param {number} params.amountSats - Amount in satoshis
291
- * @param {string} params.memo - Description for the invoice
292
- * @param {number} [params.expirySeconds] - Optional expiry time in seconds
293
- * @returns {Promise<string>} BOLT11 encoded invoice
294
- */
295
- createLightningInvoice({ amountSats, memo, expirySeconds, }: CreateLightningInvoiceParams): Promise<string>;
296
- /**
297
- * Pays a Lightning invoice.
298
- *
299
- * @param {Object} params - Parameters for paying the invoice
300
- * @param {string} params.invoice - The BOLT11-encoded Lightning invoice to pay
301
- * @returns {Promise<LightningSendRequest>} The Lightning payment request details
302
- */
303
- payLightningInvoice({ invoice }: PayLightningInvoiceParams): Promise<LightningSendRequest>;
304
- /**
305
- * Gets fee estimate for receiving Lightning payments.
306
- *
307
- * @param {LightningReceiveFeeEstimateInput} params - Input parameters for fee estimation
308
- * @returns {Promise<LightningReceiveFeeEstimateOutput | null>} Fee estimate for receiving Lightning payments
309
- * @private
310
- */
311
- private getLightningReceiveFeeEstimate;
312
- /**
313
- * Gets fee estimate for sending Lightning payments.
314
- *
315
- * @param {LightningSendFeeEstimateInput} params - Input parameters for fee estimation
316
- * @returns {Promise<LightningSendFeeEstimateOutput | null>} Fee estimate for sending Lightning payments
317
- * @private
318
- */
319
- private getLightningSendFeeEstimate;
320
- /**
321
- * Generates a deposit address for a tree.
322
- *
323
- * @param {number} vout - The vout index
324
- * @param {Uint8Array} parentSigningPubKey - The parent signing public key
325
- * @param {Transaction} [parentTx] - Optional parent transaction
326
- * @param {TreeNode} [parentNode] - Optional parent node
327
- * @returns {Promise<Object>} Deposit address information
328
- * @private
329
- */
330
- private generateDepositAddressForTree;
331
- /**
332
- * Creates a tree structure.
333
- *
334
- * @param {number} vout - The vout index
335
- * @param {DepositAddressTree} root - The root of the tree
336
- * @param {boolean} createLeaves - Whether to create leaves
337
- * @param {Transaction} [parentTx] - Optional parent transaction
338
- * @param {TreeNode} [parentNode] - Optional parent node
339
- * @returns {Promise<Object>} The created tree
340
- * @private
341
- */
342
- private createTree;
343
- /**
344
- * Initiates a withdrawal to move funds from the Spark network to an on-chain Bitcoin address.
345
- *
346
- * @param {Object} params - Parameters for the withdrawal
347
- * @param {string} params.onchainAddress - The Bitcoin address where the funds should be sent
348
- * @param {number} [params.targetAmountSats] - The amount in satoshis to withdraw. If not specified, attempts to withdraw all available funds
349
- * @returns {Promise<CoopExitRequest | null | undefined>} The withdrawal request details, or null/undefined if the request cannot be completed
350
- */
351
- withdraw({ onchainAddress, targetAmountSats, }: {
352
- onchainAddress: string;
353
- targetAmountSats?: number;
354
- }): Promise<CoopExitRequest | null | undefined>;
355
- /**
356
- * Internal method to perform a cooperative exit (withdrawal).
357
- *
358
- * @param {string} onchainAddress - The Bitcoin address where the funds should be sent
359
- * @param {number} [targetAmountSats] - The amount in satoshis to withdraw
360
- * @returns {Promise<Object | null | undefined>} The exit request details
361
- * @private
362
- */
363
- private coopExit;
364
- /**
365
- * Gets fee estimate for cooperative exit (on-chain withdrawal).
366
- *
367
- * @param {CoopExitFeeEstimateInput} params - Input parameters for fee estimation
368
- * @returns {Promise<CoopExitFeeEstimateOutput | null>} Fee estimate for the withdrawal
369
- * @private
370
- */
371
- private getCoopExitFeeEstimate;
372
- /**
373
- * Synchronizes token leaves for the wallet.
374
- *
375
- * @returns {Promise<void>}
376
- * @private
377
- */
378
- protected syncTokenLeaves(): Promise<void>;
379
- /**
380
- * Gets all token balances.
381
- *
382
- * @returns {Promise<Map<string, { balance: bigint }>>} Map of token balances and leaf counts
383
- * @private
384
- */
385
- private getAllTokenBalances;
386
- /**
387
- * Transfers tokens to another user.
388
- *
389
- * @param {Object} params - Parameters for the token transfer
390
- * @param {string} params.tokenPublicKey - The public key of the token to transfer
391
- * @param {bigint} params.tokenAmount - The amount of tokens to transfer
392
- * @param {string} params.receiverSparkAddress - The recipient's public key
393
- * @param {LeafWithPreviousTransactionData[]} [params.selectedLeaves] - Optional specific leaves to use for the transfer
394
- * @returns {Promise<string>} The transaction ID of the token transfer
395
- */
396
- sendSparkTokenTransfer({ tokenPublicKey, tokenAmount, receiverSparkAddress, selectedLeaves, }: {
397
- tokenPublicKey: string;
398
- tokenAmount: bigint;
399
- receiverSparkAddress: string;
400
- selectedLeaves?: LeafWithPreviousTransactionData[];
401
- }): Promise<string>;
402
- /**
403
- * Selects token leaves for a transfer.
404
- *
405
- * @param {string} tokenPublicKey - The public key of the token
406
- * @param {bigint} tokenAmount - The amount of tokens to select leaves for
407
- * @returns {LeafWithPreviousTransactionData[]} The selected leaves
408
- * @private
409
- */
410
- private selectTokenLeaves;
411
- }
412
-
413
- export { type CreateLightningInvoiceParams, type PayLightningInvoiceParams, type SendTransferParams, SparkWallet };