jsonld

package
v6.2.12 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const JSONLDExample = `` /* 855-byte string literal not displayed */

JSONLDExample is a JSON-LD document example with a custom nested context covering all different supported term types.

View Source
const JSONLdBase = ""

JSONLdBase is the base URL used for IRIs that are unknown when expanding a JSON-LD document.

View Source
const Jws2020Context = "https://w3c-ccg.github.io/lds-jws2020/contexts/lds-jws2020-v1.json"

Jws2020Context contains the JsonWebToken2020 Proof type context

View Source
const SchemaOrgContext = "https://schema.org"

SchemaOrgContext contains the schema.org context url

View Source
const TestCredential = `` /* 558-byte string literal not displayed */

TestCredential contains a valid credential of the Humancredential type

View Source
const TestOrganizationCredential = `` /* 798-byte string literal not displayed */

TestOrganizationCredential is an example of a NutsOrganizationCredential without Proof

View Source
const W3cStatusList2021Context = "https://w3id.org/vc/status-list/2021/v1"

W3cStatusList2021Context contains the StatusList2021 related context

View Source
const W3cVcContext = "https://www.w3.org/2018/credentials/v1"

W3cVcContext contains the w3c VerifiableCredential type context

Variables

View Source
var (
	// OrganizationNamePath contains the JSON-LD search path for finding an organization name
	OrganizationNamePath = NewPath("https://www.w3.org/2018/credentials#credentialSubject", "http://schema.org/organization", "http://schema.org/legalname")
	// OrganizationCityPath contains the JSON-LD search path for finding an organization city
	OrganizationCityPath = NewPath("https://www.w3.org/2018/credentials#credentialSubject", "http://schema.org/organization", "http://schema.org/city")
	// CredentialSubjectPath contains the JSON-LD search path for the credential subject ID
	CredentialSubjectPath = NewPath("https://www.w3.org/2018/credentials#credentialSubject")
	// CredentialIssuerPath contains the JSON-LD search path for the credential issuer
	CredentialIssuerPath = NewPath("https://www.w3.org/2018/credentials#issuer")
)
View Source
var ContextURLNotAllowedErr = errors.New("context not on the remoteallowlist")
View Source
var ErrInvalidValue = errors.New("invalid value")

ErrInvalidValue is returned when an invalid value is parsed

Functions

func AddContext

func AddContext(context interface{}, newContext ssi.URI) []interface{}

AddContext adds the context to the @context array. It makes sure no duplicates will exist.

func AllFieldsDefined

func AllFieldsDefined(DocumentLoader ld.DocumentLoader, inputJSON []byte) error

AllFieldsDefined tests whether all fields are defined in the JSON-LD context(s) of the input.

func DefaultAllowList

func DefaultAllowList() []string

DefaultAllowList returns the default allow list for external contexts

func FlagSet

func FlagSet() *pflag.FlagSet

FlagSet contains flags relevant for JSON-LD

func JWS2020ContextV1URI

func JWS2020ContextV1URI() ssi.URI

JWS2020ContextV1URI returns JWS2020ContextV1 as a URI

func NewContextLoader

func NewContextLoader(allowUnlistedExternalCalls bool, contexts ContextsConfig) (ld.DocumentLoader, error)

NewContextLoader creates a new JSON-LD context loader with the embedded FS as first loader. It loads the most used context from the embedded FS. This ensures the contents cannot be altered. If allowExternalCalls is set to true, it also loads external context from the internet.

func NewEmbeddedFSDocumentLoader

func NewEmbeddedFSDocumentLoader(fs embed.FS, nextLoader ld.DocumentLoader) ld.DocumentLoader

NewEmbeddedFSDocumentLoader creates a new embeddedFSDocumentLoader for an embedded filesystem.

func NewFilteredLoader

func NewFilteredLoader(allowedURLs []string, nextLoader ld.DocumentLoader) ld.DocumentLoader

NewFilteredLoader accepts a list of allowed urls and a nextLoader and creates a new filteredDocumentLoader

func NewMappedDocumentLoader

func NewMappedDocumentLoader(mapping map[string]string, nextLoader ld.DocumentLoader) ld.DocumentLoader

NewMappedDocumentLoader rewrites document request using a mapping and calls the nextLoader

func TestVC

func TestVC() vc.VerifiableCredential

TestVC returns an instance of the TestCredential

Types

type BoolScalar

type BoolScalar bool

