@buildonspark/spark-sdk 0.2.4 → 0.2.5
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 +9 -0
- package/dist/{chunk-3SEOTO43.js → chunk-3SPMJMUX.js} +3 -2
- package/dist/{chunk-WAQKYSDI.js → chunk-CQY5ML2A.js} +3 -2
- package/dist/{chunk-TVUMSHWA.js → chunk-LQZL2D3Y.js} +1 -1
- package/dist/{chunk-W4ZRBSWM.js → chunk-U7LRIWTF.js} +174 -45
- package/dist/{client-KhNkrXz4.d.cts → client-C88GCTPB.d.cts} +199 -104
- package/dist/{client-BF4cn8F4.d.ts → client-Dg6vS_2I.d.ts} +199 -104
- package/dist/debug.cjs +231 -71
- package/dist/debug.d.cts +6 -6
- package/dist/debug.d.ts +6 -6
- package/dist/debug.js +3 -3
- package/dist/graphql/objects/index.d.cts +6 -51
- package/dist/graphql/objects/index.d.ts +6 -51
- package/dist/graphql/objects/index.js +1 -1
- package/dist/index.cjs +208 -45
- package/dist/index.d.cts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +6 -4
- package/dist/index.node.cjs +208 -45
- package/dist/index.node.d.cts +5 -6
- package/dist/index.node.d.ts +5 -6
- package/dist/index.node.js +5 -3
- package/dist/native/index.cjs +208 -45
- package/dist/native/index.d.cts +217 -147
- package/dist/native/index.d.ts +217 -147
- package/dist/native/index.js +209 -45
- package/dist/proto/lrc20.d.cts +1 -1
- package/dist/proto/lrc20.d.ts +1 -1
- 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-B_7nZx6T.d.cts → spark-ESAfZARg.d.cts} +1 -1
- package/dist/{spark-B_7nZx6T.d.ts → spark-ESAfZARg.d.ts} +1 -1
- package/dist/{spark-wallet-C1Tr_VKI.d.ts → spark-wallet-B2WwKN8W.d.ts} +27 -11
- package/dist/{spark-wallet-DG3x2obf.d.cts → spark-wallet-Di65w0Us.d.cts} +27 -11
- package/dist/{spark-wallet.node-CN9LoB_O.d.cts → spark-wallet.node-7R0Rxyj9.d.cts} +1 -1
- package/dist/{spark-wallet.node-CGxoeCpH.d.ts → spark-wallet.node-CSPWOWRu.d.ts} +1 -1
- package/dist/tests/test-utils.cjs +9 -5
- package/dist/tests/test-utils.d.cts +4 -5
- package/dist/tests/test-utils.d.ts +4 -5
- package/dist/tests/test-utils.js +4 -4
- package/dist/types/index.cjs +3 -2
- package/dist/types/index.d.cts +3 -4
- package/dist/types/index.d.ts +3 -4
- package/dist/types/index.js +2 -2
- package/dist/{xchain-address-BHu6CpZC.d.ts → xchain-address-BsveIy5l.d.ts} +5 -4
- package/dist/{xchain-address-HBr6isnc.d.cts → xchain-address-CqRu3F21.d.cts} +5 -4
- package/package.json +1 -1
- package/src/graphql/client.ts +49 -8
- package/src/graphql/objects/SparkWalletUser.ts +1 -1
- package/src/graphql/queries/Transfers.ts +15 -0
- package/src/spark-wallet/spark-wallet.ts +156 -39
- package/src/tests/integration/ssp/static_deposit.test.ts +83 -1
- package/src/tests/integration/ssp/transfers.test.ts +97 -0
- package/src/types/sdk-types.ts +15 -0
- package/src/utils/bitcoin.ts +13 -0
- package/dist/sdk-types-CB9HrW5O.d.cts +0 -44
- package/dist/sdk-types-CkRNraXT.d.ts +0 -44
- package/src/graphql/queries/Transfer.ts +0 -10
package/dist/native/index.cjs
CHANGED
|
@@ -1367,6 +1367,7 @@ __export(index_exports, {
|
|
|
1367
1367
|
getSparkAddressFromTaproot: () => getSparkAddressFromTaproot,
|
|
1368
1368
|
getTransactionSequence: () => getTransactionSequence,
|
|
1369
1369
|
getTransferPackageSigningPayload: () => getTransferPackageSigningPayload,
|
|
1370
|
+
getTxEstimatedVbytesSizeByNumberOfInputsOutputs: () => getTxEstimatedVbytesSizeByNumberOfInputsOutputs,
|
|
1370
1371
|
getTxFromRawTxBytes: () => getTxFromRawTxBytes,
|
|
1371
1372
|
getTxFromRawTxHex: () => getTxFromRawTxHex,
|
|
1372
1373
|
getTxId: () => getTxId,
|
|
@@ -16553,6 +16554,12 @@ function getTxId(tx) {
|
|
|
16553
16554
|
function getTxIdNoReverse(tx) {
|
|
16554
16555
|
return (0, import_utils5.bytesToHex)((0, import_sha2.sha256)((0, import_sha2.sha256)(tx.toBytes(true))));
|
|
16555
16556
|
}
|
|
16557
|
+
function getTxEstimatedVbytesSizeByNumberOfInputsOutputs(numInputs, numOutputs) {
|
|
16558
|
+
const TX_OVERHEAD = 10;
|
|
16559
|
+
const IN_VBYTES = 150;
|
|
16560
|
+
const OUT_VBYTES = 34;
|
|
16561
|
+
return TX_OVERHEAD + numInputs * IN_VBYTES + numOutputs * OUT_VBYTES;
|
|
16562
|
+
}
|
|
16556
16563
|
|
|
16557
16564
|
// src/utils/keys.ts
|
|
16558
16565
|
init_buffer();
|
|
@@ -16935,6 +16942,20 @@ var import_core = require("@lightsparkdev/core");
|
|
|
16935
16942
|
|
|
16936
16943
|
// src/graphql/objects/ClaimStaticDepositStatus.ts
|
|
16937
16944
|
init_buffer();
|
|
16945
|
+
var ClaimStaticDepositStatus = /* @__PURE__ */ ((ClaimStaticDepositStatus2) => {
|
|
16946
|
+
ClaimStaticDepositStatus2["FUTURE_VALUE"] = "FUTURE_VALUE";
|
|
16947
|
+
ClaimStaticDepositStatus2["CREATED"] = "CREATED";
|
|
16948
|
+
ClaimStaticDepositStatus2["TRANSFER_CREATED"] = "TRANSFER_CREATED";
|
|
16949
|
+
ClaimStaticDepositStatus2["TRANSFER_CREATION_FAILED"] = "TRANSFER_CREATION_FAILED";
|
|
16950
|
+
ClaimStaticDepositStatus2["REFUND_SIGNING_COMMITMENTS_QUERYING_FAILED"] = "REFUND_SIGNING_COMMITMENTS_QUERYING_FAILED";
|
|
16951
|
+
ClaimStaticDepositStatus2["REFUND_SIGNING_FAILED"] = "REFUND_SIGNING_FAILED";
|
|
16952
|
+
ClaimStaticDepositStatus2["UTXO_SWAPPING_FAILED"] = "UTXO_SWAPPING_FAILED";
|
|
16953
|
+
ClaimStaticDepositStatus2["TRANSFER_COMPLETED"] = "TRANSFER_COMPLETED";
|
|
16954
|
+
ClaimStaticDepositStatus2["SPEND_TX_CREATED"] = "SPEND_TX_CREATED";
|
|
16955
|
+
ClaimStaticDepositStatus2["SPEND_TX_BROADCAST"] = "SPEND_TX_BROADCAST";
|
|
16956
|
+
return ClaimStaticDepositStatus2;
|
|
16957
|
+
})(ClaimStaticDepositStatus || {});
|
|
16958
|
+
var ClaimStaticDepositStatus_default = ClaimStaticDepositStatus;
|
|
16938
16959
|
|
|
16939
16960
|
// src/graphql/objects/CurrencyAmount.ts
|
|
16940
16961
|
init_buffer();
|
|
@@ -16977,6 +16998,26 @@ var CurrencyAmountToJson = (obj) => {
|
|
|
16977
16998
|
};
|
|
16978
16999
|
};
|
|
16979
17000
|
|
|
17001
|
+
// src/graphql/objects/ClaimStaticDeposit.ts
|
|
17002
|
+
var ClaimStaticDepositFromJson = (obj) => {
|
|
17003
|
+
return {
|
|
17004
|
+
id: obj["claim_static_deposit_id"],
|
|
17005
|
+
createdAt: obj["claim_static_deposit_created_at"],
|
|
17006
|
+
updatedAt: obj["claim_static_deposit_updated_at"],
|
|
17007
|
+
network: BitcoinNetwork_default[obj["claim_static_deposit_network"]] ?? BitcoinNetwork_default.FUTURE_VALUE,
|
|
17008
|
+
creditAmount: CurrencyAmountFromJson(
|
|
17009
|
+
obj["claim_static_deposit_credit_amount"]
|
|
17010
|
+
),
|
|
17011
|
+
maxFee: CurrencyAmountFromJson(obj["claim_static_deposit_max_fee"]),
|
|
17012
|
+
status: ClaimStaticDepositStatus_default[obj["claim_static_deposit_status"]] ?? ClaimStaticDepositStatus_default.FUTURE_VALUE,
|
|
17013
|
+
transactionId: obj["claim_static_deposit_transaction_id"],
|
|
17014
|
+
outputIndex: obj["claim_static_deposit_output_index"],
|
|
17015
|
+
bitcoinNetwork: BitcoinNetwork_default[obj["claim_static_deposit_bitcoin_network"]] ?? BitcoinNetwork_default.FUTURE_VALUE,
|
|
17016
|
+
typename: "ClaimStaticDeposit",
|
|
17017
|
+
transferSparkId: obj["claim_static_deposit_transfer_spark_id"]
|
|
17018
|
+
};
|
|
17019
|
+
};
|
|
17020
|
+
|
|
16980
17021
|
// src/graphql/objects/ClaimStaticDepositRequestType.ts
|
|
16981
17022
|
init_buffer();
|
|
16982
17023
|
var ClaimStaticDepositRequestType = /* @__PURE__ */ ((ClaimStaticDepositRequestType2) => {
|
|
@@ -17844,7 +17885,7 @@ function mapTransferLeafToWalletTransferLeaf(proto) {
|
|
|
17844
17885
|
intermediateRefundTx: (0, import_utils7.bytesToHex)(proto.intermediateRefundTx)
|
|
17845
17886
|
};
|
|
17846
17887
|
}
|
|
17847
|
-
function mapTransferToWalletTransfer(proto, identityPublicKey) {
|
|
17888
|
+
function mapTransferToWalletTransfer(proto, identityPublicKey, userRequest) {
|
|
17848
17889
|
const receiverIdentityPublicKey = (0, import_utils7.bytesToHex)(proto.receiverIdentityPublicKey);
|
|
17849
17890
|
const senderIdentityPublicKey = (0, import_utils7.bytesToHex)(proto.senderIdentityPublicKey);
|
|
17850
17891
|
return {
|
|
@@ -17858,7 +17899,8 @@ function mapTransferToWalletTransfer(proto, identityPublicKey) {
|
|
|
17858
17899
|
createdTime: proto.createdTime ? new Date(proto.createdTime) : void 0,
|
|
17859
17900
|
updatedTime: proto.updatedTime ? new Date(proto.updatedTime) : void 0,
|
|
17860
17901
|
type: TransferType[proto.type],
|
|
17861
|
-
transferDirection: receiverIdentityPublicKey === identityPublicKey ? "INCOMING" /* INCOMING */ : "OUTGOING" /* OUTGOING
|
|
17902
|
+
transferDirection: receiverIdentityPublicKey === identityPublicKey ? "INCOMING" /* INCOMING */ : "OUTGOING" /* OUTGOING */,
|
|
17903
|
+
userRequest
|
|
17862
17904
|
};
|
|
17863
17905
|
}
|
|
17864
17906
|
|
|
@@ -19372,7 +19414,7 @@ init_buffer();
|
|
|
19372
19414
|
var import_core8 = require("@lightsparkdev/core");
|
|
19373
19415
|
var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
|
|
19374
19416
|
var isBun = globalThis.Bun !== void 0;
|
|
19375
|
-
var packageVersion = true ? "0.2.
|
|
19417
|
+
var packageVersion = true ? "0.2.5" : "unknown";
|
|
19376
19418
|
var baseEnvStr = "unknown";
|
|
19377
19419
|
if (isBun) {
|
|
19378
19420
|
const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
|
|
@@ -20465,15 +20507,19 @@ var LightningSendFeeEstimate = `
|
|
|
20465
20507
|
${FRAGMENT13}
|
|
20466
20508
|
`;
|
|
20467
20509
|
|
|
20468
|
-
// src/graphql/queries/
|
|
20510
|
+
// src/graphql/queries/Transfers.ts
|
|
20469
20511
|
init_buffer();
|
|
20470
|
-
var
|
|
20471
|
-
query
|
|
20472
|
-
|
|
20512
|
+
var GetTransfers = `
|
|
20513
|
+
query Transfers($transfer_spark_ids: [UUID!]!) {
|
|
20514
|
+
transfers(transfer_spark_ids: $transfer_spark_ids) {
|
|
20473
20515
|
...TransferFragment
|
|
20516
|
+
transfer_user_request: user_request {
|
|
20517
|
+
...UserRequestFragment
|
|
20518
|
+
}
|
|
20474
20519
|
}
|
|
20475
20520
|
}
|
|
20476
20521
|
${FRAGMENT2}
|
|
20522
|
+
${FRAGMENT6}
|
|
20477
20523
|
`;
|
|
20478
20524
|
|
|
20479
20525
|
// src/graphql/queries/UserRequest.ts
|
|
@@ -20830,14 +20876,47 @@ var SspClient = class {
|
|
|
20830
20876
|
}
|
|
20831
20877
|
});
|
|
20832
20878
|
}
|
|
20833
|
-
async
|
|
20879
|
+
async getTransfers(ids) {
|
|
20834
20880
|
return await this.executeRawQuery({
|
|
20835
|
-
queryPayload:
|
|
20881
|
+
queryPayload: GetTransfers,
|
|
20836
20882
|
variables: {
|
|
20837
|
-
|
|
20883
|
+
transfer_spark_ids: ids
|
|
20838
20884
|
},
|
|
20839
20885
|
constructObject: (response) => {
|
|
20840
|
-
return
|
|
20886
|
+
return response.transfers.map((transfer) => {
|
|
20887
|
+
const transferObj = TransferFromJson(
|
|
20888
|
+
transfer
|
|
20889
|
+
);
|
|
20890
|
+
switch (transfer.transfer_user_request.__typename) {
|
|
20891
|
+
case "ClaimStaticDeposit":
|
|
20892
|
+
transferObj.userRequest = ClaimStaticDepositFromJson(
|
|
20893
|
+
transfer.transfer_user_request
|
|
20894
|
+
);
|
|
20895
|
+
break;
|
|
20896
|
+
case "CoopExitRequest":
|
|
20897
|
+
transferObj.userRequest = CoopExitRequestFromJson(
|
|
20898
|
+
transfer.transfer_user_request
|
|
20899
|
+
);
|
|
20900
|
+
break;
|
|
20901
|
+
case "LeavesSwapRequest":
|
|
20902
|
+
transferObj.userRequest = LeavesSwapRequestFromJson(
|
|
20903
|
+
transfer.transfer_user_request
|
|
20904
|
+
);
|
|
20905
|
+
break;
|
|
20906
|
+
case "LightningReceiveRequest":
|
|
20907
|
+
transferObj.userRequest = LightningReceiveRequestFromJson(
|
|
20908
|
+
transfer.transfer_user_request
|
|
20909
|
+
);
|
|
20910
|
+
break;
|
|
20911
|
+
case "LightningSendRequest":
|
|
20912
|
+
transferObj.userRequest = LightningSendRequestFromJson(
|
|
20913
|
+
transfer.transfer_user_request
|
|
20914
|
+
);
|
|
20915
|
+
break;
|
|
20916
|
+
}
|
|
20917
|
+
const { userRequestId, ...rest } = transferObj;
|
|
20918
|
+
return rest;
|
|
20919
|
+
});
|
|
20841
20920
|
}
|
|
20842
20921
|
});
|
|
20843
20922
|
}
|
|
@@ -32275,9 +32354,22 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32275
32354
|
const identityPublicKey = (0, import_utils24.bytesToHex)(
|
|
32276
32355
|
await this.config.signer.getIdentityPublicKey()
|
|
32277
32356
|
);
|
|
32357
|
+
const userRequests = await this.sspClient?.getTransfers(
|
|
32358
|
+
transfers.transfers.map((transfer) => transfer.id)
|
|
32359
|
+
);
|
|
32360
|
+
const userRequestsMap = /* @__PURE__ */ new Map();
|
|
32361
|
+
for (const userRequest of userRequests || []) {
|
|
32362
|
+
if (userRequest && userRequest.sparkId && userRequest.userRequest) {
|
|
32363
|
+
userRequestsMap.set(userRequest.sparkId, userRequest.userRequest);
|
|
32364
|
+
}
|
|
32365
|
+
}
|
|
32278
32366
|
return {
|
|
32279
32367
|
transfers: transfers.transfers.map(
|
|
32280
|
-
(transfer) => mapTransferToWalletTransfer(
|
|
32368
|
+
(transfer) => mapTransferToWalletTransfer(
|
|
32369
|
+
transfer,
|
|
32370
|
+
identityPublicKey,
|
|
32371
|
+
userRequestsMap.get(transfer.id)
|
|
32372
|
+
)
|
|
32281
32373
|
),
|
|
32282
32374
|
offset: transfers.offset
|
|
32283
32375
|
};
|
|
@@ -32460,7 +32552,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32460
32552
|
network = BitcoinNetwork_default.REGTEST;
|
|
32461
32553
|
}
|
|
32462
32554
|
if (outputIndex === void 0) {
|
|
32463
|
-
outputIndex = await this.getDepositTransactionVout(
|
|
32555
|
+
outputIndex = await this.getDepositTransactionVout({
|
|
32556
|
+
txid: transactionId
|
|
32557
|
+
});
|
|
32464
32558
|
}
|
|
32465
32559
|
const quote = await sspClient.getClaimDepositQuote({
|
|
32466
32560
|
transactionId,
|
|
@@ -32491,7 +32585,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32491
32585
|
throw new Error("SSP client not initialized");
|
|
32492
32586
|
}
|
|
32493
32587
|
if (outputIndex === void 0) {
|
|
32494
|
-
outputIndex = await this.getDepositTransactionVout(
|
|
32588
|
+
outputIndex = await this.getDepositTransactionVout({
|
|
32589
|
+
txid: transactionId
|
|
32590
|
+
});
|
|
32495
32591
|
}
|
|
32496
32592
|
let network = this.config.getSspNetwork();
|
|
32497
32593
|
if (network === BitcoinNetwork_default.FUTURE_VALUE) {
|
|
@@ -32525,25 +32621,94 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32525
32621
|
}
|
|
32526
32622
|
return response;
|
|
32527
32623
|
}
|
|
32624
|
+
/**
|
|
32625
|
+
* Get a quote on how much credit you can claim for a deposit from the SSP. If the quote charges less fees than the max fee, claim the deposit.
|
|
32626
|
+
*
|
|
32627
|
+
* @param {Object} params - The parameters object
|
|
32628
|
+
* @param {string} params.transactionId - The ID of the transaction
|
|
32629
|
+
* @param {number} params.maxFee - The maximum fee to claim the deposit for
|
|
32630
|
+
* @param {number} [params.outputIndex] - The index of the output
|
|
32631
|
+
* @returns {Promise<StaticDepositQuoteOutput>} Quote for claiming a deposit to a static deposit address
|
|
32632
|
+
*/
|
|
32633
|
+
async claimStaticDepositWithMaxFee({
|
|
32634
|
+
transactionId,
|
|
32635
|
+
maxFee,
|
|
32636
|
+
outputIndex
|
|
32637
|
+
}) {
|
|
32638
|
+
const sspClient = this.getSspClient();
|
|
32639
|
+
let network = this.config.getSspNetwork();
|
|
32640
|
+
if (network === BitcoinNetwork_default.FUTURE_VALUE) {
|
|
32641
|
+
network = BitcoinNetwork_default.REGTEST;
|
|
32642
|
+
}
|
|
32643
|
+
const depositTx = await this.getDepositTransaction(transactionId);
|
|
32644
|
+
if (outputIndex === void 0) {
|
|
32645
|
+
outputIndex = await this.getDepositTransactionVout({
|
|
32646
|
+
txid: transactionId,
|
|
32647
|
+
depositTx
|
|
32648
|
+
});
|
|
32649
|
+
}
|
|
32650
|
+
const depositAmount = Number(depositTx.getOutput(outputIndex).amount);
|
|
32651
|
+
const quote = await sspClient.getClaimDepositQuote({
|
|
32652
|
+
transactionId,
|
|
32653
|
+
outputIndex,
|
|
32654
|
+
network
|
|
32655
|
+
});
|
|
32656
|
+
if (!quote) {
|
|
32657
|
+
throw new Error("Failed to get claim deposit quote");
|
|
32658
|
+
}
|
|
32659
|
+
const { creditAmountSats, signature: sspSignature } = quote;
|
|
32660
|
+
const feeCharged = depositAmount - creditAmountSats;
|
|
32661
|
+
if (feeCharged > maxFee) {
|
|
32662
|
+
throw new ValidationError("Fee larger than max fee", {
|
|
32663
|
+
field: "feeCharged",
|
|
32664
|
+
value: feeCharged
|
|
32665
|
+
});
|
|
32666
|
+
}
|
|
32667
|
+
const response = await this.claimStaticDeposit({
|
|
32668
|
+
transactionId,
|
|
32669
|
+
creditAmountSats,
|
|
32670
|
+
sspSignature,
|
|
32671
|
+
outputIndex
|
|
32672
|
+
});
|
|
32673
|
+
if (!response) {
|
|
32674
|
+
throw new Error("Failed to claim static deposit");
|
|
32675
|
+
}
|
|
32676
|
+
return response;
|
|
32677
|
+
}
|
|
32528
32678
|
/**
|
|
32529
32679
|
* Refunds a static deposit to a destination address.
|
|
32530
32680
|
*
|
|
32531
|
-
* @param {
|
|
32532
|
-
* @param {
|
|
32533
|
-
* @param {
|
|
32534
|
-
* @param {
|
|
32681
|
+
* @param {Object} params - The refund parameters
|
|
32682
|
+
* @param {string} params.depositTransactionId - The ID of the transaction
|
|
32683
|
+
* @param {number} [params.outputIndex] - The index of the output
|
|
32684
|
+
* @param {string} params.destinationAddress - The destination address
|
|
32685
|
+
* @param {number} [params.fee] - **@deprecated** The fee to refund
|
|
32686
|
+
* @param {number} [params.satsPerVbyteFee] - The fee per vbyte to refund
|
|
32535
32687
|
* @returns {Promise<string>} The hex of the refund transaction
|
|
32536
32688
|
*/
|
|
32537
32689
|
async refundStaticDeposit({
|
|
32538
32690
|
depositTransactionId,
|
|
32539
32691
|
outputIndex,
|
|
32540
32692
|
destinationAddress,
|
|
32541
|
-
fee
|
|
32693
|
+
fee,
|
|
32694
|
+
satsPerVbyteFee
|
|
32542
32695
|
}) {
|
|
32543
|
-
if (fee
|
|
32696
|
+
if (fee !== void 0) {
|
|
32697
|
+
console.warn(
|
|
32698
|
+
`refundStaticDeposit(): \`fee\` parameter is deprecated and will be removed; please switch to \`satsPerVbyteFee\`.`
|
|
32699
|
+
);
|
|
32700
|
+
}
|
|
32701
|
+
if (fee === void 0 && satsPerVbyteFee === void 0) {
|
|
32702
|
+
throw new ValidationError("Fee or satsPerVbyteFee must be provided");
|
|
32703
|
+
}
|
|
32704
|
+
if (satsPerVbyteFee && satsPerVbyteFee > 150) {
|
|
32705
|
+
throw new ValidationError("satsPerVbyteFee must be less than 150");
|
|
32706
|
+
}
|
|
32707
|
+
const finalFee = satsPerVbyteFee ? satsPerVbyteFee * getTxEstimatedVbytesSizeByNumberOfInputsOutputs(1, 1) : fee;
|
|
32708
|
+
if (finalFee <= 200) {
|
|
32544
32709
|
throw new ValidationError("Fee must be greater than 300", {
|
|
32545
32710
|
field: "fee",
|
|
32546
|
-
value:
|
|
32711
|
+
value: finalFee
|
|
32547
32712
|
});
|
|
32548
32713
|
}
|
|
32549
32714
|
let network = this.config.getNetwork();
|
|
@@ -32551,10 +32716,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32551
32716
|
const networkJSON = networkToJSON(networkType);
|
|
32552
32717
|
const depositTx = await this.getDepositTransaction(depositTransactionId);
|
|
32553
32718
|
if (outputIndex === void 0) {
|
|
32554
|
-
outputIndex = await this.getDepositTransactionVout(
|
|
32719
|
+
outputIndex = await this.getDepositTransactionVout({
|
|
32720
|
+
txid: depositTransactionId,
|
|
32721
|
+
depositTx
|
|
32722
|
+
});
|
|
32555
32723
|
}
|
|
32556
32724
|
const totalAmount = depositTx.getOutput(outputIndex).amount;
|
|
32557
|
-
const creditAmountSats = Number(totalAmount) -
|
|
32725
|
+
const creditAmountSats = Number(totalAmount) - finalFee;
|
|
32558
32726
|
if (creditAmountSats <= 0) {
|
|
32559
32727
|
throw new ValidationError(
|
|
32560
32728
|
"Fee too large. Credit amount must be greater than 0",
|
|
@@ -32602,26 +32770,14 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32602
32770
|
const sparkClient = await this.connectionManager.createSparkClient(
|
|
32603
32771
|
this.config.getCoordinatorAddress()
|
|
32604
32772
|
);
|
|
32605
|
-
const
|
|
32606
|
-
const swapResponse = await sparkClient.initiate_utxo_swap({
|
|
32773
|
+
const swapResponse = await sparkClient.initiate_static_deposit_utxo_refund({
|
|
32607
32774
|
onChainUtxo: {
|
|
32608
32775
|
txid: (0, import_utils24.hexToBytes)(depositTransactionId),
|
|
32609
32776
|
vout: outputIndex,
|
|
32610
32777
|
network: networkType
|
|
32611
32778
|
},
|
|
32612
|
-
requestType: 2 /* Refund */,
|
|
32613
|
-
amount: {
|
|
32614
|
-
creditAmountSats: 0,
|
|
32615
|
-
$case: "creditAmountSats"
|
|
32616
|
-
},
|
|
32617
32779
|
userSignature: swapResponseUserSignature,
|
|
32618
|
-
|
|
32619
|
-
transfer: {
|
|
32620
|
-
transferId,
|
|
32621
|
-
ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
|
|
32622
|
-
receiverIdentityPublicKey: await this.config.signer.getIdentityPublicKey()
|
|
32623
|
-
},
|
|
32624
|
-
spendTxSigningJob: signingJob
|
|
32780
|
+
refundTxSigningJob: signingJob
|
|
32625
32781
|
});
|
|
32626
32782
|
if (!swapResponse) {
|
|
32627
32783
|
throw new Error("Failed to initiate utxo swap");
|
|
@@ -32634,15 +32790,15 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32634
32790
|
path: 0
|
|
32635
32791
|
},
|
|
32636
32792
|
selfCommitment: signingNonceCommitment,
|
|
32637
|
-
statechainCommitments: swapResponse.
|
|
32793
|
+
statechainCommitments: swapResponse.refundTxSigningResult.signingNonceCommitments,
|
|
32638
32794
|
verifyingKey: swapResponse.depositAddress.verifyingPublicKey
|
|
32639
32795
|
});
|
|
32640
32796
|
const signatureResult = await this.config.signer.aggregateFrost({
|
|
32641
32797
|
message: spendTxSighash,
|
|
32642
|
-
statechainSignatures: swapResponse.
|
|
32643
|
-
statechainPublicKeys: swapResponse.
|
|
32798
|
+
statechainSignatures: swapResponse.refundTxSigningResult.signatureShares,
|
|
32799
|
+
statechainPublicKeys: swapResponse.refundTxSigningResult.publicKeys,
|
|
32644
32800
|
verifyingKey: swapResponse.depositAddress.verifyingPublicKey,
|
|
32645
|
-
statechainCommitments: swapResponse.
|
|
32801
|
+
statechainCommitments: swapResponse.refundTxSigningResult.signingNonceCommitments,
|
|
32646
32802
|
selfCommitment: signingNonceCommitment,
|
|
32647
32803
|
publicKey: await this.config.signer.getStaticDepositSigningKey(0),
|
|
32648
32804
|
selfSignature: userSignature
|
|
@@ -32695,8 +32851,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32695
32851
|
}
|
|
32696
32852
|
return payload;
|
|
32697
32853
|
}
|
|
32698
|
-
async getDepositTransactionVout(
|
|
32699
|
-
|
|
32854
|
+
async getDepositTransactionVout({
|
|
32855
|
+
txid,
|
|
32856
|
+
depositTx
|
|
32857
|
+
}) {
|
|
32858
|
+
if (!depositTx) {
|
|
32859
|
+
depositTx = await this.getDepositTransaction(txid);
|
|
32860
|
+
}
|
|
32700
32861
|
const staticDepositAddresses = new Set(
|
|
32701
32862
|
await this.queryStaticDepositAddresses()
|
|
32702
32863
|
);
|
|
@@ -33911,11 +34072,12 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33911
34072
|
* Gets a transfer that has been sent by the SSP to the wallet.
|
|
33912
34073
|
*
|
|
33913
34074
|
* @param {string} id - The ID of the transfer
|
|
33914
|
-
* @returns {Promise<
|
|
34075
|
+
* @returns {Promise<TransferWithUserRequest | undefined>} The transfer
|
|
33915
34076
|
*/
|
|
33916
34077
|
async getTransferFromSsp(id) {
|
|
33917
34078
|
const sspClient = this.getSspClient();
|
|
33918
|
-
|
|
34079
|
+
const transfers = await sspClient.getTransfers([id]);
|
|
34080
|
+
return transfers?.[0];
|
|
33919
34081
|
}
|
|
33920
34082
|
/**
|
|
33921
34083
|
* Gets a transfer, that the wallet is a participant of, in the Spark network.
|
|
@@ -34597,6 +34759,7 @@ setCrypto(globalThis.crypto);
|
|
|
34597
34759
|
getSparkAddressFromTaproot,
|
|
34598
34760
|
getTransactionSequence,
|
|
34599
34761
|
getTransferPackageSigningPayload,
|
|
34762
|
+
getTxEstimatedVbytesSizeByNumberOfInputsOutputs,
|
|
34600
34763
|
getTxFromRawTxBytes,
|
|
34601
34764
|
getTxFromRawTxHex,
|
|
34602
34765
|
getTxId,
|