addresscodec

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Huge thanks to the btcsuite developers for creating this code, which we adapted for our use in compliance with the Copyfree Initiative. btcsuite base58 repo: https://github.com/btcsuite/btcd/tree/master/btcutil/base58

AUTOGENERATED by gen_alphabet.go; do not edit.

Index

Constants

View Source
const (
	// Lengths in bytes
	AccountAddressLength   = 20
	AccountPublicKeyLength = 33
	FamilySeedLength       = 16
	NodePublicKeyLength    = 33

	// Account/classic address prefix - value is 0
	AccountAddressPrefix = 0x00
	// Account public key prefix - value is 35
	AccountPublicKeyPrefix = 0x23
	// Family seed prefix - value is 33
	FamilySeedPrefix = 0x21
	// Node/validation public key prefix - value is 28
	NodePublicKeyPrefix = 0x1C
)

Variables

View Source
var (

	// Invalid classic address
	ErrInvalidClassicAddress = errors.New("invalid classic address")
	// Invalid seed
	ErrInvalidSeed = errors.New("invalid seed; could not determine encoding algorithm")

	// Invalid x-address
	ErrInvalidXAddress = errors.New("invalid x-address")
	// Invalid tag
	ErrInvalidTag = errors.New("invalid tag")
	// Invalid accountId
	ErrInvalidAccountID = errors.New("invalid accountId")

	// Invalid xrpl address, general error
	ErrInvalidAddressFormat = errors.New("invalid address format")

	// ErrChecksum indicates that the checksum of a check-encoded string does not verify against
	// the checksum.
	ErrChecksum = errors.New("checksum error")
	// ErrInvalidFormat indicates that the check-encoded string has an invalid format.
	ErrInvalidFormat = errors.New("invalid format: version and/or checksum bytes missing")
)
View Source
var (
	MainnetXAddressPrefix = []byte{0x05, 0x44}
	TestnetXAddressPrefix = []byte{0x04, 0x93}
	// X-address length - value is 35
	XAddressLength = 35
)

Functions

func Base58CheckDecode

func Base58CheckDecode(input string) (result []byte, err error)

CheckDecode decodes a string that was encoded with CheckEncode and verifies the checksum.

func Base58CheckEncode

func Base58CheckEncode(input []byte, prefix ...byte) string

CheckEncode prepends a version byte, appends a four byte checksum and returns a base58 encoding of the byte slice.

func ClassicAddressToXAddress

func ClassicAddressToXAddress(address string, tag uint32, tagFlag, testnetFlag bool) (string, error)

ClassicAddressToXAddress converts the classic address to an x-address. It returns the x-address. If the classic address is invalid, it returns an error.

func Decode

func Decode(b58string string, typePrefix []byte) ([]byte, error)

Returns the byte slice decoding of the base58-encoded string and prefix.

func DecodeAccountPublicKey

func DecodeAccountPublicKey(key string) ([]byte, error)

Returns the decoded account public key encoding as a byte slice from a base58 string.

func DecodeBase58

func DecodeBase58(b string) []byte

Decodes a modified base58 string to a byte slice.

func DecodeClassicAddressToAccountID

func DecodeClassicAddressToAccountID(cAddress string) (typePrefix, accountID []byte, err error)

Returns the decoded 'accountID' byte slice of the classic address.

func DecodeNodePublicKey

func DecodeNodePublicKey(key string) ([]byte, error)

Returns the decoded node public key encoding as a byte slice from a base58 string.

func DecodeSeed

func DecodeSeed(seed string) ([]byte, interfaces.CryptoImplementation, error)

Returns decoded seed and its algorithm.

func DecodeXAddress

func DecodeXAddress(xAddress string) (accountID []byte, tag uint32, testnet bool, err error)

DecodeXAddress returns the accountId, tag, and testnet boolean decoding of the x-address. If the x-address is invalid, it returns an error.

func Encode

func Encode(b []byte, typePrefix []byte, expectedLength int) (string, error)

Returns the base58 encoding of byte slice, with the given type prefix, whilst ensuring that the byte slice is the expected length.

func EncodeAccountIDToClassicAddress

func EncodeAccountIDToClassicAddress(accountID []byte) (string, error)

EncodeAccountIDToClassicAddress returns the classic address encoding of the accountId.

func EncodeAccountPublicKey

func EncodeAccountPublicKey(b []byte) (string, error)

Returns the account public key encoding of the byte slice as a base58 string.

func EncodeBase58

func EncodeBase58(b []byte) string

Encodes a byte slice to a base58 string encoded with the XRP alphabet.

func EncodeClassicAddressFromPublicKeyHex

func EncodeClassicAddressFromPublicKeyHex(pubkeyhex string) (string, error)

Returns the classic address from public key hex string.

func EncodeNodePublicKey

func EncodeNodePublicKey(b []byte) (string, error)

Returns the node public key encoding of the byte slice as a base58 string.

func EncodeSeed

func EncodeSeed(entropy []byte, encodingType interfaces.CryptoImplementation) (string, error)

Returns a base58 encoding of a seed.

func EncodeXAddress

func EncodeXAddress(accountID []byte, tag uint32, tagFlag, testnetFlag bool) (string, error)

EncodeXAddress returns the x-address encoding of the accountId, tag, and testnet boolean. If the accountId is not 20 bytes long, it returns an error.

func IsValidAddress

func IsValidAddress(address string) bool

IsValidAddress returns true if the address is valid. Otherwise, it returns false. Address can only be a classic address or an x-address.

func IsValidClassicAddress

func IsValidClassicAddress(cAddress string) bool

IsValidClassicAddress returns true if the classic address is valid. Otherwise, it returns false.

func IsValidXAddress

func IsValidXAddress(xAddress string) bool

IsValidXAddress returns true if the x-address is valid. Otherwise, it returns false.

func Sha256RipeMD160

func Sha256RipeMD160(b []byte) []byte

Returns byte slice of a double hashed given byte slice. The given byte slice is SHA256 hashed, then the result is RIPEMD160 hashed.

func XAddressToClassicAddress

func XAddressToClassicAddress(xAddress string) (classicAddress string, tag uint32, testnet bool, err error)

XAddressToClassicAddress converts the x-address to a classic address. It returns the classic address, tag and testnet boolean. If the x-address is invalid, it returns an error.

Types

type EncodeLengthError

type EncodeLengthError struct {
	Instance string
	Input    int
	Expected int
}

EncodeLengthError is an error that occurs when the length of the input does not match the expected length.

func (*EncodeLengthError) Error

func (e *EncodeLengthError) Error() string

Error implements the error interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL