@buildonspark/spark-sdk 0.3.4 → 0.3.6
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.
- package/CHANGELOG.md +12 -0
- package/dist/bare/index.cjs +547 -1238
- package/dist/bare/index.d.cts +676 -79
- package/dist/bare/index.d.ts +676 -79
- package/dist/bare/index.js +543 -1058
- package/dist/chunk-EHKP3Y65.js +140 -0
- package/dist/chunk-FJ7LTA2O.js +605 -0
- package/dist/chunk-LIZFXQWK.js +7 -0
- package/dist/{chunk-KIQTO4FX.js → chunk-XPHYQ2L6.js} +8128 -8727
- package/dist/{client-DWml6sjL.d.cts → client-AHn11NHe.d.cts} +1 -1
- package/dist/{client-DBZ43pJT.d.ts → client-GOlkXliC.d.ts} +1 -1
- package/dist/debug.cjs +581 -1222
- package/dist/debug.d.cts +8 -8
- package/dist/debug.d.ts +8 -8
- package/dist/debug.js +5 -3
- package/dist/graphql/objects/index.d.cts +3 -3
- package/dist/graphql/objects/index.d.ts +3 -3
- package/dist/index.cjs +531 -1231
- package/dist/index.d.cts +7 -18
- package/dist/index.d.ts +7 -18
- package/dist/index.js +5 -4
- package/dist/index.node.cjs +1200 -1441
- package/dist/index.node.d.cts +6 -7
- package/dist/index.node.d.ts +6 -7
- package/dist/index.node.js +7 -66
- package/dist/{logging-BUpzk4Z6.d.cts → logging-CW3kwBaM.d.cts} +3 -3
- package/dist/{logging-Dt2ooQiP.d.ts → logging-D7ukPwRA.d.ts} +3 -3
- package/dist/native/{chunk-D3SZRO65.js → chunk-X2QXUON7.js} +15 -0
- package/dist/native/index.cjs +702 -1214
- package/dist/native/index.d.cts +1077 -477
- package/dist/native/index.d.ts +1077 -477
- package/dist/native/index.js +700 -1042
- package/dist/native/{wasm-KT5NZXRN.js → wasm-GKEDPGTM.js} +1 -2
- package/dist/proto/spark.d.cts +1 -1
- package/dist/proto/spark.d.ts +1 -1
- package/dist/proto/spark_token.d.cts +1 -1
- package/dist/proto/spark_token.d.ts +1 -1
- package/dist/{spark-DasxuVfm.d.cts → spark-WA_4wcBr.d.cts} +1 -1
- package/dist/{spark-DasxuVfm.d.ts → spark-WA_4wcBr.d.ts} +1 -1
- package/dist/{spark-wallet-jlC0XN5f.d.ts → spark-wallet-NxG55m7K.d.cts} +105 -74
- package/dist/{spark-wallet-BoMIOPWW.d.cts → spark-wallet-jwNvWvpK.d.ts} +105 -74
- package/dist/spark-wallet.browser-Cg4fB-Nm.d.ts +26 -0
- package/dist/spark-wallet.browser-Db7Y95Kt.d.cts +26 -0
- package/dist/spark-wallet.node-DB3ZqtJG.d.ts +90 -0
- package/dist/spark-wallet.node-HEG2ahNd.d.cts +90 -0
- package/dist/tests/test-utils.cjs +17560 -7615
- package/dist/tests/test-utils.d.cts +7 -21
- package/dist/tests/test-utils.d.ts +7 -21
- package/dist/tests/test-utils.js +30 -4
- package/dist/{token-transactions-DscJaJOE.d.ts → token-transactions-B2-BO7Oz.d.ts} +2 -2
- package/dist/{token-transactions-BDzCrQSk.d.cts → token-transactions-BAN68xwg.d.cts} +2 -2
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +7 -13
- package/src/bare/index.ts +1 -1
- package/src/debug.ts +1 -1
- package/src/index.node.ts +2 -1
- package/src/index.ts +2 -1
- package/src/native/index.ts +3 -2
- package/src/services/connection/connection.browser.ts +130 -0
- package/src/services/connection/connection.node.ts +158 -0
- package/src/services/{connection.ts → connection/connection.ts} +48 -259
- package/src/services/coop-exit.ts +3 -3
- package/src/services/deposit.ts +1 -1
- package/src/services/index.ts +1 -1
- package/src/services/lightning.ts +1 -1
- package/src/services/token-transactions.ts +1 -1
- package/src/services/transfer.ts +1 -1
- package/src/spark-wallet/spark-wallet.bare.ts +12 -0
- package/src/spark-wallet/spark-wallet.browser.ts +10 -24
- package/src/spark-wallet/spark-wallet.node.ts +4 -24
- package/src/spark-wallet/spark-wallet.react-native.ts +15 -0
- package/src/spark-wallet/spark-wallet.ts +87 -75
- package/src/spark-wallet/types.ts +4 -2
- package/src/tests/integration/coop-exit.test.ts +3 -3
- package/src/tests/integration/lightning.test.ts +4 -4
- package/src/tests/integration/ssp/coop-exit-validation.test.ts +3 -5
- package/src/tests/integration/ssp/coop-exit.test.ts +3 -5
- package/src/tests/integration/ssp/lightning.test.ts +1 -1
- package/src/tests/integration/ssp/static-deposit-validation.test.ts +2 -2
- package/src/tests/integration/ssp/static_deposit.test.ts +49 -66
- package/src/tests/integration/ssp/swap.test.ts +4 -5
- package/src/tests/integration/ssp/transfers.test.ts +10 -11
- package/src/tests/integration/static_deposit.test.ts +4 -4
- package/src/tests/integration/token-output.test.ts +2 -2
- package/src/tests/integration/transfer.test.ts +30 -26
- package/src/tests/integration/watchtower.test.ts +3 -3
- package/src/tests/spark-wallet/queryNodes.test.ts +1 -2
- package/src/tests/test-utils.ts +3 -3
- package/src/tests/token-outputs.test.ts +1 -1
- package/src/tests/utils/spark-testing-wallet.ts +18 -58
- package/src/tests/utils/utils.ts +63 -0
- package/src/tests/wrapWithOtelSpan.test.ts +7 -0
- package/src/utils/network.ts +11 -10
- package/dist/bare/xhr-transport-EEEC7FYA.js +0 -165
- package/dist/chunk-YH7MDVTT.js +0 -70
- package/dist/native/chunk-C3WN3D4O.js +0 -19
- package/dist/native/xhr-transport-TNCG4HTW.js +0 -168
- package/dist/spark-wallet.node-07PksUHH.d.cts +0 -12
- package/dist/spark-wallet.node-CdWkKMSq.d.ts +0 -12
- package/dist/xhr-transport-IWJPYF7F.js +0 -167
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
} from "../proto/spark.js";
|
|
52
52
|
import { QueryTokenTransactionsResponse } from "../proto/spark_token.js";
|
|
53
53
|
import { WalletConfigService } from "../services/config.js";
|
|
54
|
-
import { ConnectionManager } from "../services/connection.js";
|
|
54
|
+
import { ConnectionManager } from "../services/connection/connection.js";
|
|
55
55
|
import { CoopExitService } from "../services/coop-exit.js";
|
|
56
56
|
import { DepositService } from "../services/deposit.js";
|
|
57
57
|
import { LightningService } from "../services/lightning.js";
|
|
@@ -157,7 +157,7 @@ import { SparkWalletEvent } from "./types.js";
|
|
|
157
157
|
* It provides methods for creating and managing wallets, handling deposits, executing transfers,
|
|
158
158
|
* and interacting with the Lightning Network.
|
|
159
159
|
*/
|
|
160
|
-
export class SparkWallet extends EventEmitter<SparkWalletEvents> {
|
|
160
|
+
export abstract class SparkWallet extends EventEmitter<SparkWalletEvents> {
|
|
161
161
|
protected config: WalletConfigService;
|
|
162
162
|
|
|
163
163
|
protected connectionManager: ConnectionManager;
|
|
@@ -193,11 +193,11 @@ export class SparkWallet extends EventEmitter<SparkWalletEvents> {
|
|
|
193
193
|
|
|
194
194
|
private tracer: Tracer | null = null;
|
|
195
195
|
|
|
196
|
-
|
|
196
|
+
constructor(options?: ConfigOptions, signer?: SparkSigner) {
|
|
197
197
|
super();
|
|
198
198
|
|
|
199
199
|
this.config = new WalletConfigService(options, signer);
|
|
200
|
-
this.connectionManager =
|
|
200
|
+
this.connectionManager = this.buildConnectionManager(this.config);
|
|
201
201
|
this.signingService = new SigningService(this.config);
|
|
202
202
|
this.depositService = new DepositService(
|
|
203
203
|
this.config,
|
|
@@ -225,34 +225,23 @@ export class SparkWallet extends EventEmitter<SparkWalletEvents> {
|
|
|
225
225
|
|
|
226
226
|
this.tracer = trace.getTracer(this.tracerId);
|
|
227
227
|
this.wrapSparkWalletMethodsWithTracing();
|
|
228
|
+
this.initializeTracer(this);
|
|
228
229
|
}
|
|
229
230
|
|
|
230
|
-
public static async initialize(
|
|
231
|
-
|
|
232
|
-
accountNumber,
|
|
233
|
-
|
|
234
|
-
options,
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
return {
|
|
243
|
-
wallet,
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const initResponse = await wallet.initWallet(mnemonicOrSeed, accountNumber);
|
|
248
|
-
|
|
249
|
-
return {
|
|
250
|
-
wallet,
|
|
251
|
-
...initResponse,
|
|
252
|
-
};
|
|
231
|
+
public static async initialize<T extends SparkWallet>(
|
|
232
|
+
this: new (options?: ConfigOptions, signer?: SparkSigner) => T,
|
|
233
|
+
{ mnemonicOrSeed, accountNumber, signer, options = {} }: SparkWalletProps,
|
|
234
|
+
): Promise<InitWalletResponse<T>> {
|
|
235
|
+
const wallet = new this(options, signer);
|
|
236
|
+
const initWalletResponse = await wallet.initWallet(
|
|
237
|
+
mnemonicOrSeed,
|
|
238
|
+
accountNumber,
|
|
239
|
+
options,
|
|
240
|
+
);
|
|
241
|
+
return initWalletResponse as InitWalletResponse<T>;
|
|
253
242
|
}
|
|
254
243
|
|
|
255
|
-
private async
|
|
244
|
+
private async createClientsAndSyncWallet() {
|
|
256
245
|
this.sspClient = new SspClient(this.config);
|
|
257
246
|
await this.connectionManager.createClients();
|
|
258
247
|
|
|
@@ -274,6 +263,10 @@ export class SparkWallet extends EventEmitter<SparkWalletEvents> {
|
|
|
274
263
|
return this.sspClient;
|
|
275
264
|
}
|
|
276
265
|
|
|
266
|
+
protected buildConnectionManager(config: WalletConfigService) {
|
|
267
|
+
return new ConnectionManager(config);
|
|
268
|
+
}
|
|
269
|
+
|
|
277
270
|
private async handleStreamEvent({ event }: SubscribeToEventsResponse) {
|
|
278
271
|
try {
|
|
279
272
|
if (
|
|
@@ -880,14 +873,22 @@ export class SparkWallet extends EventEmitter<SparkWalletEvents> {
|
|
|
880
873
|
*
|
|
881
874
|
* @returns {Promise<Object>} Object containing:
|
|
882
875
|
* - mnemonic: The mnemonic if one was generated (undefined for raw seed)
|
|
883
|
-
* -
|
|
884
|
-
* - tokenBalance: Map of token balances
|
|
876
|
+
* - wallet: The wallet instance
|
|
885
877
|
* @private
|
|
886
878
|
*/
|
|
887
879
|
protected async initWallet(
|
|
888
880
|
mnemonicOrSeed?: Uint8Array | string,
|
|
889
881
|
accountNumber?: number,
|
|
890
|
-
|
|
882
|
+
options: ConfigOptions = {},
|
|
883
|
+
): Promise<InitWalletResponse<this>> {
|
|
884
|
+
if (options.signerWithPreExistingKeys) {
|
|
885
|
+
await this.initWalletWithoutSeed();
|
|
886
|
+
return {
|
|
887
|
+
wallet: this,
|
|
888
|
+
mnemonic: undefined,
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
|
|
891
892
|
if (accountNumber === undefined) {
|
|
892
893
|
if (this.config.getNetwork() === Network.REGTEST) {
|
|
893
894
|
accountNumber = 0;
|
|
@@ -917,6 +918,7 @@ export class SparkWallet extends EventEmitter<SparkWalletEvents> {
|
|
|
917
918
|
|
|
918
919
|
return {
|
|
919
920
|
mnemonic,
|
|
921
|
+
wallet: this,
|
|
920
922
|
};
|
|
921
923
|
}
|
|
922
924
|
|
|
@@ -925,7 +927,7 @@ export class SparkWallet extends EventEmitter<SparkWalletEvents> {
|
|
|
925
927
|
* @private
|
|
926
928
|
*/
|
|
927
929
|
protected async initWalletWithoutSeed() {
|
|
928
|
-
await this.
|
|
930
|
+
await this.createClientsAndSyncWallet();
|
|
929
931
|
|
|
930
932
|
const identityPublicKey = await this.config.signer.getIdentityPublicKey();
|
|
931
933
|
|
|
@@ -957,7 +959,7 @@ export class SparkWallet extends EventEmitter<SparkWalletEvents> {
|
|
|
957
959
|
) {
|
|
958
960
|
const identityPublicKey =
|
|
959
961
|
await this.config.signer.createSparkWalletFromSeed(seed, accountNumber);
|
|
960
|
-
await this.
|
|
962
|
+
await this.createClientsAndSyncWallet();
|
|
961
963
|
|
|
962
964
|
this.sparkAddress = encodeSparkAddress({
|
|
963
965
|
identityPublicKey: identityPublicKey,
|
|
@@ -2708,7 +2710,7 @@ export class SparkWallet extends EventEmitter<SparkWalletEvents> {
|
|
|
2708
2710
|
amountSatsArray.push(amountSats);
|
|
2709
2711
|
}
|
|
2710
2712
|
|
|
2711
|
-
|
|
2713
|
+
return await this.withLeaves(async () => {
|
|
2712
2714
|
const selectLeavesToSendMap: Map<number, TreeNode[][]> =
|
|
2713
2715
|
await this.selectLeaves(amountSatsArray);
|
|
2714
2716
|
|
|
@@ -2751,50 +2753,49 @@ export class SparkWallet extends EventEmitter<SparkWalletEvents> {
|
|
|
2751
2753
|
this.leaves = this.leaves.filter((leaf) => !idsToRemove.has(leaf.id));
|
|
2752
2754
|
}
|
|
2753
2755
|
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
+
const signerIdentityPublicKey =
|
|
2757
|
+
await this.config.signer.getIdentityPublicKey();
|
|
2756
2758
|
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
signerIdentityPublicKey,
|
|
2770
|
-
job.receiverIdentityPubkey,
|
|
2771
|
-
);
|
|
2772
|
-
if (isSelfTransfer) {
|
|
2773
|
-
const pending = await this.transferService.queryTransfer(
|
|
2774
|
-
transfer.id,
|
|
2759
|
+
const outcomes = await Promise.all(
|
|
2760
|
+
jobs.map(async (job) => {
|
|
2761
|
+
try {
|
|
2762
|
+
const transfer =
|
|
2763
|
+
await this.transferService.sendTransferWithKeyTweaks(
|
|
2764
|
+
job.leafKeyTweaks,
|
|
2765
|
+
job.receiverIdentityPubkey,
|
|
2766
|
+
job.sparkInvoice,
|
|
2767
|
+
);
|
|
2768
|
+
const isSelfTransfer = equalBytes(
|
|
2769
|
+
signerIdentityPublicKey,
|
|
2770
|
+
job.receiverIdentityPubkey,
|
|
2775
2771
|
);
|
|
2776
|
-
if (
|
|
2777
|
-
await this.
|
|
2772
|
+
if (isSelfTransfer) {
|
|
2773
|
+
const pending = await this.transferService.queryTransfer(
|
|
2774
|
+
transfer.id,
|
|
2775
|
+
);
|
|
2776
|
+
if (pending) {
|
|
2777
|
+
await this.claimTransfer({ transfer: pending, optimize: true });
|
|
2778
|
+
}
|
|
2778
2779
|
}
|
|
2780
|
+
return {
|
|
2781
|
+
ok: true as const,
|
|
2782
|
+
transfer: mapTransferToWalletTransfer(
|
|
2783
|
+
transfer,
|
|
2784
|
+
bytesToHex(await this.config.signer.getIdentityPublicKey()),
|
|
2785
|
+
),
|
|
2786
|
+
param: job.param,
|
|
2787
|
+
};
|
|
2788
|
+
} catch (error) {
|
|
2789
|
+
return {
|
|
2790
|
+
ok: false as const,
|
|
2791
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
2792
|
+
param: job.param,
|
|
2793
|
+
};
|
|
2779
2794
|
}
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
bytesToHex(await this.config.signer.getIdentityPublicKey()),
|
|
2785
|
-
),
|
|
2786
|
-
param: job.param,
|
|
2787
|
-
};
|
|
2788
|
-
} catch (error) {
|
|
2789
|
-
return {
|
|
2790
|
-
ok: false as const,
|
|
2791
|
-
error: error instanceof Error ? error : new Error(String(error)),
|
|
2792
|
-
param: job.param,
|
|
2793
|
-
};
|
|
2794
|
-
}
|
|
2795
|
-
}),
|
|
2796
|
-
);
|
|
2797
|
-
return outcomes;
|
|
2795
|
+
}),
|
|
2796
|
+
);
|
|
2797
|
+
return outcomes;
|
|
2798
|
+
});
|
|
2798
2799
|
}
|
|
2799
2800
|
|
|
2800
2801
|
private buildTweaksByAmount(
|
|
@@ -3289,7 +3290,18 @@ export class SparkWallet extends EventEmitter<SparkWalletEvents> {
|
|
|
3289
3290
|
});
|
|
3290
3291
|
}
|
|
3291
3292
|
|
|
3292
|
-
if (decodedInvoice.amountMSats
|
|
3293
|
+
if (decodedInvoice.amountMSats === null && amountSats !== 0) {
|
|
3294
|
+
throw new ValidationError("Amount mismatch", {
|
|
3295
|
+
field: "amountMSats",
|
|
3296
|
+
value: "null",
|
|
3297
|
+
expected: amountSats * 1000,
|
|
3298
|
+
});
|
|
3299
|
+
}
|
|
3300
|
+
|
|
3301
|
+
if (
|
|
3302
|
+
decodedInvoice.amountMSats !== null &&
|
|
3303
|
+
decodedInvoice.amountMSats !== BigInt(amountSats * 1000)
|
|
3304
|
+
) {
|
|
3293
3305
|
throw new ValidationError("Amount mismatch", {
|
|
3294
3306
|
field: "amountMSats",
|
|
3295
3307
|
value: decodedInvoice.amountMSats,
|
|
@@ -7,6 +7,7 @@ import { KeyDerivation } from "../signer/types.js";
|
|
|
7
7
|
import { Bech32mTokenIdentifier } from "../utils/token-identifier.js";
|
|
8
8
|
import { SparkAddressFormat } from "../utils/address.js";
|
|
9
9
|
import { WalletTransfer } from "../types/index.js";
|
|
10
|
+
import type { SparkWallet } from "./spark-wallet.js";
|
|
10
11
|
|
|
11
12
|
export type CreateLightningInvoiceParams = {
|
|
12
13
|
amountSats: number;
|
|
@@ -140,8 +141,9 @@ export type TokenOutputsMap = Map<
|
|
|
140
141
|
|
|
141
142
|
export type TokenMetadataMap = Map<Bech32mTokenIdentifier, TokenMetadata>;
|
|
142
143
|
|
|
143
|
-
export type InitWalletResponse = {
|
|
144
|
-
|
|
144
|
+
export type InitWalletResponse<T extends SparkWallet = SparkWallet> = {
|
|
145
|
+
wallet: T;
|
|
146
|
+
mnemonic: string | undefined;
|
|
145
147
|
};
|
|
146
148
|
export interface SparkWalletProps {
|
|
147
149
|
mnemonicOrSeed?: Uint8Array | string;
|
|
@@ -6,7 +6,7 @@ import { TransactionInput } from "@scure/btc-signer/psbt";
|
|
|
6
6
|
import { equalBytes } from "@scure/btc-signer/utils";
|
|
7
7
|
import { uuidv7 } from "uuidv7";
|
|
8
8
|
import { WalletConfigService } from "../../services/config.js";
|
|
9
|
-
import {
|
|
9
|
+
import { ConnectionManagerNodeJS } from "../../services/connection/connection.node.js";
|
|
10
10
|
import { CoopExitService } from "../../services/coop-exit.js";
|
|
11
11
|
import { SigningService } from "../../services/signing.js";
|
|
12
12
|
import type { LeafKeyTweak } from "../../services/transfer.js";
|
|
@@ -47,7 +47,7 @@ describe.each(walletTypes)("coop exit", ({ name, Signer, createTree }) => {
|
|
|
47
47
|
options,
|
|
48
48
|
userWallet.getSigner(),
|
|
49
49
|
);
|
|
50
|
-
const connectionManager = new
|
|
50
|
+
const connectionManager = new ConnectionManagerNodeJS(configService);
|
|
51
51
|
const signingService = new SigningService(configService);
|
|
52
52
|
const coopExitService = new CoopExitService(
|
|
53
53
|
configService,
|
|
@@ -69,7 +69,7 @@ describe.each(walletTypes)("coop exit", ({ name, Signer, createTree }) => {
|
|
|
69
69
|
options,
|
|
70
70
|
sspWallet.getSigner(),
|
|
71
71
|
);
|
|
72
|
-
const sspConnectionManager = new
|
|
72
|
+
const sspConnectionManager = new ConnectionManagerNodeJS(sspConfigService);
|
|
73
73
|
const sspSigningService = new SigningService(sspConfigService);
|
|
74
74
|
const sspTransferService = new TransferService(
|
|
75
75
|
sspConfigService,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "../../index.js";
|
|
12
12
|
import { TransferStatus } from "../../proto/spark.js";
|
|
13
13
|
import { WalletConfigService } from "../../services/config.js";
|
|
14
|
-
import {
|
|
14
|
+
import { ConnectionManagerNodeJS } from "../../services/connection/connection.node.js";
|
|
15
15
|
import { LightningService } from "../../services/lightning.js";
|
|
16
16
|
import { SigningService } from "../../services/signing.js";
|
|
17
17
|
import type { LeafKeyTweak } from "../../services/transfer.js";
|
|
@@ -34,7 +34,7 @@ async function cleanUp() {
|
|
|
34
34
|
const paymentHash = sha256(preimage);
|
|
35
35
|
|
|
36
36
|
const configService = new WalletConfigService(config);
|
|
37
|
-
const connectionManager = new
|
|
37
|
+
const connectionManager = new ConnectionManagerNodeJS(configService);
|
|
38
38
|
for (const operator of Object.values(config.signingOperators!)) {
|
|
39
39
|
const client = await connectionManager.createMockClient(operator!.address);
|
|
40
40
|
await client.clean_up_preimage_share({
|
|
@@ -108,7 +108,7 @@ describe.each(walletTypes)(
|
|
|
108
108
|
},
|
|
109
109
|
userWallet.getSigner(),
|
|
110
110
|
);
|
|
111
|
-
const connectionManager = new
|
|
111
|
+
const connectionManager = new ConnectionManagerNodeJS(userConfig);
|
|
112
112
|
signingService = new SigningService(userConfig);
|
|
113
113
|
lightningService = new LightningService(
|
|
114
114
|
userConfig,
|
|
@@ -136,7 +136,7 @@ describe.each(walletTypes)(
|
|
|
136
136
|
},
|
|
137
137
|
sspWallet.getSigner(),
|
|
138
138
|
);
|
|
139
|
-
const sspConnectionManager = new
|
|
139
|
+
const sspConnectionManager = new ConnectionManagerNodeJS(sspConfig);
|
|
140
140
|
sspSigningService = new SigningService(sspConfig);
|
|
141
141
|
sspLightningService = new LightningService(
|
|
142
142
|
sspConfig,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Transaction } from "@scure/btc-signer";
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
initTestingWallet,
|
|
4
4
|
SparkWalletTesting,
|
|
5
5
|
} from "../../utils/spark-testing-wallet.js";
|
|
6
6
|
import { expect } from "@jest/globals";
|
|
@@ -16,10 +16,8 @@ describe("SSP coop exit basic validation", () => {
|
|
|
16
16
|
let quoteAmount: number;
|
|
17
17
|
|
|
18
18
|
beforeAll(async () => {
|
|
19
|
-
const { wallet, depositAddress, signedTx, vout, faucet } =
|
|
20
|
-
DEPOSIT_AMOUNT,
|
|
21
|
-
"LOCAL",
|
|
22
|
-
);
|
|
19
|
+
const { wallet, depositAddress, signedTx, vout, faucet } =
|
|
20
|
+
await initTestingWallet(DEPOSIT_AMOUNT, "LOCAL");
|
|
23
21
|
|
|
24
22
|
// Wait for the transaction to be mined
|
|
25
23
|
await new Promise((resolve) => setTimeout(resolve, 30000));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from "@jest/globals";
|
|
2
2
|
import { ExitSpeed } from "../../../types/index.js";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
initTestingWallet,
|
|
5
5
|
SparkWalletTesting,
|
|
6
6
|
} from "../../utils/spark-testing-wallet.js";
|
|
7
7
|
import { getNewAddress } from "../../utils/regtest-test-faucet.js";
|
|
@@ -15,10 +15,8 @@ describe("SSP coop exit integration", () => {
|
|
|
15
15
|
let quoteAmount: number;
|
|
16
16
|
|
|
17
17
|
beforeEach(async () => {
|
|
18
|
-
const { wallet, depositAddress, signedTx, vout, faucet } =
|
|
19
|
-
DEPOSIT_AMOUNT,
|
|
20
|
-
"LOCAL",
|
|
21
|
-
);
|
|
18
|
+
const { wallet, depositAddress, signedTx, vout, faucet } =
|
|
19
|
+
await initTestingWallet(DEPOSIT_AMOUNT, "LOCAL");
|
|
22
20
|
|
|
23
21
|
// Wait for the transaction to be mined
|
|
24
22
|
await new Promise((resolve) => setTimeout(resolve, 30000));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from "@jest/globals";
|
|
2
2
|
import { ConfigOptions } from "../../../services/wallet-config.js";
|
|
3
|
-
import { SparkWallet } from "../../../spark-wallet/spark-wallet.js";
|
|
3
|
+
import { SparkWallet } from "../../../spark-wallet/spark-wallet.node.js";
|
|
4
4
|
import {
|
|
5
5
|
BitcoinNetwork,
|
|
6
6
|
CurrencyUnit,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
initTestingWallet,
|
|
3
3
|
SparkWalletTesting,
|
|
4
4
|
} from "../../utils/spark-testing-wallet.js";
|
|
5
5
|
import { sha256 } from "@noble/hashes/sha2";
|
|
@@ -60,7 +60,7 @@ describe("SSP static deposit validation tests", () => {
|
|
|
60
60
|
signedTx,
|
|
61
61
|
vout,
|
|
62
62
|
faucet,
|
|
63
|
-
} = await
|
|
63
|
+
} = await initTestingWallet(DEPOSIT_AMOUNT, "LOCAL");
|
|
64
64
|
|
|
65
65
|
await new Promise((resolve) => setTimeout(resolve, 30000));
|
|
66
66
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
SparkWalletTestingWithStream,
|
|
3
|
+
initTestingWallet,
|
|
4
4
|
} from "../../utils/spark-testing-wallet.js";
|
|
5
5
|
import { bytesToHex } from "@noble/hashes/utils";
|
|
6
6
|
import { BitcoinFaucet } from "../../utils/test-faucet.js";
|
|
7
|
+
import { retryUntilSuccess, waitForClaim } from "../../utils/utils.js";
|
|
7
8
|
|
|
8
9
|
export const DEPOSIT_AMOUNT = 10000n;
|
|
9
10
|
const SECOND_DEPOSIT_AMOUNT = 20000n;
|
|
@@ -13,14 +14,12 @@ describe("SSP static deposit address integration", () => {
|
|
|
13
14
|
describe("Happy path testing", () => {
|
|
14
15
|
it("should claim deposits to a static deposit address", async () => {
|
|
15
16
|
const faucet = BitcoinFaucet.getInstance();
|
|
16
|
-
const { wallet: userWallet } =
|
|
17
|
-
{
|
|
17
|
+
const { wallet: userWallet } =
|
|
18
|
+
await SparkWalletTestingWithStream.initialize({
|
|
18
19
|
options: {
|
|
19
20
|
network: "LOCAL",
|
|
20
21
|
},
|
|
21
|
-
}
|
|
22
|
-
false,
|
|
23
|
-
);
|
|
22
|
+
});
|
|
24
23
|
|
|
25
24
|
const depositAddress = await userWallet.getStaticDepositAddress();
|
|
26
25
|
expect(depositAddress).toBeDefined();
|
|
@@ -111,14 +110,12 @@ describe("SSP static deposit address integration", () => {
|
|
|
111
110
|
it("should create a refund transaction", async () => {
|
|
112
111
|
const faucet = BitcoinFaucet.getInstance();
|
|
113
112
|
|
|
114
|
-
const { wallet: userWallet } =
|
|
115
|
-
{
|
|
113
|
+
const { wallet: userWallet } =
|
|
114
|
+
await SparkWalletTestingWithStream.initialize({
|
|
116
115
|
options: {
|
|
117
116
|
network: "LOCAL",
|
|
118
117
|
},
|
|
119
|
-
}
|
|
120
|
-
false,
|
|
121
|
-
);
|
|
118
|
+
});
|
|
122
119
|
|
|
123
120
|
const depositAddress = await userWallet.getStaticDepositAddress();
|
|
124
121
|
expect(depositAddress).toBeDefined();
|
|
@@ -147,11 +144,15 @@ describe("SSP static deposit address integration", () => {
|
|
|
147
144
|
|
|
148
145
|
const refundAddress = await faucet.getNewAddress();
|
|
149
146
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
147
|
+
// Chainwatcher needs to catch up. Could take a few seconds so retry until success.
|
|
148
|
+
const refundTx = await retryUntilSuccess(
|
|
149
|
+
async () =>
|
|
150
|
+
await userWallet.refundStaticDeposit({
|
|
151
|
+
depositTransactionId: transactionId,
|
|
152
|
+
destinationAddress: refundAddress,
|
|
153
|
+
satsPerVbyteFee: 2,
|
|
154
|
+
}),
|
|
155
|
+
);
|
|
155
156
|
|
|
156
157
|
expect(refundTx).toBeDefined();
|
|
157
158
|
|
|
@@ -170,14 +171,12 @@ describe("SSP static deposit address integration", () => {
|
|
|
170
171
|
|
|
171
172
|
it("should return the right amount of txns when querying for utxos sent to a static deposit address", async () => {
|
|
172
173
|
const faucet = BitcoinFaucet.getInstance();
|
|
173
|
-
const { wallet: userWallet } =
|
|
174
|
-
{
|
|
174
|
+
const { wallet: userWallet } =
|
|
175
|
+
await SparkWalletTestingWithStream.initialize({
|
|
175
176
|
options: {
|
|
176
177
|
network: "LOCAL",
|
|
177
178
|
},
|
|
178
|
-
}
|
|
179
|
-
false,
|
|
180
|
-
);
|
|
179
|
+
});
|
|
181
180
|
|
|
182
181
|
const depositAddress = await userWallet.getStaticDepositAddress();
|
|
183
182
|
expect(depositAddress).toBeDefined();
|
|
@@ -301,25 +300,19 @@ describe("SSP static deposit address integration", () => {
|
|
|
301
300
|
it("Wallet balance should be correct after concurrent claims of the same wallet initted in different places", async () => {
|
|
302
301
|
const faucet = BitcoinFaucet.getInstance();
|
|
303
302
|
const { wallet: aliceWallet, mnemonic: aliceMnemonic } =
|
|
304
|
-
await
|
|
305
|
-
{
|
|
306
|
-
|
|
307
|
-
network: "LOCAL",
|
|
308
|
-
},
|
|
303
|
+
await SparkWalletTestingWithStream.initialize({
|
|
304
|
+
options: {
|
|
305
|
+
network: "LOCAL",
|
|
309
306
|
},
|
|
310
|
-
|
|
311
|
-
);
|
|
307
|
+
});
|
|
312
308
|
|
|
313
309
|
const { wallet: aliceWallet2, mnemonic: aliceMnemonic2 } =
|
|
314
|
-
await
|
|
315
|
-
{
|
|
316
|
-
|
|
317
|
-
network: "LOCAL",
|
|
318
|
-
},
|
|
319
|
-
mnemonicOrSeed: aliceMnemonic,
|
|
310
|
+
await SparkWalletTestingWithStream.initialize({
|
|
311
|
+
options: {
|
|
312
|
+
network: "LOCAL",
|
|
320
313
|
},
|
|
321
|
-
|
|
322
|
-
);
|
|
314
|
+
mnemonicOrSeed: aliceMnemonic,
|
|
315
|
+
});
|
|
323
316
|
|
|
324
317
|
expect(aliceMnemonic).toEqual(aliceMnemonic2);
|
|
325
318
|
|
|
@@ -368,7 +361,7 @@ describe("SSP static deposit address integration", () => {
|
|
|
368
361
|
expect(successes).toHaveLength(1);
|
|
369
362
|
expect(failures).toHaveLength(1);
|
|
370
363
|
|
|
371
|
-
await
|
|
364
|
+
await waitForClaim({ wallet: aliceWallet });
|
|
372
365
|
|
|
373
366
|
const { balance: aliceBalance } = await aliceWallet.getBalance();
|
|
374
367
|
const { balance: alice2Balance } = await aliceWallet2.getBalance();
|
|
@@ -381,14 +374,12 @@ describe("SSP static deposit address integration", () => {
|
|
|
381
374
|
|
|
382
375
|
it("Wallet balance should be correct after concurrent claims of the same initted wallet", async () => {
|
|
383
376
|
const faucet = BitcoinFaucet.getInstance();
|
|
384
|
-
const { wallet: aliceWallet } =
|
|
385
|
-
{
|
|
377
|
+
const { wallet: aliceWallet } =
|
|
378
|
+
await SparkWalletTestingWithStream.initialize({
|
|
386
379
|
options: {
|
|
387
380
|
network: "LOCAL",
|
|
388
381
|
},
|
|
389
|
-
}
|
|
390
|
-
false,
|
|
391
|
-
);
|
|
382
|
+
});
|
|
392
383
|
|
|
393
384
|
const depositAddress = await aliceWallet.getStaticDepositAddress();
|
|
394
385
|
|
|
@@ -442,23 +433,19 @@ describe("SSP static deposit address integration", () => {
|
|
|
442
433
|
|
|
443
434
|
describe("Quote unhappy path testing", () => {
|
|
444
435
|
it("should error claim quote from a different wallet", async () => {
|
|
445
|
-
const { wallet: aliceWallet } =
|
|
446
|
-
{
|
|
436
|
+
const { wallet: aliceWallet } =
|
|
437
|
+
await SparkWalletTestingWithStream.initialize({
|
|
447
438
|
options: {
|
|
448
439
|
network: "LOCAL",
|
|
449
440
|
},
|
|
450
|
-
}
|
|
451
|
-
false,
|
|
452
|
-
);
|
|
441
|
+
});
|
|
453
442
|
|
|
454
|
-
const { wallet: bobWallet } =
|
|
455
|
-
{
|
|
443
|
+
const { wallet: bobWallet } =
|
|
444
|
+
await SparkWalletTestingWithStream.initialize({
|
|
456
445
|
options: {
|
|
457
446
|
network: "LOCAL",
|
|
458
447
|
},
|
|
459
|
-
}
|
|
460
|
-
false,
|
|
461
|
-
);
|
|
448
|
+
});
|
|
462
449
|
|
|
463
450
|
const faucet = BitcoinFaucet.getInstance();
|
|
464
451
|
|
|
@@ -483,14 +470,12 @@ describe("SSP static deposit address integration", () => {
|
|
|
483
470
|
}, 60000);
|
|
484
471
|
|
|
485
472
|
it("should error if txid does not exist", async () => {
|
|
486
|
-
const { wallet: aliceWallet } =
|
|
487
|
-
{
|
|
473
|
+
const { wallet: aliceWallet } =
|
|
474
|
+
await SparkWalletTestingWithStream.initialize({
|
|
488
475
|
options: {
|
|
489
476
|
network: "LOCAL",
|
|
490
477
|
},
|
|
491
|
-
}
|
|
492
|
-
false,
|
|
493
|
-
);
|
|
478
|
+
});
|
|
494
479
|
|
|
495
480
|
const faucet = BitcoinFaucet.getInstance();
|
|
496
481
|
|
|
@@ -517,14 +502,12 @@ describe("SSP static deposit address integration", () => {
|
|
|
517
502
|
});
|
|
518
503
|
|
|
519
504
|
it("should error claim quote if tx already claimed", async () => {
|
|
520
|
-
const { wallet: aliceWallet } =
|
|
521
|
-
{
|
|
505
|
+
const { wallet: aliceWallet } =
|
|
506
|
+
await SparkWalletTestingWithStream.initialize({
|
|
522
507
|
options: {
|
|
523
508
|
network: "LOCAL",
|
|
524
509
|
},
|
|
525
|
-
}
|
|
526
|
-
false,
|
|
527
|
-
);
|
|
510
|
+
});
|
|
528
511
|
|
|
529
512
|
const faucet = BitcoinFaucet.getInstance();
|
|
530
513
|
|
|
@@ -570,7 +553,7 @@ describe("SSP static deposit address integration", () => {
|
|
|
570
553
|
signedTx,
|
|
571
554
|
vout,
|
|
572
555
|
faucet,
|
|
573
|
-
} = await
|
|
556
|
+
} = await initTestingWallet(DEPOSIT_AMOUNT, "LOCAL");
|
|
574
557
|
|
|
575
558
|
// Wait for the transaction to be mined
|
|
576
559
|
await faucet.mineBlocks(6);
|
|
@@ -610,7 +593,7 @@ describe("SSP static deposit address integration", () => {
|
|
|
610
593
|
signedTx,
|
|
611
594
|
vout,
|
|
612
595
|
faucet,
|
|
613
|
-
} = await
|
|
596
|
+
} = await initTestingWallet(DEPOSIT_AMOUNT, "LOCAL");
|
|
614
597
|
|
|
615
598
|
// Wait for the transaction to be mined
|
|
616
599
|
await faucet.mineBlocks(6);
|
|
@@ -661,7 +644,7 @@ describe("SSP static deposit address integration", () => {
|
|
|
661
644
|
signedTx,
|
|
662
645
|
vout,
|
|
663
646
|
faucet,
|
|
664
|
-
} = await
|
|
647
|
+
} = await initTestingWallet(DEPOSIT_AMOUNT, "LOCAL");
|
|
665
648
|
|
|
666
649
|
// Wait for the transaction to be mined
|
|
667
650
|
await faucet.mineBlocks(6);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from "@jest/globals";
|
|
2
2
|
import { SparkWalletTesting } from "../../utils/spark-testing-wallet.js";
|
|
3
3
|
import { BitcoinFaucet } from "../../utils/test-faucet.js";
|
|
4
|
+
import { SparkWalletTestingWithStream } from "../../utils/spark-testing-wallet.js";
|
|
4
5
|
|
|
5
6
|
const DEPOSIT_AMOUNT = 10000n;
|
|
6
7
|
|
|
@@ -8,14 +9,12 @@ describe("SSP swap", () => {
|
|
|
8
9
|
it("it should swap with the SSP before sending a transfer if the user does not have exact leaf amount", async () => {
|
|
9
10
|
const faucet = BitcoinFaucet.getInstance();
|
|
10
11
|
|
|
11
|
-
const { wallet: userWallet } =
|
|
12
|
-
{
|
|
12
|
+
const { wallet: userWallet } =
|
|
13
|
+
await SparkWalletTestingWithStream.initialize({
|
|
13
14
|
options: {
|
|
14
15
|
network: "LOCAL",
|
|
15
16
|
},
|
|
16
|
-
}
|
|
17
|
-
false,
|
|
18
|
-
);
|
|
17
|
+
});
|
|
19
18
|
|
|
20
19
|
const depositAddress = await userWallet.getSingleUseDepositAddress();
|
|
21
20
|
expect(depositAddress).toBeDefined();
|