typedData

package
v0.0.0-...-0922dbf Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RevisionV0 revision
View Source
var RevisionV1 revision

Functions

func EncodeData

func EncodeData(typeDef *TypeDefinition, td *TypedData, context ...string) (enc []*felt.Felt, err error)

EncodeData encodes the given type definition using the TypedData struct.

func GetRevision

func GetRevision(version uint8) (rev *revision, err error)

Types

type Domain

type Domain struct {
	Name     string `json:"name"`
	Version  string `json:"version"`
	ChainId  string `json:"chainId"`
	Revision uint8  `json:"revision,omitempty"`
}

func (*Domain) UnmarshalJSON

func (domain *Domain) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for Domain

type RevisionTypes

type RevisionTypes struct {
	Basic  []string
	Preset map[string]TypeDefinition
}

type TypeDefinition

type TypeDefinition struct {
	Name               string     `json:"-"`
	Enconding          *felt.Felt `json:"-"`
	EncoddingString    string     `json:"-"`
	SingleEncString    string     `json:"-"`
	ReferencedTypesEnc []string   `json:"-"`
	Parameters         []TypeParameter
}

type TypeParameter

type TypeParameter struct {
	Name     string `json:"name"`
	Type     string `json:"type"`
	Contains string `json:"contains,omitempty"`
}

type TypedData

type TypedData struct {
	// contains filtered or unexported fields
}

func NewTypedData

func NewTypedData(types []TypeDefinition, primaryType string, domain Domain, message []byte) (td *TypedData, err error)

NewTypedData creates a new instance of TypedData.

Parameters: - types: a slice of TypeDefinition representing the types used in the TypedData. - primaryType: a string representing the primary type of the TypedData. - domain: a Domain struct representing the domain information of the TypedData. - message: a byte slice containing the JSON-encoded message.

Returns: - td: a pointer to the newly created TypedData instance. - err: an error if any occurred during the creation of the TypedData.

func (*TypedData) Domain

func (td *TypedData) Domain() Domain

Domain returns the domain information of the TypedData

func (*TypedData) GetMessageHash

func (td *TypedData) GetMessageHash(account string) (hash *felt.Felt, err error)

GetMessageHash calculates the hash of a typed message for a given account using the StarkCurve.

(ref: https://github.com/starknet-io/SNIPs/blob/5d5a42c654c27b377d8b7f90b453065fd19ec2eb/SNIPS/snip-12.md#specification)

Parameters: - account: A string representing the account. Returns: - hash: A pointer to a felt.Felt representing the calculated hash.

func (*TypedData) GetStructHash

func (td *TypedData) GetStructHash(typeName string, context ...string) (hash *felt.Felt, err error)

GetStructHash calculates the hash of a struct type and its respective data.

Parameters: - typeName: the name of the type to be hashed. - context: optional context strings to be included in the hash calculation.

You can use 'context' to specify the path of the type you want to hash. Example: if you want to hash the type "ExampleInner" that is within the "Example" primary type with the name of "example_inner", you can specify the context as ["example_inner"]. If "ExampleInner" has a parameter with the name of "example_inner_inner" that you want to know the hash, you can specify the context as ["example_inner", "example_inner_inner"].

Returns: - hash: A pointer to a felt.Felt representing the calculated hash. - err: an error if any occurred during the hash calculation.

func (*TypedData) GetTypeHash

func (td *TypedData) GetTypeHash(typeName string) (*felt.Felt, error)

GetTypeHash returns the hash of the given type.

Parameters: - typeName: the name of the type to hash Returns: - hash: A pointer to a felt.Felt representing the calculated hash. - err: an error if any occurred during the hash calculation.

func (*TypedData) Message

func (td *TypedData) Message() map[string]any

Message returns a copy of the TypedData's message map

func (*TypedData) PrimaryType

func (td *TypedData) PrimaryType() string

PrimaryType returns the primary type name of the TypedData

func (*TypedData) Revision

func (td *TypedData) Revision() revision

Revision returns the revision value of the TypedData

func (*TypedData) Types

func (td *TypedData) Types() map[string]TypeDefinition

Types returns a copy of the TypedData's type definitions map

func (*TypedData) UnmarshalJSON

func (td *TypedData) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for TypedData

Jump to

Keyboard shortcuts

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