Back to

Package api

v0.0.0 (c95092b)
Latest Go to latest
Published: 4 days ago | License: MIT | Module:



Package Files

func ContentHash

func ContentHash(b []byte) string

ContentHash returns base64 encoded sha256 hash.

func NewRequest

func NewRequest(method string, urs string, body io.Reader, contentHash string, tm time.Time, key *keys.EdX25519Key) (*http.Request, error)

NewRequest returns new authorized/signed HTTP request.



key := keys.GenerateEdX25519Key()

content := []byte(`[{"data":"dGVzdGluZzE="},{"data":"dGVzdGluZzI="}]`)
contentHash := api.ContentHash(content)
req, err := api.NewRequest("POST", ""+key.ID().String(), bytes.NewReader(content), contentHash, time.Now(), key)
if err != nil {
fmt.Printf("curl -H \"Authorization: %s\" -d %q %q\n", req.Header["Authorization"][0], string(content), req.URL.String())

req, err = api.NewRequest("GET", ""+key.ID().String(), nil, "", time.Now(), key)
if err != nil {
fmt.Printf("curl -H \"Authorization: %s\" %q\n", req.Header["Authorization"][0], req.URL.String())

func NewRequestWithContext

func NewRequestWithContext(ctx context.Context, method string, urs string, body io.Reader, contentHash string, tm time.Time, key *keys.EdX25519Key) (*http.Request, error)

NewRequestWithContext returns new authorized/signed HTTP request with context.

func SetLogger

func SetLogger(l Logger)

SetLogger sets logger for the package.

type Auth

type Auth struct {
	KID         keys.ID
	Method      string
	URL         *url.URL
	Sig         string
	BytesToSign string

Auth describes auth for a HTTP request.

func NewAuth

func NewAuth(method string, urs string, contentHash string, tm time.Time, key *keys.EdX25519Key) (*Auth, error)

NewAuth returns auth for an HTTP request. The url shouldn't have ? or &.

func (Auth) Header

func (a Auth) Header() string

Header is header value.

type AuthResult

type AuthResult struct {
	KID       keys.ID
	Method    string
	URL       *url.URL
	Nonce     string
	Timestamp time.Time

AuthResult is the authorized result.

func CheckAuthorization

func CheckAuthorization(ctx context.Context, method string, urs string, kid keys.ID, auth string, contentHash string, rds Redis, now time.Time) (*AuthResult, error)

CheckAuthorization checks auth header.

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 CreateInviteResponse

type CreateInviteResponse struct {
	Code string `json:"code"`

CreateInviteResponse ...

type Data

type Data struct {
	Data []byte `json:"data"`

Data for request body.

type Error

type Error struct {
	Message string `json:"message,omitempty"`
	Status  int    `json:"status,omitempty"`

Error ...

type EventsResponse

type EventsResponse struct {
	Events []*events.Event `json:"events"`
	Index  int64           `json:"idx"`

EventsResponse ...

type InviteResponse

type InviteResponse struct {
	Sender    keys.ID `json:"sender"`
	Recipient keys.ID `json:"recipient"`

InviteResponse ...

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 MessagesResponse

type MessagesResponse struct {
	Messages []*events.Event `json:"msgs"`
	Index    int64           `json:"idx"`

MessagesResponse ...

type Metadata

type Metadata struct {
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`

Metadata ...

type Redis

type Redis interface {
	// Get returns value at key.
	Get(ctx context.Context, k string) (string, error)
	// Put puts a value at key.
	Set(ctx context.Context, k string, v string) error
	// Delete key.
	Delete(ctx context.Context, k string) error
	// Expire key.
	Expire(ctx context.Context, k string, dt time.Duration) error
	// Increment value at key.
	Increment(ctx context.Context, k string) (int64, error)

Redis defines interface for memcache. Used to prevent nonce re-use for authenticated requests.

func NewRedisTest

func NewRedisTest(clock tsutil.Clock) Redis

NewRedisTest returns Redis for testing.

type Response

type Response struct {
	Error *Error `json:"error,omitempty"`

Response ...

type SigchainResponse

type SigchainResponse struct {
	KID        keys.ID             `json:"kid"`
	Metadata   map[string]Metadata `json:"md,omitempty"`
	Statements []*keys.Statement   `json:"statements"`

SigchainResponse is the response format for a Sigchain request.

func (SigchainResponse) MetadataFor

func (r SigchainResponse) MetadataFor(st *keys.Statement) Metadata

MetadataFor returns metadata for Signed.

func (SigchainResponse) Sigchain

func (r SigchainResponse) Sigchain() (*keys.Sigchain, error)

Sigchain from response.

type User

type User struct {
	ID         string      `json:"id,omitempty"`
	Name       string      `json:"name,omitempty"`
	KID        keys.ID     `json:"kid,omitempty"`
	Seq        int         `json:"seq,omitempty"`
	Service    string      `json:"service,omitempty"`
	URL        string      `json:"url,omitempty"`
	Status     user.Status `json:"status,omitempty"`
	VerifiedAt int64       `json:"verifiedAt,omitempty"`
	Timestamp  int64       `json:"ts,omitempty"`
	MatchField string      `json:"mf,omitempty"`
	Err        string      `json:"err,omitempty"`

User ...

func UserFromResult

func UserFromResult(result *user.Result) *User

UserFromResult returns User from user.Result.

func UserFromSearchResult

func UserFromSearchResult(sr *user.SearchResult) *User

UserFromSearchResult returns User from user.SearchResult.

type UserResponse

type UserResponse struct {
	User *User `json:"user"`

UserResponse ...

type UserSearchResponse

type UserSearchResponse struct {
	Users []*User `json:"users"`

UserSearchResponse ...

type VaultResponse

type VaultResponse struct {
	Vault []*events.Event `json:"vault"`
	Index int64           `json:"idx"`

VaultResponse ...

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

Jump to identifier

Keyboard shortcuts

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