Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Simplify chunkHasUncompressedPubkey and remove lazy load of output sc…
Browse files Browse the repository at this point in the history
…ript
  • Loading branch information
junderw committed May 21, 2020
1 parent 25b5806 commit c2d8d19
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
18 changes: 11 additions & 7 deletions src/payments/p2wsh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down
18 changes: 11 additions & 7 deletions ts_src/payments/p2wsh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit c2d8d19

Please sign in to comment.