sign

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: LGPL-3.0 Imports: 14 Imported by: 18

Documentation

Overview

Package sign allows for the cryptographic signing and verification an arbitrary payload.

Index

Constants

View Source
const SystemPersonaTag = "SystemPersonaTag"

SystemPersonaTag is a reserved persona tag for transaction. It is used in transactions when a PersonaTag does not actually exist (e.g. during the PersonaTag creation process).

Variables

View Source
var (
	// ErrSignatureValidationFailed is returned when a signature is not valid.
	ErrSignatureValidationFailed = errors.New("signature validation failed")
	ErrCannotSignEmptyBody       = errors.New("cannot sign empty body")
	ErrInvalidPersonaTag         = errors.New("invalid persona tag")
	ErrInvalidNamespace          = errors.New("invalid namespace")

	ErrNoPersonaTagField = errors.New("transaction must contain personaTag field")
	ErrNoNamespaceField  = errors.New("transaction must contain namespace field")
	ErrNoSignatureField  = errors.New("transaction must contain signature field")
	ErrNoBodyField       = errors.New("transaction must contain body field")
	ErrNoTimestampField  = errors.New("transaction must contain timestamp field")
)

Functions

func IsZeroHash

func IsZeroHash(hash common.Hash) bool

func Timestamp added in v1.1.1

func Timestamp(t int64) time.Time

returns a GoLang time from a sign compatible timestamp

func TimestampAt

func TimestampAt(t time.Time) int64

returns a sign compatible timestamp for the time passed in

func TimestampNow

func TimestampNow() int64

returns a sign compatible timestamp for the current wall time

Types

type Transaction

type Transaction struct {
	PersonaTag string          `json:"personaTag"`
	Namespace  string          `json:"namespace"`
	Timestamp  int64           `json:"timestamp"`                 // unix millisecond timestamp
	Salt       uint16          `json:"salt,omitempty"`            // an optional field for additional hash uniqueness
	Signature  string          `json:"signature"`                 // hex encoded string
	Hash       common.Hash     `json:"-"`                         // don't marshal or unmarshal for json
	Body       json.RawMessage `json:"body" swaggertype:"object"` // json string
}

func MappedTransaction

func MappedTransaction(tx map[string]interface{}) (*Transaction, error)

MappedTransaction Identical to UnmarshalTransaction but takes a transaction in the form of map[string]any.

func NewSystemTransaction

func NewSystemTransaction(pk *ecdsa.PrivateKey, namespace string, data any) (*Transaction, error)

NewSystemTransaction signs a given body with the given private key using the SystemPersonaTag.

func NewTransaction

func NewTransaction(
	pk *ecdsa.PrivateKey,
	personaTag,
	namespace string,
	data any,
) (*Transaction, error)

NewTransaction signs a given body, tag, and nonce with the given private key.

func UnmarshalTransaction

func UnmarshalTransaction(bz []byte) (*Transaction, error)

func (*Transaction) HashHex

func (s *Transaction) HashHex() string

HashHex return a hex encoded hash of the message and its data. if the hash was not previously set, it will be generated

func (*Transaction) IsSystemTransaction

func (s *Transaction) IsSystemTransaction() bool

func (*Transaction) Marshal

func (s *Transaction) Marshal() ([]byte, error)

Marshal serializes this Transaction to bytes, which can then be passed in to Unmarshal.

func (*Transaction) Verify

func (s *Transaction) Verify(hexAddress string) error

Verify verifies this Transaction has a valid signature. If nil is returned, the signature is valid. Signature verification follows the pattern in crypto.TestSign: https://github.com/ethereum/go-ethereum/blob/master/crypto/crypto_test.go#L94 TODO: Review this signature verification, and compare it to geth's sig verification

Jump to

Keyboard shortcuts

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