@buildonspark/spark-sdk 0.3.8 → 0.4.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 (94) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/uniffi/uniffi/spark_frost/spark_frost.kt +1361 -1367
  4. package/android/src/main/jniLibs/arm64-v8a/libuniffi_spark_frost.so +0 -0
  5. package/android/src/main/jniLibs/armeabi-v7a/libuniffi_spark_frost.so +0 -0
  6. package/android/src/main/jniLibs/x86/libuniffi_spark_frost.so +0 -0
  7. package/android/src/main/jniLibs/x86_64/libuniffi_spark_frost.so +0 -0
  8. package/dist/bare/index.cjs +1342 -1346
  9. package/dist/bare/index.d.cts +114 -68
  10. package/dist/bare/index.d.ts +114 -68
  11. package/dist/bare/index.js +1266 -1279
  12. package/dist/{chunk-FXIESWE6.js → chunk-27ILUWDJ.js} +1 -1
  13. package/dist/{chunk-5ASXVNTM.js → chunk-4YFT7DAE.js} +1 -1
  14. package/dist/{chunk-FP2CRVQH.js → chunk-G3LHXHF3.js} +1045 -1308
  15. package/dist/{chunk-XI6FCNYG.js → chunk-JLF6WJ7K.js} +1 -1
  16. package/dist/{chunk-3LPEQGVJ.js → chunk-LOXWCMZL.js} +1 -1
  17. package/dist/{chunk-5HU5W56H.js → chunk-WICAF6BS.js} +2 -2
  18. package/dist/{chunk-VFN34EOX.js → chunk-YEBEN7XD.js} +258 -0
  19. package/dist/{client-pNpGP15j.d.cts → client-BIqiUNy4.d.cts} +1 -1
  20. package/dist/{client-By-N7oJS.d.ts → client-BaQf-5gD.d.ts} +1 -1
  21. package/dist/debug.cjs +1330 -1336
  22. package/dist/debug.d.cts +20 -16
  23. package/dist/debug.d.ts +20 -16
  24. package/dist/debug.js +5 -5
  25. package/dist/graphql/objects/index.d.cts +3 -3
  26. package/dist/graphql/objects/index.d.ts +3 -3
  27. package/dist/index.cjs +1363 -1365
  28. package/dist/index.d.cts +7 -7
  29. package/dist/index.d.ts +7 -7
  30. package/dist/index.js +32 -24
  31. package/dist/index.node.cjs +1363 -1365
  32. package/dist/index.node.d.cts +7 -7
  33. package/dist/index.node.d.ts +7 -7
  34. package/dist/index.node.js +31 -23
  35. package/dist/{logging-DMFVY384.d.ts → logging-BNGm6dBp.d.ts} +42 -37
  36. package/dist/{logging-DxLp34Xm.d.cts → logging-D3IfXfHG.d.cts} +42 -37
  37. package/dist/native/index.react-native.cjs +1505 -1366
  38. package/dist/native/index.react-native.d.cts +112 -58
  39. package/dist/native/index.react-native.d.ts +112 -58
  40. package/dist/native/index.react-native.js +1415 -1289
  41. package/dist/proto/spark.cjs +258 -0
  42. package/dist/proto/spark.d.cts +1 -1
  43. package/dist/proto/spark.d.ts +1 -1
  44. package/dist/proto/spark.js +5 -1
  45. package/dist/proto/spark_token.d.cts +1 -1
  46. package/dist/proto/spark_token.d.ts +1 -1
  47. package/dist/proto/spark_token.js +2 -2
  48. package/dist/{spark-By6yHsrk.d.cts → spark-DOpheE8_.d.cts} +39 -2
  49. package/dist/{spark-By6yHsrk.d.ts → spark-DOpheE8_.d.ts} +39 -2
  50. package/dist/{spark-wallet.browser-C1dQknVj.d.ts → spark-wallet.browser-B2rGwjuM.d.ts} +2 -2
  51. package/dist/{spark-wallet.browser-CNMo3IvO.d.cts → spark-wallet.browser-Ck9No4Ks.d.cts} +2 -2
  52. package/dist/{spark-wallet.node-Og6__NMh.d.ts → spark-wallet.node-BqmKsGPs.d.ts} +2 -2
  53. package/dist/{spark-wallet.node-BZJhJZKq.d.cts → spark-wallet.node-C2TIkyt4.d.cts} +2 -2
  54. package/dist/tests/test-utils.cjs +1304 -1236
  55. package/dist/tests/test-utils.d.cts +18 -4
  56. package/dist/tests/test-utils.d.ts +18 -4
  57. package/dist/tests/test-utils.js +7 -7
  58. package/dist/{token-transactions-CLR3rnYi.d.cts → token-transactions-Db8mkjnU.d.cts} +2 -2
  59. package/dist/{token-transactions-C7yefB2S.d.ts → token-transactions-DoMcrxXQ.d.ts} +2 -2
  60. package/dist/types/index.cjs +256 -0
  61. package/dist/types/index.d.cts +2 -2
  62. package/dist/types/index.d.ts +2 -2
  63. package/dist/types/index.js +2 -2
  64. package/dist/{wallet-config-BoyMVa6n.d.ts → wallet-config-Bg3kWltL.d.ts} +42 -35
  65. package/dist/{wallet-config-xom-9UFF.d.cts → wallet-config-CuZKNo9S.d.cts} +42 -35
  66. package/ios/spark_frostFFI.xcframework/ios-arm64/SparkFrost +0 -0
  67. package/ios/spark_frostFFI.xcframework/ios-arm64/spark_frostFFI.framework/spark_frostFFI +0 -0
  68. package/ios/spark_frostFFI.xcframework/ios-arm64_x86_64-simulator/SparkFrost +0 -0
  69. package/ios/spark_frostFFI.xcframework/ios-arm64_x86_64-simulator/spark_frostFFI.framework/spark_frostFFI +0 -0
  70. package/ios/spark_frostFFI.xcframework/macos-arm64_x86_64/spark_frostFFI.framework/spark_frostFFI +0 -0
  71. package/package.json +1 -1
  72. package/src/index.react-native.ts +8 -2
  73. package/src/proto/spark.ts +348 -4
  74. package/src/services/config.ts +5 -0
  75. package/src/services/coop-exit.ts +26 -107
  76. package/src/services/deposit.ts +12 -48
  77. package/src/services/signing.ts +62 -49
  78. package/src/services/transfer.ts +437 -722
  79. package/src/services/wallet-config.ts +10 -0
  80. package/src/services/xhr-transport.ts +13 -3
  81. package/src/signer/signer.react-native.ts +73 -1
  82. package/src/spark-wallet/proto-descriptors.ts +1 -1
  83. package/src/spark-wallet/spark-wallet.ts +162 -315
  84. package/src/spark-wallet/types.ts +2 -2
  85. package/src/spark_descriptors.pb +0 -0
  86. package/src/tests/integration/lightning.test.ts +1 -27
  87. package/src/tests/integration/static_deposit.test.ts +6 -9
  88. package/src/tests/integration/unilateral-exit.test.ts +117 -0
  89. package/src/tests/optimize.test.ts +31 -1
  90. package/src/tests/utils/signing.ts +33 -0
  91. package/src/tests/utils/test-faucet.ts +61 -0
  92. package/src/utils/optimize.ts +42 -0
  93. package/src/utils/transaction.ts +250 -249
  94. package/src/utils/unilateral-exit.ts +1 -40
