Update Signature, URI, Unit

This commit is contained in:
Esteban Ordano 2014-12-16 03:02:05 -03:00
parent 32f8360fd5
commit 9d0b5e04fe
4 changed files with 13 additions and 28 deletions

View File

@ -1 +0,0 @@
# Signature

View File

@ -1,7 +1,6 @@
# URI
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.
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.
URI Examples:
```
@ -10,9 +9,7 @@ bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2
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
validating and parsing bitcoin URIs. A `URI` instance exposes the address as a
bitcore `Address` object and the amount in Satoshis, if present.
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.
The code for validating uris looks like this:
```javascript
@ -22,16 +19,11 @@ var uri = new URI(uriString);
console.log(uri.address.network, uri.amount); // 'livenet', 120000000
```
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.
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.
See [the official BIP21 spec](https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki)
for more information.
See [the official BIP21 spec](https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki) for more information.
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.
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.
The code for creating an URI from an Object looks like this:
```javascript

View File

@ -1,22 +1,18 @@
# Unit
Unit it's a 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.
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.
The supported units are BTC, mBTC, bits and satoshis. The codes for each unit
can be found as members of the Unit class.
The supported units are BTC, mBTC, bits and satoshis. The codes for each unit can be found as members of the Unit class.
```javascript
var btcCode = Unit.BTC;
var mbtcCode = Unit.mBTC;
var ubtcCode = Unit.uBTC;
var bitsCode = Unit.bits;
var satsCode = Unit.satoshis;
```
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:
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:
```javascript
var unit;
@ -33,10 +29,7 @@ unit = Unit.fromBits(amount);
unit = Unit.fromSatoshis(amount);
```
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.
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.
```javascript
var unit;

View File

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