Back to godoc.org
github.com/keys-pub/keys-ext/http/client

Package client

v0.0.0 (7a5f2c1)
Latest Go to latest
Published: 3 days ago | License: MIT | Module: github.com/keys-pub/keys-ext/http/client

Index

Examples

Package Files

func CheckEventchain

func CheckEventchain(events []*Event) error

CheckEventchain checks event previous hashes.

func EventHash

func EventHash(event *Event) *[32]byte

EventHash returns hash for Event.

func SetLogger

func SetLogger(l Logger)

SetLogger sets logger for the package.

type Client

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

Client ...

func New

func New(urs string) (*Client, error)

New creates a Client for an HTTP API.

func (*Client) AdminCheck

func (c *Client) AdminCheck(ctx context.Context, check string, admin *keys.EdX25519Key) error

AdminCheck performs user & sigchain associated with key by an admin. The server periodically checks users and sigchains, but this tells the server to do it right away. If check is a kid, will check that key. If check is "all" (not recommended), it will check all keys.

func (*Client) Check

func (c *Client) Check(ctx context.Context, key *keys.EdX25519Key) error

Check user & sigchain associated with edx25519 key. The server periodically checks users and sigchains, but this tells the server to do it right away.

func (*Client) Disco

func (c *Client) Disco(ctx context.Context, sender keys.ID, recipient *keys.EdX25519Key, typ DiscoType) (string, error)

Disco gets a discovery address.

func (*Client) DiscoDelete

func (c *Client) DiscoDelete(ctx context.Context, sender *keys.EdX25519Key, recipient keys.ID) error

DiscoDelete removes discovery addresses.

func (*Client) DiscoSave

func (c *Client) DiscoSave(ctx context.Context, sender *keys.EdX25519Key, recipient keys.ID, typ DiscoType, data string, expire time.Duration) error

DiscoSave puts a discovery offer or answer.

func (*Client) Invite

func (c *Client) Invite(ctx context.Context, sender *keys.EdX25519Key, code string) (*api.InviteResponse, error)

Invite looks for an invite with code.

func (*Client) InviteCreate

func (c *Client) InviteCreate(ctx context.Context, sender *keys.EdX25519Key, recipient keys.ID) (*api.CreateInviteResponse, error)

InviteCreate writes a sender recipient address (invite).

func (*Client) MessageDecrypt

func (c *Client) MessageDecrypt(key *keys.EdX25519Key, revent *events.Event) (*Event, keys.ID, error)

MessageDecrypt decrypts a remote Event from Messages.

func (*Client) MessageSend

func (c *Client) MessageSend(ctx context.Context, sender *keys.EdX25519Key, recipient keys.ID, event *Event) error

MessageSend posts an encrypted message. TODO: expire time.Duration

func (*Client) Messages

func (c *Client) Messages(ctx context.Context, key *keys.EdX25519Key, from keys.ID, opts *MessagesOpts) ([]*events.Event, int64, error)

Messages returns encrypted messages. To decrypt a message, use Client#MessageDecrypt.

func (*Client) SetClock

func (c *Client) SetClock(clock tsutil.Clock)

SetClock sets the clock Now fn.

func (*Client) SetHTTPClient

func (c *Client) SetHTTPClient(httpClient *http.Client)

SetHTTPClient sets the http.Client to use.

func (*Client) ShareOpen

func (c *Client) ShareOpen(ctx context.Context, key *keys.EdX25519Key) ([]byte, error)

ShareOpen opens a secret.

func (*Client) ShareSeal

func (c *Client) ShareSeal(ctx context.Context, key *keys.EdX25519Key, data []byte, expire time.Duration) error

ShareSeal saves a secret on remote with expire.

func (*Client) Sigchain

func (c *Client) Sigchain(ctx context.Context, kid keys.ID) (*api.SigchainResponse, error)

Sigchain for KID. If sigchain not found, a nil response is returned.

Example

Code:

cl, err := client.New("https://keys.pub")
if err != nil {
	log.Fatal(err)
}

kid := keys.ID("kex1ydecaulsg5qty2axyy770cjdvqn3ef2qa85xw87p09ydlvs5lurq53x0p3")
resp, err := cl.Sigchain(context.TODO(), kid)
if err != nil {
	log.Fatal(err)
}
sc, err := resp.Sigchain()
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%s", sc.Spew())

usr, err := user.FindInSigchain(sc)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%+v\n", usr)

result := user.RequestVerify(context.TODO(), request.NewHTTPRequestor(), usr, time.Now())
if result.Status != user.StatusOK {
	log.Fatalf("User check failed: %+v", result)
}

