Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary search for public key in witnessScript in signIdx function. #82

Open
Mister-EA opened this issue Mar 26, 2024 · 0 comments
Open

Comments

@Mister-EA
Copy link

There is a part of code in the signIdx function that searches for the public key of the signer in the witnessScript and throws an error if the public key is not found:

else {
      // only compressed keys are supported for now
      const pubKey = u.pubECDSA(privateKey);
      // TODO: replace with explicit checks
      // Check if script has public key or its has inside
      let hasPubkey = false;
      const pubKeyHash = u.hash160(pubKey);
      for (const i of Script.decode(inputType.lastScript)) {
        if (isBytes(i) && (P.equalBytes(i, pubKey) || P.equalBytes(i, pubKeyHash)))
          hasPubkey = true;
      }
      if (!hasPubkey) throw new Error(`Input script doesn't have pubKey: ${inputType.lastScript}`);

Is this check really necessary? I have a witnessScript that only contains addresses and opcodes. The subscripts are standard PayToAddr subscripts, so there are no public keys in them.

Would it be possible to have this check removed, since it prevents the signing process for no good reason?

For context my input is a wsh-unknown type. Since the unknown type script can be arbitrary, I don't see a reason why it has to contain the public key of the signer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant