Browse Source

Properly capitalize Base58Check and Base58

patch-2
Trevin Hofmann 10 years ago
parent
commit
374e43bed2
  1. 6
      lib/address.js
  2. 10
      lib/encoding/base58check.js
  3. 6
      lib/privatekey.js
  4. 6
      test/encoding/base58check.js
  5. 8
      test/privatekey.js

6
lib/address.js

@ -2,7 +2,7 @@
var _ = require('lodash');
var $ = require('./util/preconditions');
var base58check = require('./encoding/base58check');
var Base58Check = require('./encoding/base58check');
var Networks = require('./networks');
var Hash = require('./crypto/hash');
var JSUtil = require('./util/js');
@ -294,7 +294,7 @@ Address._transformString = function(data, network, type){
if( typeof(data) !== 'string' ) {
throw new TypeError('Address supplied is not a string.');
}
var addressBuffer = base58check.decode(data);
var addressBuffer = Base58Check.decode(data);
var info = Address._transformBuffer(addressBuffer, network, type);
return info;
};
@ -485,7 +485,7 @@ Address.prototype.toJSON = function toJSON() {
* @returns {String} Bitcoin address
*/
Address.prototype.toString = function() {
return base58check.encode(this.toBuffer());
return Base58Check.encode(this.toBuffer());
};
/**

10
lib/encoding/base58check.js

@ -1,7 +1,7 @@
'use strict';
var _ = require('lodash');
var base58 = require('./base58');
var Base58 = require('./base58');
var buffer = require('buffer');
var sha256sha256 = require('../crypto/hash').sha256sha256;
@ -26,10 +26,10 @@ Base58Check.prototype.set = function(obj) {
Base58Check.validChecksum = function validChecksum(data, checksum) {
if (_.isString(data)) {
data = new buffer.Buffer(base58.decode(data));
data = new buffer.Buffer(Base58.decode(data));
}
if (_.isString(checksum)) {
checksum = new buffer.Buffer(base58.decode(checksum));
checksum = new buffer.Buffer(Base58.decode(checksum));
}
if (!checksum) {
checksum = data.slice(-4);
@ -42,7 +42,7 @@ Base58Check.decode = function(s) {
if (typeof s !== 'string')
throw new Error('Input must be a string');
var buf = new Buffer(base58.decode(s));
var buf = new Buffer(Base58.decode(s));
if (buf.length < 4)
throw new Error("Input string too short");
@ -70,7 +70,7 @@ Base58Check.encode = function(buf) {
var hash = Base58Check.checksum(buf);
buf.copy(checkedBuf);
hash.copy(checkedBuf, buf.length);
return base58.encode(checkedBuf);
return Base58.encode(checkedBuf);
};
Base58Check.prototype.fromBuffer = function(buf) {

6
lib/privatekey.js

@ -2,7 +2,7 @@
var _ = require('lodash');
var Address = require('./address');
var base58check = require('./encoding/base58check');
var Base58Check = require('./encoding/base58check');
var BN = require('./crypto/bn');
var JSUtil = require('./util/js');
var Networks = require('./networks');
@ -206,7 +206,7 @@ PrivateKey._transformBNBuffer = function(buf, network) {
* @private
*/
PrivateKey._transformWIF = function(str, network) {
return PrivateKey._transformBuffer(base58check.decode(str), network);
return PrivateKey._transformBuffer(Base58Check.decode(str), network);
};
/**
@ -333,7 +333,7 @@ PrivateKey.prototype.toWIF = function() {
this.bn.toBuffer({size: 32})]);
}
return base58check.encode(buf);
return Base58Check.encode(buf);
};
/**

6
test/encoding/base58check.js

@ -3,7 +3,7 @@
var should = require('chai').should();
var bitcore = require('../..');
var Base58Check = bitcore.encoding.Base58Check;
var base58 = bitcore.encoding.Base58;
var Base58 = bitcore.encoding.Base58;
describe('Base58Check', function() {
var buf = new Buffer([0, 1, 2, 3, 253, 254, 255]);
@ -72,9 +72,9 @@ describe('Base58Check', function() {
});
it('should throw an error when there is a checksum mismatch', function() {
var buf2 = base58.decode(enc);
var buf2 = Base58.decode(enc);
buf2[0] = buf2[0] + 1;
var enc2 = base58.encode(buf2);
var enc2 = Base58.encode(buf2);
(function() {
Base58Check.decode(enc2);
}).should.throw('Checksum mismatch');

8
test/privatekey.js

@ -9,7 +9,7 @@ var BN = bitcore.crypto.BN;
var Point = bitcore.crypto.Point;
var PrivateKey = bitcore.PrivateKey;
var Networks = bitcore.Networks;
var base58check = bitcore.encoding.Base58Check;
var Base58Check = bitcore.encoding.Base58Check;
var validbase58 = require('./data/bitcoind/base58_keys_valid.json');
var invalidbase58 = require('./data/bitcoind/base58_keys_invalid.json');
@ -57,7 +57,7 @@ describe('PrivateKey', function() {
});
it('should create a private key from WIF buffer', function() {
var a = new PrivateKey(base58check.decode('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m'));
var a = new PrivateKey(Base58Check.decode('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m'));
should.exist(a);
should.exist(a.bn);
});
@ -100,7 +100,7 @@ describe('PrivateKey', function() {
it('should not be able to instantiate private key WIF is too long', function() {
expect(function() {
var buf = base58check.decode('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m');
var buf = Base58Check.decode('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m');
var buf2 = Buffer.concat([buf, new Buffer(0x01)]);
return new PrivateKey(buf2);
}).to.throw('Length of buffer must be 33 (uncompressed) or 34 (compressed');
@ -108,7 +108,7 @@ describe('PrivateKey', function() {
it('should not be able to instantiate private key WIF because of unknown network byte', function() {
expect(function() {
var buf = base58check.decode('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m');
var buf = Base58Check.decode('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m');
var buf2 = Buffer.concat([new Buffer('ff', 'hex'), buf.slice(1, 33)]);
return new PrivateKey(buf2);
}).to.throw('Invalid network');

Loading…
Cancel
Save