felt

package
v0.15.13 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: Apache-2.0 Imports: 6 Imported by: 137

Documentation

Index

Constants

View Source
const (
	Base16 = 16
	Base10 = 10
)
View Source
const (
	Limbs = fp.Limbs // number of 64 bits words needed to represent a Element
	Bits  = fp.Bits  // number of bits needed to represent a Element
	Bytes = fp.Bytes // number of bytes needed to represent a Element
)

Variables

View Source
var One = Felt(fp.Element(
	[4]uint64{
		18446744073709551585,
		18446744073709551615,
		18446744073709551615,
		576460752303422960,
	},
))
View Source
var Zero = Felt{}

Functions

func FromBytes added in v0.14.3

func FromBytes[F FeltLike](value []byte) F

FromBytes crates a new Felt based type given a byte array

func FromString added in v0.15.7

func FromString[F FeltLike](value string) (F, error)

FromString crates a new Felt based type given a any string

func FromUint64 added in v0.14.3

func FromUint64[F FeltLike](num uint64) F

FromUint64 creates a new Felt based type given an uint64

func NewFromBytes added in v0.15.7

func NewFromBytes[F FeltLike](val []byte) *F

NewFromBytes crates a new Felt based type given a byte array. Use this function with care since it forces a heap allocation. For efficient code use `FromBytes`

func NewFromString added in v0.15.7

func NewFromString[F FeltLike](val string) (*F, error)

NewFromString crates a new Felt based type given a string. Use this function with care since it forces a heap allocation. For efficient code use `FromString`

func NewFromUint64 added in v0.15.7

func NewFromUint64[F FeltLike](num uint64) *F

NewFromUint64 crates a new Felt based type given a uint64. Use this function with care since it forces a heap allocation. For efficient code use `FromUint64`

func NewRandom added in v0.15.7

func NewRandom[F FeltLike]() *F

NewRandom creates a new random Felt based type. It also forces a heap allocation. For efficient code use `Random`

func NewUnsafeFromString added in v0.15.8

func NewUnsafeFromString[F FeltLike](val string) *F

NewUnsafeFromString is similar to `NewFromString` but it panics instead of returning an error.

func Random added in v0.15.8

func Random[F FeltLike]() F

Creates a new random Felt based type

func UnsafeFromString added in v0.15.7

func UnsafeFromString[F FeltLike](value string) F

UnsafeFromString crates a new Felt based type given a any string. It panics if the string is not valid.

Types

type Address added in v0.15.7

type Address Felt

func (*Address) Bytes added in v0.15.7

func (a *Address) Bytes() [32]byte

func (*Address) Marshal added in v0.15.13

func (a *Address) Marshal() []byte

func (*Address) MarshalJSON added in v0.15.11

func (a *Address) MarshalJSON() ([]byte, error)

func (*Address) SetBytesCanonical added in v0.15.13

func (a *Address) SetBytesCanonical(data []byte) error

func (*Address) String added in v0.15.7

func (a *Address) String() string

func (*Address) Unmarshal added in v0.15.13

func (a *Address) Unmarshal(e []byte)

func (*Address) UnmarshalJSON added in v0.15.11

func (a *Address) UnmarshalJSON(data []byte) error

type CasmClassHash added in v0.15.10

type CasmClassHash ClassHash

func (*CasmClassHash) Marshal added in v0.15.11

func (h *CasmClassHash) Marshal() []byte

func (*CasmClassHash) MarshalJSON added in v0.15.11

func (h *CasmClassHash) MarshalJSON() ([]byte, error)

func (*CasmClassHash) SetBytesCanonical added in v0.15.13

func (h *CasmClassHash) SetBytesCanonical(data []byte) error

func (*CasmClassHash) String added in v0.15.10

func (h *CasmClassHash) String() string

func (*CasmClassHash) Unmarshal added in v0.15.11

func (h *CasmClassHash) Unmarshal(e []byte)

func (*CasmClassHash) UnmarshalJSON added in v0.15.11

func (h *CasmClassHash) UnmarshalJSON(data []byte) error

type ClassHash added in v0.15.7

type ClassHash Hash

func (*ClassHash) Marshal added in v0.15.11

