typed

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Definition

type Definition struct {
	Name string
	Type string
}

type Domain

type Domain struct {
	Name    string
	Version string
	ChainId string
}

func (Domain) FmtDefinitionEncoding

func (dm Domain) FmtDefinitionEncoding(field string) (fmtEnc []*big.Int)

FmtDefinitionEncoding formats the definition (standard Starknet Domain) encoding.

Parameters: - field: the field to format the encoding for Returns: - fmtEnc: a slice of big integers

type TypeDef

type TypeDef struct {
	Encoding    *big.Int
	Definitions []Definition
}

type TypedData

type TypedData struct {
	Types       map[string]TypeDef
	PrimaryType string
	Domain      Domain
	Message     TypedMessage
}

func NewTypedData

func NewTypedData(types map[string]TypeDef, pType string, dom Domain) (td TypedData, err error)

NewTypedData initializes a new TypedData object with the given types, primary type, and domain for interacting and signing in accordance with https://github.com/0xs34n/starknet.js/tree/develop/src/utils/typedData If the primary type is invalid, it returns an error with the message "invalid primary type: {pType}". If there is an error encoding the type hash, it returns an error with the message "error encoding type hash: {enc.String()} {err}".

Parameters: - types: a map[string]TypeDef representing the types associated with their names. - pType: a string representing the primary type. - dom: a Domain representing the domain. Returns: - td: a TypedData object - err: an error if any

func (TypedData) EncodeType

func (td TypedData) EncodeType(inType string) (enc string, err error)

EncodeType encodes the given inType using the TypedData struct.

Parameters: - inType: the type to encode Returns: - enc: the encoded type - err: any error if any

func (TypedData) GetMessageHash

func (td TypedData) GetMessageHash(account *big.Int, msg TypedMessage, sc curve.StarkCurve) (hash *big.Int, err error)

GetMessageHash calculates the hash of a typed message for a given account using the StarkCurve. (ref: https://github.com/0xs34n/starknet.js/blob/767021a203ac0b9cdb282eb6d63b33bfd7614858/src/utils/typedData/index.ts#L166)

Parameters: - account: A pointer to a big.Int representing the account. - msg: A TypedMessage object representing the message. - sc: A StarkCurve object representing the curve. Returns: - hash: A pointer to a big.Int representing the calculated hash. - err: An error object indicating any error that occurred during the calculation.

func (TypedData) GetTypeHash

func (td TypedData) GetTypeHash(inType string) (ret *big.Int, err error)

GetTypeHash returns the hash of the given type.

Parameters: - inType: the type to hash Returns: - ret: the hash of the given type - err: any error if any

func (TypedData) GetTypedMessageHash

func (td TypedData) GetTypedMessageHash(inType string, msg TypedMessage, sc curve.StarkCurve) (hash *big.Int, err error)

GetTypedMessageHash calculates the hash of a typed message using the provided StarkCurve.

Parameters:

  • inType: the type of the message
  • msg: the typed message
  • sc: the StarkCurve used for hashing

Returns:

  • hash: the calculated hash
  • err: any error if any

type TypedMessage

type TypedMessage interface {
	FmtDefinitionEncoding(string) []*big.Int
}

Jump to

Keyboard shortcuts

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