Documentation
¶
Index ¶
- Variables
- func BeforeTransaction(ctx ContextInterface) error
- func GenerateHash(payload []byte) []byte
- func VerifySignature(pub crypto.PublicKey, message, sig []byte) bool
- type Context
- type ContextInterface
- type Message
- func (msg *Message) Base64EncodedStr() (string, error)
- func (msg *Message) FromBase64EncodedStr(str string) error
- func (msg *Message) GeneratePayload(args ...string) []byte
- func (msg *Message) GenerateSignature(privkey *ecdsa.PrivateKey, args ...string) error
- func (msg *Message) Marshal() ([]byte, error)
- func (msg *Message) Unmarshal(bytes []byte) error
- func (msg *Message) VerifyAgainstArgs(args ...string) (library.Address, error)
- type SupportedAlgorithm
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyEventName = errors.New("empty event name") ErrNilEventPayload = errors.New("nil event payload") ErrInvalidEventPayload = errors.New("invalid event payload") )
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 ¶
GenerateHash returns the SHA-512 hash of the given payload. The returned hash is a byte slice.
Types ¶
type Context ¶
type Context struct { contractapi.TransactionContext // contains filtered or unexported fields }
func (*Context) SetMsgSender ¶
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 ¶
Base64EncodedStr returns the base64-encoded string representation of the Message struct.
func (*Message) FromBase64EncodedStr ¶
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 ¶
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 ¶
Marshal returns the JSON encoding of a Message struct. If the input Message pointer is nil, a new Message is created.
type SupportedAlgorithm ¶
type SupportedAlgorithm string
SupportedAlgorithm represents a supported message signing algorithm.
const ( // ECDSA is a supported message signing algorithm. ECDSA SupportedAlgorithm = "ECDSA" )