Skip to content

Commit

Permalink
fix decimal to utf8 convertion and add error handling in convert even…
Browse files Browse the repository at this point in the history
…t-data
  • Loading branch information
chabanyknikita committed Sep 30, 2024
1 parent 5538f39 commit aac457c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 5 additions & 6 deletions internal/service/handlers/helpers/proof_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
zk "github.com/rarimo/zkverifier-kit"
"github.com/status-im/keycard-go/hexutils"
"math/big"
"strconv"
"time"
)

Expand Down Expand Up @@ -65,12 +64,12 @@ func Utf8ToHex(input string) string {
}

func DecimalToHexToUtf8(input string) (string, error) {
inputDecimal, err := strconv.Atoi(input)
if err != nil {
return "", fmt.Errorf("failde to convert input string to decimal: %w", err)

inputBig, ok := new(big.Int).SetString(input, 10)
if !ok {
return "", fmt.Errorf("failed to parse big int when converting to UTF8")
}
inputUtf8 := string(hexutils.HexToBytes(strconv.FormatInt(int64(inputDecimal), 16)))

inputUtf8 := string(inputBig.Bytes())

return inputUtf8, nil
}
Expand Down
7 changes: 6 additions & 1 deletion internal/service/handlers/verification_callback_light.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ func VerificationSignatureCallback(w http.ResponseWriter, r *http.Request) {
return
}

userIDHashDecimal, _ := new(big.Int).SetString(pubSignals[10], 10)
userIDHashDecimal, ok := new(big.Int).SetString(pubSignals[10], 10)
if !ok {
Log(r).Error("failed to parse event data")
ape.RenderErr(w, problems.BadRequest(err)...)
return
}
var eventDataBytes [32]byte
userIDHashDecimal.FillBytes(eventDataBytes[:])

Expand Down

0 comments on commit aac457c

Please sign in to comment.