strkey

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0, Apache-2.0 Imports: 7 Imported by: 14

Documentation

Overview

Package strkey is an implementation of StrKey, the address scheme for the StellarNetwork.

Index

Constants

View Source
const (
	//VersionByteAccountID is the version byte used for encoded stellar addresses
	VersionByteAccountID VersionByte = 6 << 3 // Base32-encodes to 'G...'

	//VersionByteSeed is the version byte used for encoded stellar seed
	VersionByteSeed = 18 << 3 // Base32-encodes to 'S...'

	//VersionByteMuxedAccount is the version byte used for encoded stellar multiplexed addresses
	VersionByteMuxedAccount = 12 << 3 // Base32-encodes to 'M...'

	//VersionByteHashTx is the version byte used for encoded stellar hashTx
	//signer keys.
	VersionByteHashTx = 19 << 3 // Base32-encodes to 'T...'

	//VersionByteHashX is the version byte used for encoded stellar hashX
	//signer keys.
	VersionByteHashX = 23 << 3 // Base32-encodes to 'X...'

	//VersionByteSignedPayload is the version byte used for encoding "signed
	//payload" (CAP-40) signer keys.
	VersionByteSignedPayload = 15 << 3 // Base-32 encodes to 'P'

	//VersionByteContract is the version byte used for encoded stellar contracts
	VersionByteContract = 2 << 3 // Base-32 encodes to 'C'

	//VersionByteLiquidityPool is the version byte used for encoded stellar liquidity pools
	VersionByteLiquidityPool = 11 << 3

	//VersionByteClaimableBalance is the version byte used for encoded stellar claimable balances
	VersionByteClaimableBalance = 1 << 3

	//VersionByteMuxedContract is the version byte used for encoded stellar multiplexed contracts
	VersionByteMuxedContract = 22 << 3 // Base32-encodes to 'W...'
)

Variables

View Source
var ErrInvalidVersionByte = errors.New("invalid version byte")

ErrInvalidVersionByte is returned when the version byte from a provided strkey-encoded string is not one of the valid values.

Functions

func Decode

func Decode(expected VersionByte, src string) ([]byte, error)

Decode decodes the provided StrKey into a raw value, checking the checksum, ensuring the expected VersionByte (the version parameter) is the value actually encoded into the provided src string, and that the payload has the length SEP-23 prescribes for that version byte.

func Encode

func Encode(version VersionByte, src []byte) (string, error)

Encode encodes the provided data to a StrKey, using the provided version byte.

func IsValidClaimableBalance

func IsValidClaimableBalance(i interface{}) bool

func IsValidContractAddress

func IsValidContractAddress(i interface{}) bool

func IsValidEd25519PublicKey

func IsValidEd25519PublicKey(i interface{}) bool

IsValidEd25519PublicKey validates a stellar public key

func IsValidEd25519SecretSeed

func IsValidEd25519SecretSeed(i interface{}) bool

IsValidEd25519SecretSeed validates a stellar secret key

func IsValidLiquidityPool

func IsValidLiquidityPool(i interface{}) bool

func IsValidMuxedAccountEd25519PublicKey

func IsValidMuxedAccountEd25519PublicKey(s string) bool

IsValidMuxedAccountEd25519PublicKey validates a Stellar SEP-23 muxed address.

func IsValidMuxedContractAddress added in v0.8.0

func IsValidMuxedContractAddress(s string) bool

IsValidMuxedContractAddress validates a Stellar muxed contract W-address.

func MustDecode

func MustDecode(expected VersionByte, src string) []byte

MustDecode is like Decode, but panics on error

func MustEncode

func MustEncode(version VersionByte, src []byte) string

MustEncode is like Encode, but panics on error

Types

type MuxedAccount

type MuxedAccount struct {
	// contains filtered or unexported fields
}

func DecodeMuxedAccount

func DecodeMuxedAccount(address string) (*MuxedAccount, error)

