mirror of
https://github.com/arnaucube/kesto.git
synced 2026-02-07 19:46:40 +01:00
Add secp256k1 check of pubk for btcec & go-blindsecp256k1
This commit is contained in:
63
pubk-comp-ethereum-blindsigsecp256k1/check_test.go
Normal file
63
pubk-comp-ethereum-blindsigsecp256k1/check_test.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/arnaucube/go-blindsecp256k1"
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func calculateKeysFromK(t *testing.T, k *big.Int) (*btcec.PublicKey, *blindsecp256k1.PublicKey) {
|
||||
curve := btcec.S256()
|
||||
|
||||
x, y := curve.ScalarBaseMult(k.Bytes())
|
||||
|
||||
skEth := (*btcec.PrivateKey)(&ecdsa.PrivateKey{
|
||||
PublicKey: ecdsa.PublicKey{
|
||||
Curve: curve,
|
||||
X: x,
|
||||
Y: y,
|
||||
},
|
||||
D: k,
|
||||
})
|
||||
pkEthAux := (*btcec.PublicKey)(&skEth.PublicKey)
|
||||
pkEth := skEth.PubKey()
|
||||
assert.Equal(t, pkEth, pkEthAux)
|
||||
|
||||
skBlind := blindsecp256k1.PrivateKey(*k)
|
||||
pkBlind := skBlind.Public()
|
||||
|
||||
return pkEth, pkBlind
|
||||
}
|
||||
|
||||
func TestCompatibleKeys(t *testing.T) {
|
||||
// using incremental k
|
||||
for i := 0; i < 10000; i++ {
|
||||
k := big.NewInt(int64(i))
|
||||
|
||||
pkEth, pkBlind := calculateKeysFromK(t, k)
|
||||
assert.Equal(t, pkEth.X.String(), pkBlind.X.String())
|
||||
assert.Equal(t, pkEth.Y.String(), pkBlind.Y.String())
|
||||
// fmt.Println("k", k)
|
||||
// fmt.Println(pkEth)
|
||||
// fmt.Println(pkBlind)
|
||||
}
|
||||
|
||||
// using random k
|
||||
for i := 0; i < 10000; i++ {
|
||||
kaux, err := btcec.NewPrivateKey(btcec.S256())
|
||||
require.NoError(t, err)
|
||||
k := kaux.D
|
||||
|
||||
pkEth, pkBlind := calculateKeysFromK(t, k)
|
||||
assert.Equal(t, pkEth.X.String(), pkBlind.X.String())
|
||||
assert.Equal(t, pkEth.Y.String(), pkBlind.Y.String())
|
||||
// fmt.Println("k", k)
|
||||
// fmt.Println(pkEth)
|
||||
// fmt.Println(pkBlind)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user