address: fix bech32 hrp check.
This commit is contained in:
parent
6c32fbd283
commit
fa5f987775
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user