bitcoinjs-lib/types/psbt.d.ts
2019-07-19 10:12:20 +09:00

83 lines
4.6 KiB
TypeScript

/// <reference types="node" />
import { Psbt as PsbtBase } from 'bip174';
import { KeyValue, PsbtGlobalUpdate, PsbtInputUpdate, PsbtOutputUpdate, TransactionInput, TransactionOutput } from 'bip174/src/lib/interfaces';
import { Signer, SignerAsync } from './ecpair';
import { Network } from './networks';
import { Transaction } from './transaction';
/**
* Psbt class can parse and generate a PSBT binary based off of the BIP174.
* There are 6 roles that this class fulfills. (Explained in BIP174)
*
* Creator: This can be done with `new Psbt()`
* Updater: This can be done with `psbt.addInput(input)`, `psbt.addInputs(inputs)`,
* `psbt.addOutput(output)`, `psbt.addOutputs(outputs)` when you are looking to
* add new inputs and outputs to the PSBT, and `psbt.updateGlobal(itemObject)`,
* `psbt.updateInput(itemObject)`, `psbt.updateOutput(itemObject)`
* addInput requires hash: Buffer | string; and index: number; as attributes
* and can also include any attributes that are used in updateInput method.
* addOutput requires script: Buffer; and value: number; and likewise can include
* data for updateOutput.
* For a list of what attributes should be what types. Check the bip174 library.
* Also, check the integration tests for some examples of usage.
* Signer: There are a few methods. sign and signAsync, which will search all input
* information for your pubkey or pubkeyhash, and only sign inputs where it finds
* your info. Or you can explicitly sign a specific input with signInput and
* signInputAsync. For the async methods you can create a SignerAsync object
* and use something like a hardware wallet to sign with. (You must implement this)
* Combiner: psbts can be combined easily with `psbt.combine(psbt2, psbt3, psbt4 ...)`
* the psbt calling combine will always have precedence when a conflict occurs.
* Combine checks if the internal bitcoin transaction is the same, so be sure that
* all sequences, version, locktime, etc. are the same before combining.
* Input Finalizer: This role is fairly important. Not only does it need to construct
* the input scriptSigs and witnesses, but it SHOULD verify the signatures etc.
* Before running `psbt.finalizeAllInputs()` please run `psbt.validateAllSignatures()`
* Running any finalize method will delete any data in the input(s) that are no longer
* needed due to the finalized scripts containing the information.
* Transaction Extractor: This role will perform some checks before returning a
* Transaction object. Such as fee rate not being larger than maximumFeeRate etc.
*/
export declare class Psbt {
readonly data: PsbtBase;
static fromBase64(data: string, opts?: PsbtOptsOptional): Psbt;
static fromHex(data: string, opts?: PsbtOptsOptional): Psbt;
static fromBuffer(buffer: Buffer, opts?: PsbtOptsOptional): Psbt;
private __CACHE;
private opts;
constructor(opts?: PsbtOptsOptional, data?: PsbtBase);
readonly inputCount: number;
combine(...those: Psbt[]): this;
clone(): Psbt;
setMaximumFeeRate(satoshiPerByte: number): void;
setVersion(version: number): this;
setLocktime(locktime: number): this;
setSequence(inputIndex: number, sequence: number): this;
addInputs(inputDatas: TransactionInput[]): this;
addInput(inputData: TransactionInput): this;
addOutputs(outputDatas: TransactionOutput[]): this;
addOutput(outputData: TransactionOutput): this;
extractTransaction(disableFeeCheck?: boolean): Transaction;
getFeeRate(): number;
finalizeAllInputs(): this;
finalizeInput(inputIndex: number): this;
validateAllSignatures(): boolean;
validateSignatures(inputIndex: number, pubkey?: Buffer): boolean;
sign(keyPair: Signer, sighashTypes?: number[]): this;
signAsync(keyPair: Signer | SignerAsync, sighashTypes?: number[]): Promise<void>;
signInput(inputIndex: number, keyPair: Signer, sighashTypes?: number[]): this;
signInputAsync(inputIndex: number, keyPair: Signer | SignerAsync, sighashTypes?: number[]): Promise<void>;
toBuffer(): Buffer;
toHex(): string;
toBase64(): string;
updateGlobal(updateData: PsbtGlobalUpdate): this;
updateInput(inputIndex: number, updateData: PsbtInputUpdate): this;
updateOutput(outputIndex: number, updateData: PsbtOutputUpdate): this;
addUnknownKeyValToGlobal(keyVal: KeyValue): this;
addUnknownKeyValToInput(inputIndex: number, keyVal: KeyValue): this;
addUnknownKeyValToOutput(outputIndex: number, keyVal: KeyValue): this;
clearFinalizedInput(inputIndex: number): this;
}
interface PsbtOptsOptional {
network?: Network;
maximumFeeRate?: number;
}
export {};