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.

41 lines
922 B

  1. package crypto
  2. import (
  3. "encoding/hex"
  4. "testing"
  5. "github.com/btcsuite/btcutil/base58"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. type keyData struct {
  9. priv string
  10. pub string
  11. addr string
  12. }
  13. var secpDataTable = []keyData{
  14. {
  15. priv: "a96e62ed3955e65be32703f12d87b6b5cf26039ecfa948dc5107a495418e5330",
  16. pub: "02950e1cdfcb133d6024109fd489f734eeb4502418e538c28481f22bce276f248c",
  17. addr: "1CKZ9Nx4zgds8tU7nJHotKSDr4a9bYJCa3",
  18. },
  19. }
  20. func TestPubKeySecp256k1Address(t *testing.T) {
  21. for _, d := range secpDataTable {
  22. privB, _ := hex.DecodeString(d.priv)
  23. pubB, _ := hex.DecodeString(d.pub)
  24. addrB, _, _ := base58.CheckDecode(d.addr)
  25. var priv PrivKeySecp256k1
  26. copy(priv[:], privB)
  27. pubT := priv.PubKey().Unwrap().(PubKeySecp256k1)
  28. pub := pubT[:]
  29. addr := priv.PubKey().Address()
  30. assert.Equal(t, pub, pubB, "Expected pub keys to match")
  31. assert.Equal(t, addr, addrB, "Expected addresses to match")
  32. }
  33. }