credential

package
v0.0.0-...-dec6028 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VerifiableCredentialsLinkedDataContext               string = "https://www.w3.org/ns/credentials/v2"
	VerifiableCredentialsUndefinedTermsLinkedDataContext string = "https://www.w3.org/ns/credentials/undefined-terms/v2"
	VerifiableCredentialType                             string = "VerifiableCredential"
	VerifiablePresentationType                           string = "VerifiablePresentation"
	EnvelopedVerifiableCredentialType                    string = "EnvelopedVerifiableCredential"
	EnvelopedVerifiablePresentationType                  string = "EnvelopedVerifiablePresentation"

	VerifiableCredentialJSONSchemaType string = "JsonSchema"
	VerifiableCredentialIDProperty     string = "id"

	VCContentType string = "vc"
	VPContentType string = "vp"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type IssuerHolder

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

IssuerHolder represents the issuer of a Verifiable Credential or holder of a Verifiable Presentation, which can be either a URL string or an object containing an ID property

func NewIssuerHolderFromObject

func NewIssuerHolderFromObject(id string, object map[string]any) *IssuerHolder

NewIssuerHolderFromObject creates an IssuerHolder from an object with an `id` field

func NewIssuerHolderFromString

func NewIssuerHolderFromString(id string) *IssuerHolder

NewIssuerHolderFromString creates an IssuerHolder from a string (URL or ID)

func (*IssuerHolder) Get

func (i *IssuerHolder) Get(property string) any

Get returns the value of a property in the issuer/holder object, or nil if the issuer/holder is a string or the property doesn't exist

func (*IssuerHolder) ID

func (i *IssuerHolder) ID() string

ID returns the ID of the issuer

func (*IssuerHolder) IsEmpty

func (i *IssuerHolder) IsEmpty() bool

IsEmpty returns true if the issuer is empty

func (*IssuerHolder) IsObject

func (i *IssuerHolder) IsObject() bool

IsObject returns true if the issuer is an object, false if it's a string

func (*IssuerHolder) MarshalJSON

func (i *IssuerHolder) MarshalJSON() ([]byte, error)

MarshalJSON implements custom marshaling for IssuerHolder

func (*IssuerHolder) UnmarshalJSON

func (i *IssuerHolder) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom unmarshaling for IssuerHolder

type Schema

type Schema struct {
	ID        string `json:"id" validate:"required"`
	Type      string `json:"type" validate:"required"`
	DigestSRI string `json:"digestSRI,omitempty"`
}

type Subject

type Subject map[string]any

Subject represents the subject of a Verifiable Credential

func (Subject) GetID

func (s Subject) GetID() string

type VerifiableCredential

type VerifiableCredential struct {
	Context util.SingleOrArray[string] `json:"@context,omitempty" validate:"required"`
	Type    util.SingleOrArray[string] `json:"type,omitempty" validate:"required"`
	ID      string                     `json:"id,omitempty"`
	// either a URI or an object containing an `id` property.
	Issuer *IssuerHolder `json:"issuer,omitempty" validate:"required"`
	// https://www.w3.org/TR/xmlschema11-2/#dateTimes
	ValidFrom  string `json:"validFrom,omitempty" validate:"required"`
	ValidUntil string `json:"validUntil,omitempty"`
	// This is where the subject's ID *may* be present
	CredentialSubject Subject                    `json:"credentialSubject,omitempty"`
	CredentialSchema  util.SingleOrArray[Schema] `json:"credentialSchema,omitempty"`
	CredentialStatus  util.SingleOrArray[any]    `json:"credentialStatus,omitempty"`
	TermsOfUse        util.SingleOrArray[any]    `json:"termsOfUse,omitempty"`
	Evidence          util.SingleOrArray[any]    `json:"evidence,omitempty"`
}

VerifiableCredential is the verifiable credential model outlined in the vc-data-model spec https://www.w3.org/TR/vc-data-model-2.0/#verifiable-credentials

func (*VerifiableCredential) IsEmpty

func (vc *VerifiableCredential) IsEmpty() bool

func (*VerifiableCredential) IsValid

func (vc *VerifiableCredential) IsValid() error

func (*VerifiableCredential) IssuerID

func (vc *VerifiableCredential) IssuerID() string

func (*VerifiableCredential) ToMap

func (vc *VerifiableCredential) ToMap() (map[string]any, error)

ToMap converts the VerifiableCredential to a map[string]any

type VerifiablePresentation

type VerifiablePresentation struct {
	Context              util.SingleOrArray[string] `json:"@context,omitempty" validate:"required"`
	Type                 util.SingleOrArray[string] `json:"type,omitempty" validate:"required"`
	ID                   string                     `json:"id,omitempty"`
	Holder               *IssuerHolder              `json:"holder,omitempty"`
	VerifiableCredential []VerifiableCredential     `json:"verifiableCredential,omitempty"`
}

VerifiablePresentation https://www.w3.org/TR/vc-data-model-2.0/#verifiable-presentations

func (*VerifiablePresentation) IsEmpty

func (vp *VerifiablePresentation) IsEmpty() bool

func (*VerifiablePresentation) IsValid

func (vp *VerifiablePresentation) IsValid() error

func (*VerifiablePresentation) ToMap

func (vp *VerifiablePresentation) ToMap() (map[string]any, error)

ToMap converts the VerifiablePresentation to a map[string]any

Jump to

Keyboard shortcuts

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