api

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2021 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSigningMethod = errors.New("invalid signing method")
	ErrTokenNotValid        = errors.New("token not valid")
	ErrTokenTimeNotValid    = errors.New("token time not valid")
	ErrSubjectNotValid      = errors.New("subject not valid")
)

Error codes

Functions

func CanonicalHost

func CanonicalHost(host string) string

CanonicalHost returns a given host in the form of http(s)://<host>:<port>

func GenerateJWTToken

func GenerateJWTToken(addr hash.Hash, key bmcrypto.PrivKey) (string, error)

GenerateJWTToken generates a JWT token with the address and singed by the given private key

func GetErrorFromResponse

func GetErrorFromResponse(body []byte) error

GetErrorFromResponse will return an error generated from the body

func IsJWTTokenExpired

func IsJWTTokenExpired(tokenString string) bool

IsJWTTokenExpired will check if the token is already expired

func ValidateJWTToken

func ValidateJWTToken(tokenString string, addr hash.Hash, key bmcrypto.PubKey) (*jwt.Token, error)

ValidateJWTToken validates a JWT token with the given public key and address

Types

type API

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

API is a structure to connect to the server for the given account

func NewAnonymous

func NewAnonymous(host string, f serverErrorFunc) (*API, error)

NewAnonymous creates a new client that connects anonymously to a BitMaelum server (normally server-to-server communications)

func NewAuthenticated

func NewAuthenticated(addr address.Address, key bmcrypto.PrivKey, host string, f serverErrorFunc) (*API, error)

NewAuthenticated creates a new client that connects to a BitMaelum Server with specific credentials (normally client-to-server communications)

func NewClient

func NewClient(opts ClientOpts) (*API, error)

NewClient creates a new client based on the given options

func (*API) CompleteUpload

func (api *API) CompleteUpload(t ticket.Ticket) error

CompleteUpload signals the mailserver that all blocks (and headers) have been uploaded and can start processing

func (*API) CreateAPIKey

func (api *API) CreateAPIKey(addrHash hash.Hash, key key.APIKeyType) error

CreateAPIKey Create a new API key

func (*API) CreateAccount

func (api *API) CreateAccount(info vault.AccountInfo, token string) error

CreateAccount creates new account on server

func (*API) CreateAuthKey

func (api *API) CreateAuthKey(addrHash hash.Hash, key key.AuthKeyType) (string, error)

CreateAuthKey will create a new authorized key on the server

func (*API) CreateWebhook

func (api *API) CreateWebhook(wh webhook.Type) (*webhook.Type, error)

CreateWebhook Create a new API key

func (*API) Delete

func (api *API) Delete(path string) (body []byte, statusCode int, err error)

Delete from API

func (*API) DeleteAPIKey

func (api *API) DeleteAPIKey(addrHash hash.Hash, ID string) error

DeleteAPIKey deletes a new API key

func (*API) DeleteAuthKey

func (api *API) DeleteAuthKey(addrHash hash.Hash, fingerprint string) error

DeleteAuthKey deletes a new auth key

func (*API) DeleteMessage

func (api *API) DeleteMessage(t ticket.Ticket) error

DeleteMessage deletes a message and all content

func (*API) DeleteWebhook

func (api *API) DeleteWebhook(addrHash hash.Hash, ID string) error

DeleteWebhook deletes a webhook

func (*API) DisableWebhook

func (api *API) DisableWebhook(addrHash hash.Hash, ID string) error

DisableWebhook will disable a webhook

func (*API) EnableWebhook

func (api *API) EnableWebhook(addrHash hash.Hash, ID string) error

EnableWebhook will enable a webhook

func (*API) GenerateAPIAttachmentReader

func (api *API) GenerateAPIAttachmentReader(addr hash.Hash) func(messageID, attachmentID string) io.Reader

GenerateAPIAttachmentReader returns a reader function that will create a reader from the given message and attachment ID.

func (*API) GenerateAPIBlockReader

func (api *API) GenerateAPIBlockReader(addr hash.Hash) func(messageID, blockID string) io.Reader

GenerateAPIBlockReader returns a reader function that will create a reader from the given message and block ID.

func (*API) Get

func (api *API) Get(path string) (body []byte, statusCode int, err error)

Get gets raw bytes from API

func (*API) GetAPIKey

func (api *API) GetAPIKey(addrHash hash.Hash, ID string) (*key.APIKeyType, error)

GetAPIKey gets a single key

func (*API) GetAccountTicket

func (api *API) GetAccountTicket(from, to hash.Hash, subscriptionID string) (*ticket.Ticket, error)

GetAccountTicket retrieves a ticket that can be used for uploading a message

func (*API) GetAuthKey

func (api *API) GetAuthKey(addrHash hash.Hash, fingerprint string) (*key.AuthKeyType, error)

GetAuthKey gets a single key

func (*API) GetJSON

func (api *API) GetJSON(path string, v interface{}) (body []byte, status int, err error)

GetJSON gets JSON result from API

func (*API) GetMailboxList

func (api *API) GetMailboxList(addr hash.Hash) (*MailboxList, error)

GetMailboxList returns a list of mailboxes

func (*API) GetMailboxMessages

func (api *API) GetMailboxMessages(addr hash.Hash, box string, since time.Time) (*MailboxMessages, error)

GetMailboxMessages returns a list of message within a specific mailbox

func (*API) GetMessage

func (api *API) GetMessage(addr hash.Hash, messageID string) (*Message, error)

GetMessage retrieves a message header + catalog from a message