BoolScalar is the boolean version of a Scalar

func (BoolScalar) String

func (bs BoolScalar) String() string

func (BoolScalar) Value

func (bs BoolScalar) Value() interface{}

type Config

type Config struct {
	// Contexts contains the configuration for the JSON-LD Contexts
	Contexts ContextsConfig `koanf:"contexts"`
}

Config holds the config for the vcr engine

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a fresh Config filled with default values

type ContextsConfig

type ContextsConfig struct {
	// RemoteAllowList A list with urls as string which are allowed to request
	RemoteAllowList []string `koanf:"remoteallowlist"`
	// LocalFileMapping contains a list of context URLs mapped to a local file
	LocalFileMapping map[string]string `koanf:"localmapping"`
}

ContextsConfig contains config for json-ld document loader

func DefaultContextConfig

func DefaultContextConfig() ContextsConfig

DefaultContextConfig returns the default list of allowed external resources and a mapping to embedded contexts

type Document

type Document []interface{}

Document represents a JSON-LD document in expanded form. The expanded form is ideal for traversing and finding values

func (Document) ValueAt

func (e Document) ValueAt(path Path) []Scalar

ValueAt returns the value found when traversing the given path It looks at the @id, @value and @list field

type Float64Scalar

type Float64Scalar float64

Float64Scalar is the float64 version of a Scalar

func (Float64Scalar) String

func (fs Float64Scalar) String() string

func (Float64Scalar) Value

func (fs Float64Scalar) Value() interface{}

type JSONLD

type JSONLD interface {
	// DocumentLoader returns the JSON-LD DocumentLoader
	DocumentLoader() ld.DocumentLoader
}

JSONLD defines the interface of a JSON utilities engine. It allows sharing instances of utils over engines.

func NewJSONLDInstance

func NewJSONLDInstance() JSONLD

NewJSONLDInstance creates a new instance of the jsonld struct which implements the JSONLD interface

func NewTestJSONLDManager

func NewTestJSONLDManager(t testing.TB) JSONLD

NewTestJSONLDManager creates a new test context manager which contains extra test contexts

type LDUtil

type LDUtil struct {
	LDDocumentLoader ld.DocumentLoader
}

LDUtil package a set of often used JSON-LD operations for re-usability.

func (LDUtil) Canonicalize

func (util LDUtil) Canonicalize(input interface{}) (result interface{}, err error)

Canonicalize canonicalizes the json-ld input according to the URDNA2015 [RDF-DATASET-NORMALIZATION] algorithm.

type Path

type Path []string

Path is used to traverse an expanded JSON-LD document Its elements are IRIs

func NewPath

func NewPath(IRIs ...string) Path

NewPath creates a Path

func (Path) Head

func (p Path) Head() string

Head returns the first IRI of the list or ""

func (Path) IsEmpty

func (p Path) IsEmpty() bool

IsEmpty returns true of no IRIs are in the list

func (Path) Tail

func (p Path) Tail() Path

Tail returns the last IRIs of the list or nil

type Reader

type Reader struct {
	// DocumentLoader the document loader that resolves JSON-LD context urls
	DocumentLoader ld.DocumentLoader
	// AllowUndefinedProperties specifies whether the reader should return an error when it occurs a property that is not defined in the JSON-LD context.
	AllowUndefinedProperties bool
}

Reader adds Document reader functions for a JSON-LD context.

func (Reader) Read

func (r Reader) Read(source interface{}) (Document, error)

Read transforms a struct to a Document (expanded JSON-LD)

func (Reader) ReadBytes

func (r Reader) ReadBytes(asJSON []byte) (Document, error)

ReadBytes transforms a JSON-LD string to a Document (expanded JSON-LD)

type Scalar

type Scalar interface {
	fmt.Stringer
	// Value returns the underlying value (string, float, true or false)
	Value() interface{}
}

Scalar represents a JSON-LD scalar (string, number, true or false)

func MustParseScalar

func MustParseScalar(value interface{}) Scalar

MustParseScalar returns a Scalar based on an interface value. It panics when the value is not supported.

func ParseScalar

func ParseScalar(value interface{}) (Scalar, error)

ParseScalar returns a Scalar based on an interface value. It returns ErrInvalidValue for unsupported values.

type StringScalar

type StringScalar string

StringScalar is the string version of a Scalar

func (StringScalar) String

func (ss StringScalar) String() string

func (StringScalar) Value

func (ss StringScalar) Value() interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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