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.

36 lines
964 B

  1. package blindsecp256k1v0
  2. import (
  3. "math/big"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/stretchr/testify/require"
  7. )
  8. func TestFlow(t *testing.T) {
  9. // signer: create new signer key pair
  10. sk, err := NewPrivateKey()
  11. require.Nil(t, err)
  12. signerPubK := sk.Public()
  13. // signer: when user requests new R parameter to blind a new msg,
  14. // create new signerR (public) with its secret k
  15. k, signerR, err := NewRequestParameters()
  16. require.Nil(t, err)
  17. // user: blinds the msg using signer's R
  18. msg := new(big.Int).SetBytes([]byte("test"))
  19. msgBlinded, userSecretData, err := Blind(msg, signerPubK, signerR)
  20. require.Nil(t, err)
  21. // signer: signs the blinded message using its private key & secret k
  22. sBlind := sk.BlindSign(msgBlinded, k)
  23. // user: unblinds the blinded signature
  24. sig := Unblind(sBlind, userSecretData)
  25. // signature can be verified with signer PublicKey (Q)
  26. verified := Verify(msg, sig, signerPubK)
  27. assert.True(t, verified)
  28. }