You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.5 KiB

  1. package blindsecp256k1
  2. import (
  3. "encoding/hex"
  4. "math/big"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. )
  9. func TestBytesUncompressed(t *testing.T) {
  10. // Point
  11. p := &Point{
  12. X: big.NewInt(3),
  13. Y: big.NewInt(3),
  14. }
  15. b := p.BytesUncompressed()
  16. assert.Equal(t, "03000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000", hex.EncodeToString(b)) //nolint:lll
  17. p2, err := NewPointFromBytesUncompressed(b)
  18. assert.Nil(t, err)
  19. assert.Equal(t, p, p2)
  20. p = G.Mul(big.NewInt(1234))
  21. b = p.BytesUncompressed()
  22. assert.Equal(t, "f258163f65f65865a79a4279e2ebabb5a57b85501dd4b381d1dc605c434876e34c308bd3f18f062d5cc07f34948ced82f9a76f9c3e65ae64f158412da8e92e6d", hex.EncodeToString(b)) //nolint:lll
  23. p2, err = NewPointFromBytesUncompressed(b)
  24. assert.Nil(t, err)
  25. assert.Equal(t, p, p2)
  26. // PublicKey
  27. pk := PublicKey(*p)
  28. b = pk.BytesUncompressed()
  29. assert.Equal(t, "f258163f65f65865a79a4279e2ebabb5a57b85501dd4b381d1dc605c434876e34c308bd3f18f062d5cc07f34948ced82f9a76f9c3e65ae64f158412da8e92e6d", hex.EncodeToString(b)) //nolint:lll
  30. pk2, err := NewPublicKeyFromBytesUncompressed(b)
  31. assert.Nil(t, err)
  32. assert.Equal(t, &pk, pk2)
  33. // Signature
  34. sig := Signature{
  35. S: big.NewInt(9876),
  36. F: p,
  37. }
  38. b = sig.BytesUncompressed()
  39. assert.Equal(t, "9426000000000000000000000000000000000000000000000000000000000000f258163f65f65865a79a4279e2ebabb5a57b85501dd4b381d1dc605c434876e34c308bd3f18f062d5cc07f34948ced82f9a76f9c3e65ae64f158412da8e92e6d", hex.EncodeToString(b)) //nolint:lll
  40. sig2, err := NewSignatureFromBytesUncompressed(b)
  41. assert.Nil(t, err)
  42. assert.Equal(t, &sig, sig2)
  43. // Signature with bigger values
  44. s, ok := new(big.Int).SetString("43744879514016998261043792362491545206150700367692876136431010903034023684055", 10) //nolint:lll
  45. require.True(t, ok)
  46. x, ok := new(big.Int).SetString("56183217574518331862027285308947626162625485037257226169003339923450551228164", 10) //nolint:lll
  47. require.True(t, ok)
  48. y, ok := new(big.Int).SetString("62825693913681695979055350889339417157462875026935818721506450621762231021976", 10) //nolint:lll
  49. require.True(t, ok)
  50. sig = Signature{
  51. S: s,
  52. F: &Point{X: x, Y: y},
  53. }
  54. b = sig.BytesUncompressed()
  55. assert.Equal(t, "d7a75050259cc06415f19bde5460a58325e3050806ba949d9ac9728b71b9b6600457ba001981781ed31acafed3d1e82c2ad53d08e3f293eab2f199ed0193367c98311f1894598c91f10fe415ba4a6d04e1351d07430631c7decdbbdb2615e68a", hex.EncodeToString(b)) //nolint:lll
  56. sig2, err = NewSignatureFromBytesUncompressed(b)
  57. assert.Nil(t, err)
  58. assert.Equal(t, &sig, sig2)
  59. }