@gardenfi/core 2.2.1 → 2.3.0

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.
Files changed (47) hide show
  1. package/dist/{ccip-l_tRzCaI.cjs → ccip-Bf6sMWsl.cjs} +1 -1
  2. package/dist/{ccip-BkdyF3_3.js → ccip-Nj9FMoDj.js} +1 -1
  3. package/dist/index-DVTNtaWz.cjs +99 -0
  4. package/dist/index-rQk9wiZU.js +24327 -0
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +37 -34
  7. package/dist/src/index.d.ts +5 -1
  8. package/dist/src/lib/bitcoin/API.d.ts +4 -0
  9. package/dist/src/lib/bitcoin/ASConfig.d.ts +19 -0
  10. package/dist/src/lib/bitcoin/errors.d.ts +16 -0
  11. package/dist/src/lib/bitcoin/htlc.d.ts +2 -1
  12. package/dist/src/lib/bitcoin/htlcScript.d.ts +7 -0
  13. package/dist/src/lib/bitcoin/interface.d.ts +6 -0
  14. package/dist/src/lib/bitcoin/paths.d.ts +7 -0
  15. package/dist/src/lib/bitcoin/provider/provider.d.ts +118 -0
  16. package/dist/src/lib/bitcoin/provider/provider.interface.d.ts +99 -0
  17. package/dist/src/lib/bitcoin/script.d.ts +6 -0
  18. package/dist/src/lib/bitcoin/sig.d.ts +20 -0
  19. package/dist/src/lib/bitcoin/utils.d.ts +8 -0
  20. package/dist/src/lib/bitcoin/wallet/abstractWallet.d.ts +145 -0
  21. package/dist/src/lib/bitcoin/wallet/baseWallet.d.ts +13 -0
  22. package/dist/src/lib/bitcoin/wallet/wallet.d.ts +103 -0
  23. package/dist/src/lib/bitcoin/wallet/wallet.interface.d.ts +79 -0
  24. package/dist/src/lib/blockNumberFetcher/blockNumber.d.ts +1 -2
  25. package/dist/src/lib/evm/htlc/evmHTLC.d.ts +1 -1
  26. package/dist/src/lib/evm/htlc/evmHTLC.types.d.ts +2 -2
  27. package/dist/src/lib/evm/relay/evmRelay.types.d.ts +1 -2
  28. package/dist/src/lib/garden/garden.d.ts +2 -3
  29. package/dist/src/lib/garden/garden.types.d.ts +3 -4
  30. package/dist/src/lib/htlc.interface.d.ts +7 -0
  31. package/dist/src/lib/identifier.d.ts +19 -0
  32. package/dist/src/lib/quote/quote.d.ts +7 -10
  33. package/dist/src/lib/quote/quote.types.d.ts +19 -10
  34. package/dist/src/lib/secretManager/secretManager.d.ts +5 -5
  35. package/dist/src/lib/secretManager/secretManager.types.d.ts +1 -2
  36. package/dist/src/lib/solana/htlc/ISolanaHTLC.d.ts +1 -1
  37. package/dist/src/lib/solana/htlc/solanaHTLC.d.ts +1 -1
  38. package/dist/src/lib/solana/relayer/solanaRelay.d.ts +1 -2
  39. package/dist/src/lib/starknet/checkAllowanceAndApprove.d.ts +1 -1
  40. package/dist/src/lib/starknet/htlc/starknetHTLC.d.ts +1 -2
  41. package/dist/src/lib/starknet/relay/starknetRelay.d.ts +1 -2
  42. package/dist/src/lib/starknet/starknetHTLC.types.d.ts +1 -1
  43. package/dist/src/lib/switchOrAddNetwork.d.ts +1 -1
  44. package/dist/src/lib/utils.d.ts +7 -2
  45. package/package.json +9 -7
  46. package/dist/index-eHNvzW2C.js +0 -26591
  47. package/dist/index-lHPQc7tc.cjs +0 -84
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-lHPQc7tc.cjs");exports.API=e.API;exports.BlockNumberFetcher=e.BlockNumberFetcher;exports.EvmRelay=e.EvmRelay;exports.Garden=e.Garden;exports.OrderActions=e.OrderActions;exports.OrderStatus=e.OrderStatus;exports.ParseOrderStatus=e.ParseOrderStatus;exports.ParseSwapStatus=e.ParseSwapStatus;exports.Quote=e.Quote;exports.STARKNET_CONFIG=e.STARKNET_CONFIG;exports.SecretManager=e.SecretManager;exports.SolanaHTLC=e.SolanaHTLC;exports.SolanaRelay=e.SolanaRelay;exports.SolanaRelayerAddress=e.SolanaRelayerAddress;exports.StarknetHTLC=e.StarknetHTLC;exports.StarknetRelay=e.StarknetRelay;exports.SwapStatus=e.SwapStatus;exports.botanix=e.botanixMainnet;exports.checkStarknetAlloance=e.checkAllowance;exports.checkStarknetAllowanceAndApprove=e.checkAllowanceAndApprove;exports.constructOrderPair=e.constructOrderPair;exports.evmToViemChainMap=e.evmToViemChainMap;exports.filterDeadlineExpiredOrders=e.filterDeadlineExpiredOrders;exports.hyperliquid=e.hyperliquid;exports.hyperliquidTestnet=e.hyperliquidTestnet;exports.isExpired=e.isExpired;exports.isStarknetAllowanceSufficient=e.isAllowanceSufficient;exports.parseAction=e.parseAction;exports.parseActionFromStatus=e.parseActionFromStatus;exports.resolveApiConfig=e.resolveApiConfig;exports.solanaProgramAddress=e.solanaProgramAddress;exports.switchOrAddNetwork=e.switchOrAddNetwork;exports.toXOnly=e.toXOnly;exports.validateBTCAddress=e.validateBTCAddress;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-DVTNtaWz.cjs");exports.API=e.API;exports.BitcoinNetwork=e.BitcoinNetwork;exports.BitcoinProvider=e.BitcoinProvider;exports.BitcoinWallet=e.BitcoinWallet;exports.BlockNumberFetcher=e.BlockNumberFetcher;exports.EvmRelay=e.EvmRelay;exports.Garden=e.Garden;exports.OrderActions=e.OrderActions;exports.OrderStatus=e.OrderStatus;exports.ParseOrderStatus=e.ParseOrderStatus;exports.ParseSwapStatus=e.ParseSwapStatus;exports.Quote=e.Quote;exports.STARKNET_CONFIG=e.STARKNET_CONFIG;exports.SecretManager=e.SecretManager;exports.SolanaHTLC=e.SolanaHTLC;exports.SolanaRelay=e.SolanaRelay;exports.SolanaRelayerAddress=e.SolanaRelayerAddress;exports.StarknetHTLC=e.StarknetHTLC;exports.StarknetRelay=e.StarknetRelay;exports.SwapStatus=e.SwapStatus;exports.botanix=e.botanixMainnet;exports.checkStarknetAlloance=e.checkAllowance;exports.checkStarknetAllowanceAndApprove=e.checkAllowanceAndApprove;exports.constructOrderPair=e.constructOrderPair;exports.evmToViemChainMap=e.evmToViemChainMap;exports.filterDeadlineExpiredOrders=e.filterDeadlineExpiredOrders;exports.hyperliquid=e.hyperliquid;exports.hyperliquidTestnet=e.hyperliquidTestnet;exports.isExpired=e.isExpired;exports.isStarknetAllowanceSufficient=e.isAllowanceSufficient;exports.parseAction=e.parseAction;exports.parseActionFromStatus=e.parseActionFromStatus;exports.resolveApiConfig=e.resolveApiConfig;exports.solanaProgramAddress=e.solanaProgramAddress;exports.switchOrAddNetwork=e.switchOrAddNetwork;exports.toXOnly=e.toXOnly;exports.validateBTCAddress=e.validateBTCAddress;
package/dist/index.js CHANGED
@@ -1,37 +1,40 @@
1
- import { M as e, m as r, E as t, G as n, O as o, n as i, P as l, q as d, Q as S, N as c, v as A, k as p, j as u, R as k, h as O, S as h, o as m, L as y, y as T, w, z as C, F as v, t as P, K as R, J as f, r as x, x as E, p as N, u as F, D as g, T as q, I as G, C as I, A as L } from "./index-eHNvzW2C.js";
1
+ import { T as e, M as r, N as t, R as i, m as n, E as o, G as l, O as d, n as c, P as S, q as A, Q as p, U as u, v as k, k as O, j as h, V as m, h as w, S as y, o as T, L as v, y as C, w as P, z as N, F as R, t as f, K as x, J as B, r as E, x as F, p as g, u as q, D as G, W as I, I as L, C as M, A as b } from "./index-rQk9wiZU.js";
2
2
  export {
3
3
  e as API,
4
- r as BlockNumberFetcher,
5
- t as EvmRelay,
6
- n as Garden,
7
- o as OrderActions,
8
- i as OrderStatus,
9
- l as ParseOrderStatus,
10
- d as ParseSwapStatus,
11
- S as Quote,
12
- c as STARKNET_CONFIG,
13
- A as SecretManager,
14
- p as SolanaHTLC,
15
- u as SolanaRelay,
16
- k as SolanaRelayerAddress,
17
- O as StarknetHTLC,
18
- h as StarknetRelay,
19
- m as SwapStatus,
20
- y as botanix,
21
- T as checkStarknetAlloance,
22
- w as checkStarknetAllowanceAndApprove,
23
- C as constructOrderPair,
24
- v as evmToViemChainMap,
25
- P as filterDeadlineExpiredOrders,
26
- R as hyperliquid,
27
- f as hyperliquidTestnet,
28
- x as isExpired,
29
- E as isStarknetAllowanceSufficient,
30
- N as parseAction,
31
- F as parseActionFromStatus,
32
- g as resolveApiConfig,
33
- q as solanaProgramAddress,
34
- G as switchOrAddNetwork,
35
- I as toXOnly,
36
- L as validateBTCAddress
4
+ r as BitcoinNetwork,
5
+ t as BitcoinProvider,
6
+ i as BitcoinWallet,
7
+ n as BlockNumberFetcher,
8
+ o as EvmRelay,
9
+ l as Garden,
10
+ d as OrderActions,
11
+ c as OrderStatus,
12
+ S as ParseOrderStatus,
13
+ A as ParseSwapStatus,
14
+ p as Quote,
15
+ u as STARKNET_CONFIG,
16
+ k as SecretManager,
17
+ O as SolanaHTLC,
18
+ h as SolanaRelay,
19
+ m as SolanaRelayerAddress,
20
+ w as StarknetHTLC,
21
+ y as StarknetRelay,
22
+ T as SwapStatus,
23
+ v as botanix,
24
+ C as checkStarknetAlloance,
25
+ P as checkStarknetAllowanceAndApprove,
26
+ N as constructOrderPair,
27
+ R as evmToViemChainMap,
28
+ f as filterDeadlineExpiredOrders,
29
+ x as hyperliquid,
30
+ B as hyperliquidTestnet,
31
+ E as isExpired,
32
+ F as isStarknetAllowanceSufficient,
33
+ g as parseAction,
34
+ q as parseActionFromStatus,
35
+ G as resolveApiConfig,
36
+ I as solanaProgramAddress,
37
+ L as switchOrAddNetwork,
38
+ M as toXOnly,
39
+ b as validateBTCAddress
37
40
  };
