BIP 0020: Difference between revisions

From Bitcoin Wiki
Jump to navigation Jump to search
Tcatm (talk | contribs)
amount is optional
Luke-jr (talk | contribs)
Sanitize default base exponents (X8 for decimal, X4 for hexadecimal)
Line 31: Line 31:
The '''fragment''' is an optional part separated from the front parts by a hash ("#"). It holds additional identifying information that provides direction to a secondary resource, e.g. a section heading in an article identified by the remainder of the URI.  When the primary resource is an HTML document, the '''fragment''' is often an <code>id</code> attribute of a specific element and web browsers will make sure this element is visible.
The '''fragment''' is an optional part separated from the front parts by a hash ("#"). It holds additional identifying information that provides direction to a secondary resource, e.g. a section heading in an article identified by the remainder of the URI.  When the primary resource is an HTML document, the '''fragment''' is often an <code>id</code> attribute of a specific element and web browsers will make sure this element is visible.


==tcatm, modified by LukeJr==
==tcatm & Luke-Jr==
 
I propose a scheme like this:


[] means optional, <> are placeholders
[] means optional, <> are placeholders
Line 44: Line 42:
*address: bitcoin address
*address: bitcoin address
*message: optional message that is shown to the user after scanning the QR code
*message: optional message that is shown to the user after scanning the QR code
*size: amount of base bitcoin units (uBTCents/TBCᵇ-- NOT full DecimalBitCoins/BTC); this number can be prefixed with the letter "x" to signify a hexadecimal number; it can be appended with "X" <digits> to signify an exponent to the base multiplier (that is, 'X8' moves your number 8 positional places to the left-- if specifying decimal units (without an "x" prefix), this means the standard BTC unit; if specifying hexadecimal units (with an "x" prefix), this means ᵇTBC units). If exponent is omitted, X8 is assumet. I.e. amount=50.00 is 50 BTC. Use X0 to specify bitcoin base units.
*size: amount of base bitcoin units (uBTCents/TBCᵇ-- NOT full DecimalBitCoins/BTC); this number can be prefixed with the letter "x" to signify a hexadecimal number; it can be appended with "X" <digits> to signify an exponent to the base multiplier (that is, 'X8' moves your number 8 positional places to the left-- if specifying decimal units (without an "x" prefix), this means the standard BTC unit; if specifying hexadecimal units (with an "x" prefix), this means ᵇTBC units). If exponent is omitted, X8 is assumed for decimal numbers, and X4 for hexadecimal numbers. I.e. amount=50.00 is 50 BTC. Use X0 to specify bitcoin base units.


=== Examples ===
=== Examples ===
Line 55: Line 53:


Request to send 20.30 BTC to Luke-Jr:
Request to send 20.30 BTC to Luke-Jr:
  bitcoin:1KczVqwopWXQdFLe5sNQbpCq7yGSmXx2oo?amount=20.3X8&label=Luke-Jr
  bitcoin:1KczVqwopWXQdFLe5sNQbpCq7yGSmXx2oo?amount=20.3&label=Luke-Jr


Request to send 400 TBC to Luke:
Request to send 400 TBC to Luke:
  bitcoin:1KczVqwopWXQdFLe5sNQbpCq7yGSmXx2oo?amount=x400X4
  bitcoin:1KczVqwopWXQdFLe5sNQbpCq7yGSmXx2oo?amount=x400
 
Request to send 4000 TBC to Luke:
bitcoin:1KczVqwopWXQdFLe5sNQbpCq7yGSmXx2oo?amount=x4X7


Request to send 5 uBTC:
Request to send 5 uBTC:
  bitcoin:1KczVqwopWXQdFLe5sNQbpCq7yGSmXx2oo?amount=500
  bitcoin:1KczVqwopWXQdFLe5sNQbpCq7yGSmXx2oo?amount=500X0


