@buildonspark/spark-sdk 0.3.3 → 0.3.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 (72) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/bare/index.cjs +938 -1401
  3. package/dist/bare/index.d.cts +128 -10
  4. package/dist/bare/index.d.ts +128 -10
  5. package/dist/bare/index.js +933 -1399
  6. package/dist/{chunk-MGCUXELA.js → chunk-IC4IUEOS.js} +931 -125
  7. package/dist/{chunk-MH7BMOLL.js → chunk-J2P3KTQP.js} +1 -1
  8. package/dist/{chunk-SXXM52XH.js → chunk-KIQTO4FX.js} +405 -1659
  9. package/dist/{chunk-73GJOG5R.js → chunk-XWLR6G5C.js} +1 -1
  10. package/dist/{chunk-55XNR6DM.js → chunk-YH7MDVTT.js} +1 -1
  11. package/dist/{client-DrjQwET9.d.ts → client-DBZ43pJT.d.ts} +1 -1
  12. package/dist/{client-DUFejFfn.d.cts → client-DWml6sjL.d.cts} +1 -1
  13. package/dist/debug.cjs +942 -1403
  14. package/dist/debug.d.cts +8 -5
  15. package/dist/debug.d.ts +8 -5
  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 +898 -1362
  20. package/dist/index.d.cts +6 -6
  21. package/dist/index.d.ts +6 -6
  22. package/dist/index.js +9 -5
  23. package/dist/index.node.cjs +898 -1362
  24. package/dist/index.node.d.cts +6 -6
  25. package/dist/index.node.d.ts +6 -6
  26. package/dist/index.node.js +8 -4
  27. package/dist/{logging-CGeEoKYd.d.cts → logging-BUpzk4Z6.d.cts} +3 -3
  28. package/dist/{logging-DpSsvFVM.d.ts → logging-Dt2ooQiP.d.ts} +3 -3
  29. package/dist/native/index.cjs +898 -1362
  30. package/dist/native/index.d.cts +129 -25
  31. package/dist/native/index.d.ts +129 -25
  32. package/dist/native/index.js +897 -1363
  33. package/dist/proto/spark.cjs +931 -125
  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-CLz4-Ln8.d.cts → spark-DasxuVfm.d.cts} +150 -5
  41. package/dist/{spark-CLz4-Ln8.d.ts → spark-DasxuVfm.d.ts} +150 -5
  42. package/dist/{spark-wallet-BVBrWYKL.d.cts → spark-wallet-BoMIOPWW.d.cts} +13 -9
  43. package/dist/{spark-wallet-CFPm6wZs.d.ts → spark-wallet-jlC0XN5f.d.ts} +13 -9
  44. package/dist/{spark-wallet.node-e1gncoIZ.d.ts → spark-wallet.node-07PksUHH.d.cts} +1 -1
  45. package/dist/{spark-wallet.node-B_00X-1j.d.cts → spark-wallet.node-CdWkKMSq.d.ts} +1 -1
  46. package/dist/tests/test-utils.cjs +947 -144
  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-BkAqlmY6.d.ts → token-transactions-BDzCrQSk.d.cts} +5 -19
  51. package/dist/{token-transactions-BZGtwFFM.d.cts → token-transactions-DscJaJOE.d.ts} +5 -19
  52. package/dist/types/index.cjs +923 -125
  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/spark.ts +1167 -103
  58. package/src/services/config.ts +0 -4
  59. package/src/services/token-transactions.ts +11 -703
  60. package/src/services/wallet-config.ts +0 -2
  61. package/src/spark-wallet/proto-descriptors.ts +1 -1
  62. package/src/spark-wallet/spark-wallet.ts +47 -215
  63. package/src/spark_descriptors.pb +0 -0
  64. package/src/tests/address.test.ts +141 -0
  65. package/src/tests/integration/address.test.ts +4 -0
  66. package/src/tests/integration/lightning.test.ts +14 -9
  67. package/src/tests/integration/token-output.test.ts +0 -1
  68. package/src/tests/integration/transfer.test.ts +108 -2
  69. package/src/tests/token-hashing.test.ts +0 -247
  70. package/src/utils/address.ts +58 -35
  71. package/src/utils/token-hashing.ts +1 -420
  72. package/src/utils/token-transaction-validation.ts +0 -330
