make Dark Wallet buffer/string formats the default
and rename the old functions to "bitcore buffer" and "bitcore string"
This commit is contained in:
parent
a3062b622c
commit
22b87325d7
|
@ -10,11 +10,11 @@ var StealthAddress = function StealthAddress(addrstr) {
|
||||||
return new StealthAddress(addrstr);
|
return new StealthAddress(addrstr);
|
||||||
|
|
||||||
if (typeof addrstr === 'string') {
|
if (typeof addrstr === 'string') {
|
||||||
this.fromString(addrstr)
|
this.fromBitcoreString(addrstr)
|
||||||
}
|
}
|
||||||
else if (Buffer.isBuffer(addrstr)) {
|
else if (Buffer.isBuffer(addrstr)) {
|
||||||
var buf = addrstr;
|
var buf = addrstr;
|
||||||
this.fromBuffer(buf);
|
this.fromBitcoreBuffer(buf);
|
||||||
}
|
}
|
||||||
else if (addrstr) {
|
else if (addrstr) {
|
||||||
var obj = addrstr;
|
var obj = addrstr;
|
||||||
|
@ -32,12 +32,12 @@ StealthAddress.prototype.set = function(obj) {
|
||||||
};
|
};
|
||||||
|
|
||||||
StealthAddress.prototype.fromJSON = function(json) {
|
StealthAddress.prototype.fromJSON = function(json) {
|
||||||
this.fromString(json);
|
this.fromBitcoreString(json);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
StealthAddress.prototype.toJSON = function() {
|
StealthAddress.prototype.toJSON = function() {
|
||||||
return this.toString();
|
return this.toBitcoreString();
|
||||||
};
|
};
|
||||||
|
|
||||||
StealthAddress.prototype.fromStealthkey = function(stealthkey) {
|
StealthAddress.prototype.fromStealthkey = function(stealthkey) {
|
||||||
|
@ -48,7 +48,7 @@ StealthAddress.prototype.fromStealthkey = function(stealthkey) {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
StealthAddress.prototype.fromBuffer = function(buf) {
|
StealthAddress.prototype.fromBitcoreBuffer = function(buf) {
|
||||||
if (!Buffer.isBuffer(buf) || buf.length !== 66)
|
if (!Buffer.isBuffer(buf) || buf.length !== 66)
|
||||||
throw new Error('stealthkey: A stealth address must have length 66');
|
throw new Error('stealthkey: A stealth address must have length 66');
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ StealthAddress.prototype.fromBuffer = function(buf) {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
StealthAddress.prototype.fromDWBuffer = function(buf) {
|
StealthAddress.prototype.fromBuffer = function(buf) {
|
||||||
var parsed = StealthAddress.parseDWBuffer(buf);
|
var parsed = StealthAddress.parseDWBuffer(buf);
|
||||||
if ((parsed.version !== StealthAddress.mainver) && (parsed.version !== StealthAddress.testver))
|
if ((parsed.version !== StealthAddress.mainver) && (parsed.version !== StealthAddress.testver))
|
||||||
throw new Error('Invalid version');
|
throw new Error('Invalid version');
|
||||||
|
@ -80,13 +80,13 @@ StealthAddress.prototype.fromDWBuffer = function(buf) {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
StealthAddress.prototype.fromDWString = function(str) {
|
StealthAddress.prototype.fromString = function(str) {
|
||||||
return this.fromDWBuffer(Base58check(str).toBuffer());
|
return this.fromBuffer(Base58check(str).toBuffer());
|
||||||
};
|
};
|
||||||
|
|
||||||
StealthAddress.prototype.fromString = function(str) {
|
StealthAddress.prototype.fromBitcoreString = function(str) {
|
||||||
var buf = Base58check.decode(str);
|
var buf = Base58check.decode(str);
|
||||||
this.fromBuffer(buf);
|
this.fromBitcoreBuffer(buf);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
@ -107,14 +107,14 @@ StealthAddress.prototype.getReceivePubkey = function(senderKeypair) {
|
||||||
return pubkey;
|
return pubkey;
|
||||||
};
|
};
|
||||||
|
|
||||||
StealthAddress.prototype.toBuffer = function() {
|
StealthAddress.prototype.toBitcoreBuffer = function() {
|
||||||
var pBuf = this.payloadPubkey.toDER(true);
|
var pBuf = this.payloadPubkey.toDER(true);
|
||||||
var sBuf = this.scanPubkey.toDER(true);
|
var sBuf = this.scanPubkey.toDER(true);
|
||||||
|
|
||||||
return Buffer.concat([pBuf, sBuf]);
|
return Buffer.concat([pBuf, sBuf]);
|
||||||
};
|
};
|
||||||
|
|
||||||
StealthAddress.prototype.toDWBuffer = function(networkstr) {
|
StealthAddress.prototype.toBuffer = function(networkstr) {
|
||||||
if (networkstr === 'testnet')
|
if (networkstr === 'testnet')
|
||||||
var version = StealthAddress.testver;
|
var version = StealthAddress.testver;
|
||||||
else
|
else
|
||||||
|
@ -131,12 +131,12 @@ StealthAddress.prototype.toDWBuffer = function(networkstr) {
|
||||||
return buf;
|
return buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
StealthAddress.prototype.toDWString = function(networkstr) {
|
StealthAddress.prototype.toString = function(networkstr) {
|
||||||
return Base58check(this.toDWBuffer(networkstr)).toString();
|
return Base58check(this.toBuffer(networkstr)).toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
StealthAddress.prototype.toString = function() {
|
StealthAddress.prototype.toBitcoreString = function() {
|
||||||
var buf = this.toBuffer();
|
var buf = this.toBitcoreBuffer();
|
||||||
var b58 = Base58check.encode(buf);
|
var b58 = Base58check.encode(buf);
|
||||||
|
|
||||||
return b58;
|
return b58;
|
||||||
|
|
|
@ -58,39 +58,39 @@ describe('StealthAddress', function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#fromBuffer', function() {
|
describe('#fromBitcoreBuffer', function() {
|
||||||
|
|
||||||
it('should give a stealthkey address with the right pubkeys', function() {
|
it('should give a stealthkey address with the right pubkeys', function() {
|
||||||
var sa = new StealthAddress();
|
var sa = new StealthAddress();
|
||||||
var buf = Base58check.decode(addressString);
|
var buf = Base58check.decode(addressString);
|
||||||
sa.fromBuffer(buf);
|
sa.fromBitcoreBuffer(buf);
|
||||||
sa.payloadPubkey.toString().should.equal(stealthkey.payloadKeypair.pubkey.toString());
|
sa.payloadPubkey.toString().should.equal(stealthkey.payloadKeypair.pubkey.toString());
|
||||||
sa.scanPubkey.toString().should.equal(stealthkey.scanKeypair.pubkey.toString());
|
sa.scanPubkey.toString().should.equal(stealthkey.scanKeypair.pubkey.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#fromDWBuffer', function() {
|
describe('#fromBuffer', function() {
|
||||||
|
|
||||||
it('should parse this DW buffer', function() {
|
it('should parse this DW buffer', function() {
|
||||||
StealthAddress().fromDWBuffer(new Buffer(dwhex, 'hex')).toDWBuffer().toString('hex').should.equal(dwhex);
|
StealthAddress().fromBuffer(new Buffer(dwhex, 'hex')).toBuffer().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);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#fromString', function() {
|
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() {
|
it('should give a stealthkey address with the right pubkeys', function() {
|
||||||
var sa = new StealthAddress();
|
var sa = new StealthAddress();
|
||||||
sa.fromString(addressString);
|
sa.fromBitcoreString(addressString);
|
||||||
sa.payloadPubkey.toString().should.equal(stealthkey.payloadKeypair.pubkey.toString());
|
sa.payloadPubkey.toString().should.equal(stealthkey.payloadKeypair.pubkey.toString());
|
||||||
sa.scanPubkey.toString().should.equal(stealthkey.scanKeypair.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() {
|
describe('#toBuffer', function() {
|
||||||
|
|
||||||
it('should return this known address buffer', function() {
|
it('should return this known address buffer', function() {
|
||||||
var buf = Base58check.decode(addressString);
|
var buf = Base58check.decode(addressString);
|
||||||
StealthAddress().fromBuffer(buf).toBuffer().toString('hex').should.equal(buf.toString('hex'));
|
StealthAddress().fromBitcoreBuffer(buf).toBuffer().toString('hex').should.equal(dwhex);
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
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());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#toString', function() {
|
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() {
|
it('should return this known address string', function() {
|
||||||
StealthAddress().fromString(addressString).toString().should.equal(addressString);
|
StealthAddress().fromBitcoreString(addressString).toBitcoreString().should.equal(addressString);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue