Documentation ¶
Index ¶
- Constants
- Variables
- type GovernanceRulesValidator
- type GovernedProcessValidator
- type Identity
- type MultiValidator
- type PKI
- type PKIValidator
- type Participant
- type ParticipantUpdate
- type ParticipantsValidator
- type ProcessStepValidator
- type ProcessesValidators
- type RefsValidator
- type SchemaValidator
- type ScriptConfig
- type ScriptValidator
- type ScriptValidatorFunc
- type TransitionValidator
- type Validator
- func NewGovernanceRulesValidator() Validator
- func NewGovernedProcessValidator() Validator
- func NewMultiValidator(validators Validators) Validator
- func NewPKIValidator(processStepValidator *ProcessStepValidator, required []string, pki PKI) Validator
- func NewParticipantsValidator() Validator
- func NewRefsValidator() Validator
- func NewSchemaValidator(processStepValidator *ProcessStepValidator, schemaData []byte) (Validator, error)
- func NewScriptValidator(process string, pluginsPath string, scriptCfg *ScriptConfig) (Validator, error)
- func NewTransitionValidator(processStepValidator *ProcessStepValidator, from []string) Validator
- type Validators
Constants ¶
const ( ParticipantUpsert = "upsert" ParticipantRemove = "remove" )
Available update types.
const ( // ParticipantsValidatorName name for monitoring. ParticipantsValidatorName = "participants-validator" // ParticipantsMap is the ID of the map containing participants in the // governance process. ParticipantsMap = "_participants" )
const ( ParticipantsAcceptStep = "accept" ParticipantsUpdateStep = "update" ParticipantsVoteStep = "vote" )
Allowed steps in the participants map.
const ( // GovernanceProcess is the name of the process containing validation rules // in a decentralized network. // Special rules apply to segments inside this process. GovernanceProcess = "_governance" )
const (
// MultiValidatorName for monitoring.
MultiValidatorName = "multivalidator"
)
const (
// PKIValidatorName for monitoring.
PKIValidatorName = "pki-validator"
)
const (
// RefsValidatorName for monitoring.
RefsValidatorName = "refs-validator"
)
const (
// SchemaValidatorName for monitoring.
SchemaValidatorName = "schema-validator"
)
const (
// ScriptValidatorName for monitoring.
ScriptValidatorName = "script-validator"
)
const (
// StepValidatorName for monitoring.
StepValidatorName = "step-validator"
)
const (
// TransitionValidatorName for monitoring.
TransitionValidatorName = "transition-validator"
)
Variables ¶
var ( ErrInvalidVotingPower = errors.New("participant voting power is missing") ErrMissingParticipantName = errors.New("participant name is missing") ErrMissingParticipantKey = errors.New("participant public key is missing") ErrUnknownUpdateType = errors.New("unknown participant update type") ErrParticipantNotFound = errors.New("participant not found") )
Participant errors.
var ( ErrInvalidParticipantStep = errors.New("invalid step in network participants update") ErrInvalidParticipantData = errors.New("invalid participant data") ErrParticipantsAlreadyInitialized = errors.New("participants map already initialized") ErrParticipantsNotInitialized = errors.New("participants map not initialized") ErrInvalidAcceptParticipant = errors.New("invalid accept participant link") ErrInvalidUpdateParticipant = errors.New("invalid update participant link") ErrInvalidVoteParticipant = errors.New("invalid vote participant link") )
Errors used by the participants validator.
var ( ErrInvalidIdentity = errors.New("could not parse identity keys") ErrMissingKeys = errors.New("missing identity public keys") ErrMissingSignature = errors.New("missing mandatory signature") )
Errors used by the PKI validator.
var ( ErrMapIDMismatch = errors.New("mapID doesn't match previous link") ErrParentNotFound = errors.New("parent is missing from store") ErrProcessMismatch = errors.New("process doesn't match referenced link") ErrRefNotFound = errors.New("reference is missing from store") )
Errors returned by the RefsValidator.
var ( ErrLoadingPlugin = errors.New("could not load validation script") ErrInvalidPlugin = errors.New("script does not expose a 'Validate' ScriptValidatorFunc") ErrInvalidPluginHash = errors.New("script digest doesn't match received file") )
Errors returned by the script validator.
var ( ErrMissingProcess = errors.New("validator requires a process") ErrMissingLinkStep = errors.New("validator requires a link step") ErrInvalidProcessOrStep = errors.New("link process or step doesn't match expectations") )
Errors used by the ProcessStepValidator.
var (
ErrInvalidLinkSchema = errors.New("invalid link schema")
)
Errors used by the schema validator.
var (
ErrInvalidTransition = errors.New("unauthorized process step transition")
)
Errors used by the transition validator.
var (
ErrNoMatchingValidator = errors.New("link does not match any validator")
)
Errors used by the multi-validator.
Functions ¶
This section is empty.
Types ¶
type GovernanceRulesValidator ¶
type GovernanceRulesValidator struct{}
GovernanceRulesValidator validates the evolution of custom rules in a p2p decentralized network. The governance process will contain one map per business process. This map will be responsible for updating the custom validation rules that apply to the process' segments. A governance process map should have the following structure:
,------------, ,--------------, ,----------------, | accept | <====================================== | accept | <========================================= | accept | | (rules v1) | <-. | (rules v2) | <-. | (rules v3) | `------------' | ,----------, ,---------, `--------------' | `----------------'
|`-- | update | | vote | | | ,---------, | | | | rules v2 | <=== | (alice) | <---------' | ,-------------, | vote | | | | `----------' `---------' | | | <=== | (alice) | <----------' | | ,----------, | | update | `---------' | `-- | update | `--| rules v3 | ,---------, | | rules v3 | ---- X | | <=== | vote | | `----------' `-------------' | (bob) | <-------------' `---------'
where: <=== represents a parent relationship <--- represents a reference
Each accept link should also reference the latest link in the participants map and check votes against these network participants.
func (*GovernanceRulesValidator) Hash ¶
func (v *GovernanceRulesValidator) Hash() ([]byte, error)
Hash returns an empty hash since the validator doesn't have any configuration (it works the same for every decentralized network).
func (*GovernanceRulesValidator) ShouldValidate ¶
func (v *GovernanceRulesValidator) ShouldValidate(l *chainscript.Link) bool
ShouldValidate returns true if the segment is a process governance segment.
func (*GovernanceRulesValidator) Validate ¶
func (v *GovernanceRulesValidator) Validate(context.Context, store.SegmentReader, *chainscript.Link) error
Validate an update to a process' validation rules.
type GovernedProcessValidator ¶
type GovernedProcessValidator struct{}
GovernedProcessValidator validates a segment against the latest voted rules in a p2p decentralized network.
func (*GovernedProcessValidator) Hash ¶
func (v *GovernedProcessValidator) Hash() ([]byte, error)
Hash returns an empty hash since the validator doesn't have any configuration (it works the same for every decentralized network).
func (*GovernedProcessValidator) ShouldValidate ¶
func (v *GovernedProcessValidator) ShouldValidate(l *chainscript.Link) bool
ShouldValidate returns true if the segment is a process segment (i.e. not a segment from special administrative processes like governance).
func (*GovernedProcessValidator) Validate ¶
func (v *GovernedProcessValidator) Validate(context.Context, store.SegmentReader, *chainscript.Link) error
Validate the segment against the latest voted rules.
type MultiValidator ¶
type MultiValidator struct {
// contains filtered or unexported fields
}
MultiValidator is a collection of validators.
func (MultiValidator) Hash ¶
func (v MultiValidator) Hash() ([]byte, error)
Hash concatenates the hashes from its children and hashes the result.
func (MultiValidator) ShouldValidate ¶
func (v MultiValidator) ShouldValidate(link *chainscript.Link) bool
ShouldValidate returns true if at least one of the children matches.
func (MultiValidator) Validate ¶
func (v MultiValidator) Validate(ctx context.Context, r store.SegmentReader, l *chainscript.Link) error
Validate forwards the link to every child validator that matches.
type PKI ¶
PKI maps a public key to an identity. It lists all legimate keys, assigns real names to public keys and establishes n-to-n relationships between users and roles.
type PKIValidator ¶
type PKIValidator struct { *ProcessStepValidator RequiredSignatures []string PKI PKI }
PKIValidator validates the json signature requirements of a link's data.
func (PKIValidator) Hash ¶
func (pv PKIValidator) Hash() ([]byte, error)
Hash the signature requirements.
func (PKIValidator) Validate ¶
func (pv PKIValidator) Validate(ctx context.Context, _ store.SegmentReader, link *chainscript.Link) error
Validate that the provided signatures match the required ones. A requirement can be:
- a public key
- a name defined in PKI
- a role defined in PKI
type Participant ¶
type Participant struct { Name string `json:"name"` Power uint `json:"votingPower"` PublicKey []byte `json:"publicKey"` }
Participant in a decentralized network. Participants have the responsibility of voting for validation rules updates.
type ParticipantUpdate ¶
type ParticipantUpdate struct { Type string `json:"updateType"` Participant }
ParticipantUpdate operation to remove/update network participants.
func (ParticipantUpdate) Validate ¶
func (p ParticipantUpdate) Validate(current []*Participant) error
Validate participant update data.
type ParticipantsValidator ¶
type ParticipantsValidator struct{}
ParticipantsValidator validates changes to the governance participants list. The participants map should have the following structure:
,---------, ,--------------, ,----------------, | accept | <====================================== | accept | <========================================= | accept | | (alice) | <-. | (alice, bob) | <-. | (alice, carol) | `---------' | ,----------, ,---------, `--------------' | `----------------'
`-- | update | | vote | | | ,---------, | | | add: bob | <=== | (alice) | <---------' | ,-------------, | vote | | | `----------' `---------' | | update | <=== | (alice) | <----------' | | | add: carol | `---------' | `--| remove: bob | ,---------, | | | <=== | vote | | `-------------' | (bob) | <-------------' `---------'
where: <=== represents a parent relationship <--- represents a reference
func (*ParticipantsValidator) Hash ¶
func (v *ParticipantsValidator) Hash() ([]byte, error)
Hash returns an empty hash since ParticipantsValidator doesn't have any configuration (it works the same for every decentralized network).
func (*ParticipantsValidator) ShouldValidate ¶
func (v *ParticipantsValidator) ShouldValidate(l *chainscript.Link) bool
ShouldValidate returns true if the segment belongs to the participants map in the governance process.
func (*ParticipantsValidator) Validate ¶
func (v *ParticipantsValidator) Validate(ctx context.Context, r store.SegmentReader, l *chainscript.Link) error
Validate a participants update.
type ProcessStepValidator ¶
type ProcessStepValidator struct {
// contains filtered or unexported fields
}
ProcessStepValidator validates a link's process and step.
func NewProcessStepValidator ¶
func NewProcessStepValidator(process, step string) (*ProcessStepValidator, error)
NewProcessStepValidator creates a new ProcessStepValidator for the given process and step.
func (*ProcessStepValidator) Hash ¶
func (v *ProcessStepValidator) Hash() ([]byte, error)
Hash the process and step.
func (*ProcessStepValidator) ShouldValidate ¶
func (v *ProcessStepValidator) ShouldValidate(link *chainscript.Link) bool
ShouldValidate returns true if the link matches the validator's process and type. Otherwise the link is considered valid because this validator doesn't apply to it.
func (*ProcessStepValidator) Validate ¶
func (v *ProcessStepValidator) Validate(ctx context.Context, _ store.SegmentReader, link *chainscript.Link) error
Validate that the process and step match the configured values.
type ProcessesValidators ¶
type ProcessesValidators map[string]Validators
ProcessesValidators maps a process name to a list of validators.
func (ProcessesValidators) Flatten ¶
func (pv ProcessesValidators) Flatten() Validators
Flatten processes validators to a single slice.
type RefsValidator ¶
type RefsValidator struct{}
RefsValidator validates link references (parent and refs).
func (*RefsValidator) Hash ¶
func (v *RefsValidator) Hash() ([]byte, error)
Hash returns an empty hash since RefsValidator doesn't have any state.
func (*RefsValidator) ShouldValidate ¶
func (v *RefsValidator) ShouldValidate(*chainscript.Link) bool
ShouldValidate always evaluates to true, as all links should validate their references.
func (*RefsValidator) Validate ¶
func (v *RefsValidator) Validate(ctx context.Context, r store.SegmentReader, l *chainscript.Link) error
Validate all references (parent and refs).
type SchemaValidator ¶
type SchemaValidator struct { *ProcessStepValidator // contains filtered or unexported fields }
SchemaValidator validates the json schema of a link's data.
func (SchemaValidator) Hash ¶
func (sv SchemaValidator) Hash() ([]byte, error)
Hash the process, step and expected schema.
func (SchemaValidator) Validate ¶
func (sv SchemaValidator) Validate(ctx context.Context, _ store.SegmentReader, link *chainscript.Link) error
Validate the schema of a link's data.
type ScriptConfig ¶
type ScriptConfig struct {
Hash string `json:"hash"`
}
ScriptConfig defines the configuration of the go validation plugin.
type ScriptValidator ¶
type ScriptValidator struct {
// contains filtered or unexported fields
}
ScriptValidator validates a link according to custom rules written as a go plugin. The plugin should expose a `Validate` method.
func (*ScriptValidator) Hash ¶
func (sv *ScriptValidator) Hash() ([]byte, error)
Hash of the script validator.
func (*ScriptValidator) ShouldValidate ¶
func (sv *ScriptValidator) ShouldValidate(link *chainscript.Link) bool
ShouldValidate checks that the process matches.
func (*ScriptValidator) Validate ¶
func (sv *ScriptValidator) Validate(ctx context.Context, storeReader store.SegmentReader, link *chainscript.Link) error
Validate the link.
type ScriptValidatorFunc ¶
ScriptValidatorFunc is the function called when enforcing a custom validation rule.
type TransitionValidator ¶
type TransitionValidator struct { *ProcessStepValidator // contains filtered or unexported fields }
TransitionValidator restricts the transitions from a step to another. It checks that the parent step was in the list of authorized steps.
func (TransitionValidator) Hash ¶
func (tv TransitionValidator) Hash() ([]byte, error)
Hash the process, step and allowed previous steps.
func (TransitionValidator) Validate ¶
func (tv TransitionValidator) Validate(ctx context.Context, store store.SegmentReader, link *chainscript.Link) error
Validate that the link's new step follows an authorized transition. If there is no previous link the allowed transitions must explicitly contain an empty string.
type Validator ¶
type Validator interface { // Validate runs validations on a link and returns an error // if the link is invalid. Validate(context.Context, store.SegmentReader, *chainscript.Link) error // ShouldValidate returns a boolean whether the link should be checked ShouldValidate(*chainscript.Link) bool // Hash returns the hash of the validator's state. // It can be used to know which set of validations were applied // to a block. Hash() ([]byte, error) }
Validator defines a validator that has an internal state, identified by its hash.
func NewGovernanceRulesValidator ¶
func NewGovernanceRulesValidator() Validator
NewGovernanceRulesValidator creates a validator for custom validation rules updates.
func NewGovernedProcessValidator ¶
func NewGovernedProcessValidator() Validator
NewGovernedProcessValidator creates a segment validator.
func NewMultiValidator ¶
func NewMultiValidator(validators Validators) Validator
NewMultiValidator creates a validator that will simply be a collection of single-purpose validators.
func NewPKIValidator ¶
func NewPKIValidator(processStepValidator *ProcessStepValidator, required []string, pki PKI) Validator
NewPKIValidator returns a new PKIValidator.
func NewParticipantsValidator ¶
func NewParticipantsValidator() Validator
NewParticipantsValidator creates a new participants validator for the network. A participants validator is needed for decentralized networks that leverage governance to update processes' validation rules.
func NewRefsValidator ¶
func NewRefsValidator() Validator
NewRefsValidator creates a new RefsValidator.
func NewSchemaValidator ¶
func NewSchemaValidator(processStepValidator *ProcessStepValidator, schemaData []byte) (Validator, error)
NewSchemaValidator returns a new SchemaValidator.
func NewScriptValidator ¶
func NewScriptValidator(process string, pluginsPath string, scriptCfg *ScriptConfig) (Validator, error)
NewScriptValidator creates a new validator for the given process. It expects a plugin named `{hash}.so` to be found in the pluginsPath directory (where {hash} is hex-encoded). The plugin should expose a `Validate` ScriptValidatorFunc.
func NewTransitionValidator ¶
func NewTransitionValidator(processStepValidator *ProcessStepValidator, from []string) Validator
NewTransitionValidator returns a new TransitionValidator for the given process and step.