Simplify chunkHasUncompressedPubkey and remove lazy load of output script

This commit is contained in:
junderw 2020-05-21 12:54:49 +09:00
commit c2d8d19c61
No known key found for this signature in database
GPG key ID: B256185D3A971908
2 changed files with 22 additions and 14 deletions
src/payments

View file

@ -16,9 +16,13 @@ function stacksEqual(a, b) {
});
}
function chunkHasUncompressedPubkey(chunk) {
if (Buffer.isBuffer(chunk) && chunk.length === 65) {
if (ecc.isPoint(chunk)) return true;
else return false;
if (
Buffer.isBuffer(chunk) &&
chunk.length === 65 &&
chunk[0] === 0x04 &&
ecc.isPoint(chunk)
) {
return true;
} else {
return false;
}
@ -60,9 +64,6 @@ function p2wsh(a, opts) {
const _rchunks = lazy.value(() => {
return bscript.decompile(a.redeem.input);
});
const _rochunks = lazy.value(() => {
return bscript.decompile(a.redeem.output);
});
let network = a.network;
if (!network) {
network = (a.redeem && a.redeem.network) || networks_1.bitcoin;
@ -180,7 +181,10 @@ function p2wsh(a, opts) {
throw new TypeError('Witness and redeem.witness mismatch');
if (
(a.redeem.input && _rchunks().some(chunkHasUncompressedPubkey)) ||
(a.redeem.output && _rochunks().some(chunkHasUncompressedPubkey))
(a.redeem.output &&
(bscript.decompile(a.redeem.output) || []).some(
chunkHasUncompressedPubkey,
))
) {
throw new TypeError(
'redeem.input or redeem.output contains uncompressed pubkey',