Utilizing wallets like XVerse, customers can signal a message utilizing their ordinal btc handle, as an instance bc1XXX, the message is hashed primarily based on BIP0322.
So I’ve:
- Person pockets: bc1XXX
- Message hash: YYY
- Signature signed by bc1XXX: ZZZ
So this knowledge is distributed to my backend server, and I wish to confirm that ZZZ was certainly signed by bc1XXX (and incorporates YYY as message).
I am utilizing this up to now:
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 match with my unique pubkey that signed the message
However I’ve a tough time getting the proper handle from recoveredPublicKeyBuffer
which I can not match with the general public key handle of my take a look at set.
I am making an attempt to make use of this perform, however the output does not match my pubkey:
perform publicKeyToTaprootAddress(publicKey: Uint8Array) {
// Compute the SHA-256 hash of the general public key
const hash = sha256(Buffer.from(publicKey));
// Assemble the human-readable half and the info 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
return bech32m.encode(hrp, data2);
}