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.

37 lines
773 B

  1. package api
  2. import (
  3. "encoding/base64"
  4. "strconv"
  5. ethCommon "github.com/ethereum/go-ethereum/common"
  6. "github.com/hermeznetwork/hermez-node/common"
  7. "github.com/iden3/go-iden3-crypto/babyjub"
  8. )
  9. const exitIdx = "hez:EXIT:1"
  10. type errorMsg struct {
  11. Message string
  12. }
  13. func bjjToString(bjj *babyjub.PublicKey) string {
  14. pkComp := [32]byte(bjj.Compress())
  15. sum := pkComp[0]
  16. for i := 1; i < len(pkComp); i++ {
  17. sum += pkComp[i]
  18. }
  19. bjjSum := append(pkComp[:], sum)
  20. return "hez:" + base64.RawURLEncoding.EncodeToString(bjjSum)
  21. }
  22. func ethAddrToHez(addr ethCommon.Address) string {
  23. return "hez:" + addr.String()
  24. }
  25. func idxToHez(idx common.Idx, tokenSymbol string) string {
  26. if idx == 1 {
  27. return exitIdx
  28. }
  29. return "hez:" + tokenSymbol + ":" + strconv.Itoa(int(idx))
  30. }