credential

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VerifiableCredentialsLinkedDataContext string = "https://www.w3.org/2018/credentials/v1"
	VerifiableCredentialType               string = "VerifiableCredential"
	VerifiableCredentialIDProperty         string = "id"
	// VerifiableCredentialJSONSchemaProperty as defined by https://www.w3.org/TR/vc-json-schema/#jsonschemacredential
	VerifiableCredentialJSONSchemaProperty string = "jsonSchema"
	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"`
	DigestSRI string `json:"digestSRI,omitempty"`
}

type CredentialSubject

type CredentialSubject map[string]any

func (CredentialSubject) GetID

func (cs CredentialSubject) GetID() string

func (CredentialSubject) GetJSONSchema

func (cs CredentialSubject) GetJSONSchema() map[string]any

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 any    `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 any `json:"type" validate:"required"`
	// either a URI or an object containing an `id` property.
	Issuer any `json:"issuer,omitempty" validate:"required"`
	// https://www.w3.org/TR/xmlschema11-2/#dateTimes
	IssuanceDate     string `json:"issuanceDate,omitempty" validate:"required"`
	ExpirationDate   string `json:"expirationDate,omitempty"`
	CredentialStatus any    `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          []any             `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) IssuerID

func (v *VerifiableCredential) IssuerID() string

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 any) error

func (*VerifiableCredentialBuilder) AddType

func (vcb *VerifiableCredentialBuilder) AddType(t any) 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 any) error

func (*VerifiableCredentialBuilder) SetCredentialSubject

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

func (*VerifiableCredentialBuilder) SetEvidence

func (vcb *VerifiableCredentialBuilder) SetEvidence(evidence []any) 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 any) 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 any    `json:"@context,omitempty"`
	ID      string `json:"id,omitempty"`
	Holder  string `json:"holder,omitempty"`
	Type    any    `json:"type" validate:"required"`
	// an optional field as a part of https://identity.foundation/presentation-exchange/#embed-targets
	PresentationSubmission any `json:"presentation_submission,omitempty"`
	// Verifiable credential could be our object model, a JWT, or any other valid credential representation
	VerifiableCredential []any         `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 any) error

func (*VerifiablePresentationBuilder) AddType

func (vpb *VerifiablePresentationBuilder) AddType(t any) error

func (*VerifiablePresentationBuilder) AddVerifiableCredentials

func (vpb *VerifiablePresentationBuilder) AddVerifiableCredentials(creds ...any) 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 any) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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