diff options
author | Kalle Rosenbaum <kalle@rosenbaum.se> | 2015-07-28 22:41:35 +0200 |
---|---|---|
committer | Kalle Rosenbaum <kalle@rosenbaum.se> | 2015-07-28 22:41:35 +0200 |
commit | 4b6ee39ced3c6d838cee1827a5585620f7e188f5 (patch) | |
tree | b7b51484751f582feb8508f882590921936ffc71 | |
parent | 21c2ad6dbdd627aa0bcf864e1150a92e10990872 (diff) | |
download | bips-4b6ee39ced3c6d838cee1827a5585620f7e188f5.tar.xz |
Added BIP0120 and BIP0121
-rw-r--r-- | README.mediawiki | 12 | ||||
-rw-r--r-- | bip-0120.mediawiki | 152 | ||||
-rw-r--r-- | bip-0121.mediawiki | 146 |
3 files changed, 310 insertions, 0 deletions
diff --git a/README.mediawiki b/README.mediawiki index bcf13de..d11597d 100644 --- a/README.mediawiki +++ b/README.mediawiki @@ -283,6 +283,18 @@ Those proposing changes should consider that ultimately consent may rest with th | Stephen Pair | Standard | Draft +|- +| [[bip-0120.mediawiki|120]] +| Proof of Payment +| Kalle Rosenbaum +| Standard +| Draft +|- +| [[bip-0121.mediawiki|121]] +| Proof of Payment URI scheme +| Kalle Rosenbaum +| Standard +| Draft |} <!-- IMPORTANT! See the instructions at the top of this page, do NOT JUST add BIPs here! --> diff --git a/bip-0120.mediawiki b/bip-0120.mediawiki new file mode 100644 index 0000000..4fabbb8 --- /dev/null +++ b/bip-0120.mediawiki @@ -0,0 +1,152 @@ +<pre> + BIP: 120 + Title: Proof of Payment + Author: Kalle Rosenbaum <kalle@rosenbaum.se> + Status: Draft + Type: Standards Track + Created: 2015-07-28 +</pre> + +== Abstract == + +This BIP describes a system called Proof of Payment, PoP. It is used to prove that a wallet has the credentials that were used to sign a previously generated transaction. Or simply put, it lets you prove that you have made a payment. + +== Motivation == + +There are several scenarios in which it would be useful to prove that you have paid for something. For example: + +* A pre-paid hotel room where your PoP functions as a key to the door. +* An online video rental service where you pay for a video and watch it on any device. +* An ad-sign where you pay in advance for e.g. 2 weeks exclusivity. During this period you can upload new content to the sign whenever you like using PoP. +* Log in to a pay site using a PoP. +* A parking lot you pay for monthly and the car authenticates itself using PoP. +* A lottery where all participants pay to the same address, and the winner is selected among the transactions to that address. You exchange the prize for a PoP for the winning transaction. + +With Proof of Payment, these use cases can be achieved without any personal information (user name, password, e-mail address, etc) being involved. + +== Rationale == + +Desirable properties: + +# A PoP should be generated on demand. +# It should only be usable once to avoid issues due to theft. +# It should be able to create a PoP for any payment, regardless of script type (P2SH, P2PKH, etc.). +# It should prove that you have enough credentials to unlock all the inputs of the proven transaction. +# It should be easy to implement by wallets and servers to ease adoption. + +Current methods of proving a payment: + +* In BIP0070, the PaymentRequest together with the transactions fulfilling the request makes some sort of proof. However, it does not meet 1, 2 or 4 and it obviously only meets 3 if the payment is made through BIP0070. Also, there's no standard way to request/provide the proof. If standardized it would probably meet 5. +* Signing messages, chosen by the server, with the private keys used to sign the transaction. This could meet 1 and 2 but probably not 3. This is not standardized either. 4 Could be met if designed so. + +If an input script type is P2SH, any satisfying script should do, just as if it was a payment. For M-of-N multisig scripts, that would mean that any set of M keys should be sufficient, not neccesarily the same set of M keys that signed the transaction. This is important because strictly demanding the same set of M keys would defeat the purpose of a multisig address. + +== Specification == + +=== Data structure === + +A proof of payment for a transaction T, here called PoP(T), is used to prove that one has ownership of the credentials needed to unlock all the inputs of T. It has the exact same structure as a bitcoin transaction with the same inputs as T and in the same order as in T, but with each sequence number set to 0. There is exactly one output, here called the pop output, with value 0. The pop output must have the following format: + + OP_RETURN <version> <txid> <nonce> + +{| +! Field !! Size [B] !! Description +|- +| <version> || 2 || Version, little endian, currently 0x01 0x00 +|- +| <txid> || 32 || The transaction to prove +|- +| <nonce> || 6 || Random data +|} + +The lock_time of the PoP must be set to 499999999 to prevent the PoP from being included in a block, should it appear on the bitcoin p2p network. This is also the reason for setting the sequence numbers to 0, since sequence number of ffffffff would make lock_time ineffective. This specification demands that all input sequence numbers are 0, not just one of them, which would be sufficient to make lock_time effective. This is for simplicity reasons. + +An illustration of the PoP data structure and its original payment is shown below. + +<pre> + T + +------------------------------------------------+ + |inputs | outputs | + | Value,Sequence | Value,Script | + +------------------------------------------------+ + |input0 1,ffffffff | 0,pay to A | + |input1 3,ffffffff | 2,OP_RETURN <some data> | + |input2 4,ffffffff | 1,pay to B | + | | 4,pay to C | + +------------------------------------------------+ + + PoP(T) + +-------------------------------------------------------------+ + | inputs | outputs | + | Value,Sequence | Value,Script | + +-------------------------------------------------------------+ + |input0 1,00000000 | 0,OP_RETURN <version> <txid> <nonce> | + |input1 3,00000000 | | + |input2 4,00000000 | | + +-------------------------------------------------------------+ + | lock_time=499999999 | + +-------------------------------------------------------------+ +</pre> + +The PoP is signed using the same signing process that is used for bitcoin transactions. + +The purpose of the nonce is to make it harder to use a stolen PoP; Once the PoP has reached the server, that PoP is useless since the server will generate a new nonce for every PoP request. + +=== Process === + +# A proof of payment request is sent from the server to the wallet. The PoP request contains: +## a random nonce +## a destination where to send the PoP, for example a https URL +## data hinting the wallet which transaction to create a proof for. For example: +##* txid, if known by the server +##* PaymentRequest.PaymentDetails.merchant_data (in case of a BIP0070 payment) +##* amount, label, message or other information from a BIP0021 URI +# The wallet identifies a transaction T, if possible. Otherwise it asks the user to select among the ones that match the hints in 1.iii. +# The wallet creates an unsigned PoP (UPoP) for T, and asks the user to sign it. +# The user confirms +# The UPoP(T) is signed by the wallet, creating PoP(T). +# The PoP is sent to the destination in 1.ii. +# The server receiving the PoP validates it and responds with “valid” or “invalid”. +# The wallet displays the response in some way to the user. + +'''Remarks:''' + +* The method of transferring the PoP request at step 1 is not specified here. Instead that is specified in separate specifications. See [btcpop scheme BIP](btcpop scheme BIP). +* The nonce must be randomly generated by the server for every new PoP request. + +=== Validating a PoP === + +The server needs to validate the PoP and reply with "valid" or "invalid". That process is outlined below. If any step fails, the validation is aborted and "invalid" is returned: + +# Check the format of the PoP. It must pass normal transaction checks, except that the inputs may already be spent. +# Check that lock_time is 499999999. +# Check that there is exactly one output. This output must have value 0 and conform to the OP_RETURN output format outlined above. +# Check that the nonce is the same as the one requested. +# Check that the inputs of the PoP are exactly the same as in transaction T, except that the sequence numbers must all be 0. The ordering of the inputs must also be the same as in T. +# Run the scripts of all the inputs. All scipts must return true. +# Check that the txid in the PoP output is the transaction you actually want proof for. If you don’t know exactly what transaction you want proof for, check that the transaction actually pays for the product/service you deliver. +# Return "valid". + +== Security considerations == + +* Someone can intercept the PoP-request and change any parameter in it. These can be mitigated by using secure connections. Examples of tampered parameters: +** Pop destination - Stealing your PoP. +** label - Trick you to sign an unintended pop or set a label that your wallet doesn't have any record for, resulting in a broken service. Always check the PoP before signing. +** nonce - Your pop will not validate on server. +* Someone can steal a PoP, for example by tampering with the PoP request, and try to use the service hoping to get a matching nonce. Probability per try: 1/(2^48). The server should have a mechanism for detecting a brute force attack of this kind, or at least slow down the process by delaying the PoP request by some 100 ms or so. +* Even if a wallet has no funds it might still be valuable as a generator for PoPs. This makes it important to keep the security of the wallet after it has been emptied. +* Transaction malleability may cause the server to have another transaction id for a payment than the client's wallet. In that case the wallet will not be able to prove the transaction to the server. Wallets should not rely on the transaction id of the outgoing transaction. Instead it should listen for the transaction on the network and put that in its list of transactions. + +== Reference implementation == + +[https://github.com/kallerosenbaum/poppoc PoP Demo server on GitHub] + +[https://github.com/kallerosenbaum/wallet PoP-enabled Mycelium fork on GitHub] + +== References == + +[https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki BIP0021]: URI Scheme + +[https://github.com/bitcoin/bips/blob/master/bip-0070.mediawiki BIP0070]: Payment Protocol + +[https://github.com/bitcoin/bips/blob/master/bip-0121.mediawiki BIP0121]: Proof of Payment URI scheme diff --git a/bip-0121.mediawiki b/bip-0121.mediawiki new file mode 100644 index 0000000..a8ed013 --- /dev/null +++ b/bip-0121.mediawiki @@ -0,0 +1,146 @@ +<pre> + BIP: 121 + Title: Proof of Payment URI scheme + Author: Kalle Rosenbaum <kalle@rosenbaum.se> + Status: Draft + Type: Standards Track + Created: 2015-07-27 +</pre> + +== Abstract == + +This is a proposal for a URI scheme to be used in the Proof of Payment +process. + +== Motivation == + +To make a Proof of Payment, the party that wants the proof needs to +transfer a Proof of Payment request to the wallet software of the +other party. To facilitate that transfer, a new URI scheme +representing the PoP request is proposed. This URI can then be encoded +in QR images or be sent over NFC in order to transfer it to the wallet. + +== Specification == + +The specification is the same as BIP0021, with the following +differences: + +* The URI scheme is <tt>btcpop</tt> instead of <tt>bitcoin</tt> +* The path component, i.e. the address part, is always empty. +* A mandatory <tt>p</tt> parameter whose value contains the destination for the PoP. This could for example be a <tt>https:</tt> URL or a <tt>mailto:</tt> URI. +* A mandatory <tt>n</tt> parameter representing the nonce, base58 encoded. +* An optional <tt>txid</tt> parameter containing the Base58 encoded hash of the transaction to prove. + +Just as in BIP0021, elements of the query component may contain +characters outside the valid range. These must first be encoded +according to UTF-8, and then each octet of the corresponding UTF-8 +sequence must be percent-encoded as described in RFC 3986. + +All parameters except <tt>p</tt> and <tt>n</tt> are hints to the +wallet on which transaction to create a PoP for. + +The extensibility of BIP0021 applies to this scheme as well. For +example, a <tt>date</tt> parameter or a <tt>toaddr</tt> parameter +might be useful. <tt>req-*</tt> parameters are also allowed and obey +the same rules as in BIP0021, clients not supporting a <tt>req-*</tt> +parameter must consider the URI invalid. + +=== Keep URIs short === + +Implementations should keep the URIs as short as possible. This is +because it makes QR decoding more stable. A camera with a scratched +lens or low resolution may run into problems scanning huge QR +codes. This is why the <tt>txid</tt> parameter is encoded in Base58 +instead of the classic hex encoded string. We get away with 44 +characters instead of 64. Also, the <tt>nonce</tt> parameter is Base58 +encoded for the same reason. + +== Interpretation == + +=== Transaction hints === + +The wallet processing the URI must use the hints in the PoP request to +filter its transaction set. The <tt>label</tt>, <tt>amount</tt> and +<tt>message</tt> parameters must, if present in the URI, exactly match +the data associated with the original payment according to the +following table: + +{| +| <tt>btcpop:</tt> URI parameter || <tt>bitcoin:</tt> URI parameter || BIP70 PaymentDetails data +|- +| <tt>label</tt> || <tt>label</tt> || <tt>merchant_data</tt> +|- +| <tt>amount</tt> || <tt>amount</tt> || <tt>sum of outputs.amount</tt> +|- +| <tt>message</tt> || <tt>message</tt> || <tt>memo</tt> +|} + +The <tt>txid</tt> parameter value must match the transaction hash of +the payment. + +After filtering, the resulting transaction set is displayed to the +user who selects one of them to prove. An implementation could also +automatically select a transaction in the filtered set, but +there must still be a way for the user to select freely among the +matching transactions. If the filtered set is empty, no transaction +fits the hints and a message about that is presented to the user. If +the filtered set contains exactly one transaction, which is +preferable, that transaction can be automatically selected. + +As a fallback, there must also be a way for the user to select any +transaction from the wallet regardless of the transaction hints. This +can be useful if the metadata of the wallet is lost, possibly due to a +restore from backup. + +=== PoP destination <tt>p</tt> === + +The <tt>p</tt> parameter value is the destination where to send the +PoP to. This destination is typically a <tt>https:</tt> URL or a +<tt>http:</tt> URL, but it could be any type of URI, for example +<tt>mailto:</tt>. To keep <tt>btcpop:</tt> URIs short, users should +not make their <tt>p</tt> parameter unneccesarily long. + +==== <tt>http:</tt> and <tt>https:</tt> URLs ==== + +Wallet implementations must support the <tt>http:</tt> and +<tt>https:</tt> schemes in which case <tt>POST</tt> method must be +used. The content type of the POST request must be set to + + Content-Type: application/bitcoin-pop + Content-Transfer-Encoding: binary + +== Examples == + +Send PoP for a transaction with label "video 42923" to +<tt><nowiki>https://www.example.com/pop/352</nowiki></tt>, using nonce +<tt>0x73 0xd5 0x1a 0xbb 0xd8 0x9c</tt>: +<pre> + btcpop:?p=https://www.example.com/pop/352&n=zgWTm8yH&label=video 42923 +</pre> +Send PoP through mail using +<tt><nowiki>mailto:pop@example.com?subject=pop444</nowiki></tt>, amount +is 13370000 satoshis, nonce is <tt>0x6f 0xe 0xfb 0x68 0x92 0xf9</tt>. +Note that the <tt>?</tt> before <tt>subject</tt> is OK according to RFC3986, +since the query part starts from the first <tt>?</tt>: +<pre> + btcpop:?p=mailto:pop@example.com?subject%3Dpop444&n=xJdKmEbr&amount=0.1337 +</pre> +Send PoP for transaction with id +<tt>cca7507897abc89628f450e8b1e0c6fca4ec3f7b34cccf55f3f531c659ff4d79</tt> +to pizza place at <tt><nowiki>http://pizza.example.com/pop/laszlo111</nowiki></tt> using nonce <tt>0xfc 0xcc 0x2c 0x35 0xf0 0xb8</tt> +<pre> + btcpop:?p=http://pizza.example.com/pop/laszlo111&n=3AtNpVrPh&txid=Emt9MPvt1joznqHy5eEHkNtcuQuYWXzYJBQZN6BJm6NL +</pre> +== Reference implementation == + +[https://github.com/kallerosenbaum/poppoc PoP Demo server on GitHub] + +[https://github.com/kallerosenbaum/wallet PoP-enabled Mycelium fork on GitHub] + +== References == + +[https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki BIP0021]: URI Scheme + +[https://github.com/bitcoin/bips/blob/master/bip-0120.mediawiki BIP0120]: Proof of Payment + +[https://www.ietf.org/rfc/rfc3986.txt RFC3986]: Uniform Resource Identifier (URI): Generic Syntax |