The usage of wallets like XVerse, customers can signal a message the use of their ordinal btc cope with, shall we say bc1XXX, the message is hashed in line with BIP0322.
So I’ve:
- Person pockets: bc1XXX
- Message hash: YYY
- Signature signed by way of bc1XXX: ZZZ
So this information is distributed to my backend server, and I wish to test that ZZZ used to be certainly signed by way of bc1XXX (and accommodates YYY as message).
I am the use of this to this point:
const msgHash = bip0322Hash(message);
const signatureBuffer = Buffer.from(signatureStr, 'base64');
const decodedSignature = signatureBuffer.slice(2, 66);
const recoveryId = signatureBuffer[0];
// Extract public key from the signature
const recoveredPublicKeyBuffer = secp.recoverPublicKey(
msgHash,
decodedSignature,
recoveryId, // Restoration ID (0 or 1)
false
);
console.log(publicKeyToTaprootAddress(recoveredPublicKeyBuffer)); //no fit with my authentic pubkey that signed the message
However I’ve a troublesome time getting the right kind cope with from recoveredPublicKeyBuffer
which I will be able to’t fit with the general public key cope with of my check set.
I am making an attempt to make use of this serve as, however the output does not fit my pubkey:
serve as publicKeyToTaprootAddress(publicKey: Uint8Array) {
// Compute the SHA-256 hash of the general public key
const hash = sha256(Buffer.from(publicKey));
// Assemble the human-readable section and the information a part of the Bech32m string
const hrp = 'bc';
const knowledge = sha256(Buffer.from([0x01].concat(Array.from(hash))));
const data2 = bech32m.toWords(Buffer.from(knowledge));
// Encode the Bech32m string
go back bech32m.encode(hrp, data2);
}