lanyard

package module
v0.0.0-...-32be597 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

An API client for lanyard.org.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound error = xerrors.New("resource not found")

Functions

This section is empty.

Types

type Client

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

func New

func New(opts ...ClientOpt) *Client

Uses https://lanyard.org/api/v1 for a default url and http.Client with a 30s timeout unless specified using WithURL or WithClient

func (*Client) CreateTree

func (c *Client) CreateTree(
	ctx context.Context,
	addresses []hexutil.Bytes,
) (*CreateResponse, error)

If you have a list of addresses for an allowlist, you can create a Merkle tree using CreateTree. Any Merkle tree published on Lanyard will be publicly available to any user of Lanyard’s API, including minting interfaces such as Zora or mint.fun.

func (*Client) CreateTypedTree

func (c *Client) CreateTypedTree(
	ctx context.Context,
	unhashedLeaves []hexutil.Bytes,
	leafTypeDescriptor []string,
	packedEncoding bool,
) (*CreateResponse, error)

CreateTypedTree is a more advanced way of creating a tree. Useful if your tree has ABI encoded data, such as quantity or other values. unhashedLeaves is a slice of addresses or ABI encoded types. leafTypeDescriptor describes the abi-encoded types of the leaves, and is required if leaves are not address types. Set packedEncoding to true if your arguments are packed/encoded

func (*Client) GetProofFromLeaf

func (c *Client) GetProofFromLeaf(
	ctx context.Context,
	root hexutil.Bytes,
	unhashedLeaf hexutil.Bytes,
) (*ProofResponse, error)

If the tree has been published to Lanyard, GetProof will return the proof associated with an unHashedLeaf. This endpoint will return ErrNotFound if the tree associated with the root has not been published.

func (*Client) GetRootFromProof

func (c *Client) GetRootFromProof(
	ctx context.Context,
	proof []hexutil.Bytes,
) (*RootResponse, error)

If a Merkle tree has been published to Lanyard, GetRootFromLeaf will return the root of the tree based on a proof of a leaf. This endpoint will return ErrNotFound if the tree associated with the leaf has not been published.

func (*Client) GetTreeFromRoot

func (c *Client) GetTreeFromRoot(
	ctx context.Context,
	root hexutil.Bytes,
) (*TreeResponse, error)

If a Merkle tree has been published to Lanyard, GetTreeFromRoot will return the entire tree based on the root. This endpoint will return ErrNotFound if the tree associated with the root has not been published.

type ClientOpt

type ClientOpt func(*Client)

func WithClient

func WithClient(hc *http.Client) ClientOpt

func WithURL

func WithURL(url string) ClientOpt

type CreateResponse

type CreateResponse struct {
	// MerkleRoot is the root of the created merkle tree
	MerkleRoot hexutil.Bytes `json:"merkleRoot"`
}

type ProofResponse

type ProofResponse struct {
	UnhashedLeaf hexutil.Bytes   `json:"unhashedLeaf"`
	Proof        []hexutil.Bytes `json:"proof"`
}

type RootResponse

type RootResponse struct {
	Root hexutil.Bytes `json:"root"`
}

type TreeResponse

type TreeResponse struct {
	// UnhashedLeaves is a slice of addresses or ABI encoded types
	UnhashedLeaves []hexutil.Bytes `json:"unhashedLeaves"`

	// LeafTypeDescriptor describes the abi-encoded types of the leaves, and
	// is required if leaves are not address types
	LeafTypeDescriptor []string `json:"leafTypeDescriptor"`

	// PackedEncoding is true by default
	PackedEncoding bool `json:"packedEncoding"`

	LeafCount int `json:"leafCount"`
}

Jump to

Keyboard shortcuts

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