@@ -1,7 +1,7 @@
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-By-N7oJS.js';
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-BaQf-5gD.js';
2
2
  import * as btc from '@scure/btc-signer';
3
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.js';
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-DOpheE8_.js';
5
5
  import { SparkTokenServiceDefinition, SparkTokenServiceClient, QueryTokenTransactionsResponse, TokenMetadata } from './proto/spark_token.js';
6
6
  import * as _scure_base from '@scure/base';
7
7
  import { Channel } from 'nice-grpc';
@@ -9,6 +9,7 @@ import { CallOptions, ClientMiddleware, ClientMiddlewareCall, Metadata } from 'n
9
9
  import { Channel as Channel$1 } from 'nice-grpc-web';
10
10
  import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
11
11
  import { RetryOptions as RetryOptions$1 } from 'nice-grpc-client-middleware-retry';
12
+ import { TransactionOutput } from '@scure/btc-signer/psbt';
12
13
  import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
13
14
  import { EventEmitter } from 'eventemitter3';
14
15
 
@@ -38,15 +39,6 @@ declare function getNetworkFromAddress(address: string): BitcoinNetwork.MAINNET
38
39
  */
39
40
  declare function getNetworkFromString(network?: string): Network;
40
41
 
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
42
  declare const AddressNetwork: Record<NetworkType, string>;
