@buildonspark/spark-sdk 0.2.3 → 0.2.5

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 (91) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/{chunk-3SEOTO43.js → chunk-3SPMJMUX.js} +3 -2
  3. package/dist/{chunk-CDLETEDT.js → chunk-CQY5ML2A.js} +16 -3
  4. package/dist/{chunk-PTRXJS7Q.js → chunk-LQZL2D3Y.js} +1 -1
  5. package/dist/{chunk-PLLJIZC3.js → chunk-U7LRIWTF.js} +2471 -822
  6. package/dist/{client-CcYzmpmj.d.cts → client-C88GCTPB.d.cts} +211 -104
  7. package/dist/{client-CGTRS23n.d.ts → client-Dg6vS_2I.d.ts} +211 -104
  8. package/dist/debug.cjs +2511 -831
  9. package/dist/debug.d.cts +19 -6
  10. package/dist/debug.d.ts +19 -6
  11. package/dist/debug.js +3 -3
  12. package/dist/graphql/objects/index.cjs +13 -1
  13. package/dist/graphql/objects/index.d.cts +6 -51
  14. package/dist/graphql/objects/index.d.ts +6 -51
  15. package/dist/graphql/objects/index.js +1 -1
  16. package/dist/index.cjs +2491 -797
  17. package/dist/index.d.cts +189 -9
  18. package/dist/index.d.ts +189 -9
  19. package/dist/index.js +32 -4
  20. package/dist/index.node.cjs +2596 -799
  21. package/dist/index.node.d.cts +9 -190
  22. package/dist/index.node.d.ts +9 -190
  23. package/dist/index.node.js +134 -4
  24. package/dist/native/index.cjs +2491 -797
  25. package/dist/native/index.d.cts +309 -174
  26. package/dist/native/index.d.ts +309 -174
  27. package/dist/native/index.js +2495 -814
  28. package/dist/proto/lrc20.d.cts +1 -1
  29. package/dist/proto/lrc20.d.ts +1 -1
  30. package/dist/proto/spark.d.cts +1 -1
  31. package/dist/proto/spark.d.ts +1 -1
  32. package/dist/proto/spark_token.d.cts +1 -1
  33. package/dist/proto/spark_token.d.ts +1 -1
  34. package/dist/{spark-B_7nZx6T.d.cts → spark-ESAfZARg.d.cts} +1 -1
  35. package/dist/{spark-B_7nZx6T.d.ts → spark-ESAfZARg.d.ts} +1 -1
  36. package/dist/{spark-wallet-CxcGPXRB.d.ts → spark-wallet-B2WwKN8W.d.ts} +57 -35
  37. package/dist/{spark-wallet-DJJm19BP.d.cts → spark-wallet-Di65w0Us.d.cts} +57 -35
  38. package/dist/spark-wallet.node-7R0Rxyj9.d.cts +13 -0
  39. package/dist/spark-wallet.node-CSPWOWRu.d.ts +13 -0
  40. package/dist/tests/test-utils.cjs +578 -77
  41. package/dist/tests/test-utils.d.cts +12 -13
  42. package/dist/tests/test-utils.d.ts +12 -13
  43. package/dist/tests/test-utils.js +54 -17
  44. package/dist/types/index.cjs +16 -3
  45. package/dist/types/index.d.cts +3 -4
  46. package/dist/types/index.d.ts +3 -4
  47. package/dist/types/index.js +2 -2
  48. package/dist/{xchain-address-Bh9w1SeC.d.ts → xchain-address-BsveIy5l.d.ts} +56 -8
  49. package/dist/{xchain-address-SZ7dkVUE.d.cts → xchain-address-CqRu3F21.d.cts} +56 -8
  50. package/package.json +1 -1
  51. package/src/graphql/client.ts +57 -8
  52. package/src/graphql/mutations/CompleteLeavesSwap.ts +9 -1
  53. package/src/graphql/mutations/RequestSwapLeaves.ts +4 -0
  54. package/src/graphql/objects/CompleteLeavesSwapInput.ts +34 -34
  55. package/src/graphql/objects/LeavesSwapRequest.ts +4 -0
  56. package/src/graphql/objects/RequestLeavesSwapInput.ts +48 -47
  57. package/src/graphql/objects/SparkWalletUser.ts +1 -1
  58. package/src/graphql/objects/SwapLeaf.ts +40 -32
  59. package/src/graphql/objects/UserLeafInput.ts +24 -0
  60. package/src/graphql/objects/UserRequest.ts +4 -0
  61. package/src/graphql/queries/Transfers.ts +15 -0
  62. package/src/index.node.ts +1 -1
  63. package/src/native/index.ts +4 -5
  64. package/src/services/coop-exit.ts +171 -36
  65. package/src/services/deposit.ts +471 -74
  66. package/src/services/lightning.ts +18 -5
  67. package/src/services/signing.ts +162 -50
  68. package/src/services/transfer.ts +950 -384
  69. package/src/services/tree-creation.ts +342 -121
  70. package/src/spark-wallet/spark-wallet.node.ts +71 -66
  71. package/src/spark-wallet/spark-wallet.ts +561 -192
  72. package/src/tests/integration/coop-exit.test.ts +3 -8
  73. package/src/tests/integration/deposit.test.ts +3 -3
  74. package/src/tests/integration/lightning.test.ts +521 -466
  75. package/src/tests/integration/ssp/static_deposit.test.ts +83 -1
  76. package/src/tests/integration/ssp/transfers.test.ts +97 -0
  77. package/src/tests/integration/swap.test.ts +559 -307
  78. package/src/tests/integration/transfer.test.ts +625 -623
  79. package/src/tests/integration/wallet.test.ts +2 -2
  80. package/src/tests/integration/watchtower.test.ts +211 -0
  81. package/src/tests/test-utils.ts +63 -14
  82. package/src/tests/utils/test-faucet.ts +4 -2
  83. package/src/types/sdk-types.ts +15 -0
  84. package/src/utils/adaptor-signature.ts +15 -5
  85. package/src/utils/bitcoin.ts +13 -0
  86. package/src/utils/fetch.ts +75 -0
  87. package/src/utils/mempool.ts +9 -4
  88. package/src/utils/transaction.ts +388 -26
  89. package/dist/sdk-types-CB9HrW5O.d.cts +0 -44
  90. package/dist/sdk-types-CkRNraXT.d.ts +0 -44
  91. package/src/graphql/queries/Transfer.ts +0 -10
