verifiable

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package verifiable provides functionality managing verifiable credentials.

Index

Constants

View Source
const (
	Format             = "application/n-quads"
	AlgorithmURDNA2015 = "URDNA2015"
)
View Source
const (
	// LocationTypeCellID represents the cell ID location type.
	LocationTypeCellID = "cellId"
	// LocationTypeH3Cell represents the latitude/longitude location type.
	LocationTypeH3Cell = "h3Cell"
	// LocationTypeGatewayID represents the gateway ID location type.
	LocationTypeGatewayID = "gatewayId"
)

Variables

This section is empty.

Functions

func Canonicalize

func Canonicalize(data any, ldProc *ld.JsonLdProcessor, ldOptions *ld.JsonLdOptions) ([]byte, error)

Canonicalize canonicalizes the data using the given processor and options.

func DefaultDocumentLoader

func DefaultDocumentLoader(localSchemaURL, localSchema string) (ld.DocumentLoader, error)

func DefaultLdOptions

func DefaultLdOptions(localSchemaURL, localSchema string) (*ld.JsonLdOptions, error)

DefaultLdOptions returns the default JSON-LD options.

func EncodeList

func EncodeList(data []byte) (string, error)

EncodeList compresses and base64 encodes a list of bytes.

func HashData

func HashData(transformedData, proofConfig []byte) ([]byte, error)

HashData hashes the canonicalized data.

func MustEncodeList

func MustEncodeList(data []byte) string

MustEncodeList compresses and base64 encodes a list of bytes.

Types

type BitstringStatusListSubject

type BitstringStatusListSubject struct {
	ID            string `json:"id,omitempty"`
	Type          string `json:"type,omitempty"`
	StatusPurpose string `json:"statusPurpose,omitempty"`
	EncodedList   string `json:"encodedList,omitempty"`
}

BitstringStatusListSubject represents the subject of the bitstring status list verifiable credential.

type CellID added in v0.0.6

type CellID struct {
	CellID string `json:"cellId"`
}

CellID represents a cell ID location value.

type Config

type Config struct {
	PrivateKey        []byte
	ChainID           *big.Int
	VehicleNFTAddress common.Address
	BaseStatusURL     *url.URL
	BaseKeyURL        *url.URL
	BaseVocabURL      *url.URL
	BaseJSONLDURL     *url.URL
}

Config contains the configuration for a Issuer.

type Credential

type Credential struct {
	Context           []any            `json:"@context,omitempty"`
	ID                string           `json:"id,omitempty"`
	Type              []string         `json:"type,omitempty"`
	Issuer            string           `json:"issuer,omitempty"`
	ValidFrom         string           `json:"validFrom,omitempty"`
	ValidTo           string           `json:"validTo,omitempty"`
	CredentialSubject json.RawMessage  `json:"credentialSubject,omitempty"`
	CredentialStatus  CredentialStatus `json:"credentialStatus,omitempty"`
	Proof             Proof            `json:"proof,omitempty"`
}

Credential represents a verifiable credential.

type CredentialStatus

type CredentialStatus struct {
	ID                   string `json:"id,omitempty"`
	Type                 string `json:"type,omitempty"`
	StatusPurpose        string `json:"statusPurpose,omitempty"`
	StatusListIndex      uint   `json:"statusListIndex"`
	StatusListCredential string `json:"statusListCredential,omitempty"`
}

CredentialStatus represents the status of the verifiable credential.

type GatewayID added in v0.0.6

type GatewayID struct {
	GatewayID string `json:"gatewayId"`
}

GatewayID represents a gateway ID location value.

type H3Cell added in v0.0.6

type H3Cell struct {
	CellID string `json:"h3CellId"`
}

H3Cell represents a latitude/longitude location value.

type Issuer

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

Issuer issues various Verifiable Credentials.

func NewIssuer

func NewIssuer(config Config) (*Issuer, error)

NewIssuer creates a new instance of Issuer.

func (*Issuer) CreateBitstringStatusListVC

func (i *Issuer) CreateBitstringStatusListVC(tokenID uint32, revoked bool) ([]byte, error)

func (*Issuer) CreateJSONLDDoc added in v0.0.4

func (i *Issuer) CreateJSONLDDoc() ([]byte, error)

CreateJSONLDDoc creates a JSON-LD document for all VC types.

func (*Issuer) CreateKeyControlDoc added in v0.0.3

func (i *Issuer) CreateKeyControlDoc() ([]byte, error)

CreateKeyControlDoc creates a key control document for the issuer. This document is used to get the public key of the issuer.

func (*Issuer) CreatePOMVC added in v0.0.6

