sign

package module
v1.0.6-beta Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: LGPL-3.0 Imports: 11 Imported by: 13

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")
)

Functions

This section is empty.

Types

type Transaction

type Transaction struct {
	PersonaTag string          `json:"personaTag"`
	Namespace  string          `json:"namespace"`
	Nonce      uint64          `json:"nonce"`
	Signature  string          `json:"signature"` // hex encoded string
	Hash       common.Hash     `json:"hash,omitempty" swaggertype:"string"`
	Message    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, nonce uint64, data any) (*Transaction, error)

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

func NewTransaction

func NewTransaction(
	pk *ecdsa.PrivateKey,
	personaTag,
	namespace string,
	nonce uint64,
	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 signature.

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