credential

package
v0.0.2-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: Apache-2.0 Imports: 6 Imported by: 15

Documentation

Index

Constants

View Source
const (
	VerifiableCredentialsLinkedDataContext string = "https://www.w3.org/2018/credentials/v1"
	VerifiableCredentialType               string = "VerifiableCredential"
	VerifiableCredentialIDProperty         string = "id"
	VerifiablePresentationType             string = "VerifiablePresentation"

	BuilderEmptyError string = "builder cannot be empty"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CredentialSchema

type CredentialSchema struct {
	ID   string `json:"id" validate:"required"`
	Type string `json:"type" validate:"required"`
}

type CredentialSubject

type CredentialSubject map[string]interface{}

func (CredentialSubject) GetID

func (cs CredentialSubject) GetID() string

type DefaultCredentialStatus

type DefaultCredentialStatus struct {
	ID   string `json:"id" validate:"required"`
	Type string `json:"type" validate:"required"`
}

DefaultCredentialStatus https://www.w3.org/TR/2021/REC-vc-data-model-20211109/#status

type Prohibition

type Prohibition struct {
	Assigner string   `json:"assigner,omitempty"`
	Assignee string   `json:"assignee,omitempty"`
	Target   string   `json:"target,omitempty"`
	Action   []string `json:"action,omitempty"`
}

type RefreshService

type RefreshService struct {
	ID   string `json:"id" validate:"required"`
	Type string `json:"type" validate:"required"`
}

type TermsOfUse

type TermsOfUse struct {
	Type        string        `json:"type,omitempty"`
	ID          string        `json:"id,omitempty"`
	Profile     string        `json:"profile,omitempty"`
	Prohibition []Prohibition `json:"prohibition,omitempty"`
}

TermsOfUse In the current version of the specification TOU isn't well-defined; these fields are subject to change https://www.w3.org/TR/2021/REC-vc-data-model-20211109/#terms-of-use

type VerifiableCredential

type VerifiableCredential struct {
	// Either a string or set of strings
	Context interface{} `json:"@context" validate:"required"`
	ID      string      `json:"id,omitempty"`
	// Either a string or a set of strings https://www.w3.org/TR/2021/REC-vc-data-model-20211109/#types
	Type interface{} `json:"type" validate:"required"`
	// either a URI or an object containing an `id` property.
	Issuer interface{} `json:"issuer" validate:"required"`
	// https://www.w3.org/TR/xmlschema11-2/#dateTimes
	IssuanceDate     string      `json:"issuanceDate" validate:"required"`
	ExpirationDate   string      `json:"expirationDate,omitempty"`
	CredentialStatus interface{} `json:"credentialStatus,omitempty" validate:"omitempty,dive"`
	// This is where the subject's ID *may* be present
	CredentialSubject CredentialSubject `json:"credentialSubject" validate:"required"`
	CredentialSchema  *CredentialSchema `json:"credentialSchema,omitempty" validate:"omitempty,dive"`
	RefreshService    *RefreshService   `json:"refreshService,omitempty" validate:"omitempty,dive"`
	TermsOfUse        []TermsOfUse      `json:"termsOfUse,omitempty" validate:"omitempty,dive"`
	Evidence          []interface{}     `json:"evidence,omitempty" validate:"omitempty,dive"`
	// For embedded proof support
	// Proof is a digital signature over a credential https://www.w3.org/TR/2021/REC-vc-data-model-20211109/#proofs-signatures
	Proof *crypto.Proof `json:"proof,omitempty"`
}

VerifiableCredential is the verifiable credential model outlined in the vc-data-model spec https://www.w3.org/TR/2021/REC-vc-data-model-20211109/#basic-concepts

func (*VerifiableCredential) GetProof

func (v *VerifiableCredential) GetProof() *crypto.Proof

func (*VerifiableCredential) IsEmpty

func (v *VerifiableCredential) IsEmpty() bool

func (*VerifiableCredential) IsValid

func (v *VerifiableCredential) IsValid() error

func (*VerifiableCredential) SetProof

func (v *VerifiableCredential) SetProof(p *crypto.Proof)

type VerifiableCredentialBuilder

type VerifiableCredentialBuilder struct {
	*VerifiableCredential
	// contains filtered or unexported fields
}

VerifiableCredentialBuilder uses the builder pattern to construct a verifiable credential

func NewVerifiableCredentialBuilder

func NewVerifiableCredentialBuilder() VerifiableCredentialBuilder

NewVerifiableCredentialBuilder returns an initialized credential builder with some default fields populated

func (*VerifiableCredentialBuilder) AddContext

func (vcb *VerifiableCredentialBuilder) AddContext(context interface{}) error

func (*VerifiableCredentialBuilder) AddType

func (vcb *VerifiableCredentialBuilder) AddType(t interface{}) error

func (*VerifiableCredentialBuilder) Build

Build attempts to turn a builder into a valid verifiable credential, doing some object model validation. Schema validation and proof generation must be done separately.

func (*VerifiableCredentialBuilder) IsEmpty

func (vcb *VerifiableCredentialBuilder) IsEmpty() bool

func (*VerifiableCredentialBuilder) SetCredentialSchema

func (vcb *VerifiableCredentialBuilder) SetCredentialSchema(schema CredentialSchema) error

func (*VerifiableCredentialBuilder) SetCredentialStatus

func (vcb *VerifiableCredentialBuilder) SetCredentialStatus(status interface{}) error

func (*VerifiableCredentialBuilder) SetCredentialSubject

func (vcb *VerifiableCredentialBuilder) SetCredentialSubject(subject CredentialSubject) error

func (*VerifiableCredentialBuilder) SetEvidence

func (vcb *VerifiableCredentialBuilder) SetEvidence(evidence []interface{}) error

func (*VerifiableCredentialBuilder) SetExpirationDate

func (vcb *VerifiableCredentialBuilder) SetExpirationDate(dateTime string) error

func (*VerifiableCredentialBuilder) SetID

func (vcb *VerifiableCredentialBuilder) SetID(id string) error

func (*VerifiableCredentialBuilder) SetIssuanceDate

func (vcb *VerifiableCredentialBuilder) SetIssuanceDate(dateTime string) error

func (*VerifiableCredentialBuilder) SetIssuer

func (vcb *VerifiableCredentialBuilder) SetIssuer(issuer interface{}) error

func (*VerifiableCredentialBuilder) SetRefreshService

func (vcb *VerifiableCredentialBuilder) SetRefreshService(refreshService RefreshService) error

func (*VerifiableCredentialBuilder) SetTermsOfUse

func (vcb *VerifiableCredentialBuilder) SetTermsOfUse(terms []TermsOfUse) error

type VerifiablePresentation

type VerifiablePresentation struct {
	// Either a string or set of strings
	Context interface{} `json:"@context,omitempty"`
	ID      string      `json:"id,omitempty"`
	Holder  string      `json:"holder,omitempty"`
	Type    interface{} `json:"type" validate:"required"`
	// an optional field as a part of https://identity.foundation/presentation-exchange/#embed-targets
	PresentationSubmission interface{} `json:"presentation_submission,omitempty"`
	// Verifiable credential could be our object model, a JWT, or any other valid credential representation
	VerifiableCredential []interface{} `json:"verifiableCredential,omitempty"`
	Proof                *crypto.Proof `json:"proof,omitempty"`
}

VerifiablePresentation https://www.w3.org/TR/2021/REC-vc-data-model-20211109/#presentations-0

func (*VerifiablePresentation) GetProof

func (v *VerifiablePresentation) GetProof() *crypto.Proof

func (*VerifiablePresentation) IsEmpty

func (v *VerifiablePresentation) IsEmpty() bool

func (*VerifiablePresentation) IsValid

func (v *VerifiablePresentation) IsValid() error

func (*VerifiablePresentation) SetProof

func (v *VerifiablePresentation) SetProof(p *crypto.Proof)

type VerifiablePresentationBuilder

type VerifiablePresentationBuilder struct {
	*VerifiablePresentation
	// contains filtered or unexported fields
}

VerifiablePresentationBuilder uses the builder pattern to construct a verifiable presentation

func NewVerifiablePresentationBuilder

func NewVerifiablePresentationBuilder() VerifiablePresentationBuilder

NewVerifiablePresentationBuilder returns an initialized credential builder with some default fields populated

func (*VerifiablePresentationBuilder) AddContext

func (vpb *VerifiablePresentationBuilder) AddContext(context interface{}) error

func (*VerifiablePresentationBuilder) AddType

func (vpb *VerifiablePresentationBuilder) AddType(t interface{}) error

func (*VerifiablePresentationBuilder) AddVerifiableCredentials

func (vpb *VerifiablePresentationBuilder) AddVerifiableCredentials(creds ...interface{}) error

AddVerifiableCredentials appends the given credentials to the verifiable presentation. It does not check for duplicates.

func (*VerifiablePresentationBuilder) Build

Build attempts to turn a builder into a valid verifiable credential, doing some object model validation. Schema validation and proof generation must be done separately.

func (*VerifiablePresentationBuilder) IsEmpty

func (vpb *VerifiablePresentationBuilder) IsEmpty() bool

func (*VerifiablePresentationBuilder) SetHolder

func (vpb *VerifiablePresentationBuilder) SetHolder(holder string) error

func (*VerifiablePresentationBuilder) SetID

func (*VerifiablePresentationBuilder) SetPresentationSubmission

func (vpb *VerifiablePresentationBuilder) SetPresentationSubmission(ps interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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