func (i *Issuer) CreatePOMVC(subject POMSubject) ([]byte, error)

func (*Issuer) CreateVINVC

func (i *Issuer) CreateVINVC(subject VINSubject, expirationDate time.Time) ([]byte, error)

CreateVINVC creates a verifiable credential for a vehicle identification number and token ID.

func (*Issuer) CreateVocabWebpage added in v0.0.4

func (i *Issuer) CreateVocabWebpage() ([]byte, error)

CreateVocabWebpage creates a webpage for the vocabulary.

type Location added in v0.0.6

type Location struct {
	LocationType  string        `json:"locationType"`
	LocationValue LocationValue `json:"locationValue"`
	Timestamp     time.Time     `json:"timestamp"`
}

Location represents a single location event with type, value, and timestamp.

func (*Location) UnmarshalJSON added in v0.0.6

func (l *Location) UnmarshalJSON(data []byte) error

UnmarshalJSON custom unmarshals a Location to handle the polymorphic LocationValue.

type LocationValue added in v0.0.6

type LocationValue interface {
	// contains filtered or unexported methods
}

LocationValue represents a generic interface for location values.

type MultiKey added in v0.0.3

type MultiKey struct {
	ID                 string `json:"id,omitempty"`
	Type               string `json:"type,omitempty"`
	Controller         string `json:"controller,omitempty"`
	PublicKeyMultibase string `json:"publicKeyMultibase,omitempty"`
}

type POMSubject added in v0.0.6

type POMSubject struct {
	ID string `json:"id,omitempty"`
	// VehicleTokenID is the token ID of the vehicle NFT.
	VehicleTokenID uint32 `json:"vehicleTokenId,omitempty"`
	// VehicleContractAddress is the address of the vehicle contract.
	VehicleContractAddress string `json:"vehicleContractAddress,omitempty"`
	// RecordedBy is the entity that recorded the event.
	RecordedBy string     `json:"recordedBy,omitempty"`
	Locations  []Location `json:"locations"`
}

POMSubject represents the subject of the Proof of Movement VC.

type Proof

type Proof struct {
	ProofOptions
	ProofValue string `json:"proofValue,omitempty"`
}

Proof contains the signed proof value and options.

func CreateProof

func CreateProof(unsecuredDocument Credential, options ProofOptions, privateKey *ecdsa.PrivateKey, ldProcessor *ld.JsonLdProcessor, ldOptions *ld.JsonLdOptions) (Proof, error)

CreateProof creates a proof for a document using ecdsa-rdfc-2019.

type ProofOptions

type ProofOptions struct {
	Type               string `json:"type,omitempty"`
	Cryptosuite        string `json:"cryptosuite,omitempty"`
	VerificationMethod string `json:"verificationMethod,omitempty"`
	Created            string `json:"created,omitempty"`
	ProofPurpose       string `json:"proofPurpose,omitempty"`
}

ProofOptions contains the options for generating a proof.

type ProofOptionsWithContext

type ProofOptionsWithContext struct {
	Context []any `json:"@context,omitempty"`
	ProofOptions
}

proofOptionsWithContext contains the proof options with the context. this is used for canonicalization.

type VINSubject

type VINSubject struct {
	ID string `json:"id,omitempty"`
	// VehicleTokenID is the token ID of the vehicle NFT.
	VehicleTokenID uint32 `json:"vehicleTokenId,omitempty"`
	// VehicleContractAddress is the address of the vehicle contract.
	VehicleContractAddress string `json:"vehicleContractAddress,omitempty"`
	// VehicleIdentificationNumber is the VIN of the vehicle.
	VehicleIdentificationNumber string `json:"vehicleIdentificationNumber,omitempty"`
	// RecordedBy is the entity that recoreded the VIN.
	RecordedBy string `json:"recordedBy,omitempty"`
	// RecorededAt is the time the VIN was recoreded.
	RecordedAt time.Time `json:"recordedAt,omitempty"`
	// CountryCode that VIN belongs to.
	CountryCode string `json:"countryCode,omitempty"`
}

VINSubject represents the subject of the VIN verifiable credential.

type VerificationControlDocument added in v0.0.3

type VerificationControlDocument struct {
	Context              []string   `json:"@context,omitempty"`
	ID                   string     `json:"id,omitempty"`
	VerificationMethod   []MultiKey `json:"verificationMethod,omitempty"`
	Authentication       []string   `json:"authentication,omitempty"`
	AssertionMethod      []string   `json:"assertionMethod,omitempty"`
	CapabilityDelegation []string   `json:"capabilityDelegation,omitempty"`
	CapabilityInvocation []string   `json:"capabilityInvocation,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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