function pubkeyPositionInScript(pubkey, script) {
  const pubkeyHash = hash160(pubkey);
  const pubkeyXOnly = pubkey.slice(1, 33); // slice before calling?
  const decompiled = bscript.decompile(script);
  if (decompiled === null) throw new Error('Unknown script error');
  return decompiled.findIndex(element => {
    if (typeof element === 'number') return false;
    return (
      tools.compare(pubkey, element) === 0 ||
      tools.compare(pubkeyHash, element) === 0 ||
      tools.compare(pubkeyXOnly, element) === 0
    );
  });
}
Finds the position of a public key in a script.
@param pubkey The public key to search for.
@param script The script to search in.
@returns The index of the public key in the script, or -1 if not found.
@throws {Error} If there is an unknown script error.