@xchainjs/xchain-utxo 2.0.9 → 2.1.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.
- package/lib/client.d.ts +107 -7
- package/lib/constants.d.ts +43 -0
- package/lib/errors.d.ts +91 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.esm.js +1205 -4
- package/lib/index.js +1216 -3
- package/lib/strategies/accumulative.d.ts +17 -0
- package/lib/strategies/branch-and-bound.d.ts +21 -0
- package/lib/strategies/index.d.ts +6 -0
- package/lib/strategies/largest-first.d.ts +9 -0
- package/lib/strategies/single-random-draw.d.ts +17 -0
- package/lib/strategies/small-first.d.ts +17 -0
- package/lib/strategies/types.d.ts +28 -0
- package/lib/utxo-selector.d.ts +37 -0
- package/lib/validators.d.ts +38 -0
- package/package.json +3 -3
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { UTXO } from '../types';
|
|
2
|
+
import { UtxoSelectionStrategy, UtxoSelectionResult } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Accumulative strategy - simple and reliable fallback
|
|
5
|
+
*/
|
|
6
|
+
export declare class AccumulativeStrategy implements UtxoSelectionStrategy {
|
|
7
|
+
name: string;
|
|
8
|
+
private static readonly DUST_THRESHOLD;
|
|
9
|
+
private static readonly BYTES_PER_INPUT;
|
|
10
|
+
private static readonly BYTES_PER_OUTPUT;
|
|
11
|
+
private static readonly BASE_TX_SIZE;
|
|
12
|
+
select(utxos: UTXO[], targetValue: number, feeRate: number, extraOutputs?: number): UtxoSelectionResult | null;
|
|
13
|
+
/**
|
|
14
|
+
* Calculate estimated transaction fee
|
|
15
|
+
*/
|
|
16
|
+
private calculateFee;
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { UTXO } from '../types';
|
|
2
|
+
import { UtxoSelectionStrategy, UtxoSelectionResult } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Branch and Bound strategy - optimal for minimizing fees and change
|
|
5
|
+
*/
|
|
6
|
+
export declare class BranchAndBoundStrategy implements UtxoSelectionStrategy {
|
|
7
|
+
name: string;
|
|
8
|
+
private static readonly MAX_TRIES;
|
|
9
|
+
private static readonly DUST_THRESHOLD;
|
|
10
|
+
private static readonly BYTES_PER_INPUT;
|
|
11
|
+
private static readonly BYTES_PER_OUTPUT;
|
|
12
|
+
private static readonly BASE_TX_SIZE;
|
|
13
|
+
select(utxos: UTXO[], targetValue: number, feeRate: number, extraOutputs?: number): UtxoSelectionResult | null;
|
|
14
|
+
private findExactMatch;
|
|
15
|
+
private branchAndBound;
|
|
16
|
+
private calculateEfficiency;
|
|
17
|
+
/**
|
|
18
|
+
* Calculate estimated transaction fee
|
|
19
|
+
*/
|
|
20
|
+
private calculateFee;
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { UTXO } from '../types';
|
|
2
|
+
import { UtxoSelectionStrategy, UtxoSelectionResult } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Largest First strategy - good for consolidation
|
|
5
|
+
*/
|
|
6
|
+
export declare class LargestFirstStrategy implements UtxoSelectionStrategy {
|
|
7
|
+
name: string;
|
|
8
|
+
select(utxos: UTXO[], targetValue: number, feeRate: number, extraOutputs?: number): UtxoSelectionResult | null;
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { UTXO } from '../types';
|
|
2
|
+
import { UtxoSelectionStrategy, UtxoSelectionResult } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Single Random Draw strategy - good for privacy
|
|
5
|
+
*/
|
|
6
|
+
export declare class SingleRandomDrawStrategy implements UtxoSelectionStrategy {
|
|
7
|
+
name: string;
|
|
8
|
+
private static readonly DUST_THRESHOLD;
|
|
9
|
+
private static readonly BYTES_PER_INPUT;
|
|
10
|
+
private static readonly BYTES_PER_OUTPUT;
|
|
11
|
+
private static readonly BASE_TX_SIZE;
|
|
12
|
+
select(utxos: UTXO[], targetValue: number, feeRate: number, extraOutputs?: number): UtxoSelectionResult | null;
|
|
13
|
+
/**
|
|
14
|
+
* Calculate estimated transaction fee
|
|
15
|
+
*/
|
|
16
|
+
private calculateFee;
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { UTXO } from '../types';
|
|
2
|
+
import { UtxoSelectionStrategy, UtxoSelectionResult } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Small First strategy - good for consolidating many small UTXOs
|
|
5
|
+
*/
|
|
6
|
+
export declare class SmallFirstStrategy implements UtxoSelectionStrategy {
|
|
7
|
+
name: string;
|
|
8
|
+
private static readonly DUST_THRESHOLD;
|
|
9
|
+
private static readonly BYTES_PER_INPUT;
|
|
10
|
+
private static readonly BYTES_PER_OUTPUT;
|
|
11
|
+
private static readonly BASE_TX_SIZE;
|
|
12
|
+
select(utxos: UTXO[], targetValue: number, feeRate: number, extraOutputs?: number): UtxoSelectionResult | null;
|
|
13
|
+
/**
|
|
14
|
+
* Calculate estimated transaction fee
|
|
15
|
+
*/
|
|
16
|
+
private calculateFee;
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { UTXO } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for UTXO selection strategies
|
|
4
|
+
*/
|
|
5
|
+
export interface UtxoSelectionStrategy {
|
|
6
|
+
name: string;
|
|
7
|
+
select(utxos: UTXO[], targetValue: number, feeRate: number, extraOutputs?: number): UtxoSelectionResult | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Result of UTXO selection
|
|
11
|
+
*/
|
|
12
|
+
export interface UtxoSelectionResult {
|
|
13
|
+
inputs: UTXO[];
|
|
14
|
+
changeAmount: number;
|
|
15
|
+
fee: number;
|
|
16
|
+
efficiency: number;
|
|
17
|
+
strategy: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* UTXO selection preferences
|
|
21
|
+
*/
|
|
22
|
+
export interface UtxoSelectionPreferences {
|
|
23
|
+
minimizeFee?: boolean;
|
|
24
|
+
minimizeInputs?: boolean;
|
|
25
|
+
minimizeChange?: boolean;
|
|
26
|
+
avoidDust?: boolean;
|
|
27
|
+
consolidateSmallUtxos?: boolean;
|
|
28
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { UTXO } from './types';
|
|
2
|
+
import { UtxoSelectionResult, UtxoSelectionPreferences } from './strategies';
|
|
3
|
+
/**
|
|
4
|
+
* Enhanced UTXO selector with multiple strategies
|
|
5
|
+
*/
|
|
6
|
+
export declare class UtxoSelector {
|
|
7
|
+
private strategies;
|
|
8
|
+
constructor();
|
|
9
|
+
static readonly DUST_THRESHOLD = 546;
|
|
10
|
+
static readonly BYTES_PER_INPUT: 68;
|
|
11
|
+
static readonly BYTES_PER_OUTPUT: 31;
|
|
12
|
+
static readonly BASE_TX_SIZE: 10;
|
|
13
|
+
/**
|
|
14
|
+
* Select optimal UTXOs for a transaction
|
|
15
|
+
*/
|
|
16
|
+
selectOptimal(utxos: UTXO[], targetValue: number, feeRate: number, preferences?: UtxoSelectionPreferences, extraOutputs?: number): UtxoSelectionResult;
|
|
17
|
+
/**
|
|
18
|
+
* Select the best result based on preferences
|
|
19
|
+
*/
|
|
20
|
+
private selectBestResult;
|
|
21
|
+
/**
|
|
22
|
+
* Calculate a score for a result based on preferences
|
|
23
|
+
*/
|
|
24
|
+
private calculateScore;
|
|
25
|
+
/**
|
|
26
|
+
* Validate inputs for UTXO selection
|
|
27
|
+
*/
|
|
28
|
+
private validateInputs;
|
|
29
|
+
/**
|
|
30
|
+
* Validate that a result is correct
|
|
31
|
+
*/
|
|
32
|
+
private isValidResult;
|
|
33
|
+
/**
|
|
34
|
+
* Calculate estimated transaction fee
|
|
35
|
+
*/
|
|
36
|
+
static calculateFee(inputCount: number, outputCount: number, feeRate: number): number;
|
|
37
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Address } from '@xchainjs/xchain-util';
|
|
2
|
+
import { FeeBounds } from '@xchainjs/xchain-client';
|
|
3
|
+
import { TxParams, UTXO } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Comprehensive input validation for UTXO transactions
|
|
6
|
+
*/
|
|
7
|
+
export declare class UtxoTransactionValidator {
|
|
8
|
+
/**
|
|
9
|
+
* Validate transaction parameters
|
|
10
|
+
*/
|
|
11
|
+
static validateTransferParams(params: TxParams & {
|
|
12
|
+
sender?: Address;
|
|
13
|
+
feeRate?: number;
|
|
14
|
+
}, feeBounds?: FeeBounds): void;
|
|
15
|
+
/**
|
|
16
|
+
* Validate UTXO set for consistency and correctness
|
|
17
|
+
*/
|
|
18
|
+
static validateUtxoSet(utxos: UTXO[]): void;
|
|
19
|
+
/**
|
|
20
|
+
* Basic address validation - checks for null/empty and basic format
|
|
21
|
+
* NOTE: Chain-specific validation should be done by the respective client packages
|
|
22
|
+
*/
|
|
23
|
+
static validateAddressBasic(address: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Validate fee rate against network conditions
|
|
26
|
+
*/
|
|
27
|
+
static validateFeeRate(feeRate: number, networkConditions?: {
|
|
28
|
+
minFeeRate?: number;
|
|
29
|
+
maxFeeRate?: number;
|
|
30
|
+
recommendedRange?: [number, number];
|
|
31
|
+
}): void;
|
|
32
|
+
/**
|
|
33
|
+
* Validate transaction size limits
|
|
34
|
+
*/
|
|
35
|
+
static validateTransactionSize(estimatedSize: number, maxSize?: number): void;
|
|
36
|
+
private static containsControlCharacters;
|
|
37
|
+
private static sanitizeParamsForLogging;
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-utxo",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Genereic UTXO client for XChainJS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"XChain",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"directory": "release/package"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@xchainjs/xchain-client": "2.0.
|
|
38
|
+
"@xchainjs/xchain-client": "2.0.10",
|
|
39
39
|
"@xchainjs/xchain-util": "2.0.5",
|
|
40
|
-
"@xchainjs/xchain-utxo-providers": "2.0.
|
|
40
|
+
"@xchainjs/xchain-utxo-providers": "2.0.10"
|
|
41
41
|
}
|
|
42
42
|
}
|