context

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyEventName      = errors.New("empty event name")
	ErrNilEventPayload     = errors.New("nil event payload")
	ErrInvalidEventPayload = errors.New("invalid event payload")
)
View Source
var (
	// ErrNotMessage is returned when the provided data is not a message.
	ErrNotMessage = errors.New("not a message")

	// ErrInvalidMessage is returned when the provided message is invalid.
	ErrInvalidMessage = errors.New("invalid message")

	// ErrInvalidMessageSender is returned when the message sender is invalid.
	ErrInvalidMessageSender = errors.New("invalid message sender")

	// ErrAlgorithmNotSupported is returned when an unsupported algorithm is used for message signing.
	ErrAlgorithmNotSupported = errors.New("algorithm not supported yet")

	// ErrInvalidSignature is returned when the message signature is invalid.
	ErrInvalidSignature = errors.New("invalid signature")
)

Functions

func BeforeTransaction

func BeforeTransaction(ctx ContextInterface) error

func GenerateHash

func GenerateHash(payload []byte) []byte

GenerateHash returns the SHA-512 hash of the given payload. The returned hash is a byte slice.

func VerifySignature

func VerifySignature(pub crypto.PublicKey, message, sig []byte) bool

VerifySignature verifies that message was signed by the private key corresponding to the provided public key

Types

type Context

type Context struct {
	contractapi.TransactionContext
	// contains filtered or unexported fields
}

func (*Context) EmitEvent

func (ctx *Context) EmitEvent(event string, payload interface{}) error

func (*Context) MsgSender

func (ctx *Context) MsgSender() library.Address

func (*Context) Operator

func (ctx *Context) Operator() library.Address

func (*Context) SetMsgSender

func (ctx *Context) SetMsgSender(msgSender library.Address)

type ContextInterface

type ContextInterface interface {
	contractapi.TransactionContextInterface

	Operator() library.Address

	SetMsgSender(library.Address)
	MsgSender() library.Address

	EmitEvent(event string, payload interface{}) error
}

type Message

type Message struct {
	Nonce     uint64 `json:"nonce"`
	PublicKey string `json:"publicKey"`
	Signature string `json:"signature"`
}

func (*Message) Base64EncodedStr

func (msg *Message) Base64EncodedStr() (string, error)

Base64EncodedStr returns the base64-encoded string representation of the Message struct.

func (*Message) FromBase64EncodedStr

func (msg *Message) FromBase64EncodedStr(str string) error

FromBase64EncodedStr decodes a base64-encoded string and unmarshals it into a Message struct. It returns an error if the string could not be decoded or if the unmarshaling fails.

func (*Message) GeneratePayload

func (msg *Message) GeneratePayload(args ...string) []byte

GeneratePayload concatenates the message nonce with the provided arguments to create a byte slice payload. The length of the returned payload will be equal to the length of the nonce plus the combined length of all of the arguments.

func (*Message) GenerateSignature

func (msg *Message) GenerateSignature(privkey *ecdsa.PrivateKey, args ...string) error

GenerateSignature generates a cryptographic signature for the message using the provided private key and arguments. It sets the Signature and PublicKey fields of the Message struct.

func (*Message) Marshal

func (msg *Message) Marshal() ([]byte, error)

Marshal returns the JSON encoding of a Message struct. If the input Message pointer is nil, a new Message is created.

func (*Message) Unmarshal

func (msg *Message) Unmarshal(bytes []byte) error

Unmarshal unmarshals a byte slice into a Message struct

func (*Message) VerifyAgainstArgs

func (msg *Message) VerifyAgainstArgs(args ...string) (library.Address, error)

VerifyAgainstArgs verifies the message against the given arguments and returns the sender's address. If the message is invalid, it returns an error.

type SupportedAlgorithm

type SupportedAlgorithm string

SupportedAlgorithm represents a supported message signing algorithm.

const (
	// ECDSA is a supported message signing algorithm.
	ECDSA SupportedAlgorithm = "ECDSA"
)

Jump to

Keyboard shortcuts

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