Skip to content

Commit 03ea40a

Browse files
committed
rynobey#2: Accept hex numbers with/without 0x prefix
1 parent ee7fefc commit 03ea40a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

util.go

+12
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,20 @@ func ReadContentsIntoStruct(r *http.Request, obj interface{}) (error) {
6262
return nil
6363
}
6464

65+
func AddPrefixIfMissing(num string) (string) {
66+
var newNum string
67+
if len(num) < 3 || num[0:2] != "0x" {
68+
newNum = fmt.Sprintf("0x%s", num)
69+
return newNum
70+
}
71+
return num
72+
}
73+
6574
func NewBigInt(num string, err error) (*big.Int, error) {
6675
if err != nil {
6776
return nil, err
6877
} else {
78+
num = AddPrefixIfMissing(num)
6979
if len(num) < 3 {
7080
return nil, errors.New("Unable to initialize big.Int from string: too short")
7181
}
@@ -82,6 +92,8 @@ func NewECPoint(xCoord string, yCoord string, err error) (*bn256.G1, error) {
8292
return nil, err
8393
} else {
8494
P := new(bn256.G1)
95+
xCoord = AddPrefixIfMissing(xCoord)
96+
yCoord = AddPrefixIfMissing(yCoord)
8597
marshalledPoint := fmt.Sprintf("%064s%064s", xCoord[2:], yCoord[2:])
8698
marshalledBytes, err := hex.DecodeString(marshalledPoint)
8799
if err != nil {

0 commit comments

Comments
 (0)