@@ -1,15 +1,16 @@
1
1
  import { Tracer } from "@opentelemetry/api";
2
2
  import { SparkWallet as BaseSparkWallet } from "./spark-wallet.js";
3
3
  import type { InitWalletResponse } from "./types.js";
4
+ import { isObject } from "@lightsparkdev/core";
4
5
 
5
6
  export class SparkWallet extends BaseSparkWallet {
6
7
  private tracer: Tracer | null = null;
7
8
 
8
- protected wrapWithOtelSpan<T>(
9
+ protected wrapWithOtelSpan<A extends unknown[], R>(
9
10
  name: string,
10
- fn: (...args: any[]) => Promise<T>,
11
- ): (...args: any[]) => Promise<T> {
12
- return async (...args: any[]): Promise<T> => {
11
+ fn: (...args: A) => Promise<R>,
12
+ ) {
13
+ return async (...args: A) => {
13
14
  if (!this.tracer) {
14
15
  throw new Error("Tracer not initialized");
15
16
  }
@@ -17,12 +18,13 @@ export class SparkWallet extends BaseSparkWallet {
17
18
  return await this.tracer.startActiveSpan(name, async (span) => {
18
19
  const traceId = span.spanContext().traceId;
19
20
  try {
20
- return await fn(...args);
21
+ const result = await fn(...args);
22
+ return result;
21
23
  } catch (error) {
22
24
  if (error instanceof Error) {
23
25
  error.message += ` [traceId: ${traceId}]`;
24
- } else if (typeof error === "object" && error !== null) {
25
- (error as any).traceId = traceId;
26
+ } else if (isObject(error)) {
27
+ error["traceId"] = traceId;
26
28
  }
27
29
  throw error;
28
30
  } finally {
@@ -49,66 +51,69 @@ export class SparkWallet extends BaseSparkWallet {
49
51
  this.tracer = trace.getTracer(tracerName);
50
52
  }
51
53
 
54
+ private getTraceName(methodName: string) {
55
+ return `SparkWallet.${methodName}`;
56
+ }
57
+
58
+ private wrapPublicMethodsWithOtelSpan<M extends keyof SparkWallet>(
59
+ methodName: M,
60
+ ) {
61
+ const original = this[methodName];
62
+
63
+ if (typeof original !== "function") {
64
+ throw new Error(`Method ${methodName} is not a function on SparkWallet.`);
65
+ }
66
+
67
+ const wrapped = this.wrapWithOtelSpan(
68
+ this.getTraceName(methodName),
69
+ original.bind(this) as (...args: unknown[]) => Promise<unknown>,
70
+ ) as SparkWallet[M];
71
+
72
+ (this as SparkWallet)[methodName] = wrapped;
73
+ }
74
+
52
75
  private wrapSparkWalletWithTracing() {
53
- this.getIdentityPublicKey = this.wrapWithOtelSpan(
54
- "SparkWallet.getIdentityPublicKey",
55
- this.getIdentityPublicKey.bind(this),
56
- );
57
- this.getSparkAddress = this.wrapWithOtelSpan(
58
- "SparkWallet.getSparkAddress",
59
- this.getSparkAddress.bind(this),
60
- );
61
- this.getSwapFeeEstimate = this.wrapWithOtelSpan(
62
- "SparkWallet.getSwapFeeEstimate",
63
- this.getSwapFeeEstimate.bind(this),
64
- );
65
- this.getTransfers = this.wrapWithOtelSpan(
66
- "SparkWallet.getTransfers",
67
- this.getTransfers.bind(this),
68
- );
69
- this.getBalance = this.wrapWithOtelSpan(
70
- "SparkWallet.getBalance",
71
- this.getBalance.bind(this),
72
- );
73
- this.getSingleUseDepositAddress = this.wrapWithOtelSpan(
74
- "SparkWallet.getSingleUseDepositAddress",
75
- this.getSingleUseDepositAddress.bind(this),
76
- );
77
- this.getUnusedDepositAddresses = this.wrapWithOtelSpan(
78
- "SparkWallet.getUnusedDepositAddresses",
79
- this.getUnusedDepositAddresses.bind(this),
80
- );
81
- this.claimDeposit = this.wrapWithOtelSpan(
82
- "SparkWallet.claimDeposit",
83
- this.claimDeposit.bind(this),
84
- );
85
- this.advancedDeposit = this.wrapWithOtelSpan(
86
- "SparkWallet.advancedDeposit",
87
- this.advancedDeposit.bind(this),
88
- );
89
- this.transfer = this.wrapWithOtelSpan(
90
- "SparkWallet.transfer",
91
- this.transfer.bind(this),
92
- );
93
- this.createLightningInvoice = this.wrapWithOtelSpan(
94
- "SparkWallet.createLightningInvoice",
95
- this.createLightningInvoice.bind(this),
96
- );
97
- this.payLightningInvoice = this.wrapWithOtelSpan(
98
- "SparkWallet.payLightningInvoice",
99
- this.payLightningInvoice.bind(this),
100
- );
101
- this.getLightningSendFeeEstimate = this.wrapWithOtelSpan(
102
- "SparkWallet.getLightningSendFeeEstimate",
103
- this.getLightningSendFeeEstimate.bind(this),
104
- );
105
- this.withdraw = this.wrapWithOtelSpan(
106
- "SparkWallet.withdraw",
107
- this.withdraw.bind(this),
108
- );
109
- this.getWithdrawalFeeQuote = this.wrapWithOtelSpan(
110
- "SparkWallet.getWithdrawalFeeQuote",
111
- this.getWithdrawalFeeQuote.bind(this),
76
+ const methods = [
77
+ "getLeaves",
78
+ "getIdentityPublicKey",
79
+ "getSparkAddress",
80
+ "createSparkPaymentIntent",
81
+ "getSwapFeeEstimate",
82
+ "getTransfers",
83
+ "getBalance",
84
+ "getSingleUseDepositAddress",
85
+ "getStaticDepositAddress",
86
+ "queryStaticDepositAddresses",
87
+ "getClaimStaticDepositQuote",
88
+ "claimStaticDeposit",
89
+ "refundStaticDeposit",
90
+ "getUnusedDepositAddresses",
91
+ "claimDeposit",
92
+ "advancedDeposit",
93
+ "transfer",
94
+ "createLightningInvoice",
95
+ "payLightningInvoice",
96
+ "getLightningSendFeeEstimate",
97
+ "withdraw",
98
+ "getWithdrawalFeeQuote",
99
+ "getTransferFromSsp",
100
+ "getTransfer",
101
+ "transferTokens",
102
+ "batchTransferTokens",
103
+ "queryTokenTransactions",
104
+ "getLightningReceiveRequest",
105
+ "getLightningSendRequest",
106
+ "getCoopExitRequest",
107
+ "checkTimelock",
108
+ "testOnly_expireTimelock",
109
+ ] as const;
110
+
111
+ methods.forEach((m) => this.wrapPublicMethodsWithOtelSpan(m));
112
+
113
+ /* Private methods can't be indexed on `this` and need to be wrapped individually: */
114
+ this.initWallet = this.wrapWithOtelSpan(
115
+ this.getTraceName("initWallet"),
116
+ this.initWallet.bind(this),
112
117
  );
113
118
  }
114
119