base

package
v0.0.0-...-61460eb Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package field implements fast arithmetic modulo 2^255-19.

Index

Constants

View Source
const (
	/// Number of bytes in a pubkey.
	PublicKeyLength = 32
	// Maximum length of derived pubkey seed.
	MaxSeedLength = 32
	// Maximum number of seeds.
	MaxSeeds = 16
	/// Number of bytes in a signature.
	SignatureLength = 64
)
View Source
const PDA_MARKER = "ProgramDerivedAddress"
View Source
const TOKEN2022 = "token2022"

Variables

View Source
var (
	// Create new accounts, allocate account data, assign accounts to owning programs,
	// transfer lamports from System Program owned accounts and pay transacation fees.
	SystemProgramID = MustPublicKeyFromBase58("11111111111111111111111111111111")

	// Add configuration data to the chain and the list of public keys that are permitted to modify it.
	ConfigProgramID = MustPublicKeyFromBase58("Config1111111111111111111111111111111111111")

	// Create and manage accounts representing stake and rewards for delegations to validators.
	StakeProgramID = MustPublicKeyFromBase58("Stake11111111111111111111111111111111111111")

	// Create and manage accounts that track validator voting state and rewards.
	VoteProgramID = MustPublicKeyFromBase58("Vote111111111111111111111111111111111111111")

	BPFLoaderDeprecatedProgramID = MustPublicKeyFromBase58("BPFLoader1111111111111111111111111111111111")
	// Deploys, upgrades, and executes programs on the chain.
	BPFLoaderProgramID            = MustPublicKeyFromBase58("BPFLoader2111111111111111111111111111111111")
	BPFLoaderUpgradeableProgramID = MustPublicKeyFromBase58("BPFLoaderUpgradeab1e11111111111111111111111")

	// Verify secp256k1 public key recovery operations (ecrecover).
	Secp256k1ProgramID = MustPublicKeyFromBase58("KeccakSecp256k11111111111111111111111111111")

	FeatureProgramID = MustPublicKeyFromBase58("Feature111111111111111111111111111111111111")

	ComputeBudget = MustPublicKeyFromBase58("ComputeBudget111111111111111111111111111111")
)
View Source
var (
	// A Token program on the Solana blockchain.
	// This program defines a common implementation for Fungible and Non Fungible tokens.
	TokenProgramID = MustPublicKeyFromBase58("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")

	Token2022ProgramID = MustPublicKeyFromBase58("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")

	// A Uniswap-like exchange for the Token program on the Solana blockchain,
	// implementing multiple automated market maker (AMM) curves.
	TokenSwapProgramID = MustPublicKeyFromBase58("SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8")
	TokenSwapFeeOwner  = MustPublicKeyFromBase58("HfoTxFR1Tm6kGmWgYWD6J7YHVy1UwqSULUGVLXkJqaKN")

	// A lending protocol for the Token program on the Solana blockchain inspired by Aave and Compound.
	TokenLendingProgramID = MustPublicKeyFromBase58("LendZqTs8gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi")

	// This program defines the convention and provides the mechanism for mapping
	// the user's wallet address to the associated token accounts they hold.
	SPLAssociatedTokenAccountProgramID = MustPublicKeyFromBase58("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL")

	// The Memo program is a simple program that validates a string of UTF-8 encoded characters
	// and verifies that any accounts provided are signers of the transaction.
	// The program also logs the memo, as well as any verified signer addresses,
	// to the transaction log, so that anyone can easily observe memos
	// and know they were approved by zero or more addresses
	// by inspecting the transaction log from a trusted provider.
	MemoProgramID = MustPublicKeyFromBase58("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr")
)

SPL:

