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.

73 lines
2.5 KiB

  1. package nano
  2. import (
  3. "encoding/hex"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/stretchr/testify/require"
  7. )
  8. func TestLedgerKeys(t *testing.T) {
  9. assert, require := assert.New(t), require.New(t)
  10. cases := []struct {
  11. msg, pubkey, sig string
  12. valid bool
  13. }{
  14. 0: {
  15. msg: "F00D",
  16. pubkey: "8E8754F012C2FDB492183D41437FD837CB81D8BBE731924E2E0DAF43FD3F2C93",
  17. sig: "787DC03E9E4EE05983E30BAE0DEFB8DB0671DBC2F5874AC93F8D8CA4018F7A42D6F9A9BCEADB422AC8E27CEE9CA205A0B88D22CD686F0A43EB806E8190A3C400",
  18. valid: true,
  19. },
  20. 1: {
  21. msg: "DEADBEEF",
  22. pubkey: "0C45ADC887A5463F668533443C829ED13EA8E2E890C778957DC28DB9D2AD5A6C",
  23. sig: "00ED74EED8FDAC7988A14BF6BC222120CBAC249D569AF4C2ADABFC86B792F97DF73C4919BE4B6B0ACB53547273BF29FBF0A9E0992FFAB6CB6C9B09311FC86A00",
  24. valid: true,
  25. },
  26. 2: {
  27. msg: "1234567890AA",
  28. pubkey: "598FC1F0C76363D14D7480736DEEF390D85863360F075792A6975EFA149FD7EA",
  29. sig: "59AAB7D7BDC4F936B6415DE672A8B77FA6B8B3451CD95B3A631F31F9A05DAEEE5E7E4F89B64DDEBB5F63DC042CA13B8FCB8185F82AD7FD5636FFDA6B0DC9570B",
  30. valid: true,
  31. },
  32. 3: {
  33. msg: "1234432112344321",
  34. pubkey: "359E0636E780457294CCA5D2D84DB190C3EDBD6879729C10D3963DEA1D5D8120",
  35. sig: "616B44EC7A65E7C719C170D669A47DE80C6AC0BB13FBCC89230976F9CC14D4CF9ECF26D4AFBB9FFF625599F1FF6F78EDA15E9F6B6BDCE07CFE9D8C407AC45208",
  36. valid: true,
  37. },
  38. 4: {
  39. msg: "12344321123443",
  40. pubkey: "359E0636E780457294CCA5D2D84DB190C3EDBD6879729C10D3963DEA1D5D8120",
  41. sig: "616B44EC7A65E7C719C170D669A47DE80C6AC0BB13FBCC89230976F9CC14D4CF9ECF26D4AFBB9FFF625599F1FF6F78EDA15E9F6B6BDCE07CFE9D8C407AC45208",
  42. valid: false,
  43. },
  44. 5: {
  45. msg: "1234432112344321",
  46. pubkey: "459E0636E780457294CCA5D2D84DB190C3EDBD6879729C10D3963DEA1D5D8120",
  47. sig: "616B44EC7A65E7C719C170D669A47DE80C6AC0BB13FBCC89230976F9CC14D4CF9ECF26D4AFBB9FFF625599F1FF6F78EDA15E9F6B6BDCE07CFE9D8C407AC45208",
  48. valid: false,
  49. },
  50. 6: {
  51. msg: "1234432112344321",
  52. pubkey: "359E0636E780457294CCA5D2D84DB190C3EDBD6879729C10D3963DEA1D5D8120",
  53. sig: "716B44EC7A65E7C719C170D669A47DE80C6AC0BB13FBCC89230976F9CC14D4CF9ECF26D4AFBB9FFF625599F1FF6F78EDA15E9F6B6BDCE07CFE9D8C407AC45208",
  54. valid: false,
  55. },
  56. }
  57. for i, tc := range cases {
  58. bmsg, err := hex.DecodeString(tc.msg)
  59. require.NoError(err, "%d", i)
  60. priv := NewMockKey(tc.msg, tc.pubkey, tc.sig)
  61. pub := priv.PubKey()
  62. sig := priv.Sign(bmsg)
  63. valid := pub.VerifyBytes(bmsg, sig)
  64. assert.Equal(tc.valid, valid, "%d", i)
  65. }
  66. }