Skip to main content

Psbt

reddcoinjs-lib v7.0.1-rdd.1Docs


reddcoinjs-lib v7.0.1-rdd.1 / Psbt

Class: Psbt

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. signAllInputs and signAllInputsAsync, 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.validateSignaturesOfAllInputs() 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.

Constructors

new Psbt()

new Psbt(opts, data): Psbt

Parameters

opts: PsbtOptsOptional = {}

data: Psbt = ...

Returns

Psbt

Defined in

ts_src/psbt.ts:152

Properties

data

readonly data: Psbt

Defined in

ts_src/psbt.ts:154

Accessors

inputCount

Get Signature

get inputCount(): number

Returns

number

Defined in

ts_src/psbt.ts:190


locktime

Get Signature

get locktime(): number

Returns

number

Set Signature

set locktime(locktime): void

Parameters

locktime: number

Returns

void

Defined in

ts_src/psbt.ts:202


nTime

Get Signature

get nTime(): number

Returns

number

Set Signature

set nTime(nTime): void

Parameters

nTime: number

Returns

void

Defined in

ts_src/psbt.ts:210


txInputs

Get Signature

get txInputs(): PsbtTxInput[]

Returns

PsbtTxInput[]

Defined in

ts_src/psbt.ts:218


txOutputs

Get Signature

get txOutputs(): PsbtTxOutput[]

Returns

PsbtTxOutput[]

Defined in

ts_src/psbt.ts:226


version

Get Signature

get version(): number

Returns

number

Set Signature

set version(version): void

Parameters

version: number

Returns

void

Defined in

ts_src/psbt.ts:194

Methods

addInput()

addInput(inputData): this

Parameters

inputData: PsbtInputExtended

Returns

this

Defined in

ts_src/psbt.ts:301


addInputs()

addInputs(inputDatas): this

Parameters

inputDatas: PsbtInputExtended[]

Returns

this

Defined in

ts_src/psbt.ts:296


addOutput()

addOutput(outputData): this

Parameters

outputData: PsbtOutputExtended

Returns

this

Defined in

ts_src/psbt.ts:337


addOutputs()

addOutputs(outputDatas): this

Parameters

outputDatas: PsbtOutputExtended[]

Returns

this

Defined in

ts_src/psbt.ts:332


addUnknownKeyValToGlobal()

addUnknownKeyValToGlobal(keyVal): this

Parameters

keyVal: KeyValue

Returns

this

Defined in

ts_src/psbt.ts:1142


addUnknownKeyValToInput()

addUnknownKeyValToInput(inputIndex, keyVal): this

Parameters

inputIndex: number

keyVal: KeyValue

Returns

this

Defined in

ts_src/psbt.ts:1147


addUnknownKeyValToOutput()

addUnknownKeyValToOutput(outputIndex, keyVal): this

Parameters

outputIndex: number

keyVal: KeyValue

Returns

this

Defined in

ts_src/psbt.ts:1152


clearFinalizedInput()

clearFinalizedInput(inputIndex): this

Parameters

inputIndex: number

Returns

this

Defined in

ts_src/psbt.ts:1157


clone()

clone(): Psbt

Returns

Psbt

Defined in

ts_src/psbt.ts:245


combine()

combine(...those): this

Parameters

• ...those: Psbt[]

Returns

this

Defined in

ts_src/psbt.ts:240


extractTransaction()

extractTransaction(disableFeeCheck?): Transaction

Parameters

disableFeeCheck?: boolean

Returns

Transaction

Defined in

ts_src/psbt.ts:367


finalizeAllInputs()

finalizeAllInputs(): this

Returns

this

Defined in

ts_src/psbt.ts:397


finalizeInput()

finalizeInput(inputIndex, finalScriptsFunc?): this

Parameters

inputIndex: number

finalScriptsFunc?: FinalScriptsFunc | FinalTaprootScriptsFunc

Returns

this

Defined in

ts_src/psbt.ts:403


finalizeTaprootInput()

finalizeTaprootInput(inputIndex, tapLeafHashToFinalize?, finalScriptsFunc?): this

Parameters

inputIndex: number

tapLeafHashToFinalize?: Uint8Array

finalScriptsFunc?: FinalTaprootScriptsFunc = tapScriptFinalizer

Returns

this

Defined in

ts_src/psbt.ts:422


getFee()

getFee(): bigint

Returns

bigint

Defined in

ts_src/psbt.ts:388


getFeeRate()

getFeeRate(): number

Returns

number

Defined in

ts_src/psbt.ts:379


getInputType()

getInputType(inputIndex): AllScriptType

Parameters

inputIndex: number

Returns

AllScriptType

Defined in

ts_src/psbt.ts:504


inputHasHDKey()

inputHasHDKey(inputIndex, root): boolean

Parameters

inputIndex: number

root: HDSigner

Returns

boolean

Defined in

ts_src/psbt.ts:525


inputHasPubkey()

inputHasPubkey(inputIndex, pubkey): boolean

Parameters

inputIndex: number

pubkey: Uint8Array

Returns

boolean

Defined in

ts_src/psbt.ts:520


outputHasHDKey()

outputHasHDKey(outputIndex, root): boolean

Parameters

outputIndex: number

root: HDSigner

Returns

boolean

Defined in

ts_src/psbt.ts:538


outputHasPubkey()

outputHasPubkey(outputIndex, pubkey): boolean

Parameters

outputIndex: number

pubkey: Uint8Array

Returns

boolean

Defined in

ts_src/psbt.ts:533


