bitcoinjs-message
makes use of conventional signing course of which merely signal message with prefix(if not given) x18Bitcoin Signed Message:n
. This sort of signing schema has been frequent however has limitation because it solely helps p2pkh. There are implementations which assist different sort of handle with this schema(bitcoinjs-message
additionally helps p2wpkh and p2sh-p2wpkh, however not p2tr), however there is not any strict normal for it.
BIP322 suggests a brand new manner of signing schema, during which digital transaction is required to signal and confirm all varieties of addresses whereas p2pkh makes use of conventional signing course of. Nevertheless, it is nonetheless in growth and never but carried out in bitcoin-core as I do know.
I used to be additionally searching for bip322 message signing library, and simply find yourself implementing it on my own. When you want you should use it. My open supply bitcoin-sdk-js
has a function of bip322 signing and verifying message with javascript, which assist p2pkh, p2wpkh and p2tr. It is verified with bip322 check vector so you should use it. I might attempt to observe growth of bitcoin-core. Watch out as BIP322 itself is in transition.
Under is find out how to implement.
import * as bitcoin from 'bitcoin-sdk-js'
const keyPair = await bitcoin.pockets.generateKeyPair();
const privkey = keyPair.privateKey;
const pubkey = keyPair.publicKey;
const legacyAddress = await bitcoin.handle.generateAddress(
pubkey,
'legacy',
);
const segwitAddress = await bitcoin.handle.generateAddress(
pubkey,
'segwit',
);
const tapAddress = await bitcoin.handle.generateAddress(
(
await bitcoin.tapscript.getTapTweakedPubkey(
pubkey.slice(2),
await bitcoin.tapscript.getTapTweak(pubkey.slice(2)),
)
).tweakedPubKey,
'taproot',
);
const msg = 'message you wish to signal';
// When
const sigLegacy = await bitcoin.crypto.signMessage(
msg,
privkey,
legacyAddress,
);
const sigSegwit = await bitcoin.crypto.signMessage(
msg,
privkey,
segwitAddress,
);
const sigTap = await bitcoin.crypto.signMessage(msg, privkey, tapAddress);
// Then
assert.strictEqual(
await bitcoin.crypto.verifyMessage(msg, sigLegacy, legacyAddress),
true,
);
assert.strictEqual(
await bitcoin.crypto.verifyMessage(msg, sigSegwit, segwitAddress),
true,
);
assert.strictEqual(
await bitcoin.crypto.verifyMessage(msg, sigTap, tapAddress),
true,
);
p.s. I believe the web site you refer might need a problem with non-ASCII encoding, I like to recommend this web site to check conventional message signing.