@buildonspark/spark-sdk 0.3.7 → 0.3.9

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 (87) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/bare/index.cjs +8088 -7723
  3. package/dist/bare/index.d.cts +350 -262
  4. package/dist/bare/index.d.ts +350 -262
  5. package/dist/bare/index.js +7968 -7608
  6. package/dist/{chunk-J2P3KTQP.js → chunk-4YFT7DAE.js} +1 -1
  7. package/dist/{chunk-XWLR6G5C.js → chunk-JLF6WJ7K.js} +1 -1
  8. package/dist/{chunk-UYTT3C6H.js → chunk-MFCM6GUD.js} +40 -213
  9. package/dist/{chunk-KDEVNW7C.js → chunk-O4C4HGQL.js} +3391 -3292
  10. package/dist/{chunk-SRPKOCG4.js → chunk-S55NZT4P.js} +8 -10
  11. package/dist/{chunk-P4HYYSMU.js → chunk-WRE2T22S.js} +1 -1
  12. package/dist/{chunk-IC4IUEOS.js → chunk-YEBEN7XD.js} +309 -38
  13. package/dist/{client-Bcb7TUIp.d.cts → client-BIqiUNy4.d.cts} +2 -2
  14. package/dist/{client-D9T58OY8.d.ts → client-BaQf-5gD.d.ts} +2 -2
  15. package/dist/debug.cjs +8068 -7704
  16. package/dist/debug.d.cts +25 -18
  17. package/dist/debug.d.ts +25 -18
  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 +6871 -6501
  22. package/dist/index.d.cts +9 -8
  23. package/dist/index.d.ts +9 -8
  24. package/dist/index.js +36 -24
  25. package/dist/index.node.cjs +7102 -6903
  26. package/dist/index.node.d.cts +9 -8
  27. package/dist/index.node.d.ts +9 -8
  28. package/dist/index.node.js +35 -23
  29. package/dist/{logging-zkr4UlOi.d.cts → logging-CXhvuqJJ.d.cts} +45 -35
  30. package/dist/{logging-JIaZZIbR.d.ts → logging-DDeMLsVN.d.ts} +45 -35
  31. package/dist/native/{chunk-X2QXUON7.js → chunk-AFP5QR4O.js} +11 -8
  32. package/dist/native/index.react-native.cjs +7054 -6677
  33. package/dist/native/index.react-native.d.cts +180 -92
  34. package/dist/native/index.react-native.d.ts +180 -92
  35. package/dist/native/index.react-native.js +6760 -6393
  36. package/dist/native/{wasm-GKEDPGTM.js → wasm-D4TI35NF.js} +1 -1
  37. package/dist/proto/spark.cjs +309 -38
  38. package/dist/proto/spark.d.cts +1 -1
  39. package/dist/proto/spark.d.ts +1 -1
  40. package/dist/proto/spark.js +5 -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-DOpheE8_.d.cts} +69 -7
  45. package/dist/{spark-WA_4wcBr.d.ts → spark-DOpheE8_.d.ts} +69 -7
  46. package/dist/{spark-wallet.browser-DC3jdQPW.d.cts → spark-wallet.browser-CbYo8A_U.d.cts} +8 -8
  47. package/dist/{spark-wallet.browser-BwYkkOBU.d.ts → spark-wallet.browser-Cz8c4kOW.d.ts} +8 -8
  48. package/dist/{spark-wallet.node-CR_zNxmy.d.cts → spark-wallet.node-4WQgWwB2.d.cts} +9 -31
  49. package/dist/{spark-wallet.node-C9d2W-Nb.d.ts → spark-wallet.node-CmIvxtcC.d.ts} +9 -31
  50. package/dist/tests/test-utils.cjs +7341 -7065
  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-Bu023ztN.d.ts} +2 -2
  55. package/dist/{token-transactions-I_OFIoNH.d.cts → token-transactions-CV8QD3I7.d.cts} +2 -2
  56. package/dist/types/index.cjs +307 -38
  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-Bmk2eAn8.d.ts} +310 -287
  61. package/dist/{spark-wallet-BuFrUWeE.d.cts → wallet-config-DQw5llqA.d.cts} +310 -287
  62. package/package.json +3 -3
  63. package/src/proto/mock.ts +0 -264
  64. package/src/proto/spark.ts +433 -46
  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/coop-exit.ts +26 -107
  70. package/src/services/deposit.ts +12 -48
  71. package/src/services/lightning.ts +30 -4
  72. package/src/services/signing.ts +187 -37
  73. package/src/services/transfer.ts +553 -723
  74. package/src/services/wallet-config.ts +6 -0
  75. package/src/spark-wallet/proto-descriptors.ts +1 -1
  76. package/src/spark-wallet/spark-wallet.ts +132 -313
  77. package/src/spark-wallet/types.ts +2 -2
  78. package/src/spark_descriptors.pb +0 -0
  79. package/src/tests/connection.test.ts +537 -0
  80. package/src/tests/integration/connection.test.ts +39 -0
  81. package/src/tests/integration/lightning.test.ts +32 -16
  82. package/src/tests/integration/static_deposit.test.ts +13 -11
  83. package/src/tests/integration/transfer.test.ts +13 -1
  84. package/src/tests/isHermeticTest.ts +1 -1
  85. package/src/tests/utils/test-faucet.ts +53 -20
  86. package/src/utils/htlc-transactions.ts +224 -0
  87. package/src/utils/transaction.ts +285 -248
@@ -3,14 +3,15 @@ import * as btc from '@scure/btc-signer';
3
3
  import { Transaction } from '@scure/btc-signer';
4
4
  import { HDKey } from '@scure/bip32';
5
5
  import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
6
- import { CallOptions, ClientMiddlewareCall, Metadata } from 'nice-grpc-common';
6
+ import { CallOptions, ClientMiddleware, ClientMiddlewareCall, Metadata } from 'nice-grpc-common';
7
+ import * as _scure_base from '@scure/base';
7
8
  import { Channel } from 'nice-grpc';
8
9
  import { Channel as Channel$1, createChannel } from 'nice-grpc-web';
9
- import * as _scure_base from '@scure/base';
10
+ import { RetryOptions as RetryOptions$1 } from 'nice-grpc-client-middleware-retry';
11
+ import { TransactionOutput, TransactionInput } from '@scure/btc-signer/psbt';
10
12
  import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
11
13
  import { EventEmitter } from 'eventemitter3';
12
14
  import * as nice_grpc_web_lib_client_Transport_js from 'nice-grpc-web/lib/client/Transport.js';
13
- import { TransactionOutput, TransactionInput } from '@scure/btc-signer/psbt';
14
15
 
