I am making an attempt to confirm possession of a Bitcoin handle utilizing the general public key, signature, and the handle (P2PKH, P2SH, P2WPKH, P2WSH, P2TR) as enter. Nevertheless, the code under doesn’t work for Bech32 addresses.
import BitCoinLib from 'bitcoinjs-lib';
import BitCoinMessage from 'bitcoinjs-message';
BitCoinMessage.confirm(message, handle, signature);
As one other try, I attempted utilizing bitcore-lib, however it does not help handle verification. It solely accepts public key and signature as inputs.
import bitcore from 'bitcore-lib';
export perform verifyMessage(publicKey, sig, textual content) {
const message = new bitcore.Message(textual content);
var signature = bitcore.crypto.Signature.fromCompact(
Buffer.from(sig, "base64")
);
var hash = message.magicHash();
// get better the general public key
var ecdsa = new bitcore.crypto.ECDSA();
ecdsa.hashbuf = hash;
ecdsa.sig = signature;
const pubkeyInSig = ecdsa.toPublicKey();
const pubkeyInSigString = new bitcore.PublicKey(
Object.assign({}, pubkeyInSig.toObject(), { compressed: true })
).toString();
if (pubkeyInSigString != publicKey) {
return false;
}
return bitcore.crypto.ECDSA.confirm(hash, signature, pubkeyInSig);
}
What I wish to obtain is much like https://www.verifybitcoinmessage.com/, however that website additionally has limitations because it can’t confirm P2WPKH addresses.
Is it doable to confirm all varieties of addresses? If that’s the case, please present steerage on tips on how to do it.