DecodeMuxedAccount receives a muxed account M-address and parses it into a MuxedAccount object containing an ed25519 address and an id.

func (*MuxedAccount) AccountID

func (m *MuxedAccount) AccountID() (string, error)

AccountID returns the muxed account G-address according with the SEP-23 definition for multiplexed accounts.

func (*MuxedAccount) Address

func (m *MuxedAccount) Address() (string, error)

Address returns the muxed account M-address according with the SEP-23 definition for multiplexed accounts.

func (*MuxedAccount) Ed25519

func (m *MuxedAccount) Ed25519() [32]byte

Ed25519 returns the muxed account ed25519 key.

func (*MuxedAccount) ID

func (m *MuxedAccount) ID() uint64

ID returns the muxed account id according with the SEP-23 definition for multiplexed accounts.

func (*MuxedAccount) SetAccountID

func (m *MuxedAccount) SetAccountID(address string) error

SetAccountID populates the muxed account G-address.

func (*MuxedAccount) SetID

func (m *MuxedAccount) SetID(id uint64)

SetID populates the muxed account ID.

type MuxedContract added in v0.8.0

type MuxedContract struct {
	// contains filtered or unexported fields
}

func DecodeMuxedContract added in v0.8.0

func DecodeMuxedContract(address string) (*MuxedContract, error)

DecodeMuxedContract receives a muxed contract W-address and parses it into a MuxedContract object containing a contract id and a muxed id.

func (*MuxedContract) Address added in v0.8.0

func (m *MuxedContract) Address() (string, error)

Address returns the muxed contract W-address.

func (*MuxedContract) Contract added in v0.8.0

func (m *MuxedContract) Contract() [32]byte

Contract returns the muxed contract's raw 32-byte contract id.

func (*MuxedContract) ContractID added in v0.8.0

func (m *MuxedContract) ContractID() (string, error)

ContractID returns the muxed contract's underlying C-address.

func (*MuxedContract) ID added in v0.8.0

func (m *MuxedContract) ID() uint64

ID returns the muxed contract id.

func (*MuxedContract) SetContractID added in v0.8.0

func (m *MuxedContract) SetContractID(address string) error

SetContractID populates the muxed contract's underlying C-address.

func (*MuxedContract) SetID added in v0.8.0

func (m *MuxedContract) SetID(id uint64)

SetID populates the muxed contract ID.

type SignedPayload

type SignedPayload struct {
	// contains filtered or unexported fields
}

func DecodeSignedPayload

func DecodeSignedPayload(address string) (*SignedPayload, error)

DecodeSignedPayload transforms a P... signer into a `SignedPayload` instance.

func NewSignedPayload

func NewSignedPayload(signerPublicKey string, payload []byte) (*SignedPayload, error)

NewSignedPayload creates a signed payload from an account ID (G... address) and a payload. The payload buffer is copied directly into the structure, so it should not be modified after construction.

func (*SignedPayload) Encode

func (sp *SignedPayload) Encode() (string, error)

Encode turns a signed payload structure into its StrKey equivalent.

func (*SignedPayload) Payload

func (sp *SignedPayload) Payload() []byte

func (*SignedPayload) Signer

func (sp *SignedPayload) Signer() string

type VersionByte

type VersionByte byte

VersionByte represents one of the possible prefix values for a StrKey base string--the string the when encoded using base32 yields a final StrKey.

func DecodeAny

func DecodeAny(src string) (VersionByte, []byte, error)

DecodeAny decodes the provided StrKey into a raw value, checking the checksum, that the version byte is one of allowed values, and that the payload has the length SEP-23 prescribes for that version byte.

func Version

func Version(src string) (VersionByte, error)

Version extracts and returns the version byte from the provided source string.

Directories

Path Synopsis
internal
crc16
Package crc16 is implementation according to CCITT standards.
Package crc16 is implementation according to CCITT standards.

Jump to

Keyboard shortcuts

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