@buildonspark/spark-sdk 0.3.7 → 0.3.8

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 (84) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/bare/index.cjs +8359 -7810
  3. package/dist/bare/index.d.cts +260 -208
  4. package/dist/bare/index.d.ts +260 -208
  5. package/dist/bare/index.js +8241 -7689
  6. package/dist/{chunk-P4HYYSMU.js → chunk-3LPEQGVJ.js} +1 -1
  7. package/dist/{chunk-J2P3KTQP.js → chunk-5ASXVNTM.js} +1 -1
  8. package/dist/{chunk-UYTT3C6H.js → chunk-5HU5W56H.js} +40 -213
  9. package/dist/{chunk-KDEVNW7C.js → chunk-FP2CRVQH.js} +3256 -2714
  10. package/dist/{chunk-SRPKOCG4.js → chunk-FXIESWE6.js} +8 -10
  11. package/dist/{chunk-IC4IUEOS.js → chunk-VFN34EOX.js} +56 -43
  12. package/dist/{chunk-XWLR6G5C.js → chunk-XI6FCNYG.js} +1 -1
  13. package/dist/{client-D9T58OY8.d.ts → client-By-N7oJS.d.ts} +2 -2
  14. package/dist/{client-Bcb7TUIp.d.cts → client-pNpGP15j.d.cts} +2 -2
  15. package/dist/debug.cjs +8371 -7822
  16. package/dist/debug.d.cts +12 -8
  17. package/dist/debug.d.ts +12 -8
  18. package/dist/debug.js +5 -5
  19. package/dist/graphql/objects/index.d.cts +3 -3
  20. package/dist/graphql/objects/index.d.ts +3 -3
  21. package/dist/index.cjs +6990 -6438
  22. package/dist/index.d.cts +8 -7
  23. package/dist/index.d.ts +8 -7
  24. package/dist/index.js +12 -6
  25. package/dist/index.node.cjs +6515 -6134
  26. package/dist/index.node.d.cts +8 -7
  27. package/dist/index.node.d.ts +8 -7
  28. package/dist/index.node.js +11 -5
  29. package/dist/{logging-JIaZZIbR.d.ts → logging-DMFVY384.d.ts} +10 -4
  30. package/dist/{logging-zkr4UlOi.d.cts → logging-DxLp34Xm.d.cts} +10 -4
  31. package/dist/native/{chunk-X2QXUON7.js → chunk-AFP5QR4O.js} +11 -8
  32. package/dist/native/index.react-native.cjs +6981 -6422
  33. package/dist/native/index.react-native.d.cts +91 -39
  34. package/dist/native/index.react-native.d.ts +91 -39
  35. package/dist/native/index.react-native.js +6925 -6366
  36. package/dist/native/{wasm-GKEDPGTM.js → wasm-D4TI35NF.js} +1 -1
  37. package/dist/proto/spark.cjs +56 -43
  38. package/dist/proto/spark.d.cts +1 -1
  39. package/dist/proto/spark.d.ts +1 -1
  40. package/dist/proto/spark.js +1 -1
  41. package/dist/proto/spark_token.d.cts +1 -1
  42. package/dist/proto/spark_token.d.ts +1 -1
  43. package/dist/proto/spark_token.js +2 -2
  44. package/dist/{spark-WA_4wcBr.d.cts → spark-By6yHsrk.d.cts} +31 -6
  45. package/dist/{spark-WA_4wcBr.d.ts → spark-By6yHsrk.d.ts} +31 -6
  46. package/dist/{spark-wallet.browser-BwYkkOBU.d.ts → spark-wallet.browser-C1dQknVj.d.ts} +8 -8
  47. package/dist/{spark-wallet.browser-DC3jdQPW.d.cts → spark-wallet.browser-CNMo3IvO.d.cts} +8 -8
  48. package/dist/{spark-wallet.node-CR_zNxmy.d.cts → spark-wallet.node-BZJhJZKq.d.cts} +9 -31
  49. package/dist/{spark-wallet.node-C9d2W-Nb.d.ts → spark-wallet.node-Og6__NMh.d.ts} +9 -31
  50. package/dist/tests/test-utils.cjs +8466 -8080
  51. package/dist/tests/test-utils.d.cts +7 -5
  52. package/dist/tests/test-utils.d.ts +7 -5
  53. package/dist/tests/test-utils.js +7 -7
  54. package/dist/{token-transactions-BZoJuvuE.d.ts → token-transactions-C7yefB2S.d.ts} +2 -2
  55. package/dist/{token-transactions-I_OFIoNH.d.cts → token-transactions-CLR3rnYi.d.cts} +2 -2
  56. package/dist/types/index.cjs +56 -43
  57. package/dist/types/index.d.cts +2 -2
  58. package/dist/types/index.d.ts +2 -2
  59. package/dist/types/index.js +2 -2
  60. package/dist/{spark-wallet-CE5PYiIb.d.ts → wallet-config-BoyMVa6n.d.ts} +290 -265
  61. package/dist/{spark-wallet-BuFrUWeE.d.cts → wallet-config-xom-9UFF.d.cts} +290 -265
  62. package/package.json +3 -3
  63. package/src/proto/mock.ts +0 -264
  64. package/src/proto/spark.ts +94 -51
  65. package/src/services/config.ts +5 -0
  66. package/src/services/connection/connection.browser.ts +27 -19
  67. package/src/services/connection/connection.node.ts +79 -24
  68. package/src/services/connection/connection.ts +395 -233
  69. package/src/services/lightning.ts +30 -4
  70. package/src/services/signing.ts +137 -0
  71. package/src/services/transfer.ts +116 -1
  72. package/src/services/wallet-config.ts +6 -0
  73. package/src/spark-wallet/proto-descriptors.ts +1 -1
  74. package/src/spark-wallet/spark-wallet.ts +70 -76
  75. package/src/spark_descriptors.pb +0 -0
  76. package/src/tests/connection.test.ts +537 -0
  77. package/src/tests/integration/connection.test.ts +39 -0
  78. package/src/tests/integration/lightning.test.ts +25 -11
  79. package/src/tests/integration/static_deposit.test.ts +11 -10
  80. package/src/tests/integration/transfer.test.ts +13 -1
  81. package/src/tests/isHermeticTest.ts +1 -1
  82. package/src/tests/utils/test-faucet.ts +53 -20
  83. package/src/utils/htlc-transactions.ts +224 -0
  84. package/src/utils/transaction.ts +36 -0
