Documentation
¶
Index ¶
- Constants
- func ConvertDocProofToClientFormat(proof *DocumentProof) (*documentpb.DocumentProof, error)
- func ConvertProofToClientFormat(proof *proofspb.Proof) *documentpb.Proof
- func ConvertProofsToClientFormat(proofs []*proofspb.Proof) []*documentpb.Proof
- func GRPCHandler(config config.Service, registry *ServiceRegistry) documentpb.DocumentServiceServer
- func InitDocumentAnchorTask(tq queue.TaskQueuer, txService transactions.Service, accountID identity.CentID, ...) (uuid.UUID, error)
- func IsCurrencyValid(cur string) bool
- func NewError(key, msg string) error
- type AnchorProcessor
- type Bootstrapper
- type Client
- type Config
- type DocumentProof
- type Error
- type Model
- type PostBootstrapper
- type Repository
- type Service
- type ServiceRegistry
- type Validator
- type ValidatorFunc
- type ValidatorGroup
- func PostAnchoredValidator(idService identity.Service, repo anchors.AnchorRepository) ValidatorGroup
- func PostSignatureRequestValidator(idService identity.Service) ValidatorGroup
- func PreAnchorValidator(idService identity.Service) ValidatorGroup
- func PreSignatureRequestValidator(centIDBytes, priv, pub []byte) ValidatorGroup
- func SignatureRequestValidator(idService identity.Service) ValidatorGroup
Constants ¶
const ( // BootstrappedRegistry is the key to ServiceRegistry in Bootstrap context BootstrappedRegistry = "BootstrappedRegistry" // BootstrappedDocumentRepository is the key to the database repository of documents BootstrappedDocumentRepository = "BootstrappedDocumentRepository" // BootstrappedDocumentService is the key to bootstrapped document service BootstrappedDocumentService = "BootstrappedDocumentService" )
const ( // ErrDocumentConfigAccountID must be used for errors related to accountID operations ErrDocumentConfigAccountID = errors.Error("error with accountID operations") // ErrDocumentBootstrap must be used for errors related to documents package bootstrapping ErrDocumentBootstrap = errors.Error("error when bootstrapping document package") // ErrDocumentIdentifier must be used for errors caused by document identifier problems ErrDocumentIdentifier = errors.Error("document identifier error") // ErrDocumentInvalidType must be used when a provided document type is not valid to be processed by the service ErrDocumentInvalidType = errors.Error("document is of invalid type") // ErrDocumentNil must be used when the provided document through a function is nil ErrDocumentNil = errors.Error("no(nil) document provided") // ErrDocumentInvalid must only be used when the reason for invalidity is impossible to determine or the invalidity is caused by validation errors ErrDocumentInvalid = errors.Error("document is invalid") // ErrDocumentNotFound must be used to indicate that the document for provided id is not found in the system ErrDocumentNotFound = errors.Error("document not found in the system database") // ErrDocumentVersionNotFound must be used to indicate that the specified version of the document for provided id is not found in the system ErrDocumentVersionNotFound = errors.Error("specified version of the document not found in the system database") // ErrDocumentPersistence must be used when creating or updating a document in the system database failed ErrDocumentPersistence = errors.Error("error encountered when storing document in the system database") // ErrDocumentPackingCoreDocument must be used when packing of core document for the given document failed ErrDocumentPackingCoreDocument = errors.Error("core document packing failed") // ErrDocumentUnPackingCoreDocument must be used when unpacking of core document for the given document failed ErrDocumentUnPackingCoreDocument = errors.Error("core document unpacking failed") // ErrDocumentPrepareCoreDocument must be used when preparing a new core document fails for the given document ErrDocumentPrepareCoreDocument = errors.Error("core document preparation failed") // ErrDocumentSigning must be used when document signing related functionality fails ErrDocumentSigning = errors.Error("document signing failed") // ErrDocumentAnchoring must be used when document anchoring fails ErrDocumentAnchoring = errors.Error("document anchoring failed") // ErrDocumentCollaborator must be used when there is an error in processing collaborators ErrDocumentCollaborator = errors.Error("document collaborator issue") // ErrDocumentProof must be used when document proof creation fails ErrDocumentProof = errors.Error("document proof error") // ErrDocumentRepositoryModelNotRegistered must be used when the model hasn't been registered in the database repository ErrDocumentRepositoryModelNotRegistered = errors.Error("document model hasn't been registered in the database repository") // ErrDocumentRepositorySerialisation must be used when document repository encounters a marshalling error ErrDocumentRepositorySerialisation = errors.Error("document repository encountered a marshalling error") // ErrDocumentRepositoryModelNotFound must be used when document repository can not locate the given model ErrDocumentRepositoryModelNotFound = errors.Error("document repository could not locate the given model") // ErrDocumentRepositoryModelSave must be used when document repository can not save the given model ErrDocumentRepositoryModelSave = errors.Error("document repository could not save the given model") // ErrDocumentRepositoryModelAllReadyExists must be used when document repository finds an already existing model when saving ErrDocumentRepositoryModelAllReadyExists = errors.Error("document repository found an already existing model when saving") // ErrDocumentRepositoryModelDoesntExist must be used when document repository does not find an existing model for an update ErrDocumentRepositoryModelDoesntExist = errors.Error("document repository did not find an existing model for an update") )
Variables ¶
This section is empty.
Functions ¶
func ConvertDocProofToClientFormat ¶
func ConvertDocProofToClientFormat(proof *DocumentProof) (*documentpb.DocumentProof, error)
ConvertDocProofToClientFormat converts a DocumentProof to client api format
func ConvertProofToClientFormat ¶
func ConvertProofToClientFormat(proof *proofspb.Proof) *documentpb.Proof
ConvertProofToClientFormat converts a proof in precise proof format in to a client protobuf proof
func ConvertProofsToClientFormat ¶
func ConvertProofsToClientFormat(proofs []*proofspb.Proof) []*documentpb.Proof
ConvertProofsToClientFormat converts a proof protobuf from precise proofs into a client protobuf proof format
func GRPCHandler ¶
func GRPCHandler(config config.Service, registry *ServiceRegistry) documentpb.DocumentServiceServer
GRPCHandler returns an implementation of documentpb.DocumentServiceServer
func InitDocumentAnchorTask ¶
func InitDocumentAnchorTask(tq queue.TaskQueuer, txService transactions.Service, accountID identity.CentID, modelID []byte) (uuid.UUID, error)
InitDocumentAnchorTask enqueues a new document anchor task and returns the txID.
func IsCurrencyValid ¶
IsCurrencyValid checks if the currency is of length 3
Types ¶
type AnchorProcessor ¶
type AnchorProcessor interface { Send(ctx context.Context, coreDocument *coredocumentpb.CoreDocument, recipient identity.CentID) (err error) PrepareForSignatureRequests(ctx context.Context, model Model) error RequestSignatures(ctx context.Context, model Model) error PrepareForAnchoring(model Model) error AnchorDocument(ctx context.Context, model Model) error SendDocument(ctx context.Context, model Model) error }
AnchorProcessor identifies an implementation, which can do a bunch of things with a CoreDocument. E.g. send, anchor, etc.
func DefaultProcessor ¶
func DefaultProcessor(idService identity.Service, p2pClient Client, repository anchors.AnchorRepository, config Config) AnchorProcessor
DefaultProcessor returns the default implementation of CoreDocument AnchorProcessor
type Bootstrapper ¶
type Bootstrapper struct{}
Bootstrapper implements bootstrap.Bootstrapper.
func (Bootstrapper) Bootstrap ¶
func (Bootstrapper) Bootstrap(ctx map[string]interface{}) error
Bootstrap sets the required storage and registers
type Client ¶
type Client interface { // GetSignaturesForDocument gets the signatures for document GetSignaturesForDocument(ctx context.Context, doc *coredocumentpb.CoreDocument) error // after all signatures are collected the sender sends the document including the signatures SendAnchoredDocument(ctx context.Context, receiverID identity.CentID, in *p2ppb.AnchorDocumentRequest) (*p2ppb.AnchorDocumentResponse, error) }
Client defines methods that can be implemented by any type handling p2p communications.
type Config ¶
type Config interface { GetNetworkID() uint32 GetIdentityID() ([]byte, error) GetP2PConnectionTimeout() time.Duration }
Config defines required methods required for the documents package.
type DocumentProof ¶
type DocumentProof struct { DocumentID []byte VersionID []byte State string FieldProofs []*proofspb.Proof }
DocumentProof is a value to represent a document and its field proofs
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error wraps an error with specific key Deprecated: in favour of Error type in `github.com/centrifuge/go-centrifuge/errors`
type Model ¶
type Model interface { storage.Model // Get the ID of the document represented by this model ID() ([]byte, error) // PackCoreDocument packs the implementing document into a core document // should create the identifiers for the core document if not present PackCoreDocument() (*coredocumentpb.CoreDocument, error) // UnpackCoreDocument must return the document.Model // assumes that core document has valid identifiers set UnpackCoreDocument(cd *coredocumentpb.CoreDocument) error // CreateProofs creates precise-proofs for given fields CreateProofs(fields []string) (coreDoc *coredocumentpb.CoreDocument, proofs []*proofspb.Proof, err error) }
Model is an interface to abstract away model specificness like invoice or purchaseOrder The interface can cast into the type specified by the model if required
func AnchorDocument ¶
func AnchorDocument(ctx context.Context, model Model, proc AnchorProcessor, updater updaterFunc) (Model, error)
AnchorDocument add signature, requests signatures, anchors document, and sends the anchored document to collaborators
type PostBootstrapper ¶
type PostBootstrapper struct{}
PostBootstrapper to run the post after all bootstrappers.
func (PostBootstrapper) Bootstrap ¶
func (PostBootstrapper) Bootstrap(ctx map[string]interface{}) error
Bootstrap register task to the queue.
type Repository ¶
type Repository interface { // Exists checks if the id, owned by accountID, exists in DB Exists(accountID, id []byte) bool // Get returns the Model associated with ID, owned by accountID Get(accountID, id []byte) (Model, error) // Create creates the model if not present in the DB. // should error out if the document exists. Create(accountID, id []byte, model Model) error // Update strictly updates the model. // Will error out when the model doesn't exist in the DB. Update(accountID, id []byte, model Model) error // Register registers the model so that the DB can return the document without knowing the type Register(model Model) }
Repository defines the required methods for a document repository. Can be implemented by any type that stores the documents. Ex: levelDB, sql etc...
func NewDBRepository ¶
func NewDBRepository(db storage.Repository) Repository
NewDBRepository creates an instance of the documents Repository
type Service ¶
type Service interface { // GetCurrentVersion reads a document from the database GetCurrentVersion(ctx context.Context, documentID []byte) (Model, error) // Exists checks if a document exists Exists(ctx context.Context, documentID []byte) bool // GetVersion reads a document from the database GetVersion(ctx context.Context, documentID []byte, version []byte) (Model, error) // DeriveFromCoreDocument derives a model given the core document DeriveFromCoreDocument(cd *coredocumentpb.CoreDocument) (Model, error) // CreateProofs creates proofs for the latest version document given the fields CreateProofs(ctx context.Context, documentID []byte, fields []string) (*DocumentProof, error) // CreateProofsForVersion creates proofs for a particular version of the document given the fields CreateProofsForVersion(ctx context.Context, documentID, version []byte, fields []string) (*DocumentProof, error) // RequestDocumentSignature Validates and Signs document received over the p2p layer RequestDocumentSignature(ctx context.Context, model Model) (*coredocumentpb.Signature, error) // ReceiveAnchoredDocument receives a new anchored document over the p2p layer, validates and updates the document in DB ReceiveAnchoredDocument(ctx context.Context, model Model, senderID []byte) error // Create validates and persists Model and returns a Updated model Create(ctx context.Context, model Model) (Model, uuid.UUID, error) // Update validates and updates the model and return the updated model Update(ctx context.Context, model Model) (Model, uuid.UUID, error) }
Service provides an interface for functions common to all document types
func DefaultService ¶
func DefaultService( repo Repository, idService identity.Service, anchorRepo anchors.AnchorRepository, registry *ServiceRegistry) Service
DefaultService returns the default implementation of the service
type ServiceRegistry ¶
type ServiceRegistry struct {
// contains filtered or unexported fields
}
ServiceRegistry matches for a provided coreDocument the corresponding service
func NewServiceRegistry ¶
func NewServiceRegistry() *ServiceRegistry
NewServiceRegistry returns a new instance of service registry
func (*ServiceRegistry) LocateService ¶
func (s *ServiceRegistry) LocateService(serviceID string) (Service, error)
LocateService will return the registered service for the embedded document type
type Validator ¶
type Validator interface { // Validate validates the updates to the model in newState. Validate(oldState Model, newState Model) error }
Validator is an interface every Validator (atomic or group) should implement
func UpdateVersionValidator ¶
func UpdateVersionValidator() Validator
UpdateVersionValidator validates if the new core document is properly derived from old one
type ValidatorFunc ¶
ValidatorFunc implements Validator and can be used as a adaptor for functions with specific function signature
func (ValidatorFunc) Validate ¶
func (vf ValidatorFunc) Validate(old, new Model) error
Validate passes the arguments to the underlying validator function and returns the results
type ValidatorGroup ¶
type ValidatorGroup []Validator
ValidatorGroup implements Validator for validating a set of validators.
func PostAnchoredValidator ¶
func PostAnchoredValidator(idService identity.Service, repo anchors.AnchorRepository) ValidatorGroup
PostAnchoredValidator is a validator group with following validators PreAnchorValidator anchoredValidator should be called after anchoring the document/when received anchored document
func PostSignatureRequestValidator ¶
func PostSignatureRequestValidator(idService identity.Service) ValidatorGroup
PostSignatureRequestValidator is a validator group with following validators baseValidator signingRootValidator signaturesValidator should be called after the signature collection/before preparing for anchoring
func PreAnchorValidator ¶
func PreAnchorValidator(idService identity.Service) ValidatorGroup
PreAnchorValidator is a validator group with following validators base validator signing root validator document root validator signatures validator should be called before pre anchoring
func PreSignatureRequestValidator ¶
func PreSignatureRequestValidator(centIDBytes, priv, pub []byte) ValidatorGroup
PreSignatureRequestValidator is a validator group with following validators baseValidator signingRootValidator readyForSignaturesValidator should be called after sender signing the document and before requesting the document
func SignatureRequestValidator ¶
func SignatureRequestValidator(idService identity.Service) ValidatorGroup
SignatureRequestValidator returns a validator group with following validators base validator signing root validator signatures validator should be used when node receives a document requesting for signature