setInputSequence()

setInputSequence(inputIndex, sequence): this

Parameters

inputIndex: number

sequence: number

Returns

this

Defined in

ts_src/psbt.ts:284


setLocktime()

setLocktime(locktime): this

Parameters

locktime: number

Returns

this

Defined in

ts_src/psbt.ts:266


setMaximumFeeRate()

setMaximumFeeRate(satoshiPerByte): void

Parameters

satoshiPerByte: number

Returns

void

Defined in

ts_src/psbt.ts:252


setNTime()

setNTime(nTime): this

Parameters

nTime: number

Returns

this

Defined in

ts_src/psbt.ts:275


setVersion()

setVersion(version): this

Parameters

version: number

Returns

this

Defined in

ts_src/psbt.ts:257


signAllInputs()

signAllInputs(keyPair, sighashTypes?): this

Parameters

keyPair: Signer

sighashTypes?: number[]

Returns

this

Defined in

ts_src/psbt.ts:765


signAllInputsAsync()

signAllInputsAsync(keyPair, sighashTypes?): Promise<void>

Parameters

keyPair: Signer | SignerAsync

sighashTypes?: number[]

Returns

Promise<void>

Defined in

ts_src/psbt.ts:787


signAllInputsHD()

signAllInputsHD(hdKeyPair, sighashTypes): this

Parameters

hdKeyPair: HDSigner

sighashTypes: number[] = ...

Returns

this

Defined in

ts_src/psbt.ts:672


signAllInputsHDAsync()

signAllInputsHDAsync(hdKeyPair, sighashTypes): Promise<void>

Parameters

hdKeyPair: HDSigner | HDSignerAsync

sighashTypes: number[] = ...

Returns

Promise<void>

Defined in

ts_src/psbt.ts:695


signInput()

signInput(inputIndex, keyPair, sighashTypes?): this

Parameters

inputIndex: number

keyPair: Signer

sighashTypes?: number[]

Returns

this

Defined in

ts_src/psbt.ts:821


signInputAsync()

signInputAsync(inputIndex, keyPair, sighashTypes?): Promise<void>

Parameters

inputIndex: number

keyPair: Signer | SignerAsync

sighashTypes?: number[]

Returns

Promise<void>

Defined in

ts_src/psbt.ts:937


signInputHD()

signInputHD(inputIndex, hdKeyPair, sighashTypes): this

Parameters

inputIndex: number

hdKeyPair: HDSigner

sighashTypes: number[] = ...

Returns

this

Defined in

ts_src/psbt.ts:727


signInputHDAsync()

signInputHDAsync(inputIndex, hdKeyPair, sighashTypes): Promise<void>

Parameters

inputIndex: number

hdKeyPair: HDSigner | HDSignerAsync

sighashTypes: number[] = ...

Returns

Promise<void>

Defined in

ts_src/psbt.ts:744


signTaprootInput()

signTaprootInput(inputIndex, keyPair, tapLeafHashToSign?, sighashTypes?): this

Parameters

inputIndex: number

keyPair: Signer

tapLeafHashToSign?: Uint8Array

sighashTypes?: number[]

Returns

this

Defined in

ts_src/psbt.ts:843


signTaprootInputAsync()

signTaprootInputAsync(inputIndex, keyPair, tapLeafHash?, sighashTypes?): Promise<void>

Parameters

inputIndex: number

keyPair: Signer | SignerAsync

tapLeafHash?: Uint8Array

sighashTypes?: number[]

Returns

Promise<void>

Defined in

ts_src/psbt.ts:960


toBase64()

toBase64(): string

Returns

string

Defined in

ts_src/psbt.ts:1106


toBuffer()

toBuffer(): Uint8Array

Returns

Uint8Array

Defined in

ts_src/psbt.ts:1096


toHex()

toHex(): string

Returns

string

Defined in

ts_src/psbt.ts:1101


updateGlobal()

updateGlobal(updateData): this

Parameters

updateData: PsbtGlobalUpdate

Returns

this

Defined in

ts_src/psbt.ts:1111


updateInput()

updateInput(inputIndex, updateData): this

Parameters

inputIndex: number

updateData: PsbtInputUpdate

Returns

this

Defined in

ts_src/psbt.ts:1116


updateOutput()

updateOutput(outputIndex, updateData): this

Parameters

outputIndex: number

updateData: PsbtOutputUpdate

Returns

this

Defined in

ts_src/psbt.ts:1134


validateSignaturesOfAllInputs()

validateSignaturesOfAllInputs(validator): boolean

Parameters

validator: ValidateSigFunction

Returns

boolean

Defined in

ts_src/psbt.ts:546


validateSignaturesOfInput()

validateSignaturesOfInput(inputIndex, validator, pubkey?): boolean

Parameters

inputIndex: number

validator: ValidateSigFunction

pubkey?: Uint8Array

Returns

boolean

Defined in

ts_src/psbt.ts:554


fromBase64()

static fromBase64(data, opts): Psbt

Parameters

data: string

opts: PsbtOptsOptional = {}

Returns

Psbt

Defined in

ts_src/psbt.ts:132


fromBuffer()

static fromBuffer(buffer, opts): Psbt

Parameters

buffer: Uint8Array

opts: PsbtOptsOptional = {}

Returns

Psbt

Defined in

ts_src/psbt.ts:142


fromHex()

static fromHex(data, opts): Psbt

Parameters

data: string

opts: PsbtOptsOptional = {}

Returns

Psbt

Defined in

ts_src/psbt.ts:137