proxy

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2017 License: Apache-2.0 Imports: 18 Imported by: 0

README

Proxy Server

This package provides all the functionality for a local proxy http server, and ties together functionality from all the other packages to acheive this aim. Simply configure this server with your application-specific settings via a main script and you are good to go.

This server should run on the client's machine, and can accept a trusted connection from localhost (via tcp or unix socket). It provides a simple json rest API and handles all the binary wrangling and cryptographic proofs under the hood. Thus, you can host a local webapp (via electron?) and connect to this proxy, perform simple queries and posts and behind the scenes take advantage of the awesome power of the tendermint blockchain.

If you are writing native code, you can use this as well, or you can look for bindings to embed this functionality directly as a library in your codebase. (coming soon)

API

The API has various sections based on functionality. The major portions are key management, signing and posting transactions, and querying and proving data.

Key Management

We expose a number of methods for safely managing your keychain. They are typically bound under /keys, but could be placed in another location by the app.

  • POST /keys/ - provide a name and passphrase and create a brand new key
  • GET /keys/ - get a list of all available key names, along with their public key and address
  • GET /keys/{name} - get public key and address for this named key

Later expose:

  • PUT /keys/{name} - update the passphrase for the given key. requires you to correctly provide the current passphrase, as well as a new one.
  • DELETE /keys/{name} - permanently delete this private key. requires you to correctly provide the current passphrase
  • export and import functionality
Transactions

You want to post your transaction. Great. Your application must provide logic to transform json into a Signable go struct. Then we handle the rest, signing it with a keypair of your choosing, posting it to tendermint core, and returning you confirmation when it was committed.

  • POST /txs/ - provide name, passphrase and application-specific data to post to tendermint
Proving Data

We sent some money to our friend, now we want to check his balance. No, not just look at it, but really check it, verify all those cryptographic proofs that some node is not lying and it really, truly is in his account.

Thankfully, we have the technology and can do all the checks in the proxy, it might just take a second or two for us to get all those block headers.

However, this still just leaves us with a bunch of binary blobs from the server, so to make this whole process less painless, you should provide some application-specific logic to parse this binary data from the blockchain, so we can present it as json over the interface.

  • GET /query/{path}/{data} - will quickly query the data under the given (hex-encoded) key. path is key to query by merkle key, but your application could provide other prefixes, to differentiate by types (eg. account, votes, escrow). The returned data is parsed into json and displayed.
  • GET /proof/{key} - will query for a merkle proof of the given key, download block headers, and verify all the signatures of that block. After it is done, it will present you some json and a stamp that it your data is really safe and sound.

Configuring

When you instantiate a server, make sure to pass in application-specific info in order to properly. Like the following info:

Possibly as command-line flags:

  • Where to store the private keys? (or find existing ones)
  • Which type of key to generate?
  • What is the URL of the tendermint RPC server?
    • TODO: support multiple node URLs and round-robin
  • What is the chain_id we wish to connect to?

Extra code (plugin) you must write:

  • Logic to parse json -> Signable transaction
  • Logic to parse binary values from merkle tree -> structured data to render

TODO:

  • How to get the trusted validator set?

Documentation

Overview

package proxy provides http handlers to construct a proxy server for key management, transaction signing, and query validation.

Please read the README and godoc to see how to configure the server for your application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDefault

func RegisterDefault(r *mux.Router, ks KeyStore, node client.Client,
	txReader lc.SignableReader, valReader lc.ValueReader, chainID string)

RegisterDefault constructs all components and wires them up under standard routes.

TODO: something more intelligent for getting validators, this is pretty insecure right now

Types

type KeyStore

type KeyStore interface {
	keys.Manager
	keys.Signer
}

KeyStore is implemented by cryptostore.Manager

type TxSigner

type TxSigner struct {
	lc.SignableReader
	lc.Poster
}

func NewTxSigner

func NewTxSigner(server client.ABCIClient, signer keys.Signer,
	reader lc.SignableReader) TxSigner

func (TxSigner) PostTransaction

func (t TxSigner) PostTransaction(w http.ResponseWriter, r *http.Request)

func (TxSigner) Register

func (t TxSigner) Register(r *mux.Router)

type Viewer

type Viewer struct {
	client.Client
	// lc.ValueReader
	lc.Certifier
}

func NewViewer

func NewViewer(cl client.Client, cert lc.Certifier) Viewer

func (Viewer) ProveData

func (v Viewer) ProveData(w http.ResponseWriter, r *http.Request)

func (Viewer) QueryData

func (v Viewer) QueryData(w http.ResponseWriter, r *http.Request)

func (Viewer) Register

func (v Viewer) Register(r *mux.Router)

Directories

Path Synopsis
package types contains all json structs used by the proxy server for input and output.
package types contains all json structs used by the proxy server for input and output.

Jump to

Keyboard shortcuts

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