@buildonspark/spark-sdk 0.2.11 → 0.2.13
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 +15 -0
- package/dist/bare/index.cjs +761 -243
- package/dist/bare/index.d.cts +70 -11
- package/dist/bare/index.d.ts +70 -11
- package/dist/bare/index.js +684 -170
- package/dist/{chunk-A5M55UR3.js → chunk-5VWGOHED.js} +499 -8
- package/dist/{chunk-3WBPICWC.js → chunk-CKHJFQUA.js} +1 -1
- package/dist/{chunk-QNYJGFPD.js → chunk-LX45BCZW.js} +207 -160
- package/dist/{chunk-76SYPHOC.js → chunk-TB7DG5CU.js} +2 -2
- package/dist/{chunk-6CMNEDBK.js → chunk-XXTWWW6L.js} +1 -1
- package/dist/{client-Dd3QnxQu.d.ts → client-D7KDa4Ih.d.ts} +1 -1
- package/dist/{client-B9CAWKWz.d.cts → client-DVuA5-7M.d.cts} +1 -1
- package/dist/debug.cjs +761 -243
- package/dist/debug.d.cts +4 -4
- package/dist/debug.d.ts +4 -4
- package/dist/debug.js +4 -4
- package/dist/graphql/objects/index.d.cts +3 -3
- package/dist/graphql/objects/index.d.ts +3 -3
- package/dist/index.cjs +783 -265
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +5 -5
- package/dist/index.node.cjs +783 -265
- package/dist/index.node.d.cts +6 -6
- package/dist/index.node.d.ts +6 -6
- package/dist/index.node.js +4 -4
- package/dist/{logging-BOAzMqpM.d.cts → logging-BfTyKwqb.d.cts} +3 -3
- package/dist/{logging-Bt_WdZbu.d.ts → logging-CaNpBgiE.d.ts} +3 -3
- package/dist/native/index.cjs +782 -264
- package/dist/native/index.d.cts +70 -11
- package/dist/native/index.d.ts +70 -11
- package/dist/native/index.js +686 -172
- package/dist/proto/spark.cjs +499 -8
- package/dist/proto/spark.d.cts +1 -1
- package/dist/proto/spark.d.ts +1 -1
- package/dist/proto/spark.js +17 -1
- package/dist/proto/spark_token.d.cts +1 -1
- package/dist/proto/spark_token.d.ts +1 -1
- package/dist/proto/spark_token.js +2 -2
- package/dist/{spark-CtGJPkx4.d.cts → spark-C7OG9mGJ.d.cts} +79 -2
- package/dist/{spark-CtGJPkx4.d.ts → spark-C7OG9mGJ.d.ts} +79 -2
- package/dist/{spark-wallet-Cp3yv6cK.d.ts → spark-wallet-D0Df_P_x.d.ts} +26 -13
- package/dist/{spark-wallet-yc2KhsVY.d.cts → spark-wallet-Dvh1BLP6.d.cts} +26 -13
- package/dist/{spark-wallet.node-D0Qw5Wb4.d.cts → spark-wallet.node-B3V8_fgw.d.cts} +1 -1
- package/dist/{spark-wallet.node-D4IovOHu.d.ts → spark-wallet.node-bGmy8-T8.d.ts} +1 -1
- package/dist/tests/test-utils.cjs +573 -66
- package/dist/tests/test-utils.d.cts +4 -4
- package/dist/tests/test-utils.d.ts +4 -4
- package/dist/tests/test-utils.js +5 -5
- package/dist/{token-transactions-CwhlOgIP.d.cts → token-transactions-D1ta-sHH.d.cts} +2 -2
- package/dist/{token-transactions-0nmR9mQO.d.ts → token-transactions-DINiKBzd.d.ts} +2 -2
- package/dist/types/index.cjs +492 -9
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +2 -2
- package/package.json +3 -3
- package/src/proto/common.ts +1 -1
- package/src/proto/google/protobuf/descriptor.ts +4 -10
- package/src/proto/google/protobuf/duration.ts +1 -1
- package/src/proto/google/protobuf/empty.ts +1 -1
- package/src/proto/google/protobuf/timestamp.ts +1 -1
- package/src/proto/mock.ts +1 -1
- package/src/proto/spark.ts +593 -3
- package/src/proto/spark_authn.ts +1 -1
- package/src/proto/spark_token.ts +1 -1
- package/src/proto/validate/validate.ts +27 -79
- package/src/services/deposit.ts +55 -3
- package/src/services/lightning.ts +2 -2
- package/src/services/signing.ts +1 -1
- package/src/services/token-transactions.ts +2 -5
- package/src/services/transfer.ts +2 -28
- package/src/signer/signer.ts +2 -2
- package/src/spark-wallet/proto-descriptors.ts +22 -0
- package/src/spark-wallet/proto-hash.ts +743 -0
- package/src/spark-wallet/proto-reflection.ts +193 -0
- package/src/spark-wallet/spark-wallet.ts +95 -57
- package/src/spark_descriptors.pb +0 -0
- package/src/tests/address.test.ts +10 -10
- package/src/tests/bitcoin.test.ts +2 -2
- package/src/tests/bufbuild-reflection.test.ts +151 -0
- package/src/tests/cross-language-hash.test.ts +79 -0
- package/src/tests/integration/address.test.ts +3 -12
- package/src/tests/integration/coop-exit.test.ts +1 -1
- package/src/tests/integration/lightning.test.ts +1 -1
- package/src/tests/integration/ssp/static_deposit.test.ts +128 -1
- package/src/tests/integration/static_deposit.test.ts +26 -0
- package/src/tests/integration/swap.test.ts +1 -1
- package/src/tests/integration/transfer.test.ts +1 -129
- package/src/tests/integration/wallet.test.ts +7 -7
- package/src/tests/integration/watchtower.test.ts +1 -1
- package/src/tests/token-hashing.test.ts +3 -6
- package/src/tests/token-outputs.test.ts +3 -3
- package/src/tests/utils/test-faucet.ts +2 -2
- package/src/types/sdk-types.ts +1 -1
- package/src/utils/adaptor-signature.ts +1 -1
- package/src/utils/address.ts +1 -1
- package/src/utils/bitcoin.ts +1 -5
- package/src/utils/keys.ts +1 -1
- package/src/utils/secret-sharing.ts +1 -1
- package/src/utils/token-transactions.ts +1 -2
- package/src/utils/transfer_package.ts +1 -1
- package/src/utils/unilateral-exit.ts +1 -1
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
} from "./chunk-NX5KPN5F.js";
|
|
5
5
|
import {
|
|
6
6
|
SparkTokenServiceDefinition
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-XXTWWW6L.js";
|
|
8
8
|
import {
|
|
9
9
|
mapTransferToWalletTransfer,
|
|
10
10
|
mapTreeNodeToWalletLeaf
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-TB7DG5CU.js";
|
|
12
12
|
import {
|
|
13
13
|
Empty,
|
|
14
14
|
SatsPayment,
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
TokensPayment,
|
|
20
20
|
TreeNode,
|
|
21
21
|
networkToJSON
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-5VWGOHED.js";
|
|
23
23
|
import {
|
|
24
24
|
BitcoinNetwork_default,
|
|
25
25
|
ClaimStaticDepositFromJson,
|
|
@@ -152,8 +152,8 @@ var NotImplementedError = class extends SparkSDKError {
|
|
|
152
152
|
};
|
|
153
153
|
|
|
154
154
|
// src/utils/keys.ts
|
|
155
|
-
import { numberToBytesBE } from "@noble/curves/abstract/utils";
|
|
156
155
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
156
|
+
import { numberToBytesBE } from "@noble/curves/utils";
|
|
157
157
|
function addPublicKeys(a, b) {
|
|
158
158
|
if (a.length !== 33 || b.length !== 33) {
|
|
159
159
|
throw new ValidationError("Public keys must be 33 bytes", {
|
|
@@ -264,8 +264,8 @@ var setCrypto = (cryptoImplParam) => {
|
|
|
264
264
|
};
|
|
265
265
|
|
|
266
266
|
// src/utils/secret-sharing.ts
|
|
267
|
-
import { bytesToHex as bytesToHex2, equalBytes } from "@noble/curves/abstract/utils";
|
|
268
267
|
import { secp256k1 as secp256k12 } from "@noble/curves/secp256k1";
|
|
268
|
+
import { bytesToHex as bytesToHex2, equalBytes } from "@noble/curves/utils";
|
|
269
269
|
function getRandomBigInt(max) {
|
|
270
270
|
const byteLength = max.toString(2).length + 7 >> 3;
|
|
271
271
|
const maxBigInt = max;
|
|
@@ -561,13 +561,13 @@ var KeyDerivationType = /* @__PURE__ */ ((KeyDerivationType2) => {
|
|
|
561
561
|
|
|
562
562
|
// src/signer/signer.ts
|
|
563
563
|
import { privateNegate } from "@bitcoinerlab/secp256k1";
|
|
564
|
+
import { schnorr, secp256k1 as secp256k14 } from "@noble/curves/secp256k1";
|
|
564
565
|
import {
|
|
565
566
|
bytesToHex as bytesToHex3,
|
|
566
567
|
bytesToNumberBE,
|
|
567
568
|
equalBytes as equalBytes2,
|
|
568
569
|
hexToBytes
|
|
569
|
-
} from "@noble/curves/
|
|
570
|
-
import { schnorr, secp256k1 as secp256k14 } from "@noble/curves/secp256k1";
|
|
570
|
+
} from "@noble/curves/utils";
|
|
571
571
|
import { sha256 } from "@noble/hashes/sha2";
|
|
572
572
|
import { HDKey } from "@scure/bip32";
|
|
573
573
|
import { generateMnemonic, mnemonicToSeed } from "@scure/bip39";
|
|
@@ -579,7 +579,7 @@ import * as ecies from "eciesjs";
|
|
|
579
579
|
import { isNode, isBare } from "@lightsparkdev/core";
|
|
580
580
|
var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
|
|
581
581
|
var isBun = globalThis.Bun !== void 0;
|
|
582
|
-
var packageVersion = true ? "0.2.
|
|
582
|
+
var packageVersion = true ? "0.2.13" : "unknown";
|
|
583
583
|
var baseEnvStr = "unknown";
|
|
584
584
|
if (isBun) {
|
|
585
585
|
const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
|
|
@@ -2808,12 +2808,8 @@ var ConnectionManager = class {
|
|
|
2808
2808
|
};
|
|
2809
2809
|
|
|
2810
2810
|
// src/utils/bitcoin.ts
|
|
2811
|
-
import {
|
|
2812
|
-
bytesToHex as bytesToHex4,
|
|
2813
|
-
bytesToNumberBE as bytesToNumberBE2,
|
|
2814
|
-
hexToBytes as hexToBytes2
|
|
2815
|
-
} from "@noble/curves/abstract/utils";
|
|
2816
2811
|
import { schnorr as schnorr2, secp256k1 as secp256k15 } from "@noble/curves/secp256k1";
|
|
2812
|
+
import { bytesToHex as bytesToHex4, bytesToNumberBE as bytesToNumberBE2, hexToBytes as hexToBytes2 } from "@noble/curves/utils";
|
|
2817
2813
|
import { sha256 as sha2563 } from "@noble/hashes/sha2";
|
|
2818
2814
|
import * as btc2 from "@scure/btc-signer";
|
|
2819
2815
|
function computeTaprootKeyNoScript(pubkey) {
|
|
@@ -3299,7 +3295,7 @@ function getEphemeralAnchorOutput() {
|
|
|
3299
3295
|
}
|
|
3300
3296
|
|
|
3301
3297
|
// src/utils/transfer_package.ts
|
|
3302
|
-
import { hexToBytes as hexToBytes3 } from "@noble/curves/
|
|
3298
|
+
import { hexToBytes as hexToBytes3 } from "@noble/curves/utils";
|
|
3303
3299
|
import { sha256 as sha2564 } from "@noble/hashes/sha2";
|
|
3304
3300
|
function getTransferPackageSigningPayload(transferID, transferPackage) {
|
|
3305
3301
|
const encryptedPayload = transferPackage.keyTweakPackage;
|
|
@@ -3350,7 +3346,8 @@ var DepositService = class {
|
|
|
3350
3346
|
}
|
|
3351
3347
|
async validateDepositAddress({
|
|
3352
3348
|
address: address2,
|
|
3353
|
-
userPubkey
|
|
3349
|
+
userPubkey,
|
|
3350
|
+
verifyCoordinatorProof = false
|
|
3354
3351
|
}) {
|
|
3355
3352
|
if (!address2.depositAddressProof || !address2.depositAddressProof.proofOfPossessionSignature || !address2.depositAddressProof.addressSignatures) {
|
|
3356
3353
|
throw new ValidationError(
|
|
@@ -3388,7 +3385,7 @@ var DepositService = class {
|
|
|
3388
3385
|
}
|
|
3389
3386
|
const addrHash = sha2566(address2.address);
|
|
3390
3387
|
for (const operator of Object.values(this.config.getSigningOperators())) {
|
|
3391
|
-
if (operator.identifier === this.config.getCoordinatorIdentifier()) {
|
|
3388
|
+
if (operator.identifier === this.config.getCoordinatorIdentifier() && !verifyCoordinatorProof) {
|
|
3392
3389
|
continue;
|
|
3393
3390
|
}
|
|
3394
3391
|
const operatorPubkey2 = hexToBytes4(operator.identityPublicKey);
|
|
@@ -3413,6 +3410,46 @@ var DepositService = class {
|
|
|
3413
3410
|
}
|
|
3414
3411
|
}
|
|
3415
3412
|
}
|
|
3413
|
+
async generateStaticDepositAddress({
|
|
3414
|
+
signingPubkey
|
|
3415
|
+
}) {
|
|
3416
|
+
const sparkClient = await this.connectionManager.createSparkClient(
|
|
3417
|
+
this.config.getCoordinatorAddress()
|
|
3418
|
+
);
|
|
3419
|
+
let depositResp;
|
|
3420
|
+
try {
|
|
3421
|
+
depositResp = await sparkClient.generate_static_deposit_address({
|
|
3422
|
+
signingPublicKey: signingPubkey,
|
|
3423
|
+
identityPublicKey: await this.config.signer.getIdentityPublicKey(),
|
|
3424
|
+
network: this.config.getNetworkProto()
|
|
3425
|
+
});
|
|
3426
|
+
} catch (error) {
|
|
3427
|
+
throw new NetworkError(
|
|
3428
|
+
"Failed to generate static deposit address",
|
|
3429
|
+
{
|
|
3430
|
+
operation: "generate_static_deposit_address",
|
|
3431
|
+
errorCount: 1,
|
|
3432
|
+
errors: error instanceof Error ? error.message : String(error)
|
|
3433
|
+
},
|
|
3434
|
+
error
|
|
3435
|
+
);
|
|
3436
|
+
}
|
|
3437
|
+
if (!depositResp.depositAddress) {
|
|
3438
|
+
throw new ValidationError(
|
|
3439
|
+
"No static deposit address response from coordinator",
|
|
3440
|
+
{
|
|
3441
|
+
field: "depositAddress",
|
|
3442
|
+
value: depositResp
|
|
3443
|
+
}
|
|
3444
|
+
);
|
|
3445
|
+
}
|
|
3446
|
+
await this.validateDepositAddress({
|
|
3447
|
+
address: depositResp.depositAddress,
|
|
3448
|
+
userPubkey: signingPubkey,
|
|
3449
|
+
verifyCoordinatorProof: true
|
|
3450
|
+
});
|
|
3451
|
+
return depositResp;
|
|
3452
|
+
}
|
|
3416
3453
|
async generateDepositAddress({
|
|
3417
3454
|
signingPubkey,
|
|
3418
3455
|
leafId,
|
|
@@ -3953,8 +3990,8 @@ var DepositService = class {
|
|
|
3953
3990
|
|
|
3954
3991
|
// src/utils/address.ts
|
|
3955
3992
|
import { BinaryWriter as BinaryWriter3 } from "@bufbuild/protobuf/wire";
|
|
3956
|
-
import { bytesToNumberBE as bytesToNumberBE3 } from "@noble/curves/abstract/utils";
|
|
3957
3993
|
import { schnorr as schnorr4, secp256k1 as secp256k17 } from "@noble/curves/secp256k1";
|
|
3994
|
+
import { bytesToNumberBE as bytesToNumberBE3 } from "@noble/curves/utils";
|
|
3958
3995
|
import { bytesToHex as bytesToHex5, hexToBytes as hexToBytes5 } from "@noble/hashes/utils";
|
|
3959
3996
|
import { bech32m } from "@scure/base";
|
|
3960
3997
|
import { UUID } from "uuidv7";
|
|
@@ -4601,8 +4638,7 @@ function getNetworkFromBech32mTokenIdentifier(bech32mTokenIdentifier) {
|
|
|
4601
4638
|
}
|
|
4602
4639
|
|
|
4603
4640
|
// src/utils/token-transactions.ts
|
|
4604
|
-
import { bytesToNumberBE as bytesToNumberBE4 } from "@noble/curves/
|
|
4605
|
-
import { equalBytes as equalBytes4 } from "@scure/btc-signer/utils";
|
|
4641
|
+
import { bytesToNumberBE as bytesToNumberBE4, equalBytes as equalBytes4 } from "@noble/curves/utils";
|
|
4606
4642
|
function sumAvailableTokens(outputs) {
|
|
4607
4643
|
try {
|
|
4608
4644
|
return outputs.reduce(
|
|
@@ -4650,12 +4686,12 @@ function filterTokenBalanceForTokenIdentifier(tokenBalances, tokenIdentifier) {
|
|
|
4650
4686
|
}
|
|
4651
4687
|
|
|
4652
4688
|
// src/services/token-transactions.ts
|
|
4689
|
+
import { secp256k1 as secp256k19 } from "@noble/curves/secp256k1";
|
|
4653
4690
|
import {
|
|
4654
|
-
bytesToHex as
|
|
4691
|
+
bytesToHex as bytesToHex6,
|
|
4655
4692
|
bytesToNumberBE as bytesToNumberBE5,
|
|
4656
4693
|
numberToBytesBE as numberToBytesBE2
|
|
4657
|
-
} from "@noble/curves/
|
|
4658
|
-
import { secp256k1 as secp256k19 } from "@noble/curves/secp256k1";
|
|
4694
|
+
} from "@noble/curves/utils";
|
|
4659
4695
|
import { hexToBytes as hexToBytes6 } from "@noble/hashes/utils";
|
|
4660
4696
|
|
|
4661
4697
|
// src/utils/token-hashing.ts
|
|
@@ -6792,7 +6828,7 @@ var TokenTransactionService = class {
|
|
|
6792
6828
|
{
|
|
6793
6829
|
field: "revocationCommitment",
|
|
6794
6830
|
value: derivedRevocationCommitment,
|
|
6795
|
-
expected:
|
|
6831
|
+
expected: bytesToHex6(outputsToSpendCommitments[outputIndex]),
|
|
6796
6832
|
outputIndex
|
|
6797
6833
|
}
|
|
6798
6834
|
)
|
|
@@ -6818,7 +6854,7 @@ var TokenTransactionService = class {
|
|
|
6818
6854
|
threshold
|
|
6819
6855
|
);
|
|
6820
6856
|
}
|
|
6821
|
-
return
|
|
6857
|
+
return bytesToHex6(finalTokenTransactionHash);
|
|
6822
6858
|
}
|
|
6823
6859
|
async broadcastTokenTransactionV1(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
|
|
6824
6860
|
const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransaction(
|
|
@@ -6832,7 +6868,7 @@ var TokenTransactionService = class {
|
|
|
6832
6868
|
finalTokenTransactionHash,
|
|
6833
6869
|
signingOperators
|
|
6834
6870
|
);
|
|
6835
|
-
return
|
|
6871
|
+
return bytesToHex6(finalTokenTransactionHash);
|
|
6836
6872
|
}
|
|
6837
6873
|
async startTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
|
|
6838
6874
|
const sparkClient = await this.connectionManager.createSparkClient(
|
|
@@ -7424,7 +7460,7 @@ var TokenTransactionService = class {
|
|
|
7424
7460
|
// Helper function for deciding if the signer public key is the identity public key
|
|
7425
7461
|
async signMessageWithKey(message, publicKey) {
|
|
7426
7462
|
const tokenSignatures = this.config.getTokenSignatures();
|
|
7427
|
-
if (
|
|
7463
|
+
if (bytesToHex6(publicKey) === bytesToHex6(await this.config.signer.getIdentityPublicKey())) {
|
|
7428
7464
|
if (tokenSignatures === "SCHNORR") {
|
|
7429
7465
|
return await this.config.signer.signSchnorrWithIdentityKey(message);
|
|
7430
7466
|
} else {
|
|
@@ -7433,8 +7469,8 @@ var TokenTransactionService = class {
|
|
|
7433
7469
|
} else {
|
|
7434
7470
|
throw new ValidationError("Invalid public key", {
|
|
7435
7471
|
field: "publicKey",
|
|
7436
|
-
value:
|
|
7437
|
-
expected:
|
|
7472
|
+
value: bytesToHex6(publicKey),
|
|
7473
|
+
expected: bytesToHex6(await this.config.signer.getIdentityPublicKey())
|
|
7438
7474
|
});
|
|
7439
7475
|
}
|
|
7440
7476
|
}
|
|
@@ -7564,8 +7600,8 @@ function isTokenTransaction(tokenTransaction) {
|
|
|
7564
7600
|
|
|
7565
7601
|
// src/utils/adaptor-signature.ts
|
|
7566
7602
|
import { mod } from "@noble/curves/abstract/modular";
|
|
7567
|
-
import { bytesToNumberBE as bytesToNumberBE6, numberToBytesBE as numberToBytesBE3 } from "@noble/curves/abstract/utils";
|
|
7568
7603
|
import { schnorr as schnorr5, secp256k1 as secp256k110 } from "@noble/curves/secp256k1";
|
|
7604
|
+
import { bytesToNumberBE as bytesToNumberBE6, numberToBytesBE as numberToBytesBE3 } from "@noble/curves/utils";
|
|
7569
7605
|
function generateSignatureFromExistingAdaptor(signature, adaptorPrivateKeyBytes) {
|
|
7570
7606
|
const { r, s } = parseSignature(signature);
|
|
7571
7607
|
const sBigInt = bytesToNumberBE6(s);
|
|
@@ -7693,8 +7729,8 @@ function parseSignature(signature) {
|
|
|
7693
7729
|
}
|
|
7694
7730
|
|
|
7695
7731
|
// src/tests/utils/test-faucet.ts
|
|
7696
|
-
import { bytesToHex as bytesToHex8, hexToBytes as hexToBytes7 } from "@noble/curves/abstract/utils";
|
|
7697
7732
|
import { schnorr as schnorr6, secp256k1 as secp256k111 } from "@noble/curves/secp256k1";
|
|
7733
|
+
import { bytesToHex as bytesToHex7, hexToBytes as hexToBytes7 } from "@noble/curves/utils";
|
|
7698
7734
|
import * as btc3 from "@scure/btc-signer";
|
|
7699
7735
|
import { Address as Address2, OutScript as OutScript2, SigHash as SigHash2, Transaction as Transaction4 } from "@scure/btc-signer";
|
|
7700
7736
|
import { taprootTweakPrivKey as taprootTweakPrivKey2 } from "@scure/btc-signer/utils";
|
|
@@ -7849,7 +7885,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
7849
7885
|
},
|
|
7850
7886
|
STATIC_MINING_KEY
|
|
7851
7887
|
);
|
|
7852
|
-
await this.broadcastTx(
|
|
7888
|
+
await this.broadcastTx(bytesToHex7(signedSplitTx.extract()));
|
|
7853
7889
|
const splitTxId = signedSplitTx.id;
|
|
7854
7890
|
for (let i = 0; i < numCoinsToCreate; i++) {
|
|
7855
7891
|
this.coins.push({
|
|
@@ -7883,7 +7919,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
7883
7919
|
coinToSend.txout,
|
|
7884
7920
|
coinToSend.key
|
|
7885
7921
|
);
|
|
7886
|
-
await this.broadcastTx(
|
|
7922
|
+
await this.broadcastTx(bytesToHex7(signedTx.extract()));
|
|
7887
7923
|
}
|
|
7888
7924
|
async signFaucetCoin(unsignedTx, fundingTxOut, key) {
|
|
7889
7925
|
const pubKey = secp256k111.getPublicKey(key);
|
|
@@ -8003,7 +8039,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
8003
8039
|
});
|
|
8004
8040
|
}
|
|
8005
8041
|
const signedTx = await this.signFaucetCoin(tx, coin.txout, coin.key);
|
|
8006
|
-
const txHex =
|
|
8042
|
+
const txHex = bytesToHex7(signedTx.extract());
|
|
8007
8043
|
await this.broadcastTx(txHex);
|
|
8008
8044
|
const randomKey = secp256k111.utils.randomPrivateKey();
|
|
8009
8045
|
const randomPubKey = secp256k111.getPublicKey(randomKey);
|
|
@@ -8021,14 +8057,14 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
8021
8057
|
|
|
8022
8058
|
// src/spark-wallet/spark-wallet.ts
|
|
8023
8059
|
import { isNode as isNode3, isObject as isObject2, mapCurrencyAmount } from "@lightsparkdev/core";
|
|
8060
|
+
import { secp256k1 as secp256k114 } from "@noble/curves/secp256k1";
|
|
8024
8061
|
import {
|
|
8025
|
-
bytesToHex as
|
|
8062
|
+
bytesToHex as bytesToHex10,
|
|
8026
8063
|
bytesToNumberBE as bytesToNumberBE8,
|
|
8027
8064
|
equalBytes as equalBytes6,
|
|
8028
8065
|
hexToBytes as hexToBytes11,
|
|
8029
8066
|
numberToVarBytesBE
|
|
8030
|
-
} from "@noble/curves/
|
|
8031
|
-
import { secp256k1 as secp256k114 } from "@noble/curves/secp256k1";
|
|
8067
|
+
} from "@noble/curves/utils";
|
|
8032
8068
|
import { validateMnemonic } from "@scure/bip39";
|
|
8033
8069
|
import { wordlist as wordlist2 } from "@scure/bip39/wordlists/english";
|
|
8034
8070
|
import { Address as Address3, OutScript as OutScript3, Transaction as Transaction7 } from "@scure/btc-signer";
|
|
@@ -8037,7 +8073,7 @@ import { uuidv7 as uuidv74, uuidv7obj } from "uuidv7";
|
|
|
8037
8073
|
|
|
8038
8074
|
// src/graphql/client.ts
|
|
8039
8075
|
import {
|
|
8040
|
-
bytesToHex as
|
|
8076
|
+
bytesToHex as bytesToHex8,
|
|
8041
8077
|
DefaultCrypto,
|
|
8042
8078
|
NodeKeyCache,
|
|
8043
8079
|
Requester,
|
|
@@ -9023,7 +9059,7 @@ var SspClient = class {
|
|
|
9023
9059
|
{
|
|
9024
9060
|
queryPayload: GetChallenge,
|
|
9025
9061
|
variables: {
|
|
9026
|
-
public_key:
|
|
9062
|
+
public_key: bytesToHex8(await this.signer.getIdentityPublicKey())
|
|
9027
9063
|
},
|
|
9028
9064
|
constructObject: (response) => {
|
|
9029
9065
|
return GetChallengeOutputFromJson(response.get_challenge);
|
|
@@ -9039,7 +9075,7 @@ var SspClient = class {
|
|
|
9039
9075
|
variables: {
|
|
9040
9076
|
protected_challenge: protectedChallenge,
|
|
9041
9077
|
signature,
|
|
9042
|
-
identity_public_key:
|
|
9078
|
+
identity_public_key: bytesToHex8(
|
|
9043
9079
|
await this.signer.getIdentityPublicKey()
|
|
9044
9080
|
)
|
|
9045
9081
|
},
|
|
@@ -9156,13 +9192,13 @@ import { Transaction as Transaction6 } from "@scure/btc-signer";
|
|
|
9156
9192
|
import { uuidv7 as uuidv72 } from "uuidv7";
|
|
9157
9193
|
|
|
9158
9194
|
// src/services/transfer.ts
|
|
9195
|
+
import { secp256k1 as secp256k112 } from "@noble/curves/secp256k1";
|
|
9159
9196
|
import {
|
|
9160
|
-
bytesToHex as
|
|
9197
|
+
bytesToHex as bytesToHex9,
|
|
9161
9198
|
equalBytes as equalBytes5,
|
|
9162
9199
|
hexToBytes as hexToBytes8,
|
|
9163
9200
|
numberToBytesBE as numberToBytesBE4
|
|
9164
|
-
} from "@noble/curves/
|
|
9165
|
-
import { secp256k1 as secp256k112 } from "@noble/curves/secp256k1";
|
|
9201
|
+
} from "@noble/curves/utils";
|
|
9166
9202
|
import { sha256 as sha25610 } from "@noble/hashes/sha2";
|
|
9167
9203
|
import { Transaction as Transaction5 } from "@scure/btc-signer";
|
|
9168
9204
|
import * as ecies2 from "eciesjs";
|
|
@@ -9532,7 +9568,7 @@ var BaseTransferService = class {
|
|
|
9532
9568
|
}
|
|
9533
9569
|
async prepareSendTransferKeyTweaks(transferID, receiverIdentityPubkey, leaves, cpfpRefundSignatureMap, directRefundSignatureMap, directFromCpfpRefundSignatureMap) {
|
|
9534
9570
|
const receiverEciesPubKey = ecies2.PublicKey.fromHex(
|
|
9535
|
-
|
|
9571
|
+
bytesToHex9(receiverIdentityPubkey)
|
|
9536
9572
|
);
|
|
9537
9573
|
const leavesTweaksMap = /* @__PURE__ */ new Map();
|
|
9538
9574
|
for (const leaf of leaves) {
|
|
@@ -10154,24 +10190,6 @@ var TransferService = class extends BaseTransferService {
|
|
|
10154
10190
|
throw new Error(`Error finalizing node signatures in transfer: ${error}`);
|
|
10155
10191
|
}
|
|
10156
10192
|
}
|
|
10157
|
-
async cancelTransfer(transfer, operatorAddress) {
|
|
10158
|
-
const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
|
|
10159
|
-
try {
|
|
10160
|
-
const response = await sparkClient.cancel_transfer({
|
|
10161
|
-
transferId: transfer.id,
|
|
10162
|
-
senderIdentityPublicKey: await this.config.signer.getIdentityPublicKey()
|
|
10163
|
-
});
|
|
10164
|
-
return response.transfer;
|
|
10165
|
-
} catch (error) {
|
|
10166
|
-
throw new NetworkError(
|
|
10167
|
-
"Failed to cancel transfer",
|
|
10168
|
-
{
|
|
10169
|
-
method: "POST"
|
|
10170
|
-
},
|
|
10171
|
-
error
|
|
10172
|
-
);
|
|
10173
|
-
}
|
|
10174
|
-
}
|
|
10175
10193
|
async queryPendingTransfersBySender(operatorAddress) {
|
|
10176
10194
|
const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
|
|
10177
10195
|
try {
|
|
@@ -11051,12 +11069,12 @@ var CoopExitService = class extends BaseTransferService {
|
|
|
11051
11069
|
};
|
|
11052
11070
|
|
|
11053
11071
|
// src/services/lightning.ts
|
|
11072
|
+
import { secp256k1 as secp256k113 } from "@noble/curves/secp256k1";
|
|
11054
11073
|
import {
|
|
11055
11074
|
bytesToNumberBE as bytesToNumberBE7,
|
|
11056
11075
|
hexToBytes as hexToBytes9,
|
|
11057
11076
|
numberToBytesBE as numberToBytesBE5
|
|
11058
|
-
} from "@noble/curves/
|
|
11059
|
-
import { secp256k1 as secp256k113 } from "@noble/curves/secp256k1";
|
|
11077
|
+
} from "@noble/curves/utils";
|
|
11060
11078
|
import { sha256 as sha25611 } from "@noble/hashes/sha2";
|
|
11061
11079
|
import { uuidv7 as uuidv73 } from "uuidv7";
|
|
11062
11080
|
|
|
@@ -11412,7 +11430,7 @@ import { EventEmitter } from "eventemitter3";
|
|
|
11412
11430
|
import { ClientError, Status } from "nice-grpc-common";
|
|
11413
11431
|
|
|
11414
11432
|
// src/services/signing.ts
|
|
11415
|
-
import { hexToBytes as hexToBytes10 } from "@noble/curves/
|
|
11433
|
+
import { hexToBytes as hexToBytes10 } from "@noble/curves/utils";
|
|
11416
11434
|
var SigningService = class {
|
|
11417
11435
|
config;
|
|
11418
11436
|
constructor(config) {
|
|
@@ -12126,7 +12144,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12126
12144
|
* @returns {Promise<string>} The identity public key as a hex string.
|
|
12127
12145
|
*/
|
|
12128
12146
|
async getIdentityPublicKey() {
|
|
12129
|
-
return
|
|
12147
|
+
return bytesToHex10(await this.config.signer.getIdentityPublicKey());
|
|
12130
12148
|
}
|
|
12131
12149
|
/**
|
|
12132
12150
|
* Gets the Spark address of the wallet.
|
|
@@ -12136,7 +12154,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12136
12154
|
async getSparkAddress() {
|
|
12137
12155
|
if (!this.sparkAddress) {
|
|
12138
12156
|
this.sparkAddress = encodeSparkAddress({
|
|
12139
|
-
identityPublicKey:
|
|
12157
|
+
identityPublicKey: bytesToHex10(
|
|
12140
12158
|
await this.config.signer.getIdentityPublicKey()
|
|
12141
12159
|
),
|
|
12142
12160
|
network: this.config.getNetworkType()
|
|
@@ -12220,7 +12238,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12220
12238
|
const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
|
|
12221
12239
|
return encodeSparkAddressWithSignature(
|
|
12222
12240
|
{
|
|
12223
|
-
identityPublicKey:
|
|
12241
|
+
identityPublicKey: bytesToHex10(identityPublicKey),
|
|
12224
12242
|
network: this.config.getNetworkType(),
|
|
12225
12243
|
sparkInvoiceFields: invoiceFields
|
|
12226
12244
|
},
|
|
@@ -12288,7 +12306,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12288
12306
|
});
|
|
12289
12307
|
}
|
|
12290
12308
|
this.sparkAddress = encodeSparkAddress({
|
|
12291
|
-
identityPublicKey:
|
|
12309
|
+
identityPublicKey: bytesToHex10(identityPublicKey),
|
|
12292
12310
|
network: this.config.getNetworkType()
|
|
12293
12311
|
});
|
|
12294
12312
|
return this.sparkAddress;
|
|
@@ -12468,18 +12486,18 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12468
12486
|
const userLeaves = [];
|
|
12469
12487
|
userLeaves.push({
|
|
12470
12488
|
leaf_id: transfer.leaves[0].leaf.id,
|
|
12471
|
-
raw_unsigned_refund_transaction:
|
|
12489
|
+
raw_unsigned_refund_transaction: bytesToHex10(
|
|
12472
12490
|
transfer.leaves[0].intermediateRefundTx
|
|
12473
12491
|
),
|
|
12474
|
-
direct_raw_unsigned_refund_transaction:
|
|
12492
|
+
direct_raw_unsigned_refund_transaction: bytesToHex10(
|
|
12475
12493
|
transfer.leaves[0].intermediateDirectRefundTx
|
|
12476
12494
|
),
|
|
12477
|
-
direct_from_cpfp_raw_unsigned_refund_transaction:
|
|
12495
|
+
direct_from_cpfp_raw_unsigned_refund_transaction: bytesToHex10(
|
|
12478
12496
|
transfer.leaves[0].intermediateDirectFromCpfpRefundTx
|
|
12479
12497
|
),
|
|
12480
|
-
adaptor_added_signature:
|
|
12481
|
-
direct_adaptor_added_signature:
|
|
12482
|
-
direct_from_cpfp_adaptor_added_signature:
|
|
12498
|
+
adaptor_added_signature: bytesToHex10(cpfpAdaptorSignature),
|
|
12499
|
+
direct_adaptor_added_signature: bytesToHex10(directAdaptorSignature),
|
|
12500
|
+
direct_from_cpfp_adaptor_added_signature: bytesToHex10(
|
|
12483
12501
|
directFromCpfpAdaptorSignature
|
|
12484
12502
|
)
|
|
12485
12503
|
});
|
|
@@ -12532,24 +12550,24 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12532
12550
|
}
|
|
12533
12551
|
userLeaves.push({
|
|
12534
12552
|
leaf_id: leaf.leaf.id,
|
|
12535
|
-
raw_unsigned_refund_transaction:
|
|
12553
|
+
raw_unsigned_refund_transaction: bytesToHex10(
|
|
12536
12554
|
leaf.intermediateRefundTx
|
|
12537
12555
|
),
|
|
12538
|
-
direct_raw_unsigned_refund_transaction:
|
|
12556
|
+
direct_raw_unsigned_refund_transaction: bytesToHex10(
|
|
12539
12557
|
leaf.intermediateDirectRefundTx
|
|
12540
12558
|
),
|
|
12541
|
-
direct_from_cpfp_raw_unsigned_refund_transaction:
|
|
12559
|
+
direct_from_cpfp_raw_unsigned_refund_transaction: bytesToHex10(
|
|
12542
12560
|
leaf.intermediateDirectFromCpfpRefundTx
|
|
12543
12561
|
),
|
|
12544
|
-
adaptor_added_signature:
|
|
12545
|
-
direct_adaptor_added_signature:
|
|
12546
|
-
direct_from_cpfp_adaptor_added_signature:
|
|
12562
|
+
adaptor_added_signature: bytesToHex10(cpfpSignature),
|
|
12563
|
+
direct_adaptor_added_signature: bytesToHex10(directSignature),
|
|
12564
|
+
direct_from_cpfp_adaptor_added_signature: bytesToHex10(
|
|
12547
12565
|
directFromCpfpSignature
|
|
12548
12566
|
)
|
|
12549
12567
|
});
|
|
12550
12568
|
}
|
|
12551
12569
|
const sspClient = this.getSspClient();
|
|
12552
|
-
const cpfpAdaptorPubkey =
|
|
12570
|
+
const cpfpAdaptorPubkey = bytesToHex10(
|
|
12553
12571
|
secp256k114.getPublicKey(cpfpAdaptorPrivateKey)
|
|
12554
12572
|
);
|
|
12555
12573
|
if (!cpfpAdaptorPubkey) {
|
|
@@ -12557,13 +12575,13 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12557
12575
|
}
|
|
12558
12576
|
let directAdaptorPubkey;
|
|
12559
12577
|
if (directAdaptorPrivateKey.length > 0) {
|
|
12560
|
-
directAdaptorPubkey =
|
|
12578
|
+
directAdaptorPubkey = bytesToHex10(
|
|
12561
12579
|
secp256k114.getPublicKey(directAdaptorPrivateKey)
|
|
12562
12580
|
);
|
|
12563
12581
|
}
|
|
12564
12582
|
let directFromCpfpAdaptorPubkey;
|
|
12565
12583
|
if (directFromCpfpAdaptorPrivateKey.length > 0) {
|
|
12566
|
-
directFromCpfpAdaptorPubkey =
|
|
12584
|
+
directFromCpfpAdaptorPubkey = bytesToHex10(
|
|
12567
12585
|
secp256k114.getPublicKey(directFromCpfpAdaptorPrivateKey)
|
|
12568
12586
|
);
|
|
12569
12587
|
}
|
|
@@ -12703,9 +12721,9 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12703
12721
|
directFromCpfpSignatureMap
|
|
12704
12722
|
);
|
|
12705
12723
|
const completeResponse = await sspClient.completeLeaveSwap({
|
|
12706
|
-
adaptorSecretKey:
|
|
12707
|
-
directAdaptorSecretKey:
|
|
12708
|
-
directFromCpfpAdaptorSecretKey:
|
|
12724
|
+
adaptorSecretKey: bytesToHex10(cpfpAdaptorPrivateKey),
|
|
12725
|
+
directAdaptorSecretKey: bytesToHex10(directAdaptorPrivateKey),
|
|
12726
|
+
directFromCpfpAdaptorSecretKey: bytesToHex10(
|
|
12709
12727
|
directFromCpfpAdaptorPrivateKey
|
|
12710
12728
|
),
|
|
12711
12729
|
userOutboundTransferExternalId: transfer.id,
|
|
@@ -12736,7 +12754,6 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12736
12754
|
message: e.message,
|
|
12737
12755
|
stack: e.stack
|
|
12738
12756
|
});
|
|
12739
|
-
await this.cancelAllSenderInitiatedTransfers();
|
|
12740
12757
|
throw new Error(`Failed to request leaves swap: ${e}`);
|
|
12741
12758
|
}
|
|
12742
12759
|
}
|
|
@@ -12800,7 +12817,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12800
12817
|
let tokenMetadataMap = /* @__PURE__ */ new Map();
|
|
12801
12818
|
for (const [tokenIdentifier, metadata] of this.tokenMetadata) {
|
|
12802
12819
|
tokenMetadataMap.set(tokenIdentifier, {
|
|
12803
|
-
tokenPublicKey:
|
|
12820
|
+
tokenPublicKey: bytesToHex10(metadata.issuerPublicKey),
|
|
12804
12821
|
rawTokenIdentifier: metadata.tokenIdentifier,
|
|
12805
12822
|
tokenName: metadata.tokenName,
|
|
12806
12823
|
tokenTicker: metadata.tokenTicker,
|
|
@@ -12840,7 +12857,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12840
12857
|
* @returns {Promise<string>} A Bitcoin address for depositing funds
|
|
12841
12858
|
*/
|
|
12842
12859
|
async getSingleUseDepositAddress() {
|
|
12843
|
-
return await this.generateDepositAddress(
|
|
12860
|
+
return await this.generateDepositAddress();
|
|
12844
12861
|
}
|
|
12845
12862
|
/**
|
|
12846
12863
|
* Generates a new static deposit address for receiving bitcoin funds.
|
|
@@ -12849,43 +12866,32 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12849
12866
|
* @returns {Promise<string>} A Bitcoin address for depositing funds
|
|
12850
12867
|
*/
|
|
12851
12868
|
async getStaticDepositAddress() {
|
|
12852
|
-
|
|
12853
|
-
|
|
12854
|
-
|
|
12855
|
-
|
|
12856
|
-
|
|
12857
|
-
|
|
12858
|
-
|
|
12859
|
-
|
|
12860
|
-
|
|
12861
|
-
}
|
|
12862
|
-
} else {
|
|
12863
|
-
throw error;
|
|
12864
|
-
}
|
|
12869
|
+
const signingPubkey = await this.config.signer.getStaticDepositSigningKey(0);
|
|
12870
|
+
const address2 = await this.depositService.generateStaticDepositAddress({
|
|
12871
|
+
signingPubkey
|
|
12872
|
+
});
|
|
12873
|
+
if (!address2.depositAddress) {
|
|
12874
|
+
throw new RPCError("Failed to generate static deposit address", {
|
|
12875
|
+
method: "generateStaticDepositAddress",
|
|
12876
|
+
params: { signingPubkey }
|
|
12877
|
+
});
|
|
12865
12878
|
}
|
|
12879
|
+
return address2.depositAddress.address;
|
|
12866
12880
|
}
|
|
12867
12881
|
/**
|
|
12868
12882
|
* Generates a deposit address for receiving funds.
|
|
12869
|
-
*
|
|
12870
|
-
* @param {boolean} static - Whether the address is static or single use
|
|
12871
12883
|
* @returns {Promise<string>} A deposit address
|
|
12872
12884
|
* @private
|
|
12873
12885
|
*/
|
|
12874
|
-
async generateDepositAddress(
|
|
12886
|
+
async generateDepositAddress() {
|
|
12875
12887
|
const leafId = uuidv74();
|
|
12876
|
-
|
|
12877
|
-
|
|
12878
|
-
|
|
12879
|
-
}
|
|
12880
|
-
signingPubkey = await this.config.signer.getPublicKeyFromDerivation({
|
|
12881
|
-
type: "leaf" /* LEAF */,
|
|
12882
|
-
path: leafId
|
|
12883
|
-
});
|
|
12884
|
-
}
|
|
12888
|
+
const signingPubkey = await this.config.signer.getPublicKeyFromDerivation({
|
|
12889
|
+
type: "leaf" /* LEAF */,
|
|
12890
|
+
path: leafId
|
|
12891
|
+
});
|
|
12885
12892
|
const address2 = await this.depositService.generateDepositAddress({
|
|
12886
12893
|
signingPubkey,
|
|
12887
|
-
leafId
|
|
12888
|
-
isStatic
|
|
12894
|
+
leafId
|
|
12889
12895
|
});
|
|
12890
12896
|
if (!address2.depositAddress) {
|
|
12891
12897
|
throw new RPCError("Failed to generate deposit address", {
|
|
@@ -12912,7 +12918,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12912
12918
|
* @param offset - Pagination offset (default 0).
|
|
12913
12919
|
* @returns {Promise<{ txid: string, vout: number }[]>} List of confirmed UTXOs.
|
|
12914
12920
|
*/
|
|
12915
|
-
async getUtxosForDepositAddress(depositAddress, limit = 100, offset = 0) {
|
|
12921
|
+
async getUtxosForDepositAddress(depositAddress, limit = 100, offset = 0, excludeClaimed = false) {
|
|
12916
12922
|
if (!depositAddress) {
|
|
12917
12923
|
throw new ValidationError("Deposit address cannot be empty", {
|
|
12918
12924
|
field: "depositAddress"
|
|
@@ -12926,10 +12932,11 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12926
12932
|
address: depositAddress,
|
|
12927
12933
|
network: NetworkToProto[this.config.getNetwork()],
|
|
12928
12934
|
limit,
|
|
12929
|
-
offset
|
|
12935
|
+
offset,
|
|
12936
|
+
excludeClaimed
|
|
12930
12937
|
});
|
|
12931
12938
|
return response.utxos.map((utxo) => ({
|
|
12932
|
-
txid:
|
|
12939
|
+
txid: bytesToHex10(utxo.txid),
|
|
12933
12940
|
vout: utxo.vout
|
|
12934
12941
|
})) ?? [];
|
|
12935
12942
|
} catch (error) {
|
|
@@ -12999,7 +13006,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12999
13006
|
if (network === BitcoinNetwork_default.FUTURE_VALUE) {
|
|
13000
13007
|
network = BitcoinNetwork_default.REGTEST;
|
|
13001
13008
|
}
|
|
13002
|
-
const depositSecretKey =
|
|
13009
|
+
const depositSecretKey = bytesToHex10(
|
|
13003
13010
|
await this.config.signer.getStaticDepositSecretKey(0)
|
|
13004
13011
|
);
|
|
13005
13012
|
const message = await this.getStaticDepositSigningPayload(
|
|
@@ -13012,7 +13019,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
13012
13019
|
);
|
|
13013
13020
|
const hashBuffer = sha25612(message);
|
|
13014
13021
|
const signatureBytes = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
|
|
13015
|
-
const signature =
|
|
13022
|
+
const signature = bytesToHex10(signatureBytes);
|
|
13016
13023
|
const response = await this.sspClient.claimStaticDeposit({
|
|
13017
13024
|
transactionId,
|
|
13018
13025
|
outputIndex,
|
|
@@ -13164,7 +13171,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
13164
13171
|
networkJSON.toLowerCase(),
|
|
13165
13172
|
2 /* Refund */,
|
|
13166
13173
|
creditAmountSats,
|
|
13167
|
-
|
|
13174
|
+
bytesToHex10(spendTxSighash)
|
|
13168
13175
|
);
|
|
13169
13176
|
const hashBuffer = sha25612(message);
|
|
13170
13177
|
const swapResponseUserSignature = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
|
|
@@ -13209,6 +13216,64 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
13209
13216
|
});
|
|
13210
13217
|
return tx.hex;
|
|
13211
13218
|
}
|
|
13219
|
+
/**
|
|
13220
|
+
* Refunds a static deposit and broadcasts the transaction to the network.
|
|
13221
|
+
*
|
|
13222
|
+
* @param {Object} params - The refund parameters
|
|
13223
|
+
* @param {string} params.depositTransactionId - The ID of the transaction
|
|
13224
|
+
* @param {number} [params.outputIndex] - The index of the output
|
|
13225
|
+
* @param {string} params.destinationAddress - The destination address
|
|
13226
|
+
* @param {number} [params.satsPerVbyteFee] - The fee per vbyte to refund
|
|
13227
|
+
* @returns {Promise<string>} The transaction ID
|
|
13228
|
+
*/
|
|
13229
|
+
async refundAndBroadcastStaticDeposit({
|
|
13230
|
+
depositTransactionId,
|
|
13231
|
+
outputIndex,
|
|
13232
|
+
destinationAddress,
|
|
13233
|
+
satsPerVbyteFee
|
|
13234
|
+
}) {
|
|
13235
|
+
const txHex = await this.refundStaticDeposit({
|
|
13236
|
+
depositTransactionId,
|
|
13237
|
+
outputIndex,
|
|
13238
|
+
destinationAddress,
|
|
13239
|
+
satsPerVbyteFee
|
|
13240
|
+
});
|
|
13241
|
+
return await this.broadcastTx(txHex);
|
|
13242
|
+
}
|
|
13243
|
+
/**
|
|
13244
|
+
* Broadcasts a transaction to the network.
|
|
13245
|
+
*
|
|
13246
|
+
* @param {string} txHex - The hex of the transaction
|
|
13247
|
+
* @returns {Promise<string>} The transaction ID
|
|
13248
|
+
*/
|
|
13249
|
+
async broadcastTx(txHex) {
|
|
13250
|
+
if (!txHex) {
|
|
13251
|
+
throw new ValidationError("Transaction hex cannot be empty", {
|
|
13252
|
+
field: "txHex"
|
|
13253
|
+
});
|
|
13254
|
+
}
|
|
13255
|
+
const { fetch, Headers: Headers2 } = getFetch();
|
|
13256
|
+
const baseUrl = this.config.getElectrsUrl();
|
|
13257
|
+
const headers = new Headers2();
|
|
13258
|
+
if (this.config.getNetwork() === 4 /* LOCAL */) {
|
|
13259
|
+
const localFaucet = BitcoinFaucet.getInstance();
|
|
13260
|
+
const response = await localFaucet.broadcastTx(txHex);
|
|
13261
|
+
return response;
|
|
13262
|
+
} else {
|
|
13263
|
+
if (this.config.getNetwork() === 3 /* REGTEST */) {
|
|
13264
|
+
const auth = btoa(
|
|
13265
|
+
`${ELECTRS_CREDENTIALS.username}:${ELECTRS_CREDENTIALS.password}`
|
|
13266
|
+
);
|
|
13267
|
+
headers.set("Authorization", `Basic ${auth}`);
|
|
13268
|
+
}
|
|
13269
|
+
const response = await fetch(`${baseUrl}/tx`, {
|
|
13270
|
+
method: "POST",
|
|
13271
|
+
body: txHex,
|
|
13272
|
+
headers
|
|
13273
|
+
});
|
|
13274
|
+
return response.text();
|
|
13275
|
+
}
|
|
13276
|
+
}
|
|
13212
13277
|
async getStaticDepositSigningPayload(transactionID, outputIndex, network, requestType, creditAmountSats, sspSignature) {
|
|
13213
13278
|
const encoder = new TextEncoder();
|
|
13214
13279
|
const parts = [];
|
|
@@ -13687,7 +13752,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
13687
13752
|
}
|
|
13688
13753
|
return mapTransferToWalletTransfer(
|
|
13689
13754
|
transfer,
|
|
13690
|
-
|
|
13755
|
+
bytesToHex10(await this.config.signer.getIdentityPublicKey())
|
|
13691
13756
|
);
|
|
13692
13757
|
});
|
|
13693
13758
|
}
|
|
@@ -13947,24 +14012,6 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
13947
14012
|
(result) => result.status === "fulfilled" && result.value !== null
|
|
13948
14013
|
).map((result) => result.value);
|
|
13949
14014
|
}
|
|
13950
|
-
/**
|
|
13951
|
-
* Cancels all sender-initiated transfers.
|
|
13952
|
-
*
|
|
13953
|
-
* @returns {Promise<void>}
|
|
13954
|
-
* @private
|
|
13955
|
-
*/
|
|
13956
|
-
async cancelAllSenderInitiatedTransfers() {
|
|
13957
|
-
for (const operator of Object.values(this.config.getSigningOperators())) {
|
|
13958
|
-
const transfers = await this.transferService.queryPendingTransfersBySender(
|
|
13959
|
-
operator.address
|
|
13960
|
-
);
|
|
13961
|
-
for (const transfer of transfers.transfers) {
|
|
13962
|
-
if (transfer.status === 0 /* TRANSFER_STATUS_SENDER_INITIATED */) {
|
|
13963
|
-
await this.transferService.cancelTransfer(transfer, operator.address);
|
|
13964
|
-
}
|
|
13965
|
-
}
|
|
13966
|
-
}
|
|
13967
|
-
}
|
|
13968
14015
|
// ***** Lightning Flow *****
|
|
13969
14016
|
/**
|
|
13970
14017
|
* Creates a Lightning invoice for receiving payments.
|
|
@@ -14043,7 +14090,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
14043
14090
|
const invoice2 = await sspClient.requestLightningReceive({
|
|
14044
14091
|
amountSats: amountSats2,
|
|
14045
14092
|
network: bitcoinNetwork,
|
|
14046
|
-
paymentHash:
|
|
14093
|
+
paymentHash: bytesToHex10(paymentHash),
|
|
14047
14094
|
expirySecs: expirySeconds,
|
|
14048
14095
|
memo: memo2,
|
|
14049
14096
|
includeSparkAddress,
|
|
@@ -14573,7 +14620,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
14573
14620
|
return transfers?.[0];
|
|
14574
14621
|
}
|
|
14575
14622
|
async constructTransfersWithUserRequest(transfers) {
|
|
14576
|
-
const identityPublicKey =
|
|
14623
|
+
const identityPublicKey = bytesToHex10(
|
|
14577
14624
|
await this.config.signer.getIdentityPublicKey()
|
|
14578
14625
|
);
|
|
14579
14626
|
const userRequests = await this.sspClient?.getTransfers(
|
|
@@ -14817,7 +14864,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
14817
14864
|
hash,
|
|
14818
14865
|
compact
|
|
14819
14866
|
);
|
|
14820
|
-
return
|
|
14867
|
+
return bytesToHex10(signature);
|
|
14821
14868
|
}
|
|
14822
14869
|
/**
|
|
14823
14870
|
* Validates a message with the identity key.
|
|
@@ -14875,7 +14922,7 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
14875
14922
|
publicKey,
|
|
14876
14923
|
this.config.getNetwork()
|
|
14877
14924
|
);
|
|
14878
|
-
if (
|
|
14925
|
+
if (bytesToHex10(script) === bytesToHex10(identityScript)) {
|
|
14879
14926
|
try {
|
|
14880
14927
|
this.config.signer.signTransactionIndex(tx, i, publicKey);
|
|
14881
14928
|
inputsSigned++;
|
|
@@ -14919,13 +14966,13 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
14919
14966
|
depositPubKey,
|
|
14920
14967
|
this.config.getNetwork()
|
|
14921
14968
|
);
|
|
14922
|
-
if (
|
|
14969
|
+
if (bytesToHex10(script) === bytesToHex10(identityScript)) {
|
|
14923
14970
|
return {
|
|
14924
14971
|
publicKey: identityPubKey,
|
|
14925
14972
|
keyType: "identity"
|
|
14926
14973
|
};
|
|
14927
14974
|
}
|
|
14928
|
-
if (
|
|
14975
|
+
if (bytesToHex10(script) === bytesToHex10(depositScript)) {
|
|
14929
14976
|
return {
|
|
14930
14977
|
publicKey: depositPubKey,
|
|
14931
14978
|
keyType: "deposit"
|
|
@@ -15385,7 +15432,7 @@ async function isTxBroadcast(txid, baseUrl, network) {
|
|
|
15385
15432
|
}
|
|
15386
15433
|
|
|
15387
15434
|
// src/utils/unilateral-exit.ts
|
|
15388
|
-
import { bytesToHex as
|
|
15435
|
+
import { bytesToHex as bytesToHex11, hexToBytes as hexToBytes12 } from "@noble/curves/utils";
|
|
15389
15436
|
import { ripemd160 } from "@noble/hashes/legacy";
|
|
15390
15437
|
import { sha256 as sha25613 } from "@noble/hashes/sha2";
|
|
15391
15438
|
import * as btc4 from "@scure/btc-signer";
|
|
@@ -15456,10 +15503,10 @@ async function constructUnilateralExitTxs(nodeHexStrings, sparkClient, network)
|
|
|
15456
15503
|
}
|
|
15457
15504
|
}
|
|
15458
15505
|
for (const chainNode of chain) {
|
|
15459
|
-
const nodeTx =
|
|
15506
|
+
const nodeTx = bytesToHex11(chainNode.nodeTx);
|
|
15460
15507
|
transactions.push(nodeTx);
|
|
15461
15508
|
if (chainNode.id === node.id) {
|
|
15462
|
-
const refundTx =
|
|
15509
|
+
const refundTx = bytesToHex11(chainNode.refundTx);
|
|
15463
15510
|
transactions.push(refundTx);
|
|
15464
15511
|
}
|
|
15465
15512
|
}
|
|
@@ -15565,7 +15612,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
15565
15612
|
}
|
|
15566
15613
|
}
|
|
15567
15614
|
for (const chainNode of chain) {
|
|
15568
|
-
let nodeTxHex =
|
|
15615
|
+
let nodeTxHex = bytesToHex11(chainNode.nodeTx);
|
|
15569
15616
|
try {
|
|
15570
15617
|
const txObj = getTxFromRawTxHex(nodeTxHex);
|
|
15571
15618
|
const txid = getTxId(txObj);
|
|
@@ -15582,7 +15629,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
15582
15629
|
for (let i = txObj.outputsLength - 1; i >= 0; i--) {
|
|
15583
15630
|
const output = txObj.getOutput(i);
|
|
15584
15631
|
if (output?.amount === 0n && output.script) {
|
|
15585
|
-
anchorOutputScriptHex =
|
|
15632
|
+
anchorOutputScriptHex = bytesToHex11(output.script);
|
|
15586
15633
|
break;
|
|
15587
15634
|
}
|
|
15588
15635
|
}
|
|
@@ -15607,7 +15654,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
15607
15654
|
var feeBumpOut = feeBumpTx.outputsLength === 1 ? feeBumpTx.getOutput(0) : null;
|
|
15608
15655
|
var feeBumpOutPubKey = null;
|
|
15609
15656
|
for (const usedUtxo of usedUtxos) {
|
|
15610
|
-
if (feeBumpOut &&
|
|
15657
|
+
if (feeBumpOut && bytesToHex11(feeBumpOut.script) == usedUtxo.script) {
|
|
15611
15658
|
feeBumpOutPubKey = usedUtxo.publicKey;
|
|
15612
15659
|
}
|
|
15613
15660
|
const index = availableUtxos.findIndex(
|
|
@@ -15622,20 +15669,20 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
15622
15669
|
txid: getTxId(feeBumpTx),
|
|
15623
15670
|
vout: 0,
|
|
15624
15671
|
value: feeBumpOut.amount,
|
|
15625
|
-
script:
|
|
15672
|
+
script: bytesToHex11(feeBumpOut.script),
|
|
15626
15673
|
publicKey: feeBumpOutPubKey
|
|
15627
15674
|
});
|
|
15628
15675
|
const finalNodeTx = correctedParentTx || nodeTxHex;
|
|
15629
15676
|
txPackages.push({ tx: finalNodeTx, feeBumpPsbt: nodeFeeBumpPsbt });
|
|
15630
15677
|
if (chainNode.id === node.id) {
|
|
15631
|
-
let refundTxHex =
|
|
15678
|
+
let refundTxHex = bytesToHex11(chainNode.refundTx);
|
|
15632
15679
|
try {
|
|
15633
15680
|
const txObj = getTxFromRawTxHex(refundTxHex);
|
|
15634
15681
|
let anchorOutputScriptHex;
|
|
15635
15682
|
for (let i = txObj.outputsLength - 1; i >= 0; i--) {
|
|
15636
15683
|
const output = txObj.getOutput(i);
|
|
15637
15684
|
if (output?.amount === 0n && output.script) {
|
|
15638
|
-
anchorOutputScriptHex =
|
|
15685
|
+
anchorOutputScriptHex = bytesToHex11(output.script);
|
|
15639
15686
|
break;
|
|
15640
15687
|
}
|
|
15641
15688
|
}
|
|
@@ -15663,7 +15710,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
15663
15710
|
var feeBumpOut = feeBumpTx2.outputsLength === 1 ? feeBumpTx2.getOutput(0) : null;
|
|
15664
15711
|
var feeBumpOutPubKey = null;
|
|
15665
15712
|
for (const usedUtxo of usedUtxos) {
|
|
15666
|
-
if (feeBumpOut &&
|
|
15713
|
+
if (feeBumpOut && bytesToHex11(feeBumpOut.script) == usedUtxo.script) {
|
|
15667
15714
|
feeBumpOutPubKey = usedUtxo.publicKey;
|
|
15668
15715
|
}
|
|
15669
15716
|
const index = availableUtxos.findIndex(
|
|
@@ -15678,7 +15725,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
15678
15725
|
txid: getTxId(feeBumpTx2),
|
|
15679
15726
|
vout: 0,
|
|
15680
15727
|
value: feeBumpOut.amount,
|
|
15681
|
-
script:
|
|
15728
|
+
script: bytesToHex11(feeBumpOut.script),
|
|
15682
15729
|
publicKey: feeBumpOutPubKey
|
|
15683
15730
|
});
|
|
15684
15731
|
txPackages.push({
|
|
@@ -15776,7 +15823,7 @@ function constructFeeBumpTx(txHex, utxos, feeRate, previousFeeBumpTx) {
|
|
|
15776
15823
|
const pubKeyHash = hash160(hexToBytes12(fundingUtxo.publicKey));
|
|
15777
15824
|
const scriptToUse = new Uint8Array([0, 20, ...pubKeyHash]);
|
|
15778
15825
|
const providedScript = hexToBytes12(fundingUtxo.script);
|
|
15779
|
-
if (
|
|
15826
|
+
if (bytesToHex11(scriptToUse) !== bytesToHex11(providedScript)) {
|
|
15780
15827
|
throw new Error(
|
|
15781
15828
|
`\u274C Derived script doesn't match provided script for UTXO ${i + 1}.`
|
|
15782
15829
|
);
|
|
@@ -15841,7 +15888,7 @@ function constructFeeBumpTx(txHex, utxos, feeRate, previousFeeBumpTx) {
|
|
|
15841
15888
|
}
|
|
15842
15889
|
let psbtHex;
|
|
15843
15890
|
try {
|
|
15844
|
-
psbtHex =
|
|
15891
|
+
psbtHex = bytesToHex11(builder.toPSBT());
|
|
15845
15892
|
} catch (error) {
|
|
15846
15893
|
throw new Error(`Failed to extract transaction: ${error}`);
|
|
15847
15894
|
}
|