func (h *ClassHash) Marshal() []byte

func (*ClassHash) MarshalJSON added in v0.15.11

func (h *ClassHash) MarshalJSON() ([]byte, error)

func (*ClassHash) SetBytesCanonical added in v0.15.13

func (h *ClassHash) SetBytesCanonical(data []byte) error

func (*ClassHash) String added in v0.15.7

func (h *ClassHash) String() string

func (*ClassHash) Unmarshal added in v0.15.11

func (h *ClassHash) Unmarshal(e []byte)

func (*ClassHash) UnmarshalJSON added in v0.15.11

func (h *ClassHash) UnmarshalJSON(data []byte) error

type Felt

type Felt fp.Element

func (*Felt) Add

func (z *Felt) Add(x, y *Felt) *Felt

Add forwards the call to underlying field element implementation

func (*Felt) BigInt

func (z *Felt) BigInt(res *big.Int) *big.Int

BigInt forwards the call to underlying field element implementation

func (*Felt) Bits

func (z *Felt) Bits() [4]uint64

Bits forwards the call to underlying field element implementation. Provides access to z by returning its value as a little-endian [4]uint64 array.

func (*Felt) Bytes

func (z *Felt) Bytes() [32]byte

Bytes forwards the call to underlying field element implementation. Returns the value of z as a big-endian byte array

func (*Felt) Clone added in v0.9.3

func (z *Felt) Clone() *Felt

TODO: look where this is used, the clone shouldn't return a pointer

func (*Felt) Cmp added in v0.2.1

func (z *Felt) Cmp(x *Felt) int

Cmp forwards the call to underlying field element implementation. Returns:

-1 if z <  x
 0 if z == x
+1 if z >  x

func (*Felt) Div added in v0.6.0

func (z *Felt) Div(x, y *Felt) *Felt

Div forwards the call to underlying field element implementation

func (*Felt) Double added in v0.2.1

func (z *Felt) Double(x *Felt) *Felt

Double forwards the call to underlying field element implementation

func (*Felt) Equal

func (z *Felt) Equal(x *Felt) bool

Equal forwards the call to underlying field element implementation

func (*Felt) Exp added in v0.2.1

func (z *Felt) Exp(x *Felt, y *big.Int) *Felt

Exp forwards the call to underlying field element implementation

func (*Felt) Halve

func (z *Felt) Halve()

Halve forwards the call to underlying field element implementation

func (*Felt) Impl

func (z *Felt) Impl() *fp.Element

Impl returns the underlying field element type

func (*Felt) IsOne

func (z *Felt) IsOne() bool

IsOne forwards the call to underlying field element implementation

func (*Felt) IsZero

func (z *Felt) IsZero() bool

IsZero forwards the call to underlying field element implementation

func (*Felt) Marshal

func (z *Felt) Marshal() []byte

Marshal forwards the call to underlying field element implementation

func (*Felt) MarshalCBOR

func (z *Felt) MarshalCBOR() ([]byte, error)

MarshalCBOR lets Felt be encoded in CBOR format with private `val`

func (*Felt) MarshalJSON

func (z *Felt) MarshalJSON() ([]byte, error)

MarshalJSON forwards the call to underlying field element implementation

func (*Felt) Mul added in v0.2.1

func (z *Felt) Mul(x, y *Felt) *Felt

Mul forwards the call to underlying field element implementation

func (*Felt) Neg added in v0.15.7

func (z *Felt) Neg(x *Felt) *Felt

func (*Felt) Set

func (z *Felt) Set(x *Felt) *Felt

Set forwards the call to underlying field element implementation

func (*Felt) SetBigInt added in v0.4.0

func (z *Felt) SetBigInt(v *big.Int) *Felt

SetBigInt forwards the call to underlying field element implementation

func (*Felt) SetBytes

func (z *Felt) SetBytes(e []byte) *Felt

SetBytes forwards the call to underlying field element implementation

func (*Felt) SetBytesCanonical added in v0.14.7

func (z *Felt) SetBytesCanonical(e []byte) error

SetBytesCanonical forwards the call to underlying field element implementation

func (*Felt) SetRandom

func (z *Felt) SetRandom() *Felt

