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.

39 lines
867 B

  1. package common
  2. import (
  3. "math/big"
  4. ethCommon "github.com/ethereum/go-ethereum/common"
  5. "github.com/iden3/go-iden3-crypto/babyjub"
  6. )
  7. // SwapEndianness swaps the order of the bytes in the slice.
  8. func SwapEndianness(b []byte) []byte {
  9. o := make([]byte, len(b))
  10. for i := range b {
  11. o[len(b)-1-i] = b[i]
  12. }
  13. return o
  14. }
  15. // EthAddrToBigInt returns a *big.Int from a given ethereum common.Address.
  16. func EthAddrToBigInt(a ethCommon.Address) *big.Int {
  17. return new(big.Int).SetBytes(a.Bytes())
  18. }
  19. // BJJCompressedTo256BigInts returns a [256]*big.Int array with the bit
  20. // representation of the babyjub.PublicKeyComp
  21. func BJJCompressedTo256BigInts(pkComp babyjub.PublicKeyComp) [256]*big.Int {
  22. var r [256]*big.Int
  23. b := pkComp[:]
  24. for i := 0; i < 256; i++ {
  25. if b[i/8]&(1<<(i%8)) == 0 {
  26. r[i] = big.NewInt(0)
  27. } else {
  28. r[i] = big.NewInt(1)
  29. }
  30. }
  31. return r
  32. }