Skip to content

Commit bfae179

Browse files
committed
Move global data to per-input and per-output data
Change from a global map with input data to a global k/v pair with input and output data. Add new types for finalized scriptSigs and scriptWitnesses. Redefined types to support new model Updated the formatting of the listing
1 parent 7158648 commit bfae179

File tree

1 file changed

+154
-175
lines changed

1 file changed

+154
-175
lines changed

bip-0174.mediawiki

Lines changed: 154 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ risk of being defrauded.
4343
==Specification==
4444

4545
The Partially Signed Bitcoin Transaction (PSBT) format consists of key-value maps.
46-
Each key-value pair must be unique within its scope; duplicates are not allowed.
46+
Each key-value pair must have a unique key within its scope; duplicates are not allowed.
4747
Each map consists of a sequence of records, terminated by a <tt>0x00</tt> byte <ref>'''Why
4848
is the separator here <tt>0x00</tt> instead of <tt>0xff</tt>?'''
4949
The separator here is used to distinguish between each chunk of data. A separator of 0x00 would mean that
@@ -106,186 +106,101 @@ The format of each key-value map is as follows:
106106
| Must be <tt>0x00</tt>.
107107
|}
108108

109-
The first byte of each key specifies the type of the key-value pair. Some types are
110-
for global fields and other fields are for each input. The only required type in a
111-
PSBT is the transaction type, as defined below. All global types that can pertain to both
112-
inputs and outputs of a transaction can include data for both inputs and outputs of
113-
the transaction. The currently defined global types are as follows:
109+
The first byte of each key specifies the type of the key-value pair. There are global types,
110+
per-input types, and per-output types.
114111

115-
{| class="wikitable" style="width: auto; text-align: center; font-size: smaller;
116-
table-layout: fixed;"
117-
!Number
118-
!Name
119-
!Key Data
120-
!Value Data
121-
!Format Example
122-
|-
123-
| <tt>0x00</tt>
124-
| Transaction
125-
| None. The key must only contain the 1 byte type.
126-
| The transaction in network serialization. The scriptSigs and
127-
witnesses for each input must be empty unless the input is complete. The transaction
128-
must be in the witness serialization format as defined in BIP 144. A PSBT must have
129-
a transaction, otherwise it is invalid.
130-
| Key:
131-
<pre>
132-
{0x00}
133-
</pre>
134-
Value:
135-
<pre>
136-
{transaction}
137-
</pre>
138-
|-
139-
| <tt>0x01</tt>
140-
| Redeem Script<ref>'''Why are redeem scripts and witness scripts global''' Redeem
141-
scripts and witness scripts are global data to avoid duplication. Instead of specifying
142-
a redeems script and witness script multiple times in inputs that need those scripts,
143-
they are specified once in the global data.</ref>
144-
| The hash160 of the redeem script
145-
| A redeem script that will be needed to sign a Pay-To-Script-Hash input or is spent
146-
to by an output.<ref>'''Why are outputs' redeem scripts and witness scripts included?'''
147-
Redeem scripts and witness scripts spent to by an output in this transaction are included
148-
so that the user can verify that the transaction they are signing is creating the correct
149-
outputs that have the correct redeem and witness scripts. This is best used when the
150-
PSBT creator is not trusted by the signers.</ref>
151-
| Key:
152-
<pre>
153-
{0x01}|{hash160}
154-
</pre>
155-
Value:
156-
<pre>
157-
{redeem script}
158-
</pre>
159-
|-
160-
| <tt>0x02</tt>
161-
| Witness Script
162-
| The sha256 hash of the witness script
163-
| A witness script that will be needed to sign a Pay-To-Witness-Script-Hash input or is spent
164-
to by an output.
165-
| Key:
166-
<pre>
167-
{0x02}|{sha256}
168-
</pre>
169-
Value:
170-
<pre>
171-
{witness script}
172-
</pre>
173-
|-
174-
| <tt>0x03</tt>
175-
| BIP 32 Derivation path, public key, and Master Key fingerprint
176-
| The public key
177-
| The master key fingerprint concatenated with the derivation path of the public key. The
178-
derivation path is represented as 32 bit unsigned integer indexes concatenated
179-
with each other. This must omit the index of the master key. Public keys can be those that
180-
will be needed to sign any type of key hash input or is spent to by an output.
181-
| Key:
182-
<pre>
183-
{0x03}|{public key}
184-
</pre>
185-
Value:
186-
<pre>
187-
{master key fingerprint}|{32-bit int}|...|{32-bit int}
188-
</pre>
189-
|-
190-
| <tt>0x04</tt>
191-
| Number of inputs provided in the PSBT
192-
| None. The key must only contain the 1 byte type.
193-
| A compact size unsigned integer representing the number of inputs that this PSBT has
194-
| Key:
195-
<pre>
196-
{0x04}
197-
</pre>
198-
Value:
199-
<pre>
200-
{number of inputs}
201-
</pre>
202-
|}
112+
The currently defined global types are as follows:
113+
114+
* Type: Unsigned Transaction <tt>PSBT_GLOBAL_UNSIGNED_TX = 0x00</tt>
115+
** Key: None. The key must only contain the 1 byte type.
116+
*** <tt>{0x00}</tt>
117+
** Value: The transaction in network serialization. The scriptSigs and witnesses for each input must be empty. The transaction must be in the old serialization format (without witnesses). A PSBT must have a transaction, otherwise it is invalid.
118+
*** <tt>{transaction}</tt>
119+
** Note: Every PSBT must have a field with this type.
203120
204121
The currently defined per-input types are defined as follows:
205122

