merkletree_proof

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0, MIT Imports: 7 Imported by: 1

README

merkletree-proof

Merkletree proof is a complementary library for reverse hash service to fetch iden3 identity state roots and generate Sparse Merkle Tree proofs.

Docs

Install

go get github.com/iden3/go-merkletree-proof

Examples

Fetch identity state roots

Fetch identity state roots for identity state hash e12084d0d72c492c703a2053b371026bceda40afb9089c325652dfd2e5e11223 Identity state must be fetched from the blockchain State contract.

stateHash, _ := merkletree.NewHashFromHex("e12084d0d72c492c703a2053b371026bceda40afb9089c325652dfd2e5e11223")

cli := &merkletree_proof.HTTPReverseHashCli{URL: "<link to RHS>"}
// get identity state roots

stateValues, err := cli.GetNode(ctx, stateHash)
Generate proof

Generate proof for revocation nonce 670966937 and revocation root b92f062026083232bdd4d3a93986276515aa874fd3f7e928d6f67c8c91a6b705

revocationNonce, _ := merkletree.NewHashFromBigInt(big.NewInt(670966937))
revocationRoot, _ := merkletree.NewHashFromHex("b92f062026083232bdd4d3a93986276515aa874fd3f7e928d6f67c8c91a6b705")

cli := &proof.HTTPReverseHashCli{URL: "<link to RHS>"}
proof, _ := cli.GenerateProof(ctx, revocationRoot, revocationNonce)

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as below, without any additional terms or conditions.

License

Copyright 2023 0kims Association

This project is licensed under either of

at your option.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNodeNotFound = errors.New("node not found")

Functions

func GenerateProof added in v0.0.4

func GenerateProof(ctx context.Context, cli NodeReader,
	treeRoot *merkletree.Hash,
	key *merkletree.Hash) (*merkletree.Proof, error)

Types

type Node

type Node struct {
	Hash     *merkletree.Hash
	Children []*merkletree.Hash
}

func (Node) MarshalJSON

func (n Node) MarshalJSON() ([]byte, error)

func (Node) Type added in v0.0.4

func (n Node) Type() NodeType

func (*Node) UnmarshalJSON

func (n *Node) UnmarshalJSON(in []byte) error

type NodeReader added in v0.0.4

type NodeReader interface {
	GetNode(context.Context, *merkletree.Hash) (Node, error)
}

type NodeType

type NodeType byte
const (
	NodeTypeUnknown NodeType = iota
	NodeTypeMiddle  NodeType = iota
	NodeTypeLeaf    NodeType = iota
	NodeTypeState   NodeType = iota
)

type ReverseHashCli added in v0.0.4

type ReverseHashCli interface {
	GenerateProof(ctx context.Context,
		treeRoot *merkletree.Hash,
		key *merkletree.Hash) (*merkletree.Proof, error)
	GetNode(ctx context.Context,
		hash *merkletree.Hash) (Node, error)
	SaveNodes(ctx context.Context,
		nodes []Node) error
}

Directories

Path Synopsis
examples
tests
integration Module

Jump to

Keyboard shortcuts

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