View Source
var (
	// The Mint for native SOL Token accounts
	SolMint = MustPublicKeyFromBase58("So11111111111111111111111111111111111111112")

	SolMint2022 = MustPublicKeyFromBase58("9pan9bMn5HatX4EJdBwg9VgCa7Uz5HL8N1m5D3NdXejP")

	WrappedSol = SolMint
)
View Source
var (
	// The Clock sysvar contains data on cluster time,
	// including the current slot, epoch, and estimated wall-clock Unix timestamp.
	// It is updated every slot.
	SysVarClockPubkey = MustPublicKeyFromBase58("SysvarC1ock11111111111111111111111111111111")

	// The EpochSchedule sysvar contains epoch scheduling constants that are set in genesis,
	// and enables calculating the number of slots in a given epoch,
	// the epoch for a given slot, etc.
	// (Note: the epoch schedule is distinct from the leader schedule)
	SysVarEpochSchedulePubkey = MustPublicKeyFromBase58("SysvarEpochSchedu1e111111111111111111111111")

	// The Fees sysvar contains the fee calculator for the current slot.
	// It is updated every slot, based on the fee-rate governor.
	SysVarFeesPubkey = MustPublicKeyFromBase58("SysvarFees111111111111111111111111111111111")

	// The Instructions sysvar contains the serialized instructions in a Message while that Message is being processed.
	// This allows program instructions to reference other instructions in the same transaction.
	SysVarInstructionsPubkey = MustPublicKeyFromBase58("Sysvar1nstructions1111111111111111111111111")

	// The RecentBlockhashes sysvar contains the active recent blockhashes as well as their associated fee calculators.
	// It is updated every slot.
	// Entries are ordered by descending block height,
	// so the first entry holds the most recent block hash,
	// and the last entry holds an old block hash.
	SysVarRecentBlockHashesPubkey = MustPublicKeyFromBase58("SysvarRecentB1ockHashes11111111111111111111")

	// The Rent sysvar contains the rental rate.
	// Currently, the rate is static and set in genesis.
	// The Rent burn percentage is modified by manual feature activation.
	SysVarRentPubkey = MustPublicKeyFromBase58("SysvarRent111111111111111111111111111111111")

	//
	SysVarRewardsPubkey = MustPublicKeyFromBase58("SysvarRewards111111111111111111111111111111")

	// The SlotHashes sysvar contains the most recent hashes of the slot's parent banks.
	// It is updated every slot.
	SysVarSlotHashesPubkey = MustPublicKeyFromBase58("SysvarS1otHashes111111111111111111111111111")

	// The SlotHistory sysvar contains a bitvector of slots present over the last epoch. It is updated every slot.
	SysVarSlotHistoryPubkey = MustPublicKeyFromBase58("SysvarS1otHistory11111111111111111111111111")

	// The StakeHistory sysvar contains the history of cluster-wide stake activations and de-activations per epoch.
	// It is updated at the start of every epoch.
	SysVarStakeHistoryPubkey = MustPublicKeyFromBase58("SysvarStakeHistory1111111111111111111111111")
)
View Source
var (
	MetaplexCandyMachineV2ProgramID = MustPublicKeyFromBase58("cndy3Z4yapfJBmL3ShUp5exZKqR3z33thTzeNMm2gRZ")
	MetaplexTokenMetadataProgramID  = MustPublicKeyFromBase58("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s")
)
View Source
var ErrMaxSeedLengthExceeded = errors.New("Max seed length exceeded")
View Source
var ErrVarIntBufferSize = errors.New("varint: invalid buffer size")
View Source
var NoTypeIDDefaultID = TypeIDFromUint8(0)
View Source
var (
	TokenMetadataProgramID = MustPublicKeyFromBase58("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s")
)
View Source
var TypeSize = struct {
	Bool int
	Byte int

	Int8  int
	Int16 int

	Uint8   int
	Uint16  int
	Uint32  int
	Uint64  int
	Uint128 int

	Float32 int
	Float64 int

	PublicKey int
	Signature int

	Tstamp         int
	BlockTimestamp int

	CurrencyName int
}{
	Byte: 1,
	Bool: 1,

	Int8:  1,
	Int16: 2,

	Uint8:   1,
	Uint16:  2,
	Uint32:  4,
	Uint64:  8,
	Uint128: 16,

	Float32: 4,
	Float64: 8,
}

Functions

func DecodeCompactU16Length

func DecodeCompactU16Length(bytes []byte) int

DecodeCompactU16Length decodes a "Compact-u16" length from the provided byte slice.

func DecodeCompactU16LengthFromByteReader

func DecodeCompactU16LengthFromByteReader(reader io.ByteReader) (int, error)

DecodeCompactU16LengthFromByteReader decodes a "Compact-u16" length from the provided io.ByteReader.

func EncodeCompactU16Length

func EncodeCompactU16Length(bytes *[]byte, ln int)

func GetAddedRemovedPubkeys

func GetAddedRemovedPubkeys(previous PublicKeySlice, next PublicKeySlice) (added PublicKeySlice, removed PublicKeySlice)

GetAddedRemovedPubkeys accepts two slices of pubkeys (`previous` and `next`), and returns two slices: - `added` is the slice of pubkeys that are present in `next` but NOT present in `previous`. - `removed` is the slice of pubkeys that are present in `previous` but are NOT present in `next`.

func IsOnCurve

func IsOnCurve(b []byte) bool

Check if the provided `b` is on the ed25519 curve.

func ReverseBytes

func ReverseBytes(s []byte)

func Uint32FromTypeID

func Uint32FromTypeID(vid TypeID, order binary.ByteOrder) (out uint32)

Uint32FromTypeID parses a TypeID bytes to a uint32.

