javascript – The way to signal a message with privateKey on Bitcoin utilizing TS/JS?

0
31
javascript – The way to signal a message with privateKey on Bitcoin utilizing TS/JS?


I am attempting to signal the message to UniSat to this endpoint
Bind btcAddress and nftAddress.

Utilizing code like:

import * as bitcoin from 'bitcoinjs-lib';
import * as ecc from 'tiny-secp256k1';
import * as bitcoinMessage from 'bitcoinjs-message';
import { ECPairFactory } from 'ecpair';
import * as crypto from 'crypto';
import * as secp256k1 from 'tiny-secp256k1';

const ECPair = ECPairFactory(ecc);


operate signMessage(privateKeyWIF: string, message: string): string {
    const ecPair = ECPair.fromWIF(privateKeyWIF, bitcoin.networks.bitcoin);
    const privateKey = ecPair.privateKey;
    const compressed = ecPair.compressed;

    if (!privateKey) {
        throw new Error('Personal secret's lacking');
    }

    // Signal the message
    const signature = bitcoinMessage.signal(message, privateKey, compressed);

    // Encode the signature in base64
    const signatureCompact = signature.slice(1, 65).toString('hex');

    return signatureCompact;
}

const message: string = `Please affirm thatnPayment Deal with: ${paymentAddress}nOrdinals Deal with: ${ordinalsAddress}`;

const signature: string = signMessage(privateKey, message);

However on the response receiving:

{
  btcAddress: 'bc1q5fqwlf88dtu9qa2jkvwhjr94k07cerfau3mh9s',
  nftAddress: 'bc1p7n462ru9wtfgclwedfgp0eqe6w40pjwt7wvkxgdmzue2y6ptdkvsuzzmu2',
  signal: '732505d8a18002ec9b16600558457a1695c7b5b7b93b0001f566953fe8052c8b1d82d25d8233d675a8c22bacaa5858dab37b623d7fcccf5d58d8a80580d704af'
}
{
  code: -1,
  msg: 'Signature.fromCompact: Anticipated 64-byte hex',
  knowledge: null
}

What am I doing improper?

Thanks to your assist.

LEAVE A REPLY

Please enter your comment!
Please enter your name here