Documentation ¶
Overview ¶
Package utils provides utility functions for working with cryptographic messages
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotMessage is returned when trying to unmarshal invalid message bytes ErrNotMessage = errors.New("not a message") // ErrInvalidMessage is returned when trying to verify an invalid message ErrInvalidMessage = errors.New("invalid message") // ErrInvalidMessageSender is returned when trying to verify a message with an invalid sender ErrInvalidMessageSender = errors.New("invalid message sender") // ErrAlgorithmNotSupported is returned when trying to use an unsupported cryptographic algorithm ErrAlgorithmNotSupported = errors.New("algorithm not supported yet") // ErrInvalidSignature is returned when trying to verify a message with an invalid signature ErrInvalidSignature = errors.New("invalid signature") )
Functions ¶
func FromPublicKey ¶
FromPublicKey generates an Ethereum address from the given public key. It serializes the public key, hashes it using Keccak-256, truncates the hash, and adds a prefix to get the final Ethereum address.
func GenerateHash ¶
GenerateHash generates a SHA512 hash for the given payload.
func ParseTxError ¶
Types ¶
type GoPDFTemplate ¶
type GoPDFTemplate struct { // Path to image template Image string `json:"image,omitempty"` // Locations to write text Locations []Location `json:"locations,omitempty"` }
GoPDFTemplate is a template for gopdf to render a pdf from a image
func (*GoPDFTemplate) Load ¶
func (gop *GoPDFTemplate) Load(bytes []byte) error
Load loads a GoPDFTemplate from bytes
func (*GoPDFTemplate) LoadFromFile ¶
func (gop *GoPDFTemplate) LoadFromFile(path string) error
LoadFromFile loads a GoPDFTemplate from a file
func (*GoPDFTemplate) Render ¶
func (gop *GoPDFTemplate) Render(option RenderOpts) ([]byte, error)
Render renders a pdf from a GoPDFTemplate
type Location ¶
type Location struct { // Text to be written Text string `json:"text"` // Inputs to be parsed into text with fmt.Sprintf() Inputs []string `json:"inputs"` // Position of text X float64 `json:"x"` Y float64 `json:"y"` // Font style and size Style string `json:"style"` Size int `json:"size"` }
Location is a location to write text
type Message ¶
type Message struct { Nonce uint64 `json:"nonce"` PublicKey []byte `json:"publicKey"` Signature []byte `json:"signature"` }
Message represents a cryptographic message
func (*Message) GeneratePayload ¶
GeneratePayload generates a payload for the message with the given arguments. The payload includes the message nonce and all the arguments appended together.
func (*Message) Marshal ¶
Marshal returns the JSON encoding of the message. If the message is nil, a new message is created.
func (*Message) Unmarshal ¶
Unmarshal unmarshals the given bytes into a Message struct. It returns an error if the unmarshalling fails.
func (*Message) UnmarshalBase64Str ¶
UnmarshalBase64Str unmarshals the given base64-encoded string into a Message struct. It returns an error if the unmarshalling fails.