contract

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const ActingPartyAttr = "acting_party"

deprecated

View Source
const AmsterdamTimeZone = "Europe/Amsterdam"
View Source
const LegalEntityAttr = "legal_entity"
View Source
const ValidFromAttr = "valid_from"
View Source
const ValidToAttr = "valid_to"
View Source
const VerifiableCredentialContext = "https://www.w3.org/2018/credentials/v1"

VerifiableCredentialContext is the v1 base context for VPs todo: move or use lib

View Source
const VerifiablePresentationType = VPType("VerifiablePresentation")

VerifiablePresentationType is used as one of the types for a VerifiablePresentation todo move

Variables

View Source
var ErrContractNotFound = errors.New("contract not found")

ErrContractNotFound is used when a certain combination of type, language and version cannot resolve to a contract

View Source
var ErrInvalidContractFormat = errors.New("unknown contract type")

ErrInvalidContractFormat indicates tha a contract format is unknown.

View Source
var ErrInvalidContractText = errors.New("invalid contract text")

ErrInvalidContractText is used when contract texts cannot be parsed or contain invalid values

View Source
var ErrInvalidPeriod = fmt.Errorf("%w: invalid period", ErrInvalidContractText)
View Source
var ErrUnknownContractFormat = errors.New("unknown contract format")

ErrUnknownContractFormat is returned when the contract format is unknown

View Source
var ErrUnknownSessionID = errors.New("unknown sessionId")

ErrUnknownSessionID is returned when the session id is not known

View Source
var NowFunc = time.Now

NowFunc is used to store a function that returns the current time. This can be changed when you want to mock the current time.

View Source
var StandardContractTemplates = TemplateStore{
	"NL": {"BehandelaarLogin": {
		"v1": &Template{
			Type:               "BehandelaarLogin",
			Version:            "v1",
			Language:           "NL",
			SignerAttributes:   []string{".nuts.agb.agbcode"},
			Template:           `NL:BehandelaarLogin:v1 Ondergetekende geeft toestemming aan {{` + ActingPartyAttr + `}} om namens {{` + LegalEntityAttr + `}} en ondergetekende het Nuts netwerk te bevragen. Deze toestemming is geldig van {{` + ValidFromAttr + `}} tot {{` + ValidToAttr + `}}.`,
			TemplateAttributes: []string{ActingPartyAttr, LegalEntityAttr, ValidFromAttr, ValidToAttr},
			Regexp:             `NL:BehandelaarLogin:v1 Ondergetekende geeft toestemming aan (.+) om namens (.+) en ondergetekende het Nuts netwerk te bevragen. Deze toestemming is geldig van (.+) tot (.+).`,
		},
		"v2": &Template{
			Type:               "BehandelaarLogin",
			Version:            "v2",
			Language:           "NL",
			SignerAttributes:   StandardSignerAttributes,
			Template:           `NL:BehandelaarLogin:v2 Ondergetekende geeft toestemming aan {{` + ActingPartyAttr + `}} om namens {{` + LegalEntityAttr + `}} en ondergetekende het Nuts netwerk te bevragen. Deze toestemming is geldig van {{` + ValidFromAttr + `}} tot {{` + ValidToAttr + `}}.`,
			TemplateAttributes: []string{ActingPartyAttr, LegalEntityAttr, ValidFromAttr, ValidToAttr},
			Regexp:             `NL:BehandelaarLogin:v2 Ondergetekende geeft toestemming aan (.+) om namens (.+) en ondergetekende het Nuts netwerk te bevragen. Deze toestemming is geldig van (.+) tot (.+).`,
		},
		"v3": &Template{
			Type:               "BehandelaarLogin",
			Version:            "v3",
			Language:           "NL",
			SignerAttributes:   StandardSignerAttributes,
			Template:           `NL:BehandelaarLogin:v3 Hierbij verklaar ik te handelen in naam van {{` + LegalEntityAttr + `}}. Deze verklaring is geldig van {{` + ValidFromAttr + `}} tot {{` + ValidToAttr + `}}.`,
			TemplateAttributes: []string{LegalEntityAttr, ValidFromAttr, ValidToAttr},
			Regexp:             `NL:BehandelaarLogin:v3 Hierbij verklaar ik te handelen in naam van (.+). Deze verklaring is geldig van (.+) tot (.+).`,
		},
	}},
	"EN": {"PractitionerLogin": {
		"v1": &Template{
			Type:               "PractitionerLogin",
			Version:            "v1",
			Language:           "EN",
			SignerAttributes:   []string{"nuts.agb.agbcode"},
			Template:           `EN:PractitionerLogin:v1 Undersigned gives permission to {{` + ActingPartyAttr + `}} to make request to the Nuts network on behalf of {{` + LegalEntityAttr + `}} and itself. This permission is valid from {{` + ValidFromAttr + `}} until {{` + ValidToAttr + `}}.`,
			TemplateAttributes: []string{ActingPartyAttr, LegalEntityAttr, ValidFromAttr, ValidToAttr},
			Regexp:             `EN:PractitionerLogin:v1 Undersigned gives permission to (.+) to make request to the Nuts network on behalf of (.+) and itself. This permission is valid from (.+) until (.+).`,
		},
		"v2": &Template{
			Type:               "PractitionerLogin",
			Version:            "v2",
			Language:           "EN",
			SignerAttributes:   StandardSignerAttributes,
			Template:           `EN:PractitionerLogin:v2 Undersigned gives permission to {{` + ActingPartyAttr + `}} to make request to the Nuts network on behalf of {{` + LegalEntityAttr + `}} and itself. This permission is valid from {{` + ValidFromAttr + `}} until {{` + ValidToAttr + `}}.`,
			TemplateAttributes: []string{ActingPartyAttr, LegalEntityAttr, ValidFromAttr, ValidToAttr},
			Regexp:             `EN:PractitionerLogin:v2 Undersigned gives permission to (.+) to make request to the Nuts network on behalf of (.+) and itself. This permission is valid from (.+) until (.+).`,
		},
		"v3": &Template{
			Type:               "PractitionerLogin",
			Version:            "v3",
			Language:           "EN",
			SignerAttributes:   StandardSignerAttributes,
			Template:           `EN:PractitionerLogin:v3 I hereby declare to act on behalf of {{` + LegalEntityAttr + `}}. This declaration is valid from {{` + ValidFromAttr + `}} until {{` + ValidToAttr + `}}.`,
			TemplateAttributes: []string{LegalEntityAttr, ValidFromAttr, ValidToAttr},
			Regexp:             `EN:PractitionerLogin:v3 I hereby declare to act on behalf of (.+). This declaration is valid from (.+) until (.+).`,
		},
	}},
}