func Uint8FromTypeID

func Uint8FromTypeID(vid TypeID) (out uint8)

Uint32FromTypeID parses a TypeID bytes to a uint8.

Types

type AccountMeta

type AccountMeta struct {
	PublicKey  PublicKey
	IsWritable bool
	IsSigner   bool
}

func Meta

func Meta(
	pubKey PublicKey,
) *AccountMeta

Meta intializes a new AccountMeta with the provided pubKey.

func NewAccountMeta

func NewAccountMeta(
	pubKey PublicKey,
	WRITE bool,
	SIGNER bool,
) *AccountMeta

func (*AccountMeta) SIGNER

func (meta *AccountMeta) SIGNER() *AccountMeta

SIGNER sets IsSigner to true.

func (*AccountMeta) WRITE

func (meta *AccountMeta) WRITE() *AccountMeta

WRITE sets IsWritable to true.

type AccountMetaSlice

type AccountMetaSlice []*AccountMeta

func (*AccountMetaSlice) Append

func (slice *AccountMetaSlice) Append(account *AccountMeta)

func (AccountMetaSlice) Get

func (slice AccountMetaSlice) Get(index int) *AccountMeta

Get returns the AccountMeta at the desired index. If the index is not present, it returns nil.

func (AccountMetaSlice) GetAccounts

func (slice AccountMetaSlice) GetAccounts() []*AccountMeta

func (AccountMetaSlice) GetKeys

func (slice AccountMetaSlice) GetKeys() PublicKeySlice

GetKeys returns the pubkeys of all AccountMeta.

func (AccountMetaSlice) GetSigners

func (slice AccountMetaSlice) GetSigners() []*AccountMeta

GetSigners returns the accounts that are signers.

func (AccountMetaSlice) Len

func (slice AccountMetaSlice) Len() int

func (*AccountMetaSlice) SetAccounts

func (slice *AccountMetaSlice) SetAccounts(accounts []*AccountMeta) error

func (AccountMetaSlice) SplitFrom

func (slice AccountMetaSlice) SplitFrom(index int) (AccountMetaSlice, AccountMetaSlice)

type AccountsGettable

type AccountsGettable interface {
	GetAccounts() (accounts []*AccountMeta)
}

type AccountsSettable

type AccountsSettable interface {
	SetAccounts(accounts []*AccountMeta) error
}

type Base58

type Base58 []byte

type BaseVariant

type BaseVariant struct {
	TypeID TypeID
	Impl   interface{}
}

type BinaryMarshaler

type BinaryMarshaler interface {
	MarshalWithEncoder(encoder *Encoder) error
}

type BinaryUnmarshaler

type BinaryUnmarshaler interface {
	UnmarshalWithDecoder(decoder *Decoder) error
}

type CompiledInstruction

type CompiledInstruction struct {
	// Index into the message.accountKeys array indicating the program account that executes this instruction.
	// NOTE: it is actually a uint8, but using a uint16 because uint8 is treated as a byte everywhere,
	// and that can be an issue.
	ProgramIDIndex uint16 `json:"programIdIndex"`

	// List of ordered indices into the message.accountKeys array indicating which accounts to pass to the program.
	// NOTE: it is actually a []uint8, but using a uint16 because []uint8 is treated as a []byte everywhere,
	// and that can be an issue.
	Accounts []uint16 `json:"accounts"`

	// The program input data encoded in a base-58 string.
	Data Base58 `json:"data"`
}

type Decoder

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

Decoder implements the EOS unpacking, similar to FC_BUFFER

func NewBinDecoder

func NewBinDecoder(data []byte) *Decoder

func NewDecoderWithEncoding

func NewDecoderWithEncoding(data []byte, enc Encoding) *Decoder

func (*Decoder) Decode

func (dec *Decoder) Decode(v interface{}) (err error)

func (*Decoder) Discard

func (dec *Decoder) Discard(n int) (err error)

func (*Decoder) HasRemaining

func (dec *Decoder) HasRemaining() bool

func (*Decoder) IsBin

func (dec *Decoder) IsBin() bool

func (*Decoder) IsBorsh

func (dec *Decoder) IsBorsh() bool

func (*Decoder) IsCompactU16

func (dec *Decoder) IsCompactU16() bool

func (*Decoder) Peek

func (dec *Decoder) Peek(n int) (out []byte, err error)

func (*Decoder) Position

func (dec *Decoder) Position() uint

func (*Decoder) Read

func (d *Decoder) Read(buf []byte) (int, error)

func (*Decoder) ReadBool

func (dec *Decoder) ReadBool() (out bool, err error)

func (*Decoder) ReadByte

func (dec *Decoder) ReadByte() (out byte, err error)

