@atomiqlabs/base 9.1.0 → 10.0.0-dev.1
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.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/spv_swap/SpvVaultContract.d.ts +8 -0
- package/dist/spv_swap/SpvWithdrawalTransactionData.d.ts +1 -0
- package/dist/swaps/SwapCommitState.d.ts +38 -0
- package/dist/swaps/SwapCommitState.js +11 -0
- package/dist/swaps/SwapContract.d.ts +7 -5
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/spv_swap/SpvVaultContract.ts +9 -0
- package/src/spv_swap/SpvWithdrawalTransactionData.ts +2 -0
- package/src/swaps/SwapCommitState.ts +39 -0
- package/src/swaps/SwapContract.ts +7 -5
- package/dist/swaps/SwapCommitStatus.d.ts +0 -7
- package/dist/swaps/SwapCommitStatus.js +0 -11
- package/src/swaps/SwapCommitStatus.ts +0 -8
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export * from "./storage/StorageObject";
|
|
|
16
16
|
export * from "./swaps/SwapContract";
|
|
17
17
|
export * from "./swaps/SwapData";
|
|
18
18
|
export * from "./swaps/ChainSwapType";
|
|
19
|
-
export * from "./swaps/
|
|
19
|
+
export * from "./swaps/SwapCommitState";
|
|
20
20
|
export * from "./errors/SignatureVerificationError";
|
|
21
21
|
export * from "./errors/CannotInitializeATAError";
|
|
22
22
|
export * from "./errors/SwapDataVerificationError";
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ __exportStar(require("./storage/StorageObject"), exports);
|
|
|
32
32
|
__exportStar(require("./swaps/SwapContract"), exports);
|
|
33
33
|
__exportStar(require("./swaps/SwapData"), exports);
|
|
34
34
|
__exportStar(require("./swaps/ChainSwapType"), exports);
|
|
35
|
-
__exportStar(require("./swaps/
|
|
35
|
+
__exportStar(require("./swaps/SwapCommitState"), exports);
|
|
36
36
|
__exportStar(require("./errors/SignatureVerificationError"), exports);
|
|
37
37
|
__exportStar(require("./errors/CannotInitializeATAError"), exports);
|
|
38
38
|
__exportStar(require("./errors/SwapDataVerificationError"), exports);
|
|
@@ -103,6 +103,14 @@ export interface SpvVaultContract<TX = any, Signer extends AbstractSigner = Abst
|
|
|
103
103
|
* @param tokenData Data about the tokens in the vault
|
|
104
104
|
*/
|
|
105
105
|
createVaultData(owner: string, vaultId: bigint, utxo: string, confirmations: number, tokenData: SpvVaultTokenData[]): Promise<Data>;
|
|
106
|
+
/**
|
|
107
|
+
* Returns the party which currently fronted the withdrawal transaction
|
|
108
|
+
*
|
|
109
|
+
* @param owner Owner of the vault
|
|
110
|
+
* @param vaultId Vault ID
|
|
111
|
+
* @param withdrawal Withdrawal transaction to check the fronting for
|
|
112
|
+
*/
|
|
113
|
+
getFronterAddress(owner: string, vaultId: bigint, withdrawal: WithdrawalTX): Promise<string | null>;
|
|
106
114
|
/**
|
|
107
115
|
* Returns current vault data
|
|
108
116
|
*
|
|
@@ -28,6 +28,7 @@ export declare abstract class SpvWithdrawalTransactionData implements StorageObj
|
|
|
28
28
|
serialize(): any;
|
|
29
29
|
getRecipient(): string;
|
|
30
30
|
abstract isRecipient(address: string): boolean;
|
|
31
|
+
abstract getFrontingId(): string;
|
|
31
32
|
getOutputWithoutFees(): bigint[];
|
|
32
33
|
getCallerFee(): bigint[];
|
|
33
34
|
getFrontingFee(): bigint[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare enum SwapCommitStateType {
|
|
2
|
+
EXPIRED = 0,
|
|
3
|
+
NOT_COMMITED = 1,
|
|
4
|
+
COMMITED = 2,
|
|
5
|
+
PAID = 3,
|
|
6
|
+
REFUNDABLE = 4
|
|
7
|
+
}
|
|
8
|
+
export type SwapNotCommitedState = {
|
|
9
|
+
type: SwapCommitStateType.NOT_COMMITED;
|
|
10
|
+
getRefundTxId?: () => Promise<string>;
|
|
11
|
+
getTxBlock?: () => Promise<{
|
|
12
|
+
blockHeight: number;
|
|
13
|
+
blockTime: number;
|
|
14
|
+
}>;
|
|
15
|
+
};
|
|
16
|
+
export type SwapExpiredState = {
|
|
17
|
+
type: SwapCommitStateType.EXPIRED;
|
|
18
|
+
getRefundTxId?: () => Promise<string>;
|
|
19
|
+
getTxBlock?: () => Promise<{
|
|
20
|
+
blockHeight: number;
|
|
21
|
+
blockTime: number;
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
24
|
+
export type SwapRefundableState = {
|
|
25
|
+
type: SwapCommitStateType.REFUNDABLE;
|
|
26
|
+
};
|
|
27
|
+
export type SwapCommitedState = {
|
|
28
|
+
type: SwapCommitStateType.COMMITED;
|
|
29
|
+
};
|
|
30
|
+
export type SwapPaidState = {
|
|
31
|
+
type: SwapCommitStateType.PAID;
|
|
32
|
+
getClaimTxId: () => Promise<string>;
|
|
33
|
+
getTxBlock: () => Promise<{
|
|
34
|
+
blockHeight: number;
|
|
35
|
+
blockTime: number;
|
|
36
|
+
}>;
|
|
37
|
+
};
|
|
38
|
+
export type SwapCommitState = SwapNotCommitedState | SwapExpiredState | SwapRefundableState | SwapCommitedState | SwapPaidState;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwapCommitStateType = void 0;
|
|
4
|
+
var SwapCommitStateType;
|
|
5
|
+
(function (SwapCommitStateType) {
|
|
6
|
+
SwapCommitStateType[SwapCommitStateType["EXPIRED"] = 0] = "EXPIRED";
|
|
7
|
+
SwapCommitStateType[SwapCommitStateType["NOT_COMMITED"] = 1] = "NOT_COMMITED";
|
|
8
|
+
SwapCommitStateType[SwapCommitStateType["COMMITED"] = 2] = "COMMITED";
|
|
9
|
+
SwapCommitStateType[SwapCommitStateType["PAID"] = 3] = "PAID";
|
|
10
|
+
SwapCommitStateType[SwapCommitStateType["REFUNDABLE"] = 4] = "REFUNDABLE";
|
|
11
|
+
})(SwapCommitStateType = exports.SwapCommitStateType || (exports.SwapCommitStateType = {}));
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { SwapData } from "./SwapData";
|
|
3
3
|
import { BtcStoredHeader } from "../btcrelay/types/BtcStoredHeader";
|
|
4
|
-
import { SwapCommitStatus } from "./SwapCommitStatus";
|
|
5
4
|
import { ChainSwapType } from "./ChainSwapType";
|
|
6
5
|
import { RelaySynchronizer } from "../btcrelay/synchronizer/RelaySynchronizer";
|
|
7
6
|
import { Buffer } from "buffer";
|
|
8
7
|
import { AbstractSigner, TransactionConfirmationOptions } from "../chains/ChainInterface";
|
|
8
|
+
import { SwapCommitState } from "./SwapCommitState";
|
|
9
9
|
export type IntermediaryReputationType = {
|
|
10
10
|
[key in ChainSwapType]: {
|
|
11
11
|
successVolume: bigint;
|
|
@@ -50,12 +50,13 @@ export interface SwapContract<T extends SwapData = SwapData, TX = any, PreFetchD
|
|
|
50
50
|
/**
|
|
51
51
|
* Returns the unsigned transactions required for initializing a non-payIn swap (BTC -> SC)
|
|
52
52
|
*
|
|
53
|
+
* @param sender Transaction sender address, must be either offerer or claimer
|
|
53
54
|
* @param swapData Swap to init
|
|
54
55
|
* @param signature Signature data from the offerer
|
|
55
56
|
* @param skipChecks Whether to skip verification of the signature & checking if the swap is already committed
|
|
56
57
|
* @param feeRate Fee rate to use for the transaction
|
|
57
58
|
*/
|
|
58
|
-
txsInit(swapData: T, signature: SignatureData, skipChecks?: boolean, feeRate?: string): Promise<TX[]>;
|
|
59
|
+
txsInit(sender: string, swapData: T, signature: SignatureData, skipChecks?: boolean, feeRate?: string): Promise<TX[]>;
|
|
59
60
|
/**
|
|
60
61
|
* Signs & sends transactions required for claiming an HTLC swap
|
|
61
62
|
*
|
|
@@ -182,12 +183,12 @@ export interface SwapContract<T extends SwapData = SwapData, TX = any, PreFetchD
|
|
|
182
183
|
*/
|
|
183
184
|
isCommited(swapData: T): Promise<boolean>;
|
|
184
185
|
/**
|
|
185
|
-
* Returns the full status of the swap, expiry is
|
|
186
|
+
* Returns the full status of the swap, expiry is handled by the isExpired function so also requires a signer/sender
|
|
186
187
|
*
|
|
187
188
|
* @param signer
|
|
188
189
|
* @param swapData
|
|
189
190
|
*/
|
|
190
|
-
getCommitStatus(signer: string, swapData: T): Promise<
|
|
191
|
+
getCommitStatus(signer: string, swapData: T): Promise<SwapCommitState>;
|
|
191
192
|
/**
|
|
192
193
|
* Checks whether a given swap is refundable by us, i.e. it is already expired, we are offerer & swap is committed on-chain
|
|
193
194
|
*
|
|
@@ -217,13 +218,14 @@ export interface SwapContract<T extends SwapData = SwapData, TX = any, PreFetchD
|
|
|
217
218
|
/**
|
|
218
219
|
* Checks whether a signature is a valid initialization signature for a given swap
|
|
219
220
|
*
|
|
221
|
+
* @param sender Address of the sender of the transaction (must be either offerer or claimer)
|
|
220
222
|
* @param swapData Swap to initialize
|
|
221
223
|
* @param signature Signature data
|
|
222
224
|
* @param feeRate Fee rate used for the authorization
|
|
223
225
|
* @param preFetchedVerificationData Optional pre-fetched data required for signature validation
|
|
224
226
|
* @returns {Buffer | null} The message being signed if valid or null if invalid signature
|
|
225
227
|
*/
|
|
226
|
-
isValidInitAuthorization(swapData: T, signature: SignatureData, feeRate?: string, preFetchedVerificationData?: PreFetchVerification): Promise<Buffer | null>;
|
|
228
|
+
isValidInitAuthorization(sender: string, swapData: T, signature: SignatureData, feeRate?: string, preFetchedVerificationData?: PreFetchVerification): Promise<Buffer | null>;
|
|
227
229
|
/**
|
|
228
230
|
* Returns the expiry timestamp (UNIX milliseconds) of the authorization
|
|
229
231
|
*
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -16,7 +16,7 @@ export * from "./storage/StorageObject";
|
|
|
16
16
|
export * from "./swaps/SwapContract";
|
|
17
17
|
export * from "./swaps/SwapData";
|
|
18
18
|
export * from "./swaps/ChainSwapType";
|
|
19
|
-
export * from "./swaps/
|
|
19
|
+
export * from "./swaps/SwapCommitState";
|
|
20
20
|
|
|
21
21
|
export * from "./errors/SignatureVerificationError";
|
|
22
22
|
export * from "./errors/CannotInitializeATAError"
|
|
@@ -127,6 +127,15 @@ export interface SpvVaultContract<
|
|
|
127
127
|
*/
|
|
128
128
|
createVaultData(owner: string, vaultId: bigint, utxo: string, confirmations: number, tokenData: SpvVaultTokenData[]): Promise<Data>;
|
|
129
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Returns the party which currently fronted the withdrawal transaction
|
|
132
|
+
*
|
|
133
|
+
* @param owner Owner of the vault
|
|
134
|
+
* @param vaultId Vault ID
|
|
135
|
+
* @param withdrawal Withdrawal transaction to check the fronting for
|
|
136
|
+
*/
|
|
137
|
+
getFronterAddress(owner: string, vaultId: bigint, withdrawal: WithdrawalTX): Promise<string | null>;
|
|
138
|
+
|
|
130
139
|
/**
|
|
131
140
|
* Returns current vault data
|
|
132
141
|
*
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export enum SwapCommitStateType {
|
|
2
|
+
EXPIRED=0,
|
|
3
|
+
NOT_COMMITED=1,
|
|
4
|
+
COMMITED=2,
|
|
5
|
+
PAID=3,
|
|
6
|
+
REFUNDABLE=4
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type SwapNotCommitedState = {
|
|
10
|
+
type: SwapCommitStateType.NOT_COMMITED,
|
|
11
|
+
getRefundTxId?: () => Promise<string>,
|
|
12
|
+
getTxBlock?: () => Promise<{blockHeight: number, blockTime: number}>
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type SwapExpiredState = {
|
|
16
|
+
type: SwapCommitStateType.EXPIRED,
|
|
17
|
+
getRefundTxId?: () => Promise<string>,
|
|
18
|
+
getTxBlock?: () => Promise<{blockHeight: number, blockTime: number}>
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type SwapRefundableState = {
|
|
22
|
+
type: SwapCommitStateType.REFUNDABLE
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type SwapCommitedState = {
|
|
26
|
+
type: SwapCommitStateType.COMMITED
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type SwapPaidState = {
|
|
30
|
+
type: SwapCommitStateType.PAID,
|
|
31
|
+
getClaimTxId: () => Promise<string>,
|
|
32
|
+
getTxBlock: () => Promise<{blockHeight: number, blockTime: number}>
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type SwapCommitState = SwapNotCommitedState |
|
|
36
|
+
SwapExpiredState |
|
|
37
|
+
SwapRefundableState |
|
|
38
|
+
SwapCommitedState |
|
|
39
|
+
SwapPaidState;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {SwapData} from "./SwapData";
|
|
2
2
|
import {BtcStoredHeader} from "../btcrelay/types/BtcStoredHeader";
|
|
3
|
-
import {SwapCommitStatus} from "./SwapCommitStatus";
|
|
4
3
|
import {ChainSwapType} from "./ChainSwapType";
|
|
5
4
|
import {RelaySynchronizer} from "../btcrelay/synchronizer/RelaySynchronizer";
|
|
6
5
|
import {Buffer} from "buffer";
|
|
7
6
|
import {AbstractSigner, TransactionConfirmationOptions} from "../chains/ChainInterface";
|
|
7
|
+
import {SwapCommitState} from "./SwapCommitState";
|
|
8
8
|
|
|
9
9
|
export type IntermediaryReputationType = {
|
|
10
10
|
[key in ChainSwapType]: {
|
|
@@ -64,12 +64,13 @@ export interface SwapContract<
|
|
|
64
64
|
/**
|
|
65
65
|
* Returns the unsigned transactions required for initializing a non-payIn swap (BTC -> SC)
|
|
66
66
|
*
|
|
67
|
+
* @param sender Transaction sender address, must be either offerer or claimer
|
|
67
68
|
* @param swapData Swap to init
|
|
68
69
|
* @param signature Signature data from the offerer
|
|
69
70
|
* @param skipChecks Whether to skip verification of the signature & checking if the swap is already committed
|
|
70
71
|
* @param feeRate Fee rate to use for the transaction
|
|
71
72
|
*/
|
|
72
|
-
txsInit(swapData: T, signature: SignatureData, skipChecks?: boolean, feeRate?: string): Promise<TX[]>;
|
|
73
|
+
txsInit(sender: string, swapData: T, signature: SignatureData, skipChecks?: boolean, feeRate?: string): Promise<TX[]>;
|
|
73
74
|
|
|
74
75
|
/**
|
|
75
76
|
* Signs & sends transactions required for claiming an HTLC swap
|
|
@@ -229,12 +230,12 @@ export interface SwapContract<
|
|
|
229
230
|
isCommited(swapData: T): Promise<boolean>;
|
|
230
231
|
|
|
231
232
|
/**
|
|
232
|
-
* Returns the full status of the swap, expiry is
|
|
233
|
+
* Returns the full status of the swap, expiry is handled by the isExpired function so also requires a signer/sender
|
|
233
234
|
*
|
|
234
235
|
* @param signer
|
|
235
236
|
* @param swapData
|
|
236
237
|
*/
|
|
237
|
-
getCommitStatus(signer: string, swapData: T): Promise<
|
|
238
|
+
getCommitStatus(signer: string, swapData: T): Promise<SwapCommitState>;
|
|
238
239
|
|
|
239
240
|
/**
|
|
240
241
|
* Checks whether a given swap is refundable by us, i.e. it is already expired, we are offerer & swap is committed on-chain
|
|
@@ -269,13 +270,14 @@ export interface SwapContract<
|
|
|
269
270
|
/**
|
|
270
271
|
* Checks whether a signature is a valid initialization signature for a given swap
|
|
271
272
|
*
|
|
273
|
+
* @param sender Address of the sender of the transaction (must be either offerer or claimer)
|
|
272
274
|
* @param swapData Swap to initialize
|
|
273
275
|
* @param signature Signature data
|
|
274
276
|
* @param feeRate Fee rate used for the authorization
|
|
275
277
|
* @param preFetchedVerificationData Optional pre-fetched data required for signature validation
|
|
276
278
|
* @returns {Buffer | null} The message being signed if valid or null if invalid signature
|
|
277
279
|
*/
|
|
278
|
-
isValidInitAuthorization(swapData: T, signature: SignatureData, feeRate?: string, preFetchedVerificationData?: PreFetchVerification): Promise<Buffer | null>;
|
|
280
|
+
isValidInitAuthorization(sender: string, swapData: T, signature: SignatureData, feeRate?: string, preFetchedVerificationData?: PreFetchVerification): Promise<Buffer | null>;
|
|
279
281
|
|
|
280
282
|
/**
|
|
281
283
|
* Returns the expiry timestamp (UNIX milliseconds) of the authorization
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SwapCommitStatus = void 0;
|
|
4
|
-
var SwapCommitStatus;
|
|
5
|
-
(function (SwapCommitStatus) {
|
|
6
|
-
SwapCommitStatus[SwapCommitStatus["EXPIRED"] = 0] = "EXPIRED";
|
|
7
|
-
SwapCommitStatus[SwapCommitStatus["NOT_COMMITED"] = 1] = "NOT_COMMITED";
|
|
8
|
-
SwapCommitStatus[SwapCommitStatus["COMMITED"] = 2] = "COMMITED";
|
|
9
|
-
SwapCommitStatus[SwapCommitStatus["PAID"] = 3] = "PAID";
|
|
10
|
-
SwapCommitStatus[SwapCommitStatus["REFUNDABLE"] = 4] = "REFUNDABLE";
|
|
11
|
-
})(SwapCommitStatus = exports.SwapCommitStatus || (exports.SwapCommitStatus = {}));
|