Skip to content

Commit f5cb29f

Browse files
committed
Update BIP 321 with information about more modern usage of it
As Bitcoin has grown, the introduction of new address formats describing new forms of payment instructions has become increasingly fraught with compatibility issues. Not only does there exist traditional on-chain addresses, but some recipients wish to receive Lightning (when the sender supports it) or newer formats such as Silent Payments. This has led to increasing use of the BIP 21 query parameters to encode further optional payment instructions. Looking forward, as new payment instructions get adopted, it makes much more sense to include them in query parameters rather than replace the existing address field, ensuring compatibility with senders and recipients who may or may not be upgraded to support all the latest payment instructions. This updates BIP 321 to suggest that future address formats do this. Further, it updates BIP 321 to allow an empty bitcoin address in cases where new payment instructions have moved to becoming mandatory. This isn't a backwards-incompatible change any more than switching to a new address format is, so doesn't impact existing BIP 21 implementations in a new way, however provides a nice conclusion to the query-parameter-based upgrade path - once a form of payment instructions has broad adoption, senders can simply drop the existing address field, keeping their existing query parameter encoding, rather than replace the existing address field. It also addresses the question of what to do if a wallet no longer wishes to receive some legacy on-chain address, but has multiple payment instruction formats that they wish to include - deciding which one to place in the address field would be a difficult task. Finally, it defines a new query parameter, the `pop` parameter, which allows the initiating application to receive callbacks for proof of payment completion.
1 parent f958360 commit f5cb29f

File tree

1 file changed

+147
-42
lines changed

1 file changed

+147
-42
lines changed

bip-0321.mediawiki

Lines changed: 147 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,32 @@
99
Type: Standards Track
1010
Created: 2024-11-15
1111
License: BSD-2-Clause
12+
Replaces: 21
1213
</pre>
1314

14-
==Copyright==
15+
== Copyright ==
16+
1517
This BIP is licensed under the BSD 2-clause license.
1618

17-
==Abstract==
18-
This BIP proposes a URI scheme for making Bitcoin payments.
19+
== Abstract ==
20+
21+
This BIP proposes a URI scheme for describing Bitcoin payment instructions.
22+
23+
== Motivation ==
1924

20-
==Motivation==
2125
The purpose of this URI scheme is to enable users to easily make payments by simply clicking links on webpages or scanning QR Codes.
2226

23-
==Specification==
27+
This BIP is a modification of [[bip-0021.mediawiki|BIP 0021]] to add information about the modern usage of bitcoin: URIs (including standard query parameters and modern address types) as well as provide forward-looking guidance on how to incorporate new payment instructions. It further adds an optional extension to provide the payment initiator with proof of payment. BIP 21 was based on BIP 20, which was, in turn based on an earlier document by Nils Schneider.
28+
29+
== Specification ==
2430

2531
=== General rules for handling (important!) ===
2632

2733
Bitcoin clients MUST NOT act on URIs without getting the user's authorization.
2834
They SHOULD require the user to manually approve each payment individually, though in some cases they MAY allow the user to automatically make this decision.
2935

3036
=== Operating system integration ===
37+
3138
Graphical bitcoin clients SHOULD register themselves as the handler for the "bitcoin:" URI scheme by default, if no other handler is already registered. If there is already a registered handler, they MAY prompt the user to change it once when they first run the client.
3239

3340
=== General Format ===
@@ -38,94 +45,192 @@ Elements of the query component may contain characters outside the valid range.
3845

3946
=== ABNF grammar ===
4047

