Closed
Description
Given a private key (in Hex of WIF format) is there a way to get BitcoinJS to generate the corresponding Taproot (P2TR) address for that?
I sortof extracted this from the Taproot Key Spend example:
const dummyExampleWif = 'L4m2jm8B2vnN5c3FCaCRtbk7Ao9tavipfKKJZTecwLKAQzpGWBT7';
const keyPair = ECPair.fromWIF( dummyExampleWif );
// or: const keyPair = ECPair.makeRandom();
const output = Buffer.concat([
// witness v1, PUSH_DATA 32 bytes
Buffer.from([0x51, 0x20]),
// x-only pubkey (remove 1 byte y parity)
keyPair.publicKey.slice(1, 33),
]);
const p2trAddress = address.fromOutputScript( output );
However this results in an error:
Uncaught Error: OP_1 9902b7ca58529074db3c0e98f6101753f5978be6ff9ab9acdf8aee7539468048 has no matching Address
What am I doing wrong here?
P.S. I'm using bitcoinjs-lib 4.0.3.
Metadata
Metadata
Assignees
Labels
No labels