func (*Decoder) ReadByteSlice

func (dec *Decoder) ReadByteSlice() (out []byte, err error)

func (*Decoder) ReadBytes

func (dec *Decoder) ReadBytes(n int) (out []byte, err error)

ReadBytes reads a byte slice of length n.

func (*Decoder) ReadCompactU16

func (dec *Decoder) ReadCompactU16() (out int, err error)

ReadCompactU16 reads a compact u16 from the decoder.

func (*Decoder) ReadCompactU16Length

func (dec *Decoder) ReadCompactU16Length() (int, error)

func (*Decoder) ReadFloat128

func (dec *Decoder) ReadFloat128(order binary.ByteOrder) (out Float128, err error)

func (*Decoder) ReadFloat32

func (dec *Decoder) ReadFloat32(order binary.ByteOrder) (out float32, err error)

func (*Decoder) ReadFloat64

func (dec *Decoder) ReadFloat64(order binary.ByteOrder) (out float64, err error)

func (*Decoder) ReadInt128

func (dec *Decoder) ReadInt128(order binary.ByteOrder) (out Int128, err error)

func (*Decoder) ReadInt16

func (dec *Decoder) ReadInt16(order binary.ByteOrder) (out int16, err error)

func (*Decoder) ReadInt32

func (dec *Decoder) ReadInt32(order binary.ByteOrder) (out int32, err error)

func (*Decoder) ReadInt64

func (dec *Decoder) ReadInt64(order binary.ByteOrder) (out int64, err error)

func (*Decoder) ReadInt8

func (dec *Decoder) ReadInt8() (out int8, err error)

func (*Decoder) ReadLength

func (dec *Decoder) ReadLength() (length int, err error)

func (*Decoder) ReadNBytes

func (dec *Decoder) ReadNBytes(n int) (out []byte, err error)

func (*Decoder) ReadRustString

func (dec *Decoder) ReadRustString() (out string, err error)

func (*Decoder) ReadString

func (dec *Decoder) ReadString() (out string, err error)

func (*Decoder) ReadTypeID

func (dec *Decoder) ReadTypeID() (out TypeID, err error)

func (*Decoder) ReadUint128

func (dec *Decoder) ReadUint128(order binary.ByteOrder) (out Uint128, err error)

func (*Decoder) ReadUint16

func (dec *Decoder) ReadUint16(order binary.ByteOrder) (out uint16, err error)

func (*Decoder) ReadUint32

func (dec *Decoder) ReadUint32(order binary.ByteOrder) (out uint32, err error)

func (*Decoder) ReadUint64

func (dec *Decoder) ReadUint64(order binary.ByteOrder) (out uint64, err error)

func (*Decoder) ReadUint8

func (dec *Decoder) ReadUint8() (out uint8, err error)

func (*Decoder) ReadUvarint16

func (dec *Decoder) ReadUvarint16() (out uint16, err error)

func (*Decoder) ReadUvarint32

func (dec *Decoder) ReadUvarint32() (out uint32, err error)

func (*Decoder) ReadUvarint64

func (dec *Decoder) ReadUvarint64() (uint64, error)

func (*Decoder) ReadVarint16

func (dec *Decoder) ReadVarint16() (out int16, err error)

func (*Decoder) ReadVarint32

func (dec *Decoder) ReadVarint32() (out int32, err error)

func (*Decoder) ReadVarint64

func (d *Decoder) ReadVarint64() (out int64, err error)

func (*Decoder) Remaining

func (dec *Decoder) Remaining() int

func (*Decoder) Reset

func (dec *Decoder) Reset(data []byte)

Reset resets the decoder to decode a new message.

func (*Decoder) SafeReadUTF8String

func (dec *Decoder) SafeReadUTF8String() (out string, err error)

func (*Decoder) SetEncoding

func (dec *Decoder) SetEncoding(enc Encoding)

SetEncoding sets the encoding scheme to use for decoding.

func (*Decoder) SetPosition

func (dec *Decoder) SetPosition(idx uint) error

func (*Decoder) SkipBytes

func (dec *Decoder) SkipBytes(count uint) error

type Element

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

Element represents an element of the field GF(2^255-19). Note that this is not a cryptographically secure group, and should only be used to interact with edwards25519.Point coordinates.

This type works similarly to math/big.Int, and all arguments and receivers are allowed to alias.

The zero value is a valid zero element.

func (*Element) Absolute

func (v *Element) Absolute(u *Element) *Element

Absolute sets v to |u|, and returns v.

func (*Element) Add

func (v *Element) Add(a, b *Element) *Element

Add sets v = a + b, and returns v.

func (*Element) Bytes

func (v *Element) Bytes() []byte

