@buildonspark/spark-sdk 0.1.38 → 0.1.40

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 (104) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +1 -1
  3. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/arm64-v8a/libspark_frost.so +0 -0
  4. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/arm64-v8a/libuniffi_spark_frost.so +0 -0
  5. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/armeabi-v7a/libspark_frost.so +0 -0
  6. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/armeabi-v7a/libuniffi_spark_frost.so +0 -0
  7. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/x86/libspark_frost.so +0 -0
  8. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/x86/libuniffi_spark_frost.so +0 -0
  9. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/x86_64/libspark_frost.so +0 -0
  10. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/x86_64/libuniffi_spark_frost.so +0 -0
  11. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/arm64-v8a/libspark_frost.so +0 -0
  12. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/arm64-v8a/libuniffi_spark_frost.so +0 -0
  13. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/armeabi-v7a/libspark_frost.so +0 -0
  14. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/armeabi-v7a/libuniffi_spark_frost.so +0 -0
  15. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/x86/libspark_frost.so +0 -0
  16. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/x86/libuniffi_spark_frost.so +0 -0
  17. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/x86_64/libspark_frost.so +0 -0
  18. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/x86_64/libuniffi_spark_frost.so +0 -0
  19. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/arm64-v8a/libspark_frost.so +0 -0
  20. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/arm64-v8a/libuniffi_spark_frost.so +0 -0
  21. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/armeabi-v7a/libspark_frost.so +0 -0
  22. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/armeabi-v7a/libuniffi_spark_frost.so +0 -0
  23. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/x86/libspark_frost.so +0 -0
  24. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/x86/libuniffi_spark_frost.so +0 -0
  25. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/x86_64/libspark_frost.so +0 -0
  26. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/x86_64/libuniffi_spark_frost.so +0 -0
  27. package/dist/{RequestLightningSendInput-B4JdzclX.d.ts → RequestLightningSendInput-CJtcHOnu.d.ts} +1 -1
  28. package/dist/{RequestLightningSendInput-39_zGri6.d.cts → RequestLightningSendInput-DfmfqzZo.d.cts} +1 -1
  29. package/dist/address/index.d.cts +1 -1
  30. package/dist/address/index.d.ts +1 -1
  31. package/dist/address/index.js +2 -2
  32. package/dist/{chunk-W3EC5XSA.js → chunk-5MNQB2T4.js} +2 -2
  33. package/dist/chunk-ED3ZAFDI.js +784 -0
  34. package/dist/{chunk-VJTDG4BQ.js → chunk-HK6LPV6Z.js} +10 -1
  35. package/dist/{chunk-7WRK6WNJ.js → chunk-LHT4QTFK.js} +556 -41
  36. package/dist/{chunk-RAPBVYJY.js → chunk-RFCXPGDM.js} +26 -4
  37. package/dist/{chunk-DI7QXUQJ.js → chunk-W2VXS35Y.js} +4 -4
  38. package/dist/graphql/objects/index.d.cts +5 -4
  39. package/dist/graphql/objects/index.d.ts +5 -4
  40. package/dist/{index-CxAi2L8y.d.ts → index-BDEYgYxP.d.ts} +42 -4
  41. package/dist/{index-Dm17Ggfe.d.cts → index-CLdtdMU4.d.cts} +42 -4
  42. package/dist/index.cjs +1069 -40
  43. package/dist/index.d.cts +6 -6
  44. package/dist/index.d.ts +6 -6
  45. package/dist/index.js +33 -17
  46. package/dist/index.node.cjs +1069 -40
  47. package/dist/index.node.d.cts +6 -6
  48. package/dist/index.node.d.ts +6 -6
  49. package/dist/index.node.js +33 -17
  50. package/dist/native/index.cjs +1069 -40
  51. package/dist/native/index.d.cts +108 -5
  52. package/dist/native/index.d.ts +108 -5
  53. package/dist/native/index.js +1065 -40
  54. package/dist/{network-GFGEHkS4.d.cts → network-B10hBoHp.d.cts} +8 -1
  55. package/dist/{network-DobHpaV6.d.ts → network-CCgyIsGl.d.ts} +8 -1
  56. package/dist/services/config.cjs +29 -12
  57. package/dist/services/config.d.cts +4 -4
  58. package/dist/services/config.d.ts +4 -4
  59. package/dist/services/config.js +5 -5
  60. package/dist/services/connection.d.cts +4 -4
  61. package/dist/services/connection.d.ts +4 -4
  62. package/dist/services/connection.js +2 -2
  63. package/dist/services/index.cjs +30 -13
  64. package/dist/services/index.d.cts +4 -4
  65. package/dist/services/index.d.ts +4 -4
  66. package/dist/services/index.js +8 -8
  67. package/dist/services/lrc-connection.d.cts +4 -4
  68. package/dist/services/lrc-connection.d.ts +4 -4
  69. package/dist/services/lrc-connection.js +1 -1
  70. package/dist/services/token-transactions.cjs +1 -1
  71. package/dist/services/token-transactions.d.cts +4 -4
  72. package/dist/services/token-transactions.d.ts +4 -4
  73. package/dist/services/token-transactions.js +3 -3
  74. package/dist/services/wallet-config.d.cts +4 -4
  75. package/dist/services/wallet-config.d.ts +4 -4
  76. package/dist/signer/signer.cjs +23 -6
  77. package/dist/signer/signer.d.cts +3 -2
  78. package/dist/signer/signer.d.ts +3 -2
  79. package/dist/signer/signer.js +1 -1
  80. package/dist/{signer-DFGw9RRp.d.ts → signer-C5h1DpjF.d.ts} +4 -1
  81. package/dist/{signer-C1t40Wus.d.cts → signer-CYwn7h9U.d.cts} +4 -1
  82. package/dist/types/index.d.cts +4 -3
  83. package/dist/types/index.d.ts +4 -3
  84. package/dist/utils/index.cjs +891 -2
  85. package/dist/utils/index.d.cts +62 -6
  86. package/dist/utils/index.d.ts +62 -6
  87. package/dist/utils/index.js +23 -7
  88. package/package.json +1 -1
  89. package/src/services/deposit.ts +23 -5
  90. package/src/services/token-transactions.ts +1 -1
  91. package/src/services/transfer.ts +218 -11
  92. package/src/services/tree-creation.ts +29 -14
  93. package/src/signer/signer.ts +47 -5
  94. package/src/spark-wallet/spark-wallet.ts +430 -4
  95. package/src/tests/integration/swap.test.ts +225 -0
  96. package/src/tests/integration/tree-creation.test.ts +5 -1
  97. package/src/utils/index.ts +1 -0
  98. package/src/utils/mempool.ts +26 -1
  99. package/src/utils/network.ts +15 -0
  100. package/src/utils/transaction.ts +22 -2
  101. package/src/utils/unilateral-exit.ts +729 -0
  102. package/dist/chunk-E5SL7XTO.js +0 -301
  103. package/dist/{chunk-LIP2K6KR.js → chunk-2CDJZQN4.js} +3 -3
  104. package/dist/{chunk-RGWBSZIO.js → chunk-I4JI6TYN.js} +4 -4
