client

package
v0.0.0-...-57c8b1d Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2019 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Client package is responsible for connecting to a server, and if wanted checking proofs of both the chain commitment and the inclusion of our logs in the commitment

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppendLogParameters

type AppendLogParameters struct {
	LogID     string // The ID of the log to append to (in hexadecimal format)
	Index     uint64 // The 0-based index of the statement that is to be written
	Statement string // The statement (in clear text) to append to the log
}

type AppendLogReply

type AppendLogReply struct {
	Success bool
}

type Client

type Client struct {

	// You can set these function pointers to receive events
	// from the client (errors and proof updates)
	OnError       func(error, *Client)
	OnProofUpdate func([]byte, *Client)

	// FastMode means you can log more than once every commitment. This is achieved
	// by forming a hash-chain of statements. The proof size will however grow linearly
	// with the amount of statements between the commitments, you will need to include
	// the hashes of all statements up until the next commitment
	FastMode bool

	// Ready indicates the client is ready to serve commands (only relevant for FullClient)
	Ready bool

	// When connecting using NewClient() the address is kept. When there's a failure
	// the server will disconnect us for, it will automatically reconnect.
	ReconnectOnFailure bool

	// Don't create actual signatures, just dummy ones - used for initialization during
	// benchmarks
	DummySignatures bool

	AckTimeout   time.Duration
	ProofTimeout time.Duration
	// contains filtered or unexported fields
}

func NewClient

func NewClient(key []byte, addr string) (*Client, error)

NewClient will create a new Client that connects to the server and port specified in addr

func NewClientWithConnection

func NewClientWithConnection(key []byte, c net.Conn) (*Client, error)

NewClientWithConnection creates a new b_verify client using the provided private key bytes and net.Conn

func (*Client) AddForeignLog

func (c *Client) AddForeignLog(statement *wire.ForeignStatement) error

AddForeignLog will keep updating the logID's proofs for the given statement

func (*Client) AppendLog

func (c *Client) AppendLog(idx uint64, logId [32]byte, statement []byte) error

func (*Client) AppendLogText

func (c *Client) AppendLogText(idx uint64, logId [32]byte, statement string) error

AppendLogText is a convenience function called by the RPC server to append a particular piece of information to the log. This function will take care of hashing it before passing it to AppendLog. It will also keep the clear text (preimage) in our database for future verification purposes.

func (*Client) ClearCommitments

func (c *Client) ClearCommitments() error

ClearCommitments delets the client-side cache of the server commitments. This will trigger a resynchronization of the commitments and proofs.

func (*Client) ExportLog

func (c *Client) ExportLog(logId [32]byte) (*wire.ForeignStatement, error)

ExportLog will create a ForeignStatement out of the last committed statement in the given log

func (*Client) GetAllLogIDs

func (c *Client) GetAllLogIDs() ([][32]byte, error)

func (*Client) GetBlockHeaderByHash

func (c *Client) GetBlockHeaderByHash(hash *chainhash.Hash) (*btcwire.BlockHeader, error)

GetBlockHeaderByHash will return a single block header from the SPV data based on the blockhash

func (*Client) GetCommitmentDetails

func (c *Client) GetCommitmentDetails(commitment [32]byte) (*wire.Commitment, error)

GetCommitmentDetails will request the server to send over commitment details for a single commitment. If commitment is an empty byte array, the details of the last commitment will be returned.

func (*Client) GetCommitmentHistory

func (c *Client) GetCommitmentHistory(sinceCommitment [32]byte) ([]*wire.Commitment, error)

GetCommitmentHistory will request the server to send over commitment details for every commitment since sinceCommitment. If sinceCommitment is an empty byte array, all commitments will be returned.

func (*Client) GetForeignLogIDAndHash

func (c *Client) GetForeignLogIDAndHash(statement *wire.ForeignStatement) ([32]byte, [32]byte, error)

func (*Client) GetLastCommittedLog

func (c *Client) GetLastCommittedLog(logId [32]byte) (int64, [32]byte, error)

GetLastCommittedHash returns the last committed hash for the given log

func (*Client) GetLastHash

func (c *Client) GetLastHash(logId [32]byte) (int64, [32]byte, error)

GetLastHash returns the last known hash for the given log

func (*Client) GetLogCommitment

func (c *Client) GetLogCommitment(logId [32]byte, idx uint64) ([32]byte, error)

func (*Client) GetLogPreimage

func (c *Client) GetLogPreimage(logId [32]byte, idx uint64) (string, error)

func (*Client) GetProofForCommitment

func (c *Client) GetProofForCommitment(commitment [32]byte, logIds [][]byte) (*mpt.PartialMPT, error)

func (*Client) IsCommitted

func (c *Client) IsCommitted(logId [32]byte, idx uint64) bool

func (*Client) IsForeignLog

func (c *Client) IsForeignLog(logId [32]byte) bool

IsFollowingLog returns true when the passed LogID is merely being followed by this client, and not being actively written to.

func (*Client) LogHasCommitment

func (c *Client) LogHasCommitment(logId [32]byte) bool

func (*Client) ReceiveLoop

func (c *Client) ReceiveLoop()

ReceiveLoop will fetch new messages as they come in on the wire (from the server) and try to process them accordingly.

func (*Client) Reconnect

func (c *Client) Reconnect()

func (*Client) RequestProof

func (c *Client) RequestProof(logIds [][32]byte) (*mpt.PartialMPT, error)

