@buildonspark/spark-sdk 0.1.46 → 0.2.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.
Files changed (171) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/{chunk-BGGEVUJK.js → chunk-2ENZX6LT.js} +241 -7
  3. package/dist/{chunk-LHRD2WT6.js → chunk-4JD4HIAN.js} +23 -3
  4. package/dist/{chunk-I54FARY2.js → chunk-CDLETEDT.js} +11 -3
  5. package/dist/{chunk-OBFKIEMP.js → chunk-TM6CHQXC.js} +1 -1
  6. package/dist/chunk-UDK3EBE5.js +13514 -0
  7. package/dist/chunk-XYTKKLCV.js +7 -0
  8. package/dist/{RequestLightningSendInput-2cSh_In4.d.cts → client-DKbwpcnl.d.ts} +434 -212
  9. package/dist/{RequestLightningSendInput-CN6BNg_g.d.ts → client-Drs5Lapg.d.cts} +434 -212
  10. package/dist/{services/config.cjs → debug.cjs} +31007 -1003
  11. package/dist/debug.d.cts +126 -0
  12. package/dist/debug.d.ts +126 -0
  13. package/dist/debug.js +21 -0
  14. package/dist/graphql/objects/index.d.cts +4 -11
  15. package/dist/graphql/objects/index.d.ts +4 -11
  16. package/dist/graphql/objects/index.js +2 -4
  17. package/dist/index.cjs +18219 -20818
  18. package/dist/index.d.cts +15 -768
  19. package/dist/index.d.ts +15 -768
  20. package/dist/index.js +82 -76
  21. package/dist/index.node.cjs +23831 -26538
  22. package/dist/index.node.d.cts +191 -33
  23. package/dist/index.node.d.ts +191 -33
  24. package/dist/index.node.js +87 -181
  25. package/dist/native/index.cjs +17835 -20519
  26. package/dist/native/index.d.cts +1466 -1546
  27. package/dist/native/index.d.ts +1466 -1546
  28. package/dist/native/index.js +22605 -25286
  29. package/dist/proto/lrc20.d.cts +2 -2
  30. package/dist/proto/lrc20.d.ts +2 -2
  31. package/dist/proto/lrc20.js +3098 -46
  32. package/dist/proto/spark.cjs +241 -7
  33. package/dist/proto/spark.d.cts +1 -1
  34. package/dist/proto/spark.d.ts +1 -1
  35. package/dist/proto/spark.js +5 -1
  36. package/dist/proto/spark_token.cjs +22 -2
  37. package/dist/proto/spark_token.d.cts +8 -1
  38. package/dist/proto/spark_token.d.ts +8 -1
  39. package/dist/proto/spark_token.js +2 -2
  40. package/dist/{sdk-types-CKBsylfW.d.ts → sdk-types-DCIVdKUT.d.ts} +1 -1
  41. package/dist/{sdk-types-Ct8xmN7l.d.cts → sdk-types-DJ2ve9YY.d.cts} +1 -1
  42. package/dist/{spark-DbzGfse6.d.ts → spark-BUOx3U7Q.d.cts} +103 -5
  43. package/dist/{spark-DbzGfse6.d.cts → spark-BUOx3U7Q.d.ts} +103 -5
  44. package/dist/spark-wallet-CF8Oxjqs.d.ts +935 -0
  45. package/dist/spark-wallet-DOLSa3oF.d.cts +935 -0
  46. package/dist/spark_bindings/native/index.d.cts +1 -1
  47. package/dist/spark_bindings/native/index.d.ts +1 -1
  48. package/dist/spark_bindings/wasm/index.d.cts +1 -1
  49. package/dist/spark_bindings/wasm/index.d.ts +1 -1
  50. package/dist/{services/index.cjs → tests/test-utils.cjs} +9788 -10263
  51. package/dist/tests/test-utils.d.cts +79 -0
  52. package/dist/tests/test-utils.d.ts +79 -0
  53. package/dist/tests/test-utils.js +93 -0
  54. package/dist/types/index.cjs +239 -7
  55. package/dist/types/index.d.cts +5 -9
  56. package/dist/types/index.d.ts +5 -9
  57. package/dist/types/index.js +4 -6
  58. package/dist/{types-C-Rp0Oo7.d.ts → types-BADxR3bm.d.cts} +1 -1
  59. package/dist/{types-C-Rp0Oo7.d.cts → types-BADxR3bm.d.ts} +1 -1
  60. package/dist/{index-COm59SPw.d.ts → xchain-address-C2xMs9nz.d.cts} +6 -94
  61. package/dist/{index-CKL5DodV.d.cts → xchain-address-Ckto9oEz.d.ts} +6 -94
  62. package/package.json +9 -33
  63. package/src/debug.ts +13 -0
  64. package/src/graphql/client.ts +59 -20
  65. package/src/index.node.ts +28 -2
  66. package/src/index.ts +31 -1
  67. package/src/native/index.ts +16 -2
  68. package/src/proto/mock.ts +76 -0
  69. package/src/proto/spark.ts +354 -6
  70. package/src/proto/spark_token.ts +34 -2
  71. package/src/services/config.ts +4 -6
  72. package/src/services/connection.ts +131 -64
  73. package/src/services/coop-exit.ts +6 -3
  74. package/src/services/deposit.ts +9 -8
  75. package/src/services/lightning.ts +4 -3
  76. package/src/services/signing.ts +10 -6
  77. package/src/services/token-transactions.ts +100 -85
  78. package/src/services/transfer.ts +88 -60
  79. package/src/services/tree-creation.ts +17 -9
  80. package/src/services/wallet-config.ts +17 -9
  81. package/src/signer/signer.react-native.ts +5 -10
  82. package/src/signer/signer.ts +269 -339
  83. package/src/signer/types.ts +63 -0
  84. package/src/spark-wallet/spark-wallet.ts +226 -149
  85. package/src/spark-wallet/types.ts +22 -8
  86. package/src/tests/integration/adaptor-signature.test.ts +8 -9
  87. package/src/tests/integration/coop-exit.test.ts +214 -202
  88. package/src/tests/integration/lightning.test.ts +128 -103
  89. package/src/tests/integration/swap.test.ts +116 -84
  90. package/src/tests/integration/transfer.test.ts +291 -214
  91. package/src/tests/integration/tree-creation.test.ts +0 -5
  92. package/src/tests/integration/wallet.test.ts +1 -0
  93. package/src/tests/isHermeticTest.ts +3 -24
  94. package/src/tests/{test-util.ts → test-utils.ts} +13 -11
  95. package/src/tests/token-identifier.test.ts +6 -6
  96. package/src/tests/wrapWithOtelSpan.test.ts +1 -1
  97. package/src/{address → utils}/address.ts +1 -1
  98. package/src/utils/crypto.ts +19 -9
  99. package/src/utils/index.ts +2 -0
  100. package/src/utils/network.ts +17 -0
  101. package/src/utils/secret-sharing.ts +1 -2
  102. package/src/utils/signing.ts +1 -1
  103. package/src/utils/token-identifier.ts +27 -21
  104. package/src/utils/token-transaction-validation.ts +34 -0
  105. package/src/utils/token-transactions.ts +12 -8
  106. package/src/utils/unilateral-exit.ts +32 -0
  107. package/src/utils/xchain-address.ts +1 -1
  108. package/dist/BitcoinNetwork-TnABML0T.d.cts +0 -18
  109. package/dist/BitcoinNetwork-TnABML0T.d.ts +0 -18
  110. package/dist/LightningSendFeeEstimateInput-BgOhEAI-.d.cts +0 -10
  111. package/dist/LightningSendFeeEstimateInput-BgOhEAI-.d.ts +0 -10
  112. package/dist/address/index.cjs +0 -458
  113. package/dist/address/index.d.cts +0 -32
  114. package/dist/address/index.d.ts +0 -32
  115. package/dist/address/index.js +0 -17
  116. package/dist/chunk-4EMV7HHW.js +0 -277
  117. package/dist/chunk-C2S227QR.js +0 -2336
  118. package/dist/chunk-DXR2PXJU.js +0 -1122
  119. package/dist/chunk-GSI4OLXZ.js +0 -117
  120. package/dist/chunk-HHNQ3ZHC.js +0 -170
  121. package/dist/chunk-HMLOC6TE.js +0 -14
  122. package/dist/chunk-HSCLBJEL.js +0 -113
  123. package/dist/chunk-HWJWKEIU.js +0 -75
  124. package/dist/chunk-JB64OQES.js +0 -7095
  125. package/dist/chunk-KMUMFYFX.js +0 -137
  126. package/dist/chunk-N5VZVCGJ.js +0 -622
  127. package/dist/chunk-NSJF5F5O.js +0 -325
  128. package/dist/chunk-NTFKFRQ2.js +0 -3146
  129. package/dist/chunk-OFCJFZ4I.js +0 -24
  130. package/dist/chunk-QNNSEJ4P.js +0 -232
  131. package/dist/chunk-UXDODSDT.js +0 -838
  132. package/dist/chunk-VTUGIIWI.js +0 -0
  133. package/dist/chunk-Z5HIAYFT.js +0 -84
  134. package/dist/network-Css46DAz.d.cts +0 -46
  135. package/dist/network-hynb7iTZ.d.ts +0 -46
  136. package/dist/services/config.d.cts +0 -42
  137. package/dist/services/config.d.ts +0 -42
  138. package/dist/services/config.js +0 -17
  139. package/dist/services/connection.cjs +0 -17691
  140. package/dist/services/connection.d.cts +0 -95
  141. package/dist/services/connection.d.ts +0 -95
  142. package/dist/services/connection.js +0 -11
  143. package/dist/services/index.d.cts +0 -21
  144. package/dist/services/index.d.ts +0 -21
  145. package/dist/services/index.js +0 -58
  146. package/dist/services/lrc-connection.cjs +0 -4713
  147. package/dist/services/lrc-connection.d.cts +0 -34
  148. package/dist/services/lrc-connection.d.ts +0 -34
  149. package/dist/services/lrc-connection.js +0 -11
  150. package/dist/services/token-transactions.cjs +0 -2877
  151. package/dist/services/token-transactions.d.cts +0 -75
  152. package/dist/services/token-transactions.d.ts +0 -75
  153. package/dist/services/token-transactions.js +0 -15
  154. package/dist/services/wallet-config.cjs +0 -340
  155. package/dist/services/wallet-config.d.cts +0 -56
  156. package/dist/services/wallet-config.d.ts +0 -56
  157. package/dist/services/wallet-config.js +0 -33
  158. package/dist/signer/signer.cjs +0 -2004
  159. package/dist/signer/signer.d.cts +0 -10
  160. package/dist/signer/signer.d.ts +0 -10
  161. package/dist/signer/signer.js +0 -24
  162. package/dist/signer-BP6F__oR.d.cts +0 -187
  163. package/dist/signer-BVZJXcq7.d.ts +0 -187
  164. package/dist/utils/index.cjs +0 -2947
  165. package/dist/utils/index.d.cts +0 -18
  166. package/dist/utils/index.d.ts +0 -18
  167. package/dist/utils/index.js +0 -157
  168. package/ios/spark_frost.kt +0 -1900
  169. package/src/address/index.ts +0 -1
  170. package/src/services/lrc-connection.ts +0 -215
  171. /package/dist/{chunk-L3EHBOUX.js → chunk-BYXBJQAS.js} +0 -0
