Documentation
¶
Index ¶
- Constants
- func CastPointerSlice[To, From FeltLike](s []*From) []*To
- func CastSlice[To, From FeltLike](s []From) []To
- func Equal[F FeltLike](a, b *F) bool
- func FromBytes[F FeltLike](value []byte) F
- func FromMinimalBytes[F FeltLike](value []byte) (F, error)
- func FromString[F FeltLike](value string) (F, error)
- func FromUint64[F FeltLike](num uint64) F
- func ImplOf[F FeltLike](f *F) *fp.Element
- func IsZero[F FeltLike](v *F) bool
- func NewFromBytes[F FeltLike](val []byte) *F
- func NewFromString[F FeltLike](val string) (*F, error)
- func NewFromUint64[F FeltLike](num uint64) *F
- func NewRandom[F FeltLike]() *F
- func NewUnsafeFromString[F FeltLike](val string) *F
- func One[F FeltLike]() F
- func Random[F FeltLike]() F
- func UnsafeFromString[F FeltLike](value string) F
- func Zero[F FeltLike]() F
- type Address
- type CasmClassHash
- type ClassHash
- type Felt
- type FeltLike
- type Hash
- type SierraClassHash
- type Slice
- type StateRootHash
- type TransactionHash
- type Typed
- func (z *Typed[K]) Add(x, y *Typed[K]) *Typed[K]
- func (z Typed[K]) AppendText(data []byte) ([]byte, error)
- func (z *Typed[K]) BigInt(res *big.Int) *big.Int
- func (z *Typed[K]) Bits() [4]uint64
- func (z *Typed[K]) Bytes() [32]byte
- func (z *Typed[K]) Cmp(x *Typed[K]) int
- func (z *Typed[K]) Div(x, y *Typed[K]) *Typed[K]
- func (z *Typed[K]) Double(x *Typed[K]) *Typed[K]
- func (z *Typed[K]) Equal(x *Typed[K]) bool
- func (z *Typed[K]) Exp(x *Typed[K], y *big.Int) *Typed[K]
- func (z *Typed[K]) Halve()
- func (z *Typed[K]) Impl() *fp.Element
- func (z *Typed[K]) IsOne() bool
- func (z *Typed[K]) IsZero() bool
- func (z *Typed[K]) Marshal() []byte
- func (z *Typed[K]) MarshalCBOR() ([]byte, error)
- func (z Typed[K]) MarshalText() ([]byte, error)
- func (z *Typed[K]) MinimalBytes() []byte
- func (z *Typed[K]) Mul(x, y *Typed[K]) *Typed[K]
- func (z *Typed[K]) Neg(x *Typed[K]) *Typed[K]
- func (z *Typed[K]) Set(x *Typed[K]) *Typed[K]
- func (z *Typed[K]) SetBigInt(v *big.Int) *Typed[K]
- func (z *Typed[K]) SetBytes(e []byte) *Typed[K]
- func (z *Typed[K]) SetBytesCanonical(e []byte) error
- func (z *Typed[K]) SetMinimalBytes(data []byte) error
- func (z *Typed[K]) SetRandom() *Typed[K]
- func (z *Typed[K]) SetString(number string) (*Typed[K], error)
- func (z *Typed[K]) SetUint64(v uint64) *Typed[K]
- func (z *Typed[K]) ShortString() string
- func (z *Typed[K]) StoredBytes() []byte
- func (z *Typed[K]) String() string
- func (z *Typed[K]) Sub(x, y *Typed[K]) *Typed[K]
- func (z *Typed[K]) Text(base int) string
- func (z *Typed[K]) Uint64() uint64
- func (z *Typed[K]) Unmarshal(e []byte)
- func (z *Typed[K]) UnmarshalCBOR(data []byte) error
- func (z *Typed[K]) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- func (z *Typed[K]) UnmarshalText(text []byte) error
- func (z Typed[K]) ValidatorValue() any
Constants ¶
const ( Base16 = 16 Base10 = 10 )
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 // Max number of chars to represent a Felt as Hex. // 0x at the start + 2 chars per byte. MaxFeltAsHexSize = len("0x") + Bytes*2 )
const CompactWrites = false
CompactWrites reports whether this build writes felts in the compact forms.
Variables ¶
This section is empty.
Functions ¶
func CastPointerSlice ¶ added in v0.17.1
func CastPointerSlice[To, From FeltLike](s []*From) []*To
CastPointerSlice reinterprets s as pointers to another felt type, sharing its backing array.
func CastSlice ¶ added in v0.17.1
func CastSlice[To, From FeltLike](s []From) []To
CastSlice reinterprets s as another felt type, sharing its backing array.
func Equal ¶ added in v0.15.15
Equal reports whether a and b are equal; limb equality is the field element's own definition.
func FromMinimalBytes ¶ added in v0.17.1
FromMinimalBytes creates a new Felt based type from 1 to 32 big-endian bytes below the modulus.
func FromString ¶ added in v0.15.7
FromString crates a new Felt based type given a any string
func FromUint64 ¶ added in v0.14.3
FromUint64 creates a new Felt based type given an uint64
func ImplOf ¶ added in v0.17.1
ImplOf returns the field element behind any felt type without copying it.
func IsZero ¶ added in v0.15.15
IsZero reports whether v is zero; limb equality is the field element's own definition.
func NewFromBytes ¶ added in v0.15.7
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
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
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
NewUnsafeFromString is similar to `NewFromString` but it panics instead of returning an error.
func UnsafeFromString ¶ added in v0.15.7
UnsafeFromString crates a new Felt based type given a any string. It panics if the string is not valid.
Types ¶
type CasmClassHash ¶ added in v0.15.10
type CasmClassHash = Typed[casmClassHashKind]
type FeltLike ¶ added in v0.15.7
type FeltLike interface {
~[4]uint64
}
FeltLike is the constraint for generic code over felts: every Typed[K] satisfies it, as does any type declared over one. It exists because a generic type such as Slice cannot infer K.
type SierraClassHash ¶ added in v0.15.10
type SierraClassHash = Typed[sierraClassHashKind]
type Slice ¶ added in v0.16.6
type Slice[F FeltLike] []F
func (Slice[F]) MarshalCBOR ¶ added in v0.16.6
func (Slice[F]) MarshalJSONTo ¶ added in v0.16.6
func (*Slice[F]) UnmarshalCBOR ¶ added in v0.16.6
type StateRootHash ¶ added in v0.15.17
type StateRootHash = Typed[stateRootHashKind]
type TransactionHash ¶ added in v0.15.7
type TransactionHash = Typed[transactionHashKind]
type Typed ¶ added in v0.17.0
Typed is a field element told apart at compile time by a phantom kind. Every Typed[K] shares one implementation, so all felt types behave and encode the same and converting between them is free.
func (*Typed[K]) Add ¶ added in v0.17.0
Add forwards the call to underlying field element implementation
func (Typed[K]) AppendText ¶ added in v0.17.0
AppendText appends the felt's 0x hex representation to data. The quotes are placed at the encoding/json level. It is a json/v2 interface and enforces appending.
func (*Typed[K]) BigInt ¶ added in v0.17.0
BigInt forwards the call to underlying field element implementation
func (*Typed[K]) Bits ¶ added in v0.17.0
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 (*Typed[K]) Bytes ¶ added in v0.17.0
Bytes forwards the call to underlying field element implementation. Returns the value of z as a big-endian byte array
func (*Typed[K]) Cmp ¶ added in v0.17.0
Cmp forwards the call to underlying field element implementation. Returns:
-1 if z < x 0 if z == x +1 if z > x
func (*Typed[K]) Div ¶ added in v0.17.0
Div forwards the call to underlying field element implementation
func (*Typed[K]) Double ¶ added in v0.17.0
Double forwards the call to underlying field element implementation
func (*Typed[K]) Equal ¶ added in v0.17.0
Equal forwards the call to underlying field element implementation
func (*Typed[K]) Exp ¶ added in v0.17.0
Exp forwards the call to underlying field element implementation
func (*Typed[K]) Halve ¶ added in v0.17.0
func (z *Typed[K]) Halve()
Halve forwards the call to underlying field element implementation
func (*Typed[K]) IsOne ¶ added in v0.17.0
IsOne forwards the call to underlying field element implementation
func (*Typed[K]) IsZero ¶ added in v0.17.0
IsZero forwards the call to underlying field element implementation
func (*Typed[K]) Marshal ¶ added in v0.17.0
Marshal forwards the call to underlying field element implementation
func (*Typed[K]) MarshalCBOR ¶ added in v0.17.0
Fast, felt-specialized CBOR marshaling.
func (Typed[K]) MarshalText ¶ added in v0.17.0
MarshalText returns the felt as an unquoted 0x hex string with no unnecessary leading zeros. The quotes are placed at the encoding/json level. Uses a value receiver so encoding/json can call it on non-addressable values (struct fields in `any`).
func (*Typed[K]) MinimalBytes ¶ added in v0.17.1
MinimalBytes returns the big-endian value without leading zero bytes; zero is one zero byte.
func (*Typed[K]) Mul ¶ added in v0.17.0
Mul forwards the call to underlying field element implementation
func (*Typed[K]) Set ¶ added in v0.17.0
Set forwards the call to underlying field element implementation
func (*Typed[K]) SetBigInt ¶ added in v0.17.0
SetBigInt forwards the call to underlying field element implementation
func (*Typed[K]) SetBytes ¶ added in v0.17.0
SetBytes forwards the call to underlying field element implementation
func (*Typed[K]) SetBytesCanonical ¶ added in v0.17.0
SetBytesCanonical forwards the call to underlying field element implementation
func (*Typed[K]) SetMinimalBytes ¶ added in v0.17.1
SetMinimalBytes sets z from a big-endian value of 1 to 32 bytes below the modulus.
func (*Typed[K]) SetRandom ¶ added in v0.17.0
SetRandom forwards the call to underlying field element implementation
func (*Typed[K]) SetString ¶ added in v0.17.0
SetString forwards the call to underlying field element implementation
func (*Typed[K]) SetUint64 ¶ added in v0.17.0
SetUint64 forwards the call to underlying field element implementation
func (*Typed[K]) ShortString ¶ added in v0.17.0
ShortString prints the felt to a string in a shortened format
func (*Typed[K]) StoredBytes ¶ added in v0.17.1
StoredBytes returns the form this build stores a standalone felt value in: the full 32 bytes.
func (*Typed[K]) String ¶ added in v0.17.0
String forwards the call to underlying field element implementation
func (*Typed[K]) Sub ¶ added in v0.17.0
Sub forwards the call to underlying field element implementation
func (*Typed[K]) Text ¶ added in v0.17.0
Text forwards the call to underlying field element implementation
func (*Typed[K]) Uint64 ¶ added in v0.17.0
Uint64 forwards the call to underlying field element implementation
func (*Typed[K]) Unmarshal ¶ added in v0.17.0
Unmarshal forwards the call to underlying field element implementation
func (*Typed[K]) UnmarshalCBOR ¶ added in v0.17.0
UnmarshalCBOR decodes a compact or legacy felt that spans all of data, writing z only on success.
func (*Typed[K]) UnmarshalJSONFrom ¶ added in v0.17.0
UnmarshalJSONFrom sets z from a quoted 0x-prefixed hex JSON string; any other JSON value fails.
func (*Typed[K]) UnmarshalText ¶ added in v0.17.0
UnmarshalText sets z from an unquoted 0x-prefixed hex string, as map keys and text decoders pass it.
func (Typed[K]) ValidatorValue ¶ added in v0.17.1
ValidatorValue implements validator.Valuer, so every felt type is validated by its hex string.