Commit 36871c86 authored by Zhenzhen Zhan's avatar Zhenzhen Zhan
Browse files

Address conversion: Fix a bug in Address class

parent ee4434ba
......@@ -211,7 +211,11 @@ Address._transformBuffer = function(buffer, network, type) {
throw new TypeError('Address has mismatched type.');
}
info.hashBuffer = buffer.slice(bufferVersion.network.name === 'livenet' ? 3 : 4);
info.hashBuffer = buffer.slice(
bufferVersion.type === 'pubkeyhash' ?
bufferVersion.network.pubkeyAddressPrefix.length :
bufferVersion.network.scriptAddressPrefix.length
);
info.network = bufferVersion.network;
info.type = bufferVersion.type;
return info;
......
......@@ -277,7 +277,7 @@ describe('Address', function() {
it('should error because of incorrect length buffer for transform buffer', function() {
(function() {
return Address._transformBuffer(new Buffer(20));
}).should.throw('Address buffers must be exactly 21 bytes.');
}).should.throw('Address buffers must be 23 or 24 bytes.');
});
it('should error because of incorrect type for pubkey transform', function() {
......@@ -353,8 +353,10 @@ describe('Address', function() {
it('should classify from a custom network', function() {
var custom = {
name: 'customnetwork',
pubkeyAddressPrefix: Buffer.from([0x01, 0x74, 0xf1]),
pubkeyhash: 0x1c,
privatekey: 0x1e,
scriptAddressPrefix: Buffer.from([0x10, 0x64, 0xde]),
scripthash: 0x28,
xpubkey: 0x02e8de8f,
xprivkey: 0x02e8da54,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment