chainpoint

package module
v0.0.0-...-54e924c Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: MIT Imports: 22 Imported by: 0

README

Unofficial Chainpoint Client

import "github.com/boki/chainpoint"

Packages in chainpoint provide Go clients for the Chainpoint Node API.

Usage

License

All code distributed under the MIT License unless otherwise specified.

Documentation

Overview

Package chainpoint provides functionality to access the Chainpoint Node API.

A Chainpoint Node allows anyone to run a server that accepts hashes, anchors them to public blockchains, creates and verifies proofs, and participates in the Chainpoint Network.

Index

Constants

View Source
const (
	// ChpContext is the value for Chainpoint.Context
	ChpContext = "https://w3id.org/chainpoint/v4"
	// ChpType is the value for Chainpoint.Type
	ChpType = "Chainpoint"
)
View Source
const (
	AnchorCal  = "cal"
	AnchorBTC  = "btc"
	AnchorETH  = "eth"
	AnchorTCal = "tcal"
	AnchorTBTC = "tbtc"
)

Anchors ...

View Source
const (
	ContentTypeJSON   = "application/vnd.chainpoint.ld+json"
	ContentTypeBase64 = "application/vnd.chainpoint.json+base64"
)

ContentTypes supported in responses.

View Source
const UserAgent = "Chainpoint Node API Go Client"

UserAgent is the header string used to identify this package.

Variables

This section is empty.

Functions

func IsPerm

func IsPerm(err error) bool

IsPerm gets a value indicating whether the error is a permission error.

func IsTemporary

func IsTemporary(err error) bool

IsTemporary gets a value indicating whether the error is a temporary error.

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal ...

func Unmarshal

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

Unmarshal ...

Types

type Anchor

type Anchor struct {
	Type     string   `json:"type"`
	AnchorID string   `json:"anchor_id"`
	URIs     []string `json:"uris,omitempty"`
}

Anchor ...

func (Anchor) Valid

func (a Anchor) Valid() bool

Valid returns a value indicating whether the Anchor is valid.

type Branch

type Branch struct {
	Label    string      `json:"label,omitempty"`
	Branches []Branch    `json:"branches,omitempty"`
	Ops      []Operation `json:"ops"`
}

Branch ...

func (Branch) Valid

func (br Branch) Valid() bool

Valid returns a value indicating whether the Branch is valid.

type CalendarResponse

type CalendarResponse struct {
	ID       int    `json:"id"`
	Time     int    `json:"time"`
	Version  int    `json:"version"`
	StackID  string `json:"stackId"`
	Type     string `json:"type"`
	DataID   string `json:"dataId"`
	DataVal  string `json:"dataVal"`
	PrevHash string `json:"prevHash"`
	Hash     string `json:"hash"`
	Sig      string `json:"sig"`
}

CalendarResponse ...

type Chainpoint

type Chainpoint struct {
	Context      string   `json:"@context"`
	Type         string   `json:"type"`
	Hash         string   `json:"hash"`
	ProofID      string   `json:"proof_id"`
	HashReceived Time     `json:"hash_received"`
	Branches     []Branch `json:"branches"`
}

Chainpoint ...

func (*Chainpoint) MarshalBinary

func (chp *Chainpoint) MarshalBinary() ([]byte, error)

MarshalBinary ...

func (*Chainpoint) UnmarshalBinary

func (chp *Chainpoint) UnmarshalBinary(proof []byte) error

UnmarshalBinary unmarshales text into the Chainpoint structure.

func (*Chainpoint) Valid

func (chp *Chainpoint) Valid() bool

Valid returns a value indicating whether the Chainpoint is valid.

type ConfigResponse

type ConfigResponse struct {
	Version             string    `json:"version"`
	ProofExpireMinutes  int       `json:"proof_expire_minutes"`
	GetProofsMaxRest    int       `json:"get_proofs_max_rest"`
	PostHashesMax       int       `json:"post_hashes_max"`
	PostVerifyProofsMax int       `json:"post_verify_proofs_max"`
	Time                time.Time `json:"time"`
	Calendar            struct {
		Height        int    `json:"height"`
		AuditResponse string `json:"audit_response"`
	} `json:"calendar"`
}

ConfigResponse ...

type Error

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

Error response from Chainpoint APIs.

func NewError

func NewError(code int, msg string) *Error

NewError retruns a new Error given a status code and message.

func (*Error) Error

func (e *Error) Error() string

Error returns the string representation of the error.

type HashItem

type HashItem struct {
	ProofID string `json:"proof_id"`
	Hash    string `json:"hash"`
}

HashItem ...

type OpEnum

type OpEnum string

OpEnum ...

const (
	OpUnknown  OpEnum = ""
	OpSHA224   OpEnum = "sha-224"
	OpSHA256   OpEnum = "sha-256"
	OpSHA384   OpEnum = "sha-384"
	OpSHA512   OpEnum = "sha-512"
	OpSHA3224  OpEnum = "sha3-224"
	OpSHA3256  OpEnum = "sha3-256"
	OpSHA3384  OpEnum = "sha3-384"
	OpSHA3512  OpEnum = "sha3-512"
	OpSHA256x2 OpEnum = "sha-256-x2"
)

