use standard language - hash -> hashbuf
This commit is contained in:
parent
4f90478aa6
commit
e6d89a76d7
@ -3,8 +3,8 @@ var constants = require('./constants');
|
|||||||
var Hash = require('./hash');
|
var Hash = require('./hash');
|
||||||
var Pubkey = require('./pubkey');
|
var Pubkey = require('./pubkey');
|
||||||
|
|
||||||
function Address(hash, network, type) {
|
function Address(hashbuf, network, type) {
|
||||||
this.hash = hash;
|
this.hashbuf = hashbuf;
|
||||||
this.network = network;
|
this.network = network;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
};
|
};
|
||||||
@ -12,7 +12,7 @@ function Address(hash, network, type) {
|
|||||||
Address.prototype.fromPubkey = function(pubkey, network, compressed) {
|
Address.prototype.fromPubkey = function(pubkey, network, compressed) {
|
||||||
if (typeof compressed === 'undefined')
|
if (typeof compressed === 'undefined')
|
||||||
compressed = true;
|
compressed = true;
|
||||||
this.hash = Hash.sha256ripemd160(pubkey.toDER(compressed));
|
this.hashbuf = Hash.sha256ripemd160(pubkey.toDER(compressed));
|
||||||
this.network = network || 'mainnet';
|
this.network = network || 'mainnet';
|
||||||
this.type = 'pubkeyhash';
|
this.type = 'pubkeyhash';
|
||||||
return this;
|
return this;
|
||||||
@ -40,7 +40,7 @@ Address.prototype.fromString = function(str) {
|
|||||||
this.type = 'unknown';
|
this.type = 'unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hash = buf.slice(1);
|
this.hashbuf = buf.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Address.prototype.isValid = function() {
|
Address.prototype.isValid = function() {
|
||||||
@ -54,7 +54,7 @@ Address.prototype.isValid = function() {
|
|||||||
|
|
||||||
Address.prototype.toBuffer = function() {
|
Address.prototype.toBuffer = function() {
|
||||||
version = new Buffer([constants[this.network][this.type]]);
|
version = new Buffer([constants[this.network][this.type]]);
|
||||||
var buf = Buffer.concat([version, this.hash]);
|
var buf = Buffer.concat([version, this.hashbuf]);
|
||||||
return buf;
|
return buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ Address.prototype.toString = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Address.prototype.validate = function() {
|
Address.prototype.validate = function() {
|
||||||
if (!Buffer.isBuffer(this.hash) || this.hash.length !== 20)
|
if (!Buffer.isBuffer(this.hashbuf) || this.hashbuf.length !== 20)
|
||||||
throw new Error('hash must be a buffer of 20 bytes');
|
throw new Error('hash must be a buffer of 20 bytes');
|
||||||
if (this.network !== 'mainnet' && this.network !== 'testnet')
|
if (this.network !== 'mainnet' && this.network !== 'testnet')
|
||||||
throw new Error('network must be "mainnet" or "testnet"');
|
throw new Error('network must be "mainnet" or "testnet"');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user