-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
50 lines (42 loc) · 810 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package sampler
import (
"bytes"
"encoding/hex"
"io"
"github.com/holiman/uint256"
"golang.org/x/crypto/sha3"
)
func Min(a float64, b float64) float64 {
if a < b {
return a
}
return b
}
func NewBigNumFromHex(s string) *uint256.Int {
bn := new(uint256.Int)
bn.SetFromHex(s)
return bn
}
func NewBigNumFromInt(i uint64) *uint256.Int {
bn := uint256.NewInt(i)
return bn
}
func decodeHexString(hexString string) []byte {
byteSlice, err := hex.DecodeString(hexString)
if err != nil {
panic(err)
}
return byteSlice
}
func fromSeedSHAKE(seed []byte) io.Reader {
shake := sha3.NewShake256()
_, err := shake.Write(seed)
if err != nil {
panic(err) // should never happen
}
return shake
}
// Only for testing purposes.
func bytesReader(b []byte) io.Reader {
return bytes.NewReader(b)
}