@@ -18,7 +18,11 @@ export { SecretManager } from './lib/secretManager/secretManager';
18
18
  export type { ISecretManager, Secret, } from './lib/secretManager/secretManager.types';
19
19
  export { checkAllowanceAndApprove as checkStarknetAllowanceAndApprove, isAllowanceSufficient as isStarknetAllowanceSufficient, checkAllowance as checkStarknetAlloance, } from './lib/starknet/checkAllowanceAndApprove';
20
20
  export { Quote } from './lib/quote/quote';
21
- export type { IQuote, QuoteResponse, Strategies, } from './lib/quote/quote.types';
21
+ export type { IQuote, QuoteResponse, Strategies, QuoteParamsForAssets, QuoteParamsForOrderPair, QuoteOptions, BaseQuoteParams, } from './lib/quote/quote.types';
22
22
  export { constructOrderPair, validateBTCAddress, toXOnly, resolveApiConfig, } from './lib/utils';
23
23
  export { evmToViemChainMap, switchOrAddNetwork, hyperliquidTestnet, hyperliquid, botanixMainnet as botanix, } from './lib/switchOrAddNetwork';
24
+ export { BitcoinNetwork } from './lib/bitcoin/provider/provider.interface';
25
+ export { BitcoinProvider } from './lib/bitcoin/provider/provider';
26
+ export { BitcoinWallet } from './lib/bitcoin/wallet/wallet';
27
+ export type { IBitcoinProvider } from './lib/bitcoin/provider/provider.interface';
24
28
  export { API, STARKNET_CONFIG, SolanaRelayerAddress, solanaProgramAddress, } from './lib/constants';
