@buildonspark/spark-sdk 0.1.38 → 0.1.40

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 (104) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +1 -1
  3. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/arm64-v8a/libspark_frost.so +0 -0
  4. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/arm64-v8a/libuniffi_spark_frost.so +0 -0
  5. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/armeabi-v7a/libspark_frost.so +0 -0
  6. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/armeabi-v7a/libuniffi_spark_frost.so +0 -0
  7. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/x86/libspark_frost.so +0 -0
  8. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/x86/libuniffi_spark_frost.so +0 -0
  9. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/x86_64/libspark_frost.so +0 -0
  10. package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/x86_64/libuniffi_spark_frost.so +0 -0
  11. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/arm64-v8a/libspark_frost.so +0 -0
  12. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/arm64-v8a/libuniffi_spark_frost.so +0 -0
  13. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/armeabi-v7a/libspark_frost.so +0 -0
  14. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/armeabi-v7a/libuniffi_spark_frost.so +0 -0
  15. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/x86/libspark_frost.so +0 -0
  16. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/x86/libuniffi_spark_frost.so +0 -0
  17. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/x86_64/libspark_frost.so +0 -0
  18. package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/x86_64/libuniffi_spark_frost.so +0 -0
  19. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/arm64-v8a/libspark_frost.so +0 -0
  20. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/arm64-v8a/libuniffi_spark_frost.so +0 -0
  21. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/armeabi-v7a/libspark_frost.so +0 -0
  22. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/armeabi-v7a/libuniffi_spark_frost.so +0 -0
  23. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/x86/libspark_frost.so +0 -0
  24. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/x86/libuniffi_spark_frost.so +0 -0
  25. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/x86_64/libspark_frost.so +0 -0
  26. package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/x86_64/libuniffi_spark_frost.so +0 -0
  27. package/dist/{RequestLightningSendInput-B4JdzclX.d.ts → RequestLightningSendInput-CJtcHOnu.d.ts} +1 -1
  28. package/dist/{RequestLightningSendInput-39_zGri6.d.cts → RequestLightningSendInput-DfmfqzZo.d.cts} +1 -1
  29. package/dist/address/index.d.cts +1 -1
  30. package/dist/address/index.d.ts +1 -1
  31. package/dist/address/index.js +2 -2
  32. package/dist/{chunk-W3EC5XSA.js → chunk-5MNQB2T4.js} +2 -2
  33. package/dist/chunk-ED3ZAFDI.js +784 -0
  34. package/dist/{chunk-VJTDG4BQ.js → chunk-HK6LPV6Z.js} +10 -1
  35. package/dist/{chunk-7WRK6WNJ.js → chunk-LHT4QTFK.js} +556 -41
  36. package/dist/{chunk-RAPBVYJY.js → chunk-RFCXPGDM.js} +26 -4
  37. package/dist/{chunk-DI7QXUQJ.js → chunk-W2VXS35Y.js} +4 -4
  38. package/dist/graphql/objects/index.d.cts +5 -4
  39. package/dist/graphql/objects/index.d.ts +5 -4
  40. package/dist/{index-CxAi2L8y.d.ts → index-BDEYgYxP.d.ts} +42 -4
  41. package/dist/{index-Dm17Ggfe.d.cts → index-CLdtdMU4.d.cts} +42 -4
  42. package/dist/index.cjs +1069 -40
  43. package/dist/index.d.cts +6 -6
  44. package/dist/index.d.ts +6 -6
  45. package/dist/index.js +33 -17
  46. package/dist/index.node.cjs +1069 -40
  47. package/dist/index.node.d.cts +6 -6
  48. package/dist/index.node.d.ts +6 -6
  49. package/dist/index.node.js +33 -17
  50. package/dist/native/index.cjs +1069 -40
  51. package/dist/native/index.d.cts +108 -5
  52. package/dist/native/index.d.ts +108 -5
  53. package/dist/native/index.js +1065 -40
  54. package/dist/{network-GFGEHkS4.d.cts → network-B10hBoHp.d.cts} +8 -1
  55. package/dist/{network-DobHpaV6.d.ts → network-CCgyIsGl.d.ts} +8 -1
  56. package/dist/services/config.cjs +29 -12
  57. package/dist/services/config.d.cts +4 -4
  58. package/dist/services/config.d.ts +4 -4
  59. package/dist/services/config.js +5 -5
  60. package/dist/services/connection.d.cts +4 -4
  61. package/dist/services/connection.d.ts +4 -4
  62. package/dist/services/connection.js +2 -2
  63. package/dist/services/index.cjs +30 -13
  64. package/dist/services/index.d.cts +4 -4
  65. package/dist/services/index.d.ts +4 -4
  66. package/dist/services/index.js +8 -8
  67. package/dist/services/lrc-connection.d.cts +4 -4
  68. package/dist/services/lrc-connection.d.ts +4 -4
  69. package/dist/services/lrc-connection.js +1 -1
  70. package/dist/services/token-transactions.cjs +1 -1
  71. package/dist/services/token-transactions.d.cts +4 -4
  72. package/dist/services/token-transactions.d.ts +4 -4
  73. package/dist/services/token-transactions.js +3 -3
  74. package/dist/services/wallet-config.d.cts +4 -4
  75. package/dist/services/wallet-config.d.ts +4 -4
  76. package/dist/signer/signer.cjs +23 -6
  77. package/dist/signer/signer.d.cts +3 -2
  78. package/dist/signer/signer.d.ts +3 -2
  79. package/dist/signer/signer.js +1 -1
  80. package/dist/{signer-DFGw9RRp.d.ts → signer-C5h1DpjF.d.ts} +4 -1
  81. package/dist/{signer-C1t40Wus.d.cts → signer-CYwn7h9U.d.cts} +4 -1
  82. package/dist/types/index.d.cts +4 -3
  83. package/dist/types/index.d.ts +4 -3
  84. package/dist/utils/index.cjs +891 -2
  85. package/dist/utils/index.d.cts +62 -6
  86. package/dist/utils/index.d.ts +62 -6
  87. package/dist/utils/index.js +23 -7
  88. package/package.json +1 -1
  89. package/src/services/deposit.ts +23 -5
  90. package/src/services/token-transactions.ts +1 -1
  91. package/src/services/transfer.ts +218 -11
  92. package/src/services/tree-creation.ts +29 -14
  93. package/src/signer/signer.ts +47 -5
  94. package/src/spark-wallet/spark-wallet.ts +430 -4
  95. package/src/tests/integration/swap.test.ts +225 -0
  96. package/src/tests/integration/tree-creation.test.ts +5 -1
  97. package/src/utils/index.ts +1 -0
  98. package/src/utils/mempool.ts +26 -1
  99. package/src/utils/network.ts +15 -0
  100. package/src/utils/transaction.ts +22 -2
  101. package/src/utils/unilateral-exit.ts +729 -0
  102. package/dist/chunk-E5SL7XTO.js +0 -301
  103. package/dist/{chunk-LIP2K6KR.js → chunk-2CDJZQN4.js} +3 -3
  104. package/dist/{chunk-RGWBSZIO.js → chunk-I4JI6TYN.js} +4 -4
