Documentation
¶
Overview ¶
Package signed is an implementation of the transaction abstraction.
It uses a signature to make sure the identity owns the transaction. The nonce is a monotonically increasing number that is used to prevent a replay attack of an existing transaction.
Documentation Last Review: 08.10.2020
Index ¶
- func RegisterTransactionFormat(f serde.Format, e serde.FormatEngine)
- type Client
- type PublicKeyFac
- type SignatureFac
- type Transaction
- func (t *Transaction) Fingerprint(w io.Writer) error
- func (t *Transaction) GetArg(key string) []byte
- func (t *Transaction) GetArgs() []string
- func (t *Transaction) GetID() []byte
- func (t *Transaction) GetIdentity() access.Identity
- func (t *Transaction) GetNonce() uint64
- func (t *Transaction) GetSignature() crypto.Signature
- func (t *Transaction) Serialize(ctx serde.Context) ([]byte, error)
- func (t *Transaction) Sign(signer crypto.Signer) error
- type TransactionFactory
- type TransactionManager
- type TransactionOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterTransactionFormat ¶
func RegisterTransactionFormat(f serde.Format, e serde.FormatEngine)
RegisterTransactionFormat registers the engine for the provided format.
Types ¶
type Client ¶
Client is the interface the manager is using to get the nonce of an identity. It allows a local implementation, or through a network client.
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction is a signed transaction using a nonce to protect itself against replay attack.
- implements txn.Transaction
func NewTransaction ¶
func NewTransaction(nonce uint64, pk crypto.PublicKey, opts ...TransactionOption) ( *Transaction, error, )
NewTransaction creates a new transaction with the provided nonce.
func (*Transaction) Fingerprint ¶
func (t *Transaction) Fingerprint(w io.Writer) error
Fingerprint implements serde.Fingerprinter. It writes a deterministic binary representation of the transaction.
func (*Transaction) GetArg ¶
func (t *Transaction) GetArg(key string) []byte
GetArg implements txn.Transaction. It returns the value of the argument if it is set, otherwise nil.
func (*Transaction) GetArgs ¶
func (t *Transaction) GetArgs() []string
GetArgs returns the list of arguments available.
func (*Transaction) GetID ¶
func (t *Transaction) GetID() []byte
GetID implements txn.Transaction. It returns the ID of the transaction.
func (*Transaction) GetIdentity ¶
func (t *Transaction) GetIdentity() access.Identity
GetIdentity implements txn.Transaction. It returns nil.
func (*Transaction) GetNonce ¶
func (t *Transaction) GetNonce() uint64
GetNonce implements txn.Transaction. It returns the nonce of the transaction.
func (*Transaction) GetSignature ¶
func (t *Transaction) GetSignature() crypto.Signature
GetSignature returns the signature of the transaction.
type TransactionFactory ¶
type TransactionFactory struct {
// contains filtered or unexported fields
}
TransactionFactory is a factory to deserialize transactions.
- implements serde.Factory
func NewTransactionFactory ¶
func NewTransactionFactory() TransactionFactory
NewTransactionFactory returns a new factory.
func (TransactionFactory) Deserialize ¶
Deserialize implements serde.Factory. It populates the transaction from the data if appropriate, otherwise it returns an error.
func (TransactionFactory) TransactionOf ¶
func (f TransactionFactory) TransactionOf(ctx serde.Context, data []byte) (txn.Transaction, error)
TransactionOf implements txn.TransactionFactory. It populates the transaction from the data if appropriate, otherwise it returns an error.
type TransactionManager ¶
type TransactionManager struct {
// contains filtered or unexported fields
}
TransactionManager is a manager to create signed transactions. It manages the nonce by itself, except if the transaction is refused by the ledger. In that case the manager should be synchronized before creating a new one.
- implements txn.Manager
func NewManager ¶
func NewManager(signer crypto.Signer, client Client) *TransactionManager
NewManager creates a new transaction manager.
- implements txn.Manager
func (*TransactionManager) Make ¶
func (mgr *TransactionManager) Make(args ...txn.Arg) (txn.Transaction, error)
Make implements txn.Manager. It creates a transaction populated with the arguments.
Example ¶
package main import ( "fmt" "go.dedis.ch/dela/core/access" "go.dedis.ch/dela/crypto/bls" ) func main() { signer := bls.NewSigner() manager := NewManager(signer, exampleClient{nonce: 5}) tx, err := manager.Make() if err != nil { panic("failed to create first transaction: " + err.Error()) } fmt.Println(tx.GetNonce()) err = manager.Sync() if err != nil { panic("failed to synchronize: " + err.Error()) } tx, err = manager.Make() if err != nil { panic("failed to create second transaction: " + err.Error()) } fmt.Println(tx.GetNonce()) } // exampleClient is an example of a manager client. It always synchronize the // manager to the nonce value. // // - implements signed.Client type exampleClient struct { nonce uint64 } // GetNonce implements signed.Client. It always return the same nonce for // simplicity. func (cl exampleClient) GetNonce(identity access.Identity) (uint64, error) { return cl.nonce, nil }
Output: 0 5
func (*TransactionManager) Sync ¶
func (mgr *TransactionManager) Sync() error
Sync implements txn.Manager. It fetches the latest nonce of the signer to create valid transactions.
type TransactionOption ¶
type TransactionOption func(*template)
TransactionOption is the type of options to create a transaction.
func WithArg ¶
func WithArg(key string, value []byte) TransactionOption
WithArg is an option to set an argument with the key and the value.
func WithHashFactory ¶
func WithHashFactory(f crypto.HashFactory) TransactionOption
WithHashFactory is an option to set a different hash factory when creating a transaction.
func WithSignature ¶
func WithSignature(sig crypto.Signature) TransactionOption
WithSignature is an option to set a valid signature. The signature will be verified against the identity.
Directories
¶
Path | Synopsis |
---|---|
Package controller implements a CLI controller to inject a transaction manager.
|
Package controller implements a CLI controller to inject a transaction manager. |