@@ -1,13 +1,14 @@
1
- import { B as BitcoinNetwork, M as MayHaveSspClientOptions, t as SspClientOptions, H as HasSspClientOptions, S as SparkSigner, l as KeyDerivation, i as SigningCommitmentWithOptionalNonce, V as VerifiableSecretShare, W as WalletTransfer, D as DefaultSparkSigner, L as LeavesSwapFeeEstimateOutput, u as StaticDepositQuoteOutput, C as ClaimStaticDepositOutput, w as WalletLeaf, x as LightningReceiveRequest, y as LightningSendRequest, z as LightningSendFeeEstimateInput, E as ExitSpeed, F as CoopExitFeeQuote, G as CoopExitRequest, I as TransferWithUserRequest } from './client-Bcb7TUIp.cjs';
2
- import { N as Network$1, d as SparkServiceClient, b as SparkServiceDefinition, e as SparkInvoiceFields, R as RequestedSigningCommitments, U as UserSignedTxSigningJob, c as TreeNode, T as Transfer, L as LeafRefundTxSigningResult, f as NodeSignatures, F as FinalizeNodeSignaturesResponse, Q as QueryTransfersResponse, O as OutputWithPreviousTransactionData, g as QuerySparkInvoicesResponse } from './spark-WA_4wcBr.cjs';
3
- import { SparkTokenServiceClient, SparkTokenServiceDefinition, TokenMetadata, QueryTokenTransactionsResponse } from './proto/spark_token.cjs';
1
+ import { B as BitcoinNetwork, H as HasSspClientOptions, S as SparkSigner, t as SspClientOptions, l as KeyDerivation, i as SigningCommitmentWithOptionalNonce, V as VerifiableSecretShare, D as DefaultSparkSigner, L as LeavesSwapFeeEstimateOutput, u as StaticDepositQuoteOutput, C as ClaimStaticDepositOutput, W as WalletLeaf, w as WalletTransfer, x as LightningReceiveRequest, y as LightningSendRequest, z as LightningSendFeeEstimateInput, E as ExitSpeed, F as CoopExitFeeQuote, G as CoopExitRequest, I as TransferWithUserRequest, M as MayHaveSspClientOptions } from './client-pNpGP15j.cjs';
4
2
  import * as btc from '@scure/btc-signer';
5
3
  import { Transaction } from '@scure/btc-signer';
4
+ import { N as Network$1, e as SparkInvoiceFields, b as SparkServiceDefinition, f as SparkServiceClient, d as SubscribeToEventsResponse, R as RequestedSigningCommitments, U as UserSignedTxSigningJob, c as TreeNode, T as Transfer, g as StartTransferRequest, L as LeafRefundTxSigningResult, h as NodeSignatures, F as FinalizeNodeSignaturesResponse, Q as QueryTransfersResponse, i as QuerySparkInvoicesResponse, O as OutputWithPreviousTransactionData } from './spark-By6yHsrk.cjs';
5
+ import { SparkTokenServiceDefinition, SparkTokenServiceClient, QueryTokenTransactionsResponse, TokenMetadata } from './proto/spark_token.cjs';
6
+ import * as _scure_base from '@scure/base';
6
7
  import { Channel } from 'nice-grpc';
7
- import { CallOptions, ClientMiddlewareCall, Metadata } from 'nice-grpc-common';
8
+ import { CallOptions, ClientMiddleware, ClientMiddlewareCall, Metadata } from 'nice-grpc-common';
8
9
  import { Channel as Channel$1 } from 'nice-grpc-web';
9
10
  import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
10
- import * as _scure_base from '@scure/base';
11
+ import { RetryOptions as RetryOptions$1 } from 'nice-grpc-client-middleware-retry';
11
12
  import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
12
13
  import { EventEmitter } from 'eventemitter3';
13
14
 
@@ -37,37 +38,61 @@ declare function getNetworkFromAddress(address: string): BitcoinNetwork.MAINNET
37
38
  */
38
39
  declare function getNetworkFromString(network?: string): Network;
39
40
 
