@buildonspark/spark-sdk 0.2.11 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/bare/index.cjs +703 -206
  3. package/dist/bare/index.d.cts +47 -3
  4. package/dist/bare/index.d.ts +47 -3
  5. package/dist/bare/index.js +626 -133
  6. package/dist/{chunk-A5M55UR3.js → chunk-5VWGOHED.js} +499 -8
  7. package/dist/{chunk-3WBPICWC.js → chunk-NQMQVXR5.js} +1 -1
  8. package/dist/{chunk-QNYJGFPD.js → chunk-OEK3R57K.js} +149 -123
  9. package/dist/{chunk-76SYPHOC.js → chunk-TB7DG5CU.js} +2 -2
  10. package/dist/{chunk-6CMNEDBK.js → chunk-XXTWWW6L.js} +1 -1
  11. package/dist/{client-Dd3QnxQu.d.ts → client-D7KDa4Ih.d.ts} +1 -1
  12. package/dist/{client-B9CAWKWz.d.cts → client-DVuA5-7M.d.cts} +1 -1
  13. package/dist/debug.cjs +703 -206
  14. package/dist/debug.d.cts +4 -4
  15. package/dist/debug.d.ts +4 -4
  16. package/dist/debug.js +4 -4
  17. package/dist/graphql/objects/index.d.cts +3 -3
  18. package/dist/graphql/objects/index.d.ts +3 -3
  19. package/dist/index.cjs +725 -228
  20. package/dist/index.d.cts +6 -6
  21. package/dist/index.d.ts +6 -6
  22. package/dist/index.js +5 -5
  23. package/dist/index.node.cjs +725 -228
  24. package/dist/index.node.d.cts +6 -6
  25. package/dist/index.node.d.ts +6 -6
  26. package/dist/index.node.js +4 -4
  27. package/dist/{logging-Bt_WdZbu.d.ts → logging-ClNhGzus.d.ts} +3 -3
  28. package/dist/{logging-BOAzMqpM.d.cts → logging-D3kvES69.d.cts} +3 -3
  29. package/dist/native/index.cjs +724 -227
  30. package/dist/native/index.d.cts +47 -3
  31. package/dist/native/index.d.ts +47 -3
  32. package/dist/native/index.js +628 -135
  33. package/dist/proto/spark.cjs +499 -8
  34. package/dist/proto/spark.d.cts +1 -1
  35. package/dist/proto/spark.d.ts +1 -1
  36. package/dist/proto/spark.js +17 -1
  37. package/dist/proto/spark_token.d.cts +1 -1
  38. package/dist/proto/spark_token.d.ts +1 -1
  39. package/dist/proto/spark_token.js +2 -2
  40. package/dist/{spark-CtGJPkx4.d.cts → spark-C7OG9mGJ.d.cts} +79 -2
  41. package/dist/{spark-CtGJPkx4.d.ts → spark-C7OG9mGJ.d.ts} +79 -2
  42. package/dist/{spark-wallet-yc2KhsVY.d.cts → spark-wallet-Dg5IRQe2.d.cts} +3 -5
  43. package/dist/{spark-wallet-Cp3yv6cK.d.ts → spark-wallet-DiHSU-pz.d.ts} +3 -5
  44. package/dist/{spark-wallet.node-D4IovOHu.d.ts → spark-wallet.node-BZrxwomN.d.ts} +1 -1
  45. package/dist/{spark-wallet.node-D0Qw5Wb4.d.cts → spark-wallet.node-DSWb18zh.d.cts} +1 -1
  46. package/dist/tests/test-utils.cjs +573 -66
  47. package/dist/tests/test-utils.d.cts +4 -4
  48. package/dist/tests/test-utils.d.ts +4 -4
  49. package/dist/tests/test-utils.js +5 -5
  50. package/dist/{token-transactions-CwhlOgIP.d.cts → token-transactions-B-WqFYpW.d.cts} +2 -2
  51. package/dist/{token-transactions-0nmR9mQO.d.ts → token-transactions-DovxHIxV.d.ts} +2 -2
  52. package/dist/types/index.cjs +492 -9
  53. package/dist/types/index.d.cts +2 -2
  54. package/dist/types/index.d.ts +2 -2
  55. package/dist/types/index.js +2 -2
  56. package/package.json +1 -1
  57. package/src/proto/common.ts +1 -1
  58. package/src/proto/google/protobuf/descriptor.ts +4 -10
  59. package/src/proto/google/protobuf/duration.ts +1 -1
  60. package/src/proto/google/protobuf/empty.ts +1 -1
  61. package/src/proto/google/protobuf/timestamp.ts +1 -1
  62. package/src/proto/mock.ts +1 -1
  63. package/src/proto/spark.ts +593 -3
  64. package/src/proto/spark_authn.ts +1 -1
  65. package/src/proto/spark_token.ts +1 -1
  66. package/src/proto/validate/validate.ts +27 -79
  67. package/src/services/deposit.ts +55 -3
  68. package/src/services/lightning.ts +2 -2
  69. package/src/services/signing.ts +1 -1
  70. package/src/services/token-transactions.ts +2 -5
  71. package/src/services/transfer.ts +2 -2
  72. package/src/signer/signer.ts +2 -2
  73. package/src/spark-wallet/spark-wallet.ts +25 -33
  74. package/src/tests/address.test.ts +10 -10
  75. package/src/tests/bitcoin.test.ts +2 -2
  76. package/src/tests/integration/coop-exit.test.ts +1 -1
  77. package/src/tests/integration/lightning.test.ts +1 -1
  78. package/src/tests/integration/ssp/static_deposit.test.ts +122 -1
  79. package/src/tests/integration/swap.test.ts +1 -1
  80. package/src/tests/integration/transfer.test.ts +1 -5
  81. package/src/tests/integration/wallet.test.ts +7 -7
  82. package/src/tests/integration/watchtower.test.ts +1 -1
  83. package/src/tests/token-hashing.test.ts +3 -6
  84. package/src/tests/token-outputs.test.ts +3 -3
  85. package/src/tests/utils/test-faucet.ts +2 -2
  86. package/src/types/sdk-types.ts +1 -1
  87. package/src/utils/adaptor-signature.ts +1 -1
  88. package/src/utils/address.ts +1 -1
  89. package/src/utils/bitcoin.ts +1 -5
  90. package/src/utils/keys.ts +1 -1
  91. package/src/utils/secret-sharing.ts +1 -1
  92. package/src/utils/token-transactions.ts +1 -2
  93. package/src/utils/transfer_package.ts +1 -1
  94. package/src/utils/unilateral-exit.ts +1 -1
