formats

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package formats provides the interface and registry for credential metadata format generators

Index

Constants

This section is empty.

Variables

View Source
var DefaultRegistry = NewRegistry()

DefaultRegistry is the global format registry

Functions

func FormatJSON

func FormatJSON(data interface{}) ([]byte, error)

FormatJSON is a helper to marshal data as indented JSON

func List

func List() []string

List returns all format names from the default registry

func ParseFormats

func ParseFormats(formatStr string) ([]string, error)

ParseFormats parses formats using the default registry

func Register

func Register(g Generator)

Register adds a generator to the default registry

func ResolveAlias added in v0.12.0

func ResolveAlias(name string) string

ResolveAlias maps a user-facing format name to its internal registry name. If no alias is defined the input is returned unchanged.

Types

type ClaimDefinition

type ClaimDefinition struct {
	// Name is the claim identifier
	Name string

	// Path for nested claims (e.g., ["address", "street"])
	Path []string

	// DisplayName is the human-readable label
	DisplayName string

	// Type is the data type (string, number, boolean, date, datetime, image, object, array)
	Type string

	// Description of the claim
	Description string

	// Mandatory indicates if the claim is required
	Mandatory bool

	// SD indicates selective disclosure setting
	SD string

	// SvgId for SVG template reference
	SvgId string

	// Localizations per locale
	Localizations map[string]ClaimLocalization

	// FormatMappings maps format name to claim name override
	FormatMappings map[string]string

	// Children contains nested claim definitions for object and array types
	Children []ClaimDefinition
}

ClaimDefinition represents a format-agnostic claim

type ClaimLocalization

type ClaimLocalization struct {
	Label       string
	Description string
}

ClaimLocalization contains localized claim display

type DisplayLocalization

type DisplayLocalization struct {
	Name        string
	Description string
}

DisplayLocalization contains localized display properties

type Generator

type Generator interface {
	// Name returns the format identifier (e.g., "vctm", "mddl", "w3c")
	Name() string

	// Description returns a human-readable description of the format
	Description() string

	// FileExtension returns the output file extension (without dot)
	FileExtension() string

	// Generate produces the format-specific output
	Generate(parsed *ParsedCredential, cfg *config.Config) ([]byte, error)

	// DeriveIdentifier derives the format-specific ID from the parsed credential
	DeriveIdentifier(parsed *ParsedCredential, cfg *config.Config) string
}

Generator is the interface for format-specific generators

func Get

func Get(name string) (Generator, bool)

Get retrieves a generator from the default registry

type ImageRef

type ImageRef struct {
	Path         string
	AltText      string
	AbsolutePath string
}

ImageRef represents an image reference

type ParsedCredential

type ParsedCredential struct {
	// Core identifiers
	ID   string // Short identifier (derived from filename if not specified)
	Name string // Human-readable name

	// Format-specific identifiers (may be derived or explicit)
	VCT        string   // SD-JWT VC type identifier
	DocType    string   // mso_mdoc document type
	Namespace  string   // mso_mdoc namespace
	W3CTypes   []string // W3C VC type array
	W3CContext []string // W3C VC @context

	// Description
	Description string

	// Display properties
	BackgroundColor string
	TextColor       string
	LogoPath        string
	LogoAltText     string
	LogoAbsPath     string

	// SVG Template for rendering
	SVGTemplatePath      string
	SVGTemplateURI       string
	SVGTemplateIntegrity string

	// Source file info (for resolving relative paths)
	SourcePath string
	SourceDir  string

	// Generation options
	InlineImages bool

	// Localizations
	Localizations map[string]DisplayLocalization

	// Claims
	Claims []ClaimDefinition

	// Images
	Images []ImageRef

	// Format-specific overrides from front matter
	FormatOverrides map[string]map[string]interface{}

	// Claim mappings per format
	ClaimMappings map[string]map[string]string

	// Raw metadata from front matter
	Metadata map[string]interface{}

	// Formats is an optional per-credential format override (e.g. "sd-jwt,w3c").
	// When set, only the listed formats are generated for this credential.
	// When empty, all registered formats are generated (caller decides).
	Formats string
}

ParsedCredential represents format-agnostic parsed credential metadata

type Registry

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

Registry holds all registered format generators

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new format registry

func (*Registry) All

func (r *Registry) All() []Generator

All returns all registered generators

func (*Registry) Get

func (r *Registry) Get(name string) (Generator, bool)

Get retrieves a generator by name

func (*Registry) List

func (r *Registry) List() []string

List returns all registered format names

func (*Registry) ParseFormats

func (r *Registry) ParseFormats(formatStr string) ([]string, error)

ParseFormats parses a comma-separated format string into a list of format names "all" returns all registered formats

func (*Registry) Register

func (r *Registry) Register(g Generator)

Register adds a generator to the registry

Directories

Path Synopsis
Package mddl provides the MDDL format generator for mso_mdoc credentials (ISO 18013-5)
Package mddl provides the MDDL format generator for mso_mdoc credentials (ISO 18013-5)
Package vctmfmt provides the VCTM format generator for SD-JWT VC credentials
Package vctmfmt provides the VCTM format generator for SD-JWT VC credentials
Package w3c provides the W3C VC format generator for W3C VCDM 2.0 credentials
Package w3c provides the W3C VC format generator for W3C VCDM 2.0 credentials

Jump to

Keyboard shortcuts

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