Documentation ¶
Overview ¶
Package encoding provides encoding and decoding of different formats like Base62, Saltpack, BIP39.
Index ¶
- Variables
- func BreakString(msg string, wordLen int, lineLen int) string
- func BytesToPhrase(b []byte) (string, error)
- func Decode(s string, encoding Encoding) ([]byte, error)
- func DecodeBase32(s string) ([]byte, error)
- func DecodeBase62(s string) ([]byte, error)
- func DecodeBase64(s string) ([]byte, error)
- func DecodeHex(s string) ([]byte, error)
- func DecodeSaltpack(msg string, isHTML bool) ([]byte, string, error)
- func Encode(b []byte, encoding Encoding, opt ...EncodeOption) (string, error)
- func EncodeBase32(b []byte) string
- func EncodeBase62(b []byte) string
- func EncodeBase64(b []byte) string
- func EncodeHex(b []byte) string
- func EncodeSaltpack(b []byte, brand string) string
- func FindSaltpack(msg string, isHTML bool) (string, string)
- func HasUpper(s string) bool
- func IsASCII(b []byte) bool
- func IsAlphaNumeric(s string, extra string) bool
- func IsValidPhrase(phrase string, sanitize bool) bool
- func MustDecode(s string, encoding Encoding) []byte
- func MustEncode(b []byte, encoding Encoding, opt ...EncodeOption) string
- func PhraseToBytes(phrase string, sanitize bool) (*[32]byte, error)
- func TrimSaltpack(msg string, allow []rune) string
- type EncodeOption
- type EncodeOptions
- type Encoding
- type ErrInvalidPhrase
- type TextMarshaler
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidBIP39Input = errors.New("bip39 only accepts 16, 20, 24, 28, 32 bytes")
ErrInvalidBIP39Input if invalid number of bytes for encoding.
Functions ¶
func BreakString ¶
BreakString breaks words and lines.
func BytesToPhrase ¶
BytesToPhrase returns a phrase for bytes
func DecodeBase32 ¶ added in v0.1.1
DecodeBase32 decode base32.
func DecodeBase62 ¶ added in v0.1.1
DecodeBase62 decode base62.
func DecodeBase64 ¶ added in v0.1.1
DecodeBase64 decode base64.
func DecodeSaltpack ¶
DecodeSaltpack decodes saltpack message.
func Encode ¶
func Encode(b []byte, encoding Encoding, opt ...EncodeOption) (string, error)
Encode encodes bytes to an Encoding.
func EncodeSaltpack ¶
EncodeSaltpack encodes bytes to saltpack message.
func FindSaltpack ¶
FindSaltpack finds saltpack message in a string starting with "BEGIN {BRAND }MESSAGE." and ending with "END {BRAND }MESSAGE". {BRAND } is optional. If isHTML is true, we html unescape the string first.
func IsAlphaNumeric ¶
IsAlphaNumeric returns true if string is only a-z, A-Z, 0-9 with optional extra characters.
func IsValidPhrase ¶
IsValidPhrase checks is phrase is valid
func MustEncode ¶
func MustEncode(b []byte, encoding Encoding, opt ...EncodeOption) string
MustEncode returns encoding or panics on error.
func PhraseToBytes ¶
PhraseToBytes decodes a bip39 mnemonic into bytes
func TrimSaltpack ¶
TrimSaltpack removes non base63 characters from a string.
Types ¶
type EncodeOption ¶
type EncodeOption struct { Apply func(*EncodeOptions) Encodings []Encoding Name string }
EncodeOption ...
type EncodeOptions ¶
type EncodeOptions struct { // NoPadding, for encodings that can disable padding (base64, base32). NoPadding bool // Lowercase, for encodings that can be upper or lower case, use lowercase (base32). Lowercase bool }
EncodeOptions ...
type Encoding ¶
type Encoding string
Encoding is an encoding for bytes to and from a string
const ( // NoEncoding ... NoEncoding Encoding = "" // Hex (Base16) encoding Hex Encoding = "base16" // Base32 encoding Base32 Encoding = "base32" // Base58 encoding Base58 Encoding = "base58" // Base62 encoding Base62 Encoding = "base62" // Base64 encoding (with padding) Base64 Encoding = "base64" // Saltpack encoding Saltpack Encoding = "saltpack" // BIP39 encoding BIP39 Encoding = "bip39" )
func NewEncoding ¶
NewEncoding returns an Encoding from a string.
type ErrInvalidPhrase ¶
type ErrInvalidPhrase struct {
// contains filtered or unexported fields
}
ErrInvalidPhrase if phrase is invalid.
func (ErrInvalidPhrase) Error ¶
func (e ErrInvalidPhrase) Error() string
type TextMarshaler ¶ added in v0.1.4
type TextMarshaler = stdencoding.TextMarshaler
TextMarshaler alias for encoding.TextMarshaler.