Skip to content

Commit 81edb73

Browse files
committed
improve taproot pub key parsing
1 parent 544e797 commit 81edb73

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

x/lending/types/taproot.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package types
22

33
import (
44
"encoding/hex"
5-
"fmt"
65

76
"github.com/decred/dcrd/dcrec/secp256k1/v4"
87

@@ -173,14 +172,13 @@ func GetPkScriptFromAddress(address string) ([]byte, error) {
173172
}
174173

175174
// GetPkScriptFromPubKey gets the pk script from the given taproot pubkey
176-
// Assume that the given pubkey is 32 bytes w/o 0x prefix
177175
func GetPkScriptFromPubKey(pubKeyHex string) ([]byte, error) {
178-
pubKey, err := hex.DecodeString(fmt.Sprintf("02%s", pubKeyHex))
176+
pubKey, err := hex.DecodeString(pubKeyHex)
179177
if err != nil {
180178
return nil, err
181179
}
182180

183-
parsedPubKey, err := secp256k1.ParsePubKey(pubKey)
181+
parsedPubKey, err := schnorr.ParsePubKey(pubKey)
184182
if err != nil {
185183
return nil, err
186184
}
@@ -192,12 +190,12 @@ func GetPkScriptFromPubKey(pubKeyHex string) ([]byte, error) {
192190

193191
// GetNUMSPoint gets the NUMS point
194192
func GetNUMSPoint() *btcec.PublicKey {
195-
pointBytes, err := hex.DecodeString(fmt.Sprintf("02%s", NUMS_POINT))
193+
pointBytes, err := hex.DecodeString(NUMS_POINT)
196194
if err != nil {
197195
panic(err)
198196
}
199197

200-
point, err := btcec.ParsePubKey(pointBytes)
198+
point, err := schnorr.ParsePubKey(pointBytes)
201199
if err != nil {
202200
panic(err)
203201
}

0 commit comments

Comments
 (0)