@@ -1,12 +1,12 @@
1
1
  import { HDKey } from '@scure/bip32';
2
2
  import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
3
3
  import { CallOptions } from 'nice-grpc-common';
4
- import * as bitcoin from 'bitcoinjs-lib';
5
- import { Psbt } from 'bitcoinjs-lib';
6
4
  import { TokenSigner, Receipt, NetworkType as NetworkType$1, MayHaveLrc20WalletApiConfig, LRC20WalletApiConfig, HasLrc20WalletApiConfig, LRCWallet } from '@buildonspark/lrc20-sdk';
7
- import { Query } from '@lightsparkdev/core';
8
5
  import * as btc from '@scure/btc-signer';
9
6
  import { Transaction as Transaction$1 } from '@scure/btc-signer';
7
+ import * as bitcoin from 'bitcoinjs-lib';
8
+ import { Psbt } from 'bitcoinjs-lib';
9
+ import { Query } from '@lightsparkdev/core';
10
10
  import { Channel } from 'nice-grpc';
11
11
  import { Channel as Channel$1 } from 'nice-grpc-web';
12
12
  import { EventEmitter } from 'eventemitter3';
@@ -1512,6 +1512,7 @@ interface SparkSigner extends TokenSigner {
1512
1512
  signMessageWithPublicKey(message: Uint8Array, publicKey: Uint8Array, compact?: boolean): Promise<Uint8Array>;
1513
1513
  signMessageWithIdentityKey(message: Uint8Array, compact?: boolean): Promise<Uint8Array>;
1514
1514
  validateMessageWithIdentityKey(message: Uint8Array, signature: Uint8Array): Promise<boolean>;
1515
+ signTransactionIndex(tx: Transaction$1, index: number, publicKey: Uint8Array): void;
1515
1516
  encryptLeafPrivateKeyEcies(receiverPublicKey: Uint8Array, publicKey: Uint8Array): Promise<Uint8Array>;
1516
1517
  decryptEcies(ciphertext: Uint8Array): Promise<Uint8Array>;
1517
1518
  getRandomSigningCommitment(): Promise<SigningCommitment>;
@@ -1570,6 +1571,7 @@ declare class DefaultSparkSigner implements SparkSigner {
1570
1571
  validateMessageWithIdentityKey(message: Uint8Array, signature: Uint8Array): Promise<boolean>;
1571
1572
  signPsbt(psbt: Psbt, input: number, sighashTypes?: number[], receipt?: Receipt): Promise<Psbt>;
1572
1573
  private getReceiptPrivateKey;
1574
+ signTransactionIndex(tx: Transaction$1, index: number, publicKey: Uint8Array): void;
1573
1575
  }
1574
1576
 
1575
1577
  declare class ReactNativeSparkSigner extends DefaultSparkSigner {
@@ -2108,6 +2110,13 @@ declare const LRC_WALLET_NETWORK_TYPE: Readonly<{
2108
2110
  * @returns {BitcoinNetwork | null} The detected network or null if not detected
2109
2111
  */
2110
2112
  declare function getNetworkFromAddress(address: string): BitcoinNetwork.MAINNET | BitcoinNetwork.REGTEST | null;
2113
+ /**
2114
+ * Utility function to get the network enum value from a string.
2115
+ *
2116
+ * @param {string} network - The Bitcoin network to turn into an enum value
2117
+ * @returns {Network} The enum value matching the string
2118
+ */
2119
+ declare function getNetworkFromString(network?: string): Network;
2111
2120
 
2112
2121
  type SigningOperator = {
2113
2122
  readonly id: number;
@@ -2541,6 +2550,7 @@ declare class BaseTransferService {
2541
2550
  protected readonly signingService: SigningService;
2542
2551
  constructor(config: WalletConfigService, connectionManager: ConnectionManager, signingService: SigningService);
2543
2552
  sendTransferTweakKey(transfer: Transfer$1, leaves: LeafKeyTweak[], refundSignatureMap: Map<string, Uint8Array>): Promise<Transfer$1>;
2553
+ deliverTransferPackage(transfer: Transfer$1, leaves: LeafKeyTweak[], refundSignatureMap: Map<string, Uint8Array>): Promise<Transfer$1>;
2544
2554
  sendTransferWithKeyTweaks(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array): Promise<Transfer$1>;
2545
2555
  private prepareTransferPackage;
2546
2556
  private finalizeTransfer;
@@ -2594,6 +2604,7 @@ declare class TransferService extends BaseTransferService {
2594
2604
  queryPendingTransfersBySender(operatorAddress: string): Promise<QueryTransfersResponse>;
2595
2605
  refreshTimelockNodes(nodes: TreeNode[], parentNode: TreeNode, signingPubKey: Uint8Array): Promise<FinalizeNodeSignaturesResponse>;
2596
2606
  extendTimelock(node: TreeNode, signingPubKey: Uint8Array): Promise<FinalizeNodeSignaturesResponse>;
2607
+ refreshTimelockRefundTx(node: TreeNode, signingPubKey: Uint8Array): Promise<FinalizeNodeSignaturesResponse>;
2597
2608
  }
2598
2609
 
2599
2610
  declare const AddressNetwork: Record<NetworkType, string>;
@@ -2710,7 +2721,7 @@ declare class SparkWallet extends EventEmitter {
2710
2721
  private getSspClient;
2711
2722
  private handleStreamEvent;
2712
2723
  protected setupBackgroundStream(): Promise<void>;
2713
- private getLeaves;
2724
+ getLeaves(isBalanceCheck?: boolean): Promise<TreeNode[]>;
2714
2725
  private selectLeaves;
2715
2726
  private selectLeavesForSwap;
2716
2727
  private areLeavesInefficient;
@@ -3108,6 +3119,18 @@ declare class SparkWallet extends EventEmitter {
3108
3119
  * @returns {Promise<boolean>} Whether the message is valid
3109
3120
  */
3110
3121
  validateMessageWithIdentityKey(message: string, signature: string | Uint8Array): Promise<boolean>;
3122
+ /**
3123
+ * Signs a transaction with wallet keys.
3124
+ *
3125
+ * @param {string} txHex - The transaction hex to sign
3126
+ * @param {string} keyType - The type of key to use for signing ("identity", "deposit", or "auto-detect")
3127
+ * @returns {Promise<string>} The signed transaction hex
3128
+ */
3129
+ signTransaction(txHex: string, keyType?: string): Promise<string>;
3130
+ /**
3131
+ * Helper method to auto-detect which key should be used for signing a transaction.
3132
+ */
3133
+ private detectKeyForTransaction;
3111
3134
  /**
3112
3135
  * Get a Lightning receive request by ID.
3113
3136
  *
@@ -3129,6 +3152,30 @@ declare class SparkWallet extends EventEmitter {
3129
3152
  * @returns {Promise<CoopExitRequest | null>} The coop exit request
3130
3153
  */
3131
3154
  getCoopExitRequest(id: string): Promise<CoopExitRequest | null>;
3155
+ /**
3156
+ * Check the remaining timelock on a given node.
3157
+ *
3158
+ * @param {string} nodeId - The ID of the node to check
3159
+ * @returns {Promise<{nodeTimelock: number, refundTimelock: number}>} The remaining timelocks in blocks for both node and refund transactions
3160
+ */
3161
+ checkTimelock(nodeId: string): Promise<{
3162
+ nodeTimelock: number;
3163
+ refundTimelock: number;
3164
+ }>;
3165
+ /**
3166
+ * Refresh the timelock of a specific node.
3167
+ *
3168
+ * @param {string} nodeId - The ID of the node to refresh
3169
+ * @returns {Promise<void>} Promise that resolves when the timelock is refreshed
3170
+ */
3171
+ testOnly_expireTimelock(nodeId: string): Promise<void>;
3172
+ /**
3173
+ * Refresh the timelock of a specific node's refund transaction only.
3174
+ *
3175
+ * @param {string} nodeId - The ID of the node whose refund transaction to refresh
3176
+ * @returns {Promise<void>} Promise that resolves when the refund timelock is refreshed
3177
+ */
3178
+ testOnly_expireTimelockRefundTx(nodeId: string): Promise<void>;
3132
3179
  private cleanup;
3133
3180
  cleanupConnections(): Promise<void>;
3134
3181
  private startPeriodicClaimTransfers;
@@ -3137,6 +3184,7 @@ declare class SparkWallet extends EventEmitter {
3137
3184
  }
3138
3185
 
3139
3186
  declare function getLatestDepositTxId(address: string): Promise<string | null>;
3187
+ declare function isTxBroadcast(txid: string, baseUrl: string, network?: any): Promise<boolean>;
3140
3188
 
3141
3189
  declare function generateSignatureFromExistingAdaptor(signature: Uint8Array, adaptorPrivateKeyBytes: Uint8Array): Uint8Array;
3142
3190
  declare function generateAdaptorFromSignature(signature: Uint8Array): {
@@ -3188,6 +3236,12 @@ declare function filterTokenBalanceForTokenPublicKey(tokenBalances: Map<string,
3188
3236
 
3189
3237
  declare function getTransferPackageSigningPayload(transferID: string, transferPackage: TransferPackage): Uint8Array;
3190
3238
 
3239
+ declare const DEFAULT_FEE_SATS: number;
3240
+ /**
3241
+ * Subtracts the default fee from the amount if it's greater than the fee.
3242
+ * Returns the original amount if it's less than or equal to the fee.
3243
+ */
3244
+ declare function maybeApplyFee(amount: bigint): bigint;
3191
3245
  declare function createRefundTx(sequence: number, nodeOutPoint: TransactionInput, amountSats: bigint, receivingPubkey: Uint8Array, network: Network): Transaction$1;
3192
3246
  declare function getCurrentTimelock(currSequence?: number): number;
3193
3247
  declare function getTransactionSequence(currSequence?: number): number;
@@ -3197,4 +3251,53 @@ declare function getNextTransactionSequence(currSequence?: number, forRefresh?:
3197
3251
  };
3198
3252
  declare function getEphemeralAnchorOutput(): TransactionOutput;
3199
3253
 
3200
- export { AuthenticationError, ConfigurationError, ReactNativeSparkSigner as DefaultSparkSigner, InternalValidationError, LRC_WALLET_NETWORK, LRC_WALLET_NETWORK_TYPE, Network, NetworkError, NetworkToProto, type NetworkType, NotImplementedError, RPCError, ReactNativeSparkSigner, SparkSDKError, SparkWallet, ValidationError, type VerifiableSecretShare, addPrivateKeys, addPublicKeys, applyAdaptorToSignature, applyAdditiveTweakToPublicKey, bigIntToPrivateKey, calculateAvailableTokenAmount, checkIfSelectedOutputsAreAvailable, collectResponses, computeTaprootKeyNoScript, computerLagrangeCoefficients, createRefundTx, createSigningCommitment, createSigningNonce, decodeBytesToSigningCommitment, decodeBytesToSigningNonce, encodeSigningCommitmentToBytes, encodeSigningNonceToBytes, evaluatePolynomial, fieldDiv, filterTokenBalanceForTokenPublicKey, generateAdaptorFromSignature, generatePolynomialForSecretSharing, generateSignatureFromExistingAdaptor, getCurrentTimelock, getEphemeralAnchorOutput, getLatestDepositTxId, getNetwork, getNetworkFromAddress, getNextTransactionSequence, getP2TRAddressFromPkScript, getP2TRAddressFromPublicKey, getP2TRScriptFromPublicKey, getP2WPKHAddressFromPublicKey, getRandomBigInt, getRandomSigningNonce, getSigHashFromTx, getSigningCommitmentFromNonce, getTransactionSequence, getTransferPackageSigningPayload, getTxFromRawTxBytes, getTxFromRawTxHex, getTxId, getTxIdNoReverse, lastKeyWithTarget, modInverse, proofOfPossessionMessageHashForDepositAddress, recoverSecret, splitSecret, splitSecretWithProofs, subtractPrivateKeys, subtractPublicKeys, sumOfPrivateKeys, validateOutboundAdaptorSignature, validateShare };
3254
+ interface LeafInfo {
3255
+ leafId: string;
3256
+ nodeTx: string;
3257
+ refundTx: string;
3258
+ }
3259
+ interface Utxo {
3260
+ txid: string;
3261
+ vout: number;
3262
+ value: bigint;
3263
+ script: string;
3264
+ publicKey: string;
3265
+ }
3266
+ interface FeeRate {
3267
+ satPerVbyte: number;
3268
+ }
3269
+ interface FeeBumpTxPackage {
3270
+ tx: string;
3271
+ feeBumpPsbt?: string;
3272
+ }
3273
+ interface FeeBumpTxChain {
3274
+ leafId: string;
3275
+ txPackages: FeeBumpTxPackage[];
3276
+ }
3277
+ interface TxChain {
3278
+ leafId: string;
3279
+ transactions: string[];
3280
+ }
3281
+ interface BroadcastConfig {
3282
+ bitcoinCoreRpcUrl?: string;
3283
+ rpcUsername?: string;
3284
+ rpcPassword?: string;
3285
+ autoBroadcast?: boolean;
3286
+ network?: "MAINNET" | "REGTEST" | "TESTNET" | "SIGNET" | "LOCAL";
3287
+ }
3288
+ interface BroadcastResult {
3289
+ success: boolean;
3290
+ txids?: string[];
3291
+ error?: string;
3292
+ broadcastedPackages?: number;
3293
+ }
3294
+ declare function isEphemeralAnchorOutput(script?: Uint8Array, amount?: bigint): boolean;
3295
+ declare function constructUnilateralExitTxs(nodeHexStrings: string[], sparkClient?: SparkServiceClient$1, network?: any): Promise<TxChain[]>;
3296
+ declare function constructUnilateralExitFeeBumpPackages(nodeHexStrings: string[], utxos: Utxo[], feeRate: FeeRate, electrsUrl: string, sparkClient?: SparkServiceClient$1, network?: any): Promise<FeeBumpTxChain[]>;
3297
+ declare function constructFeeBumpTx(txHex: string, utxos: Utxo[], feeRate: FeeRate, previousFeeBumpTx?: string): {
3298
+ feeBumpPsbt: string;
3299
+ usedUtxos: Utxo[];
3300
+ correctedParentTx?: string;
3301
+ };
3302
+
3303
+ export { AuthenticationError, type BroadcastConfig, type BroadcastResult, ConfigurationError, DEFAULT_FEE_SATS, ReactNativeSparkSigner as DefaultSparkSigner, type FeeBumpTxChain, type FeeBumpTxPackage, type FeeRate, InternalValidationError, LRC_WALLET_NETWORK, LRC_WALLET_NETWORK_TYPE, type LeafInfo, Network, NetworkError, NetworkToProto, type NetworkType, NotImplementedError, RPCError, ReactNativeSparkSigner, SparkSDKError, SparkWallet, type TxChain, type Utxo, ValidationError, type VerifiableSecretShare, addPrivateKeys, addPublicKeys, applyAdaptorToSignature, applyAdditiveTweakToPublicKey, bigIntToPrivateKey, calculateAvailableTokenAmount, checkIfSelectedOutputsAreAvailable, collectResponses, computeTaprootKeyNoScript, computerLagrangeCoefficients, constructFeeBumpTx, constructUnilateralExitFeeBumpPackages, constructUnilateralExitTxs, createRefundTx, createSigningCommitment, createSigningNonce, decodeBytesToSigningCommitment, decodeBytesToSigningNonce, encodeSigningCommitmentToBytes, encodeSigningNonceToBytes, evaluatePolynomial, fieldDiv, filterTokenBalanceForTokenPublicKey, generateAdaptorFromSignature, generatePolynomialForSecretSharing, generateSignatureFromExistingAdaptor, getCurrentTimelock, getEphemeralAnchorOutput, getLatestDepositTxId, getNetwork, getNetworkFromAddress, getNetworkFromString, getNextTransactionSequence, getP2TRAddressFromPkScript, getP2TRAddressFromPublicKey, getP2TRScriptFromPublicKey, getP2WPKHAddressFromPublicKey, getRandomBigInt, getRandomSigningNonce, getSigHashFromTx, getSigningCommitmentFromNonce, getTransactionSequence, getTransferPackageSigningPayload, getTxFromRawTxBytes, getTxFromRawTxHex, getTxId, getTxIdNoReverse, isEphemeralAnchorOutput, isTxBroadcast, lastKeyWithTarget, maybeApplyFee, modInverse, proofOfPossessionMessageHashForDepositAddress, recoverSecret, splitSecret, splitSecretWithProofs, subtractPrivateKeys, subtractPublicKeys, sumOfPrivateKeys, validateOutboundAdaptorSignature, validateShare };
@@ -1,12 +1,12 @@
1
1
  import { HDKey } from '@scure/bip32';
2
2
  import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
3
3
  import { CallOptions } from 'nice-grpc-common';
4
- import * as bitcoin from 'bitcoinjs-lib';
5
- import { Psbt } from 'bitcoinjs-lib';
6
4
  import { TokenSigner, Receipt, NetworkType as NetworkType$1, MayHaveLrc20WalletApiConfig, LRC20WalletApiConfig, HasLrc20WalletApiConfig, LRCWallet } from '@buildonspark/lrc20-sdk';
7
- import { Query } from '@lightsparkdev/core';
8
5
  import * as btc from '@scure/btc-signer';
9
6
  import { Transaction as Transaction$1 } from '@scure/btc-signer';
7
+ import * as bitcoin from 'bitcoinjs-lib';
8
+ import { Psbt } from 'bitcoinjs-lib';
9
+ import { Query } from '@lightsparkdev/core';
10
10
  import { Channel } from 'nice-grpc';
11
11
  import { Channel as Channel$1 } from 'nice-grpc-web';
12
12
  import { EventEmitter } from 'eventemitter3';
@@ -1512,6 +1512,7 @@ interface SparkSigner extends TokenSigner {
1512
1512
  signMessageWithPublicKey(message: Uint8Array, publicKey: Uint8Array, compact?: boolean): Promise<Uint8Array>;
1513
1513
  signMessageWithIdentityKey(message: Uint8Array, compact?: boolean): Promise<Uint8Array>;
1514
1514
  validateMessageWithIdentityKey(message: Uint8Array, signature: Uint8Array): Promise<boolean>;
1515
+ signTransactionIndex(tx: Transaction$1, index: number, publicKey: Uint8Array): void;
1515
1516
  encryptLeafPrivateKeyEcies(receiverPublicKey: Uint8Array, publicKey: Uint8Array): Promise<Uint8Array>;
1516
1517
  decryptEcies(ciphertext: Uint8Array): Promise<Uint8Array>;
1517
1518
  getRandomSigningCommitment(): Promise<SigningCommitment>;
@@ -1570,6 +1571,7 @@ declare class DefaultSparkSigner implements SparkSigner {
1570
1571
  validateMessageWithIdentityKey(message: Uint8Array, signature: Uint8Array): Promise<boolean>;
1571
1572
  signPsbt(psbt: Psbt, input: number, sighashTypes?: number[], receipt?: Receipt): Promise<Psbt>;
1572
1573
  private getReceiptPrivateKey;
1574
+ signTransactionIndex(tx: Transaction$1, index: number, publicKey: Uint8Array): void;
1573
1575
  }
1574
1576
 
1575
1577
  declare class ReactNativeSparkSigner extends DefaultSparkSigner {
@@ -2108,6 +2110,13 @@ declare const LRC_WALLET_NETWORK_TYPE: Readonly<{
2108
2110
  * @returns {BitcoinNetwork | null} The detected network or null if not detected
2109
2111
  */
2110
2112
  declare function getNetworkFromAddress(address: string): BitcoinNetwork.MAINNET | BitcoinNetwork.REGTEST | null;
2113
+ /**
2114
+ * Utility function to get the network enum value from a string.
2115
+ *
2116
+ * @param {string} network - The Bitcoin network to turn into an enum value
2117
+ * @returns {Network} The enum value matching the string
2118
+ */
2119
+ declare function getNetworkFromString(network?: string): Network;
2111
2120
 
2112
2121
  type SigningOperator = {
2113
2122
  readonly id: number;
@@ -2541,6 +2550,7 @@ declare class BaseTransferService {
2541
2550
  protected readonly signingService: SigningService;
2542
2551
  constructor(config: WalletConfigService, connectionManager: ConnectionManager, signingService: SigningService);
2543
2552
  sendTransferTweakKey(transfer: Transfer$1, leaves: LeafKeyTweak[], refundSignatureMap: Map<string, Uint8Array>): Promise<Transfer$1>;
2553
+ deliverTransferPackage(transfer: Transfer$1, leaves: LeafKeyTweak[], refundSignatureMap: Map<string, Uint8Array>): Promise<Transfer$1>;
2544
2554
  sendTransferWithKeyTweaks(leaves: LeafKeyTweak[], receiverIdentityPubkey: Uint8Array): Promise<Transfer$1>;
2545
2555
  private prepareTransferPackage;
2546
2556
  private finalizeTransfer;
@@ -2594,6 +2604,7 @@ declare class TransferService extends BaseTransferService {
2594
2604
  queryPendingTransfersBySender(operatorAddress: string): Promise<QueryTransfersResponse>;
2595
2605
  refreshTimelockNodes(nodes: TreeNode[], parentNode: TreeNode, signingPubKey: Uint8Array): Promise<FinalizeNodeSignaturesResponse>;
2596
2606
  extendTimelock(node: TreeNode, signingPubKey: Uint8Array): Promise<FinalizeNodeSignaturesResponse>;
2607
+ refreshTimelockRefundTx(node: TreeNode, signingPubKey: Uint8Array): Promise<FinalizeNodeSignaturesResponse>;
2597
2608
  }
2598
2609
 
2599
2610
  declare const AddressNetwork: Record<NetworkType, string>;
@@ -2710,7 +2721,7 @@ declare class SparkWallet extends EventEmitter {
2710
2721
  private getSspClient;
2711
2722
  private handleStreamEvent;
2712
2723
  protected setupBackgroundStream(): Promise<void>;
2713
- private getLeaves;
2724
+ getLeaves(isBalanceCheck?: boolean): Promise<TreeNode[]>;
2714
2725
  private selectLeaves;
2715
2726
  private selectLeavesForSwap;
2716
2727
  private areLeavesInefficient;
@@ -3108,6 +3119,18 @@ declare class SparkWallet extends EventEmitter {
3108
3119
  * @returns {Promise<boolean>} Whether the message is valid
3109
3120
  */
3110
3121
  validateMessageWithIdentityKey(message: string, signature: string | Uint8Array): Promise<boolean>;
3122
+ /**
3123
+ * Signs a transaction with wallet keys.
3124
+ *
3125
+ * @param {string} txHex - The transaction hex to sign
3126
+ * @param {string} keyType - The type of key to use for signing ("identity", "deposit", or "auto-detect")
3127
+ * @returns {Promise<string>} The signed transaction hex
3128
+ */
3129
+ signTransaction(txHex: string, keyType?: string): Promise<string>;
3130
+ /**
3131
+ * Helper method to auto-detect which key should be used for signing a transaction.
3132
+ */
3133
+ private detectKeyForTransaction;
3111
3134
  /**
3112
3135
  * Get a Lightning receive request by ID.
3113
3136
  *
@@ -3129,6 +3152,30 @@ declare class SparkWallet extends EventEmitter {
3129
3152
  * @returns {Promise<CoopExitRequest | null>} The coop exit request
3130
3153
  */
3131
3154
  getCoopExitRequest(id: string): Promise<CoopExitRequest | null>;
3155
+ /**
3156
+ * Check the remaining timelock on a given node.
3157
+ *
3158
+ * @param {string} nodeId - The ID of the node to check
3159
+ * @returns {Promise<{nodeTimelock: number, refundTimelock: number}>} The remaining timelocks in blocks for both node and refund transactions
3160
+ */
3161
+ checkTimelock(nodeId: string): Promise<{
3162
+ nodeTimelock: number;
3163
+ refundTimelock: number;
3164
+ }>;
3165
+ /**
3166
+ * Refresh the timelock of a specific node.
3167
+ *
3168
+ * @param {string} nodeId - The ID of the node to refresh
3169
+ * @returns {Promise<void>} Promise that resolves when the timelock is refreshed
3170
+ */
3171
+ testOnly_expireTimelock(nodeId: string): Promise<void>;
3172
+ /**
3173
+ * Refresh the timelock of a specific node's refund transaction only.
3174
+ *
3175
+ * @param {string} nodeId - The ID of the node whose refund transaction to refresh
3176
+ * @returns {Promise<void>} Promise that resolves when the refund timelock is refreshed
3177
+ */
3178
+ testOnly_expireTimelockRefundTx(nodeId: string): Promise<void>;
3132
3179
  private cleanup;
3133
3180
  cleanupConnections(): Promise<void>;
3134
3181
  private startPeriodicClaimTransfers;
@@ -3137,6 +3184,7 @@ declare class SparkWallet extends EventEmitter {
3137
3184
  }
3138
3185
 
3139
3186
  declare function getLatestDepositTxId(address: string): Promise<string | null>;
3187
+ declare function isTxBroadcast(txid: string, baseUrl: string, network?: any): Promise<boolean>;
3140
3188
 
3141
3189
  declare function generateSignatureFromExistingAdaptor(signature: Uint8Array, adaptorPrivateKeyBytes: Uint8Array): Uint8Array;
3142
3190
  declare function generateAdaptorFromSignature(signature: Uint8Array): {
@@ -3188,6 +3236,12 @@ declare function filterTokenBalanceForTokenPublicKey(tokenBalances: Map<string,
3188
3236
 
3189
3237
  declare function getTransferPackageSigningPayload(transferID: string, transferPackage: TransferPackage): Uint8Array;
3190
3238
 
3239
+ declare const DEFAULT_FEE_SATS: number;
3240
+ /**
3241
+ * Subtracts the default fee from the amount if it's greater than the fee.
3242
+ * Returns the original amount if it's less than or equal to the fee.
3243
+ */
3244
+ declare function maybeApplyFee(amount: bigint): bigint;
3191
3245
  declare function createRefundTx(sequence: number, nodeOutPoint: TransactionInput, amountSats: bigint, receivingPubkey: Uint8Array, network: Network): Transaction$1;
3192
3246
  declare function getCurrentTimelock(currSequence?: number): number;
3193
3247
  declare function getTransactionSequence(currSequence?: number): number;
@@ -3197,4 +3251,53 @@ declare function getNextTransactionSequence(currSequence?: number, forRefresh?:
3197
3251
  };
3198
3252
  declare function getEphemeralAnchorOutput(): TransactionOutput;
3199
3253
 
3200
- export { AuthenticationError, ConfigurationError, ReactNativeSparkSigner as DefaultSparkSigner, InternalValidationError, LRC_WALLET_NETWORK, LRC_WALLET_NETWORK_TYPE, Network, NetworkError, NetworkToProto, type NetworkType, NotImplementedError, RPCError, ReactNativeSparkSigner, SparkSDKError, SparkWallet, ValidationError, type VerifiableSecretShare, addPrivateKeys, addPublicKeys, applyAdaptorToSignature, applyAdditiveTweakToPublicKey, bigIntToPrivateKey, calculateAvailableTokenAmount, checkIfSelectedOutputsAreAvailable, collectResponses, computeTaprootKeyNoScript, computerLagrangeCoefficients, createRefundTx, createSigningCommitment, createSigningNonce, decodeBytesToSigningCommitment, decodeBytesToSigningNonce, encodeSigningCommitmentToBytes, encodeSigningNonceToBytes, evaluatePolynomial, fieldDiv, filterTokenBalanceForTokenPublicKey, generateAdaptorFromSignature, generatePolynomialForSecretSharing, generateSignatureFromExistingAdaptor, getCurrentTimelock, getEphemeralAnchorOutput, getLatestDepositTxId, getNetwork, getNetworkFromAddress, getNextTransactionSequence, getP2TRAddressFromPkScript, getP2TRAddressFromPublicKey, getP2TRScriptFromPublicKey, getP2WPKHAddressFromPublicKey, getRandomBigInt, getRandomSigningNonce, getSigHashFromTx, getSigningCommitmentFromNonce, getTransactionSequence, getTransferPackageSigningPayload, getTxFromRawTxBytes, getTxFromRawTxHex, getTxId, getTxIdNoReverse, lastKeyWithTarget, modInverse, proofOfPossessionMessageHashForDepositAddress, recoverSecret, splitSecret, splitSecretWithProofs, subtractPrivateKeys, subtractPublicKeys, sumOfPrivateKeys, validateOutboundAdaptorSignature, validateShare };
3254
+ interface LeafInfo {
3255
+ leafId: string;
3256
+ nodeTx: string;
3257
+ refundTx: string;
3258
+ }
3259
+ interface Utxo {
3260
+ txid: string;
3261
+ vout: number;
3262
+ value: bigint;
3263
+ script: string;
3264
+ publicKey: string;
3265
+ }
3266
+ interface FeeRate {
3267
+ satPerVbyte: number;
3268
+ }
3269
+ interface FeeBumpTxPackage {
3270
+ tx: string;
3271
+ feeBumpPsbt?: string;
3272
+ }
3273
+ interface FeeBumpTxChain {
3274
+ leafId: string;
3275
+ txPackages: FeeBumpTxPackage[];
3276
+ }
3277
+ interface TxChain {
3278
+ leafId: string;
3279
+ transactions: string[];
3280
+ }
3281
+ interface BroadcastConfig {
3282
+ bitcoinCoreRpcUrl?: string;
3283
+ rpcUsername?: string;
3284
+ rpcPassword?: string;
3285
+ autoBroadcast?: boolean;
3286
+ network?: "MAINNET" | "REGTEST" | "TESTNET" | "SIGNET" | "LOCAL";
3287
+ }
3288
+ interface BroadcastResult {
3289
+ success: boolean;
3290
+ txids?: string[];
3291
+ error?: string;
3292
+ broadcastedPackages?: number;
3293
+ }
3294
+ declare function isEphemeralAnchorOutput(script?: Uint8Array, amount?: bigint): boolean;
3295
+ declare function constructUnilateralExitTxs(nodeHexStrings: string[], sparkClient?: SparkServiceClient$1, network?: any): Promise<TxChain[]>;
3296
+ declare function constructUnilateralExitFeeBumpPackages(nodeHexStrings: string[], utxos: Utxo[], feeRate: FeeRate, electrsUrl: string, sparkClient?: SparkServiceClient$1, network?: any): Promise<FeeBumpTxChain[]>;
3297
+ declare function constructFeeBumpTx(txHex: string, utxos: Utxo[], feeRate: FeeRate, previousFeeBumpTx?: string): {
3298
+ feeBumpPsbt: string;
3299
+ usedUtxos: Utxo[];
3300
+ correctedParentTx?: string;
3301
+ };
3302
+
3303
+ export { AuthenticationError, type BroadcastConfig, type BroadcastResult, ConfigurationError, DEFAULT_FEE_SATS, ReactNativeSparkSigner as DefaultSparkSigner, type FeeBumpTxChain, type FeeBumpTxPackage, type FeeRate, InternalValidationError, LRC_WALLET_NETWORK, LRC_WALLET_NETWORK_TYPE, type LeafInfo, Network, NetworkError, NetworkToProto, type NetworkType, NotImplementedError, RPCError, ReactNativeSparkSigner, SparkSDKError, SparkWallet, type TxChain, type Utxo, ValidationError, type VerifiableSecretShare, addPrivateKeys, addPublicKeys, applyAdaptorToSignature, applyAdditiveTweakToPublicKey, bigIntToPrivateKey, calculateAvailableTokenAmount, checkIfSelectedOutputsAreAvailable, collectResponses, computeTaprootKeyNoScript, computerLagrangeCoefficients, constructFeeBumpTx, constructUnilateralExitFeeBumpPackages, constructUnilateralExitTxs, createRefundTx, createSigningCommitment, createSigningNonce, decodeBytesToSigningCommitment, decodeBytesToSigningNonce, encodeSigningCommitmentToBytes, encodeSigningNonceToBytes, evaluatePolynomial, fieldDiv, filterTokenBalanceForTokenPublicKey, generateAdaptorFromSignature, generatePolynomialForSecretSharing, generateSignatureFromExistingAdaptor, getCurrentTimelock, getEphemeralAnchorOutput, getLatestDepositTxId, getNetwork, getNetworkFromAddress, getNetworkFromString, getNextTransactionSequence, getP2TRAddressFromPkScript, getP2TRAddressFromPublicKey, getP2TRScriptFromPublicKey, getP2WPKHAddressFromPublicKey, getRandomBigInt, getRandomSigningNonce, getSigHashFromTx, getSigningCommitmentFromNonce, getTransactionSequence, getTransferPackageSigningPayload, getTxFromRawTxBytes, getTxFromRawTxHex, getTxId, getTxIdNoReverse, isEphemeralAnchorOutput, isTxBroadcast, lastKeyWithTarget, maybeApplyFee, modInverse, proofOfPossessionMessageHashForDepositAddress, recoverSecret, splitSecret, splitSecretWithProofs, subtractPrivateKeys, subtractPublicKeys, sumOfPrivateKeys, validateOutboundAdaptorSignature, validateShare };