func (*API) GetMessageAttachment

func (api *API) GetMessageAttachment(addr hash.Hash, messageID, attachmentID string) (io.ReadCloser, error)

GetMessageAttachment retrieves a message attachment reader

func (*API) GetMessageBlock

func (api *API) GetMessageBlock(addr hash.Hash, messageID, blockID string) (io.ReadCloser, error)

GetMessageBlock retrieves a message block

func (*API) GetPublicKey

func (api *API) GetPublicKey(addr hash.Hash) (string, error)

GetPublicKey gets public key for given address on the mail server

func (*API) GetReader

func (api *API) GetReader(path string) (r io.ReadCloser, statusCode int, err error)

GetReader returns a io.Reader from the API. It is the same as api.Get(), except this one already has read the whole body.

func (*API) GetTicket

func (api *API) GetTicket(from, to hash.Hash, subscriptionID string) (*ticket.Ticket, error)

GetTicket retrieves a ticket that can be used for uploading a message

func (*API) GetWebhook

func (api *API) GetWebhook(addrHash hash.Hash, ID string) (*webhook.Type, error)

GetWebhook gets a single webhook

func (*API) ListAPIKeys

func (api *API) ListAPIKeys(addrHash hash.Hash) ([]key.APIKeyType, error)

ListAPIKeys lists alll API keys

func (*API) ListAuthKeys

func (api *API) ListAuthKeys(addrHash hash.Hash) ([]key.AuthKeyType, error)

ListAuthKeys lists all auth keys

func (*API) ListWebhooks

func (api *API) ListWebhooks(addrHash hash.Hash) ([]webhook.Type, error)

ListWebhooks lists alll webhooks

func (*API) Post

func (api *API) Post(path string, data []byte) (body []byte, statusCode int, err error)

Post posts to API by single bytes

func (*API) PostJSON

func (api *API) PostJSON(path string, data interface{}) (body []byte, statusCode int, err error)

PostJSON posts JSON to API

func (*API) PostReader

func (api *API) PostReader(path string, r io.Reader) (body []byte, statusCode int, err error)

PostReader posts to API through a reader

func (*API) RemoveMessage

func (api *API) RemoveMessage(addr hash.Hash, messageID string) error

RemoveMessage deletes a message on the server

func (*API) StoreGetPath

func (api *API) StoreGetPath(key bmcrypto.KeyPair, addr hash.Hash, path string, recursive bool, since time.Time) (*StoreEntry, error)

StoreGetPath will fetch an entry

func (*API) StorePutValue

func (api *API) StorePutValue(key bmcrypto.KeyPair, addr hash.Hash, path string, value string) error

StorePutValue will store an value to a path

func (*API) UpdateWebhook

func (api *API) UpdateWebhook(addrHash hash.Hash, ID string, wh webhook.Type) error

UpdateWebhook will update a webhook

func (*API) UploadBlock

func (api *API) UploadBlock(t ticket.Ticket, blockID string, r io.Reader) error

UploadBlock uploads a message block or attachment

func (*API) UploadCatalog

func (api *API) UploadCatalog(t ticket.Ticket, encryptedCatalog []byte) error

UploadCatalog uploads a catalog

func (*API) UploadHeader

func (api *API) UploadHeader(t ticket.Ticket, header *message.Header) error

UploadHeader uploads a header

func (*API) ValidateTicket

func (api *API) ValidateTicket(from, to hash.Hash, subscriptionID string, t *ticket.Ticket) (*ticket.Ticket, error)

ValidateTicket will send back a ticket-result

type ClientOpts

type ClientOpts struct {
	Host          string
	AllowInsecure bool
	Address       address.Address
	Key           *bmcrypto.PrivKey
	JWTToken      string
	Debug         bool
	ErrorFunc     serverErrorFunc
}

ClientOpts allows you to configure the API client

type MailboxList

type MailboxList struct {
	Meta struct {
		Total    int `json:"total"`
		Returned int `json:"returned"`
	} `json:"meta"`
	Boxes []MailboxListBox `json:"boxes"`
}

MailboxList is a list of mailboxes

type MailboxListBox

type MailboxListBox struct {
	ID       int      `json:"id"`
	Total    int      `json:"total"`
	Messages []string `json:"messages"`
}

MailboxListBox is a structure that holds a given mailbox and the total messages inside

type MailboxMessages

type MailboxMessages struct {
	Meta struct {
		Total    int `json:"total"`
		Returned int `json:"returned"`
		Offset   int `json:"offset"`
		Limit    int `json:"limit"`
	} `json:"meta"`
	Messages []MailboxMessagesMessage `json:"messages"`
}

MailboxMessages returns a list of mailbox messages

type MailboxMessagesMessage

type MailboxMessagesMessage struct {
	ID      string         `json:"id"`
	Header  message.Header `json:"header"`
	Catalog []byte         `json:"catalog"`
}

MailboxMessagesMessage is a message (header + catalog) within a mailbox

type Message

type Message struct {
	ID      string         `json:"id"`
	Header  message.Header `json:"h"`
	Catalog []byte         `json:"c"`
}

Message is a standard structure that returns a message header + catalog

type StoreEntry

type StoreEntry struct {
	Path      hash.Hash    `json:"path"`
	Parent    *hash.Hash   `json:"parent"`
	Data      string       `json:"data"`
	Timestamp int64        `json:"timestamp"`
	Children  []StoreEntry `json:"children"`
}

StoreEntry is the unencrypted store entry with child nodes if needed

Jump to

Keyboard shortcuts

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