Bytes returns the canonical 32-byte little-endian encoding of v.

func (*Element) Equal

func (v *Element) Equal(u *Element) int

Equal returns 1 if v and u are equal, and 0 otherwise.

func (*Element) Invert

func (v *Element) Invert(z *Element) *Element

Invert sets v = 1/z mod p, and returns v.

If z == 0, Invert returns v = 0.

func (*Element) IsNegative

func (v *Element) IsNegative() int

IsNegative returns 1 if v is negative, and 0 otherwise.

func (*Element) Mult32

func (v *Element) Mult32(x *Element, y uint32) *Element

Mult32 sets v = x * y, and returns v.

func (*Element) Multiply

func (v *Element) Multiply(x, y *Element) *Element

Multiply sets v = x * y, and returns v.

func (*Element) Negate

func (v *Element) Negate(a *Element) *Element

Negate sets v = -a, and returns v.

func (*Element) One

func (v *Element) One() *Element

One sets v = 1, and returns v.

func (*Element) Pow22523

func (v *Element) Pow22523(x *Element) *Element

Pow22523 set v = x^((p-5)/8), and returns v. (p-5)/8 is 2^252-3.

func (*Element) Select

func (v *Element) Select(a, b *Element, cond int) *Element

Select sets v to a if cond == 1, and to b if cond == 0.

func (*Element) Set

func (v *Element) Set(a *Element) *Element

Set sets v = a, and returns v.

func (*Element) SetBytes

func (v *Element) SetBytes(x []byte) (*Element, error)

SetBytes sets v to x, where x is a 32-byte little-endian encoding. If x is not of the right length, SetBytes returns nil and an error, and the receiver is unchanged.

Consistent with RFC 7748, the most significant bit (the high bit of the last byte) is ignored, and non-canonical values (2^255-19 through 2^255-1) are accepted. Note that this is laxer than specified by RFC 8032, but consistent with most Ed25519 implementations.

func (*Element) SqrtRatio

func (r *Element) SqrtRatio(u, v *Element) (R *Element, wasSquare int)

SqrtRatio sets r to the non-negative square root of the ratio of u and v.

If u/v is square, SqrtRatio returns r and 1. If u/v is not square, SqrtRatio sets r according to Section 4.3 of draft-irtf-cfrg-ristretto255-decaf448-00, and returns r and 0.

func (*Element) Square

func (v *Element) Square(x *Element) *Element

Square sets v = x * x, and returns v.

func (*Element) Subtract

func (v *Element) Subtract(a, b *Element) *Element

Subtract sets v = a - b, and returns v.

func (*Element) Swap

func (v *Element) Swap(u *Element, cond int)

Swap swaps v and u if cond == 1 or leaves them unchanged if cond == 0, and returns v.

func (*Element) Zero

func (v *Element) Zero() *Element

Zero sets v = 0, and returns v.

type Encoder

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

func NewBinEncoder

func NewBinEncoder(writer io.Writer) *Encoder

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) (err error)

func (*Encoder) WriteBool

func (e *Encoder) WriteBool(b bool) (err error)

func (*Encoder) WriteByte

func (e *Encoder) WriteByte(b byte) (err error)

func (*Encoder) WriteBytes

func (e *Encoder) WriteBytes(b []byte, writeLength bool) error

func (*Encoder) WriteCompactU16Length

func (e *Encoder) WriteCompactU16Length(ln int) (err error)

func (*Encoder) WriteFloat32

func (e *Encoder) WriteFloat32(f float32, order binary.ByteOrder) (err error)

func (*Encoder) WriteFloat64

func (e *Encoder) WriteFloat64(f float64, order binary.ByteOrder) (err error)

func (*Encoder) WriteInt128

func (e *Encoder) WriteInt128(i Int128, order binary.ByteOrder) (err error)

func (*Encoder) WriteInt16

func (e *Encoder) WriteInt16(i int16, order binary.ByteOrder) (err error)

func (*Encoder) WriteInt32

func (e *Encoder) WriteInt32(i int32, order binary.ByteOrder) (err error)

func (*Encoder) WriteInt64

func (e *Encoder) WriteInt64(i int64, order binary.ByteOrder) (err error)

func (*Encoder) WriteLength

func (e *Encoder) WriteLength(length int) error

func (*Encoder) WriteRustString

func (e *Encoder) WriteRustString(s string) (err error)

func (*Encoder) WriteString

func (e *Encoder) WriteString(s string) (err error)

func (*Encoder) WriteUVarInt

func (e *Encoder) WriteUVarInt(v int) (err error)

func (*Encoder) WriteUint128

func (e *Encoder) WriteUint128(i Uint128, order binary.ByteOrder) (err error)