206-
{| class="wikitable" style="width: auto; text-align: center; font-size: smaller;
207-
table-layout: fixed;"
208-
!Number
209-
!Name
210-
!Key Data
211-
!Value Data
212-
!Format Example
213-
|-
214-
| <tt>0x00</tt>
215-
| Non-Witness UTXO
216-
| None. The key must only contain the 1 byte type.
217-
| The transaction in network serialization format the current input spends from.
218-
| Key:
219-
<pre>
220-
{0x00}
221-
</pre>
222-
Value:
223-
<pre>
224-
{transaction}
225-
</pre>
226-
|-
227-
| <tt>0x01</tt>
228-
| Witness UTXO
229-
| None. The key must only contain the 1 byte type.
230-
| The entire transaction output in network serialization which the current input spends from.
231-
| Key:
232-
<pre>
233-
{0x01}
234-
</pre>
235-
Value:
236-
<pre>
237-
{serialized transaction output({output value}|<scriptPubKey>)}
238-
</pre>
239-
|-
240-
| <tt>0x02</tt>
241-
| Partial Signature
242-
| The public key which corresponds to this signature.
243-
| The signature as would be pushed to the stack from a scriptSig or witness.
244-
| Key:
245-
<pre>
246-
{0x02}|{public key}
247-
</pre>
248-
Value:
249-
<pre>
250-
{signature}
251-
</pre>
252-
|-
253-
| <tt>0x03</tt>
254-
| Sighash Type
255-
| None. The key must only contain the 1 byte type.
256-
| The 32-bit unsigned integer recommending a sighash type to be used for this input.
257-
The sighash type is only a recommendation and the signer does not need to use
258-
the sighash type specified.
259-
| Key:
260-
<pre>
261-
{0x03}
262-
</pre>
263-
Value:
264-
<pre>
265-
{sighash type}
266-
</pre>
267-
|-
268-
| <tt>0x04</tt>
269-
| Input index
270-
| None. The key must only contain the 1 byte type.
271-
| A compact size unsigned integer representing the 0-based index of this input. This field
272-
is optional to allow for completed inputs to be skipped without needing a separator byte.
273-
If one input has this type, then all inputs must have it.
274-
| Key:
275-
<pre>
276-
{0x04}
277-
</pre>
278-
Value:
279-
<pre>
280-
{input index}
281-
</pre>
282-
|}
123+
* Type: Non-Witness UTXO <tt>PSBT_IN_NON_WITNESS_UTXO = 0x00</tt>
124+
** Key: None. The key must only contain the 1 byte type.
125+
***<tt>{0x00}</tt>
126+
** Value: The transaction in network serialization format the current input spends from. This should only be present for inputs which spend non-segwit outputs. However, if it is unknown whether an input spends a segwit output, this type should be used.
127+
*** <tt>{transaction}</tt>
128+
129+
* Type: Witness UTXO <tt>PSBT_IN_WITNESS_UTXO = 0x01</tt>
130+
** Key: None. The key must only contain the 1 byte type.
131+
*** <tt>{0x01}</tt>
132+
** Value: The entire transaction output in network serialization which the current input spends from. This should only be present for inputs which spend segwit outputs, including P2SH embedded ones.
133+
*** <tt>{serialized transaction output({output value}|<scriptPubKey>)}</tt>
134+
135+
* Type: Partial Signature <tt>PSBT_IN_PARTIAL_SIG = 0x02</tt>
136+
** Key: The public key which corresponds to this signature.
137+
*** <tt>{0x02}|{public key}</tt>
138+
** Value: The signature as would be pushed to the stack from a scriptSig or witness.
139+
*** <tt>{signature}</tt>
140+
141+
* Type: Sighash Type <tt>PSBT_IN_SIGHASH_TYPE = 0x03</tt>
142+
** Key: None. The key must only contain the 1 byte type.
143+
*** <tt>{0x03}</tt>
144+
** Value: The 32-bit unsigned integer specifying the sighash type to be used for this input. Signatures for this input must use the sighash type, finalizers must fail to finalize inputs which have signatures that do not match the specified sighash type. Signers who cannot produce signatures with the sighash type must not provide a signature.
145+
*** <tt>{sighash type}</tt>
146+
147+
* Type: Redeem Script <tt>PSBT_IN_REDEEM_SCRIPT = 0x04</tt>
148+
** Key: None. The key must only contain the 1 byte type.
149+
*** <tt>{0x04}</tt>
150+
** Value: The redeemScript for this input if it has one.
151+
*** <tt>{redeemScript}</tt>
152+
153+
* Type: Witness Script <tt>PSBT_IN_WITNESS_SCRIPT = 0x05</tt>
154+
** Key: None. The key must only contain the 1 byte type.
155+
*** <tt>{0x05}</tt>
156+
** Value: The witnessScript for this input if it has one.
157+
*** <tt>{witnessScript}</tt>
158+
159+
* Type: BIP 32 Derivation Path <tt>PSBT_IN_BIP32_DERIVATION = 0x06</tt>
160+
** Key: The public key
161+
*** <tt>{0x06}|{public key}</tt>
162+
** Value: The master key fingerprint as defined by BIP 32 concatenated with the derivation path of the public key. The derivation path is represented as 32 bit unsigned integer indexes concatenated with each other. Public keys are those that will be needed to sign this input.
163+
*** <tt>{master key fingerprint}|{32-bit int}|...|{32-bit int}</tt>
164+
165+
* Type: Finalized scriptSig <tt>PSBT_IN_FINAL_SCRIPTSIG = 0x07</tt>
166+
** Key: None. The key must only contain the 1 byte type.
167+
*** <tt>{0x07}</tt>
168+
** Value: The Finalized scriptSig contains a fully constructed scriptSig with signatures and any other scripts necessary for the input to pass validation.
169+
*** <tt>{scriptSig}</tt>
170+
171+
* Type: Finalized scriptWitness <tt>PSBT_IN_FINAL_SCRIPTWITNESS = 0x08</tt>
172+
** Key: None. The key must only contain the 1 byte type.
173+
*** <tt>{0x08}</tt>
174+
** Value: The Finalized scriptWitness contains a fully constructed scriptWitness with signatures and any other scripts necessary for the input to pass validation.
175+
*** <tt>{scriptWitness}</tt>
176+
177+
The currently defined per-output <ref>'''Why do we need per-output data?''' Per-output data allows signers
178+
to verify that the outputs are going to the intended recipient. The output data can also be use by signers to
179+
determine which outputs are change outputs and verify that the change is returning to the correct place.</ref> types are defined as follows:
180+
181+
* Type: Redeem Script <tt>PSBT_OUT_REDEEM_SCRIPT = 0x00</tt>
182+
** Key: None. The key must only contain the 1 byte type.
183+
*** <tt>{0x00}</tt>
184+
** Value: The redeemScript for this output if it has one.
185+
*** <tt>{redeemScript}</tt>
186+
187+
* Type: Witness Script <tt>PSBT_OUT_WITNESS_SCRIPT = 0x01</tt>
188+
** Key: None. The key must only contain the 1 byte type.
189+
*** <tt>{0x01}</tt>
190+
** Value: The witnessScript for this output if it has one.
191+
*** <tt>{witnessScript}</tt>
192+
193+
* Type: BIP 32 Derivation Path <tt>PSBT_OUT_BIP32_DERIVATION = 0x02</tt>
194+
** Key: The public key
195+
*** <tt>{0x02}|{public key}</tt>
196+
** Value: The master key fingerprint concatenated with the derivation path of the public key. The derivation path is represented as 32 bit unsigned integer indexes concatenated with each other. This must omit the index of the master key. Public keys are those needed to spend this output.
197+
*** <tt>{master key fingerprint}|{32-bit int}|...|{32-bit int}</tt>
283198
284199
The transaction format is specified as follows:
285200

