@@ -5,9 +5,13 @@ import (
55
66 sdk "github.com/cosmos/cosmos-sdk/types"
77
8+ "github.com/btcsuite/btcd/btcec/v2"
89 "github.com/btcsuite/btcd/btcutil"
910 "github.com/btcsuite/btcd/chaincfg"
1011 "github.com/btcsuite/btcd/txscript"
12+
13+ "github.com/sideprotocol/side/crypto/hash"
14+ "github.com/sideprotocol/side/x/dlc/types"
1115)
1216
1317func HashLoanSecret (secret string ) string {
@@ -103,8 +107,9 @@ func createTaprootAddress(branches [][]byte, params *chaincfg.Params) (string, e
103107 if err != nil {
104108 return "" , err
105109 }
110+
106111 // Derive Taproot output key
107- taprootPubKey := txscript .ComputeTaprootOutputKey (nil , scriptRoot )
112+ taprootPubKey := txscript .ComputeTaprootOutputKey (GetInternalKey () , scriptRoot )
108113 // Generate Taproot address
109114 address , err := btcutil .NewAddressTaproot (taprootPubKey .SerializeCompressed (), params )
110115 if err != nil {
@@ -138,3 +143,19 @@ func CreateVaultAddress(borrowerPubkey string, dcaPubkey string, loanSecretHash
138143 }
139144 return taprootAddress , nil
140145}
146+
147+ // GetInternalKey gets the pub key used for taproot address generation
148+ // Generated by hash("lending") * G for now
149+ func GetInternalKey () * btcec.PublicKey {
150+ hash := hash .Sha256 ([]byte (types .ModuleName ))
151+
152+ var s btcec.ModNScalar
153+ s .SetByteSlice (hash [:])
154+
155+ var p btcec.JacobianPoint
156+ btcec .ScalarBaseMultNonConst (& s , & p )
157+
158+ p .ToAffine ()
159+
160+ return btcec .NewPublicKey (& p .X , & p .Y )
161+ }
0 commit comments