@arkade-os/boltz-swap 0.1.3 → 0.1.4
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/dist/index.cjs +19 -8
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +19 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -198,9 +198,7 @@ var ArkadeLightning = class {
|
|
|
198
198
|
}
|
|
199
199
|
this.storageProvider?.savePendingSubmarineSwap(pendingSwap);
|
|
200
200
|
this.wallet.sendBitcoin({ address: pendingSwap.response.address, amount: pendingSwap.response.expectedAmount }).then((txid) => {
|
|
201
|
-
this.waitForSwapSettlement(pendingSwap).then(async () => {
|
|
202
|
-
const finalStatus = await this.swapProvider.getSwapStatus(pendingSwap.response.id);
|
|
203
|
-
const preimage = finalStatus.transaction?.preimage ?? "";
|
|
201
|
+
this.waitForSwapSettlement(pendingSwap).then(async ({ preimage }) => {
|
|
204
202
|
resolve({ amount: pendingSwap.response.expectedAmount, preimage, txid });
|
|
205
203
|
}).catch(({ isRefundable }) => {
|
|
206
204
|
if (isRefundable) {
|
|
@@ -218,7 +216,7 @@ var ArkadeLightning = class {
|
|
|
218
216
|
});
|
|
219
217
|
});
|
|
220
218
|
}
|
|
221
|
-
// create
|
|
219
|
+
// create submarine swap
|
|
222
220
|
async createSubmarineSwap(args) {
|
|
223
221
|
const refundPublicKey = import_base.hex.encode(this.wallet.xOnlyPublicKey());
|
|
224
222
|
if (!refundPublicKey) throw new SwapError({ message: "Failed to get refund public key from wallet" });
|
|
@@ -230,6 +228,7 @@ var ArkadeLightning = class {
|
|
|
230
228
|
};
|
|
231
229
|
const swapResponse = await this.swapProvider.createSubmarineSwap(swapRequest);
|
|
232
230
|
const pendingSwap = {
|
|
231
|
+
type: "submarine",
|
|
233
232
|
createdAt: Math.floor(Date.now() / 1e3),
|
|
234
233
|
request: swapRequest,
|
|
235
234
|
response: swapResponse,
|
|
@@ -253,6 +252,7 @@ var ArkadeLightning = class {
|
|
|
253
252
|
};
|
|
254
253
|
const swapResponse = await this.swapProvider.createReverseSwap(swapRequest);
|
|
255
254
|
const pendingSwap = {
|
|
255
|
+
type: "reverse",
|
|
256
256
|
createdAt: Math.floor(Date.now() / 1e3),
|
|
257
257
|
preimage: import_base.hex.encode(preimage),
|
|
258
258
|
request: swapRequest,
|
|
@@ -500,10 +500,13 @@ var ArkadeLightning = class {
|
|
|
500
500
|
this.storageProvider?.savePendingSubmarineSwap({ ...pendingSwap, status });
|
|
501
501
|
reject(new TransactionLockupFailedError({ isRefundable: true, pendingSwap }));
|
|
502
502
|
break;
|
|
503
|
-
case "transaction.claimed":
|
|
504
|
-
this.
|
|
505
|
-
|
|
503
|
+
case "transaction.claimed": {
|
|
504
|
+
const { preimage } = await this.swapProvider.getSwapPreimage(pendingSwap.response.id);
|
|
505
|
+
console.log("preimage returned", { preimage });
|
|
506
|
+
this.storageProvider?.savePendingSubmarineSwap({ ...pendingSwap, preimage, status });
|
|
507
|
+
resolve({ preimage });
|
|
506
508
|
break;
|
|
509
|
+
}
|
|
507
510
|
default:
|
|
508
511
|
this.storageProvider?.savePendingSubmarineSwap({ ...pendingSwap, status });
|
|
509
512
|
break;
|
|
@@ -770,7 +773,7 @@ var StorageProvider = class _StorageProvider {
|
|
|
770
773
|
const swaps = this.storage[kind];
|
|
771
774
|
const found = swaps.findIndex((s) => s.response.id === swap.response.id);
|
|
772
775
|
if (found !== -1) {
|
|
773
|
-
swaps[found]
|
|
776
|
+
swaps[found] = swap;
|
|
774
777
|
} else {
|
|
775
778
|
if (kind === KEY_REVERSE_SWAPS) {
|
|
776
779
|
swaps.push(swap);
|
|
@@ -835,6 +838,9 @@ var isGetPairsResponse = (data) => {
|
|
|
835
838
|
var isCreateSubmarineSwapResponse = (data) => {
|
|
836
839
|
return data && typeof data === "object" && typeof data.id === "string" && typeof data.address === "string" && typeof data.expectedAmount === "number" && typeof data.claimPublicKey === "string" && typeof data.acceptZeroConf === "boolean" && data.timeoutBlockHeights && typeof data.timeoutBlockHeights === "object" && typeof data.timeoutBlockHeights.unilateralClaim === "number" && typeof data.timeoutBlockHeights.unilateralRefund === "number" && typeof data.timeoutBlockHeights.unilateralRefundWithoutReceiver === "number";
|
|
837
840
|
};
|
|
841
|
+
var isGetSwapPreimageResponse = (data) => {
|
|
842
|
+
return data && typeof data === "object" && typeof data.preimage === "string";
|
|
843
|
+
};
|
|
838
844
|
var isCreateReverseSwapResponse = (data) => {
|
|
839
845
|
return data && typeof data === "object" && typeof data.id === "string" && typeof data.invoice === "string" && typeof data.onchainAmount === "number" && typeof data.lockupAddress === "string" && typeof data.refundPublicKey === "string" && data.timeoutBlockHeights && typeof data.timeoutBlockHeights === "object" && typeof data.timeoutBlockHeights.refund === "number" && typeof data.timeoutBlockHeights.unilateralClaim === "number" && typeof data.timeoutBlockHeights.unilateralRefund === "number" && typeof data.timeoutBlockHeights.unilateralRefundWithoutReceiver === "number";
|
|
840
846
|
};
|
|
@@ -876,6 +882,11 @@ var BoltzSwapProvider = class {
|
|
|
876
882
|
if (!isGetSwapStatusResponse(response)) throw new SchemaError({ message: `error fetching status for swap: ${id}` });
|
|
877
883
|
return response;
|
|
878
884
|
}
|
|
885
|
+
async getSwapPreimage(id) {
|
|
886
|
+
const res = await this.request(`/v2/swap/submarine/${id}/preimage`, "GET");
|
|
887
|
+
if (!isGetSwapPreimageResponse(res)) throw new SchemaError({ message: `error fetching preimage for swap: ${id}` });
|
|
888
|
+
return res;
|
|
889
|
+
}
|
|
879
890
|
async createSubmarineSwap({
|
|
880
891
|
invoice,
|
|
881
892
|
refundPublicKey
|
package/dist/index.d.cts
CHANGED
|
@@ -70,6 +70,9 @@ type CreateSubmarineSwapResponse = {
|
|
|
70
70
|
unilateralRefundWithoutReceiver: number;
|
|
71
71
|
};
|
|
72
72
|
};
|
|
73
|
+
type GetSwapPreimageResponse = {
|
|
74
|
+
preimage: string;
|
|
75
|
+
};
|
|
73
76
|
type CreateReverseSwapRequest = {
|
|
74
77
|
claimPublicKey: string;
|
|
75
78
|
invoiceAmount: number;
|
|
@@ -98,6 +101,7 @@ declare class BoltzSwapProvider {
|
|
|
98
101
|
getNetwork(): Network;
|
|
99
102
|
getLimits(): Promise<LimitsResponse>;
|
|
100
103
|
getSwapStatus(id: string): Promise<GetSwapStatusResponse>;
|
|
104
|
+
getSwapPreimage(id: string): Promise<GetSwapPreimageResponse>;
|
|
101
105
|
createSubmarineSwap({ invoice, refundPublicKey, }: CreateSubmarineSwapRequest): Promise<CreateSubmarineSwapResponse>;
|
|
102
106
|
createReverseSwap({ invoiceAmount, claimPublicKey, preimageHash, }: CreateReverseSwapRequest): Promise<CreateReverseSwapResponse>;
|
|
103
107
|
monitorSwap(swapId: string, update: (type: BoltzSwapStatus, data?: any) => void): Promise<void>;
|
|
@@ -138,6 +142,7 @@ interface SendLightningPaymentResponse {
|
|
|
138
142
|
txid: string;
|
|
139
143
|
}
|
|
140
144
|
interface PendingReverseSwap {
|
|
145
|
+
type: 'reverse';
|
|
141
146
|
createdAt: number;
|
|
142
147
|
preimage: string;
|
|
143
148
|
status: BoltzSwapStatus;
|
|
@@ -145,7 +150,9 @@ interface PendingReverseSwap {
|
|
|
145
150
|
response: CreateReverseSwapResponse;
|
|
146
151
|
}
|
|
147
152
|
interface PendingSubmarineSwap {
|
|
153
|
+
type: 'submarine';
|
|
148
154
|
createdAt: number;
|
|
155
|
+
preimage?: string;
|
|
149
156
|
status: BoltzSwapStatus;
|
|
150
157
|
request: CreateSubmarineSwapRequest;
|
|
151
158
|
response: CreateSubmarineSwapResponse;
|
|
@@ -225,7 +232,9 @@ declare class ArkadeLightning {
|
|
|
225
232
|
* @param pendingSwap - The pending swap.
|
|
226
233
|
* @returns The status of the swap settlement.
|
|
227
234
|
*/
|
|
228
|
-
waitForSwapSettlement(pendingSwap: PendingSubmarineSwap): Promise<
|
|
235
|
+
waitForSwapSettlement(pendingSwap: PendingSubmarineSwap): Promise<{
|
|
236
|
+
preimage: string;
|
|
237
|
+
}>;
|
|
229
238
|
/**
|
|
230
239
|
* Validates the final Ark transaction.
|
|
231
240
|
* checks that all inputs have a signature for the given pubkey
|
package/dist/index.d.ts
CHANGED
|
@@ -70,6 +70,9 @@ type CreateSubmarineSwapResponse = {
|
|
|
70
70
|
unilateralRefundWithoutReceiver: number;
|
|
71
71
|
};
|
|
72
72
|
};
|
|
73
|
+
type GetSwapPreimageResponse = {
|
|
74
|
+
preimage: string;
|
|
75
|
+
};
|
|
73
76
|
type CreateReverseSwapRequest = {
|
|
74
77
|
claimPublicKey: string;
|
|
75
78
|
invoiceAmount: number;
|
|
@@ -98,6 +101,7 @@ declare class BoltzSwapProvider {
|
|
|
98
101
|
getNetwork(): Network;
|
|
99
102
|
getLimits(): Promise<LimitsResponse>;
|
|
100
103
|
getSwapStatus(id: string): Promise<GetSwapStatusResponse>;
|
|
104
|
+
getSwapPreimage(id: string): Promise<GetSwapPreimageResponse>;
|
|
101
105
|
createSubmarineSwap({ invoice, refundPublicKey, }: CreateSubmarineSwapRequest): Promise<CreateSubmarineSwapResponse>;
|
|
102
106
|
createReverseSwap({ invoiceAmount, claimPublicKey, preimageHash, }: CreateReverseSwapRequest): Promise<CreateReverseSwapResponse>;
|
|
103
107
|
monitorSwap(swapId: string, update: (type: BoltzSwapStatus, data?: any) => void): Promise<void>;
|
|
@@ -138,6 +142,7 @@ interface SendLightningPaymentResponse {
|
|
|
138
142
|
txid: string;
|
|
139
143
|
}
|
|
140
144
|
interface PendingReverseSwap {
|
|
145
|
+
type: 'reverse';
|
|
141
146
|
createdAt: number;
|
|
142
147
|
preimage: string;
|
|
143
148
|
status: BoltzSwapStatus;
|
|
@@ -145,7 +150,9 @@ interface PendingReverseSwap {
|
|
|
145
150
|
response: CreateReverseSwapResponse;
|
|
146
151
|
}
|
|
147
152
|
interface PendingSubmarineSwap {
|
|
153
|
+
type: 'submarine';
|
|
148
154
|
createdAt: number;
|
|
155
|
+
preimage?: string;
|
|
149
156
|
status: BoltzSwapStatus;
|
|
150
157
|
request: CreateSubmarineSwapRequest;
|
|
151
158
|
response: CreateSubmarineSwapResponse;
|
|
@@ -225,7 +232,9 @@ declare class ArkadeLightning {
|
|
|
225
232
|
* @param pendingSwap - The pending swap.
|
|
226
233
|
* @returns The status of the swap settlement.
|
|
227
234
|
*/
|
|
228
|
-
waitForSwapSettlement(pendingSwap: PendingSubmarineSwap): Promise<
|
|
235
|
+
waitForSwapSettlement(pendingSwap: PendingSubmarineSwap): Promise<{
|
|
236
|
+
preimage: string;
|
|
237
|
+
}>;
|
|
229
238
|
/**
|
|
230
239
|
* Validates the final Ark transaction.
|
|
231
240
|
* checks that all inputs have a signature for the given pubkey
|
package/dist/index.js
CHANGED
|
@@ -160,9 +160,7 @@ var ArkadeLightning = class {
|
|
|
160
160
|
}
|
|
161
161
|
this.storageProvider?.savePendingSubmarineSwap(pendingSwap);
|
|
162
162
|
this.wallet.sendBitcoin({ address: pendingSwap.response.address, amount: pendingSwap.response.expectedAmount }).then((txid) => {
|
|
163
|
-
this.waitForSwapSettlement(pendingSwap).then(async () => {
|
|
164
|
-
const finalStatus = await this.swapProvider.getSwapStatus(pendingSwap.response.id);
|
|
165
|
-
const preimage = finalStatus.transaction?.preimage ?? "";
|
|
163
|
+
this.waitForSwapSettlement(pendingSwap).then(async ({ preimage }) => {
|
|
166
164
|
resolve({ amount: pendingSwap.response.expectedAmount, preimage, txid });
|
|
167
165
|
}).catch(({ isRefundable }) => {
|
|
168
166
|
if (isRefundable) {
|
|
@@ -180,7 +178,7 @@ var ArkadeLightning = class {
|
|
|
180
178
|
});
|
|
181
179
|
});
|
|
182
180
|
}
|
|
183
|
-
// create
|
|
181
|
+
// create submarine swap
|
|
184
182
|
async createSubmarineSwap(args) {
|
|
185
183
|
const refundPublicKey = hex.encode(this.wallet.xOnlyPublicKey());
|
|
186
184
|
if (!refundPublicKey) throw new SwapError({ message: "Failed to get refund public key from wallet" });
|
|
@@ -192,6 +190,7 @@ var ArkadeLightning = class {
|
|
|
192
190
|
};
|
|
193
191
|
const swapResponse = await this.swapProvider.createSubmarineSwap(swapRequest);
|
|
194
192
|
const pendingSwap = {
|
|
193
|
+
type: "submarine",
|
|
195
194
|
createdAt: Math.floor(Date.now() / 1e3),
|
|
196
195
|
request: swapRequest,
|
|
197
196
|
response: swapResponse,
|
|
@@ -215,6 +214,7 @@ var ArkadeLightning = class {
|
|
|
215
214
|
};
|
|
216
215
|
const swapResponse = await this.swapProvider.createReverseSwap(swapRequest);
|
|
217
216
|
const pendingSwap = {
|
|
217
|
+
type: "reverse",
|
|
218
218
|
createdAt: Math.floor(Date.now() / 1e3),
|
|
219
219
|
preimage: hex.encode(preimage),
|
|
220
220
|
request: swapRequest,
|
|
@@ -462,10 +462,13 @@ var ArkadeLightning = class {
|
|
|
462
462
|
this.storageProvider?.savePendingSubmarineSwap({ ...pendingSwap, status });
|
|
463
463
|
reject(new TransactionLockupFailedError({ isRefundable: true, pendingSwap }));
|
|
464
464
|
break;
|
|
465
|
-
case "transaction.claimed":
|
|
466
|
-
this.
|
|
467
|
-
|
|
465
|
+
case "transaction.claimed": {
|
|
466
|
+
const { preimage } = await this.swapProvider.getSwapPreimage(pendingSwap.response.id);
|
|
467
|
+
console.log("preimage returned", { preimage });
|
|
468
|
+
this.storageProvider?.savePendingSubmarineSwap({ ...pendingSwap, preimage, status });
|
|
469
|
+
resolve({ preimage });
|
|
468
470
|
break;
|
|
471
|
+
}
|
|
469
472
|
default:
|
|
470
473
|
this.storageProvider?.savePendingSubmarineSwap({ ...pendingSwap, status });
|
|
471
474
|
break;
|
|
@@ -732,7 +735,7 @@ var StorageProvider = class _StorageProvider {
|
|
|
732
735
|
const swaps = this.storage[kind];
|
|
733
736
|
const found = swaps.findIndex((s) => s.response.id === swap.response.id);
|
|
734
737
|
if (found !== -1) {
|
|
735
|
-
swaps[found]
|
|
738
|
+
swaps[found] = swap;
|
|
736
739
|
} else {
|
|
737
740
|
if (kind === KEY_REVERSE_SWAPS) {
|
|
738
741
|
swaps.push(swap);
|
|
@@ -797,6 +800,9 @@ var isGetPairsResponse = (data) => {
|
|
|
797
800
|
var isCreateSubmarineSwapResponse = (data) => {
|
|
798
801
|
return data && typeof data === "object" && typeof data.id === "string" && typeof data.address === "string" && typeof data.expectedAmount === "number" && typeof data.claimPublicKey === "string" && typeof data.acceptZeroConf === "boolean" && data.timeoutBlockHeights && typeof data.timeoutBlockHeights === "object" && typeof data.timeoutBlockHeights.unilateralClaim === "number" && typeof data.timeoutBlockHeights.unilateralRefund === "number" && typeof data.timeoutBlockHeights.unilateralRefundWithoutReceiver === "number";
|
|
799
802
|
};
|
|
803
|
+
var isGetSwapPreimageResponse = (data) => {
|
|
804
|
+
return data && typeof data === "object" && typeof data.preimage === "string";
|
|
805
|
+
};
|
|
800
806
|
var isCreateReverseSwapResponse = (data) => {
|
|
801
807
|
return data && typeof data === "object" && typeof data.id === "string" && typeof data.invoice === "string" && typeof data.onchainAmount === "number" && typeof data.lockupAddress === "string" && typeof data.refundPublicKey === "string" && data.timeoutBlockHeights && typeof data.timeoutBlockHeights === "object" && typeof data.timeoutBlockHeights.refund === "number" && typeof data.timeoutBlockHeights.unilateralClaim === "number" && typeof data.timeoutBlockHeights.unilateralRefund === "number" && typeof data.timeoutBlockHeights.unilateralRefundWithoutReceiver === "number";
|
|
802
808
|
};
|
|
@@ -838,6 +844,11 @@ var BoltzSwapProvider = class {
|
|
|
838
844
|
if (!isGetSwapStatusResponse(response)) throw new SchemaError({ message: `error fetching status for swap: ${id}` });
|
|
839
845
|
return response;
|
|
840
846
|
}
|
|
847
|
+
async getSwapPreimage(id) {
|
|
848
|
+
const res = await this.request(`/v2/swap/submarine/${id}/preimage`, "GET");
|
|
849
|
+
if (!isGetSwapPreimageResponse(res)) throw new SchemaError({ message: `error fetching preimage for swap: ${id}` });
|
|
850
|
+
return res;
|
|
851
|
+
}
|
|
841
852
|
async createSubmarineSwap({
|
|
842
853
|
invoice,
|
|
843
854
|
refundPublicKey
|