@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @buildonspark/spark-sdk
|
|
2
2
|
|
|
3
|
+
## 0.2.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Attach the SSP request object to spark transfer if it exists
|
|
8
|
+
- Update static deposit refund flow to take sats per vbyte
|
|
9
|
+
- Allow the creation of multiple refunds in static deposit refund flow
|
|
10
|
+
- Add new function to claim a static deposit while specifying a max fee
|
|
11
|
+
|
|
3
12
|
## 0.2.4
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -35,7 +35,7 @@ function mapTransferLeafToWalletTransferLeaf(proto) {
|
|
|
35
35
|
intermediateRefundTx: bytesToHex(proto.intermediateRefundTx)
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
function mapTransferToWalletTransfer(proto, identityPublicKey) {
|
|
38
|
+
function mapTransferToWalletTransfer(proto, identityPublicKey, userRequest) {
|
|
39
39
|
const receiverIdentityPublicKey = bytesToHex(proto.receiverIdentityPublicKey);
|
|
40
40
|
const senderIdentityPublicKey = bytesToHex(proto.senderIdentityPublicKey);
|
|
41
41
|
return {
|
|
@@ -49,7 +49,8 @@ function mapTransferToWalletTransfer(proto, identityPublicKey) {
|
|
|
49
49
|
createdTime: proto.createdTime ? new Date(proto.createdTime) : void 0,
|
|
50
50
|
updatedTime: proto.updatedTime ? new Date(proto.updatedTime) : void 0,
|
|
51
51
|
type: TransferType[proto.type],
|
|
52
|
-
transferDirection: receiverIdentityPublicKey === identityPublicKey ? "INCOMING" /* INCOMING */ : "OUTGOING" /* OUTGOING
|
|
52
|
+
transferDirection: receiverIdentityPublicKey === identityPublicKey ? "INCOMING" /* INCOMING */ : "OUTGOING" /* OUTGOING */,
|
|
53
|
+
userRequest
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -1498,14 +1498,15 @@ export {
|
|
|
1498
1498
|
LightningSendRequestFromJson,
|
|
1499
1499
|
FRAGMENT6 as FRAGMENT4,
|
|
1500
1500
|
getLightningSendRequestQuery,
|
|
1501
|
+
ClaimStaticDepositStatus_default,
|
|
1502
|
+
ClaimStaticDepositFromJson,
|
|
1503
|
+
getClaimStaticDepositQuery,
|
|
1501
1504
|
ClaimStaticDepositRequestType_default,
|
|
1502
1505
|
CoopExitFeeQuoteFromJson,
|
|
1503
1506
|
FRAGMENT2 as FRAGMENT5,
|
|
1504
1507
|
getCoopExitFeeQuoteQuery,
|
|
1505
|
-
ClaimStaticDepositStatus_default,
|
|
1506
1508
|
FRAGMENT7 as FRAGMENT6,
|
|
1507
1509
|
getUserRequestQuery,
|
|
1508
|
-
getClaimStaticDepositQuery,
|
|
1509
1510
|
SparkUserRequestStatus_default,
|
|
1510
1511
|
SparkUserRequestType_default,
|
|
1511
1512
|
SparkWalletUser_default
|
|
@@ -4,9 +4,10 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
mapTransferToWalletTransfer,
|
|
6
6
|
mapTreeNodeToWalletLeaf
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-3SPMJMUX.js";
|
|
8
8
|
import {
|
|
9
9
|
BitcoinNetwork_default,
|
|
10
|
+
ClaimStaticDepositFromJson,
|
|
10
11
|
ClaimStaticDepositRequestType_default,
|
|
11
12
|
CoopExitFeeQuoteFromJson,
|
|
12
13
|
CurrencyAmountFromJson,
|
|
@@ -22,7 +23,7 @@ import {
|
|
|
22
23
|
LightningSendRequestFromJson,
|
|
23
24
|
SparkCoopExitRequestStatus_default,
|
|
24
25
|
TransferFromJson
|
|
25
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-CQY5ML2A.js";
|
|
26
27
|
import {
|
|
27
28
|
Empty,
|
|
28
29
|
SendLeafKeyTweaks,
|
|
@@ -577,7 +578,7 @@ import * as ecies from "eciesjs";
|
|
|
577
578
|
import { isNode } from "@lightsparkdev/core";
|
|
578
579
|
var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
|
|
579
580
|
var isBun = globalThis.Bun !== void 0;
|
|
580
|
-
var packageVersion = true ? "0.2.
|
|
581
|
+
var packageVersion = true ? "0.2.5" : "unknown";
|
|
581
582
|
var baseEnvStr = "unknown";
|
|
582
583
|
if (isBun) {
|
|
583
584
|
const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
|
|
@@ -2911,6 +2912,12 @@ function getTxId(tx) {
|
|
|
2911
2912
|
function getTxIdNoReverse(tx) {
|
|
2912
2913
|
return bytesToHex4(sha2563(sha2563(tx.toBytes(true))));
|
|
2913
2914
|
}
|
|
2915
|
+
function getTxEstimatedVbytesSizeByNumberOfInputsOutputs(numInputs, numOutputs) {
|
|
2916
|
+
const TX_OVERHEAD = 10;
|
|
2917
|
+
const IN_VBYTES = 150;
|
|
2918
|
+
const OUT_VBYTES = 34;
|
|
2919
|
+
return TX_OVERHEAD + numInputs * IN_VBYTES + numOutputs * OUT_VBYTES;
|
|
2920
|
+
}
|
|
2914
2921
|
|
|
2915
2922
|
// src/utils/transaction.ts
|
|
2916
2923
|
import { Transaction as Transaction2 } from "@scure/btc-signer";
|
|
@@ -7587,14 +7594,18 @@ var LightningSendFeeEstimate = `
|
|
|
7587
7594
|
${FRAGMENT13}
|
|
7588
7595
|
`;
|
|
7589
7596
|
|
|
7590
|
-
// src/graphql/queries/
|
|
7591
|
-
var
|
|
7592
|
-
query
|
|
7593
|
-
|
|
7597
|
+
// src/graphql/queries/Transfers.ts
|
|
7598
|
+
var GetTransfers = `
|
|
7599
|
+
query Transfers($transfer_spark_ids: [UUID!]!) {
|
|
7600
|
+
transfers(transfer_spark_ids: $transfer_spark_ids) {
|
|
7594
7601
|
...TransferFragment
|
|
7602
|
+
transfer_user_request: user_request {
|
|
7603
|
+
...UserRequestFragment
|
|
7604
|
+
}
|
|
7595
7605
|
}
|
|
7596
7606
|
}
|
|
7597
7607
|
${FRAGMENT}
|
|
7608
|
+
${FRAGMENT6}
|
|
7598
7609
|
`;
|
|
7599
7610
|
|
|
7600
7611
|
// src/graphql/queries/UserRequest.ts
|
|
@@ -7950,14 +7961,47 @@ var SspClient = class {
|
|
|
7950
7961
|
}
|
|
7951
7962
|
});
|
|
7952
7963
|
}
|
|
7953
|
-
async
|
|
7964
|
+
async getTransfers(ids) {
|
|
7954
7965
|
return await this.executeRawQuery({
|
|
7955
|
-
queryPayload:
|
|
7966
|
+
queryPayload: GetTransfers,
|
|
7956
7967
|
variables: {
|
|
7957
|
-
|
|
7968
|
+
transfer_spark_ids: ids
|
|
7958
7969
|
},
|
|
7959
7970
|
constructObject: (response) => {
|
|
7960
|
-
return
|
|
7971
|
+
return response.transfers.map((transfer) => {
|
|
7972
|
+
const transferObj = TransferFromJson(
|
|
7973
|
+
transfer
|
|
7974
|
+
);
|
|
7975
|
+
switch (transfer.transfer_user_request.__typename) {
|
|
7976
|
+
case "ClaimStaticDeposit":
|
|
7977
|
+
transferObj.userRequest = ClaimStaticDepositFromJson(
|
|
7978
|
+
transfer.transfer_user_request
|
|
7979
|
+
);
|
|
7980
|
+
break;
|
|
7981
|
+
case "CoopExitRequest":
|
|
7982
|
+
transferObj.userRequest = CoopExitRequestFromJson(
|
|
7983
|
+
transfer.transfer_user_request
|
|
7984
|
+
);
|
|
7985
|
+
break;
|
|
7986
|
+
case "LeavesSwapRequest":
|
|
7987
|
+
transferObj.userRequest = LeavesSwapRequestFromJson(
|
|
7988
|
+
transfer.transfer_user_request
|
|
7989
|
+
);
|
|
7990
|
+
break;
|
|
7991
|
+
case "LightningReceiveRequest":
|
|
7992
|
+
transferObj.userRequest = LightningReceiveRequestFromJson(
|
|
7993
|
+
transfer.transfer_user_request
|
|
7994
|
+
);
|
|
7995
|
+
break;
|
|
7996
|
+
case "LightningSendRequest":
|
|
7997
|
+
transferObj.userRequest = LightningSendRequestFromJson(
|
|
7998
|
+
transfer.transfer_user_request
|
|
7999
|
+
);
|
|
8000
|
+
break;
|
|
8001
|
+
}
|
|
8002
|
+
const { userRequestId, ...rest } = transferObj;
|
|
8003
|
+
return rest;
|
|
8004
|
+
});
|
|
7961
8005
|
}
|
|
7962
8006
|
});
|
|
7963
8007
|
}
|
|
@@ -12187,9 +12231,22 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12187
12231
|
const identityPublicKey = bytesToHex11(
|
|
12188
12232
|
await this.config.signer.getIdentityPublicKey()
|
|
12189
12233
|
);
|
|
12234
|
+
const userRequests = await this.sspClient?.getTransfers(
|
|
12235
|
+
transfers.transfers.map((transfer) => transfer.id)
|
|
12236
|
+
);
|
|
12237
|
+
const userRequestsMap = /* @__PURE__ */ new Map();
|
|
12238
|
+
for (const userRequest of userRequests || []) {
|
|
12239
|
+
if (userRequest && userRequest.sparkId && userRequest.userRequest) {
|
|
12240
|
+
userRequestsMap.set(userRequest.sparkId, userRequest.userRequest);
|
|
12241
|
+
}
|
|
12242
|
+
}
|
|
12190
12243
|
return {
|
|
12191
12244
|
transfers: transfers.transfers.map(
|
|
12192
|
-
(transfer) => mapTransferToWalletTransfer(
|
|
12245
|
+
(transfer) => mapTransferToWalletTransfer(
|
|
12246
|
+
transfer,
|
|
12247
|
+
identityPublicKey,
|
|
12248
|
+
userRequestsMap.get(transfer.id)
|
|
12249
|
+
)
|
|
12193
12250
|
),
|
|
12194
12251
|
offset: transfers.offset
|
|
12195
12252
|
};
|
|
@@ -12372,7 +12429,9 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12372
12429
|
network = BitcoinNetwork_default.REGTEST;
|
|
12373
12430
|
}
|
|
12374
12431
|
if (outputIndex === void 0) {
|
|
12375
|
-
outputIndex = await this.getDepositTransactionVout(
|
|
12432
|
+
outputIndex = await this.getDepositTransactionVout({
|
|
12433
|
+
txid: transactionId
|
|
12434
|
+
});
|
|
12376
12435
|
}
|
|
12377
12436
|
const quote = await sspClient.getClaimDepositQuote({
|
|
12378
12437
|
transactionId,
|
|
@@ -12403,7 +12462,9 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12403
12462
|
throw new Error("SSP client not initialized");
|
|
12404
12463
|
}
|
|
12405
12464
|
if (outputIndex === void 0) {
|
|
12406
|
-
outputIndex = await this.getDepositTransactionVout(
|
|
12465
|
+
outputIndex = await this.getDepositTransactionVout({
|
|
12466
|
+
txid: transactionId
|
|
12467
|
+
});
|
|
12407
12468
|
}
|
|
12408
12469
|
let network = this.config.getSspNetwork();
|
|
12409
12470
|
if (network === BitcoinNetwork_default.FUTURE_VALUE) {
|
|
@@ -12437,25 +12498,94 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12437
12498
|
}
|
|
12438
12499
|
return response;
|
|
12439
12500
|
}
|
|
12501
|
+
/**
|
|
12502
|
+
* 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.
|
|
12503
|
+
*
|
|
12504
|
+
* @param {Object} params - The parameters object
|
|
12505
|
+
* @param {string} params.transactionId - The ID of the transaction
|
|
12506
|
+
* @param {number} params.maxFee - The maximum fee to claim the deposit for
|
|
12507
|
+
* @param {number} [params.outputIndex] - The index of the output
|
|
12508
|
+
* @returns {Promise<StaticDepositQuoteOutput>} Quote for claiming a deposit to a static deposit address
|
|
12509
|
+
*/
|
|
12510
|
+
async claimStaticDepositWithMaxFee({
|
|
12511
|
+
transactionId,
|
|
12512
|
+
maxFee,
|
|
12513
|
+
outputIndex
|
|
12514
|
+
}) {
|
|
12515
|
+
const sspClient = this.getSspClient();
|
|
12516
|
+
let network = this.config.getSspNetwork();
|
|
12517
|
+
if (network === BitcoinNetwork_default.FUTURE_VALUE) {
|
|
12518
|
+
network = BitcoinNetwork_default.REGTEST;
|
|
12519
|
+
}
|
|
12520
|
+
const depositTx = await this.getDepositTransaction(transactionId);
|
|
12521
|
+
if (outputIndex === void 0) {
|
|
12522
|
+
outputIndex = await this.getDepositTransactionVout({
|
|
12523
|
+
txid: transactionId,
|
|
12524
|
+
depositTx
|
|
12525
|
+
});
|
|
12526
|
+
}
|
|
12527
|
+
const depositAmount = Number(depositTx.getOutput(outputIndex).amount);
|
|
12528
|
+
const quote = await sspClient.getClaimDepositQuote({
|
|
12529
|
+
transactionId,
|
|
12530
|
+
outputIndex,
|
|
12531
|
+
network
|
|
12532
|
+
});
|
|
12533
|
+
if (!quote) {
|
|
12534
|
+
throw new Error("Failed to get claim deposit quote");
|
|
12535
|
+
}
|
|
12536
|
+
const { creditAmountSats, signature: sspSignature } = quote;
|
|
12537
|
+
const feeCharged = depositAmount - creditAmountSats;
|
|
12538
|
+
if (feeCharged > maxFee) {
|
|
12539
|
+
throw new ValidationError("Fee larger than max fee", {
|
|
12540
|
+
field: "feeCharged",
|
|
12541
|
+
value: feeCharged
|
|
12542
|
+
});
|
|
12543
|
+
}
|
|
12544
|
+
const response = await this.claimStaticDeposit({
|
|
12545
|
+
transactionId,
|
|
12546
|
+
creditAmountSats,
|
|
12547
|
+
sspSignature,
|
|
12548
|
+
outputIndex
|
|
12549
|
+
});
|
|
12550
|
+
if (!response) {
|
|
12551
|
+
throw new Error("Failed to claim static deposit");
|
|
12552
|
+
}
|
|
12553
|
+
return response;
|
|
12554
|
+
}
|
|
12440
12555
|
/**
|
|
12441
12556
|
* Refunds a static deposit to a destination address.
|
|
12442
12557
|
*
|
|
12443
|
-
* @param {
|
|
12444
|
-
* @param {
|
|
12445
|
-
* @param {
|
|
12446
|
-
* @param {
|
|
12558
|
+
* @param {Object} params - The refund parameters
|
|
12559
|
+
* @param {string} params.depositTransactionId - The ID of the transaction
|
|
12560
|
+
* @param {number} [params.outputIndex] - The index of the output
|
|
12561
|
+
* @param {string} params.destinationAddress - The destination address
|
|
12562
|
+
* @param {number} [params.fee] - **@deprecated** The fee to refund
|
|
12563
|
+
* @param {number} [params.satsPerVbyteFee] - The fee per vbyte to refund
|
|
12447
12564
|
* @returns {Promise<string>} The hex of the refund transaction
|
|
12448
12565
|
*/
|
|
12449
12566
|
async refundStaticDeposit({
|
|
12450
12567
|
depositTransactionId,
|
|
12451
12568
|
outputIndex,
|
|
12452
12569
|
destinationAddress,
|
|
12453
|
-
fee
|
|
12570
|
+
fee,
|
|
12571
|
+
satsPerVbyteFee
|
|
12454
12572
|
}) {
|
|
12455
|
-
if (fee
|
|
12573
|
+
if (fee !== void 0) {
|
|
12574
|
+
console.warn(
|
|
12575
|
+
`refundStaticDeposit(): \`fee\` parameter is deprecated and will be removed; please switch to \`satsPerVbyteFee\`.`
|
|
12576
|
+
);
|
|
12577
|
+
}
|
|
12578
|
+
if (fee === void 0 && satsPerVbyteFee === void 0) {
|
|
12579
|
+
throw new ValidationError("Fee or satsPerVbyteFee must be provided");
|
|
12580
|
+
}
|
|
12581
|
+
if (satsPerVbyteFee && satsPerVbyteFee > 150) {
|
|
12582
|
+
throw new ValidationError("satsPerVbyteFee must be less than 150");
|
|
12583
|
+
}
|
|
12584
|
+
const finalFee = satsPerVbyteFee ? satsPerVbyteFee * getTxEstimatedVbytesSizeByNumberOfInputsOutputs(1, 1) : fee;
|
|
12585
|
+
if (finalFee <= 200) {
|
|
12456
12586
|
throw new ValidationError("Fee must be greater than 300", {
|
|
12457
12587
|
field: "fee",
|
|
12458
|
-
value:
|
|
12588
|
+
value: finalFee
|
|
12459
12589
|
});
|
|
12460
12590
|
}
|
|
12461
12591
|
let network = this.config.getNetwork();
|
|
@@ -12463,10 +12593,13 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12463
12593
|
const networkJSON = networkToJSON(networkType);
|
|
12464
12594
|
const depositTx = await this.getDepositTransaction(depositTransactionId);
|
|
12465
12595
|
if (outputIndex === void 0) {
|
|
12466
|
-
outputIndex = await this.getDepositTransactionVout(
|
|
12596
|
+
outputIndex = await this.getDepositTransactionVout({
|
|
12597
|
+
txid: depositTransactionId,
|
|
12598
|
+
depositTx
|
|
12599
|
+
});
|
|
12467
12600
|
}
|
|
12468
12601
|
const totalAmount = depositTx.getOutput(outputIndex).amount;
|
|
12469
|
-
const creditAmountSats = Number(totalAmount) -
|
|
12602
|
+
const creditAmountSats = Number(totalAmount) - finalFee;
|
|
12470
12603
|
if (creditAmountSats <= 0) {
|
|
12471
12604
|
throw new ValidationError(
|
|
12472
12605
|
"Fee too large. Credit amount must be greater than 0",
|
|
@@ -12514,26 +12647,14 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12514
12647
|
const sparkClient = await this.connectionManager.createSparkClient(
|
|
12515
12648
|
this.config.getCoordinatorAddress()
|
|
12516
12649
|
);
|
|
12517
|
-
const
|
|
12518
|
-
const swapResponse = await sparkClient.initiate_utxo_swap({
|
|
12650
|
+
const swapResponse = await sparkClient.initiate_static_deposit_utxo_refund({
|
|
12519
12651
|
onChainUtxo: {
|
|
12520
12652
|
txid: hexToBytes12(depositTransactionId),
|
|
12521
12653
|
vout: outputIndex,
|
|
12522
12654
|
network: networkType
|
|
12523
12655
|
},
|
|
12524
|
-
requestType: 2 /* Refund */,
|
|
12525
|
-
amount: {
|
|
12526
|
-
creditAmountSats: 0,
|
|
12527
|
-
$case: "creditAmountSats"
|
|
12528
|
-
},
|
|
12529
12656
|
userSignature: swapResponseUserSignature,
|
|
12530
|
-
|
|
12531
|
-
transfer: {
|
|
12532
|
-
transferId,
|
|
12533
|
-
ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
|
|
12534
|
-
receiverIdentityPublicKey: await this.config.signer.getIdentityPublicKey()
|
|
12535
|
-
},
|
|
12536
|
-
spendTxSigningJob: signingJob
|
|
12657
|
+
refundTxSigningJob: signingJob
|
|
12537
12658
|
});
|
|
12538
12659
|
if (!swapResponse) {
|
|
12539
12660
|
throw new Error("Failed to initiate utxo swap");
|
|
@@ -12546,15 +12667,15 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12546
12667
|
path: 0
|
|
12547
12668
|
},
|
|
12548
12669
|
selfCommitment: signingNonceCommitment,
|
|
12549
|
-
statechainCommitments: swapResponse.
|
|
12670
|
+
statechainCommitments: swapResponse.refundTxSigningResult.signingNonceCommitments,
|
|
12550
12671
|
verifyingKey: swapResponse.depositAddress.verifyingPublicKey
|
|
12551
12672
|
});
|
|
12552
12673
|
const signatureResult = await this.config.signer.aggregateFrost({
|
|
12553
12674
|
message: spendTxSighash,
|
|
12554
|
-
statechainSignatures: swapResponse.
|
|
12555
|
-
statechainPublicKeys: swapResponse.
|
|
12675
|
+
statechainSignatures: swapResponse.refundTxSigningResult.signatureShares,
|
|
12676
|
+
statechainPublicKeys: swapResponse.refundTxSigningResult.publicKeys,
|
|
12556
12677
|
verifyingKey: swapResponse.depositAddress.verifyingPublicKey,
|
|
12557
|
-
statechainCommitments: swapResponse.
|
|
12678
|
+
statechainCommitments: swapResponse.refundTxSigningResult.signingNonceCommitments,
|
|
12558
12679
|
selfCommitment: signingNonceCommitment,
|
|
12559
12680
|
publicKey: await this.config.signer.getStaticDepositSigningKey(0),
|
|
12560
12681
|
selfSignature: userSignature
|
|
@@ -12607,8 +12728,13 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
12607
12728
|
}
|
|
12608
12729
|
return payload;
|
|
12609
12730
|
}
|
|
12610
|
-
async getDepositTransactionVout(
|
|
12611
|
-
|
|
12731
|
+
async getDepositTransactionVout({
|
|
12732
|
+
txid,
|
|
12733
|
+
depositTx
|
|
12734
|
+
}) {
|
|
12735
|
+
if (!depositTx) {
|
|
12736
|
+
depositTx = await this.getDepositTransaction(txid);
|
|
12737
|
+
}
|
|
12612
12738
|
const staticDepositAddresses = new Set(
|
|
12613
12739
|
await this.queryStaticDepositAddresses()
|
|
12614
12740
|
);
|
|
@@ -13823,11 +13949,12 @@ var SparkWallet = class _SparkWallet extends EventEmitter {
|
|
|
13823
13949
|
* Gets a transfer that has been sent by the SSP to the wallet.
|
|
13824
13950
|
*
|
|
13825
13951
|
* @param {string} id - The ID of the transfer
|
|
13826
|
-
* @returns {Promise<
|
|
13952
|
+
* @returns {Promise<TransferWithUserRequest | undefined>} The transfer
|
|
13827
13953
|
*/
|
|
13828
13954
|
async getTransferFromSsp(id) {
|
|
13829
13955
|
const sspClient = this.getSspClient();
|
|
13830
|
-
|
|
13956
|
+
const transfers = await sspClient.getTransfers([id]);
|
|
13957
|
+
return transfers?.[0];
|
|
13831
13958
|
}
|
|
13832
13959
|
/**
|
|
13833
13960
|
* Gets a transfer, that the wallet is a participant of, in the Spark network.
|
|
@@ -15037,6 +15164,7 @@ __export(utils_exports, {
|
|
|
15037
15164
|
getSparkAddressFromTaproot: () => getSparkAddressFromTaproot,
|
|
15038
15165
|
getTransactionSequence: () => getTransactionSequence,
|
|
15039
15166
|
getTransferPackageSigningPayload: () => getTransferPackageSigningPayload,
|
|
15167
|
+
getTxEstimatedVbytesSizeByNumberOfInputsOutputs: () => getTxEstimatedVbytesSizeByNumberOfInputsOutputs,
|
|
15040
15168
|
getTxFromRawTxBytes: () => getTxFromRawTxBytes,
|
|
15041
15169
|
getTxFromRawTxHex: () => getTxFromRawTxHex,
|
|
15042
15170
|
getTxId: () => getTxId,
|
|
@@ -15124,6 +15252,7 @@ export {
|
|
|
15124
15252
|
getSigHashFromTx,
|
|
15125
15253
|
getTxId,
|
|
15126
15254
|
getTxIdNoReverse,
|
|
15255
|
+
getTxEstimatedVbytesSizeByNumberOfInputsOutputs,
|
|
15127
15256
|
DIRECT_TIMELOCK_OFFSET,
|
|
15128
15257
|
INITIAL_SEQUENCE,
|
|
15129
15258
|
INITIAL_DIRECT_SEQUENCE,
|