MCPcopy Create free account
hub / github.com/NoteProtocol/NoteWallet / tweakSigner

Function tweakSigner

src/btc/btc-ecc.ts:16–40  ·  view source on GitHub ↗
(
  signer: bitcoin.Signer | ECPairInterface,
  opts: any = {}
)

Source from the content-addressed store, hash-verified

14export type {TapLeafScript} from "bip174/src/lib/interfaces";
15
16export function tweakSigner(
17 signer: bitcoin.Signer | ECPairInterface,
18 opts: any = {}
19): bitcoin.Signer {
20 // @ts-ignore
21 let privateKey: Uint8Array | undefined = signer.privateKey;
22 if (!privateKey) {
23 throw new Error("Private key is required for tweaking signer!");
24 }
25 if (signer.publicKey[0] === 3) {
26 privateKey = ecc.privateNegate(privateKey);
27 }
28
29 const tweakedPrivateKey = ecc.privateAdd(
30 privateKey,
31 tapTweakHash(toXOnly(signer.publicKey), opts.tweakHash)
32 );
33 if (!tweakedPrivateKey) {
34 throw new Error("Invalid tweaked private key!");
35 }
36
37 return ECPair.fromPrivateKey(Buffer.from(tweakedPrivateKey), {
38 network: opts.network,
39 });
40}
41
42export function tapTweakHash(pubKey: Buffer, h: Buffer | undefined): Buffer {
43 return bitcoin.crypto.taggedHash(

Callers 1

signPsbtInputFunction · 0.90

Calls 2

tapTweakHashFunction · 0.85
toXOnlyFunction · 0.85

Tested by

no test coverage detected