Documentation ¶
Index ¶
- Constants
- func EncodeSignature(sig, pubKey []byte) ([]byte, error)
- func ExtractPubKey(ownerProof []byte) ([]byte, error)
- func OwnerProofer(signer Signer, pubKey []byte) func([]byte) ([]byte, error)
- func OwnerProoferForSigner(signer Signer) func([]byte) ([]byte, error)
- func OwnerProoferSecp256K1(privKey, pubKey []byte) func([]byte) ([]byte, error)
- func PredicateRunner(...) ...
- type P2pkh256Signature
- type Predicate
- type PredicateEngine
- type PredicateEngines
- type Signer
- type TxContext
Constants ¶
const MaxPredicateBinSize = 65536
Variables ¶
This section is empty.
Functions ¶
func EncodeSignature ¶
func ExtractPubKey ¶
func OwnerProofer ¶
OwnerProofer returns function which can be used as OwnerProof generator. "pubKey" must be the public key of the "signer". The generator function takes "bytes to sign" as a parameter and returns serialized owner proof (CBOR encoded Signature struct).
func OwnerProoferForSigner ¶
OwnerProoferForSigner returns OwnerProof generator for the signer. Prefer OwnerProofer(signer, pubKey) variation when pubKey of the signer is also already available.
func OwnerProoferSecp256K1 ¶
OwnerProoferSecp256K1 is like OwnerProofer but takes private / public key pair as a parameter. Keys are assumed to be ECDSA keys for the secp256k1 curve.
func PredicateRunner ¶
func PredicateRunner( executor func(ctx context.Context, predicate types.PredicateBytes, args []byte, txo *types.TransactionOrder, env TxContext) (bool, error), state *state.State, ) func(predicate types.PredicateBytes, args []byte, txo *types.TransactionOrder) error
PredicateRunner is a helper to refactor predicate support - provide implementation which is common for most tx systems (as of now only tokens tx system requires different PayloadBytes implementation, see AB-1012 for details) and "translates" between two interfaces:
- currently tx handlers do not have context.Context to pass to the predicate engine so wrapper returned doesn't require it and passes context.Background() to the predicate engine;
- provide TxContext implementation for the predicate engine (currently the only functionality needed is to extract payload bytes from tx order);
- currently tx systems do not differentiate between predicate evaluating to "false" vs returning error (ie invalid predicate or arguments) so wrapper returns error in case the predicate evaluates to "false".
Each instance of the wrapper is tx system / shard specific (tied to the state passed in as argument) and thus can't be shared between "modules" which do not share the state!
Types ¶
type P2pkh256Signature ¶
type P2pkh256Signature struct { Sig []byte PubKey []byte // contains filtered or unexported fields }
P2pkh256Signature is a signature and public key pair, typically used as owner proof (ie the public key can be used to verify the signature).
type Predicate ¶
type Predicate struct { Tag uint64 Code []byte Params []byte // contains filtered or unexported fields }
func ExtractPredicate ¶
type PredicateEngine ¶ added in v0.4.0
type PredicateEngine interface { // unique ID of the engine, this is used to dispatch predicates (predicate.Tag == engine.ID) // to the engine which is supposed to evaluate it. ID() uint64 // executes given predicate Execute(ctx context.Context, predicate *Predicate, args []byte, txo *types.TransactionOrder, env TxContext) (bool, error) }
type PredicateEngines ¶ added in v0.4.0
type PredicateEngines map[uint64]func(ctx context.Context, predicate *Predicate, args []byte, txo *types.TransactionOrder, env TxContext) (bool, error)
func Dispatcher ¶ added in v0.4.0
func Dispatcher(engines ...PredicateEngine) (PredicateEngines, error)
Dispatcher creates collection of predicate engines
func (PredicateEngines) Add ¶ added in v0.4.0
func (pe PredicateEngines) Add(engine PredicateEngine) error
func (PredicateEngines) Execute ¶ added in v0.4.0
func (pe PredicateEngines) Execute(ctx context.Context, predicate types.PredicateBytes, args []byte, txo *types.TransactionOrder, env TxContext) (bool, error)
Execute decodes predicate from binary representation and dispatches it to appropriate predicate executor.
type TxContext ¶ added in v0.4.0
type TxContext interface { GetUnit(id types.UnitID, committed bool) (*state.Unit, error) // until AB-1012 gets resolved we need this hack to get correct payload bytes. PayloadBytes(txo *types.TransactionOrder) ([]byte, error) }
environment where predicate runs (AKA transaction execution context) This is meant to provide the predicate engine with access to the tx system which processes the transaction.