@btc-vision/transaction
Version:
OPNet transaction library allows you to create and sign transactions for the OPNet network.
21 lines (20 loc) • 861 B
JavaScript
import * as ecc from '@bitcoinerlab/secp256k1';
import { initEccLib, tapTweakHash, toXOnly } from '@btc-vision/bitcoin';
import { EcKeyPair } from '../keypair/EcKeyPair.js';
initEccLib(ecc);
export class TweakedSigner {
static tweakSigner(signer, opts = {}) {
let privateKey = signer.privateKey;
if (!privateKey) {
throw new Error('Private key is required for tweaking signer!');
}
if (signer.publicKey[0] === 3) {
privateKey = ecc.privateNegate(privateKey);
}
const tweakedPrivateKey = ecc.privateAdd(privateKey, tapTweakHash(toXOnly(Buffer.from(signer.publicKey)), opts.tweakHash));
if (!tweakedPrivateKey) {
throw new Error('Invalid tweaked private key!');
}
return EcKeyPair.fromPrivateKey(Buffer.from(tweakedPrivateKey), opts.network);
}
}