base

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	// Maximum length of derived pubkey seed.
	MaxSeedLength = 32
	// Maximum number of seeds.
	MaxSeeds = 16
)
View Source
const PDA_MARKER = "ProgramDerivedAddress"

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 = common.StrToAddress("11111111111111111111111111111111")

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

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

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

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

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

	FeatureProgramID = common.StrToAddress("Feature111111111111111111111111111111111111")

	ComputeBudget = common.StrToAddress("ComputeBudget111111111111111111111111111111")

	//
	SPLNameServiceProgramID     = common.StrToAddress("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX")
	MetaplexTokenMetaProgramID  = common.StrToAddress("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s")
	ComputeBudgetProgramID      = common.StrToAddress("ComputeBudget111111111111111111111111111111")
	AddressLookupTableProgramID = common.StrToAddress("AddressLookupTab1e1111111111111111111111111")
)
View Source
var (
	// A Token program on the Solana blockchain.
	// This program defines a common implementation for Fungible and Non Fungible tokens.
	TokenProgramID = common.StrToAddress("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")

	Token2022ProgramID = common.StrToAddress("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")

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

	// A lending protocol for the Token program on the Solana blockchain inspired by Aave and Compound.
	TokenLendingProgramID = common.StrToAddress("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 = common.StrToAddress("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 = common.StrToAddress("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr")
)

SPL:

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

	SolMint2022 = common.StrToAddress("9pan9bMn5HatX4EJdBwg9VgCa7Uz5HL8N1m5D3NdXejP")

	WrappedSol = SolMint

	TokenMetadataProgramID = common.StrToAddress("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s")

	MetaplexCandyMachineV2ProgramID = common.StrToAddress("cndy3Z4yapfJBmL3ShUp5exZKqR3z33thTzeNMm2gRZ")
	MetaplexTokenMetadataProgramID  = common.StrToAddress("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s")
)
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 = common.StrToAddress("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 = common.StrToAddress("SysvarEpochSchedu1e111111111111111111111111")

	// The Fees sysvar contains the fee calculator for the current slot.
	// It is updated every slot, based on the fee-rate governor.
	SysVarFeesPubkey = common.StrToAddress("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 = common.StrToAddress("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 = common.StrToAddress("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 = common.StrToAddress("SysvarRent111111111111111111111111111111111")

	//
	SysVarRewardsPubkey = common.StrToAddress("SysvarRewards111111111111111111111111111111")

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

	// The SlotHistory sysvar contains a bitvector of slots present over the last epoch. It is updated every slot.
	SysVarSlotHistoryPubkey = common.StrToAddress("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 = common.StrToAddress("SysvarStakeHistory1111111111111111111111111")

	SysVarPubkey                 = common.StrToAddress("Sysvar1111111111111111111111111111111111111")
	SysVarRecentBlockhashsPubkey = common.StrToAddress("SysvarRecentB1ockHashes11111111111111111111")
	StakeConfigPubkey            = common.StrToAddress("StakeConfig11111111111111111111111111111111")
)
View Source
var ErrMaxSeedLengthExceeded = errors.New("Max seed length exceeded")

Functions

func CreateProgramAddress added in v0.1.0

func CreateProgramAddress(seeds [][]byte, programID common.Address) (common.Address, error)

Create a program address. Ported from https://github.com/solana-labs/solana/blob/216983c50e0a618facc39aa07472ba6d23f1b33a/sdk/program/src/pubkey.rs#L204

func FindAssociatedTokenAddress added in v0.1.0

func FindAssociatedTokenAddress(wallet common.Address, mint common.Address, options ...common.Address) (common.Address, uint8, error)

func FindAssociatedTokenAddressAndBumpSeed added in v0.1.0

func FindAssociatedTokenAddressAndBumpSeed(walletAddress common.Address, splTokenMintAddress common.Address, programID common.Address, options ...common.Address) (common.Address, uint8, error)

func FindProgramAddress added in v0.1.0

func FindProgramAddress(seed [][]byte, programID common.Address) (common.Address, uint8, error)

Find a valid program address and its corresponding bump seed.

func IsOnCurve added in v0.1.0

func IsOnCurve(b []byte) bool

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

Types

type AccountMeta added in v0.0.8

type AccountMeta struct {
	PublicKey  common.Address `json:"publickey"`
	IsWritable bool
	IsSigner   bool
}

func Meta added in v0.0.8

func Meta(pubKey common.Address) *AccountMeta

Meta intializes a new AccountMeta with the provided pubKey.

func NewAccountMeta added in v0.0.8

func NewAccountMeta(pubKey common.Address, WRITE bool, SIGNER bool) *AccountMeta

func (*AccountMeta) Less added in v0.0.8

func (meta *AccountMeta) Less(act *AccountMeta) bool

func (*AccountMeta) SIGNER added in v0.0.8

func (meta *AccountMeta) SIGNER() *AccountMeta

SIGNER sets IsSigner to true.

func (*AccountMeta) WRITE added in v0.0.8

func (meta *AccountMeta) WRITE() *AccountMeta

WRITE sets IsWritable to true.

type AccountMetaSlice added in v0.1.0

type AccountMetaSlice []*AccountMeta

func (*AccountMetaSlice) Append added in v0.1.0

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

func (AccountMetaSlice) Get added in v0.1.0

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 added in v0.1.0

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

func (AccountMetaSlice) GetKeys added in v0.1.0

func (slice AccountMetaSlice) GetKeys() (keys []common.Address)

GetKeys returns the pubkeys of all AccountMeta.

func (AccountMetaSlice) GetSigners added in v0.1.0

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

GetSigners returns the accounts that are signers.

func (AccountMetaSlice) Len added in v0.1.0

func (slice AccountMetaSlice) Len() int

func (*AccountMetaSlice) SetAccounts added in v0.1.0

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

type AccountsGettable added in v0.0.8

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

type AccountsSettable added in v0.0.8

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

type Element added in v0.1.0

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 added in v0.1.0

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

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

func (*Element) Add added in v0.1.0

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

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

func (*Element) Bytes added in v0.1.0

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

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

func (*Element) Equal added in v0.1.0

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

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

func (*Element) Invert added in v0.1.0

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 added in v0.1.0

func (v *Element) IsNegative() int

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

func (*Element) Mult32 added in v0.1.0

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

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

func (*Element) Multiply added in v0.1.0

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

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

func (*Element) Negate added in v0.1.0

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

Negate sets v = -a, and returns v.

func (*Element) One added in v0.1.0

func (v *Element) One() *Element

One sets v = 1, and returns v.

func (*Element) Pow22523 added in v0.1.0

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 added in v0.1.0

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 added in v0.1.0

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

Set sets v = a, and returns v.

func (*Element) SetBytes added in v0.1.0

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 added in v0.1.0

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 added in v0.1.0

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

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

func (*Element) Subtract added in v0.1.0

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

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

func (*Element) Swap added in v0.1.0

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 added in v0.1.0

func (v *Element) Zero() *Element

Zero sets v = 0, and returns v.

type Point added in v0.1.0

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 added in v0.1.0

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.

Jump to

Keyboard shortcuts

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