@atomiqlabs/base 10.0.0-dev.2 → 10.0.0-dev.21
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/LICENSE +201 -201
- package/dist/btc/BitcoinNetwork.d.ts +6 -6
- package/dist/btc/BitcoinNetwork.js +10 -10
- package/dist/btc/rpc/BitcoinRpc.d.ts +68 -68
- package/dist/btc/rpc/BitcoinRpc.js +2 -2
- package/dist/btcrelay/BtcRelay.d.ts +61 -61
- package/dist/btcrelay/BtcRelay.js +2 -2
- package/dist/btcrelay/synchronizer/RelaySynchronizer.d.ts +18 -18
- package/dist/btcrelay/synchronizer/RelaySynchronizer.js +2 -2
- package/dist/btcrelay/types/BtcBlock.d.ts +13 -13
- package/dist/btcrelay/types/BtcBlock.js +2 -2
- package/dist/btcrelay/types/BtcHeader.d.ts +10 -10
- package/dist/btcrelay/types/BtcHeader.js +2 -2
- package/dist/btcrelay/types/BtcStoredHeader.d.ts +11 -11
- package/dist/btcrelay/types/BtcStoredHeader.js +2 -2
- package/dist/btcrelay/utils/StatePredictorUtils.d.ts +11 -11
- package/dist/btcrelay/utils/StatePredictorUtils.js +80 -80
- package/dist/chains/ChainData.d.ts +31 -31
- package/dist/chains/ChainData.js +2 -2
- package/dist/chains/ChainInterface.d.ts +133 -110
- package/dist/chains/ChainInterface.js +7 -2
- package/dist/chains/ChainType.d.ts +24 -23
- package/dist/chains/ChainType.js +2 -2
- package/dist/errors/CannotInitializeATAError.d.ts +3 -3
- package/dist/errors/CannotInitializeATAError.js +11 -11
- package/dist/errors/SignatureVerificationError.d.ts +3 -3
- package/dist/errors/SignatureVerificationError.js +11 -11
- package/dist/errors/SwapDataVerificationError.d.ts +3 -3
- package/dist/errors/SwapDataVerificationError.js +11 -11
- package/dist/errors/TransactionRevertedError.d.ts +3 -0
- package/dist/errors/TransactionRevertedError.js +11 -0
- package/dist/events/ChainEvents.d.ts +9 -9
- package/dist/events/ChainEvents.js +2 -2
- package/dist/events/types/ChainEvent.d.ts +7 -7
- package/dist/events/types/ChainEvent.js +6 -6
- package/dist/events/types/spv_vault/SpvVaultClaimEvent.d.ts +12 -12
- package/dist/events/types/spv_vault/SpvVaultClaimEvent.js +18 -18
- package/dist/events/types/spv_vault/SpvVaultCloseEvent.d.ts +7 -7
- package/dist/events/types/spv_vault/SpvVaultCloseEvent.js +13 -13
- package/dist/events/types/spv_vault/SpvVaultDepositEvent.d.ts +7 -7
- package/dist/events/types/spv_vault/SpvVaultDepositEvent.js +13 -13
- package/dist/events/types/spv_vault/SpvVaultEvent.d.ts +15 -15
- package/dist/events/types/spv_vault/SpvVaultEvent.js +20 -20
- package/dist/events/types/spv_vault/SpvVaultFrontEvent.d.ts +10 -10
- package/dist/events/types/spv_vault/SpvVaultFrontEvent.js +16 -16
- package/dist/events/types/spv_vault/SpvVaultOpenEvent.d.ts +7 -7
- package/dist/events/types/spv_vault/SpvVaultOpenEvent.js +13 -13
- package/dist/events/types/swap/ClaimEvent.d.ts +7 -7
- package/dist/events/types/swap/ClaimEvent.js +11 -11
- package/dist/events/types/swap/InitializeEvent.d.ts +9 -9
- package/dist/events/types/swap/InitializeEvent.js +12 -12
- package/dist/events/types/swap/RefundEvent.d.ts +5 -5
- package/dist/events/types/swap/RefundEvent.js +7 -7
- package/dist/events/types/swap/SwapEvent.d.ts +12 -12
- package/dist/events/types/swap/SwapEvent.js +17 -17
- package/dist/index.d.ts +42 -38
- package/dist/index.js +58 -54
- package/dist/lockable/Lockable.d.ts +6 -6
- package/dist/lockable/Lockable.js +28 -28
- package/dist/messaging/Messenger.d.ts +8 -0
- package/dist/messaging/Messenger.js +2 -0
- package/dist/messaging/messages/Message.d.ts +11 -0
- package/dist/messaging/messages/Message.js +22 -0
- package/dist/messaging/messages/SwapClaimWitnessMessage.d.ts +10 -0
- package/dist/messaging/messages/SwapClaimWitnessMessage.js +28 -0
- package/dist/spv_swap/SpvVaultContract.d.ts +258 -199
- package/dist/spv_swap/SpvVaultContract.js +2 -2
- package/dist/spv_swap/SpvVaultData.d.ts +35 -35
- package/dist/spv_swap/SpvVaultData.js +37 -37
- package/dist/spv_swap/SpvWithdrawalState.d.ts +31 -31
- package/dist/spv_swap/SpvWithdrawalState.js +10 -10
- package/dist/spv_swap/SpvWithdrawalTransactionData.d.ts +43 -43
- package/dist/spv_swap/SpvWithdrawalTransactionData.js +143 -143
- package/dist/storage/IStorageManager.d.ts +15 -15
- package/dist/storage/IStorageManager.js +2 -2
- package/dist/storage/StorageObject.d.ts +3 -3
- package/dist/storage/StorageObject.js +2 -2
- package/dist/swaps/ChainSwapType.d.ts +6 -6
- package/dist/swaps/ChainSwapType.js +10 -10
- package/dist/swaps/SwapCommitState.d.ts +39 -38
- package/dist/swaps/SwapCommitState.js +11 -11
- package/dist/swaps/SwapContract.d.ts +479 -467
- package/dist/swaps/SwapContract.js +2 -2
- package/dist/swaps/SwapData.d.ts +37 -36
- package/dist/swaps/SwapData.js +17 -14
- package/dist/utils/BigIntBufferUtils.d.ts +6 -6
- package/dist/utils/BigIntBufferUtils.js +31 -31
- package/package.json +31 -31
- package/src/btc/BitcoinNetwork.ts +6 -6
- package/src/btc/rpc/BitcoinRpc.ts +77 -77
- package/src/btcrelay/BtcRelay.ts +70 -70
- package/src/btcrelay/synchronizer/RelaySynchronizer.ts +17 -17
- package/src/btcrelay/types/BtcBlock.ts +15 -15
- package/src/btcrelay/types/BtcHeader.ts +11 -11
- package/src/btcrelay/types/BtcStoredHeader.ts +12 -12
- package/src/btcrelay/utils/StatePredictorUtils.ts +108 -108
- package/src/chains/ChainData.ts +40 -40
- package/src/chains/ChainInterface.ts +159 -132
- package/src/chains/ChainType.ts +40 -38
- package/src/errors/CannotInitializeATAError.ts +11 -11
- package/src/errors/SignatureVerificationError.ts +11 -11
- package/src/errors/SwapDataVerificationError.ts +11 -11
- package/src/errors/TransactionRevertedError.ts +11 -0
- package/src/events/ChainEvents.ts +13 -13
- package/src/events/types/ChainEvent.ts +10 -10
- package/src/events/types/spv_vault/SpvVaultClaimEvent.ts +31 -31
- package/src/events/types/spv_vault/SpvVaultCloseEvent.ts +17 -17
- package/src/events/types/spv_vault/SpvVaultDepositEvent.ts +17 -17
- package/src/events/types/spv_vault/SpvVaultEvent.ts +25 -25
- package/src/events/types/spv_vault/SpvVaultFrontEvent.ts +27 -27
- package/src/events/types/spv_vault/SpvVaultOpenEvent.ts +16 -16
- package/src/events/types/swap/ClaimEvent.ts +15 -15
- package/src/events/types/swap/InitializeEvent.ts +18 -18
- package/src/events/types/swap/RefundEvent.ts +6 -6
- package/src/events/types/swap/SwapEvent.ts +21 -21
- package/src/index.ts +51 -46
- package/src/lockable/Lockable.ts +30 -30
- package/src/messaging/Messenger.ts +11 -0
- package/src/messaging/messages/Message.ts +25 -0
- package/src/messaging/messages/SwapClaimWitnessMessage.ts +34 -0
- package/src/spv_swap/SpvVaultContract.ts +269 -230
- package/src/spv_swap/SpvVaultData.ts +70 -70
- package/src/spv_swap/SpvWithdrawalState.ts +40 -40
- package/src/spv_swap/SpvWithdrawalTransactionData.ts +169 -169
- package/src/storage/IStorageManager.ts +16 -16
- package/src/storage/StorageObject.ts +6 -6
- package/src/swaps/ChainSwapType.ts +6 -6
- package/src/swaps/SwapCommitState.ts +40 -39
- package/src/swaps/SwapContract.ts +564 -556
- package/src/swaps/SwapData.ts +69 -65
- package/src/utils/BigIntBufferUtils.ts +31 -31
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SpvVaultData = void 0;
|
|
4
|
-
class SpvVaultData {
|
|
5
|
-
static deserialize(data) {
|
|
6
|
-
if (SpvVaultData.deserializers[data.type] != null) {
|
|
7
|
-
return new SpvVaultData.deserializers[data.type](data);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
calculateStateAfter(priorWithdrawalTxs) {
|
|
11
|
-
const balances = [...this.getBalances()];
|
|
12
|
-
let withdrawalCount = this.getWithdrawalCount();
|
|
13
|
-
let utxo = this.getUtxo();
|
|
14
|
-
for (let withdrawalTx of priorWithdrawalTxs) {
|
|
15
|
-
if (withdrawalTx.getSpentVaultUtxo() !== utxo)
|
|
16
|
-
throw new Error("Invalid transaction, doesn't spend prior vault UTXO!");
|
|
17
|
-
withdrawalTx.getTotalOutput().forEach((value, i) => {
|
|
18
|
-
if (balances[i] == null)
|
|
19
|
-
throw new Error("Tried to withdraw non-existing token!");
|
|
20
|
-
balances[i].rawAmount -= value;
|
|
21
|
-
if (balances[i].rawAmount < 0n)
|
|
22
|
-
throw new Error("Prior transaction withdrew more than available in vault");
|
|
23
|
-
});
|
|
24
|
-
utxo = withdrawalTx.getCreatedVaultUtxo();
|
|
25
|
-
withdrawalCount++;
|
|
26
|
-
}
|
|
27
|
-
balances.forEach(balance => {
|
|
28
|
-
balance.scaledAmount = balance.rawAmount * balance.multiplier;
|
|
29
|
-
});
|
|
30
|
-
return {
|
|
31
|
-
withdrawalCount,
|
|
32
|
-
balances
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.SpvVaultData = SpvVaultData;
|
|
37
|
-
SpvVaultData.deserializers = {};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SpvVaultData = void 0;
|
|
4
|
+
class SpvVaultData {
|
|
5
|
+
static deserialize(data) {
|
|
6
|
+
if (SpvVaultData.deserializers[data.type] != null) {
|
|
7
|
+
return new SpvVaultData.deserializers[data.type](data);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
calculateStateAfter(priorWithdrawalTxs) {
|
|
11
|
+
const balances = [...this.getBalances()];
|
|
12
|
+
let withdrawalCount = this.getWithdrawalCount();
|
|
13
|
+
let utxo = this.getUtxo();
|
|
14
|
+
for (let withdrawalTx of priorWithdrawalTxs) {
|
|
15
|
+
if (withdrawalTx.getSpentVaultUtxo() !== utxo)
|
|
16
|
+
throw new Error("Invalid transaction, doesn't spend prior vault UTXO!");
|
|
17
|
+
withdrawalTx.getTotalOutput().forEach((value, i) => {
|
|
18
|
+
if (balances[i] == null)
|
|
19
|
+
throw new Error("Tried to withdraw non-existing token!");
|
|
20
|
+
balances[i].rawAmount -= value;
|
|
21
|
+
if (balances[i].rawAmount < 0n)
|
|
22
|
+
throw new Error("Prior transaction withdrew more than available in vault");
|
|
23
|
+
});
|
|
24
|
+
utxo = withdrawalTx.getCreatedVaultUtxo();
|
|
25
|
+
withdrawalCount++;
|
|
26
|
+
}
|
|
27
|
+
balances.forEach(balance => {
|
|
28
|
+
balance.scaledAmount = balance.rawAmount * balance.multiplier;
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
withdrawalCount,
|
|
32
|
+
balances
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.SpvVaultData = SpvVaultData;
|
|
37
|
+
SpvVaultData.deserializers = {};
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
export declare enum SpvWithdrawalStateType {
|
|
2
|
-
CLOSED = -1,
|
|
3
|
-
NOT_FOUND = 0,
|
|
4
|
-
CLAIMED = 1,
|
|
5
|
-
FRONTED = 2
|
|
6
|
-
}
|
|
7
|
-
export type SpvWithdrawalNotFoundState = {
|
|
8
|
-
type: SpvWithdrawalStateType.NOT_FOUND;
|
|
9
|
-
};
|
|
10
|
-
type SpvWithdrawalStateCommon = {
|
|
11
|
-
txId: string;
|
|
12
|
-
owner: string;
|
|
13
|
-
vaultId: bigint;
|
|
14
|
-
};
|
|
15
|
-
export type SpvWithdrawalClaimedState = {
|
|
16
|
-
type: SpvWithdrawalStateType.CLAIMED;
|
|
17
|
-
recipient: string;
|
|
18
|
-
claimer: string;
|
|
19
|
-
fronter: string;
|
|
20
|
-
} & SpvWithdrawalStateCommon;
|
|
21
|
-
export type SpvWithdrawalFrontedState = {
|
|
22
|
-
type: SpvWithdrawalStateType.FRONTED;
|
|
23
|
-
recipient: string;
|
|
24
|
-
fronter: string;
|
|
25
|
-
} & SpvWithdrawalStateCommon;
|
|
26
|
-
export type SpvWithdrawalClosedState = {
|
|
27
|
-
type: SpvWithdrawalStateType.CLOSED;
|
|
28
|
-
error: string;
|
|
29
|
-
} & SpvWithdrawalStateCommon;
|
|
30
|
-
export type SpvWithdrawalState = SpvWithdrawalNotFoundState | SpvWithdrawalClaimedState | SpvWithdrawalFrontedState | SpvWithdrawalClosedState;
|
|
31
|
-
export {};
|
|
1
|
+
export declare enum SpvWithdrawalStateType {
|
|
2
|
+
CLOSED = -1,
|
|
3
|
+
NOT_FOUND = 0,
|
|
4
|
+
CLAIMED = 1,
|
|
5
|
+
FRONTED = 2
|
|
6
|
+
}
|
|
7
|
+
export type SpvWithdrawalNotFoundState = {
|
|
8
|
+
type: SpvWithdrawalStateType.NOT_FOUND;
|
|
9
|
+
};
|
|
10
|
+
type SpvWithdrawalStateCommon = {
|
|
11
|
+
txId: string;
|
|
12
|
+
owner: string;
|
|
13
|
+
vaultId: bigint;
|
|
14
|
+
};
|
|
15
|
+
export type SpvWithdrawalClaimedState = {
|
|
16
|
+
type: SpvWithdrawalStateType.CLAIMED;
|
|
17
|
+
recipient: string;
|
|
18
|
+
claimer: string;
|
|
19
|
+
fronter: string;
|
|
20
|
+
} & SpvWithdrawalStateCommon;
|
|
21
|
+
export type SpvWithdrawalFrontedState = {
|
|
22
|
+
type: SpvWithdrawalStateType.FRONTED;
|
|
23
|
+
recipient: string;
|
|
24
|
+
fronter: string;
|
|
25
|
+
} & SpvWithdrawalStateCommon;
|
|
26
|
+
export type SpvWithdrawalClosedState = {
|
|
27
|
+
type: SpvWithdrawalStateType.CLOSED;
|
|
28
|
+
error: string;
|
|
29
|
+
} & SpvWithdrawalStateCommon;
|
|
30
|
+
export type SpvWithdrawalState = SpvWithdrawalNotFoundState | SpvWithdrawalClaimedState | SpvWithdrawalFrontedState | SpvWithdrawalClosedState;
|
|
31
|
+
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SpvWithdrawalStateType = void 0;
|
|
4
|
-
var SpvWithdrawalStateType;
|
|
5
|
-
(function (SpvWithdrawalStateType) {
|
|
6
|
-
SpvWithdrawalStateType[SpvWithdrawalStateType["CLOSED"] = -1] = "CLOSED";
|
|
7
|
-
SpvWithdrawalStateType[SpvWithdrawalStateType["NOT_FOUND"] = 0] = "NOT_FOUND";
|
|
8
|
-
SpvWithdrawalStateType[SpvWithdrawalStateType["CLAIMED"] = 1] = "CLAIMED";
|
|
9
|
-
SpvWithdrawalStateType[SpvWithdrawalStateType["FRONTED"] = 2] = "FRONTED";
|
|
10
|
-
})(SpvWithdrawalStateType = exports.SpvWithdrawalStateType || (exports.SpvWithdrawalStateType = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SpvWithdrawalStateType = void 0;
|
|
4
|
+
var SpvWithdrawalStateType;
|
|
5
|
+
(function (SpvWithdrawalStateType) {
|
|
6
|
+
SpvWithdrawalStateType[SpvWithdrawalStateType["CLOSED"] = -1] = "CLOSED";
|
|
7
|
+
SpvWithdrawalStateType[SpvWithdrawalStateType["NOT_FOUND"] = 0] = "NOT_FOUND";
|
|
8
|
+
SpvWithdrawalStateType[SpvWithdrawalStateType["CLAIMED"] = 1] = "CLAIMED";
|
|
9
|
+
SpvWithdrawalStateType[SpvWithdrawalStateType["FRONTED"] = 2] = "FRONTED";
|
|
10
|
+
})(SpvWithdrawalStateType = exports.SpvWithdrawalStateType || (exports.SpvWithdrawalStateType = {}));
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { BtcTx } from "../btc/rpc/BitcoinRpc";
|
|
3
|
-
import { Buffer } from "buffer";
|
|
4
|
-
import { StorageObject } from "../storage/StorageObject";
|
|
5
|
-
export type ExecutionData = {
|
|
6
|
-
executionHash: string;
|
|
7
|
-
executionExpiry: number;
|
|
8
|
-
};
|
|
9
|
-
export declare abstract class SpvWithdrawalTransactionData implements StorageObject {
|
|
10
|
-
static deserializers: {
|
|
11
|
-
[type: string]: new (serialized: any) => any;
|
|
12
|
-
};
|
|
13
|
-
static deserialize<T extends SpvWithdrawalTransactionData>(data: any): T;
|
|
14
|
-
protected abstract fromOpReturnData(data: Buffer): {
|
|
15
|
-
recipient: string;
|
|
16
|
-
rawAmounts: bigint[];
|
|
17
|
-
executionHash: string;
|
|
18
|
-
};
|
|
19
|
-
readonly recipient: string;
|
|
20
|
-
readonly rawAmounts: bigint[];
|
|
21
|
-
readonly callerFeeRate: bigint;
|
|
22
|
-
readonly executionFeeRate: bigint;
|
|
23
|
-
readonly frontingFeeRate: bigint;
|
|
24
|
-
readonly executionHash: string;
|
|
25
|
-
readonly executionExpiry: number;
|
|
26
|
-
readonly btcTx: BtcTx;
|
|
27
|
-
constructor(btcTx: BtcTx);
|
|
28
|
-
serialize(): any;
|
|
29
|
-
getRecipient(): string;
|
|
30
|
-
abstract isRecipient(address: string): boolean;
|
|
31
|
-
abstract getFrontingId(): string;
|
|
32
|
-
getOutputWithoutFees(): bigint[];
|
|
33
|
-
getCallerFee(): bigint[];
|
|
34
|
-
getFrontingFee(): bigint[];
|
|
35
|
-
getExecutionFee(): bigint[];
|
|
36
|
-
getTotalOutput(): bigint[];
|
|
37
|
-
getExecutionData(): ExecutionData | null;
|
|
38
|
-
getTxId(): string;
|
|
39
|
-
getSpentVaultUtxo(): string;
|
|
40
|
-
getCreatedVaultUtxo(): string;
|
|
41
|
-
getNewVaultScript(): Buffer;
|
|
42
|
-
getNewVaultBtcAmount(): number;
|
|
43
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { BtcTx } from "../btc/rpc/BitcoinRpc";
|
|
3
|
+
import { Buffer } from "buffer";
|
|
4
|
+
import { StorageObject } from "../storage/StorageObject";
|
|
5
|
+
export type ExecutionData = {
|
|
6
|
+
executionHash: string;
|
|
7
|
+
executionExpiry: number;
|
|
8
|
+
};
|
|
9
|
+
export declare abstract class SpvWithdrawalTransactionData implements StorageObject {
|
|
10
|
+
static deserializers: {
|
|
11
|
+
[type: string]: new (serialized: any) => any;
|
|
12
|
+
};
|
|
13
|
+
static deserialize<T extends SpvWithdrawalTransactionData>(data: any): T;
|
|
14
|
+
protected abstract fromOpReturnData(data: Buffer): {
|
|
15
|
+
recipient: string;
|
|
16
|
+
rawAmounts: bigint[];
|
|
17
|
+
executionHash: string;
|
|
18
|
+
};
|
|
19
|
+
readonly recipient: string;
|
|
20
|
+
readonly rawAmounts: bigint[];
|
|
21
|
+
readonly callerFeeRate: bigint;
|
|
22
|
+
readonly executionFeeRate: bigint;
|
|
23
|
+
readonly frontingFeeRate: bigint;
|
|
24
|
+
readonly executionHash: string;
|
|
25
|
+
readonly executionExpiry: number;
|
|
26
|
+
readonly btcTx: BtcTx;
|
|
27
|
+
constructor(btcTx: BtcTx);
|
|
28
|
+
serialize(): any;
|
|
29
|
+
getRecipient(): string;
|
|
30
|
+
abstract isRecipient(address: string): boolean;
|
|
31
|
+
abstract getFrontingId(): string;
|
|
32
|
+
getOutputWithoutFees(): bigint[];
|
|
33
|
+
getCallerFee(): bigint[];
|
|
34
|
+
getFrontingFee(): bigint[];
|
|
35
|
+
getExecutionFee(): bigint[];
|
|
36
|
+
getTotalOutput(): bigint[];
|
|
37
|
+
getExecutionData(): ExecutionData | null;
|
|
38
|
+
getTxId(): string;
|
|
39
|
+
getSpentVaultUtxo(): string;
|
|
40
|
+
getCreatedVaultUtxo(): string;
|
|
41
|
+
getNewVaultScript(): Buffer;
|
|
42
|
+
getNewVaultBtcAmount(): number;
|
|
43
|
+
}
|
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SpvWithdrawalTransactionData = void 0;
|
|
4
|
-
const buffer_1 = require("buffer");
|
|
5
|
-
class SpvWithdrawalTransactionData {
|
|
6
|
-
static deserialize(data) {
|
|
7
|
-
if (SpvWithdrawalTransactionData.deserializers[data.type] != null) {
|
|
8
|
-
return new SpvWithdrawalTransactionData.deserializers[data.type](data);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
constructor(btcTx) {
|
|
12
|
-
if (btcTx.ins.length < 2)
|
|
13
|
-
throw new Error("Need at least 2 inputs");
|
|
14
|
-
if (btcTx.outs.length < 2)
|
|
15
|
-
throw new Error("Need at least 2 outputs");
|
|
16
|
-
const nSequence0 = BigInt(btcTx.ins[0].sequence);
|
|
17
|
-
const nSequence1 = BigInt(btcTx.ins[1].sequence);
|
|
18
|
-
if ((nSequence0 & 0x80000000n) != 0x80000000n)
|
|
19
|
-
throw new Error("nSequence0 high bit not set!");
|
|
20
|
-
if ((nSequence1 & 0x80000000n) != 0x80000000n)
|
|
21
|
-
throw new Error("nSequence0 high bit not set!");
|
|
22
|
-
const callerFeeRate = nSequence0 & 0xfffffn;
|
|
23
|
-
const executionFeeRate = nSequence1 & 0xfffffn;
|
|
24
|
-
const frontingFeeRate = ((nSequence0 >> 10n) & 1047552n) | ((nSequence1 >> 20n) & 1023n);
|
|
25
|
-
const executionExpiry = btcTx.locktime + 1000000000;
|
|
26
|
-
if (executionExpiry >= Math.pow(2, 32))
|
|
27
|
-
throw new Error("Execution expiry overflow");
|
|
28
|
-
const opReturnOutput = btcTx.outs[1];
|
|
29
|
-
//Parse script
|
|
30
|
-
const opReturnData = buffer_1.Buffer.from(opReturnOutput.scriptPubKey.hex, "hex");
|
|
31
|
-
if (opReturnData.length === 0)
|
|
32
|
-
throw new Error("Output 1 empty script");
|
|
33
|
-
if (opReturnData.at(0) !== 0x6a)
|
|
34
|
-
throw new Error("Output 1 is not OP_RETURN");
|
|
35
|
-
if (opReturnData.at(1) === 0)
|
|
36
|
-
throw new Error("Output 1 OP_RETURN followed by OP_0");
|
|
37
|
-
let data;
|
|
38
|
-
if (opReturnData.at(1) === 0x4c) { //OP_PUSHDATA1
|
|
39
|
-
const dataLength = opReturnData.at(2);
|
|
40
|
-
data = opReturnData.subarray(3, 3 + dataLength);
|
|
41
|
-
if (data.length !== dataLength)
|
|
42
|
-
throw new Error("Output 1 OP_RETURN data length mismatch!");
|
|
43
|
-
}
|
|
44
|
-
else if (opReturnData.at(1) <= 0x4b) { //OP_PUSH<length>
|
|
45
|
-
const dataLength = opReturnData.at(1);
|
|
46
|
-
data = opReturnData.subarray(2, 2 + dataLength);
|
|
47
|
-
if (data.length !== dataLength)
|
|
48
|
-
throw new Error("Output 1 OP_RETURN data length mismatch!");
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
throw new Error("Output 1 invalid push opcode");
|
|
52
|
-
}
|
|
53
|
-
//Parse OP_RETURN data
|
|
54
|
-
const res = this.fromOpReturnData(data);
|
|
55
|
-
this.recipient = res.recipient;
|
|
56
|
-
this.rawAmounts = res.rawAmounts;
|
|
57
|
-
this.callerFeeRate = callerFeeRate;
|
|
58
|
-
this.frontingFeeRate = frontingFeeRate;
|
|
59
|
-
this.executionFeeRate = executionFeeRate;
|
|
60
|
-
this.executionHash = res.executionHash;
|
|
61
|
-
this.executionExpiry = executionExpiry;
|
|
62
|
-
this.btcTx = btcTx;
|
|
63
|
-
}
|
|
64
|
-
serialize() {
|
|
65
|
-
return this.btcTx;
|
|
66
|
-
}
|
|
67
|
-
getRecipient() {
|
|
68
|
-
return this.recipient;
|
|
69
|
-
}
|
|
70
|
-
getOutputWithoutFees() {
|
|
71
|
-
return this.rawAmounts;
|
|
72
|
-
}
|
|
73
|
-
getCallerFee() {
|
|
74
|
-
return this.rawAmounts.map(val => val * this.callerFeeRate / 100000n);
|
|
75
|
-
}
|
|
76
|
-
getFrontingFee() {
|
|
77
|
-
return this.rawAmounts.map(val => val * this.frontingFeeRate / 100000n);
|
|
78
|
-
}
|
|
79
|
-
getExecutionFee() {
|
|
80
|
-
return [this.rawAmounts[0] * this.executionFeeRate / 100000n];
|
|
81
|
-
}
|
|
82
|
-
getTotalOutput() {
|
|
83
|
-
const amounts = [...this.getOutputWithoutFees()];
|
|
84
|
-
const callerFee = this.getCallerFee();
|
|
85
|
-
if (callerFee != null)
|
|
86
|
-
callerFee.forEach((fee, i) => {
|
|
87
|
-
if (fee == null || fee === 0n)
|
|
88
|
-
return;
|
|
89
|
-
if (amounts[i] == null)
|
|
90
|
-
throw new Error("Caller fee token out of bounds");
|
|
91
|
-
amounts[i] += fee;
|
|
92
|
-
});
|
|
93
|
-
const frontingFee = this.getFrontingFee();
|
|
94
|
-
if (frontingFee != null)
|
|
95
|
-
frontingFee.forEach((fee, i) => {
|
|
96
|
-
if (fee == null || fee === 0n)
|
|
97
|
-
return;
|
|
98
|
-
if (amounts[i] == null)
|
|
99
|
-
throw new Error("Fronting fee token out of bounds");
|
|
100
|
-
amounts[i] += fee;
|
|
101
|
-
});
|
|
102
|
-
const executionFee = this.getExecutionFee();
|
|
103
|
-
if (executionFee != null)
|
|
104
|
-
executionFee.forEach((fee, i) => {
|
|
105
|
-
if (fee == null || fee === 0n)
|
|
106
|
-
return;
|
|
107
|
-
if (amounts[i] == null)
|
|
108
|
-
throw new Error("Execution fee token out of bounds");
|
|
109
|
-
amounts[i] += fee;
|
|
110
|
-
});
|
|
111
|
-
amounts.forEach((val, index) => {
|
|
112
|
-
if (val >= 2n ** 64n)
|
|
113
|
-
throw new Error("Token " + index + " amount out of bounds");
|
|
114
|
-
});
|
|
115
|
-
return amounts;
|
|
116
|
-
}
|
|
117
|
-
getExecutionData() {
|
|
118
|
-
if (this.executionHash == null)
|
|
119
|
-
return null;
|
|
120
|
-
return {
|
|
121
|
-
executionHash: this.executionHash,
|
|
122
|
-
executionExpiry: this.executionExpiry
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
getTxId() {
|
|
126
|
-
return this.btcTx.txid;
|
|
127
|
-
}
|
|
128
|
-
getSpentVaultUtxo() {
|
|
129
|
-
const in0 = this.btcTx.ins[0];
|
|
130
|
-
return in0.txid + ":" + in0.vout;
|
|
131
|
-
}
|
|
132
|
-
getCreatedVaultUtxo() {
|
|
133
|
-
return this.getTxId() + ":0";
|
|
134
|
-
}
|
|
135
|
-
getNewVaultScript() {
|
|
136
|
-
return buffer_1.Buffer.from(this.btcTx.outs[0].scriptPubKey.hex, "hex");
|
|
137
|
-
}
|
|
138
|
-
getNewVaultBtcAmount() {
|
|
139
|
-
return this.btcTx.outs[0].value;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
exports.SpvWithdrawalTransactionData = SpvWithdrawalTransactionData;
|
|
143
|
-
SpvWithdrawalTransactionData.deserializers = {};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SpvWithdrawalTransactionData = void 0;
|
|
4
|
+
const buffer_1 = require("buffer");
|
|
5
|
+
class SpvWithdrawalTransactionData {
|
|
6
|
+
static deserialize(data) {
|
|
7
|
+
if (SpvWithdrawalTransactionData.deserializers[data.type] != null) {
|
|
8
|
+
return new SpvWithdrawalTransactionData.deserializers[data.type](data);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
constructor(btcTx) {
|
|
12
|
+
if (btcTx.ins.length < 2)
|
|
13
|
+
throw new Error("Need at least 2 inputs");
|
|
14
|
+
if (btcTx.outs.length < 2)
|
|
15
|
+
throw new Error("Need at least 2 outputs");
|
|
16
|
+
const nSequence0 = BigInt(btcTx.ins[0].sequence);
|
|
17
|
+
const nSequence1 = BigInt(btcTx.ins[1].sequence);
|
|
18
|
+
if ((nSequence0 & 0x80000000n) != 0x80000000n)
|
|
19
|
+
throw new Error("nSequence0 high bit not set!");
|
|
20
|
+
if ((nSequence1 & 0x80000000n) != 0x80000000n)
|
|
21
|
+
throw new Error("nSequence0 high bit not set!");
|
|
22
|
+
const callerFeeRate = nSequence0 & 0xfffffn;
|
|
23
|
+
const executionFeeRate = nSequence1 & 0xfffffn;
|
|
24
|
+
const frontingFeeRate = ((nSequence0 >> 10n) & 1047552n) | ((nSequence1 >> 20n) & 1023n);
|
|
25
|
+
const executionExpiry = btcTx.locktime + 1000000000;
|
|
26
|
+
if (executionExpiry >= Math.pow(2, 32))
|
|
27
|
+
throw new Error("Execution expiry overflow");
|
|
28
|
+
const opReturnOutput = btcTx.outs[1];
|
|
29
|
+
//Parse script
|
|
30
|
+
const opReturnData = buffer_1.Buffer.from(opReturnOutput.scriptPubKey.hex, "hex");
|
|
31
|
+
if (opReturnData.length === 0)
|
|
32
|
+
throw new Error("Output 1 empty script");
|
|
33
|
+
if (opReturnData.at(0) !== 0x6a)
|
|
34
|
+
throw new Error("Output 1 is not OP_RETURN");
|
|
35
|
+
if (opReturnData.at(1) === 0)
|
|
36
|
+
throw new Error("Output 1 OP_RETURN followed by OP_0");
|
|
37
|
+
let data;
|
|
38
|
+
if (opReturnData.at(1) === 0x4c) { //OP_PUSHDATA1
|
|
39
|
+
const dataLength = opReturnData.at(2);
|
|
40
|
+
data = opReturnData.subarray(3, 3 + dataLength);
|
|
41
|
+
if (data.length !== dataLength)
|
|
42
|
+
throw new Error("Output 1 OP_RETURN data length mismatch!");
|
|
43
|
+
}
|
|
44
|
+
else if (opReturnData.at(1) <= 0x4b) { //OP_PUSH<length>
|
|
45
|
+
const dataLength = opReturnData.at(1);
|
|
46
|
+
data = opReturnData.subarray(2, 2 + dataLength);
|
|
47
|
+
if (data.length !== dataLength)
|
|
48
|
+
throw new Error("Output 1 OP_RETURN data length mismatch!");
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw new Error("Output 1 invalid push opcode");
|
|
52
|
+
}
|
|
53
|
+
//Parse OP_RETURN data
|
|
54
|
+
const res = this.fromOpReturnData(data);
|
|
55
|
+
this.recipient = res.recipient;
|
|
56
|
+
this.rawAmounts = res.rawAmounts;
|
|
57
|
+
this.callerFeeRate = callerFeeRate;
|
|
58
|
+
this.frontingFeeRate = frontingFeeRate;
|
|
59
|
+
this.executionFeeRate = executionFeeRate;
|
|
60
|
+
this.executionHash = res.executionHash;
|
|
61
|
+
this.executionExpiry = executionExpiry;
|
|
62
|
+
this.btcTx = btcTx;
|
|
63
|
+
}
|
|
64
|
+
serialize() {
|
|
65
|
+
return this.btcTx;
|
|
66
|
+
}
|
|
67
|
+
getRecipient() {
|
|
68
|
+
return this.recipient;
|
|
69
|
+
}
|
|
70
|
+
getOutputWithoutFees() {
|
|
71
|
+
return this.rawAmounts;
|
|
72
|
+
}
|
|
73
|
+
getCallerFee() {
|
|
74
|
+
return this.rawAmounts.map(val => val * this.callerFeeRate / 100000n);
|
|
75
|
+
}
|
|
76
|
+
getFrontingFee() {
|
|
77
|
+
return this.rawAmounts.map(val => val * this.frontingFeeRate / 100000n);
|
|
78
|
+
}
|
|
79
|
+
getExecutionFee() {
|
|
80
|
+
return [this.rawAmounts[0] * this.executionFeeRate / 100000n];
|
|
81
|
+
}
|
|
82
|
+
getTotalOutput() {
|
|
83
|
+
const amounts = [...this.getOutputWithoutFees()];
|
|
84
|
+
const callerFee = this.getCallerFee();
|
|
85
|
+
if (callerFee != null)
|
|
86
|
+
callerFee.forEach((fee, i) => {
|
|
87
|
+
if (fee == null || fee === 0n)
|
|
88
|
+
return;
|
|
89
|
+
if (amounts[i] == null)
|
|
90
|
+
throw new Error("Caller fee token out of bounds");
|
|
91
|
+
amounts[i] += fee;
|
|
92
|
+
});
|
|
93
|
+
const frontingFee = this.getFrontingFee();
|
|
94
|
+
if (frontingFee != null)
|
|
95
|
+
frontingFee.forEach((fee, i) => {
|
|
96
|
+
if (fee == null || fee === 0n)
|
|
97
|
+
return;
|
|
98
|
+
if (amounts[i] == null)
|
|
99
|
+
throw new Error("Fronting fee token out of bounds");
|
|
100
|
+
amounts[i] += fee;
|
|
101
|
+
});
|
|
102
|
+
const executionFee = this.getExecutionFee();
|
|
103
|
+
if (executionFee != null)
|
|
104
|
+
executionFee.forEach((fee, i) => {
|
|
105
|
+
if (fee == null || fee === 0n)
|
|
106
|
+
return;
|
|
107
|
+
if (amounts[i] == null)
|
|
108
|
+
throw new Error("Execution fee token out of bounds");
|
|
109
|
+
amounts[i] += fee;
|
|
110
|
+
});
|
|
111
|
+
amounts.forEach((val, index) => {
|
|
112
|
+
if (val >= 2n ** 64n)
|
|
113
|
+
throw new Error("Token " + index + " amount out of bounds");
|
|
114
|
+
});
|
|
115
|
+
return amounts;
|
|
116
|
+
}
|
|
117
|
+
getExecutionData() {
|
|
118
|
+
if (this.executionHash == null)
|
|
119
|
+
return null;
|
|
120
|
+
return {
|
|
121
|
+
executionHash: this.executionHash,
|
|
122
|
+
executionExpiry: this.executionExpiry
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
getTxId() {
|
|
126
|
+
return this.btcTx.txid;
|
|
127
|
+
}
|
|
128
|
+
getSpentVaultUtxo() {
|
|
129
|
+
const in0 = this.btcTx.ins[0];
|
|
130
|
+
return in0.txid + ":" + in0.vout;
|
|
131
|
+
}
|
|
132
|
+
getCreatedVaultUtxo() {
|
|
133
|
+
return this.getTxId() + ":0";
|
|
134
|
+
}
|
|
135
|
+
getNewVaultScript() {
|
|
136
|
+
return buffer_1.Buffer.from(this.btcTx.outs[0].scriptPubKey.hex, "hex");
|
|
137
|
+
}
|
|
138
|
+
getNewVaultBtcAmount() {
|
|
139
|
+
return this.btcTx.outs[0].value;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.SpvWithdrawalTransactionData = SpvWithdrawalTransactionData;
|
|
143
|
+
SpvWithdrawalTransactionData.deserializers = {};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { StorageObject } from "./StorageObject";
|
|
2
|
-
export interface IStorageManager<T extends StorageObject> {
|
|
3
|
-
data: {
|
|
4
|
-
[key: string]: T;
|
|
5
|
-
};
|
|
6
|
-
init(): Promise<void>;
|
|
7
|
-
saveData(hash: string, object: T): Promise<void>;
|
|
8
|
-
removeData(hash: string): Promise<void>;
|
|
9
|
-
loadData(type: new (data: any) => T): Promise<T[]>;
|
|
10
|
-
removeDataArr?(keys: string[]): Promise<void>;
|
|
11
|
-
saveDataArr?(values: {
|
|
12
|
-
id: string;
|
|
13
|
-
object: T;
|
|
14
|
-
}[]): Promise<void>;
|
|
15
|
-
}
|
|
1
|
+
import { StorageObject } from "./StorageObject";
|
|
2
|
+
export interface IStorageManager<T extends StorageObject> {
|
|
3
|
+
data: {
|
|
4
|
+
[key: string]: T;
|
|
5
|
+
};
|
|
6
|
+
init(): Promise<void>;
|
|
7
|
+
saveData(hash: string, object: T): Promise<void>;
|
|
8
|
+
removeData(hash: string): Promise<void>;
|
|
9
|
+
loadData(type: new (data: any) => T): Promise<T[]>;
|
|
10
|
+
removeDataArr?(keys: string[]): Promise<void>;
|
|
11
|
+
saveDataArr?(values: {
|
|
12
|
+
id: string;
|
|
13
|
+
object: T;
|
|
14
|
+
}[]): Promise<void>;
|
|
15
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export interface StorageObject {
|
|
2
|
-
serialize(): any;
|
|
3
|
-
}
|
|
1
|
+
export interface StorageObject {
|
|
2
|
+
serialize(): any;
|
|
3
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare enum ChainSwapType {
|
|
2
|
-
HTLC = 0,
|
|
3
|
-
CHAIN = 1,
|
|
4
|
-
CHAIN_NONCED = 2,
|
|
5
|
-
CHAIN_TXID = 3
|
|
6
|
-
}
|
|
1
|
+
export declare enum ChainSwapType {
|
|
2
|
+
HTLC = 0,
|
|
3
|
+
CHAIN = 1,
|
|
4
|
+
CHAIN_NONCED = 2,
|
|
5
|
+
CHAIN_TXID = 3
|
|
6
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChainSwapType = void 0;
|
|
4
|
-
var ChainSwapType;
|
|
5
|
-
(function (ChainSwapType) {
|
|
6
|
-
ChainSwapType[ChainSwapType["HTLC"] = 0] = "HTLC";
|
|
7
|
-
ChainSwapType[ChainSwapType["CHAIN"] = 1] = "CHAIN";
|
|
8
|
-
ChainSwapType[ChainSwapType["CHAIN_NONCED"] = 2] = "CHAIN_NONCED";
|
|
9
|
-
ChainSwapType[ChainSwapType["CHAIN_TXID"] = 3] = "CHAIN_TXID";
|
|
10
|
-
})(ChainSwapType = exports.ChainSwapType || (exports.ChainSwapType = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChainSwapType = void 0;
|
|
4
|
+
var ChainSwapType;
|
|
5
|
+
(function (ChainSwapType) {
|
|
6
|
+
ChainSwapType[ChainSwapType["HTLC"] = 0] = "HTLC";
|
|
7
|
+
ChainSwapType[ChainSwapType["CHAIN"] = 1] = "CHAIN";
|
|
8
|
+
ChainSwapType[ChainSwapType["CHAIN_NONCED"] = 2] = "CHAIN_NONCED";
|
|
9
|
+
ChainSwapType[ChainSwapType["CHAIN_TXID"] = 3] = "CHAIN_TXID";
|
|
10
|
+
})(ChainSwapType = exports.ChainSwapType || (exports.ChainSwapType = {}));
|