15
16
  declare class SparkSDKError extends Error {
16
17
  readonly context: Record<string, unknown>;
@@ -962,7 +963,7 @@ interface GenerateDepositAddressRequest {
962
963
  }
963
964
  declare const GenerateDepositAddressRequest: MessageFns$2<GenerateDepositAddressRequest>;
964
965
  /** Address is the address of the user's public key + SE's public key. */
965
- interface Address {
966
+ interface Address$1 {
966
967
  /** The p2tr address of the user's public key + SE's public key. */
967
968
  address: string;
968
969
  /** The verifying key of the address, which is user's public key + SE's public key. */
@@ -972,10 +973,10 @@ interface Address {
972
973
  /** Is it a static deposit address */
973
974
  isStatic: boolean;
974
975
  }
975
- declare const Address: MessageFns$2<Address>;
976
+ declare const Address$1: MessageFns$2<Address$1>;
976
977
  /** GenerateDepositAddressResponse is the response to the request to generate a deposit address. */
977
978
  interface GenerateDepositAddressResponse {
978
- depositAddress: Address | undefined;
979
+ depositAddress: Address$1 | undefined;
979
980
  }
980
981
  declare const GenerateDepositAddressResponse: MessageFns$2<GenerateDepositAddressResponse>;
981
982
  /** GenerateStaticDepositAddressRequest is the request to generate a static deposit address. */
@@ -990,7 +991,7 @@ interface GenerateStaticDepositAddressRequest {
990
991
  declare const GenerateStaticDepositAddressRequest: MessageFns$2<GenerateStaticDepositAddressRequest>;
991
992
  /** GenerateStaticDepositAddressResponse is the response to the request to generate a static deposit address. */
992
993
  interface GenerateStaticDepositAddressResponse {
993
- depositAddress: Address | undefined;
994
+ depositAddress: Address$1 | undefined;
994
995
  }
995
996
  declare const GenerateStaticDepositAddressResponse: MessageFns$2<GenerateStaticDepositAddressResponse>;
996
997
  /**
@@ -1062,7 +1063,6 @@ interface SigningResult {
1062
1063
  declare const SigningResult: MessageFns$2<SigningResult>;
1063
1064
  interface RenewLeafRequest {
1064
1065
  leafId: string;
1065
- ownerIdentityPublicKey: Uint8Array;
1066
1066
  signingJobs?: //
1067
1067
  /**
1068
1068
  * Resets the node transaction timelock and refund transaction timelock
@@ -1088,6 +1088,17 @@ interface RenewLeafRequest {
1088
1088
  {
1089
1089
  $case: "renewRefundTimelockSigningJob";
1090
1090
  renewRefundTimelockSigningJob: RenewRefundTimelockSigningJob;
1091
+ } | //
1092
+ /**
1093
+ * A special case of refresh for when the node transaction is at 0 and
1094
+ * cannot be decremented further. This operation resets the refund
1095
+ * transaction's timelock and, similar to renew node, adds an additional
1096
+ * node transaction to the transaction chain with zero timelock as well.
1097
+ * This case is mostly used for user-created trees from L1 deposits.
1098
+ */
1099
+ {
1100
+ $case: "renewNodeZeroTimelockSigningJob";
1101
+ renewNodeZeroTimelockSigningJob: RenewNodeZeroTimelockSigningJob;
1091
1102
  } | undefined;
1092
1103
  }
1093
1104
  declare const RenewLeafRequest: MessageFns$2<RenewLeafRequest>;
@@ -1126,13 +1137,32 @@ interface RenewRefundTimelockSigningJob {
1126
1137
  directFromCpfpRefundTxSigningJob: UserSignedTxSigningJob | undefined;
1127
1138
  }
1128
1139
  declare const RenewRefundTimelockSigningJob: MessageFns$2<RenewRefundTimelockSigningJob>;
1140
+ interface RenewNodeZeroTimelockSigningJob {
1141
+ /**
1142
+ * Signing job with the new node transaction. The updated transaction is
1143
+ * expected to have a timelock of 0.
1144
+ */
1145
+ nodeTxSigningJob: UserSignedTxSigningJob | undefined;
1146
+ /**
1147
+ * Signing job with the updated refund transaction. This updated transaction
1148
+ * must have a timelock of 2000.
1149
+ */
1150
+ refundTxSigningJob: UserSignedTxSigningJob | undefined;
1151
+ directNodeTxSigningJob: UserSignedTxSigningJob | undefined;
1152
+ directRefundTxSigningJob: UserSignedTxSigningJob | undefined;
1153
+ directFromCpfpRefundTxSigningJob: UserSignedTxSigningJob | undefined;
1154
+ }
1155
+ declare const RenewNodeZeroTimelockSigningJob: MessageFns$2<RenewNodeZeroTimelockSigningJob>;
1129
1156
  interface RenewLeafResponse {
1130
1157
  renewResult?: {
1131
- $case: "extendResult";
1132
- extendResult: RenewNodeTimelockResult;
1158
+ $case: "renewNodeTimelockResult";
1159
+ renewNodeTimelockResult: RenewNodeTimelockResult;
1160
+ } | {
1161
+ $case: "renewRefundTimelockResult";
1162
+ renewRefundTimelockResult: RenewRefundTimelockResult;
1133
1163
  } | {
1134
- $case: "refreshResult";
1135
- refreshResult: RenewRefundTimelockResult;
1164
+ $case: "renewNodeZeroTimelockResult";
1165
+ renewNodeZeroTimelockResult: RenewNodeZeroTimelockResult;
1136
1166
  } | undefined;
1137
1167
  }
1138
1168
  declare const RenewLeafResponse: MessageFns$2<RenewLeafResponse>;
@@ -1145,6 +1175,11 @@ interface RenewRefundTimelockResult {
1145
1175
  node: TreeNode | undefined;
1146
1176
  }
1147
1177
  declare const RenewRefundTimelockResult: MessageFns$2<RenewRefundTimelockResult>;
1178
+ interface RenewNodeZeroTimelockResult {
1179
+ splitNode: TreeNode | undefined;
1180
+ node: TreeNode | undefined;
1181
+ }
1182
+ declare const RenewNodeZeroTimelockResult: MessageFns$2<RenewNodeZeroTimelockResult>;
1148
1183
  /**
1149
1184
  * NodeSignatureShares is the signature shares for a node on the tree.
1150
1185
  * For each tree node, the verifying key stays the same for both transactions.
@@ -1747,15 +1782,28 @@ interface RequestedSigningCommitments {
1747
1782
  }
1748
1783
  declare const RequestedSigningCommitments: MessageFns$2<RequestedSigningCommitments>;
1749
1784
  interface GetSigningCommitmentsRequest {
1785
+ /** The node IDs for which to get signing commitments. */
1750
1786
  nodeIds: string[];
1787
+ /** The number of signing commitments to get per node ID. */
1751
1788
  count: number;
1752
1789
  }
1753
1790
  declare const GetSigningCommitmentsRequest: MessageFns$2<GetSigningCommitmentsRequest>;
1754
1791
  interface GetSigningCommitmentsResponse {
1792
+ /**
1793
+ * A list of signing commitments for each requested node ID. The signing commitments will be
1794
+ * ordered in the same order as the requested node IDs, repeated for the number of commitments
1795
+ * requested. For example, if node_ids = [A, B] and count = 2, the response will contain:
1796
+ *
1797
+ * [commitment_A1, commitment_B1, commitment_A2, commitment_B2]
1798
+ */
1755
1799
  signingCommitments: RequestedSigningCommitments[];
1756
1800
  }
1757
1801
  declare const GetSigningCommitmentsResponse: MessageFns$2<GetSigningCommitmentsResponse>;
1758
1802
  interface SigningCommitments {
1803
+ /**
1804
+ * A map of signing operator ID (i.e. 000...01) to the signing commitment provided by that
1805
+ * operator.
1806
+ */
1759
1807
  signingCommitments: {
1760
1808
  [key: string]: SigningCommitment;
1761
1809
  };
@@ -1786,6 +1834,7 @@ interface InitiatePreimageSwapRequest {
1786
1834
  transfer: StartUserSignedTransferRequest | undefined;
1787
1835
  receiverIdentityPublicKey: Uint8Array;
1788
1836
  feeSats: number;
1837
+ transferRequest: StartTransferRequest | undefined;
1789
1838
  }
1790
1839
  declare const InitiatePreimageSwapRequest: MessageFns$2<InitiatePreimageSwapRequest>;
1791
1840
  interface InitiatePreimageSwapResponse {
@@ -2290,6 +2339,10 @@ declare const SparkServiceDefinition: {
2290
2339
  readonly responseStream: false;
2291
2340
  readonly options: {};
2292
2341
  };
2342
+ /**
2343
+ * Gets a specified number of signing commmitments for a set of nodes, which can be used as
2344
+ * part of a transfer package.
2345
+ */
2293
2346
  readonly get_signing_commitments: {
2294
2347
  readonly name: "get_signing_commitments";
2295
2348
  readonly requestType: MessageFns$2<GetSigningCommitmentsRequest>;
@@ -2677,6 +2730,10 @@ interface SparkServiceClient<CallOptionsExt = {}> {
2677
2730
  claim_transfer_tweak_keys(request: DeepPartial$2<ClaimTransferTweakKeysRequest>, options?: CallOptions & CallOptionsExt): Promise<Empty>;
2678
2731
  claim_transfer_sign_refunds(request: DeepPartial$2<ClaimTransferSignRefundsRequest>, options?: CallOptions & CallOptionsExt): Promise<ClaimTransferSignRefundsResponse>;
2679
2732
  store_preimage_share(request: DeepPartial$2<StorePreimageShareRequest>, options?: CallOptions & CallOptionsExt): Promise<Empty>;
2733
+ /**
2734
+ * Gets a specified number of signing commmitments for a set of nodes, which can be used as
2735
+ * part of a transfer package.
2736
+ */
2680
2737
  get_signing_commitments(request: DeepPartial$2<GetSigningCommitmentsRequest>, options?: CallOptions & CallOptionsExt): Promise<GetSigningCommitmentsResponse>;
2681
2738
  cooperative_exit(request: DeepPartial$2<CooperativeExitRequest>, options?: CallOptions & CallOptionsExt): Promise<CooperativeExitResponse>;
2682
2739
  initiate_preimage_swap(request: DeepPartial$2<InitiatePreimageSwapRequest>, options?: CallOptions & CallOptionsExt): Promise<InitiatePreimageSwapResponse>;
@@ -3469,6 +3526,174 @@ declare function getNetworkFromAddress(address: string): BitcoinNetwork.MAINNET
3469
3526
  */
3470
3527
  declare function getNetworkFromString(network?: string): Network;
3471
3528
 
3529
+ declare const AddressNetwork: Record<NetworkType, string>;
3530
+ declare const LegacyAddressNetwork: Record<NetworkType, string>;
3531
+ type Bech32String = `${string}1${string}`;
3532
+ type SparkAddressFormat = `${(typeof AddressNetwork)[keyof typeof AddressNetwork]}1${string}`;
3533
+ type LegacySparkAddressFormat = `${(typeof LegacyAddressNetwork)[keyof typeof LegacyAddressNetwork]}1${string}`;
3534
+ interface SparkAddressData {
3535
+ identityPublicKey: string;
3536
+ network: NetworkType;
3537
+ sparkInvoiceFields?: SparkInvoiceFields;
3538
+ }
3539
+ interface DecodedSparkAddressData {
3540
+ identityPublicKey: string;
3541
+ network: NetworkType;
3542
+ sparkInvoiceFields?: {
3543
+ version: number;
3544
+ id: string;
3545
+ paymentType?: {
3546
+ type: "tokens";
3547
+ tokenIdentifier?: string;
3548
+ amount?: bigint;
3549
+ } | {
3550
+ type: "sats";
3551
+ amount?: number;
3552
+ };
3553
+ memo?: string;
3554
+ senderPublicKey?: string;
3555
+ expiryTime?: Date;
3556
+ };
3557
+ signature?: string;
3558
+ }
3559
+ declare function encodeSparkAddress(payload: SparkAddressData): LegacySparkAddressFormat;
3560
+ declare function encodeSparkAddressWithSignature(payload: SparkAddressData, signature?: Uint8Array): LegacySparkAddressFormat;
3561
+ declare function decodeSparkAddress(address: string, network: NetworkType): DecodedSparkAddressData;
3562
+ declare function getNetworkFromSparkAddress(address: string): NetworkType;
3563
+ declare function isLegacySparkAddress(address: string): address is LegacySparkAddressFormat;
3564
+ declare function isValidSparkAddress(address: string): boolean;
3565
+ declare function isValidPublicKey(publicKey: string): void;
3566
+ declare function validateSparkInvoiceFields(sparkInvoiceFields: SparkInvoiceFields): void;
3567
+ declare function validateSparkInvoiceSignature(invoice: SparkAddressFormat): void;
3568
+ declare function toProtoTimestamp(date: Date): {
3569
+ seconds: number;
3570
+ nanos: number;
3571
+ };
3572
+ declare function assertBech32(s: string): asserts s is Bech32String;
3573
+ declare function bech32mDecode(address: string): _scure_base.Bech32Decoded<string>;
3574
+ declare function isSafeForNumber(bi: bigint): boolean;
3575
+
3576
+ type Bech32mTokenIdentifier = `btkn1${string}` | `btknrt1${string}` | `btknt1${string}` | `btkns1${string}` | `btknl1${string}`;
3577
+ interface Bech32mTokenIdentifierData {
3578
+ tokenIdentifier: Uint8Array;
3579
+ network: NetworkType;
3580
+ }
3581
+ declare function encodeBech32mTokenIdentifier(payload: Bech32mTokenIdentifierData): Bech32mTokenIdentifier;
3582
+ declare function decodeBech32mTokenIdentifier(bech32mTokenIdentifier: Bech32mTokenIdentifier, network?: NetworkType): Bech32mTokenIdentifierData;
3583
+ declare function getNetworkFromBech32mTokenIdentifier(bech32mTokenIdentifier: Bech32mTokenIdentifier): NetworkType;
3584
+
3585
+ type CreateLightningInvoiceParams = {
3586
+ amountSats: number;
3587
+ memo?: string;
3588
+ expirySeconds?: number;
3589
+ includeSparkAddress?: boolean;
3590
+ receiverIdentityPubkey?: string;
3591
+ descriptionHash?: string;
3592
+ };
3593
+ type PayLightningInvoiceParams = {
3594
+ invoice: string;
3595
+ maxFeeSats: number;
3596
+ preferSpark?: boolean;
3597
+ amountSatsToSend?: number;
3598
+ };
3599
+ type TransferParams = {
3600
+ amountSats: number;
3601
+ receiverSparkAddress: string;
3602
+ };
3603
+ type FulfillSparkInvoiceResponse = {
3604
+ satsTransactionSuccess: {
3605
+ invoice: SparkAddressFormat;
3606
+ transferResponse: WalletTransfer;
3607
+ }[];
3608
+ tokenTransactionSuccess: {
3609
+ tokenIdentifier: Bech32mTokenIdentifier;
3610
+ txid: string;
3611
+ }[];
3612
+ satsTransactionErrors: {
3613
+ invoice: string;
3614
+ error: Error;
3615
+ }[];
3616
+ tokenTransactionErrors: {
3617
+ tokenIdentifier: Bech32mTokenIdentifier;
3618
+ error: Error;
3619
+ }[];
3620
+ invalidInvoices: {
3621
+ invoice: string;
3622
+ error: Error;
3623
+ }[];
3624
+ };
3625
+ /**
3626
+ * Token metadata containing essential information about a token.
3627
+ * This is the wallet's internal representation with JavaScript-friendly types.
3628
+ *
3629
+ * rawTokenIdentifier: This is the raw binary token identifier - This is used to encode the bech32m encoded token identifier.
3630
+ *
3631
+ * tokenPublicKey: This is the hex-encoded public key of the token issuer - Same as issuerPublicKey.
3632
+ *
3633
+ * @example
3634
+ * ```typescript
3635
+ * const tokenMetadata: UserTokenMetadata = {
3636
+ * rawTokenIdentifier: new Uint8Array([1, 2, 3]),
3637
+ * tokenPublicKey: "0348fbb...",
3638
+ * tokenName: "SparkToken",
3639
+ * tokenTicker: "SPK",
3640
+ * decimals: 8,
3641
+ * maxSupply: 1000000n
3642
+ * };
3643
+ * ```
3644
+ */
3645
+ type UserTokenMetadata = {
3646
+ /** Raw binary token identifier - This is used to encode the human readable token identifier */
3647
+ rawTokenIdentifier: Uint8Array;
3648
+ /** Public key of the token issuer - Same as issuerPublicKey */
3649
+ tokenPublicKey: string;
3650
+ /** Human-readable name of the token (e.g., SparkToken)*/
3651
+ tokenName: string;
3652
+ /** Short ticker symbol for the token (e.g., "SPK") */
3653
+ tokenTicker: string;
3654
+ /** Number of decimal places for token amounts */
3655
+ decimals: number;
3656
+ /** Maximum supply of tokens that can ever be minted */
3657
+ maxSupply: bigint;
3658
+ };
3659
+ type TokenBalanceMap = Map<Bech32mTokenIdentifier, {
3660
+ balance: bigint;
3661
+ tokenMetadata: UserTokenMetadata;
3662
+ }>;
3663
+ type TokenOutputsMap = Map<Bech32mTokenIdentifier, OutputWithPreviousTransactionData$1[]>;
3664
+ type TokenMetadataMap = Map<Bech32mTokenIdentifier, TokenMetadata>;
3665
+ type InitWalletResponse<T extends SparkWallet = SparkWallet> = {
3666
+ wallet: T;
3667
+ mnemonic: string | undefined;
3668
+ };
3669
+ interface SparkWalletProps {
3670
+ mnemonicOrSeed?: Uint8Array | string;
3671
+ accountNumber?: number;
3672
+ signer?: SparkSigner;
3673
+ options?: ConfigOptions;
3674
+ }
3675
+ declare const SparkWalletEvent: {
3676
+ readonly All: "*";
3677
+ readonly TransferClaimed: "transfer:claimed";
3678
+ readonly DepositConfirmed: "deposit:confirmed";
3679
+ readonly StreamConnected: "stream:connected";
3680
+ readonly StreamDisconnected: "stream:disconnected";
3681
+ readonly StreamReconnecting: "stream:reconnecting";
3682
+ };
3683
+ interface SparkWalletEvents {
3684
+ [SparkWalletEvent.All]: (eventName: string, ...args: unknown[]) => void;
3685
+ /** Emitted when an incoming transfer is successfully claimed. Includes the transfer ID and new total balance. */
3686
+ [SparkWalletEvent.TransferClaimed]: (transferId: string, updatedBalance: bigint) => void;
3687
+ /** Emitted when a deposit is marked as available. Includes the deposit ID and new total balance. */
3688
+ [SparkWalletEvent.DepositConfirmed]: (depositId: string, updatedBalance: bigint) => void;
3689
+ /** Emitted when the stream is connected */
3690
+ [SparkWalletEvent.StreamConnected]: () => void;
3691
+ /** Emitted when the stream disconnects and fails to reconnect after max attempts */
3692
+ [SparkWalletEvent.StreamDisconnected]: (reason: string) => void;
3693
+ /** Emitted when attempting to reconnect the stream */
3694
+ [SparkWalletEvent.StreamReconnecting]: (attempt: number, maxAttempts: number, delayMs: number, error: string) => void;
3695
+ }
3696
+
3472
3697
  type SigningOperator = {
3473
3698
  readonly id: number;
3474
3699
  readonly identifier: string;
@@ -3492,6 +3717,7 @@ type ConfigOptions = MayHaveSspClientOptions & {
3492
3717
  readonly expectedWithdrawRelativeBlockLocktime?: number;
3493
3718
  readonly signerWithPreExistingKeys?: boolean;
3494
3719
  readonly console?: ConsoleOptions;
3720
+ readonly events?: Partial<SparkWalletEvents>;
3495
3721
  };
3496
3722
 
3497
3723
  declare class WalletConfigService implements HasSspClientOptions {
@@ -3516,6 +3742,7 @@ declare class WalletConfigService implements HasSspClientOptions {
3516
3742
  getSspBaseUrl(): string;
3517
3743
  getSspIdentityPublicKey(): string;
3518
3744
  getConsoleOptions(): ConsoleOptions;
3745
+ getEvents(): Partial<SparkWalletEvents>;
3519
3746
  }
3520
3747
 
3521
3748
  /** Challenge represents the core challenge data */
@@ -3620,87 +3847,55 @@ interface RetryOptions {
3620
3847
  }
3621
3848
  type SparkCallOptions = CallOptions & RetryOptions;
3622
3849
 
3623
- declare class ConnectionManager {
3624
- private config;
3625
- protected clients: Map<string, {
3626
- client: SparkServiceClient & {
3627
- close?: () => void;
3628
- };
3629
- authToken: string;
3850
+ type ChannelKey = string;
3851
+ type BrowserOrNodeJSChannel = Channel | Channel$1;
3852
+ type SparkClientType = "spark" | "stream" | "tokens";
3853
+ type Address = string;
3854
+ declare abstract class ConnectionManager {
3855
+ private static channelCache;
3856
+ private static channelInflight;
3857
+ private static authTokenCache;
3858
+ private static authInflight;
3859
+ protected makeChannelKey(address: Address, stream?: boolean): ChannelKey;
3860
+ protected static acquireChannel<T extends BrowserOrNodeJSChannel>(key: ChannelKey, create: () => Promise<T>): Promise<T>;
3861
+ protected static releaseChannel(key: ChannelKey): void;
3862
+ private static makeAuthTokenKey;
3863
+ private static getCachedAuthToken;
3864
+ private static setCachedAuthToken;
3865
+ private static invalidateCachedAuthToken;
3866
+ private static getOrCreateAuthToken;
3867
+ protected abstract createChannelWithTLS(address: Address, isStreamClientType?: boolean): Promise<Channel | Channel$1>;
3868
+ protected abstract createGrpcClient<T>(definition: SparkAuthnServiceDefinition | SparkServiceDefinition | SparkTokenServiceDefinition, channel: Channel | Channel$1, withRetries: boolean, middleware?: ClientMiddleware<RetryOptions$1, {}>, channelKey?: ChannelKey): Promise<T & {
3869
+ close?: () => void;
3630
3870
  }>;
3631
- private tokenClients;
3632
- private streamClients;
3633
- private authPromises;
3871
+ private config;
3872
+ private clientsByType;
3873
+ private identityPublicKeyHex?;
3634
3874
  constructor(config: WalletConfigService);
3635
3875
  createClients(): Promise<void>;
3636
3876
  closeConnections(): Promise<void>;
3637
- protected createChannelWithTLS(address: string, certPath?: string): Promise<Channel | Channel$1>;
3638
- createSparkStreamClient(address: string, certPath?: string): Promise<SparkServiceClient & {
3877
+ private getDefinitionForClientType;
3878
+ protected static isStreamClientType(type: SparkClientType): type is "stream";
3879
+ private getAddressToClientMap;
3880
+ private getOrCreateClientInternal;
3881
+ createSparkStreamClient(address: string): Promise<SparkServiceClient & {
3639
3882
  close?: () => void;
3640
3883
  }>;
3641
- createSparkClient(address: string, certPath?: string): Promise<SparkServiceClient & {
3884
+ createSparkClient(address: string): Promise<SparkServiceClient & {
3642
3885
  close?: () => void;
3643
3886
  }>;
3644
- createSparkTokenClient(address: string, certPath?: string): Promise<SparkTokenServiceClient & {
3887
+ createSparkTokenClient(address: string): Promise<SparkTokenServiceClient & {
3645
3888
  close?: () => void;
3646
3889
  }>;
3647
- getStreamChannel(address: string): Promise<Channel | Channel$1 | undefined>;
3648
- private authenticate;
3890
+ getChannelForClient(clientType: SparkClientType, address: Address): Promise<BrowserOrNodeJSChannel | undefined>;
3891
+ private getIdentityPublicKeyHex;
3892
+ protected authenticate(address: string): Promise<string>;
3649
3893
  private createSparkAuthnGrpcConnection;
3650
- protected createAuthnMiddleware(): (call: ClientMiddlewareCall<any, any>, options: SparkCallOptions) => AsyncGenerator<any, any, undefined>;
3651
- protected createMiddleware(address: string, authToken: string): ((call: ClientMiddlewareCall<any, any>, options: SparkCallOptions) => AsyncGenerator<any, any, undefined>) | undefined;
3652
- protected handleMiddlewareError(error: unknown, address: string, call: ClientMiddlewareCall<any, any>, metadata: Metadata, options: SparkCallOptions): AsyncGenerator<any, any, undefined>;
3653
- protected createGrpcClient<T>(defintion: SparkAuthnServiceDefinition | SparkServiceDefinition | SparkTokenServiceDefinition, channel: Channel | Channel$1, withRetries: boolean, middleware?: any): Promise<T & {
3654
- close?: () => void;
3655
- }>;
3656
- }
3657
-
3658
- declare const AddressNetwork: Record<NetworkType, string>;
3659
- declare const LegacyAddressNetwork: Record<NetworkType, string>;
3660
- type Bech32String = `${string}1${string}`;
3661
- type SparkAddressFormat = `${(typeof AddressNetwork)[keyof typeof AddressNetwork]}1${string}`;
3662
- type LegacySparkAddressFormat = `${(typeof LegacyAddressNetwork)[keyof typeof LegacyAddressNetwork]}1${string}`;
3663
- interface SparkAddressData {
3664
- identityPublicKey: string;
3665
- network: NetworkType;
3666
- sparkInvoiceFields?: SparkInvoiceFields;
3667
- }
3668
- interface DecodedSparkAddressData {
3669
- identityPublicKey: string;
3670
- network: NetworkType;
3671
- sparkInvoiceFields?: {
3672
- version: number;
3673
- id: string;
3674
- paymentType?: {
3675
- type: "tokens";
3676
- tokenIdentifier?: string;
3677
- amount?: bigint;
3678
- } | {
3679
- type: "sats";
3680
- amount?: number;
3681
- };
3682
- memo?: string;
3683
- senderPublicKey?: string;
3684
- expiryTime?: Date;
3685
- };
3686
- signature?: string;
3894
+ protected createAuthnMiddleware(): <Req, Res>(call: ClientMiddlewareCall<Req, Res>, options: SparkCallOptions) => AsyncGenerator<Res, Res | void, undefined>;
3895
+ protected createMiddleware(address: Address): <Req, Res>(call: ClientMiddlewareCall<Req, Res>, options: SparkCallOptions) => AsyncGenerator<Res, Res | void, undefined>;
3896
+ protected handleMiddlewareError<Req, Res>(error: unknown, address: string, call: ClientMiddlewareCall<Req, Res>, metadata: Metadata, options: SparkCallOptions): AsyncGenerator<Awaited<Res>, void | Awaited<Res>, undefined>;
3897
+ subscribeToEvents(address: string, signal: AbortSignal): Promise<AsyncIterable<SubscribeToEventsResponse>>;
3687
3898
  }
3688
- declare function encodeSparkAddress(payload: SparkAddressData): LegacySparkAddressFormat;
3689
- declare function encodeSparkAddressWithSignature(payload: SparkAddressData, signature?: Uint8Array): LegacySparkAddressFormat;
3690
- declare function decodeSparkAddress(address: string, network: NetworkType): DecodedSparkAddressData;
3691
- declare function getNetworkFromSparkAddress(address: string): NetworkType;
3692
- declare function isLegacySparkAddress(address: string): address is LegacySparkAddressFormat;
3693
- declare function isValidSparkAddress(address: string): boolean;
3694
- declare function isValidPublicKey(publicKey: string): void;
3695
- declare function validateSparkInvoiceFields(sparkInvoiceFields: SparkInvoiceFields): void;
3696
- declare function validateSparkInvoiceSignature(invoice: SparkAddressFormat): void;
3697
- declare function toProtoTimestamp(date: Date): {
3698
- seconds: number;
3699
- nanos: number;
3700
- };
3701
- declare function assertBech32(s: string): asserts s is Bech32String;
3702
- declare function bech32mDecode(address: string): _scure_base.Bech32Decoded<string>;
3703
- declare function isSafeForNumber(bi: bigint): boolean;
3704
3899
 
3705
3900
  declare class SigningService {
3706
3901
  private readonly config;
@@ -3711,6 +3906,12 @@ declare class SigningService {
3711
3906
  directLeafSigningJobs: UserSignedTxSigningJob[];
3712
3907
  directFromCpfpLeafSigningJobs: UserSignedTxSigningJob[];
3713
3908
  }>;
3909
+ signRefundsForLightning(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array, cpfpSigningCommitments: RequestedSigningCommitments[], directSigningCommitments: RequestedSigningCommitments[], directFromCpfpSigningCommitments: RequestedSigningCommitments[], hash: Uint8Array): Promise<{
3910
+ cpfpLeafSigningJobs: UserSignedTxSigningJob[];
3911
+ directLeafSigningJobs: UserSignedTxSigningJob[];
3912
+ directFromCpfpLeafSigningJobs: UserSignedTxSigningJob[];
3913
+ }>;
3914
+ signSigningJobs(signingJobs: (SigningJobWithOptionalNonce & RequestedSigningCommitments)[]): Promise<Map<SigningJobType, UserSignedTxSigningJob>>;
3714
3915
  }
3715
3916
 
3716
3917
  type LeafKeyTweak = {
@@ -3731,14 +3932,27 @@ type LeafRefundSigningData = {
3731
3932
  directFromCpfpRefundSigningNonceCommitment: SigningCommitmentWithOptionalNonce;
3732
3933
  vout: number;
3733
3934
  };
3935
+ type SigningJobType = "split" | "directSplit" | "node" | "directNode" | "cpfp" | "direct" | "directFromCpfp";
3936
+ type SigningJobWithOptionalNonce = {
3937
+ signingPublicKey: Uint8Array;
3938
+ rawTx: Uint8Array;
3939
+ signingNonceCommitment: SigningCommitmentWithOptionalNonce;
3940
+ type: SigningJobType;
3941
+ parentTxOut: TransactionOutput;
3942
+ leafId: string;
3943
+ keyDerivation: KeyDerivation;
3944
+ verifyingKey: Uint8Array;
3945
+ };
3734
3946
  declare class BaseTransferService {
3735
3947
  protected readonly config: WalletConfigService;
3736
3948
  protected readonly connectionManager: ConnectionManager;
3737
3949
  protected readonly signingService: SigningService;
3738
3950
  constructor(config: WalletConfigService, connectionManager: ConnectionManager, signingService: SigningService);
3739
3951
  deliverTransferPackage(transfer: Transfer, leaves: LeafKeyTweak[], cpfpRefundSignatureMap: Map<string, Uint8Array>, directRefundSignatureMap: Map<string, Uint8Array>, directFromCpfpRefundSignatureMap: Map<string, Uint8Array>): Promise<Transfer>;
3952
+ prepareTransferForLightning(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array, paymentHash: Uint8Array, expiryTime: Date, transferID: string): Promise<StartTransferRequest>;
3740
3953
  sendTransferWithKeyTweaks(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array, sparkInvoice?: SparkAddressFormat): Promise<Transfer>;
3741
3954
  private prepareTransferPackage;
3955
+ private prepareTransferPackageForLightning;
3742
3956
  signRefunds(leafDataMap: Map<string, LeafRefundSigningData>, operatorSigningResults: LeafRefundTxSigningResult[]): Promise<NodeSignatures[]>;
3743
3957
  private prepareSendTransferKeyTweaks;
3744
3958
  private prepareSingleSendTransferKeyTweak;
@@ -3781,132 +3995,12 @@ declare class TransferService extends BaseTransferService {
3781
3995
  claimTransferSignRefunds(transfer: Transfer, leafKeys: LeafKeyTweak[], proofMap?: Map<string, Uint8Array[]>): Promise<NodeSignatures[]>;
3782
3996
  private finalizeNodeSignatures;
3783
3997
  queryPendingTransfersBySender(operatorAddress: string): Promise<QueryTransfersResponse>;
3784
- private refreshTimelockNodesInternal;
3785
- refreshTimelockNodes(node: TreeNode, parentNode: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
3786
- extendTimelock(node: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
3787
- testonly_expireTimeLockNodeTx(node: TreeNode, parentNode: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
3788
- testonly_expireTimeLockRefundtx(node: TreeNode): Promise<FinalizeNodeSignaturesResponse>;
3789
- }
3790
-
3791
- type Bech32mTokenIdentifier = `btkn1${string}` | `btknrt1${string}` | `btknt1${string}` | `btkns1${string}` | `btknl1${string}`;
3792
- interface Bech32mTokenIdentifierData {
3793
- tokenIdentifier: Uint8Array;
3794
- network: NetworkType;
3795
- }
3796
- declare function encodeBech32mTokenIdentifier(payload: Bech32mTokenIdentifierData): Bech32mTokenIdentifier;
3797
- declare function decodeBech32mTokenIdentifier(bech32mTokenIdentifier: Bech32mTokenIdentifier, network?: NetworkType): Bech32mTokenIdentifierData;
3798
- declare function getNetworkFromBech32mTokenIdentifier(bech32mTokenIdentifier: Bech32mTokenIdentifier): NetworkType;
3799
-
3800
- type CreateLightningInvoiceParams = {
3801
- amountSats: number;
3802
- memo?: string;
3803
- expirySeconds?: number;
3804
- includeSparkAddress?: boolean;
3805
- receiverIdentityPubkey?: string;
3806
- descriptionHash?: string;
3807
- };
3808
- type PayLightningInvoiceParams = {
3809
- invoice: string;
3810
- maxFeeSats: number;
3811
- preferSpark?: boolean;
3812
- amountSatsToSend?: number;
3813
- };
3814
- type TransferParams = {
3815
- amountSats: number;
3816
- receiverSparkAddress: string;
3817
- };
3818
- type FulfillSparkInvoiceResponse = {
3819
- satsTransactionSuccess: {
3820
- invoice: SparkAddressFormat;
3821
- transferResponse: WalletTransfer;
3822
- }[];
3823
- tokenTransactionSuccess: {
3824
- tokenIdentifier: Bech32mTokenIdentifier;
3825
- txid: string;
3826
- }[];
3827
- satsTransactionErrors: {
3828
- invoice: string;
3829
- error: Error;
3830
- }[];
3831
- tokenTransactionErrors: {
3832
- tokenIdentifier: Bech32mTokenIdentifier;
3833
- error: Error;
3834
- }[];
3835
- invalidInvoices: {
3836
- invoice: string;
3837
- error: Error;
3838
- }[];
3839
- };
3840
- /**
3841
- * Token metadata containing essential information about a token.
3842
- * This is the wallet's internal representation with JavaScript-friendly types.
3843
- *
3844
- * rawTokenIdentifier: This is the raw binary token identifier - This is used to encode the bech32m encoded token identifier.
3845
- *
3846
- * tokenPublicKey: This is the hex-encoded public key of the token issuer - Same as issuerPublicKey.
3847
- *
3848
- * @example
3849
- * ```typescript
3850
- * const tokenMetadata: UserTokenMetadata = {
3851
- * rawTokenIdentifier: new Uint8Array([1, 2, 3]),
3852
- * tokenPublicKey: "0348fbb...",
3853
- * tokenName: "SparkToken",
3854
- * tokenTicker: "SPK",
3855
- * decimals: 8,
3856
- * maxSupply: 1000000n
3857
- * };
3858
- * ```
3859
- */
3860
- type UserTokenMetadata = {
3861
- /** Raw binary token identifier - This is used to encode the human readable token identifier */
3862
- rawTokenIdentifier: Uint8Array;
3863
- /** Public key of the token issuer - Same as issuerPublicKey */
3864
- tokenPublicKey: string;
3865
- /** Human-readable name of the token (e.g., SparkToken)*/
3866
- tokenName: string;
3867
- /** Short ticker symbol for the token (e.g., "SPK") */
3868
- tokenTicker: string;
3869
- /** Number of decimal places for token amounts */
3870
- decimals: number;
3871
- /** Maximum supply of tokens that can ever be minted */
3872
- maxSupply: bigint;
3873
- };
3874
- type TokenBalanceMap = Map<Bech32mTokenIdentifier, {
3875
- balance: bigint;
3876
- tokenMetadata: UserTokenMetadata;
3877
- }>;
3878
- type TokenOutputsMap = Map<Bech32mTokenIdentifier, OutputWithPreviousTransactionData$1[]>;
3879
- type TokenMetadataMap = Map<Bech32mTokenIdentifier, TokenMetadata>;
3880
- type InitWalletResponse<T extends SparkWallet = SparkWallet> = {
3881
- wallet: T;
3882
- mnemonic: string | undefined;
3883
- };
3884
- interface SparkWalletProps {
3885
- mnemonicOrSeed?: Uint8Array | string;
3886
- accountNumber?: number;
3887
- signer?: SparkSigner;
3888
- options?: ConfigOptions;
3889
- }
3890
- declare const SparkWalletEvent: {
3891
- readonly All: "*";
3892
- readonly TransferClaimed: "transfer:claimed";
3893
- readonly DepositConfirmed: "deposit:confirmed";
3894
- readonly StreamConnected: "stream:connected";
3895
- readonly StreamDisconnected: "stream:disconnected";
3896
- readonly StreamReconnecting: "stream:reconnecting";
3897
- };
3898
- interface SparkWalletEvents {
3899
- [SparkWalletEvent.All]: (eventName: string, ...args: unknown[]) => void;
3900
- /** Emitted when an incoming transfer is successfully claimed. Includes the transfer ID and new total balance. */
3901
- [SparkWalletEvent.TransferClaimed]: (transferId: string, updatedBalance: bigint) => void;
3902
- /** Emitted when a deposit is marked as available. Includes the deposit ID and new total balance. */
3903
- [SparkWalletEvent.DepositConfirmed]: (depositId: string, updatedBalance: bigint) => void;
3904
- /** Emitted when the stream is connected */
3905
- [SparkWalletEvent.StreamConnected]: () => void;
3906
- /** Emitted when the stream disconnects and fails to reconnect after max attempts */
3907
- [SparkWalletEvent.StreamDisconnected]: (reason: string) => void;
3908
- /** Emitted when attempting to reconnect the stream */
3909
- [SparkWalletEvent.StreamReconnecting]: (attempt: number, maxAttempts: number, delayMs: number, error: string) => void;
3998
+ renewRefundTxn(node: TreeNode, parentNode: TreeNode): Promise<TreeNode>;
3999
+ renewNodeTxn(node: TreeNode, parentNode: TreeNode): Promise<TreeNode>;
4000
+ private createRenewRefundSigningJobs;
4001
+ private createRenewNodeSigningJobs;
4002
+ renewZeroTimelockNodeTxn(node: TreeNode): Promise<TreeNode>;
4003
+ private createRenewZeroTimelockNodeSigningJobs;
3910
4004
  }
3911
4005
 
3912
4006
  /**
@@ -3937,16 +4031,15 @@ declare abstract class SparkWallet extends EventEmitter<SparkWalletEvents> {
3937
4031
  protected tokenOutputs: TokenOutputsMap;
3938
4032
  private claimTransfersInterval;
3939
4033
  private tracer;
4034
+ protected abstract buildConnectionManager(config: WalletConfigService): ConnectionManager;
3940
4035
  constructor(options?: ConfigOptions, signerArg?: SparkSigner);
3941
4036
  static initialize<T extends SparkWallet>(this: new (options?: ConfigOptions, signer?: SparkSigner) => T, { mnemonicOrSeed, accountNumber, signer, options }: SparkWalletProps): Promise<InitWalletResponse<T>>;
3942
4037
  private createClientsAndSyncWallet;
3943
4038
  private getSspClient;
3944
4039
  protected buildSigner(): DefaultSparkSigner;
3945
- protected buildConnectionManager(config: WalletConfigService): ConnectionManager;
3946
4040
  private handleStreamEvent;
3947
4041
  protected setupBackgroundStream(): Promise<void>;
3948
4042
  getLeaves(isBalanceCheck?: boolean): Promise<TreeNode[]>;
3949
- private checkExtendLeaves;
3950
4043
  private verifyKey;
3951
4044
  private popOrThrow;
3952
4045
  private selectLeaves;
@@ -4257,15 +4350,7 @@ declare abstract class SparkWallet extends EventEmitter<SparkWalletEvents> {
4257
4350
  private transferWithInvoice;
4258
4351
  private buildTweaksByAmount;
4259
4352
  private toSendTweak;
4260
- private checkExtendTimeLockNodes;
4261
- /**
4262
- * Internal method to refresh timelock nodes.
4263
- *
4264
- * @param {string} nodeId - The optional ID of the node to refresh. If not provided, all nodes will be checked.
4265
- * @returns {Promise<void>}
4266
- * @private
4267
- */
4268
- private checkRefreshTimelockNodes;
4353
+ private checkRenewLeaves;
4269
4354
  private claimTransferCore;
4270
4355
  private processClaimedTransferResults;
4271
4356
  /**
@@ -4504,13 +4589,6 @@ declare abstract class SparkWallet extends EventEmitter<SparkWalletEvents> {
4504
4589
  nodeTimelock: number;
4505
4590
  refundTimelock: number;
4506
4591
  }>;
4507
- /**
4508
- * Refresh the timelock of a specific node.
4509
- *
4510
- * @param {string} nodeId - The ID of the node to refresh
4511
- * @returns {Promise<void>} Promise that resolves when the timelock is refreshed
4512
- */
4513
- testOnly_expireTimelock(nodeId: string): Promise<void>;
4514
4592
  private cleanup;
4515
4593
  cleanupConnections(): Promise<void>;
4516
4594
  private startPeriodicClaimTransfers;
@@ -4533,11 +4611,11 @@ type Transport = NonNullable<Parameters<typeof createChannel>[1]>;
4533
4611
  declare class ConnectionManagerBrowser extends ConnectionManager {
4534
4612
  protected transport: Transport;
4535
4613
  constructor(config: WalletConfigService, transport?: nice_grpc_web_lib_client_Transport_js.Transport);
4536
- protected createChannelWithTLS(address: string, certPath?: string): Promise<Channel$1>;
4537
- protected createAuthnMiddleware(): (call: ClientMiddlewareCall<any, any>, options: SparkCallOptions) => AsyncGenerator<any, any, undefined>;
4538
- protected createMiddleware(address: string, initialAuthToken: string): (call: ClientMiddlewareCall<any, any>, options: SparkCallOptions) => AsyncGenerator<any, any, undefined>;
4539
- protected createGrpcClient<T>(defintion: SparkAuthnServiceDefinition | SparkServiceDefinition | SparkTokenServiceDefinition, channel: Channel$1, withRetries: boolean, middleware?: any): Promise<T & {
4540
- close: undefined;
4614
+ protected createChannelWithTLS(address: string): Promise<Channel$1>;
4615
+ protected createAuthnMiddleware(): <Req, Res>(call: ClientMiddlewareCall<Req, Res>, options: SparkCallOptions) => AsyncGenerator<Res, Res | void, undefined>;
4616
+ protected createMiddleware(address: string): <Req, Res>(call: ClientMiddlewareCall<Req, Res>, options: SparkCallOptions) => AsyncGenerator<Res, Res | void, undefined>;
4617
+ protected createGrpcClient<T>(definition: SparkAuthnServiceDefinition | SparkServiceDefinition | SparkTokenServiceDefinition, channel: Channel$1, withRetries: boolean, middleware?: ClientMiddleware<RetryOptions, {}>, channelKey?: string): Promise<T & {
4618
+ close: (() => void) | undefined;
4541
4619
  }>;
4542
4620
  }
4543
4621
 
@@ -4609,8 +4687,9 @@ declare function filterTokenBalanceForTokenIdentifier(tokenBalances: TokenBalanc
4609
4687
  declare function getTransferPackageSigningPayload(transferID: string, transferPackage: TransferPackage): Uint8Array;
4610
4688
 
4611
4689
  declare const DIRECT_TIMELOCK_OFFSET = 50;
4690
+ declare const HTLC_TIMELOCK_OFFSET = 70;
4691
+ declare const DIRECT_HTLC_TIMELOCK_OFFSET = 85;
4612
4692
  declare const INITIAL_SEQUENCE: number;
4613
- declare const INITIAL_DIRECT_SEQUENCE: number;
4614
4693
  declare const TEST_UNILATERAL_SEQUENCE: number;
4615
4694
  declare const TEST_UNILATERAL_DIRECT_SEQUENCE: number;
4616
4695
  declare const DEFAULT_FEE_SATS: number;
@@ -4619,51 +4698,60 @@ declare const DEFAULT_FEE_SATS: number;
4619
4698
  * Returns the original amount if it's less than or equal to the fee.
4620
4699
  */
4621
4700
  declare function maybeApplyFee(amount: bigint): bigint;
4622
- declare function createRootTx(depositOutPoint: TransactionInput, depositTxOut: TransactionOutput): [Transaction, Transaction];
4623
- declare function createSplitTx(parentOutPoint: TransactionInput, childTxOuts: TransactionOutput[]): [Transaction, Transaction];
4624
- interface CreateNodeTxInput {
4625
- txOut: TransactionOutput;
4626
- parentOutPoint: TransactionInput;
4627
- applyFee?: boolean;
4628
- includeAnchor?: boolean;
4629
- }
4630
- declare function createNodeTx({ txOut, parentOutPoint, applyFee, includeAnchor, }: CreateNodeTxInput): Transaction;
4631
- declare function createNodeTxs(txOut: TransactionOutput, txIn: TransactionInput, directTxIn?: TransactionInput): {
4632
- cpfpNodeTx: Transaction;
4633
- directNodeTx?: Transaction;
4701
+ declare function createRootNodeTx(parentTx: Transaction, vout: number): {
4702
+ nodeTx: Transaction;
4703
+ directNodeTx: Transaction;
4634
4704
  };
4635
- declare function createLeafNodeTx(sequence: number, directSequence: number, parentOutPoint: TransactionInput, txOut: TransactionOutput, shouldCalculateFee: boolean): [Transaction, Transaction];
4636
- interface CreateRefundTxInput {
4637
- sequence: number;
4638
- input: TransactionInput;
4639
- amountSats: bigint;
4705
+ declare function createZeroTimelockNodeTx(parentTx: Transaction): {
4706
+ nodeTx: Transaction;
4707
+ directNodeTx: Transaction;
4708
+ };
4709
+ declare function createInitialTimelockNodeTx(parentTx: Transaction): {
4710
+ nodeTx: Transaction;
4711
+ directNodeTx: Transaction;
4712
+ };
4713
+ declare function createDecrementedTimelockNodeTx(parentTx: Transaction, currentTx: Transaction): {
4714
+ nodeTx: Transaction;
4715
+ directNodeTx: Transaction;
4716
+ };
4717
+ declare function createTestUnilateralTimelockNodeTx(parentTx: Transaction, nodeTx: Transaction): {
4718
+ nodeTx: Transaction;
4719
+ directNodeTx: Transaction;
4720
+ };
4721
+ declare function getNextHTLCTransactionSequence(currSequence: number, isNodeTx?: boolean): {
4722
+ nextSequence: number;
4723
+ nextDirectSequence: number;
4724
+ };
4725
+ interface RefundTxParams {
4726
+ nodeTx: Transaction;
4727
+ directNodeTx?: Transaction;
4640
4728
  receivingPubkey: Uint8Array;
4641
4729
  network: Network;
4642
- shouldCalculateFee: boolean;
4643
- includeAnchor: boolean;
4644
4730
  }
4645
- declare function createRefundTx({ sequence, input, amountSats, receivingPubkey, network, shouldCalculateFee, includeAnchor, }: CreateRefundTxInput): Transaction;
4646
- interface CreateRefundTxsInput {
4731
+ interface RefundTxWithSequenceParams extends RefundTxParams {
4647
4732
  sequence: number;
4648
- directSequence?: number;
4649
- input: TransactionInput;
4650
- directInput?: TransactionInput;
4651
- amountSats: bigint;
4652
- receivingPubkey: Uint8Array;
4653
- network: Network;
4654
4733
  }
4655
- declare function createRefundTxs({ sequence, directSequence, input, directInput, amountSats, receivingPubkey, network, }: CreateRefundTxsInput): {
4734
+ interface RefundTxWithSequenceAndConnectorOutputParams extends RefundTxWithSequenceParams {
4735
+ connectorOutput: TransactionInput;
4736
+ }
4737
+ interface RefundTxs {
4656
4738
  cpfpRefundTx: Transaction;
4657
4739
  directRefundTx?: Transaction;
4658
4740
  directFromCpfpRefundTx?: Transaction;
4659
- };
4660
- declare function createConnectorRefundTransactions(sequence: number, cpfpNodeOutPoint: TransactionInput, directNodeOutPoint: TransactionInput, connectorOutput: TransactionInput, amountSats: bigint, receiverPubKey: Uint8Array, network: Network, shouldCalculateFee: boolean): [Transaction, Transaction, Transaction];
4741
+ }
4742
+ declare function createInitialTimelockRefundTxs(params: RefundTxParams): RefundTxs;
4743
+ declare function createDecrementedTimelockRefundTxs(params: RefundTxWithSequenceParams): RefundTxs;
4744
+ declare function createCurrentTimelockRefundTxs(params: RefundTxWithSequenceParams): RefundTxs;
4745
+ declare function createTestUnilateralRefundTxs(params: RefundTxParams): RefundTxs;
4746
+ declare function createConnectorRefundTxs(params: RefundTxWithSequenceAndConnectorOutputParams): RefundTxs;
4661
4747
  declare function getCurrentTimelock(currSequence?: number): number;
4662
4748
  declare function getTransactionSequence(currSequence?: number): {
4663
4749
  nextSequence: number;
4664
4750
  nextDirectSequence: number;
4665
4751
  };
4666
4752
  declare function checkIfValidSequence(currSequence?: number): void;
4753
+ declare function isZeroTimelock(currSequence: number): boolean;
4754
+ declare function doesTxnNeedRenewed(currSequence: number): boolean;
4667
4755
  declare function doesLeafNeedRefresh(currSequence: number, isNodeTx?: boolean): boolean;
4668
4756
  declare function getNextTransactionSequence(currSequence: number, isNodeTx?: boolean): {
4669
4757
  nextSequence: number;
@@ -4735,4 +4823,4 @@ declare class SparkSdkLogger {
4735
4823
  static setAllEnabled(enabled: boolean): void;
4736
4824
  }
4737
4825
 
4738
- export { type AggregateFrostParams, AuthenticationError, type Bech32mTokenIdentifier, type Bech32mTokenIdentifierData, type BroadcastConfig, type BroadcastResult, ConfigurationError, DEFAULT_FEE_SATS, DIRECT_TIMELOCK_OFFSET, type DecodedSparkAddressData, DefaultSparkSigner, type FeeBumpTxChain, type FeeBumpTxPackage, type FeeRate, type IKeyPackage, INITIAL_DIRECT_SEQUENCE, INITIAL_SEQUENCE, InternalValidationError, LOGGER_NAMES, type LeafInfo, type LegacySparkAddressFormat, type LoggerName, Network, NetworkError, NetworkToProto, type NetworkType, NotImplementedError, RPCError, type SignFrostParams, type SparkAddressData, type SparkAddressFormat, SparkSDKError, SparkSdkLogger, type SparkSigner, SparkWalletBare as SparkWallet, TEST_UNILATERAL_DIRECT_SEQUENCE, TEST_UNILATERAL_SEQUENCE, TaprootOutputKeysGenerator, TaprootSparkSigner, type TxChain, UnsafeStatelessSparkSigner, type Utxo, ValidationError, type VerifiableSecretShare, addPrivateKeys, addPublicKeys, applyAdaptorToSignature, applyAdditiveTweakToPublicKey, assertBech32, bech32mDecode, bigIntToPrivateKey, checkIfSelectedOutputsAreAvailable, checkIfValidSequence, collectResponses, computeTaprootKeyNoScript, computerLagrangeCoefficients, constructFeeBumpTx, constructUnilateralExitFeeBumpPackages, constructUnilateralExitTxs, createConnectorRefundTransactions, createLeafNodeTx, createNodeTx, createNodeTxs, createRefundTx, createRefundTxs, createRootTx, createSigningCommitment, createSigningNonce, createSplitTx, decodeBech32mTokenIdentifier, decodeBytesToSigningCommitment, decodeBytesToSigningNonce, decodeSparkAddress, doesLeafNeedRefresh, encodeBech32mTokenIdentifier, encodeSigningCommitmentToBytes, encodeSigningNonceToBytes, encodeSparkAddress, encodeSparkAddressWithSignature, evaluatePolynomial, fieldDiv, filterTokenBalanceForTokenIdentifier, generateAdaptorFromSignature, generatePolynomialForSecretSharing, generateSignatureFromExistingAdaptor, getCurrentTimelock, getEphemeralAnchorOutput, getLatestDepositTxId, getNetwork, getNetworkFromAddress, getNetworkFromBech32mTokenIdentifier, getNetworkFromSparkAddress, getNetworkFromString, getNextTransactionSequence, getP2TRAddressFromPkScript, getP2TRAddressFromPublicKey, getP2TRScriptFromPublicKey, getP2WPKHAddressFromPublicKey, getRandomBigInt, getRandomSigningNonce, getSigHashFromTx, getSigningCommitmentFromNonce, getSparkAddressFromTaproot, getTransactionSequence, getTransferPackageSigningPayload, getTxEstimatedVbytesSizeByNumberOfInputsOutputs, getTxFromRawTxBytes, getTxFromRawTxHex, getTxId, getTxIdNoReverse, isEphemeralAnchorOutput, isLegacySparkAddress, isSafeForNumber, isTxBroadcast, isValidPublicKey, isValidSparkAddress, lastKeyWithTarget, maybeApplyFee, modInverse, proofOfPossessionMessageHashForDepositAddress, protoToNetwork, recoverSecret, splitSecret, splitSecretWithProofs, subtractPrivateKeys, subtractPublicKeys, sumAvailableTokens, sumOfPrivateKeys, toProtoTimestamp, validateOutboundAdaptorSignature, validateShare, validateSparkInvoiceFields, validateSparkInvoiceSignature };
4826
+ export { type AggregateFrostParams, AuthenticationError, type Bech32mTokenIdentifier, type Bech32mTokenIdentifierData, type BroadcastConfig, type BroadcastResult, ConfigurationError, DEFAULT_FEE_SATS, DIRECT_HTLC_TIMELOCK_OFFSET, DIRECT_TIMELOCK_OFFSET, type DecodedSparkAddressData, DefaultSparkSigner, type FeeBumpTxChain, type FeeBumpTxPackage, type FeeRate, HTLC_TIMELOCK_OFFSET, type IKeyPackage, INITIAL_SEQUENCE, InternalValidationError, LOGGER_NAMES, type LeafInfo, type LegacySparkAddressFormat, type LoggerName, Network, NetworkError, NetworkToProto, type NetworkType, NotImplementedError, RPCError, type SignFrostParams, type SparkAddressData, type SparkAddressFormat, SparkSDKError, SparkSdkLogger, type SparkSigner, SparkWalletBare as SparkWallet, TEST_UNILATERAL_DIRECT_SEQUENCE, TEST_UNILATERAL_SEQUENCE, TaprootOutputKeysGenerator, TaprootSparkSigner, type TxChain, UnsafeStatelessSparkSigner, type Utxo, ValidationError, type VerifiableSecretShare, addPrivateKeys, addPublicKeys, applyAdaptorToSignature, applyAdditiveTweakToPublicKey, assertBech32, bech32mDecode, bigIntToPrivateKey, checkIfSelectedOutputsAreAvailable, checkIfValidSequence, collectResponses, computeTaprootKeyNoScript, computerLagrangeCoefficients, constructFeeBumpTx, constructUnilateralExitFeeBumpPackages, constructUnilateralExitTxs, createConnectorRefundTxs, createCurrentTimelockRefundTxs, createDecrementedTimelockNodeTx, createDecrementedTimelockRefundTxs, createInitialTimelockNodeTx, createInitialTimelockRefundTxs, createRootNodeTx, createSigningCommitment, createSigningNonce, createTestUnilateralRefundTxs, createTestUnilateralTimelockNodeTx, createZeroTimelockNodeTx, decodeBech32mTokenIdentifier, decodeBytesToSigningCommitment, decodeBytesToSigningNonce, decodeSparkAddress, doesLeafNeedRefresh, doesTxnNeedRenewed, encodeBech32mTokenIdentifier, encodeSigningCommitmentToBytes, encodeSigningNonceToBytes, encodeSparkAddress, encodeSparkAddressWithSignature, evaluatePolynomial, fieldDiv, filterTokenBalanceForTokenIdentifier, generateAdaptorFromSignature, generatePolynomialForSecretSharing, generateSignatureFromExistingAdaptor, getCurrentTimelock, getEphemeralAnchorOutput, getLatestDepositTxId, getNetwork, getNetworkFromAddress, getNetworkFromBech32mTokenIdentifier, getNetworkFromSparkAddress, getNetworkFromString, getNextHTLCTransactionSequence, getNextTransactionSequence, getP2TRAddressFromPkScript, getP2TRAddressFromPublicKey, getP2TRScriptFromPublicKey, getP2WPKHAddressFromPublicKey, getRandomBigInt, getRandomSigningNonce, getSigHashFromTx, getSigningCommitmentFromNonce, getSparkAddressFromTaproot, getTransactionSequence, getTransferPackageSigningPayload, getTxEstimatedVbytesSizeByNumberOfInputsOutputs, getTxFromRawTxBytes, getTxFromRawTxHex, getTxId, getTxIdNoReverse, isEphemeralAnchorOutput, isLegacySparkAddress, isSafeForNumber, isTxBroadcast, isValidPublicKey, isValidSparkAddress, isZeroTimelock, lastKeyWithTarget, maybeApplyFee, modInverse, proofOfPossessionMessageHashForDepositAddress, protoToNetwork, recoverSecret, splitSecret, splitSecretWithProofs, subtractPrivateKeys, subtractPublicKeys, sumAvailableTokens, sumOfPrivateKeys, toProtoTimestamp, validateOutboundAdaptorSignature, validateShare, validateSparkInvoiceFields, validateSparkInvoiceSignature };