@@ -5,9 +5,13 @@ import (
5
5
6
6
sdk "github.com/cosmos/cosmos-sdk/types"
7
7
8
+ "github.com/btcsuite/btcd/btcec/v2"
8
9
"github.com/btcsuite/btcd/btcutil"
9
10
"github.com/btcsuite/btcd/chaincfg"
10
11
"github.com/btcsuite/btcd/txscript"
12
+
13
+ "github.com/sideprotocol/side/crypto/hash"
14
+ "github.com/sideprotocol/side/x/dlc/types"
11
15
)
12
16
13
17
func HashLoanSecret (secret string ) string {
@@ -103,8 +107,9 @@ func createTaprootAddress(branches [][]byte, params *chaincfg.Params) (string, e
103
107
if err != nil {
104
108
return "" , err
105
109
}
110
+
106
111
// Derive Taproot output key
107
- taprootPubKey := txscript .ComputeTaprootOutputKey (nil , scriptRoot )
112
+ taprootPubKey := txscript .ComputeTaprootOutputKey (GetInternalKey () , scriptRoot )
108
113
// Generate Taproot address
109
114
address , err := btcutil .NewAddressTaproot (taprootPubKey .SerializeCompressed (), params )
110
115
if err != nil {
@@ -138,3 +143,19 @@ func CreateVaultAddress(borrowerPubkey string, dcaPubkey string, loanSecretHash
138
143
}
139
144
return taprootAddress , nil
140
145
}
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