Documentation
¶
Overview ¶
Package encoding provides encoding and decoding utilities ported from the Turnkey TypeScript SDK.
Index ¶
- func Base64ToBase64URL(input string) string
- func Base64URLToBase64(input string) string
- func Base64URLToString(input string) (string, error)
- func Bs58CheckDecode(s string) ([]byte, error)
- func Bs58CheckDecodeUnsafe(s string) []byte
- func Bs58CheckEncode(payload []byte) string
- func Bs58Decode(s string) []byte
- func Bs58DecodeUnsafe(s string) ([]byte, bool)
- func Bs58Encode(b []byte) string
- func BytesToHex(input []byte) string
- func Checksum(payload []byte) (checksum [4]byte)
- func HexToASCII(hexString string) string
- func HexToBase64URL(input string, length ...int) (string, error)
- func HexToBytes(hexString string, length ...int) ([]byte, error)
- func NormalizePadding(b []byte, targetLength int) ([]byte, error)
- func PointEncode(raw []byte) ([]byte, error)
- func StringToBase64URL(input string) string
- func ValidateChecksum(payload []byte) error
- type HexBytes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Base64ToBase64URL ¶
Base64ToBase64URL converts a standard base64 string to base64url by replacing '+' with '-', '/' with '_', and stripping '=' padding.
func Base64URLToBase64 ¶
Base64URLToBase64 converts a base64url string back to standard base64 by replacing '-' with '+', '_' with '/', and re-adding '=' padding.
func Base64URLToString ¶
Base64URLToString decodes a base64url string to a plain UTF-8 string.
func Bs58CheckDecode ¶
Bs58CheckDecode decodes a base58check string, verifies the checksum, and returns the payload.
func Bs58CheckDecodeUnsafe ¶
Bs58CheckDecodeUnsafe decodes a base58check string, returning nil on any error.
func Bs58CheckEncode ¶
Bs58CheckEncode appends a 4-byte double-SHA256 checksum to payload and base58 encodes the result.
func Bs58Decode ¶
Bs58Decode decodes a base58 string to a byte slice. Returns nil for invalid input.
func Bs58DecodeUnsafe ¶
Bs58DecodeUnsafe decodes a base58 string, returning (nil, false) on invalid input.
func Bs58Encode ¶
Bs58Encode encodes a byte slice to a base58 string.
func BytesToHex ¶
BytesToHex converts a byte slice into a lowercase hex string.
func HexToASCII ¶
HexToASCII converts a hex string to its ASCII string representation.
func HexToBase64URL ¶
HexToBase64URL converts a hex string to a base64url string. If length is provided, the byte buffer is left-padded with zeros to that length.
func HexToBytes ¶
HexToBytes creates a byte slice from a hex string. If length is provided, the result is left-padded with zeros to that length; it is an error if the hex value exceeds length.
func NormalizePadding ¶
NormalizePadding pads or trims a byte slice to exactly targetLength bytes. When trimming, leading bytes must be zero or an error is returned.
func PointEncode ¶
PointEncode compresses an uncompressed P-256 public key (65 bytes, 0x04 prefix) into its 33-byte compressed form (0x02 or 0x03 prefix).
func StringToBase64URL ¶
StringToBase64URL encodes a plain string to a base64url string (no padding).
func ValidateChecksum ¶
ValidateChecksum validates that a payload has a valid base58check checksum in its last four bytes.