make Dark Wallet buffer/string formats the default

and rename the old functions to "bitcore buffer" and "bitcore string"
This commit is contained in:
Ryan X. Charles 2014-09-22 21:27:31 -07:00
parent a3062b622c
commit 22b87325d7
2 changed files with 49 additions and 49 deletions

View File

@ -10,11 +10,11 @@ var StealthAddress = function StealthAddress(addrstr) {
return new StealthAddress(addrstr);
if (typeof addrstr === 'string') {
this.fromString(addrstr)
this.fromBitcoreString(addrstr)
}
else if (Buffer.isBuffer(addrstr)) {
var buf = addrstr;
this.fromBuffer(buf);
this.fromBitcoreBuffer(buf);
}
else if (addrstr) {
var obj = addrstr;
@ -32,12 +32,12 @@ StealthAddress.prototype.set = function(obj) {
};
StealthAddress.prototype.fromJSON = function(json) {
this.fromString(json);
this.fromBitcoreString(json);
return this;
};
StealthAddress.prototype.toJSON = function() {
return this.toString();
return this.toBitcoreString();
};
StealthAddress.prototype.fromStealthkey = function(stealthkey) {
@ -48,7 +48,7 @@ StealthAddress.prototype.fromStealthkey = function(stealthkey) {
return this;
};
StealthAddress.prototype.fromBuffer = function(buf) {
StealthAddress.prototype.fromBitcoreBuffer = function(buf) {
if (!Buffer.isBuffer(buf) || buf.length !== 66)
throw new Error('stealthkey: A stealth address must have length 66');
@ -61,7 +61,7 @@ StealthAddress.prototype.fromBuffer = function(buf) {
return this;
};
StealthAddress.prototype.fromDWBuffer = function(buf) {
StealthAddress.prototype.fromBuffer = function(buf) {
var parsed = StealthAddress.parseDWBuffer(buf);
if ((parsed.version !== StealthAddress.mainver) && (parsed.version !== StealthAddress.testver))
throw new Error('Invalid version');
@ -80,13 +80,13 @@ StealthAddress.prototype.fromDWBuffer = function(buf) {
return this;
};
StealthAddress.prototype.fromDWString = function(str) {
return this.fromDWBuffer(Base58check(str).toBuffer());
StealthAddress.prototype.fromString = function(str) {
return this.fromBuffer(Base58check(str).toBuffer());
};
StealthAddress.prototype.fromString = function(str) {
StealthAddress.prototype.fromBitcoreString = function(str) {
var buf = Base58check.decode(str);
this.fromBuffer(buf);
this.fromBitcoreBuffer(buf);
return this;
};
@ -107,14 +107,14 @@ StealthAddress.prototype.getReceivePubkey = function(senderKeypair) {
return pubkey;
};
StealthAddress.prototype.toBuffer = function() {
StealthAddress.prototype.toBitcoreBuffer = function() {
var pBuf = this.payloadPubkey.toDER(true);
var sBuf = this.scanPubkey.toDER(true);
return Buffer.concat([pBuf, sBuf]);
};
StealthAddress.prototype.toDWBuffer = function(networkstr) {
StealthAddress.prototype.toBuffer = function(networkstr) {
if (networkstr === 'testnet')
var version = StealthAddress.testver;
else
@ -131,12 +131,12 @@ StealthAddress.prototype.toDWBuffer = function(networkstr) {
return buf;
};
StealthAddress.prototype.toDWString = function(networkstr) {
return Base58check(this.toDWBuffer(networkstr)).toString();
StealthAddress.prototype.toString = function(networkstr) {
return Base58check(this.toBuffer(networkstr)).toString();
};
StealthAddress.prototype.toString = function() {
var buf = this.toBuffer();
StealthAddress.prototype.toBitcoreString = function() {
var buf = this.toBitcoreBuffer();
var b58 = Base58check.encode(buf);
return b58;

View File

@ -58,39 +58,39 @@ describe('StealthAddress', function() {
});
describe('#fromBuffer', function() {
describe('#fromBitcoreBuffer', function() {
it('should give a stealthkey address with the right pubkeys', function() {
var sa = new StealthAddress();
var buf = Base58check.decode(addressString);
sa.fromBuffer(buf);
sa.fromBitcoreBuffer(buf);
sa.payloadPubkey.toString().should.equal(stealthkey.payloadKeypair.pubkey.toString());
sa.scanPubkey.toString().should.equal(stealthkey.scanKeypair.pubkey.toString());
});
});
describe('#fromDWBuffer', function() {
describe('#fromBuffer', function() {
it('should parse this DW buffer', function() {
StealthAddress().fromDWBuffer(new Buffer(dwhex, 'hex')).toDWBuffer().toString('hex').should.equal(dwhex);
});
});
describe('#fromDWString', function() {
it('should parse this DW buffer', function() {
StealthAddress().fromDWString(Base58check(new Buffer(dwhex, 'hex')).toString()).toDWBuffer().toString('hex').should.equal(dwhex);
StealthAddress().fromBuffer(new Buffer(dwhex, 'hex')).toBuffer().toString('hex').should.equal(dwhex);
});
});
describe('#fromString', function() {
it('should parse this DW buffer', function() {
StealthAddress().fromString(Base58check(new Buffer(dwhex, 'hex')).toString()).toBuffer().toString('hex').should.equal(dwhex);
});
});
describe('#fromBitcoreString', function() {
it('should give a stealthkey address with the right pubkeys', function() {
var sa = new StealthAddress();
sa.fromString(addressString);
sa.fromBitcoreString(addressString);
sa.payloadPubkey.toString().should.equal(stealthkey.payloadKeypair.pubkey.toString());
sa.scanPubkey.toString().should.equal(stealthkey.scanKeypair.pubkey.toString());
});
@ -134,37 +134,37 @@ describe('StealthAddress', function() {
});
describe('#toBitcoreBuffer', function() {
it('should return this known address buffer', function() {
var buf = Base58check.decode(addressString);
StealthAddress().fromBitcoreBuffer(buf).toBitcoreBuffer().toString('hex').should.equal(buf.toString('hex'));
});
});
describe('#toBuffer', function() {
it('should return this known address buffer', function() {
var buf = Base58check.decode(addressString);
StealthAddress().fromBuffer(buf).toBuffer().toString('hex').should.equal(buf.toString('hex'));
});
});
describe('#toDWBuffer', function() {
it('should return this known address buffer', function() {
var buf = Base58check.decode(addressString);
StealthAddress().fromBuffer(buf).toDWBuffer().toString('hex').should.equal(dwhex);
});
});
describe('#toDWString', function() {
it('should return this known address buffer', function() {
var buf = Base58check.decode(addressString);
StealthAddress().fromBuffer(buf).toDWString().should.equal(Base58check(new Buffer(dwhex, 'hex')).toString());
StealthAddress().fromBitcoreBuffer(buf).toBuffer().toString('hex').should.equal(dwhex);
});
});
describe('#toString', function() {
it('should return this known address buffer', function() {
var buf = Base58check.decode(addressString);
StealthAddress().fromBitcoreBuffer(buf).toString().should.equal(Base58check(new Buffer(dwhex, 'hex')).toString());
});
});
describe('#toBitcoreString', function() {
it('should return this known address string', function() {
StealthAddress().fromString(addressString).toString().should.equal(addressString);
StealthAddress().fromBitcoreString(addressString).toBitcoreString().should.equal(addressString);
});
});