StandardContractTemplates contains a the official contract templates as specified in the Nuts specification EN:PractitionerLogin:v1 Template

View Source
var StandardSignerAttributes = []string{
	".gemeente.personalData.firstnames",
	"pbdf.sidn-pbdf.email.email",
}

StandardSignerAttributes defines the standard list of attributes used for a contract. If SignerAttribute name starts with a dot '.', it uses the configured scheme manager

Functions

This section is empty.

Types

type BaseVerifiablePresentation

type BaseVerifiablePresentation struct {
	Context []string               `json:"@context"`
	Proof   map[string]interface{} `json:"proof"`
	Type    []VPType               `json:"type"`
}

BaseVerifiablePresentation represents a W3C Verifiable Presentation with only its Type attribute

type Contract

type Contract struct {
	RawContractText string
	Template        *Template
	Params          map[string]string
}

Contract contains the contract template, the raw contract text and the extracted params.

func ParseContractString

func ParseContractString(rawContractText string, contractTemplates TemplateStore) (*Contract, error)

ParseContractString parses a raw string, finds the contract from the store and extracts the params Note: It does not verify the params

func (Contract) Verify

func (sc Contract) Verify() error

Verify verifies the params with the template

func (Contract) VerifyForGivenTime

func (sc Contract) VerifyForGivenTime(checkTime time.Time) error

VerifyForGivenTime checks if the contract is valid for the given moment in time TODO: support of different time zones: https://github.com/nuts-foundation/nuts-auth/issues/152

type Language

type Language string

Language of the contract in all caps. example: "NL"

type Proof

type Proof struct {
	Type string `json:"type"`
}

Proof represents the Proof part of a Verifiable Presentation specific verifiers may extend upon this Proof

type SessionPointer

type SessionPointer interface {
	SessionID() string
	Payload() []byte
}

SessionPointer contains session information for the means how to sign the payload

type Signer