func (*Encoder) WriteUint16

func (e *Encoder) WriteUint16(i uint16, order binary.ByteOrder) (err error)

func (*Encoder) WriteUint32

func (e *Encoder) WriteUint32(i uint32, order binary.ByteOrder) (err error)

func (*Encoder) WriteUint64

func (e *Encoder) WriteUint64(i uint64, order binary.ByteOrder) (err error)

func (*Encoder) WriteUint8

func (e *Encoder) WriteUint8(i uint8) (err error)

func (*Encoder) WriteVarInt

func (e *Encoder) WriteVarInt(v int) (err error)

func (*Encoder) Written

func (e *Encoder) Written() int

Written returns the count of bytes written.

type Encoding

type Encoding int
const (
	EncodingBin Encoding = iota
	EncodingCompactU16
	EncodingBorsh
)

func (Encoding) IsBin

func (en Encoding) IsBin() bool

func (Encoding) IsBorsh

func (en Encoding) IsBorsh() bool

func (Encoding) IsCompactU16

func (en Encoding) IsCompactU16() bool

func (Encoding) String

func (enc Encoding) String() string

type Float128

type Float128 Uint128

func (Float128) MarshalJSON

func (i Float128) MarshalJSON() (data []byte, err error)

func (Float128) MarshalWithEncoder

func (i Float128) MarshalWithEncoder(enc *Encoder) error

func (*Float128) UnmarshalJSON

func (i *Float128) UnmarshalJSON(data []byte) error

func (*Float128) UnmarshalWithDecoder

func (i *Float128) UnmarshalWithDecoder(dec *Decoder) error

type Hash

type Hash PublicKey

type Instruction

type Instruction interface {
	ProgramID() PublicKey     // the programID the instruction acts on
	Accounts() []*AccountMeta // returns the list of accounts the instructions requires
	Data() ([]byte, error)    // the binary encoded instructions
}

type Int128

type Int128 Uint128

Int128

func (Int128) BigInt

func (i Int128) BigInt() *big.Int

func (Int128) DecimalString

func (i Int128) DecimalString() string

func (Int128) MarshalJSON

func (i Int128) MarshalJSON() (data []byte, err error)

func (Int128) MarshalWithEncoder

func (i Int128) MarshalWithEncoder(enc *Encoder) error

func (Int128) String

func (i Int128) String() string

func (*Int128) UnmarshalJSON

func (i *Int128) UnmarshalJSON(data []byte) error

func (*Int128) UnmarshalWithDecoder

func (i *Int128) UnmarshalWithDecoder(dec *Decoder) error

type InvalidDecoderError

type InvalidDecoderError struct {
	Type reflect.Type
}

An InvalidDecoderError describes an invalid argument passed to Decoder. (The argument to Decoder must be a non-nil pointer.)

func (*InvalidDecoderError) Error

func (e *InvalidDecoderError) Error() string

type Message

type Message struct {

	// List of base-58 encoded public keys used by the transaction,
	// including by the instructions and for signatures.
	// The first `message.header.numRequiredSignatures` public keys must sign the transaction.
	AccountKeys []PublicKey `json:"accountKeys"`

	// Details the account types and signatures required by the transaction.
	Header MessageHeader `json:"header"`

	// A base-58 encoded hash of a recent block in the ledger used to
	// prevent transaction duplication and to give transactions lifetimes.
	RecentBlockhash Hash `json:"recentBlockhash"`

	// List of program instructions that will be executed in sequence
	// and committed in one atomic transaction if all succeed.
	Instructions []CompiledInstruction `json:"instructions"`
	// contains filtered or unexported fields
}

func (*Message) IsSigner

func (m *Message) IsSigner(account PublicKey) bool

func (*Message) IsWritable

func (m *Message) IsWritable(account PublicKey) bool

func (*Message) MarshalBinary

func (mx *Message) MarshalBinary() ([]byte, error)

func (*Message) Signers

func (m *Message) Signers() PublicKeySlice

Signers returns the pubkeys of all accounts that are signers.

func (*Message) UnmarshalBase64

func (mx *Message) UnmarshalBase64(b64 string) error

func (*Message) UnmarshalLegacy

func (mx *Message) UnmarshalLegacy(decoder *Decoder) (err error)

func (*Message) UnmarshalV0

func (mx *Message) UnmarshalV0(decoder *Decoder) (err error)

func (*Message) UnmarshalWithDecoder

func (mx *Message) UnmarshalWithDecoder(decoder *Decoder) (err error)

func (*Message) Writable

func (m *Message) Writable() (out PublicKeySlice)

Writable returns the pubkeys of all accounts that are writable.

type MessageAddressTableLookup