41-
(See also [[#Simpler syntax|a simpler representation of syntax]])
42-
43-
bitcoinurn = "bitcoin:" bitcoinaddress [ "?" bitcoinparams ]
48+
bitcoinurn = "bitcoin:" [ bitcoinaddress ] [ "?" bitcoinparams ]
4449
bitcoinaddress = *base58 / *bech32 / *bech32m
4550
bitcoinparams = bitcoinparam [ "&" bitcoinparams ]
46-
bitcoinparam = [ amountparam / labelparam / messageparam / otherparam / reqparam ]
51+
bitcoinparam = [ amountparam / labelparam / messageparam / responseparam / otherparam / reqparam ]
4752
amountparam = "amount=" *digit [ "." *digit ]
4853
labelparam = "label=" *qchar
4954
messageparam = "message=" *qchar
55+
responseparam = [ "req-" ] "pop=" *qchar
5056
otherparam = qchar *qchar [ "=" *qchar ]
5157
reqparam = "req-" qchar *qchar [ "=" *qchar ]
5258
5359
Here, "qchar" corresponds to valid characters of an RFC 3986 URI query component, excluding the "=" and "&" characters, which this BIP takes as separators.
5460

55-
The scheme component ("bitcoin:") is case-insensitive, and implementations must accept any combination of uppercase and lowercase letters. The rest of the URI is case-sensitive, including the query parameter keys.
61+
The scheme component ("bitcoin:") is case-insensitive, and implementations must accept any combination of uppercase and lowercase letters. The query parameter keys are also case-insensitive. Query parameter values and bitcoin address fields may be case-sensitive depending on their content.
62+
63+
Multiple query parameters with the same key MAY be included for query parameters representing payment instructions. Multiple query parameters with the same key MUST NOT be included for keys "label", "message", or "pop". Multiple query parameters with the same key for other keys MUST be allowed for unknown query parameters. Future query parameter keys may or may not allow for duplicate parameters.
64+
65+
=== Bitcoin Address ===
66+
67+
The bitcoinaddress body MUST be either a base58 P2SH or P2PKH address, bech32 Segwit version 0 address, bech32m Segwit address, or empty. Future address formats SHOULD instead be placed in query keys as optional payment instructions to provide backwards compatibility during upgrade cycles. The bitcoinaddress part of the URI MAY be left empty if there is at least one payment instruction provided in a query parameter, allowing for recipients wishing to avoid a standard on-chain fallback.
5668

5769
=== Query Keys ===
5870

59-
*label: Label for that address (e.g. name of receiver)
60-
*address: bitcoin address
71+
The following keys are defined generally and apply to any URI regardless of payment instructions:
72+
73+
*label: Label for the recipient (e.g. name of receiver)
6174
*message: message that describes the transaction to the user ([[#Examples|see examples below]])
62-
*(others): optional, for future extensions
75+
*pop: a URI which the Bitcoin Wallet may return to in order to provide the application which initiated the payment with proof that a payment was completed.
76+
77+
The following keys are currently defined for payment instructions of various forms:
78+
79+
*lightning: Lightning BOLT 11 invoices
80+
*lno: Lightning BOLT12 offers
81+
*pay: [[bip-0351.mediawiki|BIP 351 Private Payment addresses]]
82+
*sp: [[bip-0352.mediawiki|BIP 352 Silent Payment addresses]]
83+
84+
New payment instructions using bech32 or bech32m encodings SHOULD reuse their address format's Human Readable Part as the parameter key.
6385

6486
==== Transfer amount ====
6587

6688
If an amount is provided, it MUST be specified in decimal BTC.
6789
All amounts MUST contain no commas and use a period (.) as the separating character to separate whole numbers and decimal fractions.
6890
I.e. amount=50.00 or amount=50 is treated as 50 BTC, and amount=50,000.00 is invalid.
6991

70-
Bitcoin clients MAY display the amount in any format that is not intended to deceive the user.
71-
They SHOULD choose a format that is foremost least confusing, and only after that most reasonable given the amount requested.
72-
For example, so long as the majority of users work in BTC units, values should always be displayed in BTC by default, even if mBTC or TBC would otherwise be a more logical interpretation of the amount.
92+
=== Proof of Payment ===
93+
94+
The URI MAY include a "pop" (or "req-pop") parameter whose value can be used to build a URI which the wallet application can, after payment completes, "open" to provide proof the payment was completed or other information about the payment.
95+
96+
The value of a "pop" (or "req-pop") parameter shall be a percent-encoded (per RFC 3986 section 2.1) URI prefix. The wallet application, if it supports providing payment information SHOULD percent-decode the provided URI once, append the query parameter key from which the payment instructions used were read, append a single =, and finally append the Payment Information to the resulting URI and open it with the default system handler for the URI. For payment instructions read from the body of the URI, "onchain" SHALL be used in place of the key.
97+
98+
A wallet MUST validate that the provided URI's scheme is not (case-insensitive) "http", "https", "file", "javascript", "mailto" or any other scheme which will open in a web browser prior to opening it.
99+
100+
If a wallet will not open the pop scheme (either because it does not support returning payment information for the selected payment method or because it uses a URI scheme which should not be opened) and the parameter was passed as a "req-pop" parameter, the wallet MUST NOT initiate payment.
101+
102+
For payments made using an on-chain transaction, the Payment Information shall be the full (including witness data) Bitcoin transaction as it was broadcasted to the Bitcoin network, encoded in hex.
103+
104+
For payments made using a BOLT 11 invoice (communicated via the `lightning` parameter), the Payment Information shall be the hex-encoded payment preimage.
105+
106+
Other payment schemes will define their own Payment Information format. This BIP may be updated from time to time with Payment Information formats for other payment schemes.
107+
73108
== Rationale ==
74109

75-
===Payment identifiers, not person identifiers===
76-
Current best practices are that a unique address should be used for every transaction.
77-
Therefore, a URI scheme should not represent an exchange of personal information, but a one-time payment.
110+
=== Payment identifiers, not person identifiers ===
78111

79-
===Accessibility (URI scheme name)===
80-
Should someone from the outside happen to see such a URI, the URI scheme name already gives a description.
81-
A quick search should then do the rest to help them find the resources needed to make their payment.
82-
Other proposed names sound much more cryptic; the chance that someone googles that out of curiosity are much slimmer.
83-
Also, very likely, what he will find are mostly technical specifications - not the best introduction to bitcoin.
112+
Best practices are that a unique address should be used for every transaction on-chain.
113+
Therefore, a URI which contains an on-chain payment address MUST NOT represent an exchange of personal information, but a one-time payment instruction. URIs which represent only reusable non-address-reusing payment instructions (like Lightning BOLT12 offers or Silent Payments) MAY be reused as a wallet sees fit.
84114

85-
==Forward compatibility==
86-
Variables which are prefixed with a req- are considered required. If a client does not implement any variables which are prefixed with req-, it MUST consider the entire URI invalid. Any other variables which are not implemented, but which are not prefixed with a req-, can be safely ignored.
115+
=== Proof of Payment ===
87116

88-
==Backward compatibility==
89-
As this BIP is written, several clients already implement a bitcoin: URI scheme similar to this one, however usually without the additional "req-" prefix requirement. Thus, it is recommended that additional variables prefixed with req- not be used in a mission-critical way until a grace period of 6 months from the finalization of this BIP has passed in order to allow client developers to release new versions, and users of old clients to upgrade.
117+
On many mobile operating systems (especially, or any operating system more generally), applications may "open" a bitcoin: URI in order to initiate a payment with the user's default wallet application. These payment-initiating applications may wish to learn about the completed payment.
90118

91-
== Appendix ==
119+
For payments completed on-chain, this is largely addressed by having the payment-initiating application monitor the blockchain for payment completion, however for other payment schemes (e.g. lightning), no such global ledger of transactions exists. In that case, proof of payment must be provided via some other mechanism.
120+
121+
In order to avoid inadvertently revealing the sender's IP address or other information to the recipient, proof URIs must only be opened when they will simply switch to another locally-installed application (i.e. the application which initiated the payment). When clicking a URI from a website, the website should already have plenty of logic on its backend to process payment completion and a proof-of-payment callback is unnecessary.
122+
123+
== Forward compatibility ==
124+
125+
Query parameter keys which are prefixed with a req- are considered required. If a client does not implement handling a query parameter which has a key prefixed with req-, it MUST consider the entire URI invalid. Any other query parameters which are not implemented, but which are not prefixed with a req-, can be safely ignored.
92126

93-
=== Simpler syntax ===
127+
As future new address types should be added using query parameters rather than the `bitcoinaddress` field, URIs seamlessly support various payment instructions while senders only need to support legacy instructions. This allows old senders to pay newer recipients which offer more modern payment instruction formats.
94128

95-
This section is non-normative and does not cover all possible syntax.
96-
Please see the BNF grammar above for the normative syntax.
129+
== Backward compatibility ==
97130

98-
[foo] means optional, &lt;bar&gt; are placeholders
131+
Compared to BIP 21, this document describes standard query parameters containing payment instructions, makes query parameters case-insensitive, allows bech32 and bech32m addresses in the `bitcoinaddress` field, and allows for URIs with an empty `bitcoinaddress` field. Use of bech32 and bech32m `bitcoinaddress` fields were long-since common practice in 2024, and the `lightning` query parameter storing BOLT 11 payment instructions became common practice in the year or three leading up to 2024. Inclusion of standard query parameters was added to provide guidance on query parameter usage going forward.
99132

100-
<nowiki>bitcoin:<address>[?amount=<amount>][?label=<label>][?message=<message>]</nowiki>
133+
Additionally, this BIP describes the "pop" query parameter, which was unused and will be ignored by BIP 21 implementations.
134+
135+
Any existing BIP 21 implementation should automatically be fully compliant with this BIP, as the changes only describe existing practice or impact future address format inclusion, with the one possible exception of query parameters being made case-insensitive. Note, however, that treating query parameters as case-insensitive is already common practice due to the use of mostly-uppercase URIs in QR codes.
136+
137+
== Appendix ==
101138

102139
=== Examples ===
103140

141+
==== URIs ====
142+
104143
Just the address:
105144
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W
106145

107-
Address with name:
146+
Address with recipient's name as label:
108147
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Luke-Jr
109148

110149
Request 20.30 BTC to "Luke-Jr":
111150
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=20.3&label=Luke-Jr
112151

152+
Address with recipient's name as label:
153+
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Luke-Jr
154+
113155
Request 50 BTC with message:
114156
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=50&label=Luke-Jr&message=Donation%20for%20project%20xyz
115157

158+
Request funds to be paid over lightning to a BOLT 11 invoice with a fallback to on-chain payments:
159+
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?lightning=lnbc420bogusinvoice
160+
161+
Request funds to be paid over lightning to a BOLT 11 invoice with no fallback:
162+
bitcoin:?lightning=lnbc420bogusinvoice
163+
164+
Request funds to be paid over lightning to a BOLT 12 offer with no fallback:
165+
bitcoin:?lno=lno1bogusoffer
166+
167+
Request funds to be paid over lightning to a BOLT 12 offer or silent payments address with no fallback:
168+
bitcoin:?lno=lno1bogusoffer&sp=sp1qsilentpayment
169+
170+
Request funds to be paid to a silent payments address with no fallback:
171+
bitcoin:?sp=sp1qsilentpayment
172+
173+
Request funds to be paid to a silent payments address with a fallback:
174+
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?sp=sp1qsilentpayment
175+
116176
Some future version that has variables which are (currently) not understood and required and thus invalid:
117177
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-somethingyoudontunderstand=50&req-somethingelseyoudontget=999
118178

119179
Some future version that has variables which are (currently) not understood but not required and thus valid:
120180
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?somethingyoudontunderstand=50&somethingelseyoudontget=999
121181

182+
Multiple segwit addresses may be included for various versions of segwit, note that the human-readable part for all of them is `bc`
183+
bitcoin:?bc=bc1qufgy354j3kmvuch987xe4s40836x3h0lg8f5n2&bc=bc1p5swkugezn97763tl0yty6556856uug0q6jflljvep9m4p7339x5qzyrh4g
184+
185+
Many QR codes utilize all-uppercase URIs, which should be handled fine
186+
BITCOIN:BC1QUFGY354J3KMVUCH987XE4S40836X3H0LG8F5N2?BC=BC1P5SWKUGEZN97763TL0YTY6556856UUG0Q6JFLLJVEP9M4P7339X5QZYRH4G
187+
BITCOIN:?BC=BC1QUFGY354J3KMVUCH987XE4S40836X3H0LG8F5N2&BC=BC1P5SWKUGEZN97763TL0YTY6556856UUG0Q6JFLLJVEP9M4P7339X5QZYRH4G
188+
189+
A testnet segwit addresses must be included in the `tb` parameter
190+
bitcoin:?tb=tb1qghfhmd4zh7ncpmxl3qzhmq566jk8ckq4gafnmg
191+
122192
Characters must be URI encoded properly.
123193

124-
== Reference Implementations ==
125-
=== Bitcoin clients ===
126-
* Bitcoin-Qt supports the old version of Bitcoin URIs (ie without the req- prefix), with Windows and KDE integration as of commit 70f55355e29c8e45b607e782c5d76609d23cc858.
194+
==== Invalid URIs ====
195+
196+
Labels must not appear twice:
197+
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Luke-Jr&label=Matt
198+
199+
Amounts must not appear twice:
200+
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=42&amount=10
201+
202+
Amounts must not appear twice even if they are the same:
203+
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=42&amount=42
204+
205+
Multiple proof of payment URIs must not appear, even if they are sometimes prefixed with req-:
206+
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?pop=callback%3a&req-pop=callback%3a
207+
208+
A testnet segwit addresses must be included in the `tb` parameter, not the `bc` parameter.
209+
bitcoin:?bc=tb1qghfhmd4zh7ncpmxl3qzhmq566jk8ckq4gafnmg
210+
211+
==== Proof of Payment ====
212+
213+
If the original URI is
214+
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?pop=initiatingapp%3a
215+
the wallet should perform the payment information callback by opening
216+
initiatingapp:onchain=$HEX_ENCODED_TRANSACTION
217+
218+
If the original URI is
219+
bitcoin:?lightning=lnbc420bogusinvoice&pop=callbackuri%3abody%3fpop=
220+
the wallet should perform the proof-of-payment callback by opening
221+
callbackuri:body?pop=lightning=$HEX_ENCODED_PAYMENT_PREIMAGE
222+
223+
If the original URI is
224+
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?lightning=lnbc420bogusinvoice&pop=app%3a%3f
225+
and the wallet pays on-chain, it should perform the payment information callback by opening
226+
app:?onchain=$HEX_ENCODED_TRANSACTION
227+
but if the app pays using lightning, it should perform the proof-of-payment callback by opening
228+
app:?lightning=$HEX_ENCODED_PAYMENT_PREIMAGE
229+
230+
If the original URI is
231+
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?pop=https%3aiwantyouripaddress.com
232+
the wallet should make a payment as it normally would but MUST NOT interact with iwantyouripaddress.com
127233

128-
=== Libraries ===
129-
* Javascript - https://github.com/bitcoinjs/bip21
130-
* Java - https://github.com/SandroMachado/BitcoinPaymentURI
131-
* Swift - https://github.com/SandroMachado/BitcoinPaymentURISwift
234+
If the original URI is
235+
bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-pop=https%3aevilwebsite.com
236+
the wallet MUST NOT make a payment

0 commit comments

Comments
 (0)