contract

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package contract is a generated GoMock package.

Index

Constants

View Source
const ActingPartyAttr = "acting_party"

deprecated, can be removed after irma signature test data has been updated to v3 templates

View Source
const AmsterdamTimeZone = "Europe/Amsterdam"

AmsterdamTimeZone contains the timezone of the Cannabis capital of Europe.

View Source
const LegalEntityAttr = "legal_entity"

LegalEntityAttr contains the key of the legal-entity attribute.

View Source
const LegalEntityCityAttr = "legal_entity_city"

LegalEntityCityAttr contains the key of the legal-entity city attribute.

View Source
const ValidFromAttr = "valid_from"

ValidFromAttr contains the key of the valid-from attribute.

View Source
const ValidToAttr = "valid_to"

ValidToAttr contains the key of the valid-to attribute.

Variables

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)

ErrInvalidPeriod is returned when the given period is invalid

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",
			Locale:             "nl_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 (.+).`,
		},
		"v3": &Template{
			Type:               "BehandelaarLogin",
			Version:            "v3",
			Language:           "NL",
			Locale:             "nl_NL",
			SignerAttributes:   StandardSignerAttributes,
			Template:           `NL:BehandelaarLogin:v3 Hierbij verklaar ik te handelen in naam van {{` + LegalEntityAttr + `}} te {{` + LegalEntityCityAttr + `}}. Deze verklaring is geldig van {{` + ValidFromAttr + `}} tot {{` + ValidToAttr + `}}.`,
			TemplateAttributes: []string{LegalEntityAttr, LegalEntityCityAttr, ValidFromAttr, ValidToAttr},
			Regexp:             `NL:BehandelaarLogin:v3 Hierbij verklaar ik te handelen in naam van (.+) te (.+). Deze verklaring is geldig van (.+) tot (.+).`,
		},
	}},
	"EN": {"PractitionerLogin": {
		"v3": &Template{
			Type:               "PractitionerLogin",
			Version:            "v3",
			Language:           "EN",
			Locale:             "en_US",
			SignerAttributes:   StandardSignerAttributes,
			Template:           `EN:PractitionerLogin:v3 I hereby declare to act on behalf of {{` + LegalEntityAttr + `}} located in {{` + LegalEntityCityAttr + `}}. This declaration is valid from {{` + ValidFromAttr + `}} until {{` + ValidToAttr + `}}.`,
			TemplateAttributes: []string{LegalEntityAttr, LegalEntityCityAttr, ValidFromAttr, ValidToAttr},
			Regexp:             `EN:PractitionerLogin:v3 I hereby declare to act on behalf of (.+) located in (.+). This declaration is valid from (.+) until (.+).`,
		},
	}},
}

StandardContractTemplates contains a the official contract templates as specified in the Nuts specification EN:PractitionerLogin:v1 Template todo: remove v1 template after renewing (irma) test data.

View Source
var StandardSignerAttributes = []string{
	".gemeente.personalData.initials",
	".gemeente.personalData.prefix",
	".gemeente.personalData.familyname",
	".gemeente.personalData.digidlevel",
	".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 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

type Language

type Language string

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

type MockSessionPointer

type MockSessionPointer struct {
	// contains filtered or unexported fields
}

MockSessionPointer is a mock of SessionPointer interface.

func NewMockSessionPointer

func NewMockSessionPointer(ctrl *gomock.Controller) *MockSessionPointer

NewMockSessionPointer creates a new mock instance.

func (*MockSessionPointer) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockSessionPointer) MarshalJSON

func (m *MockSessionPointer) MarshalJSON() ([]byte, error)

MarshalJSON mocks base method.

func (*MockSessionPointer) Payload

func (m *MockSessionPointer) Payload() []byte

Payload mocks base method.

func (*MockSessionPointer) SessionID

func (m *MockSessionPointer) SessionID() string

SessionID mocks base method.

type MockSessionPointerMockRecorder

type MockSessionPointerMockRecorder struct {
	// contains filtered or unexported fields
}

MockSessionPointerMockRecorder is the mock recorder for MockSessionPointer.

func (*MockSessionPointerMockRecorder) MarshalJSON

func (mr *MockSessionPointerMockRecorder) MarshalJSON() *gomock.Call

MarshalJSON indicates an expected call of MarshalJSON.

func (*MockSessionPointerMockRecorder) Payload

Payload indicates an expected call of Payload.

