Documentation ¶
Index ¶
- Constants
- Variables
- func DivMod(n, m, p *big.Int) *big.Int
- func FmtKecBytes(in *big.Int, rolen int) (buf []byte)
- func MaskBits(mask, wordSize int, slice []byte) (ret []byte)
- func MerkleHash(x, y *big.Int) (*big.Int, error)
- func ProofMerklePath(root *big.Int, leaf *big.Int, path []*big.Int) bool
- type Account
- func (account *Account) Call(ctx context.Context, call types.FunctionCall) ([]string, error)
- func (account *Account) EstimateFee(ctx context.Context, calls []types.FunctionCall, details types.ExecuteDetails) (*types.FeeEstimate, error)
- func (account *Account) Execute(ctx context.Context, calls []types.FunctionCall, details types.ExecuteDetails) (*types.AddInvokeTransactionOutput, error)
- func (account *Account) Nonce(ctx context.Context) (*big.Int, error)
- func (account *Account) Sign(msgHash *big.Int) (*big.Int, *big.Int, error)
- func (account *Account) TransactionHash(calls []types.FunctionCall, details types.ExecuteDetails) (*big.Int, error)
- type AccountOption
- type AccountOptionFunc
- type AccountPlugin
- type CurveOption
- type Definition
- type Domain
- type FixedSizeMerkleTree
- type ProviderType
- type StarkCurve
- func (sc StarkCurve) Add(x1, y1, x2, y2 *big.Int) (x, y *big.Int)
- func (sc StarkCurve) ComputeHashOnElements(elems []*big.Int) (hash *big.Int, err error)
- func (sc StarkCurve) Double(x1, y1 *big.Int) (x, y *big.Int)
- func (sc StarkCurve) EcMult(m, x1, y1 *big.Int) (x, y *big.Int)
- func (sc StarkCurve) GenerateSecret(msgHash, privKey, seed *big.Int) (secret *big.Int)
- func (sc StarkCurve) GetRandomPrivateKey() (priv *big.Int, err error)
- func (sc StarkCurve) GetYCoordinate(starkX *big.Int) *big.Int
- func (sc StarkCurve) HashElements(elems []*big.Int) (hash *big.Int, err error)
- func (sc StarkCurve) InvModCurveSize(x *big.Int) *big.Int
- func (sc StarkCurve) IsOnCurve(x, y *big.Int) bool
- func (sc StarkCurve) MimicEcMultAir(mout, x1, y1, x2, y2 *big.Int) (x *big.Int, y *big.Int, err error)
- func (sc StarkCurve) PedersenHash(elems []*big.Int) (hash *big.Int, err error)
- func (sc StarkCurve) PrivateToPoint(privKey *big.Int) (x, y *big.Int, err error)
- func (sc StarkCurve) ScalarBaseMult(k []byte) (x, y *big.Int)
- func (sc StarkCurve) ScalarMult(x1, y1 *big.Int, k []byte) (x, y *big.Int)
- func (sc StarkCurve) Sign(msgHash, privKey *big.Int, seed ...*big.Int) (x, y *big.Int, err error)
- func (sc StarkCurve) Verify(msgHash, r, s, pubX, pubY *big.Int) bool
- type StarkCurvePayload
- type TypeDef
- type TypedData
- func (td TypedData) EncodeType(inType string) (enc string, err error)
- func (td TypedData) GetMessageHash(account *big.Int, msg TypedMessage, sc StarkCurve) (hash *big.Int, err error)
- func (td TypedData) GetTypeHash(inType string) (ret *big.Int, err error)
- func (td TypedData) GetTypedMessageHash(inType string, msg TypedMessage, sc StarkCurve) (hash *big.Int, err error)
- type TypedMessage
Constants ¶
const ( TRANSACTION_PREFIX = "invoke" EXECUTE_SELECTOR = "__execute__" CONTRACT_ADDRESS_PREFIX = "STARKNET_CONTRACT_ADDRESS" )
Variables ¶
var ( ErrUnsupportedAccount = errors.New("unsupported account implementation") MAX_FEE, _ = big.NewInt(0).SetString("0x20000000000", 0) )
var PedersenParamsRaw []byte
Functions ¶
func FmtKecBytes ¶ added in v0.2.0
format the bytes in Keccak hash
Types ¶
type Account ¶ added in v0.3.0
type Account struct { AccountAddress string // contains filtered or unexported fields }
func NewGatewayAccount ¶ added in v0.4.0
func NewGatewayAccount(private, address string, provider *gateway.GatewayProvider, options ...AccountOptionFunc) (*Account, error)
func NewRPCAccount ¶ added in v0.4.0
func (*Account) EstimateFee ¶ added in v0.3.0
func (account *Account) EstimateFee(ctx context.Context, calls []types.FunctionCall, details types.ExecuteDetails) (*types.FeeEstimate, error)
func (*Account) Execute ¶ added in v0.3.0
func (account *Account) Execute(ctx context.Context, calls []types.FunctionCall, details types.ExecuteDetails) (*types.AddInvokeTransactionOutput, error)
func (*Account) TransactionHash ¶ added in v0.4.0
func (account *Account) TransactionHash(calls []types.FunctionCall, details types.ExecuteDetails) (*big.Int, error)
type AccountOption ¶ added in v0.4.0
type AccountOption struct { AccountPlugin AccountPlugin // contains filtered or unexported fields }
func AccountVersion0 ¶ added in v0.4.0
func AccountVersion0(string, string) (AccountOption, error)
func AccountVersion1 ¶ added in v0.4.0
func AccountVersion1(string, string) (AccountOption, error)
type AccountOptionFunc ¶ added in v0.4.0
type AccountOptionFunc func(string, string) (AccountOption, error)
type AccountPlugin ¶ added in v0.4.0
type AccountPlugin interface {
PluginCall(calls []types.FunctionCall) (types.FunctionCall, error)
}
type CurveOption ¶ added in v0.3.0
type CurveOption interface {
// contains filtered or unexported methods
}
func WithConstants ¶ added in v0.3.0
func WithConstants(paramsPath ...string) CurveOption
functions that require pedersen hashes must be run on a curve initialized with constant points
type Definition ¶ added in v0.2.0
type FixedSizeMerkleTree ¶ added in v0.4.0
func NewFixedSizeMerkleTree ¶ added in v0.4.0
func NewFixedSizeMerkleTree(leaves ...*big.Int) (*FixedSizeMerkleTree, error)
type ProviderType ¶ added in v0.4.0
type ProviderType string
const ( ProviderRPCv01 ProviderType = "rpcv01" ProviderGateway ProviderType = "gateway" )
type StarkCurve ¶
type StarkCurve struct { *elliptic.CurveParams EcGenX *big.Int EcGenY *big.Int MinusShiftPointX *big.Int MinusShiftPointY *big.Int Max *big.Int Alpha *big.Int ConstantPoints [][]*big.Int }
Returned stark curve includes several values above and beyond what the 'elliptic' interface calls for to facilitate common starkware functions
var Curve StarkCurve
func (StarkCurve) Add ¶
func (sc StarkCurve) Add(x1, y1, x2, y2 *big.Int) (x, y *big.Int)
Gets two points on an elliptic curve mod p and returns their sum. Assumes affine form (x, y) is spread (x1 *big.Int, y1 *big.Int)
func (StarkCurve) ComputeHashOnElements ¶ added in v0.4.0
Hashes the contents of a given array with its size using a golang Pedersen Hash implementation.
func (StarkCurve) Double ¶
func (sc StarkCurve) Double(x1, y1 *big.Int) (x, y *big.Int)
Doubles a point on an elliptic curve with the equation y^2 = x^3 + alpha*x + beta mod p. Assumes affine form (x, y) is spread (x1 *big.Int, y1 *big.Int)
func (StarkCurve) EcMult ¶
func (sc StarkCurve) EcMult(m, x1, y1 *big.Int) (x, y *big.Int)
Multiplies by m a point on the elliptic curve with equation y^2 = x^3 + alpha*x + beta mod p. Assumes affine form (x, y) is spread (x1 *big.Int, y1 *big.Int) and that 0 < m < order(point).
func (StarkCurve) GenerateSecret ¶
func (sc StarkCurve) GenerateSecret(msgHash, privKey, seed *big.Int) (secret *big.Int)
implementation based on https://github.com/codahale/rfc6979/blob/master/rfc6979.go for the specification, see https://tools.ietf.org/html/rfc6979#section-3.2
func (StarkCurve) GetRandomPrivateKey ¶
func (sc StarkCurve) GetRandomPrivateKey() (priv *big.Int, err error)
obtain random primary key on stark curve NOTE: to be used for testing purposes
func (StarkCurve) GetYCoordinate ¶
func (sc StarkCurve) GetYCoordinate(starkX *big.Int) *big.Int
Given the x coordinate of a stark_key, returns a possible y coordinate such that together the point (x,y) is on the curve. Note: the real y coordinate is either y or -y.
func (StarkCurve) HashElements ¶
Hashes the contents of a given array using a golang Pedersen Hash implementation.
(ref: https://github.com/seanjameshan/starknet.js/blob/main/src/utils/ellipticCurve.ts)
func (StarkCurve) InvModCurveSize ¶
func (sc StarkCurve) InvModCurveSize(x *big.Int) *big.Int
func (StarkCurve) MimicEcMultAir ¶
func (sc StarkCurve) MimicEcMultAir(mout, x1, y1, x2, y2 *big.Int) (x *big.Int, y *big.Int, err error)
Computes m * point + shift_point using the same steps like the AIR and throws an exception if and only if the AIR errors.
func (StarkCurve) PedersenHash ¶
Provides the pedersen hash of given array of big integers. NOTE: This function assumes the curve has been initialized with contant points
(ref: https://github.com/seanjameshan/starknet.js/blob/main/src/utils/ellipticCurve.ts)
func (StarkCurve) PrivateToPoint ¶
obtain public key coordinates from stark curve given the private key
func (StarkCurve) ScalarBaseMult ¶
func (sc StarkCurve) ScalarBaseMult(k []byte) (x, y *big.Int)
func (StarkCurve) ScalarMult ¶
func (StarkCurve) Sign ¶
Signs the hash value of contents with the provided private key. Secret is generated using a golang implementation of RFC 6979. Implementation does not yet include "extra entropy" or "retry gen".
type StarkCurvePayload ¶
type StarkCurvePayload struct { License []string `json:"_license"` Comment string `json:"_comment"` FieldPrime *big.Int `json:"FIELD_PRIME"` FieldGen int `json:"FIELD_GEN"` EcOrder *big.Int `json:"EC_ORDER"` Alpha int64 `json:"ALPHA"` Beta *big.Int `json:"BETA"` ConstantPoints [][]*big.Int `json:"CONSTANT_POINTS"` }
struct definition for parsing 'pedersen_params.json'
var PedersenParams StarkCurvePayload
type TypeDef ¶ added in v0.2.0
type TypeDef struct { Encoding *big.Int Definitions []Definition }
type TypedData ¶ added in v0.2.0
type TypedData struct { Types map[string]TypeDef PrimaryType string Domain Domain Message TypedMessage }
func NewTypedData ¶ added in v0.2.0
'typedData' interface for interacting and signing typed data in accordance with https://github.com/0xs34n/starknet.js/tree/develop/src/utils/typedData
func (TypedData) EncodeType ¶ added in v0.2.0
func (TypedData) GetMessageHash ¶ added in v0.2.0
func (td TypedData) GetMessageHash(account *big.Int, msg TypedMessage, sc StarkCurve) (hash *big.Int, err error)
func (TypedData) GetTypeHash ¶ added in v0.2.0
func (TypedData) GetTypedMessageHash ¶ added in v0.2.0
func (td TypedData) GetTypedMessageHash(inType string, msg TypedMessage, sc StarkCurve) (hash *big.Int, err error)