common

package
v0.0.0-...-26275c3 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCreateBip39Entropy                  = errors.New("failed to create bip39 entropy")
	ErrCreateBip39Mnemonic                 = errors.New("failed to create bip39 mnemonic")
	ErrCreateBip39SeedFromMnemonic         = errors.New("failed to create bip39 seed from mnemonic")
	ErrCreateAccountFromSeed               = errors.New("failed to create account from seed")
	ErrDecodeBase58ToAccount               = errors.New("failed to decode base58 to account")
	ErrDeriveKeyFromSeed                   = errors.New("failed to derive key from seed")
	ErrInvalidPublicKey                    = errors.New("invalid base58 public key")
	ErrInvalidPublicKeyLength              = errors.New("invalid public key length")
	ErrNewMnemonic                         = errors.New("failed to create new mnemonic")
	ErrDeriveAccountFromMnemonicBip44      = errors.New("failed to derive account from mnemonic bip44")
	ErrDeriveAccountsListFromMnemonicBip44 = errors.New("failed to derive accounts list from mnemonic bip44")
	ErrDeriveAccountFromMnemonicBip39      = errors.New("failed to derive account from mnemonic bip39")
	ErrDeriveTokenAccount                  = errors.New("failed to derive associated token account")
	ErrInvalidWalletAddress                = errors.New("invalid wallet address: must be a base58 encoded public key")
)

Predefiend errors

Functions

func AccountFromBase58

func AccountFromBase58(s string) (types.Account, error)

FromBase58 creates an Solana account from a base58 encoded string

func AccountFromString

func AccountFromString(s string) (types.Account, error)

AccountFromString creates an Solana account from a base58 encoded string. Alias for AccountFromBase58

func AccountToBase58

func AccountToBase58(a types.Account) string

ToBase58 converts an Solana account to a base58 encoded string

func DeriveAccountFromMnemonicBip39

func DeriveAccountFromMnemonicBip39(mnemonic string) (types.Account, error)

DeriveAccountFromMnemonicBip39 derives an Solana account from a mnemonic phrase Compatible with BIP39 (solana cli tool)

func DeriveAccountFromMnemonicBip44

func DeriveAccountFromMnemonicBip44(mnemonic string) (types.Account, error)

DeriveAccountFromMnemonicBip44 derives an Solana account from a mnemonic phrase Compatible with BIP44 (phantom wallet)

func DeriveAccountsListFromMnemonicBip44

func DeriveAccountsListFromMnemonicBip44(mnemonic string, count int) ([]types.Account, error)

DeriveAccountsListFromMnemonicBip44 derives a list of Solana accounts from a mnemonic phrase Compatible with BIP44 (phantom wallet)

func DeriveTokenAccount

func DeriveTokenAccount(base58WalletAddr, base58MintAddr string) (common.PublicKey, error)

DeriveTokenAccount derives an associated token account from a Solana account and a mint address. This is a wrapper around the FindAssociatedTokenAddress function from the solana-go-sdk. base58WalletAddr is the base58 encoded address of the Solana account. base58MintAddr is the base58 encoded address of the token mint. The function returns the base58 encoded address of the token account or an error.

func DeriveTokenAccountPubkey

func DeriveTokenAccountPubkey(wallet, mint common.PublicKey) (common.PublicKey, error)

DeriveTokenAccountPubkey derives an associated token account from a Solana account and a mint address. This is a wrapper around the FindAssociatedTokenAddress function from the solana-go-sdk.

func DeriveTokenLockAccount

func DeriveTokenLockAccount(walletAddress, tokenMintAddress common.PublicKey) (common.PublicKey, error)

DeriveTokenLockAccount derives an associated token holder account from a Solana account and a mint address.

func FindBurnerPubkey

func FindBurnerPubkey() (common.PublicKey, error)

FindBurnerPubkey returns the pubkey of the burner account

func NewAccount

func NewAccount() types.Account

NewAccount creates a new Solana account

func NewAccountFromSeed

func NewAccountFromSeed(seed []byte) (types.Account, error)

NewAccountFromSeed creates a new Solana account from a seed

func NewMnemonic

func NewMnemonic(len MnemonicLength) (string, error)

NewMnemonic generates a new mnemonic phrase

func PublicKeyFromBase58

func PublicKeyFromBase58(s string) common.PublicKey

PublicKeyFromBase58 converts a base58 encoded public key to a PublicKey type Alias for PublicKeyFromString

func PublicKeyFromString

func PublicKeyFromString(s string) common.PublicKey

PublicKeyFromString converts a string to a PublicKey type Wrapper around the common.PublicKeyFromString function from the solana-go-sdk

func ValidateSolanaWalletAddr

func ValidateSolanaWalletAddr(addr string) error

ValidateSolanaWalletAddr validates a Solana wallet address. Returns an error if the address is invalid, nil otherwise.

Types

type MnemonicLength

type MnemonicLength int

Mnemonic length type

const (
	MnemonicLength12 MnemonicLength = 128 // 128 bits of entropy
	MnemonicLength24 MnemonicLength = 256 // 256 bits of entropy
)

Predefined mnemonic lengths

Jump to

Keyboard shortcuts

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