@buildonspark/spark-sdk 0.2.3 → 0.2.4

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 (73) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/{chunk-PTRXJS7Q.js → chunk-TVUMSHWA.js} +1 -1
  3. package/dist/{chunk-PLLJIZC3.js → chunk-W4ZRBSWM.js} +2298 -778
  4. package/dist/{chunk-CDLETEDT.js → chunk-WAQKYSDI.js} +13 -1
  5. package/dist/{client-CGTRS23n.d.ts → client-BF4cn8F4.d.ts} +15 -3
  6. package/dist/{client-CcYzmpmj.d.cts → client-KhNkrXz4.d.cts} +15 -3
  7. package/dist/debug.cjs +2282 -762
  8. package/dist/debug.d.cts +17 -4
  9. package/dist/debug.d.ts +17 -4
  10. package/dist/debug.js +2 -2
  11. package/dist/graphql/objects/index.cjs +13 -1
  12. package/dist/graphql/objects/index.d.cts +2 -2
  13. package/dist/graphql/objects/index.d.ts +2 -2
  14. package/dist/graphql/objects/index.js +1 -1
  15. package/dist/index.cjs +2283 -752
  16. package/dist/index.d.cts +189 -8
  17. package/dist/index.d.ts +189 -8
  18. package/dist/index.js +29 -3
  19. package/dist/index.node.cjs +2387 -753
  20. package/dist/index.node.d.cts +9 -189
  21. package/dist/index.node.d.ts +9 -189
  22. package/dist/index.node.js +131 -3
  23. package/dist/native/index.cjs +2283 -752
  24. package/dist/native/index.d.cts +95 -30
  25. package/dist/native/index.d.ts +95 -30
  26. package/dist/native/index.js +2284 -767
  27. package/dist/{spark-wallet-CxcGPXRB.d.ts → spark-wallet-C1Tr_VKI.d.ts} +31 -25
  28. package/dist/{spark-wallet-DJJm19BP.d.cts → spark-wallet-DG3x2obf.d.cts} +31 -25
  29. package/dist/spark-wallet.node-CGxoeCpH.d.ts +13 -0
  30. package/dist/spark-wallet.node-CN9LoB_O.d.cts +13 -0
  31. package/dist/tests/test-utils.cjs +570 -73
  32. package/dist/tests/test-utils.d.cts +11 -11
  33. package/dist/tests/test-utils.d.ts +11 -11
  34. package/dist/tests/test-utils.js +53 -16
  35. package/dist/types/index.cjs +13 -1
  36. package/dist/types/index.d.cts +1 -1
  37. package/dist/types/index.d.ts +1 -1
  38. package/dist/types/index.js +1 -1
  39. package/dist/{xchain-address-Bh9w1SeC.d.ts → xchain-address-BHu6CpZC.d.ts} +54 -7
  40. package/dist/{xchain-address-SZ7dkVUE.d.cts → xchain-address-HBr6isnc.d.cts} +54 -7
  41. package/package.json +1 -1
  42. package/src/graphql/client.ts +8 -0
  43. package/src/graphql/mutations/CompleteLeavesSwap.ts +9 -1
  44. package/src/graphql/mutations/RequestSwapLeaves.ts +4 -0
  45. package/src/graphql/objects/CompleteLeavesSwapInput.ts +34 -34
  46. package/src/graphql/objects/LeavesSwapRequest.ts +4 -0
  47. package/src/graphql/objects/RequestLeavesSwapInput.ts +48 -47
  48. package/src/graphql/objects/SwapLeaf.ts +40 -32
  49. package/src/graphql/objects/UserLeafInput.ts +24 -0
  50. package/src/graphql/objects/UserRequest.ts +4 -0
  51. package/src/index.node.ts +1 -1
  52. package/src/native/index.ts +4 -5
  53. package/src/services/coop-exit.ts +171 -36
  54. package/src/services/deposit.ts +471 -74
  55. package/src/services/lightning.ts +18 -5
  56. package/src/services/signing.ts +162 -50
  57. package/src/services/transfer.ts +950 -384
  58. package/src/services/tree-creation.ts +342 -121
  59. package/src/spark-wallet/spark-wallet.node.ts +71 -66
  60. package/src/spark-wallet/spark-wallet.ts +405 -153
  61. package/src/tests/integration/coop-exit.test.ts +3 -8
  62. package/src/tests/integration/deposit.test.ts +3 -3
  63. package/src/tests/integration/lightning.test.ts +521 -466
  64. package/src/tests/integration/swap.test.ts +559 -307
  65. package/src/tests/integration/transfer.test.ts +625 -623
  66. package/src/tests/integration/wallet.test.ts +2 -2
  67. package/src/tests/integration/watchtower.test.ts +211 -0
  68. package/src/tests/test-utils.ts +63 -14
  69. package/src/tests/utils/test-faucet.ts +4 -2
  70. package/src/utils/adaptor-signature.ts +15 -5
  71. package/src/utils/fetch.ts +75 -0
  72. package/src/utils/mempool.ts +9 -4
  73. package/src/utils/transaction.ts +388 -26
@@ -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