bitcoinjs-lib / Psbt
Class: Psbt
Defined in: ts_src/psbt.ts:131
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
Constructor
new Psbt(
opts?,data?):Psbt
Defined in: ts_src/psbt.ts:152
Parameters
opts?
PsbtOptsOptional = {}
data?
Psbt = ...
Returns
Psbt
Properties
data
readonlydata:Psbt
Defined in: ts_src/psbt.ts:154
Accessors
inputCount
Get Signature
get inputCount():
number
Defined in: ts_src/psbt.ts:190
Returns
number
locktime
Get Signature
get locktime():
number
Defined in: ts_src/psbt.ts:202
Returns
number
Set Signature
set locktime(
locktime):void
Defined in: ts_src/psbt.ts:206
Parameters
locktime
number
Returns
void
txInputs
Get Signature
get txInputs():
PsbtTxInput[]
Defined in: ts_src/psbt.ts:210
Returns
txOutputs
Get Signature
get txOutputs():
PsbtTxOutput[]
Defined in: ts_src/psbt.ts:218
Returns
version
Get Signature
get version():
number
Defined in: ts_src/psbt.ts:194
Returns
number
Set Signature
set version(
version):void
Defined in: ts_src/psbt.ts:198
Parameters
version
number
Returns
void
Methods
addInput()
addInput(
inputData):this
Defined in: ts_src/psbt.ts:288
Parameters
inputData
PsbtInputExtended
Returns
this
addInputs()
addInputs(
inputDatas):this
Defined in: ts_src/psbt.ts:283
Parameters
inputDatas
PsbtInputExtended[]
Returns
this
addOutput()
addOutput(
outputData):this
Defined in: ts_src/psbt.ts:324
Parameters
outputData
PsbtOutputExtended
Returns
this
addOutputs()
addOutputs(
outputDatas):this
Defined in: ts_src/psbt.ts:319
Parameters
outputDatas
PsbtOutputExtended[]
Returns
this
addUnknownKeyValToGlobal()
addUnknownKeyValToGlobal(
keyVal):this
Defined in: ts_src/psbt.ts:1135
Parameters
keyVal
KeyValue
Returns
this
addUnknownKeyValToInput()
addUnknownKeyValToInput(
inputIndex,keyVal):this
Defined in: ts_src/psbt.ts:1140
Parameters
inputIndex
number
keyVal
KeyValue
Returns
this
addUnknownKeyValToOutput()
addUnknownKeyValToOutput(
outputIndex,keyVal):this
Defined in: ts_src/psbt.ts:1145
Parameters
outputIndex
number
keyVal
KeyValue
Returns
this
clearFinalizedInput()
clearFinalizedInput(
inputIndex):this
Defined in: ts_src/psbt.ts:1150
Parameters
inputIndex
number
Returns
this
clone()
clone():
Psbt
Defined in: ts_src/psbt.ts:241
Returns
Psbt
combine()
combine(...
those):this
Defined in: ts_src/psbt.ts:232
Parameters
those
...Psbt[]
Returns
this
extractTransaction()
extractTransaction(
disableFeeCheck?):Transaction
Defined in: ts_src/psbt.ts:354
Parameters
disableFeeCheck?
boolean
Returns
finalizeAllInputs()
finalizeAllInputs():
this
Defined in: ts_src/psbt.ts:384
Returns
this
finalizeInput()
finalizeInput(
inputIndex,finalScriptsFunc?):this
Defined in: ts_src/psbt.ts:390
Parameters
inputIndex
number
finalScriptsFunc?
FinalScriptsFunc | FinalTaprootScriptsFunc
Returns
this
finalizeTaprootInput()
finalizeTaprootInput(
inputIndex,tapLeafHashToFinalize?,finalScriptsFunc?):this
Defined in: ts_src/psbt.ts:409
Parameters
inputIndex
number
tapLeafHashToFinalize?
Uint8Array
finalScriptsFunc?
FinalTaprootScriptsFunc = tapScriptFinalizer
Returns
this
getFee()
getFee():
bigint
Defined in: ts_src/psbt.ts:375
Returns
bigint
getFeeRate()
getFeeRate():
number
Defined in: ts_src/psbt.ts:366
Returns
number
getInputType()
getInputType(
inputIndex):AllScriptType
Defined in: ts_src/psbt.ts:491
Parameters
inputIndex
number
Returns
AllScriptType
inputHasHDKey()
inputHasHDKey(
inputIndex,root):boolean
Defined in: ts_src/psbt.ts:512
Parameters
inputIndex
number
root
Returns
boolean
inputHasPubkey()
inputHasPubkey(
inputIndex,pubkey):boolean
Defined in: ts_src/psbt.ts:507
Parameters
inputIndex
number
pubkey
Uint8Array
Returns
boolean
outputHasHDKey()
outputHasHDKey(
outputIndex,root):boolean
Defined in: ts_src/psbt.ts:525
Parameters
outputIndex
number
root
Returns
boolean
outputHasPubkey()
outputHasPubkey(
outputIndex,pubkey):boolean
Defined in: ts_src/psbt.ts:520
Parameters
outputIndex
number
pubkey
Uint8Array
Returns
boolean
setInputSequence()
setInputSequence(
inputIndex,sequence):this
Defined in: ts_src/psbt.ts:271
Parameters
inputIndex
number
sequence
number
Returns
this
setLocktime()
setLocktime(
locktime):this
Defined in: ts_src/psbt.ts:262
Parameters
locktime
number
Returns
this
setMaximumFeeRate()
setMaximumFeeRate(
satoshiPerByte):void
Defined in: ts_src/psbt.ts:248
Parameters
satoshiPerByte
number
Returns
void
setVersion()
setVersion(
version):this
Defined in: ts_src/psbt.ts:253
Parameters
version
number
Returns
this
signAllInputs()
signAllInputs(
keyPair,sighashTypes?):this
Defined in: ts_src/psbt.ts:752
Parameters
keyPair
sighashTypes?
number[]
Returns
this
signAllInputsAsync()
signAllInputsAsync(
keyPair,sighashTypes?):Promise<void>
Defined in: ts_src/psbt.ts:774
Parameters
keyPair
sighashTypes?
number[]
Returns
Promise<void>
signAllInputsHD()
signAllInputsHD(
hdKeyPair,sighashTypes?):this
Defined in: ts_src/psbt.ts:659
Parameters
hdKeyPair
sighashTypes?
number[] = ...
Returns
this
signAllInputsHDAsync()
signAllInputsHDAsync(
hdKeyPair,sighashTypes?):Promise<void>
Defined in: ts_src/psbt.ts:682
Parameters
hdKeyPair
sighashTypes?
number[] = ...
Returns
Promise<void>
signInput()
signInput(
inputIndex,keyPair,sighashTypes?):this
Defined in: ts_src/psbt.ts:808
Parameters
inputIndex
number
keyPair
sighashTypes?
number[]
Returns
this
signInputAsync()
signInputAsync(
inputIndex,keyPair,sighashTypes?):Promise<void>
Defined in: ts_src/psbt.ts:924
Parameters
inputIndex
number
keyPair
sighashTypes?
number[]
Returns
Promise<void>
signInputHD()
signInputHD(
inputIndex,hdKeyPair,sighashTypes?):this
Defined in: ts_src/psbt.ts:714
Parameters
inputIndex
number
hdKeyPair
sighashTypes?
number[] = ...
Returns
this
signInputHDAsync()
signInputHDAsync(
inputIndex,hdKeyPair,sighashTypes?):Promise<void>
Defined in: ts_src/psbt.ts:731
Parameters
inputIndex
number
hdKeyPair
sighashTypes?
number[] = ...
Returns
Promise<void>
signTaprootInput()
signTaprootInput(
inputIndex,keyPair,tapLeafHashToSign?,sighashTypes?):this
Defined in: ts_src/psbt.ts:830
Parameters
inputIndex
number
keyPair
tapLeafHashToSign?
Uint8Array
sighashTypes?
number[]
Returns
this
signTaprootInputAsync()
signTaprootInputAsync(
inputIndex,keyPair,tapLeafHash?,sighashTypes?):Promise<void>
Defined in: ts_src/psbt.ts:947
Parameters
inputIndex
number
keyPair
tapLeafHash?
Uint8Array
sighashTypes?
number[]
Returns
Promise<void>
toBase64()
toBase64():
string
Defined in: ts_src/psbt.ts:1093
Returns
string
toBuffer()
toBuffer():
Uint8Array
Defined in: ts_src/psbt.ts:1083
Returns
Uint8Array
toHex()
toHex():
string
Defined in: ts_src/psbt.ts:1088
Returns
string
updateGlobal()
updateGlobal(
updateData):this
Defined in: ts_src/psbt.ts:1098
Parameters
updateData
PsbtGlobalUpdate
Returns
this
updateInput()
updateInput(
inputIndex,updateData):this
Defined in: ts_src/psbt.ts:1103
Parameters
inputIndex
number
updateData
PsbtInputUpdate
Returns
this
updateOutput()
updateOutput(
outputIndex,updateData):this
Defined in: ts_src/psbt.ts:1127
Parameters
outputIndex
number
updateData
PsbtOutputUpdate
Returns
this
validateSignaturesOfAllInputs()
validateSignaturesOfAllInputs(
validator):boolean
Defined in: ts_src/psbt.ts:533
Parameters
validator
ValidateSigFunction
Returns
boolean
validateSignaturesOfInput()
validateSignaturesOfInput(
inputIndex,validator,pubkey?):boolean
Defined in: ts_src/psbt.ts:541
Parameters
inputIndex
number
validator
ValidateSigFunction
pubkey?
Uint8Array
Returns
boolean
fromBase64()
staticfromBase64(data,opts?):Psbt
Defined in: ts_src/psbt.ts:132
Parameters
data
string
opts?
PsbtOptsOptional = {}
Returns
Psbt
fromBuffer()
staticfromBuffer(buffer,opts?):Psbt
Defined in: ts_src/psbt.ts:142
Parameters
buffer
Uint8Array
opts?
PsbtOptsOptional = {}
Returns
Psbt
fromHex()
staticfromHex(data,opts?):Psbt
Defined in: ts_src/psbt.ts:137
Parameters
data
string
opts?
PsbtOptsOptional = {}
Returns
Psbt