address: better network validation.
This commit is contained in:
parent
2365355d79
commit
9215e4fe48
@ -378,10 +378,8 @@ HTTPServer.prototype._init = function _init() {
|
|||||||
enforce(typeof output.address === 'string',
|
enforce(typeof output.address === 'string',
|
||||||
'Address must be a string.');
|
'Address must be a string.');
|
||||||
output.address = Address.fromBase58(output.address);
|
output.address = Address.fromBase58(output.address);
|
||||||
if (this.network.type === 'main') {
|
enforce(output.address.verifyNetwork(this.network),
|
||||||
enforce(output.address.network === this.network,
|
'Wrong network for address.');
|
||||||
'Wrong network for address.');
|
|
||||||
}
|
|
||||||
} else if (output.script) {
|
} else if (output.script) {
|
||||||
enforce(typeof output.script === 'string',
|
enforce(typeof output.script === 'string',
|
||||||
'Script must be a string.');
|
'Script must be a string.');
|
||||||
|
|||||||
@ -90,6 +90,30 @@ Address.prototype.getHash = function getHash(enc) {
|
|||||||
return this.hash;
|
return this.hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a network address prefix for the address.
|
||||||
|
* @param {Network?} network
|
||||||
|
* @returns {Number}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Address.prototype.getPrefix = function getPrefix(network) {
|
||||||
|
if (!network)
|
||||||
|
network = this.network;
|
||||||
|
network = Network.get(network);
|
||||||
|
return Address.getPrefix(this.type, network);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify an address network (compares prefixes).
|
||||||
|
* @param {Network} network
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Address.prototype.verifyNetwork = function verifyNetwork(network) {
|
||||||
|
assert(network);
|
||||||
|
return this.getPrefix() === this.getPrefix(network);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the address type as a string.
|
* Get the address type as a string.
|
||||||
* @returns {AddressType}
|
* @returns {AddressType}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user