51
43
  declare const LegacyAddressNetwork: Record<NetworkType, string>;
52
44
  type Bech32String = `${string}1${string}`;
@@ -94,6 +86,15 @@ declare function assertBech32(s: string): asserts s is Bech32String;
94
86
  declare function bech32mDecode(address: string): _scure_base.Bech32Decoded<string>;
95
87
  declare function isSafeForNumber(bi: bigint): boolean;
96
88
 
89
+ type Bech32mTokenIdentifier = `btkn1${string}` | `btknrt1${string}` | `btknt1${string}` | `btkns1${string}` | `btknl1${string}`;
90
+ interface Bech32mTokenIdentifierData {
91
+ tokenIdentifier: Uint8Array;
92
+ network: NetworkType;
93
+ }
94
+ declare function encodeBech32mTokenIdentifier(payload: Bech32mTokenIdentifierData): Bech32mTokenIdentifier;
95
+ declare function decodeBech32mTokenIdentifier(bech32mTokenIdentifier: Bech32mTokenIdentifier, network?: NetworkType): Bech32mTokenIdentifierData;
96
+ declare function getNetworkFromBech32mTokenIdentifier(bech32mTokenIdentifier: Bech32mTokenIdentifier): NetworkType;
97
+
97
98
  declare class WalletConfigService implements HasSspClientOptions {
98
99
  private readonly config;
99
100
  readonly signer: SparkSigner;
@@ -117,6 +118,7 @@ declare class WalletConfigService implements HasSspClientOptions {
117
118
  getSspIdentityPublicKey(): string;
118
119
  getConsoleOptions(): ConsoleOptions;
119
120
  getEvents(): Partial<SparkWalletEvents>;
121
+ getOptimizationOptions(): OptimizationOptions;
120
122
  }
121
123
 
122
124
  /** Challenge represents the core challenge data */
@@ -285,6 +287,7 @@ declare class SigningService {
285
287
  directLeafSigningJobs: UserSignedTxSigningJob[];
286
288
  directFromCpfpLeafSigningJobs: UserSignedTxSigningJob[];
287
289
  }>;
290
+ signSigningJobs(signingJobs: (SigningJobWithOptionalNonce & RequestedSigningCommitments)[]): Promise<Map<SigningJobType, UserSignedTxSigningJob>>;
288
291
  }
289
292
 
290
293
  type LeafKeyTweak = {
@@ -305,6 +308,17 @@ type LeafRefundSigningData = {
305
308
  directFromCpfpRefundSigningNonceCommitment: SigningCommitmentWithOptionalNonce;
306
309
  vout: number;
307
310
  };
311
+ type SigningJobType = "split" | "directSplit" | "node" | "directNode" | "cpfp" | "direct" | "directFromCpfp";
312
+ type SigningJobWithOptionalNonce = {
313
+ signingPublicKey: Uint8Array;
314
+ rawTx: Uint8Array;
315
+ signingNonceCommitment: SigningCommitmentWithOptionalNonce;
316
+ type: SigningJobType;
317
+ parentTxOut: TransactionOutput;
318
+ leafId: string;
319
+ keyDerivation: KeyDerivation;
320
+ verifyingKey: Uint8Array;
321
+ };
308
322
  declare class BaseTransferService {
309
323
  protected readonly config: WalletConfigService;
310
324
  protected readonly connectionManager: ConnectionManager;
@@ -357,11 +371,12 @@ declare class TransferService extends BaseTransferService {
357
371
  claimTransferSignRefunds(transfer: Transfer, leafKeys: LeafKeyTweak[], proofMap?: Map<string, Uint8Array[]>): Promise<NodeSignatures[]>;
358
372
  private finalizeNodeSignatures;
359
373
  queryPendingTransfersBySender(operatorAddress: string): Promise<QueryTransfersResponse>;
360
- private refreshTimelockNodesInternal;
361
- refreshTimelockNodes(node: TreeNode, parentNode: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
362
- extendTimelock(node: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
363
- testonly_expireTimeLockNodeTx(node: TreeNode, parentNode: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
364
- testonly_expireTimeLockRefundtx(node: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
374
+ renewRefundTxn(node: TreeNode, parentNode: TreeNode): Promise<TreeNode>;
375
+ renewNodeTxn(node: TreeNode, parentNode: TreeNode): Promise<TreeNode>;
376
+ private createRenewRefundSigningJobs;
377
+ private createRenewNodeSigningJobs;
378
+ renewZeroTimelockNodeTxn(node: TreeNode): Promise<TreeNode>;
379
+ private createRenewZeroTimelockNodeSigningJobs;
365
380
  }
366
381
 
367
382
  /**
@@ -401,13 +416,15 @@ declare abstract class SparkWallet extends EventEmitter<SparkWalletEvents> {
401
416
  private handleStreamEvent;
402
417
  protected setupBackgroundStream(): Promise<void>;
403
418
  getLeaves(isBalanceCheck?: boolean): Promise<TreeNode[]>;
404
- private checkExtendLeaves;
405
419
  private verifyKey;
406
420
  private popOrThrow;
407
421
  private selectLeaves;
408
422
  private selectLeavesForSwap;
409
- private areLeavesInefficient;
410
- private optimizeLeaves;
423
+ optimizeLeaves(multiplicity?: number | undefined): AsyncGenerator<{
424
+ step: number;
425
+ total: number;
426
+ controller: AbortController;
427
+ }, void, void>;
411
428
  private syncWallet;
412
429
  private withLeaves;
413
430
  /**
@@ -712,15 +729,7 @@ declare abstract class SparkWallet extends EventEmitter<SparkWalletEvents> {
712
729
  private transferWithInvoice;
713
730
  private buildTweaksByAmount;
714
731
  private toSendTweak;
715
- private checkExtendTimeLockNodes;
716
- /**
717
- * Internal method to refresh timelock nodes.
718
- *
719
- * @param {string} nodeId - The optional ID of the node to refresh. If not provided, all nodes will be checked.
720
- * @returns {Promise<void>}
721
- * @private
722
- */
723
- private checkRefreshTimelockNodes;
732
+ private checkRenewLeaves;
724
733
  private claimTransferCore;
725
734
  private processClaimedTransferResults;
726
735
  /**
@@ -959,13 +968,6 @@ declare abstract class SparkWallet extends EventEmitter<SparkWalletEvents> {
959
968
  nodeTimelock: number;
960
969
  refundTimelock: number;
961
970
  }>;
962
- /**
963
- * Refresh the timelock of a specific node.
964
- *
965
- * @param {string} nodeId - The ID of the node to refresh
966
- * @returns {Promise<void>} Promise that resolves when the timelock is refreshed
967
- */
968
- testOnly_expireTimelock(nodeId: string): Promise<void>;
969
971
  private cleanup;
970
972
  cleanupConnections(): Promise<void>;
971
973
  private startPeriodicClaimTransfers;
@@ -1143,6 +1145,10 @@ type SigningOperator = {
1143
1145
  type ConsoleOptions = {
1144
1146
  otel?: boolean;
1145
1147
  };
1148
+ type OptimizationOptions = {
1149
+ readonly auto?: boolean;
1150
+ readonly multiplicity?: number;
1151
+ };
1146
1152
  type ConfigOptions = MayHaveSspClientOptions & {
1147
1153
  readonly network?: NetworkType;
1148
1154
  readonly signingOperators?: Readonly<Record<string, SigningOperator>>;
@@ -1158,6 +1164,7 @@ type ConfigOptions = MayHaveSspClientOptions & {
1158
1164
  readonly signerWithPreExistingKeys?: boolean;
1159
1165
  readonly console?: ConsoleOptions;
1160
1166
  readonly events?: Partial<SparkWalletEvents>;
1167
+ readonly optimizationOptions?: OptimizationOptions;
1161
1168
  };
1162
1169
  declare const WalletConfig: {
1163
1170
  LOCAL: Required<ConfigOptions>;
@@ -1,7 +1,7 @@
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';
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-BIqiUNy4.cjs';
2
2
  import * as btc from '@scure/btc-signer';
3
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';
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-DOpheE8_.cjs';
5
5
  import { SparkTokenServiceDefinition, SparkTokenServiceClient, QueryTokenTransactionsResponse, TokenMetadata } from './proto/spark_token.cjs';
6
6
  import * as _scure_base from '@scure/base';
7
7
  import { Channel } from 'nice-grpc';
@@ -9,6 +9,7 @@ import { CallOptions, ClientMiddleware, ClientMiddlewareCall, Metadata } from 'n
9
9
  import { Channel as Channel$1 } from 'nice-grpc-web';
10
10
  import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
11
11
  import { RetryOptions as RetryOptions$1 } from 'nice-grpc-client-middleware-retry';
12
+ import { TransactionOutput } from '@scure/btc-signer/psbt';
12
13
  import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
13
14
  import { EventEmitter } from 'eventemitter3';
14
15
 
@@ -38,15 +39,6 @@ declare function getNetworkFromAddress(address: string): BitcoinNetwork.MAINNET
38
39
  */
39
40
  declare function getNetworkFromString(network?: string): Network;
40
41
 
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
42
  declare const AddressNetwork: Record<NetworkType, string>;
51
43
  declare const LegacyAddressNetwork: Record<NetworkType, string>;
52
44
  type Bech32String = `${string}1${string}`;
@@ -94,6 +86,15 @@ declare function assertBech32(s: string): asserts s is Bech32String;
94
86
  declare function bech32mDecode(address: string): _scure_base.Bech32Decoded<string>;
95
87
  declare function isSafeForNumber(bi: bigint): boolean;
96
88
 
89
+ type Bech32mTokenIdentifier = `btkn1${string}` | `btknrt1${string}` | `btknt1${string}` | `btkns1${string}` | `btknl1${string}`;
90
+ interface Bech32mTokenIdentifierData {
91
+ tokenIdentifier: Uint8Array;
92
+ network: NetworkType;
93
+ }
94
+ declare function encodeBech32mTokenIdentifier(payload: Bech32mTokenIdentifierData): Bech32mTokenIdentifier;
95
+ declare function decodeBech32mTokenIdentifier(bech32mTokenIdentifier: Bech32mTokenIdentifier, network?: NetworkType): Bech32mTokenIdentifierData;
96
+ declare function getNetworkFromBech32mTokenIdentifier(bech32mTokenIdentifier: Bech32mTokenIdentifier): NetworkType;
97
+
97
98
  declare class WalletConfigService implements HasSspClientOptions {
98
99
  private readonly config;
99
100
  readonly signer: SparkSigner;
@@ -117,6 +118,7 @@ declare class WalletConfigService implements HasSspClientOptions {
117
118
  getSspIdentityPublicKey(): string;
118
119
  getConsoleOptions(): ConsoleOptions;
119
120
  getEvents(): Partial<SparkWalletEvents>;
121
+ getOptimizationOptions(): OptimizationOptions;
120
122
  }
121
123
 
122
124
  /** Challenge represents the core challenge data */
@@ -285,6 +287,7 @@ declare class SigningService {
285
287
  directLeafSigningJobs: UserSignedTxSigningJob[];
286
288
  directFromCpfpLeafSigningJobs: UserSignedTxSigningJob[];
287
289
  }>;
290
+ signSigningJobs(signingJobs: (SigningJobWithOptionalNonce & RequestedSigningCommitments)[]): Promise<Map<SigningJobType, UserSignedTxSigningJob>>;
288
291
  }
289
292
 
290
293
  type LeafKeyTweak = {
@@ -305,6 +308,17 @@ type LeafRefundSigningData = {
305
308
  directFromCpfpRefundSigningNonceCommitment: SigningCommitmentWithOptionalNonce;
306
309
  vout: number;
307
310
  };
311
+ type SigningJobType = "split" | "directSplit" | "node" | "directNode" | "cpfp" | "direct" | "directFromCpfp";
312
+ type SigningJobWithOptionalNonce = {
313
+ signingPublicKey: Uint8Array;
314
+ rawTx: Uint8Array;
315
+ signingNonceCommitment: SigningCommitmentWithOptionalNonce;
316
+ type: SigningJobType;
317
+ parentTxOut: TransactionOutput;
318
+ leafId: string;
319
+ keyDerivation: KeyDerivation;
320
+ verifyingKey: Uint8Array;
321
+ };
308
322
  declare class BaseTransferService {
309
323
  protected readonly config: WalletConfigService;
310
324
  protected readonly connectionManager: ConnectionManager;
@@ -357,11 +371,12 @@ declare class TransferService extends BaseTransferService {
357
371
  claimTransferSignRefunds(transfer: Transfer, leafKeys: LeafKeyTweak[], proofMap?: Map<string, Uint8Array[]>): Promise<NodeSignatures[]>;
358
372
  private finalizeNodeSignatures;
359
373
  queryPendingTransfersBySender(operatorAddress: string): Promise<QueryTransfersResponse>;
360
- private refreshTimelockNodesInternal;
361
- refreshTimelockNodes(node: TreeNode, parentNode: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
362
- extendTimelock(node: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
363
- testonly_expireTimeLockNodeTx(node: TreeNode, parentNode: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
364
- testonly_expireTimeLockRefundtx(node: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
374
+ renewRefundTxn(node: TreeNode, parentNode: TreeNode): Promise<TreeNode>;
375
+ renewNodeTxn(node: TreeNode, parentNode: TreeNode): Promise<TreeNode>;
376
+ private createRenewRefundSigningJobs;
377
+ private createRenewNodeSigningJobs;
378
+ renewZeroTimelockNodeTxn(node: TreeNode): Promise<TreeNode>;
379
+ private createRenewZeroTimelockNodeSigningJobs;
365
380
  }
366
381
 
367
382
  /**
@@ -401,13 +416,15 @@ declare abstract class SparkWallet extends EventEmitter<SparkWalletEvents> {
401
416
  private handleStreamEvent;
402
417
  protected setupBackgroundStream(): Promise<void>;
403
418
  getLeaves(isBalanceCheck?: boolean): Promise<TreeNode[]>;
404
- private checkExtendLeaves;
405
419
  private verifyKey;
406
420
  private popOrThrow;
407
421
  private selectLeaves;
408
422
  private selectLeavesForSwap;
409
- private areLeavesInefficient;
410
- private optimizeLeaves;
423
+ optimizeLeaves(multiplicity?: number | undefined): AsyncGenerator<{
424
+ step: number;
425
+ total: number;
426
+ controller: AbortController;
427
+ }, void, void>;
411
428
  private syncWallet;
412
429
  private withLeaves;
413
430
  /**
@@ -712,15 +729,7 @@ declare abstract class SparkWallet extends EventEmitter<SparkWalletEvents> {
712
729
  private transferWithInvoice;
713
730
  private buildTweaksByAmount;
714
731
  private toSendTweak;
715
- private checkExtendTimeLockNodes;
716
- /**
717
- * Internal method to refresh timelock nodes.
718
- *
719
- * @param {string} nodeId - The optional ID of the node to refresh. If not provided, all nodes will be checked.
720
- * @returns {Promise<void>}
721
- * @private
722
- */
723
- private checkRefreshTimelockNodes;
732
+ private checkRenewLeaves;
724
733
  private claimTransferCore;
725
734
  private processClaimedTransferResults;
726
735
  /**
@@ -959,13 +968,6 @@ declare abstract class SparkWallet extends EventEmitter<SparkWalletEvents> {
959
968
  nodeTimelock: number;
960
969
  refundTimelock: number;
961
970
  }>;
962
- /**
963
- * Refresh the timelock of a specific node.
964
- *
965
- * @param {string} nodeId - The ID of the node to refresh
966
- * @returns {Promise<void>} Promise that resolves when the timelock is refreshed
967
- */
968
- testOnly_expireTimelock(nodeId: string): Promise<void>;
969
971
  private cleanup;
970
972
  cleanupConnections(): Promise<void>;
971
973
  private startPeriodicClaimTransfers;
@@ -1143,6 +1145,10 @@ type SigningOperator = {
1143
1145
  type ConsoleOptions = {
1144
1146
  otel?: boolean;
1145
1147
  };
1148
+ type OptimizationOptions = {
1149
+ readonly auto?: boolean;
1150
+ readonly multiplicity?: number;
1151
+ };
1146
1152
  type ConfigOptions = MayHaveSspClientOptions & {
1147
1153
  readonly network?: NetworkType;
1148
1154
  readonly signingOperators?: Readonly<Record<string, SigningOperator>>;
@@ -1158,6 +1164,7 @@ type ConfigOptions = MayHaveSspClientOptions & {
1158
1164
  readonly signerWithPreExistingKeys?: boolean;
1159
1165
  readonly console?: ConsoleOptions;
1160
1166
  readonly events?: Partial<SparkWalletEvents>;
1167
+ readonly optimizationOptions?: OptimizationOptions;
1161
1168
  };
1162
1169
  declare const WalletConfig: {
1163
1170
  LOCAL: Required<ConfigOptions>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buildonspark/spark-sdk",
3
- "version": "0.3.8",
3
+ "version": "0.4.0",
4
4
  "author": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
@@ -7,9 +7,15 @@ setCrypto(globalThis.crypto);
7
7
  export * from "./errors/index.js";
8
8
  export * from "./utils/index.js";
9
9
 
10
- export { ReactNativeSparkSigner } from "./signer/signer.react-native.js";
10
+ export {
11
+ ReactNativeSparkSigner,
12
+ ReactNativeTaprootSparkSigner,
13
+ } from "./signer/signer.react-native.js";
11
14
  /* Enable some consumers to use named import DefaultSparkSigner regardless of module, see LIG-7662 */
12
- export { ReactNativeSparkSigner as DefaultSparkSigner } from "./signer/signer.react-native.js";
15
+ export {
16
+ ReactNativeSparkSigner as DefaultSparkSigner,
17
+ ReactNativeTaprootSparkSigner as TaprootSparkSigner,
18
+ } from "./signer/signer.react-native.js";
13
19
 
14
20
  export { SparkWallet } from "./spark-wallet/spark-wallet.react-native.js";
15
21
  export * from "./spark-wallet/types.js";