Documentation ¶
Index ¶
- Constants
- func VCContextV1URI() ssi.URI
- func VerifiableCredentialTypeV1URI() ssi.URI
- func VerifiablePresentationTypeV1URI() ssi.URI
- type CredentialStatus
- type JSONWebSignature2020Proof
- type JWTSigner
- type Proof
- type VerifiableCredential
- func (vc VerifiableCredential) ContainsContext(context ssi.URI) bool
- func (vc VerifiableCredential) CredentialStatuses() ([]CredentialStatus, error)
- func (vc VerifiableCredential) Format() string
- func (vc VerifiableCredential) IsType(vcType ssi.URI) bool
- func (vc VerifiableCredential) JWT() jwt.Token
- func (vc VerifiableCredential) MarshalJSON() ([]byte, error)
- func (vc VerifiableCredential) Proofs() ([]Proof, error)
- func (vc VerifiableCredential) Raw() string
- func (vc VerifiableCredential) SubjectDID() (*did.DID, error)
- func (vc VerifiableCredential) UnmarshalCredentialStatus(target any) error
- func (vc VerifiableCredential) UnmarshalCredentialSubject(target interface{}) error
- func (vc *VerifiableCredential) UnmarshalJSON(b []byte) error
- func (vc VerifiableCredential) UnmarshalProofValue(target interface{}) error
- func (vc VerifiableCredential) ValidAt(t time.Time, skew time.Duration) bool
- type VerifiablePresentation
- func (vp VerifiablePresentation) ContainsContext(context ssi.URI) bool
- func (vp VerifiablePresentation) Format() string
- func (vp VerifiablePresentation) IsType(vcType ssi.URI) bool
- func (vp VerifiablePresentation) JWT() jwt.Token
- func (vp VerifiablePresentation) MarshalJSON() ([]byte, error)
- func (vp VerifiablePresentation) Proofs() ([]Proof, error)
- func (vp VerifiablePresentation) Raw() string
- func (vp *VerifiablePresentation) UnmarshalJSON(b []byte) error
- func (vp VerifiablePresentation) UnmarshalProofValue(target interface{}) error
Constants ¶
const ( // JSONLDCredentialProofFormat is the format for JSON-LD based credentials. JSONLDCredentialProofFormat string = "ldp_vc" // JWTCredentialProofFormat is the format for JWT based credentials. // Note: various specs have not yet decided on the exact const (jwt_vc or jwt_vc_json, etc), so this is subject to change. JWTCredentialProofFormat = "jwt_vc" )
const ( // JSONLDPresentationProofFormat is the format for JSON-LD based presentations. JSONLDPresentationProofFormat string = "ldp_vp" // JWTPresentationProofFormat is the format for JWT based presentations. // Note: various specs have not yet decided on the exact const (jwt_vp or jwt_vp_json, etc), so this is subject to change. JWTPresentationProofFormat = "jwt_vp" )
const VCContextV1 = "https://www.w3.org/2018/credentials/v1"
VCContextV1 is the context required for every credential and presentation
const VerifiableCredentialType = "VerifiableCredential"
VerifiableCredentialType is the default credential type required for every credential
const VerifiablePresentationType = "VerifiablePresentation"
VerifiablePresentationType is the default credential type required for every credential
Variables ¶
This section is empty.
Functions ¶
func VCContextV1URI ¶
VCContextV1URI returns 'https://www.w3.org/2018/credentials/v1' as URI
func VerifiableCredentialTypeV1URI ¶
VerifiableCredentialTypeV1URI returns VerifiableCredential as URI
func VerifiablePresentationTypeV1URI ¶ added in v0.3.0
VerifiablePresentationTypeV1URI returns VerifiablePresentation as URI
Types ¶
type CredentialStatus ¶
type CredentialStatus struct { ID ssi.URI `json:"id"` Type string `json:"type"` // contains filtered or unexported fields }
CredentialStatus contains the required fields ID and Type, and the raw data for unmarshalling into a custom type.
func (*CredentialStatus) Raw ¶ added in v0.10.0
func (cs *CredentialStatus) Raw() []byte
Raw returns a copy of the underlying credentialStatus data as set during UnmarshalJSON. This can be used to marshal the data into a custom status credential type.
func (*CredentialStatus) UnmarshalJSON ¶ added in v0.10.0
func (cs *CredentialStatus) UnmarshalJSON(input []byte) error
type JSONWebSignature2020Proof ¶
type JSONWebSignature2020Proof struct { Proof Challenge *string `json:"challenge,omitempty"` Jws string `json:"jws"` }
JSONWebSignature2020Proof is a VC proof with a signature according to JsonWebSignature2020
type Proof ¶
type Proof struct { // Type defines the specific proof type used. // For example, an Ed25519Signature2018 type indicates that the proof includes a digital signature produced by an ed25519 cryptographic key. Type ssi.ProofType `json:"type"` // ProofPurpose defines the intent for the proof, the reason why an entity created it. // Acts as a safeguard to prevent the proof from being misused for a purpose other than the one it was intended for. // For example, a proof can be used for purposes of authentication, for asserting control of a Verifiable Credential (assertionMethod), and several others. ProofPurpose string `json:"proofPurpose"` // VerificationMethod points to the ID that can be used to verify the proof, eg: a public key. VerificationMethod ssi.URI `json:"verificationMethod"` // Created notes when the proof was created using a iso8601 string Created time.Time `json:"created"` // Domain specifies the restricted domain of the proof Domain *string `json:"domain,omitempty"` }
Proof represents a credential/presentation proof as defined by the Linked Data Proofs 1.0 specification (https://w3c-ccg.github.io/ld-proofs/). The proof value must be implemented in a custom type since the specification doesn't define the json object for this. For example: a jws for detached JSON Web Signatures uses the 'jws' json field
type VerifiableCredential ¶
type VerifiableCredential struct { // Context defines the json-ld context to dereference the URIs Context []ssi.URI `json:"@context"` // ID is an unique identifier for the credential. It is optional ID *ssi.URI `json:"id,omitempty"` // Type holds multiple types for a credential. A credential must always have the 'VerifiableCredential' type. Type []ssi.URI `json:"type"` // Issuer refers to the party that issued the credential Issuer ssi.URI `json:"issuer"` // IssuanceDate is a rfc3339 formatted datetime. IssuanceDate time.Time `json:"issuanceDate"` // ExpirationDate is a rfc3339 formatted datetime. It is optional ExpirationDate *time.Time `json:"expirationDate,omitempty"` // CredentialStatus holds information on how the credential can be revoked. It must be extracted using the UnmarshalCredentialStatus method and a custom type. CredentialStatus []any `json:"credentialStatus,omitempty"` // CredentialSubject holds the actual data for the credential. It must be extracted using the UnmarshalCredentialSubject method and a custom type. CredentialSubject []interface{} `json:"credentialSubject"` // Proof contains the cryptographic proof(s). It must be extracted using the Proofs method or UnmarshalProofValue method for non-generic proof fields. Proof []interface{} `json:"proof,omitempty"` // contains filtered or unexported fields }
VerifiableCredential represents a credential as defined by the Verifiable Credentials Data Model 1.0 specification (https://www.w3.org/TR/vc-data-model/).
func CreateJWTVerifiableCredential ¶ added in v0.7.1
func CreateJWTVerifiableCredential(ctx context.Context, template VerifiableCredential, signer JWTSigner) (*VerifiableCredential, error)
CreateJWTVerifiableCredential creates a JWT Verifiable Credential from the given credential template. For signing the actual JWT it calls the given signer, which must return the created JWT in string format. Note: the signer is responsible for adding the right key claims (e.g. `kid`).
func ParseVerifiableCredential ¶ added in v0.7.0
func ParseVerifiableCredential(raw string) (*VerifiableCredential, error)
ParseVerifiableCredential parses a Verifiable Credential from a string, which can be either in JSON-LD or JWT format. JWTs are parsed according to https://www.w3.org/TR/2022/REC-vc-data-model-20220303/#jwt-decoding If the format is JWT, the parsed token can be retrieved using JWT(). Note that it does not do any signature checking.
func (VerifiableCredential) ContainsContext ¶
func (vc VerifiableCredential) ContainsContext(context ssi.URI) bool
ContainsContext returns true when a credential contains the requested context
func (VerifiableCredential) CredentialStatuses ¶ added in v0.10.0
func (vc VerifiableCredential) CredentialStatuses() ([]CredentialStatus, error)
CredentialStatuses returns VerifiableCredential.CredentialStatus marshalled into a CredentialStatus slice.
func (VerifiableCredential) Format ¶ added in v0.7.0
func (vc VerifiableCredential) Format() string
Format returns the format of the credential (e.g. jwt_vc or ldp_vc).
func (VerifiableCredential) IsType ¶
func (vc VerifiableCredential) IsType(vcType ssi.URI) bool
IsType returns true when a credential contains the requested type
func (VerifiableCredential) JWT ¶ added in v0.7.0
func (vc VerifiableCredential) JWT() jwt.Token
JWT returns the JWT token if the credential was parsed from a JWT.
func (VerifiableCredential) MarshalJSON ¶
func (vc VerifiableCredential) MarshalJSON() ([]byte, error)
func (VerifiableCredential) Proofs ¶
func (vc VerifiableCredential) Proofs() ([]Proof, error)
Proofs returns the basic proofs for this credential. For specific proof contents, UnmarshalProofValue must be used.
func (VerifiableCredential) Raw ¶ added in v0.7.0
func (vc VerifiableCredential) Raw() string
Raw returns the source of the credential as it was parsed.
func (VerifiableCredential) SubjectDID ¶ added in v0.6.5
func (vc VerifiableCredential) SubjectDID() (*did.DID, error)
SubjectDID returns the credential subject's ID as DID (credentialSubject.id). If there are multiple subjects, all subjects must have the same ID. It returns an error when: - there are no credential subjects, - the ID is not a valid DID - all subject IDs are empty - not all subjects have the same ID
func (VerifiableCredential) UnmarshalCredentialStatus ¶ added in v0.10.0
func (vc VerifiableCredential) UnmarshalCredentialStatus(target any) error
UnmarshalCredentialStatus unmarshalls the credentialStatus field to the provided target. Always pass a slice as target.
func (VerifiableCredential) UnmarshalCredentialSubject ¶
func (vc VerifiableCredential) UnmarshalCredentialSubject(target interface{}) error
UnmarshalCredentialSubject unmarshalls the credentialSubject to the given credentialSubject type. Always pass a slice as target.
func (*VerifiableCredential) UnmarshalJSON ¶
func (vc *VerifiableCredential) UnmarshalJSON(b []byte) error
func (VerifiableCredential) UnmarshalProofValue ¶
func (vc VerifiableCredential) UnmarshalProofValue(target interface{}) error
UnmarshalProofValue unmarshalls the proof to the given proof type. Always pass a slice as target since there could be multiple proofs. Each proof will result in a value, where null values may exist when the proof doesn't have the json member.
func (VerifiableCredential) ValidAt ¶ added in v0.10.0
ValidAt checks that t is within the validity window of the credential. The skew parameter allows compensating for some clock skew (set to 0 for strict validation). Return true if - t+skew >= IssuanceDate - t-skew <= ExpirationDate For any value that is missing, the evaluation defaults to true.
type VerifiablePresentation ¶ added in v0.3.0
type VerifiablePresentation struct { // Context defines the json-ld context to dereference the URIs Context []ssi.URI `json:"@context"` // ID is an unique identifier for the presentation. It is optional ID *ssi.URI `json:"id,omitempty"` // Type holds multiple types for a presentation. A presentation must always have the 'VerifiablePresentation' type. Type []ssi.URI `json:"type"` // Holder refers to the party that generated the presentation. It is optional Holder *ssi.URI `json:"holder,omitempty"` // VerifiableCredential may hold credentials that are proven with this presentation. VerifiableCredential []VerifiableCredential `json:"verifiableCredential,omitempty"` // Proof contains the cryptographic proof(s). It must be extracted using the Proofs method or UnmarshalProofValue method for non-generic proof fields. Proof []interface{} `json:"proof,omitempty"` // contains filtered or unexported fields }
VerifiablePresentation represents a presentation as defined by the Verifiable Credentials Data Model 1.0 specification (https://www.w3.org/TR/vc-data-model/).
func ParseVerifiablePresentation ¶ added in v0.7.0
func ParseVerifiablePresentation(raw string) (*VerifiablePresentation, error)
ParseVerifiablePresentation parses a Verifiable Presentation from a string, which can be either in JSON-LD or JWT format. If the format is JWT, the parsed token can be retrieved using JWT(). Note that it does not do any signature checking, or check that the signer of the VP is the subject of the VCs.
func (VerifiablePresentation) ContainsContext ¶ added in v0.3.0
func (vp VerifiablePresentation) ContainsContext(context ssi.URI) bool
ContainsContext returns true when a credential contains the requested context
func (VerifiablePresentation) Format ¶ added in v0.7.0
func (vp VerifiablePresentation) Format() string
Format returns the format of the presentation (e.g. jwt_vp or ldp_vp).
func (VerifiablePresentation) IsType ¶ added in v0.3.0
func (vp VerifiablePresentation) IsType(vcType ssi.URI) bool
IsType returns true when a presentation contains the requested type
func (VerifiablePresentation) JWT ¶ added in v0.7.0
func (vp VerifiablePresentation) JWT() jwt.Token
JWT returns the JWT token if the presentation was parsed from a JWT.
func (VerifiablePresentation) MarshalJSON ¶ added in v0.3.0
func (vp VerifiablePresentation) MarshalJSON() ([]byte, error)
func (VerifiablePresentation) Proofs ¶ added in v0.3.0
func (vp VerifiablePresentation) Proofs() ([]Proof, error)
Proofs returns the basic proofs for this presentation. For specific proof contents, UnmarshalProofValue must be used.
func (VerifiablePresentation) Raw ¶ added in v0.7.0
func (vp VerifiablePresentation) Raw() string
Raw returns the source of the presentation as it was parsed.
func (*VerifiablePresentation) UnmarshalJSON ¶ added in v0.3.0
func (vp *VerifiablePresentation) UnmarshalJSON(b []byte) error
func (VerifiablePresentation) UnmarshalProofValue ¶ added in v0.3.0
func (vp VerifiablePresentation) UnmarshalProofValue(target interface{}) error
UnmarshalProofValue unmarshalls the proof to the given proof type. Always pass a slice as target since there could be multiple proofs. Each proof will result in a value, where null values may exist when the proof doesn't have the json member.