@@ -5,7 +5,6 @@ import {
5
5
  import { bytesToHex } from "@noble/hashes/utils";
6
6
  import { BitcoinFaucet } from "../../utils/test-faucet.js";
7
7
 
8
- const SMALL_DEPOSIT_AMOUNT = 10n;
9
8
  export const DEPOSIT_AMOUNT = 10000n;
10
9
  const SECOND_DEPOSIT_AMOUNT = 20000n;
11
10
  const THIRD_DEPOSIT_AMOUNT = 30000n;
@@ -168,6 +167,128 @@ describe("SSP static deposit address integration", () => {
168
167
 
169
168
  expect(refundTx).not.toBe(refundTx2);
170
169
  }, 60000);
170
+
171
+ it("should return the right amount of txns when querying for utxos sent to a static deposit address", async () => {
172
+ const faucet = BitcoinFaucet.getInstance();
173
+ const { wallet: userWallet } = await SparkWalletTesting.initialize(
174
+ {
175
+ options: {
176
+ network: "LOCAL",
177
+ },
178
+ },
179
+ false,
180
+ );
181
+
182
+ const depositAddress = await userWallet.getStaticDepositAddress();
183
+ expect(depositAddress).toBeDefined();
184
+ const signedTx = await faucet.sendToAddress(
185
+ depositAddress,
186
+ DEPOSIT_AMOUNT,
187
+ );
188
+
189
+ // Wait for the transaction to be mined
190
+ await faucet.mineBlocks(6);
191
+ expect(signedTx).toBeDefined();
192
+ const transactionId = signedTx.id;
193
+ let vout;
194
+ for (let i = 0; i < signedTx.outputsLength; i++) {
195
+ const output = signedTx.getOutput(i);
196
+ if (output.amount === DEPOSIT_AMOUNT) {
197
+ vout = i;
198
+ break;
199
+ }
200
+ }
201
+
202
+ const quote = await userWallet.getClaimStaticDepositQuote(
203
+ transactionId,
204
+ vout!,
205
+ );
206
+
207
+ await new Promise((resolve) => setTimeout(resolve, 1000));
208
+
209
+ const quoteAmount = quote!.creditAmountSats;
210
+ const sspSignature = quote!.signature;
211
+
212
+ await userWallet.claimStaticDeposit({
213
+ transactionId,
214
+ creditAmountSats: quoteAmount,
215
+ sspSignature,
216
+ outputIndex: vout!,
217
+ });
218
+ await new Promise((resolve) => setTimeout(resolve, 1000));
219
+ const { balance } = await userWallet.getBalance();
220
+ expect(balance).toBe(BigInt(quoteAmount));
221
+
222
+ // Test depositing money to the same address and second time and claiming.
223
+ const signedTx2 = await faucet.sendToAddress(
224
+ depositAddress,
225
+ SECOND_DEPOSIT_AMOUNT,
226
+ );
227
+ const transactionId2 = signedTx2.id;
228
+ // Wait for the transaction to be mined
229
+ await faucet.mineBlocks(6);
230
+ // Test claiming and getting the quote without passing in the output index.
231
+ const quote2 =
232
+ await userWallet.getClaimStaticDepositQuote(transactionId2);
233
+ const quoteAmount2 = quote2!.creditAmountSats;
234
+ const sspSignature2 = quote2!.signature;
235
+ await userWallet.claimStaticDeposit({
236
+ transactionId: transactionId2,
237
+ creditAmountSats: quoteAmount2,
238
+ sspSignature: sspSignature2,
239
+ });
240
+ await new Promise((resolve) => setTimeout(resolve, 1000));
241
+ const { balance: balance2 } = await userWallet.getBalance();
242
+ expect(balance2).toBe(BigInt(quoteAmount + quoteAmount2));
243
+
244
+ // Test depositing money to the same address and test claim with max fee flow.
245
+ const signedTx3 = await faucet.sendToAddress(
246
+ depositAddress,
247
+ THIRD_DEPOSIT_AMOUNT,
248
+ );
249
+ const transactionId3 = signedTx3.id;
250
+ // Wait for the transaction to be mined
251
+ await faucet.mineBlocks(6);
252
+ // Get quote so we can calculate the expected balance. Not needed for actual flow.
253
+ const quote3 =
254
+ await userWallet.getClaimStaticDepositQuote(transactionId3);
255
+ const quoteAmount3 = quote3!.creditAmountSats;
256
+ await userWallet.claimStaticDepositWithMaxFee({
257
+ transactionId: transactionId3,
258
+ maxFee: 1000,
259
+ });
260
+ await new Promise((resolve) => setTimeout(resolve, 1000));
261
+ const { balance: balance3 } = await userWallet.getBalance();
262
+ expect(balance3).toBe(BigInt(quoteAmount + quoteAmount2 + quoteAmount3));
263
+ // Get transfers should include static deposit transfers.
264
+ const transfers = await userWallet.getTransfers();
265
+ expect(transfers.transfers.length).toBe(3);
266
+
267
+ for (let i = 0; i < 98; i++) {
268
+ await faucet.sendToAddress(depositAddress, THIRD_DEPOSIT_AMOUNT);
269
+ await faucet.mineBlocks(6);
270
+ await new Promise((resolve) => setTimeout(resolve, 100));
271
+ }
272
+
273
+ await faucet.mineBlocks(6);
274
+ await new Promise((resolve) => setTimeout(resolve, 1000));
275
+
276
+ const utxosExcludeClaimed = await userWallet.getUtxosForDepositAddress(
277
+ depositAddress,
278
+ 100,
279
+ 0,
280
+ true,
281
+ );
282
+ expect(utxosExcludeClaimed.length).toBe(98);
283
+
284
+ const utxos = await userWallet.getUtxosForDepositAddress(
285
+ depositAddress,
286
+ 100,
287
+ 0,
288
+ false,
289
+ );
290
+ expect(utxos.length).toBe(100);
291
+ }, 60000);
171
292
  });