func (*MockSessionPointerMockRecorder) SessionID

func (mr *MockSessionPointerMockRecorder) SessionID() *gomock.Call

SessionID indicates an expected call of SessionID.

type MockSigner

type MockSigner struct {
	// contains filtered or unexported fields
}

MockSigner is a mock of Signer interface.

func NewMockSigner

func NewMockSigner(ctrl *gomock.Controller) *MockSigner

NewMockSigner creates a new mock instance.

func (*MockSigner) EXPECT

func (m *MockSigner) EXPECT() *MockSignerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockSigner) SigningSessionStatus

func (m *MockSigner) SigningSessionStatus(sessionID string) (SigningSessionResult, error)

SigningSessionStatus mocks base method.

func (*MockSigner) StartSigningSession

func (m *MockSigner) StartSigningSession(rawContractText string) (SessionPointer, error)

StartSigningSession mocks base method.

type MockSignerMockRecorder

type MockSignerMockRecorder struct {
	// contains filtered or unexported fields
}

MockSignerMockRecorder is the mock recorder for MockSigner.

func (*MockSignerMockRecorder) SigningSessionStatus

func (mr *MockSignerMockRecorder) SigningSessionStatus(sessionID interface{}) *gomock.Call

SigningSessionStatus indicates an expected call of SigningSessionStatus.

func (*MockSignerMockRecorder) StartSigningSession

func (mr *MockSignerMockRecorder) StartSigningSession(rawContractText interface{}) *gomock.Call

StartSigningSession indicates an expected call of StartSigningSession.

type MockSigningSessionResult

type MockSigningSessionResult struct {
	// contains filtered or unexported fields
}

MockSigningSessionResult is a mock of SigningSessionResult interface.

func NewMockSigningSessionResult

func NewMockSigningSessionResult(ctrl *gomock.Controller) *MockSigningSessionResult

NewMockSigningSessionResult creates a new mock instance.

func (*MockSigningSessionResult) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockSigningSessionResult) Status

func (m *MockSigningSessionResult) Status() string

Status mocks base method.

func (*MockSigningSessionResult) VerifiablePresentation

func (m *MockSigningSessionResult) VerifiablePresentation() (*vc.VerifiablePresentation, error)

VerifiablePresentation mocks base method.

type MockSigningSessionResultMockRecorder

type MockSigningSessionResultMockRecorder struct {
	// contains filtered or unexported fields
}

MockSigningSessionResultMockRecorder is the mock recorder for MockSigningSessionResult.

func (*MockSigningSessionResultMockRecorder) Status

Status indicates an expected call of Status.

func (*MockSigningSessionResultMockRecorder) VerifiablePresentation

func (mr *MockSigningSessionResultMockRecorder) VerifiablePresentation() *gomock.Call

VerifiablePresentation indicates an expected call of VerifiablePresentation.

type SessionPointer

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

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
	SigningSessionStatus(sessionID string) (SigningSessionResult, error)
	// StartSigningSession starts a session for the implementing signer
	StartSigningSession(rawContractText string) (SessionPointer, error)
}

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

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() (*vc.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"`
	// Locale contains the locale of the contract in ICU format which consists of:
	// - the language code (ISO-639-2)
	// - an underscore (_)
	// - the country code (ISO-3166)
	// For example: nl_NL, en_GB, en_US, fr_FR
	Locale               string   `json:"-"`
	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, v3 is used. Returns the template or nil

type Type

type Type string

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

type VPVerificationResult

type VPVerificationResult interface {
	// 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 returns the the VP type like "NutsUziPresentation".
	VPType() string
	// DisclosedAttribute returns the attribute value used to sign this contract
	// returns empty string when not found
	DisclosedAttribute(key string) string
	// ContractAttribute returns the attribute value used to fill the contract
	// returns empty string when not found
	ContractAttribute(key string) string
	// DisclosedAttributes returns the attributes used to sign this contract
	DisclosedAttributes() map[string]string
	// ContractAttributes returns the attributes used to fill the contract
	ContractAttributes() map[string]string
}

VPVerificationResult describes the result of a contract validation it abstracts the name of the disclosed attributes from the means. the access token for example uses "initials", "family_name", "prefix" and "email"

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(vp vc.VerifiablePresentation, checkTime *time.Time) (VPVerificationResult, error)
}

VPVerifier defines the interface needed to verify a VerifiablePresentation

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