From 3b5c0bbefb22b7417344cf8294963cc6b0751b3a Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Mon, 14 Aug 2023 07:57:45 -0400 Subject: [PATCH] chore: add BigIntToBytes32 utils function --- rln/utils.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/rln/utils.go b/rln/utils.go index eff03de..d4a12ea 100644 --- a/rln/utils.go +++ b/rln/utils.go @@ -2,6 +2,7 @@ package rln import ( "encoding/hex" + "math/big" ) func ToIdentityCredentials(groupKeys [][]string) ([]IdentityCredential, error) { @@ -62,9 +63,19 @@ func ToBytes32LE(hexStr string) ([32]byte, error) { return [32]byte{}, err } - for i := 0; i < len(b)/2; i++ { - b[i], b[len(b)-i-1] = b[len(b)-i-1], b[i] + bLen := len(b) + for i := 0; i < bLen/2; i++ { + b[i], b[bLen-i-1] = b[bLen-i-1], b[i] } return Bytes32(b), nil } + +func BigIntToBytes32(value *big.Int) [32]byte { + b := value.Bytes() + bLen := len(b) + for i := 0; i < bLen/2; i++ { + b[i], b[bLen-i-1] = b[bLen-i-1], b[i] + } + return Bytes32(b) +}