type MessageAddressTableLookup struct {
	AccountKey      PublicKey // The account key of the address table.
	WritableIndexes []uint8
	ReadonlyIndexes []uint8
}

type MessageAddressTableLookupSlice

type MessageAddressTableLookupSlice []MessageAddressTableLookup

func (MessageAddressTableLookupSlice) GetTableIDs

func (lookups MessageAddressTableLookupSlice) GetTableIDs() PublicKeySlice

GetTableIDs returns the list of all address table IDs.

func (MessageAddressTableLookupSlice) NumLookups

func (lookups MessageAddressTableLookupSlice) NumLookups() int

NumLookups returns the number of accounts in all the MessageAddressTableLookupSlice

type MessageHeader

type MessageHeader struct {
	// The total number of signatures required to make the transaction valid.
	// The signatures must match the first `numRequiredSignatures` of `message.account_keys`.
	NumRequiredSignatures uint8 `json:"numRequiredSignatures"`

	// The last numReadonlySignedAccounts of the signed keys are read-only accounts.
	// Programs may process multiple transactions that load read-only accounts within
	// a single PoH entry, but are not permitted to credit or debit lamports or modify
	// account data.
	// Transactions targeting the same read-write account are evaluated sequentially.
	NumReadonlySignedAccounts uint8 `json:"numReadonlySignedAccounts"`

	// The last `numReadonlyUnsignedAccounts` of the unsigned keys are read-only accounts.
	NumReadonlyUnsignedAccounts uint8 `json:"numReadonlyUnsignedAccounts"`
}

type MessageVersion

type MessageVersion int
const (
	MessageVersionLegacy MessageVersion = 0 // default
	MessageVersionV0     MessageVersion = 1 // v0
)

type Point

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

Point represents a point on the edwards25519 curve.

This type works similarly to math/big.Int, and all arguments and receivers are allowed to alias.

The zero value is NOT valid, and it may be used only as a receiver.

func (*Point) SetBytes

func (v *Point) SetBytes(x []byte) (*Point, error)

SetBytes sets v = x, where x is a 32-byte encoding of v. If x does not represent a valid point on the curve, SetBytes returns nil and an error and the receiver is unchanged. Otherwise, SetBytes returns v.

Note that SetBytes accepts all non-canonical encodings of valid points. That is, it follows decoding rules that match most implementations in the ecosystem rather than RFC 8032.

type PrivateKey

type PrivateKey []byte

func MustPrivateKeyFromBase58

func MustPrivateKeyFromBase58(in string) PrivateKey

func NewRandomPrivateKey

func NewRandomPrivateKey() (PrivateKey, error)

func PrivateKeyFromBase58

func PrivateKeyFromBase58(privkey string) (PrivateKey, error)

func (PrivateKey) Bytes

func (p PrivateKey) Bytes() []byte

func (PrivateKey) PublicKey

func (k PrivateKey) PublicKey() PublicKey

func (PrivateKey) Sign

func (k PrivateKey) Sign(payload []byte) (Signature, error)

func (PrivateKey) String

func (k PrivateKey) String() string

type PublicKey

type PublicKey [PublicKeyLength]byte

func FindAssociatedTokenAddress

func FindAssociatedTokenAddress(wallet PublicKey, mint PublicKey, options ...string) (PublicKey, uint8, error)

func FindAssociatedTokenAddressAndBumpSeed

func FindAssociatedTokenAddressAndBumpSeed(walletAddress PublicKey, splTokenMintAddress PublicKey, programID PublicKey, options ...string) (PublicKey, uint8, error)

func FindProgramAddress

func FindProgramAddress(seed [][]byte, programID PublicKey) (PublicKey, uint8, error)

Find a valid program address and its corresponding bump seed.

func MustPublicKeyFromBase58

func MustPublicKeyFromBase58(in string) PublicKey

func PublicKeyFromBase58

func PublicKeyFromBase58(in string) (out PublicKey, err error)

func PublicKeyFromBytes

func PublicKeyFromBytes(in []byte) (out PublicKey)

func (PublicKey) Bytes

func (p PublicKey) Bytes() []byte

func (PublicKey) Equals

func (p PublicKey) Equals(pb PublicKey) bool

func (PublicKey) IsZero

func (p PublicKey) IsZero() bool

IsZero returns whether the public key is zero. NOTE: the System Program public key is also zero.

func (PublicKey) MarshalText

func (p PublicKey) MarshalText() ([]byte, error)

func (PublicKey) Short

func (p PublicKey) Short(n int) string

Short returns a shortened pubkey string, only including the first n chars, ellipsis, and the last n characters. NOTE: this is ONLY for visual representation for humans, and cannot be used for anything else.

