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('lodash');
var $ = require('./util/preconditions'); var $ = require('./util/preconditions');
var base58check = require('./encoding/base58check'); var Base58Check = require('./encoding/base58check');
var Networks = require('./networks'); var Networks = require('./networks');
var Hash = require('./crypto/hash'); var Hash = require('./crypto/hash');
var JSUtil = require('./util/js'); var JSUtil = require('./util/js');
@ -294,7 +294,7 @@ Address._transformString = function(data, network, type){
if( typeof(data) !== 'string' ) { if( typeof(data) !== 'string' ) {
throw new TypeError('Address supplied is not a 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); var info = Address._transformBuffer(addressBuffer, network, type);
return info; return info;
}; };
@ -485,7 +485,7 @@ Address.prototype.toJSON = function toJSON() {
* @returns {String} Bitcoin address * @returns {String} Bitcoin address
*/ */
Address.prototype.toString = function() { 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'; 'use strict';
var _ = require('lodash'); var _ = require('lodash');
var base58 = require('./base58'); var Base58 = require('./base58');
var buffer = require('buffer'); var buffer = require('buffer');
var sha256sha256 = require('../crypto/hash').sha256sha256; var sha256sha256 = require('../crypto/hash').sha256sha256;
@ -26,10 +26,10 @@ Base58Check.prototype.set = function(obj) {
Base58Check.validChecksum = function validChecksum(data, checksum) { Base58Check.validChecksum = function validChecksum(data, checksum) {
if (_.isString(data)) { if (_.isString(data)) {
data = new buffer.Buffer(base58.decode(data)); data = new buffer.Buffer(Base58.decode(data));
} }
if (_.isString(checksum)) { if (_.isString(checksum)) {
checksum = new buffer.Buffer(base58.decode(checksum)); checksum = new buffer.Buffer(Base58.decode(checksum));
} }
if (!checksum) { if (!checksum) {
checksum = data.slice(-4); checksum = data.slice(-4);
@ -42,7 +42,7 @@ Base58Check.decode = function(s) {
if (typeof s !== 'string') if (typeof s !== 'string')
throw new Error('Input must be a 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) if (buf.length < 4)
throw new Error("Input string too short"); throw new Error("Input string too short");
@ -70,7 +70,7 @@ Base58Check.encode = function(buf) {
var hash = Base58Check.checksum(buf); var hash = Base58Check.checksum(buf);
buf.copy(checkedBuf); buf.copy(checkedBuf);
hash.copy(checkedBuf, buf.length); hash.copy(checkedBuf, buf.length);
return base58.encode(checkedBuf); return Base58.encode(checkedBuf);
}; };
Base58Check.prototype.fromBuffer = function(buf) { Base58Check.prototype.fromBuffer = function(buf) {

6
lib/privatekey.js

@ -2,7 +2,7 @@
var _ = require('lodash'); var _ = require('lodash');
var Address = require('./address'); var Address = require('./address');
var base58check = require('./encoding/base58check'); var Base58Check = require('./encoding/base58check');
var BN = require('./crypto/bn'); var BN = require('./crypto/bn');
var JSUtil = require('./util/js'); var JSUtil = require('./util/js');
var Networks = require('./networks'); var Networks = require('./networks');
@ -206,7 +206,7 @@ PrivateKey._transformBNBuffer = function(buf, network) {
* @private * @private
*/ */
PrivateKey._transformWIF = function(str, network) { 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})]); 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 should = require('chai').should();
var bitcore = require('../..'); var bitcore = require('../..');
var Base58Check = bitcore.encoding.Base58Check; var Base58Check = bitcore.encoding.Base58Check;
var base58 = bitcore.encoding.Base58; var Base58 = bitcore.encoding.Base58;
describe('Base58Check', function() { describe('Base58Check', function() {
var buf = new Buffer([0, 1, 2, 3, 253, 254, 255]); 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() { 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; buf2[0] = buf2[0] + 1;
var enc2 = base58.encode(buf2); var enc2 = Base58.encode(buf2);
(function() { (function() {
Base58Check.decode(enc2); Base58Check.decode(enc2);
}).should.throw('Checksum mismatch'); }).should.throw('Checksum mismatch');

8
test/privatekey.js

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

Loading…
Cancel
Save