1- import { ECPairFactory } from 'ecpair' ;
2-
31import { Psbt as PsbtBase } from 'bip174' ;
42import * as varuint from 'bip174/src/lib/converter/varint' ;
53import {
@@ -15,7 +13,6 @@ import {
1513 TransactionFromBuffer ,
1614} from 'bip174/src/lib/interfaces' ;
1715import { checkForInput , checkForOutput } from 'bip174/src/lib/utils' ;
18- import { TinySecp256k1Interface as ECPairTinySecp256k1Interface } from 'ecpair' ;
1916
2017import { fromOutputScript , toOutputScript } from './address' ;
2118import { cloneBuffer , reverseBuffer } from './bufferutils' ;
@@ -24,7 +21,6 @@ import { bitcoin as btcNetwork, Network } from './networks';
2421import * as payments from './payments' ;
2522import * as bscript from './script' ;
2623import { Output , Transaction } from './transaction' ;
27- import { tapTweakHash } from './payments/taprootutils' ;
2824import { TinySecp256k1Interface } from './types' ;
2925
3026export interface TransactionInput {
@@ -782,40 +778,6 @@ export class Psbt {
782778 }
783779}
784780
785- /**
786- * Helper method for converting a normal Signer into a Taproot Signer.
787- * Note that this helper method requires the Private Key of the Signer to be present.
788- * Steps:
789- * - if the Y coordinate of the Signer Public Key is odd then negate the Private Key
790- * - tweak the private key with the provided hash (should be empty for key-path spending)
791- * @param signer - a taproot signer object, the Private Key must be present
792- * @param opts - tweak options
793- * @returns a Signer having the Private and Public keys tweaked
794- */
795- export function tweakSigner ( signer : Signer , opts : TaprootSignerOpts ) : Signer {
796- // todo: test ecc??
797- let privateKey : Uint8Array | undefined = signer . privateKey ;
798- if ( ! privateKey ) {
799- throw new Error ( 'Private key is required for tweaking signer!' ) ;
800- }
801- if ( signer . publicKey [ 0 ] === 3 ) {
802- privateKey = opts . eccLib . privateNegate ( privateKey ! ) ;
803- }
804-
805- const tweakedPrivateKey = opts . eccLib . privateAdd (
806- privateKey ,
807- tapTweakHash ( signer . publicKey . slice ( 1 , 33 ) , opts . tweakHash ) ,
808- ) ;
809- if ( ! tweakedPrivateKey ) {
810- throw new Error ( 'Invalid tweaked private key!' ) ;
811- }
812-
813- const ECPair = ECPairFactory ( opts . eccLib ) ;
814- return ECPair . fromPrivateKey ( Buffer . from ( tweakedPrivateKey ) , {
815- network : opts . network ,
816- } ) ;
817- }
818-
819781interface PsbtCache {
820782 __NON_WITNESS_UTXO_TX_CACHE : Transaction [ ] ;
821783 __NON_WITNESS_UTXO_BUF_CACHE : Buffer [ ] ;
@@ -889,25 +851,11 @@ export interface HDSignerAsync extends HDSignerBase {
889851
890852export interface Signer {
891853 publicKey : Buffer ;
892- /**
893- * Private Key is optional, it is required only if the signer must be tweaked.
894- * See the `tweakSigner()` method.
895- */
896- privateKey ?: Buffer ;
897854 network ?: any ;
898855 sign ( hash : Buffer , lowR ?: boolean ) : Buffer ;
899856 signSchnorr ?( hash : Buffer ) : Buffer ;
900857 getPublicKey ?( ) : Buffer ;
901858}
902- /**
903- * Options for tweaking a Signer into a valid Taproot Signer
904- */
905- export interface TaprootSignerOpts {
906- network ?: Network ;
907- eccLib : TinySecp256k1Interface & ECPairTinySecp256k1Interface ;
908- /** The hash used to tweak the Signer */
909- tweakHash ?: Buffer ;
910- }
911859
912860export interface SignerAsync {
913861 publicKey : Buffer ;
0 commit comments