func (PublicKey) String

func (p PublicKey) String() string

func (PublicKey) ToPointer

func (p PublicKey) ToPointer() *PublicKey

ToPointer returns a pointer to the pubkey.

func (*PublicKey) UnmarshalText

func (p *PublicKey) UnmarshalText(data []byte) (err error)

type PublicKeySlice

type PublicKeySlice []PublicKey

func (*PublicKeySlice) Append

func (slice *PublicKeySlice) Append(pubkeys ...PublicKey)

func (PublicKeySlice) Has

func (slice PublicKeySlice) Has(pubkey PublicKey) bool

func (PublicKeySlice) Split

func (slice PublicKeySlice) Split(chunkSize int) []PublicKeySlice

Split splits the slice into chunks of the specified size.

func (*PublicKeySlice) UniqueAppend

func (slice *PublicKeySlice) UniqueAppend(pubkey PublicKey) bool

UniqueAppend appends the provided pubkey only if it is not already present in the slice. Returns true when the provided pubkey wasn't already present.

type Signature

type Signature [64]byte

type Transaction

type Transaction struct {
	// A list of base-58 encoded signatures applied to the transaction.
	// The list is always of length `message.header.numRequiredSignatures` and not empty.
	// The signature at index `i` corresponds to the public key at index
	// `i` in `message.account_keys`. The first one is used as the transaction id.
	Signatures []Signature `json:"signatures"`

	// Defines the content of the transaction.
	Message Message `json:"message"`
}

func NewTransaction

func NewTransaction(instructions []Instruction, recentBlockHash Hash, payer PublicKey) (*Transaction, error)

func (*Transaction) MarshalBinary

func (tx *Transaction) MarshalBinary() ([]byte, error)

func (*Transaction) Sign

func (tx *Transaction) Sign(getter privateKeyGetter) (out []Signature, err error)

func (Transaction) ToBase58

func (tx Transaction) ToBase58() (string, error)

func (Transaction) ToBase64

func (tx Transaction) ToBase64() (string, error)

func (*Transaction) UnmarshalBase58

func (tx *Transaction) UnmarshalBase58(b58 string) error

UnmarshalBase58 decodes a base58 encoded transaction.

func (*Transaction) UnmarshalBase64

func (tx *Transaction) UnmarshalBase64(b64 string) error

UnmarshalBase64 decodes a base64 encoded transaction.

func (*Transaction) UnmarshalWithDecoder

func (tx *Transaction) UnmarshalWithDecoder(decoder *Decoder) (err error)

type TypeID

type TypeID [8]byte

TypeID defines the internal representation of an instruction type ID (or account type, etc. in anchor programs) and it's used to associate instructions to decoders in the variant tracker.

func TypeIDFromBytes

func TypeIDFromBytes(slice []byte) (id TypeID)

TypeIDFromBytes converts a []byte to a TypeID. The provided slice must be 8 bytes long or less.

func TypeIDFromUint32

func TypeIDFromUint32(v uint32, bo binary.ByteOrder) TypeID

TypeIDFromUint32 converts a uint32 to a TypeID.

func TypeIDFromUint8

func TypeIDFromUint8(v uint8) TypeID

TypeIDFromUint32 converts a uint8 to a TypeID.

func (TypeID) Bytes

func (vid TypeID) Bytes() []byte

func (TypeID) Uint32

func (vid TypeID) Uint32() uint32

Uint32 parses the TypeID to a uint32.

func (TypeID) Uint8

func (vid TypeID) Uint8() uint8

Uint8 parses the TypeID to a Uint8.

type Uint128

type Uint128 struct {
	Lo         uint64
	Hi         uint64
	Endianness binary.ByteOrder
}

Uint128

func NewUint128BigEndian

func NewUint128BigEndian() *Uint128

func NewUint128LittleEndian

func NewUint128LittleEndian() *Uint128

func (Uint128) BigInt

func (i Uint128) BigInt() *big.Int

func (Uint128) Bytes

func (i Uint128) Bytes() []byte

func (Uint128) DecimalString

func (i Uint128) DecimalString() string

func (Uint128) HexString

func (i Uint128) HexString() string

func (Uint128) MarshalJSON

func (i Uint128) MarshalJSON() (data []byte, err error)

func (Uint128) MarshalWithEncoder

func (i Uint128) MarshalWithEncoder(enc *Encoder) error

func (Uint128) String

func (i Uint128) String() string

func (*Uint128) UnmarshalJSON

func (i *Uint128) UnmarshalJSON(data []byte) error

func (*Uint128) UnmarshalWithDecoder

func (i *Uint128) UnmarshalWithDecoder(dec *Decoder) error

Jump to

Keyboard shortcuts

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