Merge pull request #81 from Dcousens/tostring

EC*Key.toString now returns hex instead of WIF
This commit is contained in:
Wei Lu 2014-03-24 03:11:32 +08:00
commit eca20ad297
2 changed files with 10 additions and 14 deletions

View file

@ -96,7 +96,7 @@ ECKey.prototype.toBase64 = function() {
return convert.bytesToBase64(this.toBytes()) return convert.bytesToBase64(this.toBytes())
} }
ECKey.prototype.toString = ECKey.prototype.toWif ECKey.prototype.toString = ECKey.prototype.toHex
ECKey.prototype.getAddress = function(version) { ECKey.prototype.getAddress = function(version) {
return this.getPub().getAddress(version) return this.getPub().getAddress(version)
@ -170,7 +170,7 @@ ECPubKey.prototype.toWif = function(version) {
return base58.checkEncode(this.toBytes(), version) return base58.checkEncode(this.toBytes(), version)
} }
ECPubKey.prototype.toString = ECPubKey.prototype.toWif ECPubKey.prototype.toString = ECPubKey.prototype.toHex
ECPubKey.prototype.getAddress = function(version) { ECPubKey.prototype.getAddress = function(version) {
var version = version || Network.mainnet.addressVersion; var version = version || Network.mainnet.addressVersion;

View file

@ -33,20 +33,16 @@ describe('HDWallet', function() {
}) })
describe('constructor & seed deserialization', function() { describe('constructor & seed deserialization', function() {
var expectedPrivKey, seed; var expectedPrivateKey = '0fd71c652e847ba7ea7956e3cf3fc0a0985871846b1b2c23b9c6a29a38cee86001';
var seed = [
beforeEach(function(){ 99, 114, 97, 122, 121, 32, 104, 111, 114, 115, 101, 32, 98,
expectedPrivKey = 'KwkW62Lzm4a7Eo5nPLezrVjWBGFh2KMfpyf4Swz9NmfsVaLoeXv9' 97, 116, 116, 101, 114, 121, 32, 115, 116, 97, 112, 108, 101
seed = [ ];
99, 114, 97, 122, 121, 32, 104, 111, 114, 115, 101, 32, 98,
97, 116, 116, 101, 114, 121, 32, 115, 116, 97, 112, 108, 101
]
})
it('creates from binary seed', function() { it('creates from binary seed', function() {
var hd = new HDWallet(seed) var hd = new HDWallet(seed)
assert.equal(hd.priv, expectedPrivKey) assert.equal(hd.priv.toHex(), expectedPrivateKey)
assert(hd.pub) assert(hd.pub)
}) })
@ -54,7 +50,7 @@ describe('HDWallet', function() {
it('creates from hex seed', function() { it('creates from hex seed', function() {
var hd = HDWallet.fromSeedHex(b2h(seed)) var hd = HDWallet.fromSeedHex(b2h(seed))
assert.equal(hd.priv, expectedPrivKey) assert.equal(hd.priv.toHex(), expectedPrivateKey)
assert(hd.pub) assert(hd.pub)
}) })
}) })
@ -63,7 +59,7 @@ describe('HDWallet', function() {
it('creates from string seed', function() { it('creates from string seed', function() {
var hd = HDWallet.fromSeedString(convert.bytesToString(seed)) var hd = HDWallet.fromSeedString(convert.bytesToString(seed))
assert.equal(hd.priv, expectedPrivKey) assert.equal(hd.priv.toHex(), expectedPrivateKey)
assert(hd.pub) assert(hd.pub)
}) })
}) })