172
293
 
173
294
  describe("Concurrency testing", () => {
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from "@jest/globals";
2
- import { hexToBytes } from "@noble/curves/abstract/utils";
3
2
  import { secp256k1 } from "@noble/curves/secp256k1";
3
+ import { hexToBytes } from "@noble/curves/utils";
4
4
  import { uuidv7 } from "uuidv7";
5
5
  import { ValidationError } from "../../errors/types.js";
6
6
  import { KeyDerivationType } from "../../index.js";
@@ -1,9 +1,5 @@
1
1
  import { describe, expect, it, jest } from "@jest/globals";
2
- import {
3
- bytesToHex,
4
- equalBytes,
5
- hexToBytes,
6
- } from "@noble/curves/abstract/utils";
2
+ import { bytesToHex, equalBytes, hexToBytes } from "@noble/curves/utils";
7
3
  import { generateMnemonic } from "@scure/bip39";
8
4
  import { wordlist } from "@scure/bip39/wordlists/english";
9
5
  import { uuidv7 } from "uuidv7";
@@ -1,20 +1,20 @@
1
1
  import { describe, expect, it } from "@jest/globals";
2
+ import { schnorr, secp256k1 } from "@noble/curves/secp256k1";
3
+ import { bytesToHex } from "@noble/curves/utils";
4
+ import type { Transaction } from "@scure/btc-signer";
2
5
  import { ConfigOptions } from "../../services/wallet-config.js";
3
- import { NetworkType } from "../../utils/network.js";
4
- import { walletTypes } from "../test-utils.js";
5
- import { SparkWalletTesting } from "../utils/spark-testing-wallet.js";
6
- import { secp256k1, schnorr } from "@noble/curves/secp256k1";
7
- import { bytesToHex } from "@noble/curves/abstract/utils";
8
6
  import type { SparkSigner } from "../../signer/signer.js";
9
- import type { Transaction } from "@scure/btc-signer";
10
7
  import type {
11
8
  AggregateFrostParams,
12
9
  KeyDerivation,
13
- SigningCommitmentWithOptionalNonce,
14
10
  SignFrostParams,
11
+ SigningCommitmentWithOptionalNonce,
15
12
  SplitSecretWithProofsParams,
16
13
  } from "../../signer/types.js";
14
+ import { NetworkType } from "../../utils/network.js";
17
15
  import type { VerifiableSecretShare } from "../../utils/secret-sharing.js";
16
+ import { walletTypes } from "../test-utils.js";
17
+ import { SparkWalletTesting } from "../utils/spark-testing-wallet.js";
18
18
 
19
19
  describe.each(walletTypes)("wallet", ({ name, Signer }) => {
20
20
  it(`${name} - should initialize a wallet`, async () => {
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it, jest } from "@jest/globals";
2
- import { bytesToHex, hexToBytes } from "@noble/curves/abstract/utils";
2
+ import { bytesToHex, hexToBytes } from "@noble/curves/utils";
3
3
  import { uuidv7 } from "uuidv7";
4
4
  import { KeyDerivation, KeyDerivationType } from "../../index.js";
5
5
  import { WalletConfigService } from "../../services/config.js";
@@ -1,14 +1,11 @@
1
- import { numberToBytesBE } from "@noble/curves/abstract/utils";
1
+ import { numberToBytesBE } from "@noble/curves/utils";
2
+ import { sha256 } from "@noble/hashes/sha2";
3
+ import { Network } from "../proto/spark.js";
2
4
  import {
3
5
  hashTokenTransactionV0,
4
6
  hashTokenTransactionV1,
5
7
  hashTokenTransactionV2,
6
8
  } from "../utils/token-hashing.js";
7
- import { Network, OutputWithPreviousTransactionData } from "../proto/spark.js";
8
- import { TokenTransactionService } from "../services/token-transactions.js";
9
- import { WalletConfigService } from "../services/config.js";
10
- import { ConnectionManager } from "../services/connection.js";
11
- import { sha256 } from "@noble/hashes/sha2";
12
9
 
13
10
  // Test constants for consistent test data across all hash tests
14
11
  const TEST_TOKEN_PUBLIC_KEY = new Uint8Array([
@@ -1,9 +1,9 @@
1
- import { numberToBytesBE } from "@noble/curves/abstract/utils";
1
+ import { numberToBytesBE } from "@noble/curves/utils";
2
+ import { ValidationError } from "../errors/types.js";
2
3
  import { OutputWithPreviousTransactionData } from "../proto/spark.js";
3
- import { TokenTransactionService } from "../services/token-transactions.js";
4
4
  import { WalletConfigService } from "../services/config.js";
5
5
  import { ConnectionManager } from "../services/connection.js";
6
- import { ValidationError } from "../errors/types.js";
6
+ import { TokenTransactionService } from "../services/token-transactions.js";
7
7
 
8
8
  describe("select token outputs", () => {
9
9
  let tokenTransactionService: TokenTransactionService;
@@ -1,5 +1,5 @@
1
- import { bytesToHex, hexToBytes } from "@noble/curves/abstract/utils";
2
1
  import { schnorr, secp256k1 } from "@noble/curves/secp256k1";
2
+ import { bytesToHex, hexToBytes } from "@noble/curves/utils";
3
3
  import * as btc from "@scure/btc-signer";
4
4
  import { Address, OutScript, SigHash, Transaction } from "@scure/btc-signer";
5
5
  import { TransactionInput, TransactionOutput } from "@scure/btc-signer/psbt";
@@ -9,8 +9,8 @@ import {
9
9
  getP2TRAddressFromPublicKey,
10
10
  getP2TRScriptFromPublicKey,
11
11
  } from "../../utils/bitcoin.js";
12
- import { getNetwork, Network } from "../../utils/network.js";
13
12
  import { getFetch } from "../../utils/fetch.js";
13
+ import { getNetwork, Network } from "../../utils/network.js";
14
14
 
15
15
  // Static keys for deterministic testing
16
16
  // P2TRAddress: bcrt1p2uy9zw5ltayucsuzl4tet6ckelzawp08qrtunacscsszflye907q62uqhl
@@ -1,4 +1,4 @@
1
- import { bytesToHex } from "@noble/curves/abstract/utils";
1
+ import { bytesToHex } from "@noble/curves/utils";
2
2
  import ClaimStaticDeposit from "../graphql/objects/ClaimStaticDeposit.js";
3
3
  import CoopExitRequest from "../graphql/objects/CoopExitRequest.js";
4
4
  import LeavesSwapRequest from "../graphql/objects/LeavesSwapRequest.js";
@@ -1,6 +1,6 @@
1
1
  import { mod } from "@noble/curves/abstract/modular";
2
- import { bytesToNumberBE, numberToBytesBE } from "@noble/curves/abstract/utils";
3
2
  import { schnorr, secp256k1 } from "@noble/curves/secp256k1";
3
+ import { bytesToNumberBE, numberToBytesBE } from "@noble/curves/utils";
4
4
  import { ValidationError } from "../errors/index.js";
5
5
 
6
6
  export function generateSignatureFromExistingAdaptor(
@@ -1,6 +1,6 @@
1
1
  import { BinaryWriter } from "@bufbuild/protobuf/wire";
2
- import { bytesToNumberBE } from "@noble/curves/abstract/utils";
3
2
  import { schnorr, secp256k1 } from "@noble/curves/secp256k1";
3
+ import { bytesToNumberBE } from "@noble/curves/utils";
4
4
  import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
5
5
  import { bech32m } from "@scure/base";
6
6
  import { UUID } from "uuidv7";
@@ -1,9 +1,5 @@
1
- import {
2
- bytesToHex,
3
- bytesToNumberBE,
4
- hexToBytes,
5
- } from "@noble/curves/abstract/utils";
6
1
  import { schnorr, secp256k1 } from "@noble/curves/secp256k1";
2
+ import { bytesToHex, bytesToNumberBE, hexToBytes } from "@noble/curves/utils";
7
3
 
8
4
  import { sha256 } from "@noble/hashes/sha2";
9
5
  import * as btc from "@scure/btc-signer";
package/src/utils/keys.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { numberToBytesBE } from "@noble/curves/abstract/utils";
2
1
  import { secp256k1 } from "@noble/curves/secp256k1";
2
+ import { numberToBytesBE } from "@noble/curves/utils";
3
3
  import { ValidationError } from "../errors/index.js";
4
4
 
5
5
  export function addPublicKeys(a: Uint8Array, b: Uint8Array): Uint8Array {
@@ -1,5 +1,5 @@
1
- import { bytesToHex, equalBytes } from "@noble/curves/abstract/utils";
2
1
  import { secp256k1 } from "@noble/curves/secp256k1";
2
+ import { bytesToHex, equalBytes } from "@noble/curves/utils";
3
3
  import { ValidationError } from "../errors/index.js";
4
4
  import { getCrypto } from "./crypto.js";
5
5
 
@@ -1,5 +1,4 @@
1
- import { bytesToHex, bytesToNumberBE } from "@noble/curves/abstract/utils";
2
- import { equalBytes } from "@scure/btc-signer/utils";
1
+ import { bytesToNumberBE, equalBytes } from "@noble/curves/utils";
3
2
  import { OutputWithPreviousTransactionData } from "../proto/spark.js";
4
3
  import { TokenBalanceMap, TokenOutputsMap } from "../spark-wallet/types.js";
5
4
  import {
@@ -1,4 +1,4 @@
1
- import { hexToBytes } from "@noble/curves/abstract/utils";
1
+ import { hexToBytes } from "@noble/curves/utils";
2
2
  import { sha256 } from "@noble/hashes/sha2";
3
3
  import { TransferPackage } from "../proto/spark.js";
4
4
 
@@ -1,6 +1,6 @@
1
1
  // unilateral-exit.ts
2
2
 
3
- import { bytesToHex, hexToBytes } from "@noble/curves/abstract/utils";
3
+ import { bytesToHex, hexToBytes } from "@noble/curves/utils";
4
4
  import { ripemd160 } from "@noble/hashes/legacy";
5
5
  import { sha256 } from "@noble/hashes/sha2";
6
6
  import * as btc from "@scure/btc-signer";