Documentation ¶
Overview ¶
Package common contains various helper functions.
Index ¶
- Constants
- Variables
- func AllZero(b []byte) bool
- func BigMax(x, y *big.Int) *big.Int
- func BigMin(x, y *big.Int) *big.Int
- func BigPow(a, b int64) *big.Int
- func BigUint64(v *big.Int) (uint64, bool)
- func Bool2Bytes(b bool) []byte
- func Byte(bigint *big.Int, padlength, n int) byte
- func Bytes2Hex(d []byte) string
- func BytesEqual(a, b []byte) bool
- func BytesToString(data []byte) string
- func CopyBytes(b []byte) (copiedBytes []byte)
- func CreateDirIfNotExist(dir string) error
- func Decrypt(cryptograph string, passphrase string) (string, error)
- func DecryptBytes(encryptedJSON []byte, passphrase []byte) ([]byte, error)
- func Encrypt(raw string, passphrase string) (string, error)
- func EncryptBytes(raw []byte, passphrase []byte) ([]byte, error)
- func Exp(base, exponent *big.Int) *big.Int
- func FromHex(s string) []byte
- func Hash(size int, data ...[]byte) []byte
- func Hash256(data ...[]byte) []byte
- func Hex2Bytes(str string) []byte
- func Hex2BytesFixed(str string, flen int) []byte
- func Hex32ToBytes(s string) [32]byte
- func Hex64ToBytes(s string) [64]byte
- func HexToBytes(s string) []byte
- func Int2Bytes(i int64) []byte
- func Int64ToBytes(i int64) []byte
- func JoinBytes(data ...[]byte) []byte
- func LeftPadBytes(slice []byte, l int) []byte
- func Max(x, y uint64) uint64
- func Min(x, y uint64) uint64
- func PaddedBigBytes(bigint *big.Int, n int) []byte
- func ReadBits(bigint *big.Int, buf []byte)
- func ReverseBytes(str []byte) (result []byte)
- func RightPadBytes(slice []byte, l int) []byte
- func S256(x *big.Int) *big.Int
- func SafeAdd(x, y uint64) (uint64, bool)
- func SafeMul(x, y uint64) (uint64, bool)
- func SafeSub(x, y uint64) (uint64, bool)
- func String2Bytes(s string) []byte
- func StringToBigInt(str *string) (*big.Int, error)
- func ToHex(b []byte) stringdeprecated
- func ToIndentString(v interface{}) string
- func ToString(v interface{}) string
- func ToWordSize(size uint64) uint64
- func TrimBuffToString(bytes []byte) string
- func TrimQuotes(s string) string
- func U256(x *big.Int) *big.Int
- func Uint64ToBytes(i uint64) []byte
Constants ¶
const ( // StandardScryptN is the N parameter of Scrypt encryption algorithm, using 256MB // memory and taking approximately 1s CPU time on a modern processor. StandardScryptN = 1 << 18 // StandardScryptP is the P parameter of Scrypt encryption algorithm, using 256MB // memory and taking approximately 1s CPU time on a modern processor. StandardScryptP = 1 )
Variables ¶
Functions ¶
func BigUint64 ¶ added in v0.0.9
BigUint64 returns the integer casted to a uint64 and returns whether it overflowed in the process.
func Bool2Bytes ¶ added in v0.0.9
func Byte ¶ added in v0.0.9
Byte returns the byte at position n, with the supplied padlength in Little-Endian encoding. n==0 returns the MSB Example: bigint '5', padlength 32, n=31 => 5
func BytesEqual ¶ added in v0.0.9
func BytesToString ¶ added in v0.0.9
func CreateDirIfNotExist ¶
CreateDirIfNotExist create given folder
func DecryptBytes ¶ added in v0.0.5
DecryptBytes decrypt raw json to raw
func EncryptBytes ¶ added in v0.0.5
EncryptBytes encrypts raw by passphrase to json binary
func Exp ¶ added in v0.0.9
Exp implements exponentiation by squaring. Exp returns a newly-allocated big integer and does not change base or exponent. The result is truncated to 256 bits.
func FromHex ¶
FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".
func Hex2BytesFixed ¶
Hex2BytesFixed returns bytes of a specified fixed length flen.
func Hex32ToBytes ¶
func Hex64ToBytes ¶
func HexToBytes ¶
func Int64ToBytes ¶ added in v0.0.9
func LeftPadBytes ¶
LeftPadBytes zero-pads slice to the left up to length l.
func PaddedBigBytes ¶ added in v0.0.9
PaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.
func ReadBits ¶ added in v0.0.9
ReadBits encodes the absolute amount of bigint as big-endian bytes. Callers must ensure that buf has enough space. If buf is too short the result will be incomplete.
func ReverseBytes ¶
func RightPadBytes ¶
RightPadBytes zero-pads slice to the right up to length l.
func S256 ¶ added in v0.0.9
S256 interprets x as a two's complement number. x must not exceed 256 bits (the result is undefined if it does) and is not modified.
S256(0) = 0 S256(1) = 1 S256(2**255) = -2**255 S256(2**256-1) = -1
func String2Bytes ¶ added in v0.0.9
func ToIndentString ¶ added in v1.0.1
func ToIndentString(v interface{}) string
func ToWordSize ¶ added in v0.0.9
ToWordSize returns the ceiled word size required for memory expansion.
func TrimBuffToString ¶ added in v0.0.9
trim the '\00' byte
func U256 ¶ added in v0.0.9
U256 encodes as a 256 bit two's complement number. This operation is destructive.
func Uint64ToBytes ¶ added in v0.0.9
Types ¶
This section is empty.