Verifying the deal with and the message utilizing the general public key, deal with, and signature! – CoinNewsTrend

Verifying the deal with and the message utilizing the general public key, deal with, and signature!

[ad_1]

I am making an attempt to confirm possession of a Bitcoin deal with utilizing the general public key, signature, and the deal with (P2PKH, P2SH, P2WPKH, P2WSH, P2TR) as enter. Nevertheless, the code beneath doesn’t work for Bech32 addresses.

import BitCoinLib from 'bitcoinjs-lib';
import BitCoinMessage from 'bitcoinjs-message';

BitCoinMessage.confirm(message, deal with, signature);

As one other try, I attempted utilizing bitcore-lib, nevertheless it would not assist deal with verification. It solely accepts public key and signature as inputs.

import bitcore from 'bitcore-lib';

export operate 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 well 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 need to obtain is much like https://www.verifybitcoinmessage.com/, however that web site additionally has limitations because it can’t confirm P2WPKH addresses.

Is it potential to confirm all kinds of addresses? If that’s the case, please present steering on the best way to do it.

[ad_2]

Supply hyperlink