Request to send 50 BTC with message:
Request to send 50 BTC with message:
Line 92: Line 93:
  (m[7] ? (parseInt(m[7], 16) * Math.pow(16, -(m[7].length))) : 0)
  (m[7] ? (parseInt(m[7], 16) * Math.pow(16, -(m[7].length))) : 0)
  ) * (
  ) * (
  m[9] ? Math.pow(16, parseInt(m[9], 16)) : 1e8
  m[9] ? Math.pow(16, parseInt(m[9], 16)) : 0x10000
  )
  )
  ) : (
  ) : (

Revision as of 00:55, 13 January 2011

This is about creating a URI scheme for bitcoin. Previous discussion in the forum http://www.bitcoin.org/smf/index.php?topic=55.0 x-btc specification at x-btc

RFC 3986

the following is taken from wikipedia

Internet standard STD 66 (also RFC 3986) defines the generic syntax to be used in all URI schemes. Every URI is defined as consisting of four parts, as follows:

<scheme name> : <hierarchical part> [ ? <query> ] [ # <fragment> ]

The scheme name consists of a letter followed by any combination of letters, digits, and the plus ("+"), period ("."), or hyphen ("-") characters; and is terminated by a colon (":").

The hierarchical part of the URI is intended to hold identification information hierarchical in nature. Usually this part begins with a double forward slash ("//"), followed by an authority part and an optional path.

  • The authority part holds an optional user information part terminated with "@" (e.g. username:password@), a hostname (i.e. domain name or IP address), and an optional port number preceded by a colon ":".
  • The path part is a sequence of segments (conceptually similar to directories, though not necessarily representing them) separated by a forward slash ("/"). Each segment can contain parameters separated from it using a semicolon (";"), though this is rarely used in practice.

The query is an optional part separated with a question mark, which contains additional identification information which is not hierarchical in nature. The query string syntax is not generically defined, but is commonly organized as a sequence of <key>=<value> pairs separated by a semicolon[1][2][3] or separated by an ampersand, for example:

Semicolon: key1=value1;key2=value2;key3=value3
Ampersand: key1=value1&key2=value2&key3=value3

The fragment is an optional part separated from the front parts by a hash ("#"). It holds additional identifying information that provides direction to a secondary resource, e.g. a section heading in an article identified by the remainder of the URI. When the primary resource is an HTML document, the fragment is often an id attribute of a specific element and web browsers will make sure this element is visible.

tcatm & Luke-Jr

[] means optional, <> are placeholders

bitcoin:<address>[?amount=<size>][&label=<label>][&message=<message>]

Variables

  • label: Label for that address (e.g. name of receiver)
  • address: bitcoin address
  • message: optional message that is shown to the user after scanning the QR code
  • size: amount of base bitcoin units (uBTCents/TBCᵇ-- NOT full DecimalBitCoins/BTC); this number can be prefixed with the letter "x" to signify a hexadecimal number; it can be appended with "X" <digits> to signify an exponent to the base multiplier (that is, 'X8' moves your number 8 positional places to the left-- if specifying decimal units (without an "x" prefix), this means the standard BTC unit; if specifying hexadecimal units (with an "x" prefix), this means ᵇTBC units). If exponent is omitted, X8 is assumed for decimal numbers, and X4 for hexadecimal numbers. I.e. amount=50.00 is 50 BTC. Use X0 to specify bitcoin base units.

Examples

Just the address:

bitcoin:1KczVqwopWXQdFLe5sNQbpCq7yGSmXx2oo

Address with name:

bitcoin:1KczVqwopWXQdFLe5sNQbpCq7yGSmXx2oo?label=Luke-Jr

Request to send 20.30 BTC to Luke-Jr:

bitcoin:1KczVqwopWXQdFLe5sNQbpCq7yGSmXx2oo?amount=20.3&label=Luke-Jr

Request to send 400 TBC to Luke:

bitcoin:1KczVqwopWXQdFLe5sNQbpCq7yGSmXx2oo?amount=x400

Request to send 4000 TBC to Luke:

bitcoin:1KczVqwopWXQdFLe5sNQbpCq7yGSmXx2oo?amount=x4X7

Request to send 5 uBTC:

bitcoin:1KczVqwopWXQdFLe5sNQbpCq7yGSmXx2oo?amount=500X0

Request to send 50 BTC with message:

bitcoin:1KczVqwopWXQdFLe5sNQbpCq7yGSmXx2oo?amount=5X9&label=Luke-Jr&message=Donation%20for%20project%20xyz

Characters must be URI encoded properly.

BNF syntax

bitcoinurn      = "bitcoin:" bitcoinaddress [ ";version=" bitcoinversion ] [ "?" bitcoinparams ]
bitcoinaddress  = FIXME :)
bitcoinversion  = "1.0"
bitcoinparams   = *bitcoinparam
bitcoinparam    = amountparam | labelparam | messageparam
amountparam     = "amount=" amount
amount          = amountdecimal | amounthex
amountdecimal   = digits [ "X" digits ]
amounthex       = "x" hexdigits [ "X" hexdigits ]
labelparam      = "label=" *uchar
messageparam    = "label=" *uchar

Parsing amount

ECMAScript

reAmount = /^(([\d.]+)(X(\d+))?|x([\da-f]*)(\.([\da-f]*))?(X([\da-f]+))?)$/i;
function parseAmount(txt) {
	var m = txt.match(reAmount);
	return m[5] ? (
		(
			parseInt(m[5], 16) +
			(m[7] ? (parseInt(m[7], 16) * Math.pow(16, -(m[7].length))) : 0)
		) * (
			m[9] ? Math.pow(16, parseInt(m[9], 16)) : 0x10000
		)
	) : (
			m[2]
		*
			(m[4] ? Math.pow(10, m[4]) : 1e8)
	);
}

Criticism

marcusaurelius

Payment identifiers, not person identifiers

in my opinion, the most basic idea of the URI scheme (as this is a currency) is to facilitate payment. so the URIs should represent first and foremost payments. if it represents something else, this needs to be specified. Thus bitcoin:13guMzcGPvdD3qjQvCoNc1w5XAgJ638KaQ represent a payment to me using my bitcoin adress, not my bitcoin adress itself. So after parsing the URI (via link/qr/whatever) the application should open a transaction window with the adress filled in. you then need to add an amount and confirm the payment. If your application is smart, it will also have a button "just store the adress". But the point i am trying to make, is that the default use of the URI should be for payment, nor for exchanging adresses.

Accessibility

imported from the forum: I like the simplicity of bitcoin:xxxxxxxxxxxxx plus very much approve of its accessibility. Should someone from the outside happen to see such a uri, the protocol name already gives a description. A quick google search should then do the rest. x-btc sounds much more cryptic, the chance that s/1 gooogles that out of curiosity are much slimmer. Also, very likely, what s/he will find are mostly technical specifications. Not a good introduction to bitcoin.

for the same reason i am for using '&' as a delimiter for key-value-pairs. people know it from urls. make it easy for people to understand what is going on.

Keep it simple

don't explicitly write down information that can be inferred. don't mark the address as an address. if there is no address, this does lose much of its utility. we could, however, specify 'address' as a reserved word, so that bitcoin:address?amount=50 would initiate a transaction with the amount filled in, but with a blank address. I am not convinced that there is a use case, though.

Use-cases

before the URI scheme is finalised one should think long and hard about use-cases. in what circumstances will who use this for what?

  • an online shop has a 'buy this'-link, which uses the URI scheme.
    • PROBLEM: click on the link opens the application. how does the merchant notice this.
      • POSSIBLE SOLUTION: javascript can detect the click.
      • POSSIBLE SOLUTION: the checkout site checks its bitcoin account for payment via httprequest
    • PROBLEM: the time problem (~10minutes) is very apparent here. nobody wants to wait 10minutes for the transaction to be confirmed.
  • a person only has an online client, no actual application
    • PROBLEM: how to redirect the URI, so that the online client gets a notice?

Backwards compatibility

we want URIs generated in 2011 to still work in 2036. think about extensibility. of course we can make only educated guesses (and nothing more!) about the future, but don't act as if there is none. this should be the best we can do, but it should not be seen as forever set in stone. make it possible for later generations to improve our work, to mend our errors, without breaking the URIs created now. Version incompatibility is the easiest thing to drive users crazy: "i now upgraded to this shiny new version. what? it doesn't support the old format? AAAAAAARRRGH!"

References

  1. RFC 1866 section 8.2.1 : by Tim Berners-Lee in 1995 encourages CGI authors to support ';' in addition to '&'.
  2. HTML 4.01 Specification: Implementation, and Design Notes: "CGI implementors support the use of ";" in place of "&" to save authors the trouble of escaping "&" characters in this manner."
  3. Hypertext Markup Language - 2.0 "CGI implementors are encouraged to support the use of ';' in place of '&' "