Psbt
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
new Psbt()
new Psbt(
opts
,data
):Psbt
Defined in: ts_src/psbt.ts:152
Parameters
opts
PsbtOptsOptional
= {}
data
Psbt
= ...
Returns
Properties
data
readonly
data: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:284
Parameters
inputData
Returns
this
addInputs()
addInputs(
inputDatas
):this
Defined in: ts_src/psbt.ts:279
Parameters
inputDatas
Returns
this
addOutput()
addOutput(
outputData
):this
Defined in: ts_src/psbt.ts:320
Parameters
outputData
Returns
this
addOutputs()
addOutputs(
outputDatas
):this
Defined in: ts_src/psbt.ts:315
Parameters
outputDatas
Returns
this
addUnknownKeyValToGlobal()
addUnknownKeyValToGlobal(
keyVal
):this
Defined in: ts_src/psbt.ts:1125
Parameters
keyVal
KeyValue
Returns
this
addUnknownKeyValToInput()
addUnknownKeyValToInput(
inputIndex
,keyVal
):this
Defined in: ts_src/psbt.ts:1130
Parameters
inputIndex
number
keyVal
KeyValue
Returns
this
addUnknownKeyValToOutput()
addUnknownKeyValToOutput(
outputIndex
,keyVal
):this
Defined in: ts_src/psbt.ts:1135
Parameters
outputIndex
number
keyVal
KeyValue
Returns
this
clearFinalizedInput()
clearFinalizedInput(
inputIndex
):this
Defined in: ts_src/psbt.ts:1140
Parameters
inputIndex
number
Returns
this
clone()
clone():
Psbt
Defined in: ts_src/psbt.ts:237
Returns
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:350
Parameters
disableFeeCheck?
boolean
Returns
finalizeAllInputs()
finalizeAllInputs():
this
Defined in: ts_src/psbt.ts:380
Returns
this
finalizeInput()
finalizeInput(
inputIndex
,finalScriptsFunc
?):this
Defined in: ts_src/psbt.ts:386
Parameters
inputIndex
number
finalScriptsFunc?
FinalScriptsFunc
| FinalTaprootScriptsFunc
Returns
this
finalizeTaprootInput()
finalizeTaprootInput(
inputIndex
,tapLeafHashToFinalize
?,finalScriptsFunc
?):this
Defined in: ts_src/psbt.ts:405
Parameters
inputIndex
number
tapLeafHashToFinalize?
Uint8Array
finalScriptsFunc?
FinalTaprootScriptsFunc
= tapScriptFinalizer
Returns
this
getFee()
getFee():
bigint
Defined in: ts_src/psbt.ts:371
Returns
bigint
getFeeRate()
getFeeRate():
number
Defined in: ts_src/psbt.ts:362
Returns
number
getInputType()
getInputType(
inputIndex
):AllScriptType
Defined in: ts_src/psbt.ts:487
Parameters
inputIndex
number
Returns
AllScriptType
inputHasHDKey()
inputHasHDKey(
inputIndex
,root
):boolean
Defined in: ts_src/psbt.ts:508
Parameters
inputIndex
number
root
Returns
boolean
inputHasPubkey()
inputHasPubkey(
inputIndex
,pubkey
):boolean
Defined in: ts_src/psbt.ts:503
Parameters
inputIndex
number
pubkey
Uint8Array
Returns
boolean
outputHasHDKey()
outputHasHDKey(
outputIndex
,root
):boolean
Defined in: ts_src/psbt.ts:521
Parameters
outputIndex
number
root
Returns
boolean
outputHasPubkey()
outputHasPubkey(
outputIndex
,pubkey
):boolean
Defined in: ts_src/psbt.ts:516
Parameters
outputIndex
number
pubkey
Uint8Array
Returns
boolean
setInputSequence()
setInputSequence(
inputIndex
,sequence
):this
Defined in: ts_src/psbt.ts:267
Parameters
inputIndex
number
sequence
number
Returns
this
setLocktime()
setLocktime(
locktime
):this
Defined in: ts_src/psbt.ts:258
Parameters
locktime
number
Returns
this
setMaximumFeeRate()
setMaximumFeeRate(
satoshiPerByte
):void
Defined in: ts_src/psbt.ts:244
Parameters
satoshiPerByte
number
Returns
void
setVersion()
setVersion(
version
):this
Defined in: ts_src/psbt.ts:249
Parameters
version
number
Returns
this
signAllInputs()
signAllInputs(
keyPair
,sighashTypes
?):this
Defined in: ts_src/psbt.ts:748
Parameters
keyPair
sighashTypes?
number
[]
Returns
this
signAllInputsAsync()
signAllInputsAsync(
keyPair
,sighashTypes
?):Promise
\<void
>
Defined in: ts_src/psbt.ts:770
Parameters
keyPair
sighashTypes?
number
[]
Returns
Promise
\<void
>
signAllInputsHD()
signAllInputsHD(
hdKeyPair
,sighashTypes
):this
Defined in: ts_src/psbt.ts:655
Parameters
hdKeyPair
sighashTypes
number
[] = ...
Returns
this
signAllInputsHDAsync()
signAllInputsHDAsync(
hdKeyPair
,sighashTypes
):Promise
\<void
>
Defined in: ts_src/psbt.ts:678
Parameters
hdKeyPair
sighashTypes
number
[] = ...
Returns
Promise
\<void
>
signInput()
signInput(
inputIndex
,keyPair
,sighashTypes
?):this
Defined in: ts_src/psbt.ts:804
Parameters
inputIndex
number
keyPair
sighashTypes?
number
[]
Returns
this
signInputAsync()
signInputAsync(
inputIndex
,keyPair
,sighashTypes
?):Promise
\<void
>
Defined in: ts_src/psbt.ts:920
Parameters
inputIndex
number
keyPair
sighashTypes?
number
[]
Returns
Promise
\<void
>
signInputHD()
signInputHD(
inputIndex
,hdKeyPair
,sighashTypes
):this
Defined in: ts_src/psbt.ts:710
Parameters
inputIndex
number
hdKeyPair
sighashTypes
number
[] = ...
Returns
this
signInputHDAsync()
signInputHDAsync(
inputIndex
,hdKeyPair
,sighashTypes
):Promise
\<void
>
Defined in: ts_src/psbt.ts:727
Parameters
inputIndex
number
hdKeyPair
sighashTypes
number
[] = ...
Returns
Promise
\<void
>
signTaprootInput()
signTaprootInput(
inputIndex
,keyPair
,tapLeafHashToSign
?,sighashTypes
?):this
Defined in: ts_src/psbt.ts:826
Parameters
inputIndex
number
keyPair
tapLeafHashToSign?
Uint8Array
sighashTypes?
number
[]
Returns
this
signTaprootInputAsync()
signTaprootInputAsync(
inputIndex
,keyPair
,tapLeafHash
?,sighashTypes
?):Promise
\<void
>
Defined in: ts_src/psbt.ts:943
Parameters
inputIndex
number
keyPair
tapLeafHash?
Uint8Array
sighashTypes?
number
[]
Returns
Promise
\<void
>
toBase64()
toBase64():
string
Defined in: ts_src/psbt.ts:1089
Returns
string
toBuffer()
toBuffer():
Uint8Array
Defined in: ts_src/psbt.ts:1079
Returns
Uint8Array
toHex()
toHex():
string
Defined in: ts_src/psbt.ts:1084
Returns
string
updateGlobal()
updateGlobal(
updateData
):this
Defined in: ts_src/psbt.ts:1094
Parameters
updateData
PsbtGlobalUpdate
Returns
this
updateInput()
updateInput(
inputIndex
,updateData
):this
Defined in: ts_src/psbt.ts:1099
Parameters
inputIndex
number
updateData
PsbtInputUpdate
Returns
this
updateOutput()
updateOutput(
outputIndex
,updateData
):this
Defined in: ts_src/psbt.ts:1117
Parameters
outputIndex
number
updateData
PsbtOutputUpdate
Returns
this
validateSignaturesOfAllInputs()
validateSignaturesOfAllInputs(
validator
):boolean
Defined in: ts_src/psbt.ts:529
Parameters
validator
Returns
boolean
validateSignaturesOfInput()
validateSignaturesOfInput(
inputIndex
,validator
,pubkey
?):boolean
Defined in: ts_src/psbt.ts:537
Parameters
inputIndex
number
validator
pubkey?
Uint8Array
Returns
boolean
fromBase64()
static
fromBase64(data
,opts
):Psbt
Defined in: ts_src/psbt.ts:132
Parameters
data
string
opts
PsbtOptsOptional
= {}
Returns
fromBuffer()
static
fromBuffer(buffer
,opts
):Psbt
Defined in: ts_src/psbt.ts:142
Parameters
buffer
Uint8Array
opts
PsbtOptsOptional
= {}
Returns
fromHex()
static
fromHex(data
,opts
):Psbt
Defined in: ts_src/psbt.ts:137
Parameters
data
string
opts
PsbtOptsOptional
= {}