transaction

package
v0.0.0-...-1b5cee2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const ExpirationTimeInDays = 7 // transaction validity expiration time in days. TODO: move to config

Variables

View Source
var (
	ErrTransactionHasAFutureTime        = errors.New("transaction has a future time")
	ErrExpiredTransaction               = errors.New("transaction has expired")
	ErrTransactionHashIsInvalid         = errors.New("transaction hash is invalid")
	ErrSignatureNotValidOrDataCorrupted = errors.New("signature not valid or data are corrupted")
	ErrSubjectIsEmpty                   = errors.New("subject cannot be empty")
	ErrAddressIsInvalid                 = errors.New("address is invalid")
)

Functions

This section is empty.

Types

type Signer

type Signer interface {
	Sign(message []byte) (digest [32]byte, signature []byte)
	Address() string
}

Signer provides signing and address methods.

type Transaction

type Transaction struct {
	ID                any       `json:"-"                  bson:"_id"                db:"id"`
	CreatedAt         time.Time `json:"created_at"         bson:"created_at"         db:"created_at"`
	Hash              [32]byte  `json:"hash"               bson:"hash"               db:"hash"`
	IssuerAddress     string    `json:"issuer_address"     bson:"issuer_address"     db:"issuer_address"`
	ReceiverAddress   string    `json:"receiver_address"   bson:"receiver_address"   db:"receiver_address"`
	Subject           string    `json:"subject"            bson:"subject"            db:"subject"`
	Data              []byte    `json:"data"               bson:"data"               db:"data"`
	IssuerSignature   []byte    `json:"issuer_signature"   bson:"issuer_signature"   db:"issuer_signature"`
	ReceiverSignature []byte    `json:"receiver_signature" bson:"receiver_signature" db:"receiver_signature"`
}

Transaction contains transaction information, subject type, subject data, signatures and public keys. Transaction is valid for a week from being issued. Subject represents an information how to read the Data and / or how to decode them. Data is not validated by the computantis server, Ladger ior block. What is stored in Data is not important for the whole Computantis system. It is only important that the data are signed by the issuer and the receiver and both parties agreed on them.

func New

func New(subject string, data []byte, receiverAddress string, issuer Signer) (Transaction, error)

New creates new transaction signed by the issuer.

func (*Transaction) GeMessage

func (t *Transaction) GeMessage() []byte

GeMessage returns message used for signature validation.

func (*Transaction) Sign

func (t *Transaction) Sign(receiver Signer, v Verifier) ([32]byte, error)

Sign verifies issuer signature and signs Transaction by the receiver.

type TransactionAwaitingReceiverSignature

type TransactionAwaitingReceiverSignature struct {
	ID              any         `json:"-"                bson:"_id,omitempty"    db:"id"`
	ReceiverAddress string      `json:"receiver_address" bson:"receiver_address" db:"receiver_address"`
	IssuerAddress   string      `json:"issuer_address"   bson:"issuer_address"   db:"issuer_address"`
	Transaction     Transaction `json:"transaction"      bson:"transaction"      db:"-"`
	TransactionHash [32]byte    `json:"transaction_hash" bson:"transaction_hash" db:"hash"`
}

TransactionAwaitingReceiverSignature represents transaction awaiting receiver signature. It is as well the entity of all issued transactions that has not been signed by receiver yet.

type TransactionInBlock

type TransactionInBlock struct {
	ID              any      `json:"-" bson:"_id,omitempty"    db:"id"`
	BlockHash       [32]byte `json:"-" bson:"block_hash"       db:"block_hash"`
	TransactionHash [32]byte `json:"-" bson:"transaction_hash" db:"transaction_hash"`
}

TransactionInBlock stores relation between Transaction and Block to which Transaction was added. It is stored for fast lookup only to allow to find Block hash in which Transaction was added.

type Verifier

type Verifier interface {
	Verify(message, signature []byte, hash [32]byte, issuer string) error
}

Verifier provides signature verification method.

Jump to

Keyboard shortcuts

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