Skip to content

Commit 4e2bb34

Browse files
danpapeveleslavs
authored andcommitted
add examples for TxRefs with Outpoints; fix some typos and wording
1 parent a8bb0a4 commit 4e2bb34

File tree

1 file changed

+58
-38
lines changed

1 file changed

+58
-38
lines changed

bip-0136.mediawiki

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@
1616
== Introduction ==
1717

1818
=== Abstract ===
19-
This document proposes a convenient human useable format, '''"TxRef"''', as a standard way to refer to a transaction position within the Bitcoin Blockchain, and optionally a particular outpoint index with the referred transaction. The primary purpose of this format is to allow users to refer to a confirmed transaction (and optionally an outpoint index within) in a standard reliable and concise way.
19+
This document proposes a convenient human useable format, '''"TxRef"''', as a standard way to refer to a transaction position within the Bitcoin Blockchain, and optionally a particular outpoint index within the referred transaction. The primary purpose of this format is to allow users to refer to a confirmed transaction (and optionally an outpoint index within) in a standard, reliable, and concise way.
2020

21-
''Please note: Unlike TxID where there is strong cryptographic link between the ID and the actual transaction. TxRef only provide a weak link to a particular transaction. TxRef locates an offset within a blockchain for a transaction, that may - or may not - point to an actual transaction, which fact may change with reorganisations. We recommend that TxRef's should be not used for positions within the blockchain having a maturity less than 100 blocks.''
21+
''Please note: Unlike TxID where there is strong cryptographic link between the ID and the actual transaction, TxRef only provides a weak link to a particular transaction. TxRef locates an offset within a blockchain for a transaction, that may - or may not - point to an actual transaction, which in fact may change with reorganisations. We recommend that TxRef's should be not used for positions within the blockchain having a maturity less than 100 blocks.''
2222

2323
=== Copyright ===
2424

2525
This BIP is licensed under the 2-clause BSD license.
2626

2727
=== Motivation ===
28-
Since the first version of Bitcoin, TxID's (Transaction Identifiers) that are a core part of the consensus protocol, have been routinely used to identify individual transactions between users.
28+
Since the first version of Bitcoin, TxID's (Transaction Identifiers) have been a core part of the consensus protocol and have been routinely used to identify individual transactions between users.
2929

3030
However, for many use-cases they have practical limitations:
3131
* TxIDs are expensive for full nodes to lookup (requiring either a linear scan of the blockchain, or an expensive TxID index).
32-
* TxIDs require third-party service for SPV wallets to lookup.
32+
* TxIDs require third-party services for SPV wallets to lookup.
3333
* TxIDs are very long HEX encoded values (64 characters long).
3434
3535
For transactions that have been embedded in the blockchain, it is possible to reference them not by their TxID, but by their location within the blockchain itself. The encoding can be made friendly for occasional human transcription. In this document, we propose a standard for doing this.
3636