OpEnums introduced by package chainpoint.

type Operation

type Operation struct {
	L       string   `json:"l,omitempty"`
	R       string   `json:"r,omitempty"`
	Op      OpEnum   `json:"op,omitempty"`
	Anchors []Anchor `json:"anchors,omitempty"`
}

Operation ...

func (Operation) Valid

func (op Operation) Valid() bool

Valid returns a value indicating whether the Operation is valid.

type ParsedAnchor

type ParsedAnchor struct {
	Type          string
	AnchorID      string
	URIs          []string
	ExpectedValue string
}

ParsedAnchor ...

type ParsedBranch

type ParsedBranch struct {
	Label         string
	Branches      []ParsedBranch
	Anchors       []ParsedAnchor
	OpReturnValue string
	BTCTxID       string
}

ParsedBranch ...

type ParsedChainpoint

type ParsedChainpoint struct {
	Hash         string
	ProofID      string
	HashReceived Time
	Branches     []ParsedBranch
}

ParsedChainpoint ...

func Parse

func Parse(chp *Chainpoint) (*ParsedChainpoint, error)

Parse ...

type PostHash

type PostHash struct {
	URI  string `json:"uri,omitempty"`
	Meta struct {
		SubmittedAt     time.Time       `json:"submitted_at"`
		ProcessingHints ProcessingHints `json:"processing_hints"`
	} `json:"meta"`
	Hashes []HashItem `json:"hashes"`
}

PostHash ...

type ProcessingHints

type ProcessingHints map[string]time.Time

ProcessingHints ...

func (ProcessingHints) Next

func (h ProcessingHints) Next(t time.Time) time.Time

Next returns the processing hint that is closest to t, or 0, if all hints are less than t.

type Proof

type Proof struct {
	ProofID          string          `json:"proof_id"`         // The Version 1 UUID used to retrieve the proof.
	Proof            json.RawMessage `json:"proof"`            // The JSON or Base64 encoded binary form of the proof.
	AnchorsCompleted []string        `json:"anchors_complete"` // An Array that indicates which blockchains the proof is anchored to at the time of retrieval.
}

Proof ...

type Service

type Service struct {
	UserAgent string // optional additional User-Agent fragment
	// contains filtered or unexported fields
}

A Service is a Chainpoint Node API client.

func New

func New(client *http.Client) (*Service, error)

New initializes and returns a Service with given options.

func (*Service) Calendar

func (s *Service) Calendar(ctx context.Context, uri, height string) (*CalendarResponse, error)

Calendar retrieves the calendar block at the given height.

func (*Service) CalendarData

func (s *Service) CalendarData(ctx context.Context, uri, height string) (string, error)

CalendarData retrieves the calendar block data_val at the given height.

func (*Service) CalendarHash

func (s *Service) CalendarHash(ctx context.Context, uri, height string) (string, error)

CalendarHash retrieves the calendar block hash at the given height.

func (*Service) Config

func (s *Service) Config(ctx context.Context, uri string) (*ConfigResponse, error)

Config retrieves the configuration information for the Node.

func (*Service) Hashes

func (s *Service) Hashes(ctx context.Context, uri string, hashes []string) (*PostHash, error)

Hashes submits one or more hashes to one Node, returning an array of proof handle objects, one for each submitted hash.

func (*Service) Proofs

func (s *Service) Proofs(ctx context.Context, nodeURI string, proofIDs []string, contentType ...string) ([]*Proof, error)

Proofs retrieves a collection of proofs for one or more hash IDs from the specified Node URI.

func (*Service) Verify

func (s *Service) Verify(ctx context.Context, uri string, proofs []*Chainpoint) ([]*VerifyResponse, error)

Verify submits one or more proofs for verification.

type Time

type Time string

Time ...

func NewTime

func NewTime(t time.Time) Time

NewTime ...

func (Time) String

func (t Time) String() string

func (Time) Time

func (t Time) Time() (time.Time, error)

Time ...

type VerifyResponse

type VerifyResponse struct {
	ProofIndex   int                    `json:"proof_index"`
	Hash         string                 `json:"hash"`
	HashCore     string                 `json:"hash_core"`
	HashReceived time.Time              `json:"hash_received"`
	Anchors      []VerifyResponseAnchor `json:"anchors"`
	Status       string                 `json:"status"`
}

VerifyResponse ...

type VerifyResponseAnchor

type VerifyResponseAnchor struct {
	Branch string `json:"branch"`
	Type   string `json:"type"`
	Valid  bool   `json:"valid"`
}

VerifyResponseAnchor ...

Directories

Path Synopsis
cmd
encoding

Jump to

Keyboard shortcuts

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