Simplify chunkHasUncompressedPubkey and remove lazy load of output script
This commit is contained in:
parent
25b5806cf1
commit
c2d8d19c61
2 changed files with 22 additions and 14 deletions
|
@ -16,9 +16,13 @@ function stacksEqual(a, b) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function chunkHasUncompressedPubkey(chunk) {
|
function chunkHasUncompressedPubkey(chunk) {
|
||||||
if (Buffer.isBuffer(chunk) && chunk.length === 65) {
|
if (
|
||||||
if (ecc.isPoint(chunk)) return true;
|
Buffer.isBuffer(chunk) &&
|
||||||
else return false;
|
chunk.length === 65 &&
|
||||||
|
chunk[0] === 0x04 &&
|
||||||
|
ecc.isPoint(chunk)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -60,9 +64,6 @@ function p2wsh(a, opts) {
|
||||||
const _rchunks = lazy.value(() => {
|
const _rchunks = lazy.value(() => {
|
||||||
return bscript.decompile(a.redeem.input);
|
return bscript.decompile(a.redeem.input);
|
||||||
});
|
});
|
||||||
const _rochunks = lazy.value(() => {
|
|
||||||
return bscript.decompile(a.redeem.output);
|
|
||||||
});
|
|
||||||
let network = a.network;
|
let network = a.network;
|
||||||
if (!network) {
|
if (!network) {
|
||||||
network = (a.redeem && a.redeem.network) || networks_1.bitcoin;
|
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');
|
throw new TypeError('Witness and redeem.witness mismatch');
|
||||||
if (
|
if (
|
||||||
(a.redeem.input && _rchunks().some(chunkHasUncompressedPubkey)) ||
|
(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(
|
throw new TypeError(
|
||||||
'redeem.input or redeem.output contains uncompressed pubkey',
|
'redeem.input or redeem.output contains uncompressed pubkey',
|
||||||
|
|
|
@ -20,9 +20,13 @@ function stacksEqual(a: Buffer[], b: Buffer[]): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
function chunkHasUncompressedPubkey(chunk: StackElement): boolean {
|
function chunkHasUncompressedPubkey(chunk: StackElement): boolean {
|
||||||
if (Buffer.isBuffer(chunk) && chunk.length === 65) {
|
if (
|
||||||
if (ecc.isPoint(chunk)) return true;
|
Buffer.isBuffer(chunk) &&
|
||||||
else return false;
|
chunk.length === 65 &&
|
||||||
|
chunk[0] === 0x04 &&
|
||||||
|
ecc.isPoint(chunk)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -69,9 +73,6 @@ export function p2wsh(a: Payment, opts?: PaymentOpts): Payment {
|
||||||
const _rchunks = lazy.value(() => {
|
const _rchunks = lazy.value(() => {
|
||||||
return bscript.decompile(a.redeem!.input!);
|
return bscript.decompile(a.redeem!.input!);
|
||||||
}) as StackFunction;
|
}) as StackFunction;
|
||||||
const _rochunks = lazy.value(() => {
|
|
||||||
return bscript.decompile(a.redeem!.output!);
|
|
||||||
}) as StackFunction;
|
|
||||||
|
|
||||||
let network = a.network;
|
let network = a.network;
|
||||||
if (!network) {
|
if (!network) {
|
||||||
|
@ -202,7 +203,10 @@ export function p2wsh(a: Payment, opts?: PaymentOpts): Payment {
|
||||||
throw new TypeError('Witness and redeem.witness mismatch');
|
throw new TypeError('Witness and redeem.witness mismatch');
|
||||||
if (
|
if (
|
||||||
(a.redeem.input && _rchunks().some(chunkHasUncompressedPubkey)) ||
|
(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(
|
throw new TypeError(
|
||||||
'redeem.input or redeem.output contains uncompressed pubkey',
|
'redeem.input or redeem.output contains uncompressed pubkey',
|
||||||
|
|
Loading…
Add table
Reference in a new issue