Browse Source

Update Signature, URI, Unit

patch-2
Esteban Ordano 10 years ago
parent
commit
9d0b5e04fe
  1. 1
      docs/Signature.md
  2. 18
      docs/URI.md
  3. 17
      docs/Unit.md
  4. 5
      lib/unit.js

1
docs/Signature.md

@ -1 +0,0 @@
# Signature

18
docs/URI.md

@ -1,7 +1,6 @@
# URI # URI
Represents a bitcoin payment uri. Bitcoin URI strings became the most popular Represents a bitcoin payment uri. Bitcoin URI strings became the most popular way to share payment request, sometimes as a bitcoin link and others using a QR code.
way to share payment request, sometimes as a bitcoin link and others using a QR code.
URI Examples: URI Examples:
``` ```
@ -10,9 +9,7 @@ bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2
bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2&message=Payment&label=Satoshi&extra=other-param bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2&message=Payment&label=Satoshi&extra=other-param
``` ```
The main use that we expect you'll have for the `URI` class in bitcore is The main use that we expect you'll have for the `URI` class in bitcore is validating and parsing bitcoin URIs. A `URI` instance exposes the address as a bitcore `Address` object and the amount in Satoshis, if present.
validating and parsing bitcoin URIs. A `URI` instance exposes the address as a
bitcore `Address` object and the amount in Satoshis, if present.
The code for validating uris looks like this: The code for validating uris looks like this:
```javascript ```javascript
@ -22,16 +19,11 @@ var uri = new URI(uriString);
console.log(uri.address.network, uri.amount); // 'livenet', 120000000 console.log(uri.address.network, uri.amount); // 'livenet', 120000000
``` ```
All standard parameters can be found as members of the `URI` instance. However All standard parameters can be found as members of the `URI` instance. However a bitcoin uri may contain other non-standard parameters, all those can be found under the `extra` namespace.
a bitcoin uri may contain other non-standard parameters, all those can be found
under the `extra` namespace.
See [the official BIP21 spec](https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki) See [the official BIP21 spec](https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki) for more information.
for more information.
Other usecase important usecase for the `URI` class is creating a bitcoin URI for Other usecase important usecase for the `URI` class is creating a bitcoin URI for sharing a payment request. That can be acomplished by using an Object to create an instance of URI.
sharing a payment request. That can be acomplished by using an Object to create
an instance of URI.
The code for creating an URI from an Object looks like this: The code for creating an URI from an Object looks like this:
```javascript ```javascript

17
docs/Unit.md

@ -1,22 +1,18 @@
# Unit # Unit
Unit it's a utility for handling and converting bitcoins units. We strongly Unit is an utility for handling and converting bitcoins units. We strongly recommend you to always use satoshis to represent amount inside your application and only convert them to other units in the front-end.
recommend you to always use satoshis to represent amount inside your application
and only convert them to other units in the front-end.
The supported units are BTC, mBTC, bits and satoshis. The codes for each unit The supported units are BTC, mBTC, bits and satoshis. The codes for each unit can be found as members of the Unit class.
can be found as members of the Unit class.
```javascript ```javascript
var btcCode = Unit.BTC; var btcCode = Unit.BTC;
var mbtcCode = Unit.mBTC; var mbtcCode = Unit.mBTC;
var ubtcCode = Unit.uBTC;
var bitsCode = Unit.bits; var bitsCode = Unit.bits;
var satsCode = Unit.satoshis; var satsCode = Unit.satoshis;
``` ```
There are two ways for creating a unit instance. You can instanciate the class There are two ways for creating a unit instance. You can instanciate the class using a value and a unit code; alternatively if the unit it's fixed you could you some of the static methods. Check some examples below:
using a value and a unit code; alternatively if the unit it's fixed you could
you some of the static methods. Check some examples below:
```javascript ```javascript
var unit; var unit;
@ -33,10 +29,7 @@ unit = Unit.fromBits(amount);
unit = Unit.fromSatoshis(amount); unit = Unit.fromSatoshis(amount);
``` ```
Once you have a unit instance, you can check it's representantion in all the Once you have a unit instance, you can check it's representantion in all the available units. For your convinience the classes expose three ways to acomplish this. Using the `.to(unitCode)` method, using a fixed unit like `.toSatoshis()` or by using the accessors.
available units. For your convinience the classes expose three ways to acomplish
this. Using the `.to(unitCode)` method, using a fixed unit like `.toSatoshis()`
or by using the accessors.
```javascript ```javascript
var unit; var unit;

5
lib/unit.js

@ -48,6 +48,7 @@ function Unit(amount, code) {
var UNITS = { var UNITS = {
'BTC' : [1e8, 8], 'BTC' : [1e8, 8],
'mBTC' : [1e5, 5], 'mBTC' : [1e5, 5],
'uBTC' : [1e2, 2],
'bits' : [1e2, 2], 'bits' : [1e2, 2],
'satoshis' : [1, 0] 'satoshis' : [1, 0]
}; };
@ -95,7 +96,7 @@ Unit.fromMilis = function(amount) {
* @param {Number} amount - The amount in bits * @param {Number} amount - The amount in bits
* @returns {Unit} A Unit instance * @returns {Unit} A Unit instance
*/ */
Unit.fromBits = function(amount) { Unit.fromMicros = Unit.fromBits = function(amount) {
return new Unit(amount, Unit.bits); return new Unit(amount, Unit.bits);
}; };
@ -152,7 +153,7 @@ Unit.prototype.toMilis = function(code) {
* *
* @returns {Number} The value converted to bits * @returns {Number} The value converted to bits
*/ */
Unit.prototype.toBits = function(code) { Unit.prototype.toMicros = Unit.prototype.toBits = function(code) {
return this.to(Unit.bits); return this.to(Unit.bits);
}; };

Loading…
Cancel
Save