RequestProof asks the server for a full proof of the passed in LogIDs. These are the LogIDs returned from CreateLog() or CreateLogText(). The return value is a partial MPT that only contains the paths from these logs to the root.

func (*Client) Run

func (c *Client) Run(resync bool) error

Run will kick off the full client functionality, that also stores its key in a keyfile in the user's home directory, keep track of log statements and their proofs, as well as commitments and their merkle proof to the blockchain block headers. This is the "complete" functionality for b_verify.

func (*Client) SPVAskHeaders

func (c *Client) SPVAskHeaders() error

SPVAskHeaders will (re)initiate the header synchronization if we have the idea that we might have stale data, we can call this to talk to our known peers and fetch new headers.

func (*Client) SPVHeight

func (c *Client) SPVHeight() int32

func (*Client) SPVSynced

func (c *Client) SPVSynced() bool

SPVSynced returns true if there's no more headers to fetch for us (and we can assume we've synced up all the headers from the blockchain)

func (*Client) SignedAppendLog

func (c *Client) SignedAppendLog(idx uint64, logId [32]byte, statement []byte) (*wire.SignedLogStatement, error)

SignedAppendLog is a convenience function to generate a SignedLogStatement message using the key in this client

func (*Client) StartLog

func (c *Client) StartLog(initialStatement []byte) ([32]byte, error)

StartLog will start a new log on the server. It will locally calculate the LogID, since that's deterministic. It will sign the CreateLog instruction with the client's key and then send it to the server. It will wait for the server to have acknowledged the log.

func (*Client) StartLogText

func (c *Client) StartLogText(initialStatement string) ([32]byte, error)

StartLogText is a convenience function called by the RPC server to start a new log with a particular piece of information. This function will take care of hashing it before passing it to StartLog. It will also keep the clear text (preimage) in our database for future verification purposes.

func (*Client) StartSPV

func (c *Client) StartSPV() error

StartSPV will initiate the process of downloading headers from the blockchain to allow us to check SPV proofs for the commitment transactions

func (*Client) SubscribeProofUpdates

func (c *Client) SubscribeProofUpdates() error

SubscribeProofUpdates will tell the server that we want to receive delta proofs as soon as the server commits a new value to the chain. The server will then send us a ProofUpdate message automatically, which the client can read out by setting a function pointer to OnProofUpdate

func (*Client) UnsubscribeProofUpdates

func (c *Client) UnsubscribeProofUpdates() error

UnsubscribeProofUpdates will tell the server to stop sending us automatic proof updates. In that case, the proofs will have to be requested manually

func (*Client) UsesKey

func (c *Client) UsesKey(key []byte) bool

UsesKey return true if this client is using the key passed in. We don't want to expose the key as a public variable but if you know the key yourself, we can tell you if it matches.

type ErrorResponse

type ErrorResponse struct {
	Error        bool
	ErrorDetails string
}

type JsonCommitment

type JsonCommitment struct {
	Commitment             string
	TxHash                 string
	TriggeredAtBlockHeight int
	IncludedInBlock        string
}

type LogInfo

type LogInfo struct {
	Foreign                 bool
	LogID                   string
	LastStatement           string
	LastIndex               int64
	LastCommitment          string
	LastCommitmentProof     string
	LastCommitmentBlock     string
	LastCommitmentTimestamp int64
	Valid                   bool
	Error                   string
}

type RpcServer

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

RpcServer runs a simple JSON based API for clients to start and maintain logs using the client

func NewRpcServer

func NewRpcServer(c *Client) *RpcServer

NewRpcServer creates a new RPC server

func (*RpcServer) AddForeignLog

func (s *RpcServer) AddForeignLog(w http.ResponseWriter, r *http.Request)

AddForeignLog is an RPC method to instruct this client to keep updated proofs for the given log statement

func (*RpcServer) AppendLog

func (s *RpcServer) AppendLog(w http.ResponseWriter, r *http.Request)

AppendLog is an RPC method to append to an existing log

func (*RpcServer) Commitments

func (s *RpcServer) Commitments(w http.ResponseWriter, r *http.Request)

Commitments will return a list of server commitments

func (*RpcServer) Export

func (s *RpcServer) Export(w http.ResponseWriter, r *http.Request)

Logs will return a list of known logs and their last statements and proofs

func (*RpcServer) Logs

func (s *RpcServer) Logs(w http.ResponseWriter, r *http.Request)

Logs will return a list of known logs and their last statements and proofs

func (*RpcServer) Start

func (s *RpcServer) Start() error

Start starts the RPC server listening to client connections

func (*RpcServer) StartLog

func (s *RpcServer) StartLog(w http.ResponseWriter, r *http.Request)

StartLog is an RPC method to start a new log

func (*RpcServer) Status

func (s *RpcServer) Status(w http.ResponseWriter, r *http.Request)

Status is an RPC method to fetch the status of the server

func (*RpcServer) VerifyOnce

func (s *RpcServer) VerifyOnce(w http.ResponseWriter, r *http.Request)

type StartLogParameters

type StartLogParameters struct {
	InitialStatement string // The statement (in clear text) you wish to start the log with
}

type StartLogReply

type StartLogReply struct {
	LogID string // The Log ID (hex encoded bytes)
}

type StatusReply

type StatusReply struct {
	BlockHeight int32 `json:"blockHeight"`
	Synced      bool  `json:"synced"`
}

type VerificationResult

type VerificationResult struct {
	Statement      string
	Valid          bool
	Error          string
	PubKey         string
	BlockHash      string
	TxHash         string
	BlockTimestamp int64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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