tbdex

package
v0.9.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DigestJSON added in v0.7.0

func DigestJSON(payload any) ([]byte, error)

DigestJSON generates a SHA-256 hash of the canonicalized input payload.

func Sign

func Sign(digester Digester, bearerDID did.BearerDID) (string, error)

Sign signs a resource with a given bearerDID

func Validate

func Validate(dataType DataType, input []byte, opts ...ValidateOption) error

Validate validates the input provided in two phases:

  1. Validate the general structure of the resource or message based on the Type.
  2. Validate the specific structure of the resource or message based on the Kind.

A Kind can be optionally specified in order to fail early if the input's Kind does match what was provided. This is useful when the Kind is known ahead of time. If the Kind is not specified, validation will proceed to phase 2 using metadata.kind.

Note

Kind-specific schemas are lazily loaded the first time they are needed and then cached for future use.

func VerifyDigest added in v0.7.0

func VerifyDigest(expectedDigest string, payload any) error

VerifyDigest verifies that the digest of a given payload matches the expected digest.

func VerifySignature added in v0.7.0

func VerifySignature(digester Digester, signature string) (*jws.Decoded, error)

VerifySignature verifies the given signature and the signed payload

Types

type DataType

type DataType string

DataType represents the type of data being validated e.g. resource or message

const (
	TypeResource DataType = "resource" // TypeResource represents tbdex resource
	TypeMessage  DataType = "message"  // TypeMessage represents tbdex message

)

type Digester

type Digester interface {
	Digest() ([]byte, error)
}

Digester is an interface for resources that can be digested

type MessageMetadata added in v0.7.0

type MessageMetadata struct {
	From       string `json:"from"`
	To         string `json:"to"`
	Kind       string `json:"kind"`
	ID         string `json:"id"`
	ExchangeID string `json:"exchangeId"`
	CreatedAt  string `json:"createdAt"`
	ExternalID string `json:"externalId,omitempty"`
	Protocol   string `json:"protocol"`
}

MessageMetadata represents the metadata of a message e.g. RFQ, quote etc.

type ResourceMetadata

type ResourceMetadata struct {
	From      string `json:"from"`
	Kind      string `json:"kind"`
	ID        string `json:"id"`
	CreatedAt string `json:"createdAt"`
	UpdatedAt string `json:"updatedAt,omitempty"`
	Protocol  string `json:"protocol"`
}

ResourceMetadata represents the metadata of a resource e.g. offering, balance etc.

type ValidateOption

type ValidateOption func(*validateOptions)

ValidateOption is a function that sets an option for the Validate function

func WithKind

func WithKind(kind string) ValidateOption

WithKind sets the kind option for the Validate function

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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