40
- type SigningOperator = {
41
- readonly id: number;
42
- readonly identifier: string;
43
- readonly address: string;
44
- readonly identityPublicKey: string;
45
- };
46
- type ConsoleOptions = {
47
- otel?: boolean;
48
- };
49
- type ConfigOptions = MayHaveSspClientOptions & {
50
- readonly network?: NetworkType;
51
- readonly signingOperators?: Readonly<Record<string, SigningOperator>>;
52
- readonly coordinatorIdentifier?: string;
53
- readonly frostSignerAddress?: string;
54
- readonly threshold?: number;
55
- readonly tokenSignatures?: "ECDSA" | "SCHNORR";
56
- readonly tokenValidityDurationSeconds?: number;
57
- readonly electrsUrl?: string;
58
- readonly sspClientOptions?: SspClientOptions;
59
- readonly expectedWithdrawBondSats?: number;
60
- readonly expectedWithdrawRelativeBlockLocktime?: number;
61
- readonly signerWithPreExistingKeys?: boolean;
62
- readonly console?: ConsoleOptions;
63
- };
64
- declare const WalletConfig: {
65
- LOCAL: Required<ConfigOptions>;
66
- LOCAL_SCHNORR: Required<ConfigOptions>;
67
- LOCAL_ECDSA: Required<ConfigOptions>;
68
- REGTEST: Required<ConfigOptions>;
69
- MAINNET: Required<ConfigOptions>;
41
+ type Bech32mTokenIdentifier = `btkn1${string}` | `btknrt1${string}` | `btknt1${string}` | `btkns1${string}` | `btknl1${string}`;
42
+ interface Bech32mTokenIdentifierData {
43
+ tokenIdentifier: Uint8Array;
44
+ network: NetworkType;
45
+ }
46
+ declare function encodeBech32mTokenIdentifier(payload: Bech32mTokenIdentifierData): Bech32mTokenIdentifier;
47
+ declare function decodeBech32mTokenIdentifier(bech32mTokenIdentifier: Bech32mTokenIdentifier, network?: NetworkType): Bech32mTokenIdentifierData;
48
+ declare function getNetworkFromBech32mTokenIdentifier(bech32mTokenIdentifier: Bech32mTokenIdentifier): NetworkType;
49
+
50
+ declare const AddressNetwork: Record<NetworkType, string>;
51
+ declare const LegacyAddressNetwork: Record<NetworkType, string>;
52
+ type Bech32String = `${string}1${string}`;
53
+ type SparkAddressFormat = `${(typeof AddressNetwork)[keyof typeof AddressNetwork]}1${string}`;
54
+ type LegacySparkAddressFormat = `${(typeof LegacyAddressNetwork)[keyof typeof LegacyAddressNetwork]}1${string}`;
55
+ interface SparkAddressData {
56
+ identityPublicKey: string;
57
+ network: NetworkType;
58
+ sparkInvoiceFields?: SparkInvoiceFields;
59
+ }
60
+ interface DecodedSparkAddressData {
61
+ identityPublicKey: string;
62
+ network: NetworkType;
63
+ sparkInvoiceFields?: {
64
+ version: number;
65
+ id: string;
66
+ paymentType?: {
67
+ type: "tokens";
68
+ tokenIdentifier?: string;
69
+ amount?: bigint;
70
+ } | {
71
+ type: "sats";
72
+ amount?: number;
73
+ };
74
+ memo?: string;
75
+ senderPublicKey?: string;
76
+ expiryTime?: Date;
77
+ };
78
+ signature?: string;
79
+ }
80
+ declare function encodeSparkAddress(payload: SparkAddressData): LegacySparkAddressFormat;
81
+ declare function encodeSparkAddressWithSignature(payload: SparkAddressData, signature?: Uint8Array): LegacySparkAddressFormat;
82
+ declare function decodeSparkAddress(address: string, network: NetworkType): DecodedSparkAddressData;
83
+ declare function getNetworkFromSparkAddress(address: string): NetworkType;
84
+ declare function isLegacySparkAddress(address: string): address is LegacySparkAddressFormat;
85
+ declare function isValidSparkAddress(address: string): boolean;
86
+ declare function isValidPublicKey(publicKey: string): void;
87
+ declare function validateSparkInvoiceFields(sparkInvoiceFields: SparkInvoiceFields): void;
88
+ declare function validateSparkInvoiceSignature(invoice: SparkAddressFormat): void;
89
+ declare function toProtoTimestamp(date: Date): {
90
+ seconds: number;
91
+ nanos: number;
70
92
  };
93
+ declare function assertBech32(s: string): asserts s is Bech32String;
94
+ declare function bech32mDecode(address: string): _scure_base.Bech32Decoded<string>;
95
+ declare function isSafeForNumber(bi: bigint): boolean;
71
96
 
72
97
  declare class WalletConfigService implements HasSspClientOptions {
73
98
  private readonly config;
@@ -91,6 +116,7 @@ declare class WalletConfigService implements HasSspClientOptions {
91
116
  getSspBaseUrl(): string;
92
117
  getSspIdentityPublicKey(): string;
93
118
  getConsoleOptions(): ConsoleOptions;
119
+ getEvents(): Partial<SparkWalletEvents>;
94
120
  }
95
121
 
96
122
  /** Challenge represents the core challenge data */
@@ -195,87 +221,55 @@ interface RetryOptions {
195
221
  }
196
222
  type SparkCallOptions = CallOptions & RetryOptions;
197
223
 
198
- declare class ConnectionManager {
199
- private config;
200
- protected clients: Map<string, {
201
- client: SparkServiceClient & {
202
- close?: () => void;
203
- };
204
- authToken: string;
224
+ type ChannelKey = string;
225
+ type BrowserOrNodeJSChannel = Channel | Channel$1;
226
+ type SparkClientType = "spark" | "stream" | "tokens";
227
+ type Address = string;
228
+ declare abstract class ConnectionManager {
229
+ private static channelCache;
230
+ private static channelInflight;
231
+ private static authTokenCache;
232
+ private static authInflight;
233
+ protected makeChannelKey(address: Address, stream?: boolean): ChannelKey;
234
+ protected static acquireChannel<T extends BrowserOrNodeJSChannel>(key: ChannelKey, create: () => Promise<T>): Promise<T>;
235
+ protected static releaseChannel(key: ChannelKey): void;
236
+ private static makeAuthTokenKey;
237
+ private static getCachedAuthToken;
238
+ private static setCachedAuthToken;
239
+ private static invalidateCachedAuthToken;
240
+ private static getOrCreateAuthToken;
241
+ protected abstract createChannelWithTLS(address: Address, isStreamClientType?: boolean): Promise<Channel | Channel$1>;
242
+ protected abstract createGrpcClient<T>(definition: SparkAuthnServiceDefinition | SparkServiceDefinition | SparkTokenServiceDefinition, channel: Channel | Channel$1, withRetries: boolean, middleware?: ClientMiddleware<RetryOptions$1, {}>, channelKey?: ChannelKey): Promise<T & {
243
+ close?: () => void;
205
244
  }>;
206
- private tokenClients;
207
- private streamClients;
208
- private authPromises;
245
+ private config;
246
+ private clientsByType;
247
+ private identityPublicKeyHex?;
209
248
  constructor(config: WalletConfigService);
210
249
  createClients(): Promise<void>;
211
250
  closeConnections(): Promise<void>;
212
- protected createChannelWithTLS(address: string, certPath?: string): Promise<Channel | Channel$1>;
213
- createSparkStreamClient(address: string, certPath?: string): Promise<SparkServiceClient & {
251
+ private getDefinitionForClientType;
252
+ protected static isStreamClientType(type: SparkClientType): type is "stream";
253
+ private getAddressToClientMap;
254
+ private getOrCreateClientInternal;
255
+ createSparkStreamClient(address: string): Promise<SparkServiceClient & {
214
256
  close?: () => void;
215
257
  }>;
216
- createSparkClient(address: string, certPath?: string): Promise<SparkServiceClient & {
258
+ createSparkClient(address: string): Promise<SparkServiceClient & {
217
259
  close?: () => void;
218
260
  }>;
219
- createSparkTokenClient(address: string, certPath?: string): Promise<SparkTokenServiceClient & {
261
+ createSparkTokenClient(address: string): Promise<SparkTokenServiceClient & {
220
262
  close?: () => void;
221
263
  }>;
222
- getStreamChannel(address: string): Promise<Channel | Channel$1 | undefined>;
223
- private authenticate;
264
+ getChannelForClient(clientType: SparkClientType, address: Address): Promise<BrowserOrNodeJSChannel | undefined>;
265
+ private getIdentityPublicKeyHex;
266
+ protected authenticate(address: string): Promise<string>;
224
267
  private createSparkAuthnGrpcConnection;
225
- protected createAuthnMiddleware(): (call: ClientMiddlewareCall<any, any>, options: SparkCallOptions) => AsyncGenerator<any, any, undefined>;
226
- protected createMiddleware(address: string, authToken: string): ((call: ClientMiddlewareCall<any, any>, options: SparkCallOptions) => AsyncGenerator<any, any, undefined>) | undefined;
227
- protected handleMiddlewareError(error: unknown, address: string, call: ClientMiddlewareCall<any, any>, metadata: Metadata, options: SparkCallOptions): AsyncGenerator<any, any, undefined>;
228
- protected createGrpcClient<T>(defintion: SparkAuthnServiceDefinition | SparkServiceDefinition | SparkTokenServiceDefinition, channel: Channel | Channel$1, withRetries: boolean, middleware?: any): Promise<T & {
229
- close?: () => void;
230
- }>;
231
- }
232
-
233
- declare const AddressNetwork: Record<NetworkType, string>;
234
- declare const LegacyAddressNetwork: Record<NetworkType, string>;
235
- type Bech32String = `${string}1${string}`;
236
- type SparkAddressFormat = `${(typeof AddressNetwork)[keyof typeof AddressNetwork]}1${string}`;
237
- type LegacySparkAddressFormat = `${(typeof LegacyAddressNetwork)[keyof typeof LegacyAddressNetwork]}1${string}`;
238
- interface SparkAddressData {
239
- identityPublicKey: string;
240
- network: NetworkType;
241
- sparkInvoiceFields?: SparkInvoiceFields;
242
- }
243
- interface DecodedSparkAddressData {
244
- identityPublicKey: string;
245
- network: NetworkType;
246
- sparkInvoiceFields?: {
247
- version: number;
248
- id: string;
249
- paymentType?: {
250
- type: "tokens";
251
- tokenIdentifier?: string;
252
- amount?: bigint;
253
- } | {
254
- type: "sats";
255
- amount?: number;
256
- };
257
- memo?: string;
258
- senderPublicKey?: string;
259
- expiryTime?: Date;
260
- };
261
- signature?: string;
268
+ protected createAuthnMiddleware(): <Req, Res>(call: ClientMiddlewareCall<Req, Res>, options: SparkCallOptions) => AsyncGenerator<Res, Res | void, undefined>;
269
+ protected createMiddleware(address: Address): <Req, Res>(call: ClientMiddlewareCall<Req, Res>, options: SparkCallOptions) => AsyncGenerator<Res, Res | void, undefined>;
270
+ protected handleMiddlewareError<Req, Res>(error: unknown, address: string, call: ClientMiddlewareCall<Req, Res>, metadata: Metadata, options: SparkCallOptions): AsyncGenerator<Awaited<Res>, void | Awaited<Res>, undefined>;
271
+ subscribeToEvents(address: string, signal: AbortSignal): Promise<AsyncIterable<SubscribeToEventsResponse>>;
262
272
  }
263
- declare function encodeSparkAddress(payload: SparkAddressData): LegacySparkAddressFormat;
264
- declare function encodeSparkAddressWithSignature(payload: SparkAddressData, signature?: Uint8Array): LegacySparkAddressFormat;
265
- declare function decodeSparkAddress(address: string, network: NetworkType): DecodedSparkAddressData;
266
- declare function getNetworkFromSparkAddress(address: string): NetworkType;
267
- declare function isLegacySparkAddress(address: string): address is LegacySparkAddressFormat;
268
- declare function isValidSparkAddress(address: string): boolean;
269
- declare function isValidPublicKey(publicKey: string): void;
270
- declare function validateSparkInvoiceFields(sparkInvoiceFields: SparkInvoiceFields): void;
271
- declare function validateSparkInvoiceSignature(invoice: SparkAddressFormat): void;
272
- declare function toProtoTimestamp(date: Date): {
273
- seconds: number;
274
- nanos: number;
275
- };
276
- declare function assertBech32(s: string): asserts s is Bech32String;
277
- declare function bech32mDecode(address: string): _scure_base.Bech32Decoded<string>;
278
- declare function isSafeForNumber(bi: bigint): boolean;
279
273
 
280
274
  declare class SigningService {
281
275
  private readonly config;
@@ -286,6 +280,11 @@ declare class SigningService {
286
280
  directLeafSigningJobs: UserSignedTxSigningJob[];
287
281
  directFromCpfpLeafSigningJobs: UserSignedTxSigningJob[];
288
282
  }>;
283
+ signRefundsForLightning(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array, cpfpSigningCommitments: RequestedSigningCommitments[], directSigningCommitments: RequestedSigningCommitments[], directFromCpfpSigningCommitments: RequestedSigningCommitments[], hash: Uint8Array): Promise<{
284
+ cpfpLeafSigningJobs: UserSignedTxSigningJob[];
285
+ directLeafSigningJobs: UserSignedTxSigningJob[];
286
+ directFromCpfpLeafSigningJobs: UserSignedTxSigningJob[];
287
+ }>;
289
288
  }
290
289
 
291
290
  type LeafKeyTweak = {
@@ -312,8 +311,10 @@ declare class BaseTransferService {
312
311
  protected readonly signingService: SigningService;
313
312
  constructor(config: WalletConfigService, connectionManager: ConnectionManager, signingService: SigningService);
314
313
  deliverTransferPackage(transfer: Transfer, leaves: LeafKeyTweak[], cpfpRefundSignatureMap: Map<string, Uint8Array>, directRefundSignatureMap: Map<string, Uint8Array>, directFromCpfpRefundSignatureMap: Map<string, Uint8Array>): Promise<Transfer>;
314
+ prepareTransferForLightning(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array, paymentHash: Uint8Array, expiryTime: Date, transferID: string): Promise<StartTransferRequest>;
315
315
  sendTransferWithKeyTweaks(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array, sparkInvoice?: SparkAddressFormat): Promise<Transfer>;
316
316
  private prepareTransferPackage;
317
+ private prepareTransferPackageForLightning;
317
318
  signRefunds(leafDataMap: Map<string, LeafRefundSigningData>, operatorSigningResults: LeafRefundTxSigningResult[]): Promise<NodeSignatures[]>;
318
319
  private prepareSendTransferKeyTweaks;
319
320
  private prepareSingleSendTransferKeyTweak;
@@ -363,165 +364,6 @@ declare class TransferService extends BaseTransferService {
363
364
  testonly_expireTimeLockRefundtx(node: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
364
365
  }
365
366
 
366
- type Bech32mTokenIdentifier = `btkn1${string}` | `btknrt1${string}` | `btknt1${string}` | `btkns1${string}` | `btknl1${string}`;
367
- interface Bech32mTokenIdentifierData {
368
- tokenIdentifier: Uint8Array;
369
- network: NetworkType;
370
- }
371
- declare function encodeBech32mTokenIdentifier(payload: Bech32mTokenIdentifierData): Bech32mTokenIdentifier;
372
- declare function decodeBech32mTokenIdentifier(bech32mTokenIdentifier: Bech32mTokenIdentifier, network?: NetworkType): Bech32mTokenIdentifierData;
373
- declare function getNetworkFromBech32mTokenIdentifier(bech32mTokenIdentifier: Bech32mTokenIdentifier): NetworkType;
374
-
375
- type CreateLightningInvoiceParams = {
376
- amountSats: number;
377
- memo?: string;
378
- expirySeconds?: number;
379
- includeSparkAddress?: boolean;
380
- receiverIdentityPubkey?: string;
381
- descriptionHash?: string;
382
- };
383
- type PayLightningInvoiceParams = {
384
- invoice: string;
385
- maxFeeSats: number;
386
- preferSpark?: boolean;
387
- amountSatsToSend?: number;
388
- };
389
- type TransferParams = {
390
- amountSats: number;
391
- receiverSparkAddress: string;
392
- };
393
- type TransferWithInvoiceParams = {
394
- amountSats: number;
395
- receiverIdentityPubkey: Uint8Array;
396
- sparkInvoice?: SparkAddressFormat;
397
- };
398
- type TransferWithInvoiceOutcome = {
399
- ok: true;
400
- transfer: WalletTransfer;
401
- param: TransferWithInvoiceParams;
402
- } | {
403
- ok: false;
404
- error: Error;
405
- param: TransferWithInvoiceParams;
406
- };
407
- type FulfillSparkInvoiceResponse = {
408
- satsTransactionSuccess: {
409
- invoice: SparkAddressFormat;
410
- transferResponse: WalletTransfer;
411
- }[];
412
- tokenTransactionSuccess: {
413
- tokenIdentifier: Bech32mTokenIdentifier;
414
- txid: string;
415
- }[];
416
- satsTransactionErrors: {
417
- invoice: string;
418
- error: Error;
419
- }[];
420
- tokenTransactionErrors: {
421
- tokenIdentifier: Bech32mTokenIdentifier;
422
- error: Error;
423
- }[];
424
- invalidInvoices: {
425
- invoice: string;
426
- error: Error;
427
- }[];
428
- };
429
- type TokenInvoice = {
430
- invoice: string;
431
- identifierHex: string;
432
- amount: bigint;
433
- };
434
- type InvalidInvoice = {
435
- invoice: string;
436
- error: Error;
437
- };
438
- type GroupSparkInvoicesResult = {
439
- satsInvoices: TransferWithInvoiceParams[];
440
- tokenInvoices: Map<string, TokenInvoice[]>;
441
- invalidInvoices: InvalidInvoice[];
442
- };
443
- type DepositParams = {
444
- keyDerivation: KeyDerivation;
445
- verifyingKey: Uint8Array;
446
- depositTx: Transaction;
447
- vout: number;
448
- };
449
- /**
450
- * Token metadata containing essential information about a token.
451
- * This is the wallet's internal representation with JavaScript-friendly types.
452
- *
453
- * rawTokenIdentifier: This is the raw binary token identifier - This is used to encode the bech32m encoded token identifier.
454
- *
455
- * tokenPublicKey: This is the hex-encoded public key of the token issuer - Same as issuerPublicKey.
456
- *
457
- * @example
458
- * ```typescript
459
- * const tokenMetadata: UserTokenMetadata = {
460
- * rawTokenIdentifier: new Uint8Array([1, 2, 3]),
461
- * tokenPublicKey: "0348fbb...",
462
- * tokenName: "SparkToken",
463
- * tokenTicker: "SPK",
464
- * decimals: 8,
465
- * maxSupply: 1000000n
466
- * };
467
- * ```
468
- */
469
- type UserTokenMetadata = {
470
- /** Raw binary token identifier - This is used to encode the human readable token identifier */
471
- rawTokenIdentifier: Uint8Array;
472
- /** Public key of the token issuer - Same as issuerPublicKey */
473
- tokenPublicKey: string;
474
- /** Human-readable name of the token (e.g., SparkToken)*/
475
- tokenName: string;
476
- /** Short ticker symbol for the token (e.g., "SPK") */
477
- tokenTicker: string;
478
- /** Number of decimal places for token amounts */
479
- decimals: number;
480
- /** Maximum supply of tokens that can ever be minted */
481
- maxSupply: bigint;
482
- };
483
- type TokenBalanceMap = Map<Bech32mTokenIdentifier, {
484
- balance: bigint;
485
- tokenMetadata: UserTokenMetadata;
486
- }>;
487
- type RawTokenIdentifierHex = string & {
488
- readonly __brand: "RawTokenIdentifierHex";
489
- };
490
- type TokenOutputsMap = Map<Bech32mTokenIdentifier, OutputWithPreviousTransactionData[]>;
491
- type TokenMetadataMap = Map<Bech32mTokenIdentifier, TokenMetadata>;
492
- type InitWalletResponse<T extends SparkWallet = SparkWallet> = {
493
- wallet: T;
494
- mnemonic: string | undefined;
495
- };
496
- interface SparkWalletProps {
497
- mnemonicOrSeed?: Uint8Array | string;
498
- accountNumber?: number;
499
- signer?: SparkSigner;
500
- options?: ConfigOptions;
501
- }
502
- declare const SparkWalletEvent: {
503
- readonly All: "*";
504
- readonly TransferClaimed: "transfer:claimed";
505
- readonly DepositConfirmed: "deposit:confirmed";
506
- readonly StreamConnected: "stream:connected";
507
- readonly StreamDisconnected: "stream:disconnected";
508
- readonly StreamReconnecting: "stream:reconnecting";
509
- };
510
- type SparkWalletEventType = (typeof SparkWalletEvent)[keyof typeof SparkWalletEvent];
511
- interface SparkWalletEvents {
512
- [SparkWalletEvent.All]: (eventName: string, ...args: unknown[]) => void;
513
- /** Emitted when an incoming transfer is successfully claimed. Includes the transfer ID and new total balance. */
514
- [SparkWalletEvent.TransferClaimed]: (transferId: string, updatedBalance: bigint) => void;
515
- /** Emitted when a deposit is marked as available. Includes the deposit ID and new total balance. */
516
- [SparkWalletEvent.DepositConfirmed]: (depositId: string, updatedBalance: bigint) => void;
517
- /** Emitted when the stream is connected */
518
- [SparkWalletEvent.StreamConnected]: () => void;
519
- /** Emitted when the stream disconnects and fails to reconnect after max attempts */
520
- [SparkWalletEvent.StreamDisconnected]: (reason: string) => void;
521
- /** Emitted when attempting to reconnect the stream */
522
- [SparkWalletEvent.StreamReconnecting]: (attempt: number, maxAttempts: number, delayMs: number, error: string) => void;
523
- }
524
-
525
367
  /**
526
368
  * The SparkWallet class is the primary interface for interacting with the Spark network.
527
369
  * It provides methods for creating and managing wallets, handling deposits, executing transfers,
@@ -550,12 +392,12 @@ declare abstract class SparkWallet extends EventEmitter<SparkWalletEvents> {
550
392
  protected tokenOutputs: TokenOutputsMap;
551
393
  private claimTransfersInterval;
552
394
  private tracer;
395
+ protected abstract buildConnectionManager(config: WalletConfigService): ConnectionManager;
553
396
  constructor(options?: ConfigOptions, signerArg?: SparkSigner);
554
397
  static initialize<T extends SparkWallet>(this: new (options?: ConfigOptions, signer?: SparkSigner) => T, { mnemonicOrSeed, accountNumber, signer, options }: SparkWalletProps): Promise<InitWalletResponse<T>>;
555
398
  private createClientsAndSyncWallet;
556
399
  private getSspClient;
557
400
  protected buildSigner(): DefaultSparkSigner;
558
- protected buildConnectionManager(config: WalletConfigService): ConnectionManager;
559
401
  private handleStreamEvent;
560
402
  protected setupBackgroundStream(): Promise<void>;
561
403
  getLeaves(isBalanceCheck?: boolean): Promise<TreeNode[]>;
@@ -1142,4 +984,187 @@ declare abstract class SparkWallet extends EventEmitter<SparkWalletEvents> {
1142
984
  private wrapSparkWalletMethodsWithTracing;
1143
985
  }
1144
986
 
1145
- export { type SparkCallOptions as $, type CreateLightningInvoiceParams as A, type Bech32mTokenIdentifier as B, ConnectionManager as C, type DecodedSparkAddressData as D, type TransferWithInvoiceParams as E, type TransferWithInvoiceOutcome as F, type FulfillSparkInvoiceResponse as G, type TokenInvoice as H, type InvalidInvoice as I, type GroupSparkInvoicesResult as J, type DepositParams as K, type LegacySparkAddressFormat as L, type TokenBalanceMap as M, Network as N, type TokenOutputsMap as O, type PayLightningInvoiceParams as P, type TokenMetadataMap as Q, type RawTokenIdentifierHex as R, type SparkAddressFormat as S, type TransferParams as T, type UserTokenMetadata as U, type InitWalletResponse as V, WalletConfigService as W, type SparkWalletProps as X, SparkWalletEvent as Y, type SparkWalletEventType as Z, type SparkWalletEvents as _, WalletConfig as a, SparkAuthnServiceDefinition as a0, SparkWallet as a1, type ConfigOptions as b, type SparkAddressData as c, encodeSparkAddressWithSignature as d, encodeSparkAddress as e, decodeSparkAddress as f, getNetworkFromSparkAddress as g, isValidSparkAddress as h, isLegacySparkAddress as i, isValidPublicKey as j, validateSparkInvoiceSignature as k, assertBech32 as l, bech32mDecode as m, isSafeForNumber as n, type NetworkType as o, NetworkToProto as p, protoToNetwork as q, getNetwork as r, getNetworkFromAddress as s, toProtoTimestamp as t, getNetworkFromString as u, validateSparkInvoiceFields as v, type Bech32mTokenIdentifierData as w, encodeBech32mTokenIdentifier as x, decodeBech32mTokenIdentifier as y, getNetworkFromBech32mTokenIdentifier as z };
987
+ type CreateLightningInvoiceParams = {
988
+ amountSats: number;
989
+ memo?: string;
990
+ expirySeconds?: number;
991
+ includeSparkAddress?: boolean;
992
+ receiverIdentityPubkey?: string;
993
+ descriptionHash?: string;
994
+ };
995
+ type PayLightningInvoiceParams = {
996
+ invoice: string;
997
+ maxFeeSats: number;
998
+ preferSpark?: boolean;
999
+ amountSatsToSend?: number;
1000
+ };
1001
+ type TransferParams = {
1002
+ amountSats: number;
1003
+ receiverSparkAddress: string;
1004
+ };
1005
+ type TransferWithInvoiceParams = {
1006
+ amountSats: number;
1007
+ receiverIdentityPubkey: Uint8Array;
1008
+ sparkInvoice?: SparkAddressFormat;
1009
+ };
1010
+ type TransferWithInvoiceOutcome = {
1011
+ ok: true;
1012
+ transfer: WalletTransfer;
1013
+ param: TransferWithInvoiceParams;
1014
+ } | {
1015
+ ok: false;
1016
+ error: Error;
1017
+ param: TransferWithInvoiceParams;
1018
+ };
1019
+ type FulfillSparkInvoiceResponse = {
1020
+ satsTransactionSuccess: {
1021
+ invoice: SparkAddressFormat;
1022
+ transferResponse: WalletTransfer;
1023
+ }[];
1024
+ tokenTransactionSuccess: {
1025
+ tokenIdentifier: Bech32mTokenIdentifier;
1026
+ txid: string;
1027
+ }[];
1028
+ satsTransactionErrors: {
1029
+ invoice: string;
1030
+ error: Error;
1031
+ }[];
1032
+ tokenTransactionErrors: {
1033
+ tokenIdentifier: Bech32mTokenIdentifier;
1034
+ error: Error;
1035
+ }[];
1036
+ invalidInvoices: {
1037
+ invoice: string;
1038
+ error: Error;
1039
+ }[];
1040
+ };
1041
+ type TokenInvoice = {
1042
+ invoice: string;
1043
+ identifierHex: string;
1044
+ amount: bigint;
1045
+ };
1046
+ type InvalidInvoice = {
1047
+ invoice: string;
1048
+ error: Error;
1049
+ };
1050
+ type GroupSparkInvoicesResult = {
1051
+ satsInvoices: TransferWithInvoiceParams[];
1052
+ tokenInvoices: Map<string, TokenInvoice[]>;
1053
+ invalidInvoices: InvalidInvoice[];
1054
+ };
1055
+ type DepositParams = {
1056
+ keyDerivation: KeyDerivation;
1057
+ verifyingKey: Uint8Array;
1058
+ depositTx: Transaction;
1059
+ vout: number;
1060
+ };
1061
+ /**
1062
+ * Token metadata containing essential information about a token.
1063
+ * This is the wallet's internal representation with JavaScript-friendly types.
1064
+ *
1065
+ * rawTokenIdentifier: This is the raw binary token identifier - This is used to encode the bech32m encoded token identifier.
1066
+ *
1067
+ * tokenPublicKey: This is the hex-encoded public key of the token issuer - Same as issuerPublicKey.
1068
+ *
1069
+ * @example
1070
+ * ```typescript
1071
+ * const tokenMetadata: UserTokenMetadata = {
1072
+ * rawTokenIdentifier: new Uint8Array([1, 2, 3]),
1073
+ * tokenPublicKey: "0348fbb...",
1074
+ * tokenName: "SparkToken",
1075
+ * tokenTicker: "SPK",
1076
+ * decimals: 8,
1077
+ * maxSupply: 1000000n
1078
+ * };
1079
+ * ```
1080
+ */
1081
+ type UserTokenMetadata = {
1082
+ /** Raw binary token identifier - This is used to encode the human readable token identifier */
1083
+ rawTokenIdentifier: Uint8Array;
1084
+ /** Public key of the token issuer - Same as issuerPublicKey */
1085
+ tokenPublicKey: string;
1086
+ /** Human-readable name of the token (e.g., SparkToken)*/
1087
+ tokenName: string;
1088
+ /** Short ticker symbol for the token (e.g., "SPK") */
1089
+ tokenTicker: string;
1090
+ /** Number of decimal places for token amounts */
1091
+ decimals: number;
1092
+ /** Maximum supply of tokens that can ever be minted */
1093
+ maxSupply: bigint;
1094
+ };
1095
+ type TokenBalanceMap = Map<Bech32mTokenIdentifier, {
1096
+ balance: bigint;
1097
+ tokenMetadata: UserTokenMetadata;
1098
+ }>;
1099
+ type RawTokenIdentifierHex = string & {
1100
+ readonly __brand: "RawTokenIdentifierHex";
1101
+ };
1102
+ type TokenOutputsMap = Map<Bech32mTokenIdentifier, OutputWithPreviousTransactionData[]>;
1103
+ type TokenMetadataMap = Map<Bech32mTokenIdentifier, TokenMetadata>;
1104
+ type InitWalletResponse<T extends SparkWallet = SparkWallet> = {
1105
+ wallet: T;
1106
+ mnemonic: string | undefined;
1107
+ };
1108
+ interface SparkWalletProps {
1109
+ mnemonicOrSeed?: Uint8Array | string;
1110
+ accountNumber?: number;
1111
+ signer?: SparkSigner;
1112
+ options?: ConfigOptions;
1113
+ }
1114
+ declare const SparkWalletEvent: {
1115
+ readonly All: "*";
1116
+ readonly TransferClaimed: "transfer:claimed";
1117
+ readonly DepositConfirmed: "deposit:confirmed";
1118
+ readonly StreamConnected: "stream:connected";
1119
+ readonly StreamDisconnected: "stream:disconnected";
1120
+ readonly StreamReconnecting: "stream:reconnecting";
1121
+ };
1122
+ type SparkWalletEventType = (typeof SparkWalletEvent)[keyof typeof SparkWalletEvent];
1123
+ interface SparkWalletEvents {
1124
+ [SparkWalletEvent.All]: (eventName: string, ...args: unknown[]) => void;
1125
+ /** Emitted when an incoming transfer is successfully claimed. Includes the transfer ID and new total balance. */
1126
+ [SparkWalletEvent.TransferClaimed]: (transferId: string, updatedBalance: bigint) => void;
1127
+ /** Emitted when a deposit is marked as available. Includes the deposit ID and new total balance. */
1128
+ [SparkWalletEvent.DepositConfirmed]: (depositId: string, updatedBalance: bigint) => void;
1129
+ /** Emitted when the stream is connected */
1130
+ [SparkWalletEvent.StreamConnected]: () => void;
1131
+ /** Emitted when the stream disconnects and fails to reconnect after max attempts */
1132
+ [SparkWalletEvent.StreamDisconnected]: (reason: string) => void;
1133
+ /** Emitted when attempting to reconnect the stream */
1134
+ [SparkWalletEvent.StreamReconnecting]: (attempt: number, maxAttempts: number, delayMs: number, error: string) => void;
1135
+ }
1136
+
1137
+ type SigningOperator = {
1138
+ readonly id: number;
1139
+ readonly identifier: string;
1140
+ readonly address: string;
1141
+ readonly identityPublicKey: string;
1142
+ };
1143
+ type ConsoleOptions = {
1144
+ otel?: boolean;
1145
+ };
1146
+ type ConfigOptions = MayHaveSspClientOptions & {
1147
+ readonly network?: NetworkType;
1148
+ readonly signingOperators?: Readonly<Record<string, SigningOperator>>;
1149
+ readonly coordinatorIdentifier?: string;
1150
+ readonly frostSignerAddress?: string;
1151
+ readonly threshold?: number;
1152
+ readonly tokenSignatures?: "ECDSA" | "SCHNORR";
1153
+ readonly tokenValidityDurationSeconds?: number;
1154
+ readonly electrsUrl?: string;
1155
+ readonly sspClientOptions?: SspClientOptions;
1156
+ readonly expectedWithdrawBondSats?: number;
1157
+ readonly expectedWithdrawRelativeBlockLocktime?: number;
1158
+ readonly signerWithPreExistingKeys?: boolean;
1159
+ readonly console?: ConsoleOptions;
1160
+ readonly events?: Partial<SparkWalletEvents>;
1161
+ };
1162
+ declare const WalletConfig: {
1163
+ LOCAL: Required<ConfigOptions>;
1164
+ LOCAL_SCHNORR: Required<ConfigOptions>;
1165
+ LOCAL_ECDSA: Required<ConfigOptions>;
1166
+ REGTEST: Required<ConfigOptions>;
1167
+ MAINNET: Required<ConfigOptions>;
1168
+ };
1169
+
1170
+ export { type SparkCallOptions as $, type CreateLightningInvoiceParams as A, type Bech32mTokenIdentifier as B, ConnectionManager as C, type DecodedSparkAddressData as D, type TransferWithInvoiceParams as E, type TransferWithInvoiceOutcome as F, type FulfillSparkInvoiceResponse as G, type TokenInvoice as H, type InvalidInvoice as I, type GroupSparkInvoicesResult as J, type DepositParams as K, type LegacySparkAddressFormat as L, type TokenBalanceMap as M, Network as N, type TokenOutputsMap as O, type PayLightningInvoiceParams as P, type TokenMetadataMap as Q, type RawTokenIdentifierHex as R, type SparkAddressFormat as S, type TransferParams as T, type UserTokenMetadata as U, type InitWalletResponse as V, WalletConfigService as W, type SparkWalletProps as X, SparkWalletEvent as Y, type SparkWalletEventType as Z, type SparkWalletEvents as _, WalletConfig as a, SparkAuthnServiceDefinition as a0, type RetryOptions as a1, SparkWallet as a2, type ConfigOptions as b, type SparkAddressData as c, encodeSparkAddressWithSignature as d, encodeSparkAddress as e, decodeSparkAddress as f, getNetworkFromSparkAddress as g, isValidSparkAddress as h, isLegacySparkAddress as i, isValidPublicKey as j, validateSparkInvoiceSignature as k, assertBech32 as l, bech32mDecode as m, isSafeForNumber as n, type NetworkType as o, NetworkToProto as p, protoToNetwork as q, getNetwork as r, getNetworkFromAddress as s, toProtoTimestamp as t, getNetworkFromString as u, validateSparkInvoiceFields as v, type Bech32mTokenIdentifierData as w, encodeBech32mTokenIdentifier as x, decodeBech32mTokenIdentifier as y, getNetworkFromBech32mTokenIdentifier as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buildonspark/spark-sdk",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "author": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
@@ -111,8 +111,8 @@
111
111
  "postversion": "yarn build",
112
112
  "test-cmd": "node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --detectOpenHandles --forceExit",
113
113
  "test": "yarn test-cmd src/tests/*.test.ts",
114
- "test:integration": "HERMETIC_TEST=true yarn test-cmd src/tests/integration/*.test.ts",
115
- "test:integration:ssp": "HERMETIC_TEST=true yarn test-cmd src/tests/integration/ssp/*.test.ts",
114
+ "test:integration": "yarn test-cmd src/tests/integration/*.test.ts",
115
+ "test:integration:ssp": "yarn test-cmd src/tests/integration/ssp/*.test.ts",
116
116
  "types:watch": "tsc-absolute --watch",
117
117
  "types": "tsc",
118
118
  "patch-wasm": "node ./wasm/patch-wasm.mjs",