@iota-big3/sdk-blockchain
Version:
Comprehensive blockchain integration platform with multi-chain support, smart contracts, DeFi protocols, NFT infrastructure, Bitcoin support, and seamless SDK ecosystem integration for IOTA Big3
184 lines • 5.04 kB
TypeScript
/**
* Bitcoin-specific type definitions
* Following Phase 2g incremental implementation
*/
import type { IBlockchainManager } from '../types';
export interface BitcoinNetwork {
name: 'mainnet' | 'testnet' | 'regtest';
bech32: string;
pubKeyHash: number;
scriptHash: number;
wif: number;
}
export interface BitcoinConfig {
enabled: boolean;
network: 'mainnet' | 'testnet' | 'regtest';
rpcUrl?: string;
rpcAuth?: {
username: string;
password: string;
};
electrumServers?: string[];
lightning?: LightningConfig;
}
export interface LightningConfig {
enabled: boolean;
implementation: 'lnd' | 'c-lightning' | 'eclair';
host: string;
macaroon?: string;
cert?: string;
}
export interface UTXO {
txid: string;
vout: number;
value: number;
scriptPubKey: string;
address?: string;
confirmations: number;
}
export interface TransactionInput {
txid: string;
vout: number;
sequence?: number;
scriptSig?: string;
witness?: string[];
}
export interface TransactionOutput {
address?: string;
script?: string;
value: number;
}
export interface BitcoinTransaction {
inputs: TransactionInput[];
outputs: TransactionOutput[];
version: number;
locktime: number;
fee?: number;
size: number;
vsize: number;
weight: number;
}
export type AddressType = 'p2pkh' | 'p2sh' | 'p2wpkh' | 'p2wsh' | 'p2tr';
export interface MultisigAddress {
address: string;
redeemScript: Buffer;
m: number;
n: number;
pubkeys: string[];
}
export interface PSBTOptions {
inputs: Array<{
txid: string;
vout: number;
value: number;
scriptPubKey?: string;
redeemScript?: Buffer;
witnessScript?: Buffer;
}>;
outputs: Array<{
address?: string;
script?: string;
value: number;
}>;
locktime?: number;
version?: number;
}
export interface PSBT {
data: {
inputs: any[];
outputs: any[];
};
toBase64(): string;
toHex(): string;
sign(keyPair: any): void;
finalizeAllInputs(): void;
extractTransaction(): any;
}
export interface LightningInvoice {
paymentRequest: string;
paymentHash: string;
amount: number;
description: string;
expiry: number;
timestamp: number;
}
export interface LightningChannel {
channelId: string;
nodeId: string;
capacity: number;
localBalance: number;
remoteBalance: number;
active: boolean;
}
export interface SendTransactionParams {
to: string;
amount: number;
feeRate?: number;
utxos?: UTXO[];
rbf?: boolean;
data?: Buffer;
}
export interface FeeEstimate {
fastestFee: number;
halfHourFee: number;
hourFee: number;
economyFee: number;
}
export interface BitcoinBlock {
hash: string;
height: number;
time: number;
nTx: number;
size: number;
weight: number;
merkleRoot: string;
previousBlockHash: string;
}
export interface IBitcoinManager extends IBlockchainManager {
generateAddress(type: AddressType): Promise<string>;
validateAddress(address: string): Promise<boolean>;
getUTXOs(address: string): Promise<UTXO[]>;
selectUTXOs(utxos: UTXO[], amount: number): Promise<UTXO[]>;
sendTransaction(params: SendTransactionParams): Promise<string>;
createPSBT(options: PSBTOptions): Promise<PSBT>;
signPSBT(psbt: PSBT, privateKey: string): Promise<PSBT>;
broadcastTransaction(hex: string): Promise<string>;
estimateFee(params: SendTransactionParams): Promise<number>;
getFeeRates(): Promise<FeeEstimate>;
getBalance(address: string): Promise<number>;
batchGetBalances(addresses: string[]): Promise<number[]>;
createMultisig(params: {
pubkeys: string[];
m: number;
network?: string;
}): Promise<MultisigAddress>;
createMultisigPSBT(params: {
multisig: MultisigAddress;
inputs: TransactionInput[];
outputs: TransactionOutput[];
}): Promise<PSBT>;
getNetwork(): string;
getBlockHeight(): Promise<number>;
getBlock(hashOrHeight: string | number): Promise<BitcoinBlock>;
lightning?: {
createInvoice(params: {
amount: number;
description: string;
expiry?: number;
}): Promise<LightningInvoice>;
decodeInvoice(paymentRequest: string): Promise<LightningInvoice>;
payInvoice(paymentRequest: string): Promise<{
paymentHash: string;
}>;
listChannels(): Promise<LightningChannel[]>;
};
}
export type BitcoinEventType = 'transaction:sent' | 'transaction:confirmed' | 'block:new' | 'utxo:spent' | 'utxo:received' | 'lightning:invoice:created' | 'lightning:invoice:paid' | 'lightning:channel:opened' | 'lightning:channel:closed';
export interface BitcoinEvent {
type: BitcoinEventType;
data: unknown;
timestamp: Date;
txid?: string;
blockHeight?: number;
}
//# sourceMappingURL=types.d.ts.map