mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-03-21 15:49:23 +00:00
[NOD-876] Replace ecc with go-secp256k1 for public keys (#670)
* Replace ecc with go-secp256k1 in txscript * Replace ecc with go-secp256k1 in util and cmd * Replace ecc.Multiset with secp256k1.MultiSet
This commit is contained in:
@@ -10,11 +10,11 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/kaspanet/go-secp256k1"
|
||||
"hash"
|
||||
|
||||
"golang.org/x/crypto/ripemd160"
|
||||
|
||||
"github.com/kaspanet/kaspad/ecc"
|
||||
"github.com/kaspanet/kaspad/util/daghash"
|
||||
"github.com/kaspanet/kaspad/wire"
|
||||
)
|
||||
@@ -2033,36 +2033,34 @@ func opcodeCheckSig(op *parsedOpcode, vm *Engine) error {
|
||||
script := vm.currentScript()
|
||||
|
||||
// Generate the signature hash based on the signature hash type.
|
||||
hash, err := calcSignatureHash(script, hashType, &vm.tx, vm.txIdx)
|
||||
sigHash, err := calcSignatureHash(script, hashType, &vm.tx, vm.txIdx)
|
||||
if err != nil {
|
||||
vm.dstack.PushBool(false)
|
||||
return nil
|
||||
}
|
||||
|
||||
pubKey, err := ecc.ParsePubKey(pkBytes, ecc.S256())
|
||||
pubKey, err := secp256k1.DeserializeSchnorrPubKey(pkBytes)
|
||||
if err != nil {
|
||||
vm.dstack.PushBool(false)
|
||||
return nil
|
||||
}
|
||||
|
||||
signature, err := ecc.ParseSignature(sigBytes)
|
||||
signature, err := secp256k1.DeserializeSchnorrSignatureFromSlice(sigBytes)
|
||||
if err != nil {
|
||||
vm.dstack.PushBool(false)
|
||||
return nil
|
||||
}
|
||||
|
||||
var valid bool
|
||||
secpHash := secp256k1.Hash(*sigHash)
|
||||
if vm.sigCache != nil {
|
||||
var sigHash daghash.Hash
|
||||
copy(sigHash[:], hash)
|
||||
|
||||
valid = vm.sigCache.Exists(sigHash, signature, pubKey)
|
||||
if !valid && signature.Verify(hash, pubKey) {
|
||||
vm.sigCache.Add(sigHash, signature, pubKey)
|
||||
valid = vm.sigCache.Exists(secpHash, signature, pubKey)
|
||||
if !valid && pubKey.SchnorrVerify(&secpHash, signature) {
|
||||
vm.sigCache.Add(secpHash, signature, pubKey)
|
||||
valid = true
|
||||
}
|
||||
} else {
|
||||
valid = signature.Verify(hash, pubKey)
|
||||
valid = pubKey.SchnorrVerify(&secpHash, signature)
|
||||
}
|
||||
|
||||
if !valid && len(sigBytes) > 0 {
|
||||
@@ -2092,7 +2090,7 @@ func opcodeCheckSigVerify(op *parsedOpcode, vm *Engine) error {
|
||||
// the same signature multiple times when verifying a multisig.
|
||||
type parsedSigInfo struct {
|
||||
signature []byte
|
||||
parsedSignature *ecc.Signature
|
||||
parsedSignature *secp256k1.SchnorrSignature
|
||||
parsed bool
|
||||
}
|
||||
|
||||
@@ -2204,7 +2202,7 @@ func opcodeCheckMultiSig(op *parsedOpcode, vm *Engine) error {
|
||||
signature := rawSig[:len(rawSig)-1]
|
||||
|
||||
// Only parse and check the signature encoding once.
|
||||
var parsedSig *ecc.Signature
|
||||
var parsedSig *secp256k1.SchnorrSignature
|
||||
if !sigInfo.parsed {
|
||||
if err := vm.checkHashTypeEncoding(hashType); err != nil {
|
||||
return err
|
||||
@@ -2214,13 +2212,12 @@ func opcodeCheckMultiSig(op *parsedOpcode, vm *Engine) error {
|
||||
}
|
||||
|
||||
// Parse the signature.
|
||||
var err error
|
||||
parsedSig, err = ecc.ParseSignature(signature)
|
||||
|
||||
parsedSig, err = secp256k1.DeserializeSchnorrSignatureFromSlice(signature)
|
||||
sigInfo.parsed = true
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
sigInfo.parsedSignature = parsedSig
|
||||
} else {
|
||||
// Skip to the next pubkey if the signature is invalid.
|
||||
@@ -2237,29 +2234,28 @@ func opcodeCheckMultiSig(op *parsedOpcode, vm *Engine) error {
|
||||
}
|
||||
|
||||
// Parse the pubkey.
|
||||
parsedPubKey, err := ecc.ParsePubKey(pubKey, ecc.S256())
|
||||
parsedPubKey, err := secp256k1.DeserializeSchnorrPubKey(pubKey)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Generate the signature hash based on the signature hash type.
|
||||
hash, err := calcSignatureHash(script, hashType, &vm.tx, vm.txIdx)
|
||||
sigHash, err := calcSignatureHash(script, hashType, &vm.tx, vm.txIdx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
secpHash := secp256k1.Hash(*sigHash)
|
||||
var valid bool
|
||||
if vm.sigCache != nil {
|
||||
var sigHash daghash.Hash
|
||||
copy(sigHash[:], hash)
|
||||
|
||||
valid = vm.sigCache.Exists(sigHash, parsedSig, parsedPubKey)
|
||||
if !valid && parsedSig.Verify(hash, parsedPubKey) {
|
||||
vm.sigCache.Add(sigHash, parsedSig, parsedPubKey)
|
||||
valid = vm.sigCache.Exists(secpHash, parsedSig, parsedPubKey)
|
||||
if !valid && parsedPubKey.SchnorrVerify(&secpHash, parsedSig) {
|
||||
vm.sigCache.Add(secpHash, parsedSig, parsedPubKey)
|
||||
valid = true
|
||||
}
|
||||
} else {
|
||||
valid = parsedSig.Verify(hash, parsedPubKey)
|
||||
valid = parsedPubKey.SchnorrVerify(&secpHash, parsedSig)
|
||||
}
|
||||
|
||||
if valid {
|
||||
|
||||
@@ -285,7 +285,7 @@ func shallowCopyTx(tx *wire.MsgTx) wire.MsgTx {
|
||||
// CalcSignatureHash will, given a script and hash type for the current script
|
||||
// engine instance, calculate the signature hash to be used for signing and
|
||||
// verification.
|
||||
func CalcSignatureHash(script []byte, hashType SigHashType, tx *wire.MsgTx, idx int) ([]byte, error) {
|
||||
func CalcSignatureHash(script []byte, hashType SigHashType, tx *wire.MsgTx, idx int) (*daghash.Hash, error) {
|
||||
parsedScript, err := parseScript(script)
|
||||
if err != nil {
|
||||
return nil, errors.Errorf("cannot parse output script: %s", err)
|
||||
@@ -296,7 +296,7 @@ func CalcSignatureHash(script []byte, hashType SigHashType, tx *wire.MsgTx, idx
|
||||
// calcSignatureHash will, given a script and hash type for the current script
|
||||
// engine instance, calculate the signature hash to be used for signing and
|
||||
// verification.
|
||||
func calcSignatureHash(script []parsedOpcode, hashType SigHashType, tx *wire.MsgTx, idx int) ([]byte, error) {
|
||||
func calcSignatureHash(script []parsedOpcode, hashType SigHashType, tx *wire.MsgTx, idx int) (*daghash.Hash, error) {
|
||||
// The SigHashSingle signature type signs only the corresponding input
|
||||
// and output (the output with the same index number as the input).
|
||||
//
|
||||
@@ -367,7 +367,8 @@ func calcSignatureHash(script []parsedOpcode, hashType SigHashType, tx *wire.Msg
|
||||
wbuf := bytes.NewBuffer(make([]byte, 0, txCopy.SerializeSize()+4))
|
||||
txCopy.Serialize(wbuf)
|
||||
binary.Write(wbuf, binary.LittleEndian, hashType)
|
||||
return daghash.DoubleHashB(wbuf.Bytes()), nil
|
||||
hash := daghash.DoubleHashH(wbuf.Bytes())
|
||||
return &hash, nil
|
||||
}
|
||||
|
||||
// asSmallInt returns the passed opcode, which must be true according to
|
||||
|
||||
@@ -5,10 +5,8 @@
|
||||
package txscript
|
||||
|
||||
import (
|
||||
"github.com/kaspanet/go-secp256k1"
|
||||
"sync"
|
||||
|
||||
"github.com/kaspanet/kaspad/ecc"
|
||||
"github.com/kaspanet/kaspad/util/daghash"
|
||||
)
|
||||
|
||||
// sigCacheEntry represents an entry in the SigCache. Entries within the
|
||||
@@ -18,8 +16,8 @@ import (
|
||||
// match. In the occasion that two sigHashes collide, the newer sigHash will
|
||||
// simply overwrite the existing entry.
|
||||
type sigCacheEntry struct {
|
||||
sig *ecc.Signature
|
||||
pubKey *ecc.PublicKey
|
||||
sig *secp256k1.SchnorrSignature
|
||||
pubKey *secp256k1.SchnorrPublicKey
|
||||
}
|
||||
|
||||
// SigCache implements an ECDSA signature verification cache with a randomized
|
||||
@@ -34,7 +32,7 @@ type sigCacheEntry struct {
|
||||
// if they've already been seen and verified within the mempool.
|
||||
type SigCache struct {
|
||||
sync.RWMutex
|
||||
validSigs map[daghash.Hash]sigCacheEntry
|
||||
validSigs map[secp256k1.Hash]sigCacheEntry
|
||||
maxEntries uint
|
||||
}
|
||||
|
||||
@@ -45,7 +43,7 @@ type SigCache struct {
|
||||
// cache to exceed the max.
|
||||
func NewSigCache(maxEntries uint) *SigCache {
|
||||
return &SigCache{
|
||||
validSigs: make(map[daghash.Hash]sigCacheEntry, maxEntries),
|
||||
validSigs: make(map[secp256k1.Hash]sigCacheEntry, maxEntries),
|
||||
maxEntries: maxEntries,
|
||||
}
|
||||
}
|
||||
@@ -55,7 +53,7 @@ func NewSigCache(maxEntries uint) *SigCache {
|
||||
//
|
||||
// NOTE: This function is safe for concurrent access. Readers won't be blocked
|
||||
// unless there exists a writer, adding an entry to the SigCache.
|
||||
func (s *SigCache) Exists(sigHash daghash.Hash, sig *ecc.Signature, pubKey *ecc.PublicKey) bool {
|
||||
func (s *SigCache) Exists(sigHash secp256k1.Hash, sig *secp256k1.SchnorrSignature, pubKey *secp256k1.SchnorrPublicKey) bool {
|
||||
s.RLock()
|
||||
defer s.RUnlock()
|
||||
entry, ok := s.validSigs[sigHash]
|
||||
@@ -70,7 +68,7 @@ func (s *SigCache) Exists(sigHash daghash.Hash, sig *ecc.Signature, pubKey *ecc.
|
||||
//
|
||||
// NOTE: This function is safe for concurrent access. Writers will block
|
||||
// simultaneous readers until function execution has concluded.
|
||||
func (s *SigCache) Add(sigHash daghash.Hash, sig *ecc.Signature, pubKey *ecc.PublicKey) {
|
||||
func (s *SigCache) Add(sigHash secp256k1.Hash, sig *secp256k1.SchnorrSignature, pubKey *secp256k1.SchnorrPublicKey) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
|
||||
@@ -6,32 +6,35 @@ package txscript
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"github.com/kaspanet/go-secp256k1"
|
||||
"testing"
|
||||
|
||||
"github.com/kaspanet/kaspad/ecc"
|
||||
"github.com/kaspanet/kaspad/util/daghash"
|
||||
)
|
||||
|
||||
// genRandomSig returns a random message, a signature of the message under the
|
||||
// public key and the public key. This function is used to generate randomized
|
||||
// test data.
|
||||
func genRandomSig() (*daghash.Hash, *ecc.Signature, *ecc.PublicKey, error) {
|
||||
privKey, err := ecc.NewPrivateKey(ecc.S256())
|
||||
func genRandomSig() (*secp256k1.Hash, *secp256k1.SchnorrSignature, *secp256k1.SchnorrPublicKey, error) {
|
||||
privKey, err := secp256k1.GeneratePrivateKey()
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
var msgHash daghash.Hash
|
||||
msgHash := &secp256k1.Hash{}
|
||||
if _, err := rand.Read(msgHash[:]); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
sig, err := privKey.Sign(msgHash[:])
|
||||
sig, err := privKey.SchnorrSign(msgHash)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
return &msgHash, sig, privKey.PubKey(), nil
|
||||
pubkey, err := privKey.SchnorrPublicKey()
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
return msgHash, sig, pubkey, nil
|
||||
}
|
||||
|
||||
// TestSigCacheAddExists tests the ability to add, and later check the
|
||||
@@ -42,15 +45,16 @@ func TestSigCacheAddExists(t *testing.T) {
|
||||
// Generate a random sigCache entry triplet.
|
||||
msg1, sig1, key1, err := genRandomSig()
|
||||
if err != nil {
|
||||
t.Errorf("unable to generate random signature test data")
|
||||
t.Fatalf("unable to generate random signature test data")
|
||||
}
|
||||
|
||||
// Add the triplet to the signature cache.
|
||||
sigCache.Add(*msg1, sig1, key1)
|
||||
|
||||
// The previously added triplet should now be found within the sigcache.
|
||||
sig1Copy, _ := ecc.ParseSignature(sig1.Serialize())
|
||||
key1Copy, _ := ecc.ParsePubKey(key1.SerializeCompressed(), ecc.S256())
|
||||
sig1Copy := secp256k1.DeserializeSchnorrSignature(sig1.Serialize())
|
||||
key1Serialized, _ := key1.SerializeCompressed()
|
||||
key1Copy, _ := secp256k1.DeserializeSchnorrPubKey(key1Serialized)
|
||||
if !sigCache.Exists(*msg1, sig1Copy, key1Copy) {
|
||||
t.Errorf("previously added item not found in signature cache")
|
||||
}
|
||||
@@ -73,8 +77,9 @@ func TestSigCacheAddEvictEntry(t *testing.T) {
|
||||
|
||||
sigCache.Add(*msg, sig, key)
|
||||
|
||||
sigCopy, _ := ecc.ParseSignature(sig.Serialize())
|
||||
keyCopy, _ := ecc.ParsePubKey(key.SerializeCompressed(), ecc.S256())
|
||||
sigCopy := secp256k1.DeserializeSchnorrSignature(sig.Serialize())
|
||||
keySerialized, _ := key.SerializeCompressed()
|
||||
keyCopy, _ := secp256k1.DeserializeSchnorrPubKey(keySerialized)
|
||||
if !sigCache.Exists(*msg, sigCopy, keyCopy) {
|
||||
t.Errorf("previously added item not found in signature" +
|
||||
"cache")
|
||||
@@ -102,8 +107,9 @@ func TestSigCacheAddEvictEntry(t *testing.T) {
|
||||
}
|
||||
|
||||
// The entry added above should be found within the sigcache.
|
||||
sigNewCopy, _ := ecc.ParseSignature(sigNew.Serialize())
|
||||
keyNewCopy, _ := ecc.ParsePubKey(keyNew.SerializeCompressed(), ecc.S256())
|
||||
sigNewCopy := secp256k1.DeserializeSchnorrSignature(sigNew.Serialize())
|
||||
keyNewSerialized, _ := keyNew.SerializeCompressed()
|
||||
keyNewCopy, _ := secp256k1.DeserializeSchnorrPubKey(keyNewSerialized)
|
||||
if !sigCache.Exists(*msgNew, sigNewCopy, keyNewCopy) {
|
||||
t.Fatalf("previously added item not found in signature cache")
|
||||
}
|
||||
@@ -118,15 +124,16 @@ func TestSigCacheAddMaxEntriesZeroOrNegative(t *testing.T) {
|
||||
// Generate a random sigCache entry triplet.
|
||||
msg1, sig1, key1, err := genRandomSig()
|
||||
if err != nil {
|
||||
t.Errorf("unable to generate random signature test data")
|
||||
t.Fatalf("unable to generate random signature test data")
|
||||
}
|
||||
|
||||
// Add the triplet to the signature cache.
|
||||
sigCache.Add(*msg1, sig1, key1)
|
||||
|
||||
// The generated triplet should not be found.
|
||||
sig1Copy, _ := ecc.ParseSignature(sig1.Serialize())
|
||||
key1Copy, _ := ecc.ParsePubKey(key1.SerializeCompressed(), ecc.S256())
|
||||
sig1Copy := secp256k1.DeserializeSchnorrSignature(sig1.Serialize())
|
||||
key1Serialized, _ := key1.SerializeCompressed()
|
||||
key1Copy, _ := secp256k1.DeserializeSchnorrPubKey(key1Serialized)
|
||||
if sigCache.Exists(*msg1, sig1Copy, key1Copy) {
|
||||
t.Errorf("previously added signature found in sigcache, but" +
|
||||
"shouldn't have been")
|
||||
|
||||
@@ -5,29 +5,30 @@
|
||||
package txscript
|
||||
|
||||
import (
|
||||
"github.com/kaspanet/go-secp256k1"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/kaspanet/kaspad/dagconfig"
|
||||
"github.com/kaspanet/kaspad/ecc"
|
||||
"github.com/kaspanet/kaspad/util"
|
||||
"github.com/kaspanet/kaspad/wire"
|
||||
)
|
||||
|
||||
// RawTxInSignature returns the serialized ECDSA signature for the input idx of
|
||||
// RawTxInSignature returns the serialized Schnorr signature for the input idx of
|
||||
// the given transaction, with hashType appended to it.
|
||||
func RawTxInSignature(tx *wire.MsgTx, idx int, script []byte,
|
||||
hashType SigHashType, key *ecc.PrivateKey) ([]byte, error) {
|
||||
hashType SigHashType, key *secp256k1.PrivateKey) ([]byte, error) {
|
||||
|
||||
hash, err := CalcSignatureHash(script, hashType, tx, idx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
signature, err := key.Sign(hash)
|
||||
secpHash := secp256k1.Hash(*hash)
|
||||
signature, err := key.SchnorrSign(&secpHash)
|
||||
if err != nil {
|
||||
return nil, errors.Errorf("cannot sign tx input: %s", err)
|
||||
}
|
||||
|
||||
return append(signature.Serialize(), byte(hashType)), nil
|
||||
return append(signature.Serialize()[:], byte(hashType)), nil
|
||||
}
|
||||
|
||||
// SignatureScript creates an input signature script for tx to spend KAS sent
|
||||
@@ -38,18 +39,24 @@ func RawTxInSignature(tx *wire.MsgTx, idx int, script []byte,
|
||||
// as the idx'th input. privKey is serialized in either a compressed or
|
||||
// uncompressed format based on compress. This format must match the same format
|
||||
// used to generate the payment address, or the script validation will fail.
|
||||
func SignatureScript(tx *wire.MsgTx, idx int, script []byte, hashType SigHashType, privKey *ecc.PrivateKey, compress bool) ([]byte, error) {
|
||||
func SignatureScript(tx *wire.MsgTx, idx int, script []byte, hashType SigHashType, privKey *secp256k1.PrivateKey, compress bool) ([]byte, error) {
|
||||
sig, err := RawTxInSignature(tx, idx, script, hashType, privKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pk := (*ecc.PublicKey)(&privKey.PublicKey)
|
||||
pk, err := privKey.SchnorrPublicKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var pkData []byte
|
||||
if compress {
|
||||
pkData = pk.SerializeCompressed()
|
||||
pkData, err = pk.SerializeCompressed()
|
||||
} else {
|
||||
pkData = pk.SerializeUncompressed()
|
||||
pkData, err = pk.SerializeUncompressed()
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewScriptBuilder().AddData(sig).AddData(pkData).Script()
|
||||
@@ -159,14 +166,14 @@ func mergeScripts(dagParams *dagconfig.Params, tx *wire.MsgTx, idx int,
|
||||
// KeyDB is an interface type provided to SignTxOutput, it encapsulates
|
||||
// any user state required to get the private keys for an address.
|
||||
type KeyDB interface {
|
||||
GetKey(util.Address) (*ecc.PrivateKey, bool, error)
|
||||
GetKey(util.Address) (*secp256k1.PrivateKey, bool, error)
|
||||
}
|
||||
|
||||
// KeyClosure implements KeyDB with a closure.
|
||||
type KeyClosure func(util.Address) (*ecc.PrivateKey, bool, error)
|
||||
type KeyClosure func(util.Address) (*secp256k1.PrivateKey, bool, error)
|
||||
|
||||
// GetKey implements KeyDB by returning the result of calling the closure.
|
||||
func (kc KeyClosure) GetKey(address util.Address) (*ecc.PrivateKey,
|
||||
func (kc KeyClosure) GetKey(address util.Address) (*secp256k1.PrivateKey,
|
||||
bool, error) {
|
||||
return kc(address)
|
||||
}
|
||||
|
||||
@@ -6,29 +6,29 @@ package txscript
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/kaspanet/go-secp256k1"
|
||||
"github.com/pkg/errors"
|
||||
"testing"
|
||||
|
||||
"github.com/kaspanet/kaspad/dagconfig"
|
||||
"github.com/kaspanet/kaspad/ecc"
|
||||
"github.com/kaspanet/kaspad/util"
|
||||
"github.com/kaspanet/kaspad/util/daghash"
|
||||
"github.com/kaspanet/kaspad/wire"
|
||||
)
|
||||
|
||||
type addressToKey struct {
|
||||
key *ecc.PrivateKey
|
||||
key *secp256k1.PrivateKey
|
||||
compressed bool
|
||||
}
|
||||
|
||||
func mkGetKey(keys map[string]addressToKey) KeyDB {
|
||||
if keys == nil {
|
||||
return KeyClosure(func(addr util.Address) (*ecc.PrivateKey,
|
||||
return KeyClosure(func(addr util.Address) (*secp256k1.PrivateKey,
|
||||
bool, error) {
|
||||
return nil, false, errors.New("nope")
|
||||
})
|
||||
}
|
||||
return KeyClosure(func(addr util.Address) (*ecc.PrivateKey,
|
||||
return KeyClosure(func(addr util.Address) (*secp256k1.PrivateKey,
|
||||
bool, error) {
|
||||
a2k, ok := keys[addr.EncodeAddress()]
|
||||
if !ok {
|
||||
@@ -139,17 +139,29 @@ func TestSignTxOutput(t *testing.T) {
|
||||
for _, hashType := range hashTypes {
|
||||
for i := range tx.TxIn {
|
||||
msg := fmt.Sprintf("%d:%d", hashType, i)
|
||||
key, err := ecc.NewPrivateKey(ecc.S256())
|
||||
key, err := secp256k1.GeneratePrivateKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make privKey for %s: %v",
|
||||
t.Errorf("failed to make privKey for %s: %s",
|
||||
msg, err)
|
||||
break
|
||||
}
|
||||
|
||||
pk := (*ecc.PublicKey)(&key.PublicKey).
|
||||
SerializeUncompressed()
|
||||
pubKey, err := key.SchnorrPublicKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a publickey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
|
||||
uncompressedPubKey, err := pubKey.SerializeUncompressed()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a pubkey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
|
||||
address, err := util.NewAddressPubKeyHash(
|
||||
util.Hash160(pk), util.Bech32PrefixKaspaTest)
|
||||
util.Hash160(uncompressedPubKey), util.Bech32PrefixKaspaTest)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@@ -176,17 +188,28 @@ func TestSignTxOutput(t *testing.T) {
|
||||
for _, hashType := range hashTypes {
|
||||
for i := range tx.TxIn {
|
||||
msg := fmt.Sprintf("%d:%d", hashType, i)
|
||||
key, err := ecc.NewPrivateKey(ecc.S256())
|
||||
key, err := secp256k1.GeneratePrivateKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make privKey for %s: %v",
|
||||
t.Errorf("failed to make privKey for %s: %s",
|
||||
msg, err)
|
||||
break
|
||||
}
|
||||
|
||||
pk := (*ecc.PublicKey)(&key.PublicKey).
|
||||
SerializeUncompressed()
|
||||
pubKey, err := key.SchnorrPublicKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a publickey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
|
||||
uncompressedPubKey, err := pubKey.SerializeUncompressed()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a pubkey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
address, err := util.NewAddressPubKeyHash(
|
||||
util.Hash160(pk), util.Bech32PrefixKaspaTest)
|
||||
util.Hash160(uncompressedPubKey), util.Bech32PrefixKaspaTest)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@@ -237,17 +260,29 @@ func TestSignTxOutput(t *testing.T) {
|
||||
for i := range tx.TxIn {
|
||||
msg := fmt.Sprintf("%d:%d", hashType, i)
|
||||
|
||||
key, err := ecc.NewPrivateKey(ecc.S256())
|
||||
key, err := secp256k1.GeneratePrivateKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make privKey for %s: %v",
|
||||
t.Errorf("failed to make privKey for %s: %s",
|
||||
msg, err)
|
||||
break
|
||||
}
|
||||
|
||||
pk := (*ecc.PublicKey)(&key.PublicKey).
|
||||
SerializeCompressed()
|
||||
pubKey, err := key.SchnorrPublicKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a publickey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
|
||||
compressedPubKey, err := pubKey.SerializeCompressed()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a pubkey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
|
||||
address, err := util.NewAddressPubKeyHash(
|
||||
util.Hash160(pk), util.Bech32PrefixKaspaTest)
|
||||
util.Hash160(compressedPubKey), util.Bech32PrefixKaspaTest)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@@ -275,17 +310,29 @@ func TestSignTxOutput(t *testing.T) {
|
||||
for i := range tx.TxIn {
|
||||
msg := fmt.Sprintf("%d:%d", hashType, i)
|
||||
|
||||
key, err := ecc.NewPrivateKey(ecc.S256())
|
||||
key, err := secp256k1.GeneratePrivateKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make privKey for %s: %v",
|
||||
t.Errorf("failed to make privKey for %s: %s",
|
||||
msg, err)
|
||||
break
|
||||
}
|
||||
|
||||
pk := (*ecc.PublicKey)(&key.PublicKey).
|
||||
SerializeCompressed()
|
||||
pubKey, err := key.SchnorrPublicKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a publickey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
|
||||
compressedPubKey, err := pubKey.SerializeCompressed()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a pubkey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
|
||||
address, err := util.NewAddressPubKeyHash(
|
||||
util.Hash160(pk), util.Bech32PrefixKaspaTest)
|
||||
util.Hash160(compressedPubKey), util.Bech32PrefixKaspaTest)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@@ -336,17 +383,29 @@ func TestSignTxOutput(t *testing.T) {
|
||||
for _, hashType := range hashTypes {
|
||||
for i := range tx.TxIn {
|
||||
msg := fmt.Sprintf("%d:%d", hashType, i)
|
||||
key, err := ecc.NewPrivateKey(ecc.S256())
|
||||
key, err := secp256k1.GeneratePrivateKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make privKey for %s: %v",
|
||||
t.Errorf("failed to make privKey for %s: %s",
|
||||
msg, err)
|
||||
break
|
||||
}
|
||||
|
||||
pk := (*ecc.PublicKey)(&key.PublicKey).
|
||||
SerializeUncompressed()
|
||||
pubKey, err := key.SchnorrPublicKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a publickey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
|
||||
uncompressedPubKey, err := pubKey.SerializeUncompressed()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a pubkey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
|
||||
address, err := util.NewAddressPubKeyHash(
|
||||
util.Hash160(pk), util.Bech32PrefixKaspaTest)
|
||||
util.Hash160(uncompressedPubKey), util.Bech32PrefixKaspaTest)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@@ -392,17 +451,29 @@ func TestSignTxOutput(t *testing.T) {
|
||||
for _, hashType := range hashTypes {
|
||||
for i := range tx.TxIn {
|
||||
msg := fmt.Sprintf("%d:%d", hashType, i)
|
||||
key, err := ecc.NewPrivateKey(ecc.S256())
|
||||
key, err := secp256k1.GeneratePrivateKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make privKey for %s: %v",
|
||||
t.Errorf("failed to make privKey for %s: %s",
|
||||
msg, err)
|
||||
break
|
||||
}
|
||||
|
||||
pk := (*ecc.PublicKey)(&key.PublicKey).
|
||||
SerializeUncompressed()
|
||||
pubKey, err := key.SchnorrPublicKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a publickey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
|
||||
uncompressedPubKey, err := pubKey.SerializeUncompressed()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a pubkey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
|
||||
address, err := util.NewAddressPubKeyHash(
|
||||
util.Hash160(pk), util.Bech32PrefixKaspaTest)
|
||||
util.Hash160(uncompressedPubKey), util.Bech32PrefixKaspaTest)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@@ -474,17 +545,29 @@ func TestSignTxOutput(t *testing.T) {
|
||||
for i := range tx.TxIn {
|
||||
msg := fmt.Sprintf("%d:%d", hashType, i)
|
||||
|
||||
key, err := ecc.NewPrivateKey(ecc.S256())
|
||||
key, err := secp256k1.GeneratePrivateKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make privKey for %s: %v",
|
||||
t.Errorf("failed to make privKey for %s: %s",
|
||||
msg, err)
|
||||
break
|
||||
}
|
||||
|
||||
pk := (*ecc.PublicKey)(&key.PublicKey).
|
||||
SerializeCompressed()
|
||||
pubKey, err := key.SchnorrPublicKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a publickey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
|
||||
compressedPubKey, err := pubKey.SerializeCompressed()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a pubkey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
|
||||
address, err := util.NewAddressPubKeyHash(
|
||||
util.Hash160(pk), util.Bech32PrefixKaspaTest)
|
||||
util.Hash160(compressedPubKey), util.Bech32PrefixKaspaTest)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@@ -530,17 +613,29 @@ func TestSignTxOutput(t *testing.T) {
|
||||
for i := range tx.TxIn {
|
||||
msg := fmt.Sprintf("%d:%d", hashType, i)
|
||||
|
||||
key, err := ecc.NewPrivateKey(ecc.S256())
|
||||
key, err := secp256k1.GeneratePrivateKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make privKey for %s: %v",
|
||||
t.Errorf("failed to make privKey for %s: %s",
|
||||
msg, err)
|
||||
break
|
||||
}
|
||||
|
||||
pk := (*ecc.PublicKey)(&key.PublicKey).
|
||||
SerializeCompressed()
|
||||
pubKey, err := key.SchnorrPublicKey()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a publickey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
|
||||
compressedPubKey, err := pubKey.SerializeCompressed()
|
||||
if err != nil {
|
||||
t.Errorf("failed to make a pubkey for %s: %s",
|
||||
key, err)
|
||||
break
|
||||
}
|
||||
|
||||
address, err := util.NewAddressPubKeyHash(
|
||||
util.Hash160(pk), util.Bech32PrefixKaspaTest)
|
||||
util.Hash160(compressedPubKey), util.Bech32PrefixKaspaTest)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@@ -629,7 +724,7 @@ var coinbaseOutpoint = &wire.Outpoint{
|
||||
// Pregenerated private key, with associated public key and scriptPubKeys
|
||||
// for the uncompressed and compressed hash160.
|
||||
var (
|
||||
privKeyD = []byte{0x6b, 0x0f, 0xd8, 0xda, 0x54, 0x22, 0xd0, 0xb7,
|
||||
privKeyD = secp256k1.SerializedPrivateKey{0x6b, 0x0f, 0xd8, 0xda, 0x54, 0x22, 0xd0, 0xb7,
|
||||
0xb4, 0xfc, 0x4e, 0x55, 0xd4, 0x88, 0x42, 0xb3, 0xa1, 0x65,
|
||||
0xac, 0x70, 0x7f, 0x3d, 0xa4, 0x39, 0x5e, 0xcb, 0x3b, 0xb0,
|
||||
0xd6, 0x0e, 0x06, 0x92}
|
||||
@@ -864,7 +959,7 @@ var sigScriptTests = []tstSigScript{
|
||||
func TestSignatureScript(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
privKey, _ := ecc.PrivKeyFromBytes(ecc.S256(), privKeyD)
|
||||
privKey, _ := secp256k1.DeserializePrivateKey(&privKeyD)
|
||||
|
||||
nexttest:
|
||||
for i := range sigScriptTests {
|
||||
|
||||
Reference in New Issue
Block a user