fmt.Printf("%s\n", result.Status)
/sigchain/kex1ydecaulsg5qty2axyy770cjdvqn3ef2qa85xw87p09ydlvs5lurq53x0p3/1 {".sig":"Rf39uRlHXTqmOjcqUs5BTssshRdqpaFfmoYYJuA5rNVGgGd/bRG8p8ZebB8K+w9kozMpnuAoa4lko+oPHcabCQ==","data":"eyJrIjoia2V4MXlkZWNhdWxzZzVxdHkyYXh5eTc3MGNqZHZxbjNlZjJxYTg1eHc4N3AwOXlkbHZzNWx1cnE1M3gwcDMiLCJuIjoia2V5cy5wdWIiLCJzcSI6MSwic3IiOiJodHRwcyIsInUiOiJodHRwczovL2tleXMucHViL2tleXNwdWIudHh0In0=","kid":"kex1ydecaulsg5qty2axyy770cjdvqn3ef2qa85xw87p09ydlvs5lurq53x0p3","seq":1,"ts":1588276919715,"type":"user"}
keys.pub@https!kex1ydecaulsg5qty2axyy770cjdvqn3ef2qa85xw87p09ydlvs5lurq53x0p3-1#https://keys.pub/keyspub.txt
ok

func (*Client) SigchainSave

func (c *Client) SigchainSave(ctx context.Context, st *keys.Statement) error

SigchainSave ...

func (*Client) URL

func (c *Client) URL() *url.URL

URL ...

func (*Client) User

func (c *Client) User(ctx context.Context, kid keys.ID) (*api.UserResponse, error)

User ...

func (*Client) UserSearch

func (c *Client) UserSearch(ctx context.Context, query string, limit int) (*api.UserSearchResponse, error)

UserSearch ...

func (*Client) Vault

func (c *Client) Vault(ctx context.Context, key *keys.EdX25519Key, opt ...VaultOption) (*Vault, error)

Vault events. Vault data is decrypted using the vault key before being returned. Callers should check for repeated nonces and event chain ordering.

func (*Client) VaultDelete

func (c *Client) VaultDelete(ctx context.Context, key *keys.EdX25519Key) error

VaultDelete removes a vault.

func (*Client) VaultExists

func (c *Client) VaultExists(ctx context.Context, key *keys.EdX25519Key) (bool, error)

VaultExists checks if vault exists.

func (*Client) VaultSend

func (c *Client) VaultSend(ctx context.Context, key *keys.EdX25519Key, events []*Event) error

VaultSend saves events to the vault API encrypted with key.

type ContextLogger

type ContextLogger interface {
	Debugf(ctx context.Context, format string, args ...interface{})
	Infof(ctx context.Context, format string, args ...interface{})
	Warningf(ctx context.Context, format string, args ...interface{})
	Errorf(ctx context.Context, format string, args ...interface{})
}

ContextLogger interface used in this package with request context.

func NewContextLogger

func NewContextLogger(lev LogLevel) ContextLogger

NewContextLogger ...

type DiscoType

type DiscoType string

DiscoType is the type of discovery address.

const (
	// Offer initiates.
	Offer DiscoType = "offer"
	// Answer listens.
	Answer DiscoType = "answer"
)

type ErrResponse

type ErrResponse struct {
	StatusCode int
	Message    string
	URL        *url.URL
}

ErrResponse ...

func (ErrResponse) Error

func (e ErrResponse) Error() string

type Event

type Event struct {
	// Path for event /{collection}/{id}.
	Path string `msgpack:"p"`
	// Data ...
	Data []byte `msgpack:"dat"`

	// Nonce to prevent replay.
	Nonce []byte `msgpack:"n"`
	// Prev is a hash of the previous item (optional if root).
	Prev []byte `msgpack:"prv,omitempty"`

	// Index is set by clients from remote events API (untrusted).
	Index int64 `msgpack:"idx,omitempty"`
	// Timestamp is set by clients from the remote events API (untrusted).
	Timestamp int64 `msgpack:"ts,omitempty"`
}

Event describes a client event.

func NewEvent

func NewEvent(path string, b []byte, prev *Event) *Event

NewEvent creates a new event.

type LogLevel

type LogLevel int

LogLevel ...

const (
	// DebugLevel ...
	DebugLevel LogLevel = 3
	// InfoLevel ...
	InfoLevel LogLevel = 2
	// WarnLevel ...
	WarnLevel LogLevel = 1
	// ErrLevel ...
	ErrLevel LogLevel = 0
)

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

Logger interface used in this package.

func NewLogger

func NewLogger(lev LogLevel) Logger

NewLogger ...

type MessagesOpts

type MessagesOpts struct {
	// Index to list to/from
	Index int64
	// Direction ascending or descending
	Direction events.Direction
	// Limit by
	Limit int
}

MessagesOpts options for Messages.

type Vault

type Vault struct {
	Events []*Event
	Index  int64
}

Vault events from the API, decrypted with vault API key.

type VaultOption

type VaultOption func(o *VaultOptions)

VaultOption option.

func VaultIndex

func VaultIndex(index int64) VaultOption

VaultIndex ...

func VaultLimit

func VaultLimit(limit int) VaultOption

VaultLimit ...

type VaultOptions

type VaultOptions struct {
	// Index to list to/from
	Index int64
	// Limit by
	Limit int
}

VaultOptions options for Vault.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier