@xchainjs/xchain-utxo 2.0.10 → 2.2.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.
@@ -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,6 @@
1
+ export * from './types';
2
+ export * from './branch-and-bound';
3
+ export * from './single-random-draw';
4
+ export * from './accumulative';
5
+ export * from './largest-first';
6
+ export * from './small-first';
@@ -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.10",
3
+ "version": "2.2.0",
4
4
  "description": "Genereic UTXO client for XChainJS",
5
5
  "keywords": [
6
6
  "XChain",