286201

287202
<pre>
288-
{0x70736274}|{0xff}|{global key-value map}|{input key-value map}|...|{input key-value map}
203+
{0x70736274}|{0xff}|{global key-value map}|{input key-value map}|...|{input key-value map}|{output key-value map}|...|{output key-value map}|
289204
</pre>
290205

291206
{| class="wikitable" style="width: auto; text-align: center; font-size: smaller; table-layout: fixed;"
@@ -325,7 +240,13 @@ in the non-PSBT format will be able to be unserialized by a PSBT unserializer.</
325240
| Inputs
326241
| Array of key-value maps
327242
| varies
328-
| The key-value pairs for each input as described below
243+
| The key-value pairs for each input as described above. Every input in the unsigned transaction must have a corresponding input map.
244+
|-
245+
| 1+
246+
| Outputs
247+
| Array of key-value maps
248+
| varies
249+
| The key-value pairs for each output as described above. Every output in the unsigned transaction must have a corresponding output map.
329250
|}
330251

331252
Each block of data between separators can be viewed as a scope, and all separators
@@ -519,13 +440,71 @@ Any data types, their associated scope and BIP number must be defined here
519440
{| class="wikitable" style="width: auto; text-align: center; font-size: smaller; table-layout: fixed;"
520441
!Scope
521442
!Type values
443+
!Name
522444
!BIP Number
523445
|-
524446
| Global
525-
| 0,1,2,3,4
447+
| 0
448+
| PSBT_GLOBAL_UNSIGNED_TX
449+
| BIP 174
450+
|-
451+
| Input
452+
| 0
453+
| PSBT_IN_NON_WITNESS_UTXO
454+
| BIP 174
455+
|-
456+
| Input
457+
| 1
458+
| PSBT_IN_WITNESS_UTXO
459+
| BIP 174
460+
|-
461+
| Input
462+
| 2
463+
| PSBT_IN_PARTIAL_SIG
526464
| BIP 174
527465
|-
528466
| Input
529-
| 0,1,2,3,4
467+
| 3
468+
| PSBT_IN_SIGHASH_TYPE
469+
| BIP 174
470+
|-
471+
| Input
472+
| 4
473+
| PSBT_IN_REDEEM_SCRIPT
474+
| BIP 174
475+
|-
476+
| Input
477+
| 5
478+
| PSBT_IN_WITNESS_SCRIPT
479+
| BIP 174
480+
|-
481+
| Input
482+
| 6
483+
| PSBT_IN_BIP32_DERIVATION
484+
| BIP 174
485+
|-
486+
| Input
487+
| 7
488+
| PSBT_IN_FINAL_SCRIPTSIG
489+
| BIP 174
490+
|-
491+
| Input
492+
| 8
493+
| PSBT_IN_FINAL_SCRIPTWITNESS
494+
| BIP 174
495+
|-
496+
| Output
497+
| 0
498+
| PSBT_OUT_REDEEM_SCRIPT
499+
| BIP 174
500+
|-
501+
| Output
502+
| 1
503+
| PSBT_OUT_WITNESS_SCRIPT
504+
| BIP 174
505+
|-
506+
| Output
507+
| 2
508+
| PSBT_OUT_BIP32_DERIVATION
530509
| BIP 174
531510
|}

0 commit comments

Comments
 (0)