get rid of obsolete 'bitcore' stealth addr format

This commit is contained in:
Ryan X. Charles 2014-09-22 21:51:19 -07:00
parent fd499089bb
commit 4fabad21a1
2 changed files with 8 additions and 81 deletions

View File

@ -10,11 +10,11 @@ var StealthAddress = function StealthAddress(addrstr) {
return new StealthAddress(addrstr);
if (typeof addrstr === 'string') {
this.fromBitcoreString(addrstr)
this.fromString(addrstr)
}
else if (Buffer.isBuffer(addrstr)) {
var buf = addrstr;
this.fromBitcoreBuffer(buf);
this.fromBuffer(buf);
}
else if (addrstr) {
var obj = addrstr;
@ -32,12 +32,12 @@ StealthAddress.prototype.set = function(obj) {
};
StealthAddress.prototype.fromJSON = function(json) {
this.fromBitcoreString(json);
this.fromString(json);
return this;
};
StealthAddress.prototype.toJSON = function() {
return this.toBitcoreString();
return this.toString();
};
StealthAddress.prototype.fromStealthkey = function(stealthkey) {
@ -48,19 +48,6 @@ StealthAddress.prototype.fromStealthkey = function(stealthkey) {
return this;
};
StealthAddress.prototype.fromBitcoreBuffer = function(buf) {
if (!Buffer.isBuffer(buf) || buf.length !== 66)
throw new Error('stealthkey: A stealth address must have length 66');
var pPubBuf = buf.slice(0, 33);
var sPubBuf = buf.slice(33, 66);
this.payloadPubkey = Pubkey().fromDER(pPubBuf);
this.scanPubkey = Pubkey().fromDER(sPubBuf);
return this;
};
StealthAddress.prototype.fromBuffer = function(buf) {
var parsed = StealthAddress.parseDWBuffer(buf);
if ((parsed.version !== StealthAddress.mainver) && (parsed.version !== StealthAddress.testver))
@ -84,13 +71,6 @@ StealthAddress.prototype.fromString = function(str) {
return this.fromBuffer(Base58check(str).toBuffer());
};
StealthAddress.prototype.fromBitcoreString = function(str) {
var buf = Base58check.decode(str);
this.fromBitcoreBuffer(buf);
return this;
};
StealthAddress.prototype.getSharedKeypair = function(senderKeypair) {
var sharedSecretPoint = this.scanPubkey.point.mul(senderKeypair.privkey.bn);
var sharedSecretPubkey = Pubkey(sharedSecretPoint);
@ -107,13 +87,6 @@ StealthAddress.prototype.getReceivePubkey = function(senderKeypair) {
return pubkey;
};
StealthAddress.prototype.toBitcoreBuffer = function() {
var pBuf = this.payloadPubkey.toDER(true);
var sBuf = this.scanPubkey.toDER(true);
return Buffer.concat([pBuf, sBuf]);
};
StealthAddress.prototype.toBuffer = function(networkstr) {
if (networkstr === 'testnet')
var version = StealthAddress.testver;
@ -135,13 +108,6 @@ StealthAddress.prototype.toString = function(networkstr) {
return Base58check(this.toBuffer(networkstr)).toString();
};
StealthAddress.prototype.toBitcoreString = function() {
var buf = this.toBitcoreBuffer();
var b58 = Base58check.encode(buf);
return b58;
};
StealthAddress.parseDWBuffer = function(buf) {
var br = new BufferReader(buf);
var parsed = {};

View File

@ -25,8 +25,9 @@ describe('StealthAddress', function() {
senderKeypair.privkey.bn = BN().fromBuffer(Hash.sha256(new Buffer('test 3')));
senderKeypair.privkey2pubkey();
var addressString = '9dDbC9FzZ74r8njQkXD6W27gtrxLiWaeFPHxeo1fynQRXPicqxVt7u95ozbwoVVMXyrzaHKN9owsteg63FgwDfrxWx82SAW';
var addressString = 'vJmtuUb8ysKiM1HtHQF23FGfjGAKu5sM94UyyjknqhJHNdj5CZzwtpGzeyaATQ2HvuzomNVtiwsTJSWzzCBgCTtUZbRFpzKVq9MAUr';
var dwhex = '2a0002697763d7e9becb0c180083738c32c05b0e2fee26d6278020c06bbb04d5f66b32010362408459041e0473298af3824dbabe4d2b7f846825ed4d1c2e2c670c07cb275d0100';
var dwbuf = new Buffer(dwhex, 'hex');
it('should make a new stealth address', function() {
var sa = new StealthAddress();
@ -58,18 +59,6 @@ describe('StealthAddress', 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.fromBitcoreBuffer(buf);
sa.payloadPubkey.toString().should.equal(stealthkey.payloadKeypair.pubkey.toString());
sa.scanPubkey.toString().should.equal(stealthkey.scanKeypair.pubkey.toString());
});
});
describe('#fromBuffer', function() {
it('should parse this DW buffer', function() {
@ -86,17 +75,6 @@ describe('StealthAddress', function() {
});
describe('#fromBitcoreString', function() {
it('should give a stealthkey address with the right pubkeys', function() {
var sa = new StealthAddress();
sa.fromBitcoreString(addressString);
sa.payloadPubkey.toString().should.equal(stealthkey.payloadKeypair.pubkey.toString());
sa.scanPubkey.toString().should.equal(stealthkey.scanKeypair.pubkey.toString());
});
});
describe('#getSharedKeypair', function() {
it('should return a key', function() {
@ -134,20 +112,11 @@ 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().fromBitcoreBuffer(buf).toBuffer().toString('hex').should.equal(dwhex);
StealthAddress().fromBuffer(dwbuf).toBuffer().toString('hex').should.equal(dwhex);
});
});
@ -156,15 +125,7 @@ describe('StealthAddress', 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().fromBitcoreString(addressString).toBitcoreString().should.equal(addressString);
StealthAddress().fromBuffer(buf).toString().should.equal(Base58check(new Buffer(dwhex, 'hex')).toString());
});
});