address: fix bech32 hrp check.

This commit is contained in:
Christopher Jeffrey 2017-05-13 18:57:40 -07:00
parent 6c32fbd283
commit fa5f987775
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -245,20 +245,23 @@ Address.prototype.toBech32 = function toBech32(network) {
*/
Address.prototype.fromString = function fromString(addr, network) {
var i, type, hrp;
var i, type, hrp, expect;
assert(typeof addr === 'string');
assert(addr.length >= 2);
hrp = addr.substring(0, 2).toLowerCase();
if (network) {
network = Network.get(network);
hrp = network.addressPrefix.bech32;
if (util.startsWith(addr, hrp))
expect = network.addressPrefix.bech32;
if (hrp === expect)
return this.fromBech32(addr, network);
} else {
for (i = 0; i < networks.types.length; i++) {
type = networks.types[i];
hrp = networks[type].addressPrefix.bech32;
if (util.startsWith(addr, hrp))
expect = networks[type].addressPrefix.bech32;
if (hrp === expect)
return this.fromBech32(addr, type);
}
}