mirror of
https://github.com/arnaucube/go-blindsecp256k1.git
synced 2026-02-07 03:26:40 +01:00
Add test hash odd bytes for js compatibility
To ensure compatibility with https://github.com/arnaucube/blindsecp256k1-js/
This commit is contained in:
@@ -157,8 +157,8 @@ type UserSecretData struct {
|
|||||||
|
|
||||||
// Blind performs the blinding operation on m using signerR parameter
|
// Blind performs the blinding operation on m using signerR parameter
|
||||||
func Blind(m *big.Int, signerR *Point) (*big.Int, *UserSecretData, error) {
|
func Blind(m *big.Int, signerR *Point) (*big.Int, *UserSecretData, error) {
|
||||||
if !btcec.S256().IsOnCurve(signerR.X, signerR.Y) {
|
if err := signerR.isValid(); err != nil {
|
||||||
return nil, nil, fmt.Errorf("signerR point is not on secp256k1")
|
return nil, nil, fmt.Errorf("signerR %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
u := &UserSecretData{}
|
u := &UserSecretData{}
|
||||||
@@ -172,7 +172,7 @@ func Blind(m *big.Int, signerR *Point) (*big.Int, *UserSecretData, error) {
|
|||||||
|
|
||||||
// TODO check that F != O (point at infinity)
|
// TODO check that F != O (point at infinity)
|
||||||
if err := u.F.isValid(); err != nil {
|
if err := u.F.isValid(); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, fmt.Errorf("u.F %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rx := new(big.Int).Mod(u.F.X, N)
|
rx := new(big.Int).Mod(u.F.X, N)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -38,6 +39,28 @@ func TestFlow(t *testing.T) {
|
|||||||
assert.True(t, verified)
|
assert.True(t, verified)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHashMOddBytes(t *testing.T) {
|
||||||
|
// This test is made with same values than
|
||||||
|
// https://github.com/arnaucube/blindsecp256k1-js to ensure
|
||||||
|
// compatibility
|
||||||
|
mStr := "3024162961766929396601888431330224482373544644288322432261208139289299439809"
|
||||||
|
m, ok := new(big.Int).SetString(mStr, 10)
|
||||||
|
require.True(t, ok)
|
||||||
|
mBytes := m.Bytes()
|
||||||
|
|
||||||
|
hBytes := crypto.Keccak256(mBytes[3:])
|
||||||
|
h := new(big.Int).SetBytes(hBytes)
|
||||||
|
assert.Equal(t,
|
||||||
|
"57523339312508913023232057765773019244858443678197951618720342803494056599369",
|
||||||
|
h.String())
|
||||||
|
|
||||||
|
hBytes = crypto.Keccak256(append(mBytes, []byte{0x12, 0x34}...))
|
||||||
|
h = new(big.Int).SetBytes(hBytes)
|
||||||
|
assert.Equal(t,
|
||||||
|
"9697834584560956691445940439424778243200861871421750951058436814122640359156",
|
||||||
|
h.String())
|
||||||
|
}
|
||||||
|
|
||||||
// func newBigIntWithBitLen(n int) *big.Int {
|
// func newBigIntWithBitLen(n int) *big.Int {
|
||||||
// b := make([]byte, n/8)
|
// b := make([]byte, n/8)
|
||||||
// for i := 0; i < len(b); i++ {
|
// for i := 0; i < len(b); i++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user