merklize

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: AGPL-3.0 Imports: 16 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIncorrectType = errors.New("incorrect type")
View Source
var ErrorContextTypeIsEmpty = errors.New("ctxType is empty")

ErrorContextTypeIsEmpty is returned when context type tp resolve is empty

View Source
var ErrorFieldIsEmpty = errors.New("fieldPath is empty")

ErrorFieldIsEmpty is returned when field path to resolve is empty

Functions

func AddEntriesToMerkleTree

func AddEntriesToMerkleTree(ctx context.Context, mt mtAppender,
	entries []RDFEntry) error

func SetHasher

func SetHasher(h Hasher)

SetHasher changes default hasher

Types

type Hasher

type Hasher interface {
	Hash(inpBI []*big.Int) (*big.Int, error)
	HashBytes(msg []byte) (*big.Int, error)
	Prime() *big.Int
}

Hasher is an interface to hash data

type MerkleTree

type MerkleTree interface {
	Add(context.Context, *big.Int, *big.Int) error
	GenerateProof(context.Context, *big.Int) (*merkletree.Proof, error)
	Root() *merkletree.Hash
}

MerkleTree is merkle tree structure

func MerkleTreeSQLAdapter

func MerkleTreeSQLAdapter(mt *merkletree.MerkleTree) MerkleTree

MerkleTreeSQLAdapter is merkle tree sql adapter

type MerklizeOption

type MerklizeOption func(m *Merklizer)

MerklizeOption is options for merklizer

func WithHasher

func WithHasher(h Hasher) MerklizeOption

WithHasher sets Hasher option

func WithMerkleTree

func WithMerkleTree(mt MerkleTree) MerklizeOption

WithMerkleTree sets MerkleTree option

type Merklizer

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

Merklizer is a struct to work with json-ld doc merklization

func MerklizeJSONLD

func MerklizeJSONLD(ctx context.Context, in io.Reader,
	opts ...MerklizeOption) (*Merklizer, error)

MerklizeJSONLD takes a JSON-LD document, parses it and returns a Merklizer

func (*Merklizer) MkValue

func (m *Merklizer) MkValue(val any) (Value, error)

func (*Merklizer) Proof

func (m *Merklizer) Proof(ctx context.Context,
	path Path) (*merkletree.Proof, Value, error)

Proof generate and return Proof and Value by the given Path. If the path is not found, it returns nil as value interface.

func (*Merklizer) RawValue

func (m *Merklizer) RawValue(path Path) (any, error)

func (*Merklizer) ResolveDocPath

func (m *Merklizer) ResolveDocPath(path string) (Path, error)

func (*Merklizer) Root

func (m *Merklizer) Root() *merkletree.Hash

type Options

type Options struct {
	Hasher Hasher
}

Options type allows to change hashing algorithm and create Path and RDFEntry instances with hasher different from default one.

func (Options) NewPath

func (o Options) NewPath(parts ...interface{}) (Path, error)

func (Options) NewRDFEntry

func (o Options) NewRDFEntry(key Path, value interface{}) (RDFEntry, error)

func (Options) PathFromContext

func (o Options) PathFromContext(ctxBytes []byte, path string) (Path, error)

type Path

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

func NewFieldPathFromContext

func NewFieldPathFromContext(ctxBytes []byte, ctxType, fieldPath string) (Path, error)

NewFieldPathFromContext resolves field path without type path prefix

func NewPath

func NewPath(parts ...interface{}) (Path, error)

func NewPathFromContext

func NewPathFromContext(ctxBytes []byte, path string) (Path, error)

NewPathFromContext parses context and do its best to generate full Path from shortcut line field1.field2.field3...

func NewPathFromDocument

func NewPathFromDocument(docBytes []byte, path string) (Path, error)

func (*Path) Append

func (p *Path) Append(parts ...interface{}) error

func (*Path) MtEntry

func (p *Path) MtEntry() (*big.Int, error)

func (*Path) Parts

func (p *Path) Parts() []interface{}

func (*Path) Prepend

func (p *Path) Prepend(parts ...interface{}) error

Prepend path's parts from the beginning

type PoseidonHasher

type PoseidonHasher struct{}

PoseidonHasher is an applier of poseidon hash algorithm

func (PoseidonHasher) Hash

func (p PoseidonHasher) Hash(inpBI []*big.Int) (*big.Int, error)

Hash returns poseidon hash on big int params

func (PoseidonHasher) HashBytes

func (p PoseidonHasher) HashBytes(msg []byte) (*big.Int, error)

HashBytes returns poseidon hash on bytes

func (PoseidonHasher) Prime

func (p PoseidonHasher) Prime() *big.Int

Prime returns Q constant

type RDFEntry

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

func EntriesFromRDF

func EntriesFromRDF(ds *ld.RDFDataset) ([]RDFEntry, error)

EntriesFromRDF creates entries from RDF dataset suitable to add to merkle tree

func EntriesFromRDFWithHasher

func EntriesFromRDFWithHasher(ds *ld.RDFDataset,
	hasher Hasher) ([]RDFEntry, error)

EntriesFromRDFWithHasher creates entries from RDF dataset suitable to add to with a provided Hasher merkle tree

func NewRDFEntry

func NewRDFEntry(key Path, value any) (RDFEntry, error)

func (RDFEntry) KeyMtEntry

func (e RDFEntry) KeyMtEntry() (*big.Int, error)

func (RDFEntry) KeyValueMtEntries

func (e RDFEntry) KeyValueMtEntries() (
	keyMtEntry *big.Int, valueMtEntry *big.Int, err error)

func (RDFEntry) ValueMtEntry

func (e RDFEntry) ValueMtEntry() (*big.Int, error)

type Value

type Value interface {
	MtEntry() (*big.Int, error)

	IsTime() bool
	AsTime() (time.Time, error)

	IsString() bool
	AsString() (string, error)

	IsInt64() bool
	AsInt64() (int64, error)

	IsBool() bool
	AsBool() (bool, error)
}

func NewValue

func NewValue(hasher Hasher, val any) (Value, error)

NewValue creates new Value

Jump to

Keyboard shortcuts

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