mirror of
https://github.com/luxfi/mpc.git
synced 2026-09-24 00:26:24 +00:00
Upgrade tss-lib to v2
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
package encoding
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcutil"
|
||||
)
|
||||
|
||||
func PublicKeyToBech32Address(publicKey *btcec.PublicKey, network *chaincfg.Params) (string, error) {
|
||||
// Create a P2WPKH (Pay-to-Witness-Public-Key-Hash) address from the public key
|
||||
address, err := btcutil.NewAddressWitnessPubKeyHash(btcutil.Hash160(publicKey.SerializeCompressed()), network)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return address.EncodeAddress(), nil
|
||||
}
|
||||
|
||||
func PublicKeyToP2SHSegWitAddress(publicKey *btcec.PublicKey, network *chaincfg.Params) (string, error) {
|
||||
// Create a P2WSH (Pay-to-Witness-Script-Hash) script
|
||||
pubKeyHash := btcutil.Hash160(publicKey.SerializeCompressed())
|
||||
segwitAddress, err := btcutil.NewAddressWitnessPubKeyHash(pubKeyHash, network)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
payToAddrScript, err := txscript.PayToAddrScript(segwitAddress)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// TODO: Redeem script, have no idea about it
|
||||
address, err := btcutil.NewAddressScriptHash(payToAddrScript, network)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return address.String(), nil
|
||||
}
|
||||
@@ -4,26 +4,26 @@ import (
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEncodeDecodeKey(t *testing.T) {
|
||||
// generate public key with ecdsa
|
||||
privateKey, err := btcec.NewPrivateKey(btcec.S256())
|
||||
privateKey, err := btcec.NewPrivateKey()
|
||||
if err != nil {
|
||||
log.Fatal("Error generating private key:", err)
|
||||
}
|
||||
|
||||
// Extract the public key from the private key
|
||||
publicKey := &privateKey.PublicKey
|
||||
publicKey := privateKey.PubKey()
|
||||
|
||||
encodedKey, err := EncodeS256PubKey(publicKey)
|
||||
encodedKey, err := EncodeS256PubKey(publicKey.ToECDSA())
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, encodedKey)
|
||||
|
||||
decodedPubKey, err := DecodeECDSAPubKey(encodedKey)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, publicKey.X, decodedPubKey.X)
|
||||
assert.Equal(t, publicKey.Y, decodedPubKey.Y)
|
||||
assert.Equal(t, publicKey.X(), decodedPubKey.X)
|
||||
assert.Equal(t, publicKey.Y(), decodedPubKey.Y)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user