selfsdk

package module
v0.0.0-...-96bc9f9 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 23 Imported by: 4

README

Self Go SDK

Go Reference CI Go Report Card

The official Self SDK for Go.

This SDK provides access to the following self services:

  • Authentication: For authenticating users
  • Identity: For looking up identities, apps, devices, public keys
  • Fact: For requesting information from identities or intemediaries
  • Messaging: For building services to interact with other entities

Installation

Dependencies
Self OMEMO

End-to-end encryption protocol. Refer to the Installing a released version for installation instructions on different OSS.

Install
go get github.com/joinself/self-go-sdk

Usage

Register Application

Before the SDK can be used you must first register an application on the Self Developer Portal. Once registered, the portal will generate credentials for the application that the SDK will use to authenticate against the Self network.

Self provides two isolated networks:

Developer Portal (production network) - Suitable for production services
Developer Portal (sandbox network) - Suitable for testing and experimentation

Register your application using one of the links above (further information).

Examples
Client setup
import "github.com/joinself/self-go-sdk"

func main() {
    cfg := selfsdk.Config{
        SelfAppID:           "<application-id>",
        SelfAppDeviceSecret: "<application-secret-key>",
        StorageDir:          "/data",
        StorageKey:          "random-secret-string",
        Environment:         "sandbox",  // optional (defaults to production)
    }

    client, err := selfsdk.New(cfg)
    client.Start()
}
Identities

The identities service provides functionality for looking up identities, devices and public keys.

To query an identity:

import "github.com/joinself/self-go-sdk"

func main() {
    svc := client.IdentityService()

    identity, err := svc.GetIdentity("<self-id>")
    ...
}
Facts

The fact service can be used to ask for specific attested facts from an identity. These requests can be sent to the identity directly, or via an intermediary if you would prefer not to see the users personal information directly, but would like to know it satisfies a given criteria.

For detailed examples of fact requests:

To directly ask an identity for facts:

import (
    "github.com/joinself/self-go-sdk"
    "github.com/joinself/self-go-sdk/fact"
)

func main() {
    svc := client.FactService()

    req := fact.FactRequest{
        ...
    }

    resp, err := svc.Request(&req)
    ...
}
Authentication

The authentication service can be used to send an authentication challenge to a users device. The response the user sends will be signed by their identity and can be validated. You can authenticate a client by two means; If you know the self id of the user you wish to authenticate, you can do it directly. Alternatively, if you do not know the identity of the user, you can generate and display a qr code that can be read by the users device.

For detailed examples of authentication requests:

To authenticate a user directly:

import (
    "github.com/joinself/self-go-sdk"
)

func main() {
    svc := client.AuthenticationService()

    err = svc.Request("<self-id>")
    ...
}

Documentation

Support

Looking for help? Reach out to us at support@joinself.com

Contributing

See Contributing.

License

See License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client handles all interactions with self services

func New

func New(cfg Config) (*Client, error)

New creates a new self client

func (*Client) AuthenticationService

func (c *Client) AuthenticationService() *authentication.Service

AuthenticationService returns a client for working with authentication

func (*Client) ChatService

func (c *Client) ChatService() *chat.Service

ChatService returns a client for interacting with chat

func (*Client) Close

func (c *Client) Close() error

Close gracefully closes the self client

func (*Client) DocsService

func (c *Client) DocsService() *documents.Service

DocsService returns a client for interacting with document signatures.

func (*Client) FactService

func (c *Client) FactService() *fact.Service

FactService returns a client for working with facts

func (*Client) IdentityService

func (c *Client) IdentityService() *identity.Service

IdentityService returns a client for working with identities

func (*Client) MessagingService

func (c *Client) MessagingService() *messaging.Service

MessagingService returns a client for working with messages

func (*Client) Rest

func (c *Client) Rest() RestTransport

Rest provides access to the rest client to interact used by the sdk.

func (*Client) SelfAppID

func (c *Client) SelfAppID() string

SelfAppID returns the current SelfAppID for this app.

func (*Client) Start

func (c *Client) Start() error

func (*Client) VoiceService

func (c *Client) VoiceService() *voice.Service

VoiceService returns a client for managing voice call negotiation.

type Config

type Config struct {
	SelfAppID            string
	SelfAppDeviceSecret  string
	StorageKey           string
	DeviceID             string
	StorageDir           string
	APIURL               string
	MessagingURL         string
	Environment          string
	OnConnect            func()
	OnDisconnect         func(err error)
	OnPing               func()
	ReconnectionAttempts int
	TCPDeadline          time.Duration
	RequestTimeout       time.Duration
	Connectors           *Connectors
	// contains filtered or unexported fields
}

Config configuration options for the sdk

type Connectors

type Connectors struct {
	Rest           RestTransport
	Websocket      WebsocketTransport
	Messaging      MessagingClient
	PKI            PKIClient
	Storage        Storage
	FileInteractor remoteFile
}

Connectors stores all connectors for working with different self api's

type MessagingClient

type MessagingClient interface {
	Start() bool
	Send(recipients []string, mtype string, plaintext []byte) error
	SendAsync(recipients []string, mtype string, plaintext []byte, callback func(error))
	Request(recipients []string, cid string, mtype string, data []byte, timeout time.Duration) (string, []byte, error)
	Register(cid string)
	Wait(cid string, timeout time.Duration) (string, []byte, error)
	Subscribe(msgType string, sub func(sender string, payload []byte))
	Close() error
}

MessagingClient defines the interface required for the sdk to perform operations against self's messaging service

type PKIClient

type PKIClient interface {
	GetHistory(selfID string) ([]json.RawMessage, error)
	GetDeviceKey(selfID, deviceID string) ([]byte, error)
	SetDeviceKeys(selfID, deviceID string, pkb []byte) error
}

PKIClient defines the interface required for the sdk to perform retrieving identity and device public keys from self

type RestTransport

type RestTransport interface {
	Get(path string) ([]byte, error)
	Post(path string, ctype string, data []byte) ([]byte, error)
	Put(path string, ctype string, data []byte) ([]byte, error)
	Delete(path string) ([]byte, error)
	BuildURL(path string) string
}

RestTransport defines the interface required for the sdk to perform operations against self's rest api

type Storage

type Storage interface {
	AccountCreate(inboxID string, secretKey ed25519.PrivateKey) error
	AccountOffset(inboxID string) (int64, error)
	Encrypt(from string, to []string, plaintext []byte) ([]byte, error)
	Decrypt(from, to string, offset int64, ciphertext []byte) ([]byte, error)
	Close() error
}

Storage the storage interface that is used to handle persistence across

type WebsocketTransport

type WebsocketTransport interface {
	Send(recipients []string, mtype string, priority int, data []byte) error
	SendAsync(recipients []string, mtype string, priority int, data []byte, callback func(error))
	Receive() ([]byte, string, int64, []byte, error)
	Connect() error
	Close() error
}

WebsocketTransport defines the interface required for the sdk to perform operations against self's websocket services

Jump to

Keyboard shortcuts

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