@buildonspark/spark-sdk 0.2.2 → 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 (94) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/{chunk-TM6CHQXC.js → chunk-3SEOTO43.js} +1 -1
  3. package/dist/{chunk-2ENZX6LT.js → chunk-AAZWSPUK.js} +84 -8
  4. package/dist/{chunk-4JD4HIAN.js → chunk-G4MSZ6DE.js} +299 -1
  5. package/dist/{chunk-S2AL73MZ.js → chunk-TVUMSHWA.js} +1 -1
  6. package/dist/{chunk-2TUM3R6C.js → chunk-W4ZRBSWM.js} +2351 -797
  7. package/dist/{chunk-CDLETEDT.js → chunk-WAQKYSDI.js} +13 -1
  8. package/dist/{client-CGTRS23n.d.ts → client-BF4cn8F4.d.ts} +15 -3
  9. package/dist/{client-CcYzmpmj.d.cts → client-KhNkrXz4.d.cts} +15 -3
  10. package/dist/debug.cjs +2948 -1023
  11. package/dist/debug.d.cts +19 -6
  12. package/dist/debug.d.ts +19 -6
  13. package/dist/debug.js +5 -5
  14. package/dist/graphql/objects/index.cjs +13 -1
  15. package/dist/graphql/objects/index.d.cts +2 -2
  16. package/dist/graphql/objects/index.d.ts +2 -2
  17. package/dist/graphql/objects/index.js +1 -1
  18. package/dist/index.cjs +2794 -858
  19. package/dist/index.d.cts +190 -9
  20. package/dist/index.d.ts +190 -9
  21. package/dist/index.js +32 -6
  22. package/dist/index.node.cjs +2931 -892
  23. package/dist/index.node.d.cts +10 -188
  24. package/dist/index.node.d.ts +10 -188
  25. package/dist/index.node.js +134 -6
  26. package/dist/native/index.cjs +2794 -858
  27. package/dist/native/index.d.cts +148 -40
  28. package/dist/native/index.d.ts +148 -40
  29. package/dist/native/index.js +2799 -877
  30. package/dist/proto/lrc20.d.cts +1 -1
  31. package/dist/proto/lrc20.d.ts +1 -1
  32. package/dist/proto/lrc20.js +1 -1
  33. package/dist/proto/spark.cjs +84 -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 +1 -1
  37. package/dist/proto/spark_token.cjs +301 -0
  38. package/dist/proto/spark_token.d.cts +35 -2
  39. package/dist/proto/spark_token.d.ts +35 -2
  40. package/dist/proto/spark_token.js +8 -2
  41. package/dist/{sdk-types-DJ2ve9YY.d.cts → sdk-types-CB9HrW5O.d.cts} +1 -1
  42. package/dist/{sdk-types-DCIVdKUT.d.ts → sdk-types-CkRNraXT.d.ts} +1 -1
  43. package/dist/{spark-BUOx3U7Q.d.cts → spark-B_7nZx6T.d.cts} +112 -10
  44. package/dist/{spark-BUOx3U7Q.d.ts → spark-B_7nZx6T.d.ts} +112 -10
  45. package/dist/{spark-wallet-B_96y9BS.d.ts → spark-wallet-C1Tr_VKI.d.ts} +38 -28
  46. package/dist/{spark-wallet-CHwKQYJu.d.cts → spark-wallet-DG3x2obf.d.cts} +38 -28
  47. package/dist/spark-wallet.node-CGxoeCpH.d.ts +13 -0
  48. package/dist/spark-wallet.node-CN9LoB_O.d.cts +13 -0
  49. package/dist/tests/test-utils.cjs +1086 -218
  50. package/dist/tests/test-utils.d.cts +13 -13
  51. package/dist/tests/test-utils.d.ts +13 -13
  52. package/dist/tests/test-utils.js +56 -19
  53. package/dist/types/index.cjs +97 -9
  54. package/dist/types/index.d.cts +3 -3
  55. package/dist/types/index.d.ts +3 -3
  56. package/dist/types/index.js +3 -3
  57. package/dist/{xchain-address-D5MIHCDL.d.cts → xchain-address-BHu6CpZC.d.ts} +55 -8
  58. package/dist/{xchain-address-DLbW1iDh.d.ts → xchain-address-HBr6isnc.d.cts} +55 -8
  59. package/package.json +1 -1
  60. package/src/graphql/client.ts +8 -0
  61. package/src/graphql/mutations/CompleteLeavesSwap.ts +9 -1
  62. package/src/graphql/mutations/RequestSwapLeaves.ts +4 -0
  63. package/src/graphql/objects/CompleteLeavesSwapInput.ts +34 -34
  64. package/src/graphql/objects/LeavesSwapRequest.ts +4 -0
  65. package/src/graphql/objects/RequestLeavesSwapInput.ts +48 -47
  66. package/src/graphql/objects/SwapLeaf.ts +40 -32
  67. package/src/graphql/objects/UserLeafInput.ts +24 -0
  68. package/src/graphql/objects/UserRequest.ts +4 -0
  69. package/src/index.node.ts +1 -1
  70. package/src/native/index.ts +4 -5
  71. package/src/proto/spark.ts +172 -16
  72. package/src/proto/spark_token.ts +369 -0
  73. package/src/services/coop-exit.ts +171 -36
  74. package/src/services/deposit.ts +471 -74
  75. package/src/services/lightning.ts +18 -5
  76. package/src/services/signing.ts +162 -50
  77. package/src/services/token-transactions.ts +6 -2
  78. package/src/services/transfer.ts +950 -384
  79. package/src/services/tree-creation.ts +342 -121
  80. package/src/spark-wallet/spark-wallet.node.ts +71 -66
  81. package/src/spark-wallet/spark-wallet.ts +459 -166
  82. package/src/tests/integration/coop-exit.test.ts +3 -8
  83. package/src/tests/integration/deposit.test.ts +3 -3
  84. package/src/tests/integration/lightning.test.ts +521 -466
  85. package/src/tests/integration/swap.test.ts +559 -307
  86. package/src/tests/integration/transfer.test.ts +625 -623
  87. package/src/tests/integration/wallet.test.ts +2 -2
  88. package/src/tests/integration/watchtower.test.ts +211 -0
  89. package/src/tests/test-utils.ts +63 -14
  90. package/src/tests/utils/test-faucet.ts +4 -2
  91. package/src/utils/adaptor-signature.ts +15 -5
  92. package/src/utils/fetch.ts +75 -0
  93. package/src/utils/mempool.ts +9 -4
  94. 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