@@ -0,0 +1,4 @@
1
+ export declare const verifyAPIs: (APIs: string[]) => string[];
2
+ export declare const getAPIs: (network: string) => string[];
3
+ export declare const RPC_URLS_TESTNET: string[];
4
+ export declare const RPC_URLS_MAINNET: string[];
@@ -0,0 +1,19 @@
1
+ import { Address } from 'viem';
2
+ import { OnChainIdentifier } from '../identifier';
3
+
4
+ export type AtomicSwapConfig = {
5
+ secretHash: string;
6
+ /**
7
+ * The number of blocks before the swap expires
8
+ */
9
+ expiryBlocks: number;
10
+ /**
11
+ * Amount in it's lowest denomination
12
+ */
13
+ amount: bigint;
14
+ recipientAddress: OnChainIdentifier;
15
+ refundAddress: OnChainIdentifier;
16
+ initiatorAddress: OnChainIdentifier;
17
+ contractAddress?: Address;
18
+ chain?: number;
19
+ };
@@ -0,0 +1,16 @@
1
+ export declare const BWErrors: {
2
+ INVALID_PK: string;
3
+ FEE_EXCEEDS_AMOUNT: (fee: number, amt: number) => string;
4
+ SWAP_NOT_FOUND: string;
5
+ SCRIPT_NOT_FUNDED: string;
6
+ SWAP_NOT_EXPIRED: (expiry: number) => string;
7
+ MIN_AMOUNT: (minAmt: number) => string;
8
+ INSUFFICIENT_FUNDS: (actual: number, expected: number) => string;
9
+ AmtPlusFeeExceedsBalance: (amt: number, fee: number, balance: number) => string;
10
+ };
11
+ export declare const BitcoinHTLCErrors: {
12
+ INVALID_SECRET_HASH: string;
13
+ INVALID_PUBKEY_OR_SECRET: string;
14
+ INVALID_PUBKEY: string;
15
+ ORDER_NOT_EXPIRED: string;
16
+ };
@@ -1,4 +1,5 @@
1
- import { IBitcoinWallet, IHTLCWallet } from '@catalogfi/wallets';
1
+ import { IHTLCWallet } from '../htlc.interface';
2
+ import { IBitcoinWallet } from './wallet/wallet.interface';
2
3
 
3
4
  export declare enum Leaf {
4
5
  REFUND = 0,
@@ -0,0 +1,7 @@
1
+ import { Network } from 'bitcoinjs-lib';
2
+ import { AtomicSwapConfig } from './ASConfig';
3
+
4
+ export declare const getHTLCScript: (swapConfig: AtomicSwapConfig, network: Network, legacy?: boolean) => {
5
+ script: Buffer<ArrayBufferLike>;
6
+ address: string;
7
+ };
@@ -0,0 +1,6 @@
1
+ export declare const AddressType: {
2
+ readonly p2pkh: "p2pkh";
3
+ readonly p2wpkh: "p2wpkh";
4
+ readonly 'p2wpkh-p2sh': "p2wpkh-p2sh";
5
+ };
6
+ export type AddressType = typeof AddressType[keyof typeof AddressType];
@@ -0,0 +1,7 @@
1
+ import { BitcoinNetwork } from './provider/provider.interface';
2
+
3
+ export declare const BitcoinPaths: {
4
+ bip44: (network: BitcoinNetwork, index?: number, account?: number) => string;
5
+ bip49: (network: BitcoinNetwork, index?: number, account?: number) => string;
6
+ bip84: (network: BitcoinNetwork, index?: number, account?: number) => string;
7
+ };
@@ -0,0 +1,118 @@
1
+ import { BitcoinNetwork, BitcoinTx, BitcoinTxType, BitcoinUTXO, FeeRates, IBitcoinProvider, Urgency } from './provider.interface';
2
+
3
+ export declare class BitcoinProvider implements IBitcoinProvider {
4
+ private readonly network;
5
+ private readonly APIs;
6
+ private cacheTimeout;
7
+ private readonly utxosCache;
8
+ constructor(network: BitcoinNetwork, API?: string);
9
+ /**
10
+ * Gets the output index of the UTXO
11
+ *
12
+ * @param {string} txId - Transaction ID
13
+ * @param {string} address - Address of the UTXO
14
+ *
15
+ * @returns {Promise<number>} Output index
16
+ *
17
+ * @throws If the UTXO is not found
18
+ */
19
+ getTxIndex(txId: string, address: string): Promise<number>;
20
+ /**
21
+ * Broadcasts the transaction. Retries upto 5 times.
22
+ *
23
+ * @param {string} tx - Hex representation of the transaction
24
+ * @returns {Promise<string>} Transaction ID
25
+ *
26
+ * @throws If the it fails to broadcast
27
+ */
28
+ broadcast(tx: string): Promise<string>;
29
+ /**
30
+ * Gets the balance of an address
31
+ *
32
+ * @param {string} address - Bitcoin address
33
+ * @returns {Promise<number>} The balance in satoshies
34
+ */
35
+ getBalance(address: string): Promise<number>;
36
+ /**
37
+ * Sets the timeout for the cache
38
+ *
39
+ * After the timeout, the cache will be invalidated and the next call will not use the cache
40
+ * @param timeout - Time in milliseconds
41
+ */
42
+ setTimeoutForCache(timeout: number): void;
43
+ /**
44
+ * Returns all UTXOs that can be unlocked by the given address. If the balance field is provided
45
+ * then the returned UTXOs are sorted in descending order.
46
+ *
47
+ * @param {string} address - Bitcoin address
48
+ * @param {number} [balance] - The upper cap for the summation of the returned UTXOs.
49
+ */
50
+ getUTXOs(address: string, balance?: number | undefined): Promise<BitcoinUTXO[]>;
51
+ /**
52
+ * Transaction Hex for the given transaction ID
53
+ *
54
+ * @param {string} txId - Transaction ID
55
+ * @returns {Promise<string>} Transaction Hex
56
+ */
57
+ getTransactionHex(txId: string): Promise<string>;
58
+ /**
59
+ * Transaction for the given transaction ID
60
+ *
61
+ * @param {string} txId - Transaction ID
62
+ * @returns {Promise<BitcoinTx>}
63
+ */
64
+ getTransaction(txId: string): Promise<BitcoinTx>;
65
+ /**
66
+ * Confirmations for the given transaction ID
67
+ *
68
+ * @param {string} txHash - Transaction ID
69
+ * @returns {Promise<number>} The number of confirmation
70
+ */
71
+ getConfirmations(txHash: string): Promise<number>;
72
+ /**
73
+ * Get fee rates
74
+ *
75
+ * @returns {Promise<FeeRates>}
76
+ */
77
+ getFeeRates(): Promise<FeeRates>;
78
+ /**
79
+ * Transactions for the given address and type. Limits to the latest 50 transactions.
80
+ *
81
+ * @param {string} address - Bitcoin address
82
+ * @param {BitcoinTxType} type - Transaction type
83
+ *
84
+ * @returns {Promise<BitcoinTx[]>}
85
+ */
86
+ getTransactions(address: string, type: BitcoinTxType): Promise<BitcoinTx[]>;
87
+ /**
88
+ * Returns the network of the provider
89
+ *
90
+ * @returns {BitcoinNetwork}
91
+ */
92
+ getNetwork(): BitcoinNetwork;
93
+ /**
94
+ * Returns the latest block height
95
+ *
96
+ * @returns {Promise<number>} Block height
97
+ */
98
+ getLatestTip(): Promise<number>;
99
+ /**
100
+ * Suggests fee for sending a transaction with a given amount. Must only be used for segwit inputs and outputs
101
+ *
102
+ *
103
+ * only for segwit inputs and outputs
104
+ * @param {string} account - Bitcoin address
105
+ * @param {number} amount - in satoshis
106
+ * @param {Urgency} urgency - urgency of the transaction
107
+ *
108
+ * @returns {Promise<number>} Recommended Fee
109
+ */
110
+ suggestFee(account: string, amount: number, urgency: Urgency): Promise<number>;
111
+ /**
112
+ * Returns the timestamps when a list of unconfirmed transactions was initially observed in the mempool.
113
+ * If a transaction is not found in the mempool or has been mined, the timestamp will be 0.
114
+ * @param txIds
115
+ * @returns List of time stamps in milliseconds
116
+ */
117
+ getTransactionTimes(txIds: string[]): Promise<number[]>;
118
+ }
@@ -0,0 +1,99 @@
1
+ type BaseUTXO = {
2
+ txid: string;
3
+ vout: number;
4
+ value: number;
5
+ };
6
+ export type BitcoinUTXO = ({
7
+ status: {
8
+ confirmed: true;
9
+ block_height: number;
10
+ };
11
+ } | {
12
+ status: {
13
+ confirmed: false;
14
+ };
15
+ }) & BaseUTXO;
16
+ /**
17
+ * Enum for fee rates
18
+ * @enum {string}
19
+ */
20
+ export declare enum Urgency {
21
+ SLOW = "SLOW",
22
+ MEDIUM = "MEDIUM",
23
+ FAST = "FAST"
24
+ }
25
+ /**
26
+ * Interface for Bitcoin provider
27
+ *
28
+ * Gives read only access to the mempool
29
+ */
30
+ export interface IBitcoinProvider {
31
+ broadcast(tx: string): Promise<string>;
32
+ getUTXOs(address: string, balance?: number): Promise<BitcoinUTXO[]>;
33
+ getBalance(address: string): Promise<number>;
34
+ getTransaction(txId: string): Promise<BitcoinTx>;
35
+ getTransactionHex(txId: string): Promise<string>;
36
+ getFeeRates(): Promise<FeeRates>;
37
+ getTransactions(address: string, type: BitcoinTxType): Promise<BitcoinTx[]>;
38
+ getNetwork(): BitcoinNetwork;
39
+ getLatestTip(): Promise<number>;
40
+ getConfirmations(txHash: string): Promise<number>;
41
+ getTxIndex(txId: string, address: string): Promise<number>;
42
+ getTransactionTimes(txIds: string[]): Promise<number[]>;
43
+ suggestFee(account: string, amount: number, urgency: Urgency): Promise<number>;
44
+ }
45
+ export type BitcoinTx = {
46
+ txid: string;
47
+ fee: number;
48
+ vin: {
49
+ txid: string;
50
+ vout: number;
51
+ scriptsig?: string;
52
+ scriptsig_asm?: string;
53
+ is_coinbase: boolean;
54
+ witness?: string[];
55
+ sequence: number;
56
+ prevout: {
57
+ scriptpubkey: string;
58
+ scriptpubkey_asm: string;
59
+ scriptpubkey_type: string;
60
+ scriptpubkey_address: string;
61
+ value: number;
62
+ };
63
+ }[];
64
+ vout: {
65
+ scriptpubkey: string;
66
+ scriptpubkey_asm: string;
67
+ scriptpubkey_type: string;
68
+ scriptpubkey_address: string;
69
+ value: number;
70
+ }[];
71
+ status: {
72
+ confirmed: boolean;
73
+ block_height?: number;
74
+ block_hash?: string;
75
+ block_time?: number;
76
+ };
77
+ };
78
+ export type FeeRates = {
79
+ fastestFee: number;
80
+ halfHourFee: number;
81
+ hourFee: number;
82
+ economyFee: number;
83
+ minimumFee: number;
84
+ };
85
+ export declare enum BitcoinNetwork {
86
+ Mainnet = "Mainnet",
87
+ Testnet = "Testnet",
88
+ Regtest = "Regtest"
89
+ }
90
+ export declare enum BitcoinTxType {
91
+ ALL = "ALL",
92
+ IN = "IN",
93
+ OUT = "OUT"
94
+ }
95
+ export type FeeRateKeys = keyof FeeRates;
96
+ export declare const UrgencyToFeeRateKey: {
97
+ [urgency in Urgency]: FeeRateKeys;
98
+ };
99
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare const ScriptType: {
2
+ readonly P2SH: "p2sh";
3
+ readonly P2WSH: "p2wsh";
4
+ readonly P2TR: "p2tr";
5
+ };
6
+ export type ScriptType = typeof ScriptType[keyof typeof ScriptType];
@@ -0,0 +1,20 @@
1
+ export type SigHashType = number;
2
+ type SignatureType = 'segwitV0' | 'segwitV1' | 'p2shSignature';
3
+ export declare const SigHashType: {
4
+ readonly ALL: 1;
5
+ readonly NONE: 2;
6
+ readonly SINGLE: 3;
7
+ readonly ALL_ANYONECANPAY: number;
8
+ readonly NONE_ANYONECANPAY: number;
9
+ readonly SINGLE_ANYONECANPAY: number;
10
+ };
11
+ export declare class AddSignature {
12
+ _scriptType: SignatureType;
13
+ _sigHashType: SigHashType;
14
+ constructor(type: SignatureType, sigHashType: SigHashType);
15
+ get scriptType(): SignatureType;
16
+ get sigHashType(): number;
17
+ toString(): string;
18
+ static fromString(str: string): Promise<AddSignature>;
19
+ }
20
+ export {};
@@ -0,0 +1,8 @@
1
+ import { networks } from 'bitcoinjs-lib';
2
+ import { BitcoinNetwork } from './provider/provider.interface';
3
+
4
+ export declare function getBitcoinNetwork(network: BitcoinNetwork): networks.Network;
5
+ export declare function mnemonicToPrivateKey(mnemonic: string, network: BitcoinNetwork, opts?: {
6
+ index?: number;
7
+ path?: string;
8
+ }): string;
@@ -0,0 +1,145 @@
1
+ import { Network, payments, Transaction } from 'bitcoinjs-lib';
2
+ import { BitcoinUTXO, IBitcoinProvider, Urgency } from '../provider/provider.interface';
3
+ import { AddSignature, SigHashType } from '../sig';
4
+ import { AtomicSwapConfig } from '../ASConfig';
5
+ import { IHTLCWallet } from '../../htlc.interface';
6
+ import { ScriptType } from '../script';
7
+ import { BitcoinWalletConfig, IBitcoinWallet } from './wallet.interface';
8
+ import { WalletChain } from './baseWallet';
9
+
10
+ export declare abstract class AbstractBitcoinWallet implements IBitcoinWallet {
11
+ abstract getAddress(): Promise<string>;
12
+ abstract getBalance(): Promise<number>;
13
+ abstract sign(hexString: string): Promise<string>;
14
+ abstract getPublicKey(): Promise<string>;
15
+ abstract getNetwork(): Promise<Network>;
16
+ abstract getProvider(): Promise<IBitcoinProvider>;
17
+ abstract send(toAddress: string, amt: number, fee?: number): Promise<string>;
18
+ abstract spend(script: Buffer, scriptAddress: string, { toAddress, fee, nSequence, unlockScript, // only for p2sh
19
+ witness, }: {
20
+ toAddress?: string;
21
+ fee?: number;
22
+ nSequence?: number;
23
+ witness?: (Buffer | AddSignature)[];
24
+ unlockScript?: (payments.StackElement | AddSignature)[];
25
+ }): Promise<string>;
26
+ abstract walletConfig(): BitcoinWalletConfig;
27
+ abstract signSchnorr(buf: Buffer): Promise<Buffer>;
28
+ addSignatureSegwitV0(type?: SigHashType): AddSignature;
29
+ addSignatureP2sh(type?: SigHashType): AddSignature;
30
+ addSignatureSegwitV1(type?: SigHashType): AddSignature;
31
+ /**
32
+ * Returns the chain of the wallet. It can be Bitcoin or EVM
33
+ */
34
+ chain(): WalletChain;
35
+ /**
36
+ * Add all inputs to a transaction
37
+ * @param {Transaction} tx
38
+ * @param {string} address - The address whose UTXOs you want to include
39
+ * @param {IBitcoinProvider} provider
40
+ * @param {Object} opts - Optional
41
+ * @param {BitcoinUTXO[]} opts.utxos - List of UTXOs to include in the transaction. Optional. If not provide then the UTXOs belong to the specified address will be used
42
+ * @param {number} opts.nSequence - The sequence number. Optional
43
+ *
44
+ */
45
+ addAllInputs(tx: Transaction, address: string, provider: IBitcoinProvider, opts?: {
46
+ utxos?: BitcoinUTXO[];
47
+ nSequence?: number;
48
+ }): Promise<Transaction>;
49
+ /**
50
+ * Fee suggested by the provided
51
+ *
52
+ * @override
53
+ * @param {number} amount - in satoshis
54
+ * @param {Urgency} urgency - urgency of the fee
55
+ * @returns {Promise<number>}
56
+ *
57
+ */
58
+ suggestFee(amount: number, urgency: Urgency): Promise<number>;
59
+ /**
60
+ * Converts an address to its corresponding output script.
61
+ *
62
+ * @param {string} address - The address to convert.
63
+ * @return {Promise<Buffer>} The output script corresponding to the address.
64
+ *
65
+ */
66
+ toOutputScript(address: string): Promise<Buffer>;
67
+ /**
68
+ * Calculates the total value (balance) from an array of Bitcoin UTXOs.
69
+ *
70
+ * @param {BitcoinUTXO[]} utxos - The array of Bitcoin UTXOs.
71
+ * @return {number} The total value of the UTXOs.
72
+ *
73
+ */
74
+ totalValueFromUTXOs(utxos: BitcoinUTXO[]): number;
75
+ /**
76
+ * Converts a script to an p2wsh address.
77
+ *
78
+ * @param {Buffer} script - The script to convert.
79
+ * @return {Promise<string>} The generated address.
80
+ *
81
+ */
82
+ scriptToAddress(script: Buffer): Promise<string>;
83
+ /**
84
+ * Creates an HTLC wallet.
85
+ *
86
+ * @param {AtomicSwapConfig} swapConfig - The swap configuration for the HTLC wallet.
87
+ * @returns {Promise<IHTLCWallet>}
88
+ *
89
+ */
90
+ newSwap(swapConfig: AtomicSwapConfig): Promise<IHTLCWallet>;
91
+ /**
92
+ * Given a script address and network, returns the type of the script.
93
+ *
94
+ * @returns {ScriptType} The type of the script (P2SH, P2WSH, P2TR)
95
+ */
96
+ getScriptType(scriptAddress: string, network: Network): ScriptType;
97
+ }
98
+ type AtomicSwap = AtomicSwapConfig & {
99
+ redeemScript: Buffer;
100
+ scriptAddress: string;
101
+ };
102
+ export declare class BitcoinHTLC implements IHTLCWallet {
103
+ private readonly wallet;
104
+ private readonly swap;
105
+ /**
106
+ * @constructor
107
+ * @param {IBitcoinWallet} wallet
108
+ * @param {AtomicSwap} swap - Atomic swap config
109
+ *
110
+ */
111
+ constructor(wallet: IBitcoinWallet, swap: AtomicSwap);
112
+ /**
113
+ * Returns the script address
114
+ *
115
+ * @returns {string}
116
+ *
117
+ */
118
+ id(): string;
119
+ /**
120
+ * Initiate the HTLC by sending bitcoin to the HTLC script
121
+ *
122
+ * @returns {Promise<string>} Transaction ID
123
+ *
124
+ */
125
+ init(): Promise<string>;
126
+ /**
127
+ * Redeems the HTLC by spending all bitcoin from the given script.
128
+ *
129
+ * @param {string} secret - The secret for the atomic swap
130
+ * @param {string} [receiver] - The address of the receiver. If not provided then the wallet address is used as the receiver.
131
+ *
132
+ * @returns {Promise<string>} Transaction ID
133
+ *
134
+ */
135
+ redeem(secret: string, receiver?: string): Promise<string>;
136
+ /**
137
+ * Refunds the HTLC by spending all bitcoin from the given script.
138
+ *
139
+ * @param {string} [receiver] - The address of the receiver. If not provided then the wallet address is used as the receiver.
140
+ * @returns {Promise<string>} Transaction ID
141
+ *
142
+ */
143
+ refund(receiver?: string): Promise<string>;
144
+ }
145
+ export {};
@@ -0,0 +1,13 @@
1
+ import { IHTLCWallet } from '../../htlc.interface';
2
+ import { AtomicSwapConfig } from '../ASConfig';
3
+
4
+ export declare enum WalletChain {
5
+ Bitcoin = 0,
6
+ EVM = 1
7
+ }
8
+ export interface IBaseWallet {
9
+ chain(): WalletChain;
10
+ getAddress(): Promise<string>;
11
+ sign(hexMsg: string): Promise<string>;
12
+ newSwap(swapConfig: AtomicSwapConfig): Promise<IHTLCWallet>;
13
+ }