3737
=== Examples ===
3838
These examples are for Bitcoin Transactions.
39-
* Genesis Coinbase Transaction: <tt>tx1:rqqq-qqqq-qmhu-qhp</tt>
39+
* Genesis Coinbase Transaction (Transaction #0 of Block #0): <tt>tx1:rqqq-qqqq-qmhu-qhp</tt>
4040
* Transaction #2205 of Block #466793: <tt>tx1:rjk0-uqay-zsrw-hqe</tt>
4141
4242
== Specification ==
@@ -69,12 +69,12 @@ TxRef uses standard Bech32<ref name=":0">'''Why use Bech32 Encoding for Confirme
6969
* Separator: '''"1"'''.
7070
* Data Part.
7171
72-
Please node: other specifcations, such as [https://w3c-ccg.github.io/did-spec/ Decentralized Identifier syntax] , have implicitly encoded the information contained within the HRP elsewhere. In this case they may choose not include the HRP as specified here.
72+
Please note: other specifications, such as [https://w3c-ccg.github.io/did-spec/ the Decentralized Identifiers spec], have implicitly encoded the information contained within the HRP elsewhere. In this case they may choose to not include the HRP as specified here.
7373

7474
To increase portability and readability additional separators SHOULD be added:
7575

7676
* A Colon<ref>'''Why add a colon here?''' This allows it to conform better with W3C URN/URL standards.</ref> '''":"''' added after '1'.
77-
* Hyphens<ref>'''Why hyphens to the TxRef?''' As TxRef's are short, we expect that they will be quoted via voice or written by hand. The inclusion of hyphens every 4 characters breaks the string and means people don't lose their place so easily.</ref> '''"-"''' added after every 4 characters beyond the colon.
77+
* Hyphens<ref>'''Why hyphens within the TxRef?''' As TxRef's are short, we expect that they will be quoted via voice or written by hand. The inclusion of hyphens every 4 characters breaks up the string and means people don't lose their place so easily.</ref> '''"-"''' added after every 4 characters beyond the colon.
7878
7979
All non-bech32-alphabet characters after the bech32 code separator MUST be ignored/removed when parsing (except for terminating characters).<ref>'''Why strip all non-bech32-alphabet characters?''' We do not wish to expect the users to keep their TxRef's in good unicode form (hyphens, colons, invisible spaces, random unicode characters, etc). We expect them to copy, paste, write by-hand, write in a mix of character sets, etc. Parsers should automatically correct for all sorts of these common errors.
8080
</ref>
@@ -116,10 +116,10 @@ All non-bech32-alphabet characters after the bech32 code separator MUST be ignor
116116
|1
117117
|"'''-'''"
118118
|}
119-
The Data - Hyphen patten is repeated for the entire length of data, ( a hyphen is inserted after every encoded 20 bits or 4 data characters).
119+
The Data - Hyphen pattern is repeated for the entire length of data, ( a hyphen is inserted after every encoded 20 bits or 4 data characters).
120120
=== Data ===
121121

122-
The 75 or 90 bits of data encoded in the string above are defined in this manner:
122+
Depending on if an optional transaction outpoint is included, there can be 75 or 90 bits of data encoded in the string above. These bits are defined in this manner:
123123

124124
{| class="wikitable"
125125
|+TxRef Binary Format for Bitcoin Mainnet and Bitcoin Testnet:
@@ -130,7 +130,7 @@ The 75 or 90 bits of data encoded in the string above are defined in this manner
130130
!'''Values'''
131131
!'''Notes'''
132132
|-
133-
|Magic
133+
|Magic Code
134134
|0 – 4
135135
|5
136136
|Chain Namespacing Code
@@ -161,7 +161,7 @@ The 75 or 90 bits of data encoded in the string above are defined in this manner
161161
|Tx 0 (coinbase) to Tx position 32767
162162
|Max Tx's in block is 16665
163163
|}
164-
If the magic is '''0x4''' or '''0x7''', an optional outpoint is included in the encoding:
164+
If the magic code is '''0x4''' or '''0x7''', an optional outpoint is included in the encoding:
165165

166166
{| class="wikitable"
167167
|+Optional Outpoint Index Encoding:
@@ -176,7 +176,7 @@ If the magic is '''0x4''' or '''0x7''', an optional outpoint is included in the
176176
|45 – 59
177177
|15
178178
|The index of the Outpoint inside the Tx
179-
|Outpoint 0 to Outpoint Position 32767
179+
|Outpoint 0 to Outpoint Position 32767
180180
|
181181
|}
182182

@@ -220,19 +220,19 @@ There are no known compatibility issues.
220220
<references />
221221

222222
== Reference implementations ==
223-
C Reference Implementation (supports version 0): https://github.com/jonasschnelli/bitcoin_txref_code
223+
C Reference Implementation (supports magic codes 0x3 and 0x6): https://github.com/jonasschnelli/bitcoin_txref_code
224224

225-
Go Reference Implementation (supports version 0): https://github.com/kulpreet/txref
225+
Go Reference Implementation (supports magic codes 0x3 and 0x6): https://github.com/kulpreet/txref
226226

227-
C++ Reference Implementation (support versions 0 and 1): https://github.com/dcdpr/btcr-DID-method/blob/master/libtxref
227+
C++ Reference Implementation (support magic codes 0x3, 0x4, 0x6, 0x7): https://github.com/dcdpr/btcr-DID-method/
228228

229229
== Appendices ==
230230

231231
=== Test Vectors ===
232232
There are two sets of Test Vectors included here:
233233

234234
* Bech32 Encoding Test Vectors. These are to test if a implementation accepts the encoding, with the correct human readable part, and separator.
235-
* Bitcoin TxRef Test Vectors. These test the full specification, in particular correct values for block height and the transaction index.
235+
* Bitcoin TxRef Test Vectors. These test the full specification, in particular, correct values for block height and the transaction index.
236236
237237
==== Bech32 Encoding (for TxRef). ====
238238
''Please Note: All test vectors are shown to help test if a string is compliant or not. All real-life applications (such as for Bitcoin) should comply with the Bitcoin Test Vectors listed Below.''
@@ -247,15 +247,22 @@ The following list gives invalid TxRef's and the reason for their invalidity.
247247
* <tt>bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kg3g4ty</tt>: Invalid human-readable part
248248
* <tt>tx1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5</tt>: Invalid checksum
249249
250-
==== Bitcoin TxRef ====
251-
The following list gives properly encoded Bitcoin TxRef's and the values in hex. (block height, transaction index)
250+
==== Bitcoin TxRef (mainnet and testnet) ====
251+
The following list gives properly encoded Bitcoin mainnet TxRef's and the values in hex. (block height, transaction index)
252252

253253
* <tt>tx1:rqqq-qqqq-qmhu-qhp</tt>: <tt>(0x0, 0x0)</tt>
254254
* <tt>tx1:rqqq-qqll-l8xh-jkg</tt>: <tt>(0x0, 0x7FFF)</tt>
255255
* <tt>tx1:r7ll-llqq-qghq-qr8</tt>: <tt>(0xFFFFFF, 0x0)</tt>
256256
* <tt>tx1:r7ll-llll-l5xt-jzw</tt>: <tt>(0xFFFFFF, 0x7FFF)</tt>
257257
258-
The following list gives valid Bitcoin TxRef's and the values in hex. (block height, transaction index)
258+
The following list gives properly encoded Bitcoin testnet TxRef's and the values in hex. (block height, transaction index)
259+
260+
* <tt>txtest1:xqqq-qqqq-qkla-64l</tt>: <tt>(0x0, 0x0)</tt>
261+
* <tt>txtest1:xqqq-qqll-l2wk-g5k</tt>: <tt>(0x0, 0x7FFF)</tt>
262+
* <tt>txtest1:x7ll-llqq-q9lp-6pe</tt>: <tt>(0xFFFFFF, 0x0)</tt>
263+
* <tt>txtest1:x7ll-llll-lew2-gqs</tt>: <tt>(0xFFFFFF, 0x7FFF)</tt>
264+
265+
The following list gives valid (though strangely formatted) Bitcoin TxRef's and the values in hex. (block height, transaction index)
259266
* <tt>tx1:rjk0-uqay-zsrw-hqe</tt>: <tt>(0x71F69, 0x89D)</tt>
260267
* <tt>TX1RJK0UQAYZSRWHQE</tt>: <tt>(0x71F69, 0x89D)</tt>
261268
* <tt>TX1RJK0--UQaYZSRw----HQE</tt>: <tt>(0x71F69, 0x89D)</tt>
@@ -268,6 +275,38 @@ The following list gives invalid Bitcoin TxRef's and the reason for their invali
268275
* <tt>tx1:rjk0-u5ng-gghq-fkg7</tt>: Valid Bech32, but 10x5bit packages instead of 8.
269276
* <tt>tx1:rjk0-u5qd-s43z</tt>: Valid Bech32, but 6x5bit packages instead of 8.
270277
278+
==== Bitcoin TxRef with Outpoints (mainnet and testnet) ====
279+
The following list gives properly encoded Bitcoin mainnet TxRef's with Outpoints and the values in hex. (block height, transaction index, TXO index)
280+
281+
* <tt>tx1:yqqq-qqqq-qqqq-ksvh-26</tt>: <tt>(0x0, 0x0, 0x0)</tt>
282+
* <tt>tx1:yqqq-qqll-lqqq-v0h2-2k</tt>: <tt>(0x0, 0x7FFF, 0x0)</tt>
283+
* <tt>tx1:y7ll-llqq-qqqq-a5zy-tc</tt>: <tt>(0xFFFFFF, 0x0, 0x0)</tt>
284+
* <tt>tx1:y7ll-llll-lqqq-8tee-t5</tt>: <tt>(0xFFFFFF, 0x7FFF, 0x0)</tt>
285+
286+
* <tt>tx1:yqqq-qqqq-qpqq-5j9q-nz</tt>: <tt>(0x0, 0x0, 0x1)</tt>
287+
* <tt>tx1:yqqq-qqll-lpqq-wd7a-nw</tt>: <tt>(0x0, 0x7FFF, 0x1)</tt>
288+
* <tt>tx1:y7ll-llqq-qpqq-lktn-jq</tt>: <tt>(0xFFFFFF, 0x0, 0x1)</tt>
289+
* <tt>tx1:y7ll-llll-lpqq-9fsw-jv</tt>: <tt>(0xFFFFFF, 0x7FFF, 0x1)</tt>
290+
291+
* <tt>tx1:yjk0-uqay-zrfq-g2cg-t8</tt>: <tt>(0x71F69, 0x89D, 0x123)</tt>
292+
* <tt>tx1:yjk0-uqay-zu4x-nk6u-pc</tt>: <tt>(0x71F69, 0x89D, 0x1ABC)</tt>
293+
294+
The following list gives properly encoded Bitcoin testnet TxRef's with Outpoints and the values in hex. (block height, transaction index, TXO index)
295+
296+
* <tt>txtest1:8qqq-qqqq-qqqq-cgru-fa</tt>: <tt>(0x0, 0x0, 0x0)</tt>
297+
* <tt>txtest1:8qqq-qqll-lqqq-zhcp-f3</tt>: <tt>(0x0, 0x7FFF, 0x0)</tt>
298+
* <tt>txtest1:87ll-llqq-qqqq-nvd0-gl</tt>: <tt>(0xFFFFFF, 0x0, 0x0)</tt>
299+
* <tt>txtest1:87ll-llll-lqqq-fnkj-gn</tt>: <tt>(0xFFFFFF, 0x7FFF, 0x0)</tt>
300+
301+
* <tt>txtest1:8qqq-qqqq-qpqq-622t-s9</tt>: <tt>(0x0, 0x0, 0x1)</tt>
302+
* <tt>txtest1:8qqq-qqll-lpqq-q43k-sf</tt>: <tt>(0x0, 0x7FFF, 0x1)</tt>
303+
* <tt>txtest1:87ll-llqq-qpqq-3wyc-38</tt>: <tt>(0xFFFFFF, 0x0, 0x1)</tt>
304+
* <tt>txtest1:87ll-llll-lpqq-t3l9-3t</tt>: <tt>(0xFFFFFF, 0x7FFF, 0x1)</tt>
305+
306+
* <tt>txtest1:8jk0-uqay-zrfq-xjhr-gq</tt>: <tt>(0x71F69, 0x89D, 0x123)</tt>
307+
* <tt>txtest1:8jk0-uqay-zu4x-aw4h-zl</tt>: <tt>(0x71F69, 0x89D, 0x1ABC)</tt>
308+
309+
271310
=== Bitcoin TxRef Payload Value Choice: ===
272311
Some calculations showing why we chose these particular bit-length of the block height and transaction index.
273312

@@ -285,24 +324,5 @@ Some calculations showing why we chose these particular bit-length of the block
285324
*The ''extreme'' smallest Tx is 60 Byte's: Max 16665 tx in a block.
286325
**4B version + 1B tx_in count + 36B previous_output + 1B script length + 0B signature script + 4B sequence + 1B tx_out count + 8B amount + 1B script length + 0B pubkey script + 4B lock_time = 60B
287326
288-
=== Test Vectors (version 1) ===
289-
These test vectors are extended TxRefs (version 1):
290-
291-
==== Bitcoin Extended TxRef ====
292-
The following list gives properly encoded Bitcoin Extended TxRef's and the values in hex. (block height, transaction index, TXO index)
293-
294-
* <tt>tx1:rpqq-qqqq-qqqq-q2ge-ahz</tt>: <tt>(0x0, 0x0, 0x0)</tt>
295-
* <tt>tx1:rpqq-qqql-llqq-qshz-qhw</tt>: <tt>(0x0, 0x7FFF, 0x0)</tt>
296-
* <tt>tx1:rp7l-lllq-qqqq-qpvh-wkq</tt>: <tt>(0xFFFFFF, 0x0, 0x0)</tt>
297-
* <tt>tx1:rp7l-llll-llqq-qmnv-nkv</tt>: <tt>(0xFFFFFF, 0x7FFF, 0x0)</tt>
298-
299-
* <tt>tx1:rpqq-qqqq-qqpq-qg2s-2w6</tt>: <tt>(0x0, 0x0, 0x1)</tt>
300-
* <tt>tx1:rpqq-qqql-llpq-qj4t-hwk</tt>: <tt>(0x0, 0x7FFF, 0x1)</tt>
301-
* <tt>tx1:rp7l-lllq-qqpq-qrw7-e0c</tt>: <tt>(0xFFFFFF, 0x0, 0x1)</tt>
302-
* <tt>tx1:rp7l-llll-llpq-qe39-y05</tt>: <tt>(0xFFFFFF, 0x7FFF, 0x1)</tt>
303-
304-
* <tt>tx1:rpjk-0uqa-yzu4-x0w0-kuq</tt>: <tt>(0x71F69, 0x89D, 0x1ABC)</tt>
305-
* <tt>txtest1:xpjk-0uqa-yzu4-xgrl-pue</tt>: <tt>(0x71F69, 0x89D, 0x1ABC)</tt> (testnet, magic number = 0x6)
306-
307327
== Acknowledgements ==
308328
Special Thanks to Pieter Wuille and Greg Maxwell for Bech32, a wonderful user-facing data encoding.

0 commit comments

Comments
 (0)