@@ -1,8 +1,4 @@
1
1
  import { InternalValidationError } from "../errors/types.js";
2
- import {
3
- TokenTransaction as TokenTransactionV0,
4
- TokenOutputToSpend as TokenOutputToSpendV0,
5
- } from "../proto/spark.js";
6
2
  import {
7
3
  TokenTransaction as TokenTransaction,
8
4
  TokenOutputToSpend as TokenOutputToSpend,
@@ -19,332 +15,6 @@ function hasDuplicates<T>(array: T[]): boolean {
19
15
  return new Set(array).size !== array.length;
20
16
  }
21
17
 
22
- export function validateTokenTransactionV0(
23
- finalTokenTransaction: TokenTransactionV0,
24
- partialTokenTransaction: TokenTransactionV0,
25
- signingOperators: Record<string, any>,
26
- keyshareInfo: { ownerIdentifiers: string[]; threshold: number },
27
- expectedWithdrawBondSats: number,
28
- expectedWithdrawRelativeBlockLocktime: number,
29
- expectedThreshold: number,
30
- ) {
31
- if (finalTokenTransaction.network !== partialTokenTransaction.network) {
32
- throw new InternalValidationError(
33
- "Network mismatch in response token transaction",
34
- {
35
- value: finalTokenTransaction.network,
36
- expected: partialTokenTransaction.network,
37
- },
38
- );
39
- }
40
-
41
- if (!finalTokenTransaction.tokenInputs) {
42
- throw new InternalValidationError(
43
- "Token inputs missing in final transaction",
44
- {
45
- value: finalTokenTransaction,
46
- },
47
- );
48
- }
49
-
50
- if (!partialTokenTransaction.tokenInputs) {
51
- throw new InternalValidationError(
52
- "Token inputs missing in partial transaction",
53
- {
54
- value: partialTokenTransaction,
55
- },
56
- );
57
- }
58
-
59
- if (
60
- finalTokenTransaction.tokenInputs.$case !==
61
- partialTokenTransaction.tokenInputs.$case
62
- ) {
63
- throw new InternalValidationError(
64
- `Transaction type mismatch: final transaction has ${finalTokenTransaction.tokenInputs.$case}, partial transaction has ${partialTokenTransaction.tokenInputs.$case}`,
65
- {
66
- value: finalTokenTransaction.tokenInputs.$case,
67
- expected: partialTokenTransaction.tokenInputs.$case,
68
- },
69
- );
70
- }
71
-
72
- if (
73
- finalTokenTransaction.sparkOperatorIdentityPublicKeys.length !==
74
- partialTokenTransaction.sparkOperatorIdentityPublicKeys.length
75
- ) {
76
- throw new InternalValidationError(
77
- "Spark operator identity public keys count mismatch",
78
- {
79
- value: finalTokenTransaction.sparkOperatorIdentityPublicKeys.length,
80
- expected:
81
- partialTokenTransaction.sparkOperatorIdentityPublicKeys.length,
82
- },
83
- );
84
- }
85
-
86
- if (
87
- partialTokenTransaction.tokenInputs.$case === "mintInput" &&
88
- finalTokenTransaction.tokenInputs.$case === "mintInput"
89
- ) {
90
- const finalMintInput = finalTokenTransaction.tokenInputs.mintInput;
91
- const partialMintInput = partialTokenTransaction.tokenInputs.mintInput;
92
-
93
- if (
94
- !areByteArraysEqual(
95
- finalMintInput.issuerPublicKey,
96
- partialMintInput.issuerPublicKey,
97
- )
98
- ) {
99
- throw new InternalValidationError(
100
- "Issuer public key mismatch in mint input",
101
- {
102
- value: finalMintInput.issuerPublicKey.toString(),
103
- expected: partialMintInput.issuerPublicKey.toString(),
104
- },
105
- );
106
- }
107
- } else if (
108
- partialTokenTransaction.tokenInputs.$case === "transferInput" &&
109
- finalTokenTransaction.tokenInputs.$case === "transferInput"
110
- ) {
111
- const finalTransferInput = finalTokenTransaction.tokenInputs.transferInput;
112
- const partialTransferInput =
113
- partialTokenTransaction.tokenInputs.transferInput;
114
-
115
- if (
116
- finalTransferInput.outputsToSpend.length !==
117
- partialTransferInput.outputsToSpend.length
118
- ) {
119
- throw new InternalValidationError(
120
- "Outputs to spend count mismatch in transfer input",
121
- {
122
- value: finalTransferInput.outputsToSpend.length,
123
- expected: partialTransferInput.outputsToSpend.length,
124
- },
125
- );
126
- }
127
-
128
- for (let i = 0; i < finalTransferInput.outputsToSpend.length; i++) {
129
- const finalOutput = finalTransferInput.outputsToSpend[
130
- i
131
- ] as TokenOutputToSpendV0;
132
- const partialOutput = partialTransferInput.outputsToSpend[
133
- i
134
- ] as TokenOutputToSpendV0;
135
-
136
- if (!finalOutput) {
137
- throw new InternalValidationError(
138
- "Token output to spend missing in final transaction",
139
- {
140
- outputIndex: i,
141
- value: finalOutput,
142
- },
143
- );
144
- }
145
-
146
- if (!partialOutput) {
147
- throw new InternalValidationError(
148
- "Token output to spend missing in partial transaction",
149
- {
150
- outputIndex: i,
151
- value: partialOutput,
152
- },
153
- );
154
- }
155
-
156
- if (
157
- !areByteArraysEqual(
158
- finalOutput.prevTokenTransactionHash,
159
- partialOutput.prevTokenTransactionHash,
160
- )
161
- ) {
162
- throw new InternalValidationError(
163
- "Previous token transaction hash mismatch in transfer input",
164
- {
165
- outputIndex: i,
166
- value: finalOutput.prevTokenTransactionHash.toString(),
167
- expected: partialOutput.prevTokenTransactionHash.toString(),
168
- },
169
- );
170
- }
171
-
172
- if (
173
- finalOutput.prevTokenTransactionVout !==
174
- partialOutput.prevTokenTransactionVout
175
- ) {
176
- throw new InternalValidationError(
177
- "Previous token transaction vout mismatch in transfer input",
178
- {
179
- outputIndex: i,
180
- value: finalOutput.prevTokenTransactionVout,
181
- expected: partialOutput.prevTokenTransactionVout,
182
- },
183
- );
184
- }
185
- }
186
- }
187
-
188
- if (
189
- finalTokenTransaction.tokenOutputs.length !==
190
- partialTokenTransaction.tokenOutputs.length
191
- ) {
192
- throw new InternalValidationError("Token outputs count mismatch", {
193
- value: finalTokenTransaction.tokenOutputs.length,
194
- expected: partialTokenTransaction.tokenOutputs.length,
195
- });
196
- }
197
-
198
- for (let i = 0; i < finalTokenTransaction.tokenOutputs.length; i++) {
199
- const finalOutput = finalTokenTransaction.tokenOutputs[i];
200
- const partialOutput = partialTokenTransaction.tokenOutputs[i];
201
-
202
- if (!finalOutput) {
203
- throw new InternalValidationError(
204
- "Token output missing in final transaction",
205
- {
206
- outputIndex: i,
207
- value: finalOutput,
208
- },
209
- );
210
- }
211
-
212
- if (!partialOutput) {
213
- throw new InternalValidationError(
214
- "Token output missing in partial transaction",
215
- {
216
- outputIndex: i,
217
- value: partialOutput,
218
- },
219
- );
220
- }
221
-
222
- if (
223
- !areByteArraysEqual(
224
- finalOutput.ownerPublicKey,
225
- partialOutput.ownerPublicKey,
226
- )
227
- ) {
228
- throw new InternalValidationError(
229
- "Owner public key mismatch in token output",
230
- {
231
- outputIndex: i,
232
- value: finalOutput.ownerPublicKey.toString(),
233
- expected: partialOutput.ownerPublicKey.toString(),
234
- },
235
- );
236
- }
237
-
238
- if (
239
- finalOutput.tokenPublicKey !== undefined &&
240
- partialOutput.tokenPublicKey !== undefined &&
241
- !areByteArraysEqual(
242
- finalOutput.tokenPublicKey,
243
- partialOutput.tokenPublicKey,
244
- )
245
- ) {
246
- throw new InternalValidationError(
247
- "Token public key mismatch in token output",
248
- {
249
- outputIndex: i,
250
- value: finalOutput.tokenPublicKey?.toString(),
251
- expected: partialOutput.tokenPublicKey?.toString(),
252
- },
253
- );
254
- }
255
-
256
- if (
257
- !areByteArraysEqual(finalOutput.tokenAmount, partialOutput.tokenAmount)
258
- ) {
259
- throw new InternalValidationError(
260
- "Token amount mismatch in token output",
261
- {
262
- outputIndex: i,
263
- value: finalOutput.tokenAmount.toString(),
264
- expected: partialOutput.tokenAmount.toString(),
265
- },
266
- );
267
- }
268
-
269
- if (finalOutput.withdrawBondSats !== undefined) {
270
- if (finalOutput.withdrawBondSats !== expectedWithdrawBondSats) {
271
- throw new InternalValidationError(
272
- "Withdraw bond sats mismatch in token output",
273
- {
274
- outputIndex: i,
275
- value: finalOutput.withdrawBondSats,
276
- expected: expectedWithdrawBondSats,
277
- },
278
- );
279
- }
280
- }
281
-
282
- if (finalOutput.withdrawRelativeBlockLocktime !== undefined) {
283
- if (
284
- finalOutput.withdrawRelativeBlockLocktime !==
285
- expectedWithdrawRelativeBlockLocktime
286
- ) {
287
- throw new InternalValidationError(
288
- "Withdraw relative block locktime mismatch in token output",
289
- {
290
- outputIndex: i,
291
- value: finalOutput.withdrawRelativeBlockLocktime,
292
- expected: expectedWithdrawRelativeBlockLocktime,
293
- },
294
- );
295
- }
296
- }
297
-
298
- if (keyshareInfo.threshold !== expectedThreshold) {
299
- throw new InternalValidationError(
300
- "Threshold mismatch: expected " +
301
- expectedThreshold +
302
- " but got " +
303
- keyshareInfo.threshold,
304
- {
305
- field: "threshold",
306
- value: keyshareInfo.threshold,
307
- expected: expectedThreshold,
308
- },
309
- );
310
- }
311
- }
312
-
313
- if (
314
- keyshareInfo.ownerIdentifiers.length !==
315
- Object.keys(signingOperators).length
316
- ) {
317
- throw new InternalValidationError(
318
- `Keyshare operator count (${keyshareInfo.ownerIdentifiers.length}) does not match signing operator count (${Object.keys(signingOperators).length})`,
319
- {
320
- keyshareInfo: keyshareInfo.ownerIdentifiers.length,
321
- signingOperators: Object.keys(signingOperators).length,
322
- },
323
- );
324
- }
325
-
326
- if (hasDuplicates(keyshareInfo.ownerIdentifiers)) {
327
- throw new InternalValidationError(
328
- "Duplicate ownerIdentifiers found in keyshareInfo",
329
- {
330
- keyshareInfo: keyshareInfo.ownerIdentifiers,
331
- },
332
- );
333
- }
334
-
335
- for (const identifier of keyshareInfo.ownerIdentifiers) {
336
- if (!signingOperators[identifier]) {
337
- throw new InternalValidationError(
338
- `Keyshare operator ${identifier} not found in signing operator list`,
339
- {
340
- keyshareInfo: identifier,
341
- signingOperators: Object.keys(signingOperators),
342
- },
343
- );
344
- }
345
- }
346
- }
347
-
348
18
  export function validateTokenTransaction(
349
19
  finalTokenTransaction: TokenTransaction,
350
20
  partialTokenTransaction: TokenTransaction,