type Signer interface {
	// SigningSessionStatus returns the current status of the signing session or services.ErrSessionNotFound if not found
	// todo: name should have been SessionStatus, but its currently in use by the old interface
	SigningSessionStatus(sessionID string) (SigningSessionResult, error)
	// StartSession starts a session for the implementing signer
	// todo: name should have been StartSession, but its currently in use by the old interface
	StartSigningSession(rawContractText string) (SessionPointer, error)
}

Signer is responsible for signing contract signing requests. Signing is done by making use of asynchronous SigningSessions.

type SigningMeans

type SigningMeans string

SigningMeans holds the unique nuts name of the singing means.

type SigningSessionResult

type SigningSessionResult interface {
	// Status returns the current state of the SigningSession
	Status() string
	// VerifiablePresentation returns a VerifiablePresentation holding the presentation proof and disclosed attributes or an error if
	// no proof is present yet
	VerifiablePresentation() (VerifiablePresentation, error)
}

SigningSessionResult holds information in the current status of the SigningSession

type State

type State string

State contains the result of the verification. It van be VALID or INVALID. This makes it human readable.

const (
	// Valid is used to indicate a contract was valid on the time of testing
	Valid State = "VALID"
	// Invalid is used to indicate a contract was invalid on the time of testing
	Invalid State = "INVALID"
)

type Template

type Template struct {
	Type                 Type     `json:"type"`
	Version              Version  `json:"version"`
	Language             Language `json:"language"`
	SignerAttributes     []string `json:"signer_attributes"`
	SignerDemoAttributes []string `json:"-"`
	Template             string   `json:"Template"`
	TemplateAttributes   []string `json:"template_attributes"`
	Regexp               string   `json:"-"`
}

Template stores al properties of a contract template which can result in a signed contract

func (Template) Render

func (c Template) Render(vars map[string]string, validFrom time.Time, validDuration time.Duration) (*Contract, error)

Render a template using the given templates variables. The combination of validFrom and the duration configure the validFrom and validTo template attributes. The ValidFrom or ValidTo provided in the vars map will be overwritten. Note: For date calculation the Amsterdam timezone and Dutch locale is used.

type TemplateStore

type TemplateStore map[Language]map[Type]map[Version]*Template

TemplateStore contains a list of Contract templates sorted by language, type and version

func (TemplateStore) FindFromRawContractText

func (m TemplateStore) FindFromRawContractText(rawContractText string) (*Template, error)

func (TemplateStore) Get

func (m TemplateStore) Get(cType Type, language Language, version Version) *Template

Get safely searches the template store. When no version is given, v1 is used. Returns the template or nil

type Type

type Type string

Type contains type of the contract to sign. Example: "BehandelaarLogin"

type VPType

type VPType string

VPType holds the type of the Verifiable Presentation. Based on the format an appropriate validator can be selected.

type VPVerificationResult

type VPVerificationResult struct {
	// Validity indicates if the Presentation is valid
	// It can contains the "VALID" or "INVALID" status.
	// Validators must only set the Validity to "VALID" if the whole VP, including the embedded
	// contract are valid at the given moment in time.
	Validity State
	// VPType contains the the VP type like "NutsUziPresentation".
	VPType VPType
	// ContractID contains the identifier string of the signed contract message like: "EN:PractitionerLogin:v3"
	ContractID string
	// DisclosedAttributes contain the attributes used to sign this contract
	DisclosedAttributes map[string]string
	// ContractAttributes contain the attributes used to fill the contract
	ContractAttributes map[string]string
}

VPVerificationResult contains the result of a contract validation

type VPVerifier

type VPVerifier interface {
	// VerifyVP validates a verifiable presentation.
	// When the verifier could not handle the verifiable presentation, an error should be thrown.
	VerifyVP(rawVerifiablePresentation []byte, checkTime *time.Time) (*VPVerificationResult, error)
}

VPVerifier defines the interface needed to verify a VerifiablePresentation

type VerifiablePresentation

type VerifiablePresentation interface {
}

VerifiablePresentation represents a W3C Verifiable Presentation

type VerifiablePresentationBase

type VerifiablePresentationBase struct {
	Context []string `json:"@context"`
	Type    []VPType
}

VerifiablePresentationBase holds the basic fields for a VerifiableCredential todo: move or use lib

type VerifierType

type VerifierType string

VerifierType is the type for a specific verifier

type Version

type Version string

Version of the contract. example: "v1"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL