Simplify chunkHasUncompressedPubkey and remove lazy load of output script

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

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',

View file

@ -20,9 +20,13 @@ function stacksEqual(a: Buffer[], b: Buffer[]): boolean {
}
function chunkHasUncompressedPubkey(chunk: StackElement): boolean {
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;
}
@ -69,9 +73,6 @@ export function p2wsh(a: Payment, opts?: PaymentOpts): Payment {
const _rchunks = lazy.value(() => {
return bscript.decompile(a.redeem!.input!);
}) as StackFunction;
const _rochunks = lazy.value(() => {
return bscript.decompile(a.redeem!.output!);
}) as StackFunction;
let network = a.network;
if (!network) {
@ -202,7 +203,10 @@ export function p2wsh(a: Payment, opts?: PaymentOpts): Payment {
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',