more address parsing.
This commit is contained in:
parent
718ae3c1aa
commit
38a92ebecf
@ -173,19 +173,25 @@ Address.prototype.fromBase58 = function fromBase58(data) {
|
|||||||
assert(type != null, 'Unknown address prefix.');
|
assert(type != null, 'Unknown address prefix.');
|
||||||
|
|
||||||
if (data.length > 25) {
|
if (data.length > 25) {
|
||||||
|
assert(network.address.witness[type], 'Non-witness address too long.');
|
||||||
version = p.readU8();
|
version = p.readU8();
|
||||||
assert(data.length === 27 || data.length === 39);
|
|
||||||
assert(version >= 0 && version <= 16, 'Bad program version.');
|
assert(version >= 0 && version <= 16, 'Bad program version.');
|
||||||
assert(p.readU8() === 0, 'Address version padding is non-zero.');
|
assert(p.readU8() === 0, 'Address version padding is non-zero.');
|
||||||
} else {
|
} else {
|
||||||
|
assert(data.length === 25, 'Address too short.');
|
||||||
version = -1;
|
version = -1;
|
||||||
assert(data.length === 25);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.length === 39)
|
hash = p.readBytes(p.left() - 4);
|
||||||
hash = p.readBytes(32);
|
|
||||||
else
|
if (version === -1)
|
||||||
hash = p.readBytes(20);
|
assert(hash.length === 20, 'Hash is the wrong size.');
|
||||||
|
else if (version === 0 && type === 'witnesspubkeyhash')
|
||||||
|
assert(hash.length === 20, 'Hash is the wrong size.');
|
||||||
|
else if (version === 0 && type === 'witnessscripthash')
|
||||||
|
assert(hash.length === 32, 'Hash is the wrong size.');
|
||||||
|
else if (version === 1 && type === 'witnessscripthash')
|
||||||
|
assert(hash.length === 32, 'Hash is the wrong size.');
|
||||||
|
|
||||||
p.verifyChecksum();
|
p.verifyChecksum();
|
||||||
|
|
||||||
|
|||||||
@ -283,8 +283,8 @@ Mnemonic.prototype.fromPhrase = function fromPhrase(phrase) {
|
|||||||
for (i = 0; i < cbits; i++) {
|
for (i = 0; i < cbits; i++) {
|
||||||
bit = i % 8;
|
bit = i % 8;
|
||||||
oct = (i - bit) / 8;
|
oct = (i - bit) / 8;
|
||||||
b = (chk[oct] >>> (7 - bit)) & 1;
|
b = (ent[oct] >>> (7 - bit)) & 1;
|
||||||
j = (ent[oct] >>> (7 - bit)) & 1;
|
j = (chk[oct] >>> (7 - bit)) & 1;
|
||||||
if (b !== j)
|
if (b !== j)
|
||||||
throw new Error('Invalid checksum.');
|
throw new Error('Invalid checksum.');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -380,13 +380,13 @@ main.address = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Base58Address} versions.
|
* {@link Base58Address} witness types.
|
||||||
* @enum {Number}
|
* @enum {Number}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
versions: {
|
witness: {
|
||||||
witnesspubkeyhash: 0,
|
witnesspubkeyhash: true,
|
||||||
witnessscripthash: 0
|
witnessscripthash: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -398,14 +398,6 @@ main.address = {
|
|||||||
|
|
||||||
main.address.prefixesByVal = utils.revMap(main.address.prefixes);
|
main.address.prefixesByVal = utils.revMap(main.address.prefixes);
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link Base58Address} versions by value.
|
|
||||||
* @type {RevMap}
|
|
||||||
* @default
|
|
||||||
*/
|
|
||||||
|
|
||||||
main.address.versionsByVal = utils.revMap(main.address.versions);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default value for whether the mempool
|
* Default value for whether the mempool
|
||||||
* accepts non-standard transactions.
|
* accepts non-standard transactions.
|
||||||
@ -598,14 +590,13 @@ testnet.address = {
|
|||||||
witnesspubkeyhash: 3,
|
witnesspubkeyhash: 3,
|
||||||
witnessscripthash: 40
|
witnessscripthash: 40
|
||||||
},
|
},
|
||||||
versions: {
|
witness: {
|
||||||
witnesspubkeyhash: 0,
|
witnesspubkeyhash: true,
|
||||||
witnessscripthash: 0
|
witnessscripthash: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
testnet.address.prefixesByVal = utils.revMap(testnet.address.prefixes);
|
testnet.address.prefixesByVal = utils.revMap(testnet.address.prefixes);
|
||||||
testnet.address.versionsByVal = utils.revMap(testnet.address.versions);
|
|
||||||
|
|
||||||
testnet.requireStandard = false;
|
testnet.requireStandard = false;
|
||||||
|
|
||||||
@ -745,14 +736,13 @@ regtest.address = {
|
|||||||
witnesspubkeyhash: 3,
|
witnesspubkeyhash: 3,
|
||||||
witnessscripthash: 40
|
witnessscripthash: 40
|
||||||
},
|
},
|
||||||
versions: {
|
witness: {
|
||||||
witnesspubkeyhash: 0,
|
witnesspubkeyhash: true,
|
||||||
witnessscripthash: 0
|
witnessscripthash: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
regtest.address.prefixesByVal = utils.revMap(regtest.address.prefixes);
|
regtest.address.prefixesByVal = utils.revMap(regtest.address.prefixes);
|
||||||
regtest.address.versionsByVal = utils.revMap(regtest.address.versions);
|
|
||||||
|
|
||||||
regtest.requireStandard = false;
|
regtest.requireStandard = false;
|
||||||
|
|
||||||
@ -876,14 +866,13 @@ segnet3.address = {
|
|||||||
witnesspubkeyhash: 3,
|
witnesspubkeyhash: 3,
|
||||||
witnessscripthash: 40
|
witnessscripthash: 40
|
||||||
},
|
},
|
||||||
versions: {
|
witness: {
|
||||||
witnesspubkeyhash: 0,
|
witnesspubkeyhash: true,
|
||||||
witnessscripthash: 0
|
witnessscripthash: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
segnet3.address.prefixesByVal = utils.revMap(segnet3.address.prefixes);
|
segnet3.address.prefixesByVal = utils.revMap(segnet3.address.prefixes);
|
||||||
segnet3.address.versionsByVal = utils.revMap(segnet3.address.versions);
|
|
||||||
|
|
||||||
segnet3.requireStandard = false;
|
segnet3.requireStandard = false;
|
||||||
|
|
||||||
@ -1022,14 +1011,13 @@ segnet4.address = {
|
|||||||
witnesspubkeyhash: 3,
|
witnesspubkeyhash: 3,
|
||||||
witnessscripthash: 40
|
witnessscripthash: 40
|
||||||
},
|
},
|
||||||
versions: {
|
witness: {
|
||||||
witnesspubkeyhash: 0,
|
witnesspubkeyhash: true,
|
||||||
witnessscripthash: 0
|
witnessscripthash: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
segnet4.address.prefixesByVal = utils.revMap(segnet4.address.prefixes);
|
segnet4.address.prefixesByVal = utils.revMap(segnet4.address.prefixes);
|
||||||
segnet4.address.versionsByVal = utils.revMap(segnet4.address.versions);
|
|
||||||
|
|
||||||
segnet4.requireStandard = false;
|
segnet4.requireStandard = false;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user