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) {
|
Address.prototype.fromString = function fromString(addr, network) {
|
||||||
var i, type, hrp;
|
var i, type, hrp, expect;
|
||||||
|
|
||||||
assert(typeof addr === 'string');
|
assert(typeof addr === 'string');
|
||||||
|
assert(addr.length >= 2);
|
||||||
|
|
||||||
|
hrp = addr.substring(0, 2).toLowerCase();
|
||||||
|
|
||||||
if (network) {
|
if (network) {
|
||||||
network = Network.get(network);
|
network = Network.get(network);
|
||||||
hrp = network.addressPrefix.bech32;
|
expect = network.addressPrefix.bech32;
|
||||||
if (util.startsWith(addr, hrp))
|
if (hrp === expect)
|
||||||
return this.fromBech32(addr, network);
|
return this.fromBech32(addr, network);
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < networks.types.length; i++) {
|
for (i = 0; i < networks.types.length; i++) {
|
||||||
type = networks.types[i];
|
type = networks.types[i];
|
||||||
hrp = networks[type].addressPrefix.bech32;
|
expect = networks[type].addressPrefix.bech32;
|
||||||
if (util.startsWith(addr, hrp))
|
if (hrp === expect)
|
||||||
return this.fromBech32(addr, type);
|
return this.fromBech32(addr, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user