@@ -0,0 +1,935 @@
1
+ import { B as BitcoinNetwork, a2 as MayHaveSspClientOptions, a3 as SspClientOptions, a4 as HasSspClientOptions, a1 as SparkSigner, a5 as KeyDerivation, a6 as SigningCommitment, K as VerifiableSecretShare, m as LeavesSwapFeeEstimateOutput, H as StaticDepositQuoteOutput, C as ClaimStaticDepositOutput, q as LightningReceiveRequest, v as LightningSendRequest, s as LightningSendFeeEstimateInput, E as ExitSpeed, f as CoopExitFeeQuote, i as CoopExitRequest, T as Transfer$1 } from './client-Drs5Lapg.cjs';
2
+ import { N as Network$1, E as Empty, g as SparkServiceClient, h as RequestedSigningCommitments, U as UserSignedTxSigningJob, d as TreeNode, f as Transfer, L as LeafRefundTxSigningResult, i as NodeSignatures, F as FinalizeNodeSignaturesResponse, Q as QueryTransfersResponse, P as PaymentIntentFields, j as OutputWithPreviousTransactionData } from './spark-BUOx3U7Q.cjs';
3
+ import { NetworkType as NetworkType$1, MayHaveLrc20WalletApiConfig, LRC20WalletApiConfig, HasLrc20WalletApiConfig, LRCWallet } from '@buildonspark/lrc20-sdk';
4
+ import * as btc from '@scure/btc-signer';
5
+ import { Transaction } from '@scure/btc-signer';
6
+ import * as bitcoin from 'bitcoinjs-lib';
7
+ import { Channel } from 'nice-grpc';
8
+ import { Channel as Channel$1 } from 'nice-grpc-web';
9
+ import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
10
+ import { CallOptions } from 'nice-grpc-common';
11
+ import { SparkTokenServiceClient, TokenMetadata, TokenTransactionWithStatus } from './proto/spark_token.cjs';
12
+ import { EventEmitter } from 'eventemitter3';
13
+ import { a as WalletTransfer, W as WalletLeaf } from './sdk-types-DJ2ve9YY.cjs';
14
+
15
+ declare enum Network {
16
+ MAINNET = 0,
17
+ TESTNET = 1,
18
+ SIGNET = 2,
19
+ REGTEST = 3,
20
+ LOCAL = 4
21
+ }
22
+ type NetworkType = keyof typeof Network;
23
+ declare const NetworkToProto: Record<Network, Network$1>;
24
+ declare const protoToNetwork: (protoNetwork: Network$1) => Network | undefined;
25
+ declare const getNetwork: (network: Network) => typeof btc.NETWORK;
26
+ declare const LRC_WALLET_NETWORK: Readonly<{
27
+ 0: bitcoin.networks.Network;
28
+ 1: bitcoin.networks.Network;
29
+ 2: bitcoin.networks.Network;
30
+ 3: bitcoin.networks.Network;
31
+ 4: bitcoin.networks.Network;
32
+ }>;
33
+ declare const LRC_WALLET_NETWORK_TYPE: Readonly<{
34
+ 0: NetworkType$1.MAINNET;
35
+ 1: NetworkType$1.TESTNET;
36
+ 2: NetworkType$1.TESTNET;
37
+ 3: NetworkType$1.REGTEST;
38
+ 4: NetworkType$1.LOCAL;
39
+ }>;
40
+ /**
41
+ * Utility function to determine the network from a Bitcoin address.
42
+ *
43
+ * @param {string} address - The Bitcoin address
44
+ * @returns {BitcoinNetwork | null} The detected network or null if not detected
45
+ */
46
+ declare function getNetworkFromAddress(address: string): BitcoinNetwork.MAINNET | BitcoinNetwork.REGTEST | null;
47
+ /**
48
+ * Utility function to get the network enum value from a string.
49
+ *
50
+ * @param {string} network - The Bitcoin network to turn into an enum value
51
+ * @returns {Network} The enum value matching the string
52
+ */
53
+ declare function getNetworkFromString(network?: string): Network;
54
+
55
+ type SigningOperator = {
56
+ readonly id: number;
57
+ readonly identifier: string;
58
+ readonly address: string;
59
+ readonly identityPublicKey: string;
60
+ };
61
+ type ConfigOptions = MayHaveLrc20WalletApiConfig & MayHaveSspClientOptions & {
62
+ readonly network?: NetworkType;
63
+ readonly signingOperators?: Readonly<Record<string, SigningOperator>>;
64
+ readonly coodinatorIdentifier?: string;
65
+ readonly frostSignerAddress?: string;
66
+ readonly lrc20Address?: string;
67
+ readonly threshold?: number;
68
+ readonly tokenSignatures?: "ECDSA" | "SCHNORR";
69
+ readonly tokenValidityDurationSeconds?: number;
70
+ readonly tokenTransactionVersion?: "V0" | "V1";
71
+ readonly electrsUrl?: string;
72
+ readonly lrc20ApiConfig?: LRC20WalletApiConfig;
73
+ readonly sspClientOptions?: SspClientOptions;
74
+ readonly expectedWithdrawBondSats?: number;
75
+ readonly expectedWithdrawRelativeBlockLocktime?: number;
76
+ };
77
+ declare const WalletConfig: {
78
+ LOCAL: Required<ConfigOptions>;
79
+ LOCAL_SCHNORR: Required<ConfigOptions>;
80
+ LOCAL_ECDSA: Required<ConfigOptions>;
81
+ REGTEST: Required<ConfigOptions>;
82
+ MAINNET: Required<ConfigOptions>;
83
+ };
84
+
85
+ declare class WalletConfigService implements HasLrc20WalletApiConfig, HasSspClientOptions {
86
+ private readonly config;
87
+ readonly signer: SparkSigner;
88
+ readonly lrc20ApiConfig: LRC20WalletApiConfig;
89
+ readonly sspClientOptions: SspClientOptions;
90
+ constructor(options?: ConfigOptions, signer?: SparkSigner);
91
+ private getDefaultConfig;
92
+ getCoordinatorAddress(): string;
93
+ getLrc20Address(): string;
94
+ getSigningOperators(): Readonly<Record<string, SigningOperator>>;
95
+ getThreshold(): number;
96
+ getCoordinatorIdentifier(): string;
97
+ getExpectedWithdrawBondSats(): number;
98
+ getExpectedWithdrawRelativeBlockLocktime(): number;
99
+ getSspNetwork(): BitcoinNetwork;
100
+ getNetwork(): Network;
101
+ getNetworkType(): NetworkType;
102
+ getNetworkProto(): number;
103
+ getTokenSignatures(): "ECDSA" | "SCHNORR";
104
+ getTokenTransactionVersion(): "V0" | "V1";
105
+ getTokenValidityDurationSeconds(): number;
106
+ getElectrsUrl(): string;
107
+ getSspIdentityPublicKey(): string;
108
+ }
109
+
110
+ declare enum InterruptTransferRequest_InterruptTransferAction {
111
+ NONE = 0,
112
+ INTERRUPT = 1,
113
+ RESUME = 2,
114
+ UNRECOGNIZED = -1
115
+ }
116
+ interface CleanUpPreimageShareRequest {
117
+ paymentHash: Uint8Array;
118
+ }
119
+ declare const CleanUpPreimageShareRequest: MessageFns<CleanUpPreimageShareRequest>;
120
+ interface InterruptTransferRequest {
121
+ action: InterruptTransferRequest_InterruptTransferAction;
122
+ }
123
+ declare const InterruptTransferRequest: MessageFns<InterruptTransferRequest>;
124
+ interface UpdateNodesStatusRequest {
125
+ nodeIds: string[];
126
+ status: string;
127
+ }
128
+ declare const UpdateNodesStatusRequest: MessageFns<UpdateNodesStatusRequest>;
129
+ /** TriggerTaskRequest is used to trigger a scheduled task immediately in hermetic tests. */
130
+ interface TriggerTaskRequest {
131
+ taskName: string;
132
+ }
133
+ declare const TriggerTaskRequest: MessageFns<TriggerTaskRequest>;
134
+ interface MockServiceClient<CallOptionsExt = {}> {
135
+ clean_up_preimage_share(request: DeepPartial<CleanUpPreimageShareRequest>, options?: CallOptions & CallOptionsExt): Promise<Empty>;
136
+ interrupt_transfer(request: DeepPartial<InterruptTransferRequest>, options?: CallOptions & CallOptionsExt): Promise<Empty>;
137
+ update_nodes_status(request: DeepPartial<UpdateNodesStatusRequest>, options?: CallOptions & CallOptionsExt): Promise<Empty>;
138
+ /** Triggers the execution of a scheduled task immediately by name. Used by hermetic tests */
139
+ trigger_task(request: DeepPartial<TriggerTaskRequest>, options?: CallOptions & CallOptionsExt): Promise<Empty>;
140
+ }
141
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
142
+ type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
143
+ $case: string;
144
+ } ? {
145
+ [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
146
+ } & {
147
+ $case: T["$case"];
148
+ } : T extends {} ? {
149
+ [K in keyof T]?: DeepPartial<T[K]>;
150
+ } : Partial<T>;
151
+ interface MessageFns<T> {
152
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
153
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
154
+ fromJSON(object: any): T;
155
+ toJSON(message: T): unknown;
156
+ create(base?: DeepPartial<T>): T;
157
+ fromPartial(object: DeepPartial<T>): T;
158
+ }
159
+
160
+ declare class ConnectionManager {
161
+ private config;
162
+ private clients;
163
+ private tokenClients;
164
+ private streamClients;
165
+ private authPromises;
166
+ constructor(config: WalletConfigService);
167
+ createClients(): Promise<void>;
168
+ closeConnections(): Promise<void>;
169
+ createMockClient(address: string): Promise<MockServiceClient & {
170
+ close: () => void;
171
+ }>;
172
+ private createChannelWithTLS;
173
+ createSparkStreamClient(address: string, certPath?: string): Promise<SparkServiceClient & {
174
+ close?: () => void;
175
+ }>;
176
+ createSparkClient(address: string, certPath?: string): Promise<SparkServiceClient & {
177
+ close?: () => void;
178
+ }>;
179
+ createSparkTokenClient(address: string, certPath?: string): Promise<SparkTokenServiceClient & {
180
+ close?: () => void;
181
+ }>;
182
+ getStreamChannel(address: string): Promise<Channel | Channel$1 | undefined>;
183
+ private authenticate;
184
+ private createSparkAuthnGrpcConnection;
185
+ private createAuthnMiddleware;
186
+ private createMiddleware;
187
+ private handleMiddlewareError;
188
+ private createNodeMiddleware;
189
+ private createBrowserMiddleware;
190
+ private createGrpcClient;
191
+ }
192
+
193
+ declare class SigningService {
194
+ private readonly config;
195
+ constructor(config: WalletConfigService);
196
+ signRefunds(leaves: LeafKeyTweak[], signingCommitments: RequestedSigningCommitments[], receiverIdentityPubkey: Uint8Array): Promise<UserSignedTxSigningJob[]>;
197
+ }
198
+
199
+ type LeafKeyTweak = {
200
+ leaf: TreeNode;
201
+ keyDerivation: KeyDerivation;
202
+ newKeyDerivation: KeyDerivation;
203
+ };
204
+ type ClaimLeafData = {
205
+ keyDerivation: KeyDerivation;
206
+ tx?: Transaction;
207
+ refundTx?: Transaction;
208
+ signingNonceCommitment: SigningCommitment;
209
+ vout?: number;
210
+ };
211
+ type LeafRefundSigningData = {
212
+ keyDerivation: KeyDerivation;
213
+ receivingPubkey: Uint8Array;
214
+ tx: Transaction;
215
+ refundTx?: Transaction;
216
+ signingNonceCommitment: SigningCommitment;
217
+ vout: number;
218
+ };
219
+ declare class BaseTransferService {
220
+ protected readonly config: WalletConfigService;
221
+ protected readonly connectionManager: ConnectionManager;
222
+ protected readonly signingService: SigningService;
223
+ constructor(config: WalletConfigService, connectionManager: ConnectionManager, signingService: SigningService);
224
+ sendTransferTweakKey(transfer: Transfer, leaves: LeafKeyTweak[], refundSignatureMap: Map<string, Uint8Array>): Promise<Transfer>;
225
+ deliverTransferPackage(transfer: Transfer, leaves: LeafKeyTweak[], refundSignatureMap: Map<string, Uint8Array>): Promise<Transfer>;
226
+ sendTransferWithKeyTweaks(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array): Promise<Transfer>;
227
+ private prepareTransferPackage;
228
+ private finalizeTransfer;
229
+ signRefunds(leafDataMap: Map<string, ClaimLeafData>, operatorSigningResults: LeafRefundTxSigningResult[], adaptorPubKey?: Uint8Array): Promise<NodeSignatures[]>;
230
+ private prepareSendTransferKeyTweaks;
231
+ private prepareSingleSendTransferKeyTweak;
232
+ protected findShare(shares: VerifiableSecretShare[], operatorID: number): VerifiableSecretShare | undefined;
233
+ private compareTransfers;
234
+ }
235
+ declare class TransferService extends BaseTransferService {
236
+ constructor(config: WalletConfigService, connectionManager: ConnectionManager, signingService: SigningService);
237
+ /**
238
+ * @deprecated Use sendTransferWithKeyTweaks instead
239
+ * Deprecated in v0.1.32
240
+ */
241
+ sendTransfer(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array): Promise<Transfer>;
242
+ claimTransfer(transfer: Transfer, leaves: LeafKeyTweak[]): Promise<FinalizeNodeSignaturesResponse>;
243
+ queryPendingTransfers(): Promise<QueryTransfersResponse>;
244
+ queryAllTransfers(limit: number, offset: number): Promise<QueryTransfersResponse>;
245
+ verifyPendingTransfer(transfer: Transfer): Promise<Map<string, Uint8Array>>;
246
+ queryTransfer(transferId: string): Promise<Transfer | undefined>;
247
+ sendTransferSignRefund(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array, expiryTime: Date): Promise<{
248
+ transfer: Transfer;
249
+ signatureMap: Map<string, Uint8Array>;
250
+ leafDataMap: Map<string, LeafRefundSigningData>;
251
+ }>;
252
+ startSwapSignRefund(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array, expiryTime: Date): Promise<{
253
+ transfer: Transfer;
254
+ signatureMap: Map<string, Uint8Array>;
255
+ leafDataMap: Map<string, LeafRefundSigningData>;
256
+ }>;
257
+ counterSwapSignRefund(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array, expiryTime: Date, adaptorPubKey?: Uint8Array): Promise<{
258
+ transfer: Transfer;
259
+ signatureMap: Map<string, Uint8Array>;
260
+ leafDataMap: Map<string, LeafRefundSigningData>;
261
+ signingResults: LeafRefundTxSigningResult[];
262
+ }>;
263
+ sendTransferSignRefundInternal(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array, expiryTime: Date, forSwap: boolean, adaptorPubKey?: Uint8Array): Promise<{
264
+ transfer: Transfer;
265
+ signatureMap: Map<string, Uint8Array>;
266
+ leafDataMap: Map<string, LeafRefundSigningData>;
267
+ signingResults: LeafRefundTxSigningResult[];
268
+ }>;
269
+ private prepareRefundSoSigningJobs;
270
+ claimTransferTweakKeys(transfer: Transfer, leaves: LeafKeyTweak[]): Promise<Map<string, Uint8Array[]>>;
271
+ private prepareClaimLeavesKeyTweaks;
272
+ private prepareClaimLeafKeyTweaks;
273
+ claimTransferSignRefunds(transfer: Transfer, leafKeys: LeafKeyTweak[], proofMap?: Map<string, Uint8Array[]>): Promise<NodeSignatures[]>;
274
+ private finalizeNodeSignatures;
275
+ cancelTransfer(transfer: Transfer, operatorAddress: string): Promise<Transfer | undefined>;
276
+ queryPendingTransfersBySender(operatorAddress: string): Promise<QueryTransfersResponse>;
277
+ refreshTimelockNodes(nodes: TreeNode[], parentNode: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
278
+ extendTimelock(node: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
279
+ refreshTimelockRefundTx(node: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
280
+ }
281
+
282
+ declare const AddressNetwork: Record<NetworkType, string>;
283
+ type SparkAddressFormat = `${(typeof AddressNetwork)[keyof typeof AddressNetwork]}1${string}`;
284
+ interface SparkAddressData {
285
+ identityPublicKey: string;
286
+ network: NetworkType;
287
+ paymentIntentFields?: PaymentIntentFields;
288
+ }
289
+ interface DecodedSparkAddressData {
290
+ identityPublicKey: string;
291
+ network: NetworkType;
292
+ paymentIntentFields?: {
293
+ id: string;
294
+ assetIdentifier?: string;
295
+ assetAmount: bigint;
296
+ memo?: string;
297
+ };
298
+ }
299
+ declare function encodeSparkAddress(payload: SparkAddressData): SparkAddressFormat;
300
+ declare function decodeSparkAddress(address: string, network: NetworkType): DecodedSparkAddressData;
301
+ declare function isValidSparkAddress(address: string): boolean;
302
+ declare function isValidPublicKey(publicKey: string): void;
303
+
304
+ type Bech32mTokenIdentifier = `btk1${string}` | `btkrt1${string}` | `btkt1${string}` | `btks1${string}` | `btkl1${string}`;
305
+ interface Bech32mTokenIdentifierData {
306
+ tokenIdentifier: Uint8Array;
307
+ network: NetworkType;
308
+ }
309
+ declare function encodeBech32mTokenIdentifier(payload: Bech32mTokenIdentifierData): Bech32mTokenIdentifier;
310
+ declare function decodeBech32mTokenIdentifier(bech32mTokenIdentifier: Bech32mTokenIdentifier, network: NetworkType): Bech32mTokenIdentifierData;
311
+
312
+ type CreateLightningInvoiceParams = {
313
+ amountSats: number;
314
+ memo?: string;
315
+ expirySeconds?: number;
316
+ includeSparkAddress?: boolean;
317
+ receiverIdentityPubkey?: string;
318
+ descriptionHash?: string;
319
+ };
320
+ type PayLightningInvoiceParams = {
321
+ invoice: string;
322
+ maxFeeSats: number;
323
+ preferSpark?: boolean;
324
+ amountSatsToSend?: number;
325
+ };
326
+ type TransferParams = {
327
+ amountSats: number;
328
+ receiverSparkAddress: string;
329
+ };
330
+ type DepositParams = {
331
+ keyDerivation: KeyDerivation;
332
+ verifyingKey: Uint8Array;
333
+ depositTx: Transaction;
334
+ vout: number;
335
+ };
336
+ /**
337
+ * Token metadata containing essential information about a token.
338
+ * This is the wallet's internal representation with JavaScript-friendly types.
339
+ *
340
+ * rawTokenIdentifier: This is the raw binary token identifier - This is used to encode the bech32m encoded token identifier.
341
+ *
342
+ * tokenPublicKey: This is the hex-encoded public key of the token issuer - Same as issuerPublicKey.
343
+ *
344
+ * @example
345
+ * ```typescript
346
+ * const tokenMetadata: UserTokenMetadata = {
347
+ * rawTokenIdentifier: new Uint8Array([1, 2, 3]),
348
+ * tokenPublicKey: "0348fbb...",
349
+ * tokenName: "SparkToken",
350
+ * tokenTicker: "SPK",
351
+ * decimals: 8,
352
+ * maxSupply: 1000000n
353
+ * };
354
+ * ```
355
+ */
356
+ type UserTokenMetadata = {
357
+ /** Raw binary token identifier - This is used to encode the human readable token identifier */
358
+ rawTokenIdentifier: Uint8Array;
359
+ /** Public key of the token issuer - Same as issuerPublicKey */
360
+ tokenPublicKey: string;
361
+ /** Human-readable name of the token (e.g., SparkToken)*/
362
+ tokenName: string;
363
+ /** Short ticker symbol for the token (e.g., "SPK") */
364
+ tokenTicker: string;
365
+ /** Number of decimal places for token amounts */
366
+ decimals: number;
367
+ /** Maximum supply of tokens that can ever be minted */
368
+ maxSupply: bigint;
369
+ };
370
+ type TokenBalanceMap = Map<Bech32mTokenIdentifier, {
371
+ balance: bigint;
372
+ tokenMetadata: UserTokenMetadata;
373
+ }>;
374
+ type RawTokenIdentifierHex = string & {
375
+ readonly __brand: "RawTokenIdentifierHex";
376
+ };
377
+ type TokenOutputsMap = Map<Bech32mTokenIdentifier, OutputWithPreviousTransactionData[]>;
378
+ type TokenMetadataMap = Map<Bech32mTokenIdentifier, TokenMetadata>;
379
+ type InitWalletResponse = {
380
+ mnemonic?: string | undefined;
381
+ };
382
+ interface SparkWalletProps {
383
+ mnemonicOrSeed?: Uint8Array | string;
384
+ accountNumber?: number;
385
+ signer?: SparkSigner;
386
+ options?: ConfigOptions;
387
+ }
388
+ interface SparkWalletEvents {
389
+ /** Emitted when an incoming transfer is successfully claimed. Includes the transfer ID and new total balance. */
390
+ "transfer:claimed": (transferId: string, updatedBalance: number) => void;
391
+ /** Emitted when a deposit is marked as available. Includes the deposit ID and new total balance. */
392
+ "deposit:confirmed": (depositId: string, updatedBalance: number) => void;
393
+ /** Emitted when the stream is connected */
394
+ "stream:connected": () => void;
395
+ /** Emitted when the stream disconnects and fails to reconnect after max attempts */
396
+ "stream:disconnected": (reason: string) => void;
397
+ /** Emitted when attempting to reconnect the stream */
398
+ "stream:reconnecting": (attempt: number, maxAttempts: number, delayMs: number, error: string) => void;
399
+ }
400
+
401
+ /**
402
+ * The SparkWallet class is the primary interface for interacting with the Spark network.
403
+ * It provides methods for creating and managing wallets, handling deposits, executing transfers,
404
+ * and interacting with the Lightning Network.
405
+ */
406
+ declare class SparkWallet extends EventEmitter {
407
+ protected config: WalletConfigService;
408
+ protected connectionManager: ConnectionManager;
409
+ protected lrc20Wallet: LRCWallet | undefined;
410
+ protected transferService: TransferService;
411
+ protected tracerId: string;
412
+ private depositService;
413
+ private treeCreationService;
414
+ private lightningService;
415
+ private coopExitService;
416
+ private signingService;
417
+ private tokenTransactionService;
418
+ private claimTransferMutex;
419
+ private leavesMutex;
420
+ private optimizationInProgress;
421
+ private sspClient;
422
+ private mutexes;
423
+ private pendingWithdrawnOutputIds;
424
+ private sparkAddress;
425
+ private streamController;
426
+ protected leaves: TreeNode[];
427
+ protected tokenMetadata: TokenMetadataMap;
428
+ protected tokenOutputs: TokenOutputsMap;
429
+ private claimTransfersInterval;
430
+ protected wrapWithOtelSpan<T>(name: string, fn: (...args: any[]) => Promise<T>): (...args: any[]) => Promise<T>;
431
+ protected constructor(options?: ConfigOptions, signer?: SparkSigner);
432
+ static initialize({ mnemonicOrSeed, accountNumber, signer, options, }: SparkWalletProps): Promise<{
433
+ mnemonic?: string | undefined;
434
+ wallet: SparkWallet;
435
+ }>;
436
+ private initializeWallet;
437
+ private getSspClient;
438
+ private handleStreamEvent;
439
+ protected setupBackgroundStream(): Promise<void>;
440
+ getLeaves(isBalanceCheck?: boolean): Promise<TreeNode[]>;
441
+ private selectLeaves;
442
+ private selectLeavesForSwap;
443
+ private areLeavesInefficient;
444
+ private optimizeLeaves;
445
+ private syncWallet;
446
+ private withLeaves;
447
+ /**
448
+ * Gets the identity public key of the wallet.
449
+ *
450
+ * @returns {Promise<string>} The identity public key as a hex string.
451
+ */
452
+ getIdentityPublicKey(): Promise<string>;
453
+ /**
454
+ * Gets the Spark address of the wallet.
455
+ *
456
+ * @returns {Promise<string>} The Spark address as a hex string.
457
+ */
458
+ getSparkAddress(): Promise<SparkAddressFormat>;
459
+ createSparkPaymentIntent(assetIdentifier?: string, assetAmount?: bigint, memo?: string): Promise<SparkAddressFormat>;
460
+ /**
461
+ * Initializes the wallet using either a mnemonic phrase or a raw seed.
462
+ * initWallet will also claim any pending incoming lightning payment, spark transfer,
463
+ * or bitcoin deposit.
464
+ *
465
+ * @param {Uint8Array | string} [mnemonicOrSeed] - (Optional) Either:
466
+ * - A BIP-39 mnemonic phrase as string
467
+ * - A raw seed as Uint8Array or hex string
468
+ * If not provided, generates a new mnemonic and uses it to create a new wallet
469
+ *
470
+ * @param {number} [accountNumber] - (Optional) The account number to use for the wallet. Defaults to 1 to maintain backwards compatability for legacy mainnet wallets.
471
+ *
472
+ * @returns {Promise<Object>} Object containing:
473
+ * - mnemonic: The mnemonic if one was generated (undefined for raw seed)
474
+ * - balance: The wallet's initial balance in satoshis
475
+ * - tokenBalance: Map of token balances
476
+ * @private
477
+ */
478
+ protected initWallet(mnemonicOrSeed?: Uint8Array | string, accountNumber?: number): Promise<InitWalletResponse | undefined>;
479
+ /**
480
+ * Initializes a wallet from a seed.
481
+ *
482
+ * @param {Uint8Array | string} seed - The seed to initialize the wallet from
483
+ * @returns {Promise<string>} The identity public key
484
+ * @private
485
+ */
486
+ private initWalletFromSeed;
487
+ /**
488
+ * Gets the estimated fee for a swap of leaves.
489
+ *
490
+ * @param amountSats - The amount of sats to swap
491
+ * @returns {Promise<LeavesSwapFeeEstimateOutput>} The estimated fee for the swap
492
+ */
493
+ getSwapFeeEstimate(amountSats: number): Promise<LeavesSwapFeeEstimateOutput>;
494
+ /**
495
+ * Requests a swap of leaves to optimize wallet structure.
496
+ *
497
+ * @param {Object} params - Parameters for the leaves swap
498
+ * @param {number} [params.targetAmount] - Target amount for the swap
499
+ * @param {TreeNode[]} [params.leaves] - Specific leaves to swap
500
+ * @returns {Promise<Object>} The completed swap response
501
+ * @private
502
+ */
503
+ private requestLeavesSwap;
504
+ /**
505
+ * Processes a single batch of leaves for swapping.
506
+ */
507
+ private processSwapBatch;
508
+ /**
509
+ * Gets all transfers for the wallet.
510
+ *
511
+ * @param {number} [limit=20] - Maximum number of transfers to return
512
+ * @param {number} [offset=0] - Offset for pagination
513
+ * @returns {Promise<QueryTransfersResponse>} Response containing the list of transfers
514
+ */
515
+ getTransfers(limit?: number, offset?: number): Promise<{
516
+ transfers: WalletTransfer[];
517
+ offset: number;
518
+ }>;
519
+ /**
520
+ * Gets the current balance of the wallet.
521
+ * You can use the forceRefetch option to synchronize your wallet and claim any
522
+ * pending incoming lightning payment, spark transfer, or bitcoin deposit before returning the balance.
523
+ *
524
+ * @returns {Promise<Object>} Object containing:
525
+ * - balance: The wallet's current balance in satoshis
526
+ * - tokenBalances: Map of the bech32m encodedtoken identifier to token balances and token info
527
+ */
528
+ getBalance(): Promise<{
529
+ balance: bigint;
530
+ tokenBalances: TokenBalanceMap;
531
+ }>;
532
+ private getTokenMetadata;
533
+ private getTokenBalance;
534
+ private getInternalBalance;
535
+ /**
536
+ * Generates a new deposit address for receiving bitcoin funds.
537
+ * Note that this function returns a bitcoin address, not a spark address, and this address is single use.
538
+ * Once you deposit funds to this address, it cannot be used again.
539
+ * For Layer 1 Bitcoin deposits, Spark generates Pay to Taproot (P2TR) addresses.
540
+ * These addresses start with "bc1p" and can be used to receive Bitcoin from any wallet.
541
+ *
542
+ * @returns {Promise<string>} A Bitcoin address for depositing funds
543
+ */
544
+ getSingleUseDepositAddress(): Promise<string>;
545
+ /**
546
+ * Generates a new static deposit address for receiving bitcoin funds.
547
+ * This address is permanent and can be used multiple times.
548
+ *
549
+ * @returns {Promise<string>} A Bitcoin address for depositing funds
550
+ */
551
+ getStaticDepositAddress(): Promise<string>;
552
+ /**
553
+ * Generates a deposit address for receiving funds.
554
+ *
555
+ * @param {boolean} static - Whether the address is static or single use
556
+ * @returns {Promise<string>} A deposit address
557
+ * @private
558
+ */
559
+ private generateDepositAddress;
560
+ queryStaticDepositAddresses(): Promise<string[]>;
561
+ /**
562
+ * Get a quote on how much credit you can claim for a deposit from the SSP.
563
+ *
564
+ * @param {string} transactionId - The ID of the transaction
565
+ * @param {number} [outputIndex] - The index of the output
566
+ * @returns {Promise<StaticDepositQuoteOutput>} Quote for claiming a deposit to a static deposit address
567
+ */
568
+ getClaimStaticDepositQuote(transactionId: string, outputIndex?: number): Promise<StaticDepositQuoteOutput>;
569
+ /**
570
+ * Claims a deposit to a static deposit address.
571
+ *
572
+ * @param {string} transactionId - The ID of the transaction
573
+ * @param {number} creditAmountSats - The amount of credit to claim
574
+ * @param {string} sspSignature - The SSP signature for the deposit
575
+ * @param {number} [outputIndex] - The index of the output
576
+ * @returns {Promise<RequestClaimDepositQuoteOutput | null>} Quote for claiming a deposit to a static deposit address
577
+ */
578
+ claimStaticDeposit({ transactionId, creditAmountSats, sspSignature, outputIndex, }: {
579
+ transactionId: string;
580
+ creditAmountSats: number;
581
+ sspSignature: string;
582
+ outputIndex?: number;
583
+ }): Promise<ClaimStaticDepositOutput | null>;
584
+ /**
585
+ * Refunds a static deposit to a destination address.
586
+ *
587
+ * @param {string} depositTransactionId - The ID of the transaction
588
+ * @param {number} [outputIndex] - The index of the output
589
+ * @param {string} destinationAddress - The destination address
590
+ * @param {number} fee - The fee to refund
591
+ * @returns {Promise<string>} The hex of the refund transaction
592
+ */
593
+ refundStaticDeposit({ depositTransactionId, outputIndex, destinationAddress, fee, }: {
594
+ depositTransactionId: string;
595
+ outputIndex?: number;
596
+ destinationAddress: string;
597
+ fee: number;
598
+ }): Promise<string>;
599
+ private getStaticDepositSigningPayload;
600
+ private getDepositTransactionVout;
601
+ private getDepositTransaction;
602
+ /**
603
+ * Finalizes a deposit to the wallet.
604
+ *
605
+ * @param {DepositParams} params - Parameters for finalizing the deposit
606
+ * @returns {Promise<void>} The nodes created from the deposit
607
+ * @private
608
+ */
609
+ private finalizeDeposit;
610
+ /**
611
+ * Gets all unused deposit addresses for the wallet.
612
+ *
613
+ * @returns {Promise<string[]>} The unused deposit addresses
614
+ */
615
+ getUnusedDepositAddresses(): Promise<string[]>;
616
+ /**
617
+ * Gets all unused deposit addresses for the wallet.
618
+ *
619
+ * @param {Object} params - Parameters for querying unused deposit addresses
620
+ * @param {Uint8Array<ArrayBufferLike>} [params.identityPublicKey] - The identity public key
621
+ * @param {NetworkProto} [params.network] - The network
622
+ * @returns {Promise<DepositAddressQueryResult[]>} The unused deposit addresses
623
+ */
624
+ private queryAllUnusedDepositAddresses;
625
+ /**
626
+ * Claims a deposit to the wallet.
627
+ * Note that if you used advancedDeposit, you don't need to call this function.
628
+ * @param {string} txid - The transaction ID of the deposit
629
+ * @returns {Promise<WalletLeaf[] | undefined>} The nodes resulting from the deposit
630
+ */
631
+ claimDeposit(txid: string): Promise<WalletLeaf[]>;
632
+ /**
633
+ * Non-trusty flow for depositing funds to the wallet.
634
+ * Construct the tx spending from an L1 wallet to the Spark address.
635
+ * After calling this function, you must sign and broadcast the tx.
636
+ *
637
+ * @param {string} txHex - The hex string of the transaction to deposit
638
+ * @returns {Promise<TreeNode[] | undefined>} The nodes resulting from the deposit
639
+ */
640
+ advancedDeposit(txHex: string): Promise<TreeNode[]>;
641
+ /**
642
+ * Transfers deposit to self to claim ownership.
643
+ *
644
+ * @param {TreeNode[]} leaves - The leaves to transfer
645
+ * @param {Uint8Array} signingPubKey - The signing public key
646
+ * @returns {Promise<TreeNode[] | undefined>} The nodes resulting from the transfer
647
+ * @private
648
+ */
649
+ private transferLeavesToSelf;
650
+ /**
651
+ * Sends a transfer to another Spark user.
652
+ *
653
+ * @param {TransferParams} params - Parameters for the transfer
654
+ * @param {string} params.receiverSparkAddress - The recipient's Spark address
655
+ * @param {number} params.amountSats - Amount to send in satoshis
656
+ * @returns {Promise<WalletTransfer>} The completed transfer details
657
+ */
658
+ transfer({ amountSats, receiverSparkAddress, }: TransferParams): Promise<WalletTransfer>;
659
+ private checkExtendTimeLockNodes;
660
+ /**
661
+ * Internal method to refresh timelock nodes.
662
+ *
663
+ * @param {string} nodeId - The optional ID of the node to refresh. If not provided, all nodes will be checked.
664
+ * @returns {Promise<void>}
665
+ * @private
666
+ */
667
+ private checkRefreshTimelockNodes;
668
+ /**
669
+ * Claims a specific transfer.
670
+ *
671
+ * @param {Transfer} transfer - The transfer to claim
672
+ * @returns {Promise<Object>} The claim result
673
+ */
674
+ private claimTransfer;
675
+ /**
676
+ * Claims all pending transfers.
677
+ *
678
+ * @returns {Promise<string[]>} Array of successfully claimed transfer IDs
679
+ * @private
680
+ */
681
+ private claimTransfers;
682
+ /**
683
+ * Cancels all sender-initiated transfers.
684
+ *
685
+ * @returns {Promise<void>}
686
+ * @private
687
+ */
688
+ private cancelAllSenderInitiatedTransfers;
689
+ /**
690
+ * Creates a Lightning invoice for receiving payments.
691
+ *
692
+ * @param {Object} params - Parameters for the lightning invoice
693
+ * @param {number} params.amountSats - Amount in satoshis
694
+ * @param {string} [params.memo] - Description for the invoice. Should not be provided if the descriptionHash is provided.
695
+ * @param {number} [params.expirySeconds] - Optional expiry time in seconds
696
+ * @param {boolean} [params.includeSparkAddress] - Optional boolean signalling whether or not to include the spark address in the invoice
697
+ * @param {string} [params.receiverIdentityPubkey] - Optional public key of the wallet receiving the lightning invoice. If not present, the receiver will be the creator of this request.
698
+ * @param {string} [params.descriptionHash] - Optional h tag of the invoice. This is the hash of a longer description to include in the lightning invoice. It is used in LNURL and UMA as the hash of the metadata. This field is mutually exclusive with the memo field. Only one or the other should be provided.
699
+ * @returns {Promise<LightningReceiveRequest>} BOLT11 encoded invoice
700
+ */
701
+ createLightningInvoice({ amountSats, memo, expirySeconds, includeSparkAddress, receiverIdentityPubkey, descriptionHash, }: CreateLightningInvoiceParams): Promise<LightningReceiveRequest>;
702
+ /**
703
+ * Pays a Lightning invoice.
704
+ *
705
+ * @param {Object} params - Parameters for paying the invoice
706
+ * @param {string} params.invoice - The BOLT11-encoded Lightning invoice to pay
707
+ * @param {boolean} [params.preferSpark] - Whether to prefer a spark transfer over lightning for the payment
708
+ * @param {number} [params.amountSatsToSend] - The amount in sats to send. This is only valid for 0 amount lightning invoices.
709
+ * @returns {Promise<LightningSendRequest>} The Lightning payment request details
710
+ */
711
+ payLightningInvoice({ invoice, maxFeeSats, preferSpark, amountSatsToSend, }: PayLightningInvoiceParams): Promise<LightningSendRequest | WalletTransfer>;
712
+ /**
713
+ * Gets fee estimate for sending Lightning payments.
714
+ *
715
+ * @param {LightningSendFeeEstimateInput} params - Input parameters for fee estimation
716
+ * @returns {Promise<number>} Fee estimate for sending Lightning payments
717
+ */
718
+ getLightningSendFeeEstimate({ encodedInvoice, amountSats, }: LightningSendFeeEstimateInput): Promise<number>;
719
+ /**
720
+ * Generates a deposit address for a tree.
721
+ *
722
+ * @param {number} vout - The vout index
723
+ * @param {Uint8Array} parentSigningPubKey - The parent signing public key
724
+ * @param {Transaction} [parentTx] - Optional parent transaction
725
+ * @param {TreeNode} [parentNode] - Optional parent node
726
+ * @returns {Promise<Object>} Deposit address information
727
+ * @private
728
+ */
729
+ private generateDepositAddressForTree;
730
+ /**
731
+ * Creates a tree structure.
732
+ *
733
+ * @param {number} vout - The vout index
734
+ * @param {DepositAddressTree} root - The root of the tree
735
+ * @param {boolean} createLeaves - Whether to create leaves
736
+ * @param {Transaction} [parentTx] - Optional parent transaction
737
+ * @param {TreeNode} [parentNode] - Optional parent node
738
+ * @returns {Promise<Object>} The created tree
739
+ * @private
740
+ */
741
+ private createTree;
742
+ /**
743
+ * Initiates a withdrawal to move funds from the Spark network to an on-chain Bitcoin address.
744
+ *
745
+ * @param {Object} params - Parameters for the withdrawal
746
+ * @param {string} params.onchainAddress - The Bitcoin address where the funds should be sent
747
+ * @param {CoopExitFeeQuote} params.feeQuote - The fee quote for the withdrawal
748
+ * @param {ExitSpeed} params.exitSpeed - The exit speed chosen for the withdrawal
749
+ * @param {number} [params.amountSats] - The amount in satoshis to withdraw. If not specified, attempts to withdraw all available funds and deductFeeFromWithdrawalAmount is set to true.
750
+ * @param {boolean} [params.deductFeeFromWithdrawalAmount] - Controls how the withdrawal fee is handled. If true, the fee is deducted from the withdrawal amount (amountSats), meaning the recipient will receive amountSats minus the fee. If false, the fee is paid separately from the wallet balance, meaning the recipient will receive the full amountSats.
751
+ * @returns {Promise<CoopExitRequest | null | undefined>} The withdrawal request details, or null/undefined if the request cannot be completed
752
+ */
753
+ withdraw({ onchainAddress, exitSpeed, feeQuote, amountSats, deductFeeFromWithdrawalAmount, }: {
754
+ onchainAddress: string;
755
+ exitSpeed: ExitSpeed;
756
+ feeQuote: CoopExitFeeQuote;
757
+ amountSats?: number;
758
+ deductFeeFromWithdrawalAmount?: boolean;
759
+ }): Promise<CoopExitRequest | null>;
760
+ /**
761
+ * Internal method to perform a cooperative exit (withdrawal).
762
+ *
763
+ * @param {string} onchainAddress - The Bitcoin address where the funds should be sent
764
+ * @param {number} [targetAmountSats] - The amount in satoshis to withdraw
765
+ * @returns {Promise<Object | null | undefined>} The exit request details
766
+ * @private
767
+ */
768
+ private coopExit;
769
+ /**
770
+ * Gets fee estimate for cooperative exit (on-chain withdrawal).
771
+ *
772
+ * @param {Object} params - Input parameters for fee estimation
773
+ * @param {number} params.amountSats - The amount in satoshis to withdraw
774
+ * @param {string} params.withdrawalAddress - The Bitcoin address where the funds should be sent
775
+ * @returns {Promise<CoopExitFeeQuote | null>} Fee estimate for the withdrawal
776
+ */
777
+ getWithdrawalFeeQuote({ amountSats, withdrawalAddress, }: {
778
+ amountSats: number;
779
+ withdrawalAddress: string;
780
+ }): Promise<CoopExitFeeQuote | null>;
781
+ /**
782
+ * Gets a transfer that has been sent by the SSP to the wallet.
783
+ *
784
+ * @param {string} id - The ID of the transfer
785
+ * @returns {Promise<GraphQLTransferObj | null>} The transfer
786
+ */
787
+ getTransferFromSsp(id: string): Promise<Transfer$1 | null>;
788
+ /**
789
+ * Gets a transfer, that the wallet is a participant of, in the Spark network.
790
+ * Only contains data about the spark->spark transfer, use getTransferFromSsp if you're
791
+ * looking for information related to a lightning transfer.
792
+ *
793
+ * @param {string} id - The ID of the transfer
794
+ * @returns {Promise<Transfer | undefined>} The transfer
795
+ */
796
+ getTransfer(id: string): Promise<WalletTransfer | undefined>;
797
+ /**
798
+ * Synchronizes token outputs for the wallet.
799
+ *
800
+ * @returns {Promise<void>}
801
+ * @private
802
+ */
803
+ protected syncTokenOutputs(): Promise<void>;
804
+ /**
805
+ * Transfers tokens to another user.
806
+ *
807
+ * @param {Object} params - Parameters for the token transfer
808
+ * @param {string} params.tokenPublicKey - The public key of the token to transfer
809
+ * @param {bigint} params.tokenAmount - The amount of tokens to transfer
810
+ * @param {string} params.receiverSparkAddress - The recipient's public key
811
+ * @param {OutputWithPreviousTransactionData[]} [params.selectedOutputs] - Optional specific leaves to use for the transfer
812
+ * @returns {Promise<string>} The transaction ID of the token transfer
813
+ */
814
+ transferTokens({ tokenIdentifier, tokenAmount, receiverSparkAddress, outputSelectionStrategy, selectedOutputs, }: {
815
+ tokenIdentifier: Bech32mTokenIdentifier;
816
+ tokenAmount: bigint;
817
+ receiverSparkAddress: string;
818
+ outputSelectionStrategy?: "SMALL_FIRST" | "LARGE_FIRST";
819
+ selectedOutputs?: OutputWithPreviousTransactionData[];
820
+ }): Promise<string>;
821
+ /**
822
+ * Transfers tokens with multiple outputs
823
+ *
824
+ * @param {Array} receiverOutputs - Array of transfer parameters
825
+ * @param {string} receiverOutputs[].tokenPublicKey - The public key of the token to transfer
826
+ * @param {bigint} receiverOutputs[].tokenAmount - The amount of tokens to transfer
827
+ * @param {string} receiverOutputs[].receiverSparkAddress - The recipient's public key
828
+ * @param {OutputWithPreviousTransactionData[]} [selectedOutputs] - Optional specific leaves to use for the transfer
829
+ * @returns {Promise<string[]>} Array of transaction IDs for the token transfers
830
+ */
831
+ batchTransferTokens(receiverOutputs: {
832
+ tokenIdentifier: Bech32mTokenIdentifier;
833
+ tokenAmount: bigint;
834
+ receiverSparkAddress: string;
835
+ }[], outputSelectionStrategy?: "SMALL_FIRST" | "LARGE_FIRST", selectedOutputs?: OutputWithPreviousTransactionData[]): Promise<string>;
836
+ /**
837
+ * Retrieves token transaction history for specified tokens
838
+ * Can optionally filter by specific transaction hashes.
839
+ *
840
+ * @param ownerPublicKeys - Optional array of owner public keys to query transactions for
841
+ * @param issuerPublicKeys - Optional array of issuer public keys to query transactions for
842
+ * @param tokenTransactionHashes - Optional array of specific transaction hashes to filter by
843
+ * @param tokenIdentifiers - Optional array of token identifiers to filter by
844
+ * @param outputIds - Optional array of output IDs to filter by
845
+ * @returns Promise resolving to array of token transactions with their current status
846
+ */
847
+ queryTokenTransactions({ ownerPublicKeys, issuerPublicKeys, tokenTransactionHashes, tokenIdentifiers, outputIds, }: {
848
+ ownerPublicKeys?: string[];
849
+ issuerPublicKeys?: string[];
850
+ tokenTransactionHashes?: string[];
851
+ tokenIdentifiers?: string[];
852
+ outputIds?: string[];
853
+ }): Promise<TokenTransactionWithStatus[]>;
854
+ getTokenL1Address(): Promise<string>;
855
+ /**
856
+ * Signs a message with the identity key.
857
+ *
858
+ * @param {string} message - The message to sign
859
+ * @param {boolean} [compact] - Whether to use compact encoding. If false, the message will be encoded as DER.
860
+ * @returns {Promise<string>} The signed message
861
+ */
862
+ signMessageWithIdentityKey(message: string, compact?: boolean): Promise<string>;
863
+ /**
864
+ * Validates a message with the identity key.
865
+ *
866
+ * @param {string} message - The original message that was signed
867
+ * @param {string | Uint8Array} signature - Signature to validate
868
+ * @returns {Promise<boolean>} Whether the message is valid
869
+ */
870
+ validateMessageWithIdentityKey(message: string, signature: string | Uint8Array): Promise<boolean>;
871
+ /**
872
+ * Signs a transaction with wallet keys.
873
+ *
874
+ * @param {string} txHex - The transaction hex to sign
875
+ * @param {string} keyType - The type of key to use for signing ("identity", "deposit", or "auto-detect")
876
+ * @returns {Promise<string>} The signed transaction hex
877
+ */
878
+ signTransaction(txHex: string, keyType?: string): Promise<string>;
879
+ /**
880
+ * Helper method to auto-detect which key should be used for signing a transaction.
881
+ */
882
+ private detectKeyForTransaction;
883
+ /**
884
+ * Get a Lightning receive request by ID.
885
+ *
886
+ * @param {string} id - The ID of the Lightning receive request
887
+ * @returns {Promise<LightningReceiveRequest | null>} The Lightning receive request
888
+ */
889
+ getLightningReceiveRequest(id: string): Promise<LightningReceiveRequest | null>;
890
+ /**
891
+ * Get a Lightning send request by ID.
892
+ *
893
+ * @param {string} id - The ID of the Lightning send request
894
+ * @returns {Promise<LightningSendRequest | null>} The Lightning send request
895
+ */
896
+ getLightningSendRequest(id: string): Promise<LightningSendRequest | null>;
897
+ /**
898
+ * Get a coop exit request by ID.
899
+ *
900
+ * @param {string} id - The ID of the coop exit request
901
+ * @returns {Promise<CoopExitRequest | null>} The coop exit request
902
+ */
903
+ getCoopExitRequest(id: string): Promise<CoopExitRequest | null>;
904
+ /**
905
+ * Check the remaining timelock on a given node.
906
+ *
907
+ * @param {string} nodeId - The ID of the node to check
908
+ * @returns {Promise<{nodeTimelock: number, refundTimelock: number}>} The remaining timelocks in blocks for both node and refund transactions
909
+ */
910
+ checkTimelock(nodeId: string): Promise<{
911
+ nodeTimelock: number;
912
+ refundTimelock: number;
913
+ }>;
914
+ /**
915
+ * Refresh the timelock of a specific node.
916
+ *
917
+ * @param {string} nodeId - The ID of the node to refresh
918
+ * @returns {Promise<void>} Promise that resolves when the timelock is refreshed
919
+ */
920
+ testOnly_expireTimelock(nodeId: string): Promise<void>;
921
+ /**
922
+ * Refresh the timelock of a specific node's refund transaction only.
923
+ *
924
+ * @param {string} nodeId - The ID of the node whose refund transaction to refresh
925
+ * @returns {Promise<void>} Promise that resolves when the refund timelock is refreshed
926
+ */
927
+ testOnly_expireTimelockRefundTx(nodeId: string): Promise<void>;
928
+ private cleanup;
929
+ cleanupConnections(): Promise<void>;
930
+ private startPeriodicClaimTransfers;
931
+ private updateLeaves;
932
+ private queryNodes;
933
+ }
934
+
935
+ export { type Bech32mTokenIdentifier as B, type ConfigOptions as C, type DecodedSparkAddressData as D, type InitWalletResponse as I, LRC_WALLET_NETWORK as L, Network as N, type PayLightningInvoiceParams as P, type RawTokenIdentifierHex as R, type SparkAddressData as S, type TokenOutputsMap as T, type UserTokenMetadata as U, WalletConfigService as W, type Bech32mTokenIdentifierData as a, LRC_WALLET_NETWORK_TYPE as b, NetworkToProto as c, type NetworkType as d, type SparkAddressFormat as e, decodeBech32mTokenIdentifier as f, decodeSparkAddress as g, encodeBech32mTokenIdentifier as h, encodeSparkAddress as i, getNetwork as j, getNetworkFromAddress as k, getNetworkFromString as l, isValidPublicKey as m, isValidSparkAddress as n, SparkWallet as o, protoToNetwork as p, type SparkWalletProps as q, type TokenBalanceMap as r, ConnectionManager as s, WalletConfig as t, type CreateLightningInvoiceParams as u, type TransferParams as v, type DepositParams as w, type TokenMetadataMap as x, type SparkWalletEvents as y };