@arklabs/wallet-sdk
Version:
Bitcoin wallet SDK with Taproot and Ark integration
117 lines (116 loc) • 3 kB
TypeScript
import { Output, SettlementEvent } from "../providers/ark";
import { Identity } from "../identity";
import { NetworkName } from "../networks";
import { RelativeTimelock } from "../script/tapscript";
import { EncodedVtxoScript, TapLeafScript } from "../script/base";
export interface WalletConfig {
network: NetworkName;
identity: Identity;
esploraUrl?: string;
arkServerUrl?: string;
arkServerPublicKey?: string;
boardingTimelock?: RelativeTimelock;
}
export interface WalletBalance {
onchain: {
confirmed: number;
unconfirmed: number;
total: number;
};
offchain: {
swept: number;
settled: number;
pending: number;
total: number;
};
total: number;
}
export interface SendBitcoinParams {
address: string;
amount: number;
feeRate?: number;
memo?: string;
}
export interface Recipient {
address: string;
amount: number;
}
export interface SettleParams {
inputs: (string | ({
tapLeafScript: TapLeafScript;
} & Outpoint & EncodedVtxoScript))[];
outputs: Output[];
}
export interface VtxoTaprootAddress {
address: string;
scripts: {
exit: string[];
forfeit: string[];
};
}
export interface AddressInfo {
onchain: string;
offchain?: VtxoTaprootAddress;
boarding?: VtxoTaprootAddress;
bip21: string;
}
export interface TapscriptInfo {
offchain?: string[];
boarding?: string[];
}
export interface Status {
confirmed: boolean;
block_height?: number;
block_hash?: string;
block_time?: number;
}
export interface VirtualStatus {
state: "pending" | "settled" | "swept" | "spent";
batchTxID?: string;
batchExpiry?: number;
}
export interface Outpoint {
txid: string;
vout: number;
}
export interface Coin extends Outpoint {
value: number;
status: Status;
}
export interface VirtualCoin extends Coin {
virtualStatus: VirtualStatus;
spentBy?: string;
createdAt: Date;
}
export declare enum TxType {
TxSent = "SENT",
TxReceived = "RECEIVED"
}
export interface TxKey {
boardingTxid: string;
roundTxid: string;
redeemTxid: string;
}
export interface ArkTransaction {
key: TxKey;
type: TxType;
amount: number;
settled: boolean;
createdAt: number;
}
export type ExtendedCoin = {
tapLeafScript: TapLeafScript;
} & EncodedVtxoScript & Coin;
export type ExtendedVirtualCoin = {
tapLeafScript: TapLeafScript;
} & EncodedVtxoScript & VirtualCoin;
export interface IWallet {
getAddress(): Promise<AddressInfo>;
getBalance(): Promise<WalletBalance>;
getCoins(): Promise<Coin[]>;
getVtxos(): Promise<ExtendedVirtualCoin[]>;
getBoardingUtxos(): Promise<ExtendedCoin[]>;
getTransactionHistory(): Promise<ArkTransaction[]>;
sendBitcoin(params: SendBitcoinParams, zeroFee?: boolean): Promise<string>;
settle(params?: SettleParams, eventCallback?: (event: SettlementEvent) => void): Promise<string>;
}