@@ -1,301 +0,0 @@
1
- import {
2
- getNetwork,
3
- getNetworkFromAddress
4
- } from "./chunk-VJTDG4BQ.js";
5
- import {
6
- ELECTRS_CREDENTIALS,
7
- getElectrsUrl
8
- } from "./chunk-ZUVYYR5T.js";
9
- import {
10
- BitcoinNetwork_default
11
- } from "./chunk-HMLOC6TE.js";
12
- import {
13
- ValidationError
14
- } from "./chunk-TWF35O6M.js";
15
-
16
- // src/utils/bitcoin.ts
17
- import {
18
- bytesToHex,
19
- bytesToNumberBE,
20
- hexToBytes
21
- } from "@noble/curves/abstract/utils";
22
- import { schnorr, secp256k1 } from "@noble/curves/secp256k1";
23
- import { sha256 } from "@noble/hashes/sha2";
24
- import * as btc from "@scure/btc-signer";
25
- function computeTaprootKeyNoScript(pubkey) {
26
- if (pubkey.length !== 32) {
27
- throw new ValidationError("Public key must be 32 bytes", {
28
- field: "pubkey",
29
- value: pubkey.length,
30
- expected: 32
31
- });
32
- }
33
- const taggedHash = schnorr.utils.taggedHash("TapTweak", pubkey);
34
- const tweak = bytesToNumberBE(taggedHash);
35
- const P = schnorr.utils.lift_x(schnorr.utils.bytesToNumberBE(pubkey));
36
- const Q = P.add(secp256k1.ProjectivePoint.fromPrivateKey(tweak));
37
- return Q.toRawBytes();
38
- }
39
- function getP2TRScriptFromPublicKey(pubKey, network) {
40
- if (pubKey.length !== 33) {
41
- throw new ValidationError("Public key must be 33 bytes", {
42
- field: "pubKey",
43
- value: pubKey.length,
44
- expected: 33
45
- });
46
- }
47
- const internalKey = secp256k1.ProjectivePoint.fromHex(pubKey);
48
- const script = btc.p2tr(
49
- internalKey.toRawBytes().slice(1, 33),
50
- void 0,
51
- getNetwork(network)
52
- ).script;
53
- if (!script) {
54
- throw new ValidationError("Failed to get P2TR script", {
55
- field: "script",
56
- value: "null"
57
- });
58
- }
59
- return script;
60
- }
61
- function getP2TRAddressFromPublicKey(pubKey, network) {
62
- if (pubKey.length !== 33) {
63
- throw new ValidationError("Public key must be 33 bytes", {
64
- field: "pubKey",
65
- value: pubKey.length,
66
- expected: 33
67
- });
68
- }
69
- const internalKey = secp256k1.ProjectivePoint.fromHex(pubKey);
70
- const address = btc.p2tr(
71
- internalKey.toRawBytes().slice(1, 33),
72
- void 0,
73
- getNetwork(network)
74
- ).address;
75
- if (!address) {
76
- throw new ValidationError("Failed to get P2TR address", {
77
- field: "address",
78
- value: "null"
79
- });
80
- }
81
- return address;
82
- }
83
- function getP2TRAddressFromPkScript(pkScript, network) {
84
- if (pkScript.length !== 34 || pkScript[0] !== 81 || pkScript[1] !== 32) {
85
- throw new ValidationError("Invalid pkscript", {
86
- field: "pkScript",
87
- value: bytesToHex(pkScript),
88
- expected: "34 bytes starting with 0x51 0x20"
89
- });
90
- }
91
- const parsedScript = btc.OutScript.decode(pkScript);
92
- return btc.Address(getNetwork(network)).encode(parsedScript);
93
- }
94
- function getP2WPKHAddressFromPublicKey(pubKey, network) {
95
- if (pubKey.length !== 33) {
96
- throw new ValidationError("Public key must be 33 bytes", {
97
- field: "pubKey",
98
- value: pubKey.length,
99
- expected: 33
100
- });
101
- }
102
- const address = btc.p2wpkh(pubKey, getNetwork(network)).address;
103
- if (!address) {
104
- throw new ValidationError("Failed to get P2WPKH address", {
105
- field: "address",
106
- value: "null"
107
- });
108
- }
109
- return address;
110
- }
111
- function getTxFromRawTxHex(rawTxHex) {
112
- const txBytes = hexToBytes(rawTxHex);
113
- const tx = btc.Transaction.fromRaw(txBytes, {
114
- allowUnknownOutputs: true
115
- });
116
- if (!tx) {
117
- throw new ValidationError("Failed to parse transaction", {
118
- field: "tx",
119
- value: "null"
120
- });
121
- }
122
- return tx;
123
- }
124
- function getTxFromRawTxBytes(rawTxBytes) {
125
- const tx = btc.Transaction.fromRaw(rawTxBytes, {
126
- allowUnknownOutputs: true
127
- });
128
- if (!tx) {
129
- throw new ValidationError("Failed to parse transaction", {
130
- field: "tx",
131
- value: "null"
132
- });
133
- }
134
- return tx;
135
- }
136
- function getSigHashFromTx(tx, inputIndex, prevOutput) {
137
- const prevScript = prevOutput.script;
138
- if (!prevScript) {
139
- throw new ValidationError("No script found in prevOutput", {
140
- field: "prevScript",
141
- value: "null"
142
- });
143
- }
144
- const amount = prevOutput.amount;
145
- if (!amount) {
146
- throw new ValidationError("No amount found in prevOutput", {
147
- field: "amount",
148
- value: "null"
149
- });
150
- }
151
- return tx.preimageWitnessV1(
152
- inputIndex,
153
- new Array(tx.inputsLength).fill(prevScript),
154
- btc.SigHash.DEFAULT,
155
- new Array(tx.inputsLength).fill(amount)
156
- );
157
- }
158
- function getTxId(tx) {
159
- return bytesToHex(sha256(sha256(tx.toBytes(true))).reverse());
160
- }
161
- function getTxIdNoReverse(tx) {
162
- return bytesToHex(sha256(sha256(tx.toBytes(true))));
163
- }
164
-
165
- // src/utils/mempool.ts
166
- async function getLatestDepositTxId(address) {
167
- const network = getNetworkFromAddress(address);
168
- const baseUrl = network === BitcoinNetwork_default.REGTEST ? getElectrsUrl("REGTEST") : getElectrsUrl("MAINNET");
169
- const headers = {};
170
- if (network === BitcoinNetwork_default.REGTEST) {
171
- const auth = btoa(
172
- `${ELECTRS_CREDENTIALS.username}:${ELECTRS_CREDENTIALS.password}`
173
- );
174
- headers["Authorization"] = `Basic ${auth}`;
175
- }
176
- const response = await fetch(`${baseUrl}/address/${address}/txs`, {
177
- headers
178
- });
179
- const addressTxs = await response.json();
180
- if (addressTxs && addressTxs.length > 0) {
181
- const latestTx = addressTxs[0];
182
- const outputIndex = latestTx.vout.findIndex(
183
- (output) => output.scriptpubkey_address === address
184
- );
185
- if (outputIndex === -1) {
186
- return null;
187
- }
188
- return latestTx.txid;
189
- }
190
- return null;
191
- }
192
-
193
- // src/utils/proof.ts
194
- import { sha256 as sha2562 } from "@noble/hashes/sha2";
195
- function proofOfPossessionMessageHashForDepositAddress(userPubkey, operatorPubkey, depositAddress) {
196
- const encoder = new TextEncoder();
197
- const depositAddressBytes = encoder.encode(depositAddress);
198
- const proofMsg = new Uint8Array([
199
- ...userPubkey,
200
- ...operatorPubkey,
201
- ...depositAddressBytes
202
- ]);
203
- return sha2562(proofMsg);
204
- }
205
-
206
- // src/utils/transfer_package.ts
207
- import { hexToBytes as hexToBytes2 } from "@noble/curves/abstract/utils";
208
- import { sha256 as sha2563 } from "@noble/hashes/sha2";
209
- function getTransferPackageSigningPayload(transferID, transferPackage) {
210
- const encryptedPayload = transferPackage.keyTweakPackage;
211
- const pairs = Object.entries(
212
- encryptedPayload
213
- ).map(([key, value]) => ({ key, value }));
214
- pairs.sort((a, b) => a.key.localeCompare(b.key));
215
- const encoder = new TextEncoder();
216
- let message = hexToBytes2(transferID.replaceAll("-", ""));
217
- for (const pair of pairs) {
218
- const keyPart = encoder.encode(pair.key + ":");
219
- const separator = encoder.encode(";");
220
- message = new Uint8Array([
221
- ...message,
222
- ...keyPart,
223
- ...pair.value,
224
- ...separator
225
- ]);
226
- }
227
- return sha2563(message);
228
- }
229
-
230
- // src/utils/transaction.ts
231
- import { Transaction as Transaction2 } from "@scure/btc-signer";
232
- var TIME_LOCK_INTERVAL = 100;
233
- function createRefundTx(sequence, nodeOutPoint, amountSats, receivingPubkey, network) {
234
- const newRefundTx = new Transaction2({ allowUnknownOutputs: true });
235
- newRefundTx.addInput({
236
- ...nodeOutPoint,
237
- sequence
238
- });
239
- const refundPkScript = getP2TRScriptFromPublicKey(receivingPubkey, network);
240
- newRefundTx.addOutput({
241
- script: refundPkScript,
242
- amount: amountSats
243
- });
244
- newRefundTx.addOutput(getEphemeralAnchorOutput());
245
- return newRefundTx;
246
- }
247
- function getCurrentTimelock(currSequence) {
248
- return (currSequence || 0) & 65535;
249
- }
250
- function getTransactionSequence(currSequence) {
251
- const timelock = getCurrentTimelock(currSequence);
252
- return 1 << 30 | timelock;
253
- }
254
- function getNextTransactionSequence(currSequence, forRefresh) {
255
- const currentTimelock = getCurrentTimelock(currSequence);
256
- const nextTimelock = currentTimelock - TIME_LOCK_INTERVAL;
257
- if (forRefresh && nextTimelock <= 100 && currentTimelock > 0) {
258
- return {
259
- nextSequence: 1 << 30 | nextTimelock,
260
- needRefresh: true
261
- };
262
- }
263
- if (nextTimelock <= 0) {
264
- throw new ValidationError("timelock interval is less than or equal to 0", {
265
- field: "nextTimelock",
266
- value: nextTimelock
267
- });
268
- }
269
- return {
270
- nextSequence: 1 << 30 | nextTimelock,
271
- needRefresh: nextTimelock <= 100
272
- };
273
- }
274
- function getEphemeralAnchorOutput() {
275
- return {
276
- script: new Uint8Array([81, 2, 78, 115]),
277
- // Pay-to-anchor (P2A) ephemeral anchor output
278
- amount: 0n
279
- };
280
- }
281
-
282
- export {
283
- computeTaprootKeyNoScript,
284
- getP2TRScriptFromPublicKey,
285
- getP2TRAddressFromPublicKey,
286
- getP2TRAddressFromPkScript,
287
- getP2WPKHAddressFromPublicKey,
288
- getTxFromRawTxHex,
289
- getTxFromRawTxBytes,
290
- getSigHashFromTx,
291
- getTxId,
292
- getTxIdNoReverse,
293
- createRefundTx,
294
- getCurrentTimelock,
295
- getTransactionSequence,
296
- getNextTransactionSequence,
297
- getEphemeralAnchorOutput,
298
- getTransferPackageSigningPayload,
299
- proofOfPossessionMessageHashForDepositAddress,
300
- getLatestDepositTxId
301
- };
@@ -1,9 +1,9 @@
1
- import {
2
- SparkAddress
3
- } from "./chunk-C5LTJBI7.js";
4
1
  import {
5
2
  ValidationError
6
3
  } from "./chunk-TWF35O6M.js";
4
+ import {
5
+ SparkAddress
6
+ } from "./chunk-C5LTJBI7.js";
7
7
 
8
8
  // src/address/address.ts
9
9
  import { secp256k1 } from "@noble/curves/secp256k1";
@@ -1,7 +1,3 @@
1
- import {
2
- Empty,
3
- SparkServiceDefinition
4
- } from "./chunk-C5LTJBI7.js";
5
1
  import {
6
2
  isBun,
7
3
  isReactNative
@@ -10,6 +6,10 @@ import {
10
6
  AuthenticationError,
11
7
  NetworkError
12
8
  } from "./chunk-TWF35O6M.js";
9
+ import {
10
+ Empty,
11
+ SparkServiceDefinition
12
+ } from "./chunk-C5LTJBI7.js";
13
13
 
14
14
  // src/services/connection.ts
15
15
  import { isNode } from "@lightsparkdev/core";