Documentation ¶
Overview ¶
Package proxy implements the HTTP payment proxy between a locally exposed endpoint and the public internet.
Index ¶
Constants ¶
const ( AuthorizationHeader = "etherapi-authorization" // Client side payment authorization header VerificationHeader = "etherapi-verification" // Server side payment verification header )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Charger ¶
type Charger interface { // Charge calls down into the underlying Ethereum contract layer and executes // a payment charging transaction. It returns the hex encoded transaction id // to enable later verification. Charge(from, to common.Address, nonce uint64, amount *big.Int, signature []byte) (common.Hash, error) }
Charger chaaaaarges! :D Fun's aside, this interfaces provides the capability to redeem an authorized payment by the underlying framework.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy is a payment gateway between arbitrarily many internal services and the outside world. Its role is to broker API requests between them, while at the same time enforcing payment authorizations.
func (*Proxy) ServeHTTP ¶
func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler, extracting and validating payment headers contained within the HTTP request. If payment information is accepted, the request is passed on to the internal service for execution. Otherwise the proxy short circuits the request and sends back an appropriate error.
type Vault ¶
type Vault struct {
// contains filtered or unexported fields
}
Vault is a payment aggregator collecting the individual accepted payments made by various clients. It can at any point return the most recent payment + proof, and can also charge the payments via the Ethereum network.
func (*Vault) AutoCharge ¶
AutoCharge starts a periodical automatic charging to claim collected funds.
func (*Vault) Charge ¶
func (v *Vault) Charge()
Charge will redeem all pending payments from the vault.
type Verifier ¶
type Verifier interface { // Exists checks whether there's a live payment channel already set up between // the sender and recipient. Exists(from, to common.Address) bool // Verify checks whether the authorization is cryptographically valid, and also // whether there are enough funds in the payment channel to process this payment. Verify(from, to common.Address, nonce uint64, amount *big.Int, signature []byte) (bool, bool) // Price returns the price provided by the signature of (from || to). Price(from, to common.Address) *big.Int // Nonce returns the nonce provided by the signature of (from || to). Nonce(from, to common.Address) *big.Int }
Verifier is an interface that accepts the details of a payment authorization and returns whether the sender is allowed to make the payment or not.