SetRandom forwards the call to underlying field element implementation

func (*Felt) SetString

func (z *Felt) SetString(number string) (*Felt, error)

SetString forwards the call to underlying field element implementation

func (*Felt) SetUint64

func (z *Felt) SetUint64(v uint64) *Felt

SetUint64 forwards the call to underlying field element implementation

func (*Felt) ShortString

func (z *Felt) ShortString() string

ShortString prints the felt to a string in a shortened format

func (*Felt) String

func (z *Felt) String() string

String forwards the call to underlying field element implementation

func (*Felt) Sub added in v0.2.1

func (z *Felt) Sub(x, y *Felt) *Felt

Sub forwards the call to underlying field element implementation

func (*Felt) Text

func (z *Felt) Text(base int) string

Text forwards the call to underlying field element implementation

func (*Felt) Uint64 added in v0.4.0

func (z *Felt) Uint64() uint64

Uint64 forwards the call to underlying field element implementation

func (*Felt) Unmarshal added in v0.13.0

func (z *Felt) Unmarshal(e []byte)

Unmarshal forwards the call to underlying field element implementation

func (*Felt) UnmarshalCBOR

func (z *Felt) UnmarshalCBOR(data []byte) error

UnmarshalCBOR lets Felt be decoded from CBOR format with private `val`

func (*Felt) UnmarshalJSON

func (z *Felt) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts numbers and strings as input. See Element.SetString for valid prefixes (0x, 0b, ...). If there is an error, we try to explicitly unmarshal from hex before returning an error. This implementation is based on gnark-crypto's UnmarshalJSON.

type FeltLike added in v0.15.7

type FeltLike interface {
	~[4]uint64
}

Interface that represents all types that implement Felt as a sublying type E.g: Hash and Address

type Hash added in v0.15.7

type Hash Felt

func (*Hash) Bytes added in v0.15.7

func (h *Hash) Bytes() [32]byte

func (*Hash) Marshal added in v0.15.11

func (h *Hash) Marshal() []byte

func (*Hash) MarshalJSON added in v0.15.11

func (h *Hash) MarshalJSON() ([]byte, error)

func (*Hash) SetBytesCanonical added in v0.15.13

func (h *Hash) SetBytesCanonical(data []byte) error

func (*Hash) String added in v0.15.7

func (h *Hash) String() string

func (*Hash) Unmarshal added in v0.15.11

func (h *Hash) Unmarshal(e []byte)

func (*Hash) UnmarshalJSON added in v0.15.11

func (h *Hash) UnmarshalJSON(data []byte) error

type SierraClassHash added in v0.15.10

type SierraClassHash ClassHash

func (*SierraClassHash) Marshal added in v0.15.11

func (h *SierraClassHash) Marshal() []byte

func (*SierraClassHash) MarshalJSON added in v0.15.11

func (h *SierraClassHash) MarshalJSON() ([]byte, error)

func (*SierraClassHash) SetBytesCanonical added in v0.15.13

func (h *SierraClassHash) SetBytesCanonical(data []byte) error

func (*SierraClassHash) String added in v0.15.10

func (h *SierraClassHash) String() string

func (*SierraClassHash) Unmarshal added in v0.15.11

func (h *SierraClassHash) Unmarshal(e []byte)

func (*SierraClassHash) UnmarshalJSON added in v0.15.11

func (h *SierraClassHash) UnmarshalJSON(data []byte) error

type TransactionHash added in v0.15.7

type TransactionHash Hash

func (*TransactionHash) Marshal added in v0.15.13

func (h *TransactionHash) Marshal() []byte

func (*TransactionHash) MarshalJSON added in v0.15.11

func (h *TransactionHash) MarshalJSON() ([]byte, error)

func (*TransactionHash) SetBytesCanonical added in v0.15.13

func (h *TransactionHash) SetBytesCanonical(data []byte) error

func (*TransactionHash) String added in v0.15.7

func (h *TransactionHash) String() string

func (*TransactionHash) Unmarshal added in v0.15.13

func (h *TransactionHash) Unmarshal(e []byte)

func (*TransactionHash) UnmarshalJSON added in v0.15.11

func (h *TransactionHash) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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