Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoRegion is used when the envelope is missing a region. ErrNoRegion = NewError("no-region") // ErrValidation is used when a document fails a validation request. ErrValidation = NewError("validation") // ErrCalculation wraps around errors that we're generated during a // call to perform calculations on a document. ErrCalculation = NewError("calculation") // ErrMarshal is provided when there has been a problem attempting to encode // or marshal an object, usually into JSON. ErrMarshal = NewError("marshal") // ErrSignature identifies an issue related to signatures. ErrSignature = NewError("signature") // ErrInternal is a "catch-all" for errors that are not expected. ErrInternal = NewError("internal") )
Functions ¶
func Regions ¶
func Regions() *region.Collection
Regions provides a region collection containing all the known region definitions.
Types ¶
type Calculable ¶
Calculable defines the methods expected of a document payload that contains a `Calculate` method to be used to perform any additional calculations.
type Document ¶
type Document interface {
Type() string
}
Document defines what we expect from a document to be able to be included in an envelope.
type Envelope ¶
type Envelope struct { Head *Header `json:"head" jsonschema:"title=Header,description=Details on what the contents are"` Document *Payload `json:"doc" jsonschema:"title=Document,description=The data being enveloped"` Signatures []*dsig.Signature `json:"sigs" jsonschema:"title=Signatures,description=JSON Web Signatures of the header"` }
Envelope wraps around a gobl document and provides support for digest creation and digital signatures.
func NewEnvelope ¶
NewEnvelope builds a new envelope object ready for data to be inserted and signed. If you are loading data from json, you can safely use a regular `new(Envelope)` call directly. A known region code is required as this will be used for any calculations and validations that need to be performed on the document to be inserted.
func (*Envelope) Insert ¶
Insert takes the provided document, performs any calculations, validates, then serializes it ready for use.
func (*Envelope) Region ¶
Region extracts the region from the header and provides a complete region object.
func (*Envelope) Sign ¶
func (e *Envelope) Sign(key *dsig.PrivateKey) error
Sign uses the private key to the envelope headers.
type Error ¶
Error provides a structure to better be able to make error comparisons. The contents can also be serialised as JSON ready to send to a client if needed.
func (*Error) Is ¶
Is checks to see if the target error matches the current error or part of the chain.
func (*Error) WithErrorf ¶
WithErrorf wraps around the `fmt.Errorf` call to provide a more meaningful error in the context.
type Header ¶
type Header struct { UUID uuid.UUID `json:"uuid" jsonschema:"title=UUID,description=Unique UUIDv1 identifier for the envelope."` Type string `json:"typ" jsonschema:"title=Type,description=Body type of the document contents."` Region region.Code `json:"rgn" jsonschema:"title=Region,description=Code for the region the document should be validated with."` Digest *dsig.Digest `json:"dig" jsonschema:"title=Digest,description=Digest of the canonical JSON body."` Stamps []*Stamp `json:"stamps,omitempty" jsonschema:"title=Stamps,description=Seals of approval from other organisations."` Tags []string `json:"tags,omitempty" jsonschema:"title=Tags,description=Set of labels that describe but have no influence on the data."` Meta org.Meta `json:"meta,omitempty" jsonschema:"title=Meta,description=Additional semi-structured information about this envelope."` Notes string `` /* 133-byte string literal not displayed */ Draft bool `` /* 162-byte string literal not displayed */ }
Header defines the meta data of the body. The header is used as the payload for the JSON Web Signatures, so we want this to be as compact as possible.
type Payload ¶
type Payload struct {
// contains filtered or unexported fields
}
Payload helps us handle the document's contents by essentially wrapping around the json RawMessage.
func (Payload) JSONSchemaType ¶
func (Payload) JSONSchemaType() *jsonschema.Type
func (*Payload) MarshalJSON ¶
func (*Payload) UnmarshalJSON ¶
type Signatures ¶
Signatures keeps together a list of signatures that we're used to sign the document head contents.
type Stamp ¶
type Stamp struct { Provider string `json:"prv" jsonschema:"title=Provider,description=Identity of the agency used to create the stamp"` Value string `json:"val" jsonschema:"title=Value,description=The serialized stamp value generated for or by the external agency"` }
Stamp defines an official seal of approval from a third party like a governmental agency or intermediary and should thus be included in any official envelopes.
type Validatable ¶
Validatable describes a document that can be validated.