package direct

import "github.com/threefoldtech/rmb-sdk-go/direct"

Index

Constants

const (
	PongWait     = 40 * time.Second
	PingInterval = 20 * time.Second
)
const (
	KeyTypeEd25519 = "ed25519"
	KeyTypeSr25519 = "sr25519"
)
const (
	SignatureTypeEd25519 = "ed25519"
	SignatureTypeSr25519 = "sr25519"
)
const CustomSigning = "RMB"

Functions

func Challenge

func Challenge(env *types.Envelope) ([]byte, error)

func NewJWT

func NewJWT(identity substrate.Identity, id uint32, session string, ttl uint32) (string, error)

func Sign

func Sign(signer substrate.Identity, input []byte) ([]byte, error)

func VerifySignature

func VerifySignature(twinDB TwinDB, env *types.Envelope) error

VerifySignature is responsible for verifying that the source produced this signature

Types

type DirectClient

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

func NewClient

func NewClient(ctx context.Context, keytype string, mnemonics string, relayURL string, session string, sub *substrate.Substrate, enableEncryption bool) (*DirectClient, error)

NewClient creates a new RMB direct client. It connects directly to the RMB-Relay, and peridically tries to reconnect if the connection broke.

You can close the connection by canceling the passed context.

Make sure the context passed to Call() does not outlive the directClient's context. Call() will panic if called while the directClient's context is canceled.

func (*DirectClient) Call

func (d *DirectClient) Call(ctx context.Context, twin uint32, fn string, data interface{}, result interface{}) error

func (*DirectClient) Ping

func (d *DirectClient) Ping(ctx context.Context) error

Ping sends an application level ping. You normally do not ever need to call this yourself because this rmb client takes care of automatic pinging of the server and reconnecting if needed. But in case you want to test if a connection is active and established you can call this Ping method yourself. If no error is returned then ping has succeeded. Make sure to always provide a ctx with a timeout or a deadline otherwise the call will block forever waiting for a response.

type Ed25519VerifyingKey

type Ed25519VerifyingKey []byte

func (Ed25519VerifyingKey) Verify

func (k Ed25519VerifyingKey) Verify(msg []byte, sig []byte) bool

type InnerConnection

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

func NewConnection

func NewConnection(identity substrate.Identity, url string, session string, twinID uint32) InnerConnection

func (*InnerConnection) Start

func (c *InnerConnection) Start(ctx context.Context) (Reader, Writer)

type Reader

type Reader <-chan []byte

func (Reader) Read

func (r Reader) Read() []byte

type RmbSigner

type RmbSigner struct{}

func (*RmbSigner) Alg

func (s *RmbSigner) Alg() string

func (*RmbSigner) Sign

func (s *RmbSigner) Sign(signingString string, key interface{}) (string, error)

func (*RmbSigner) Verify

func (s *RmbSigner) Verify(signingString, signature string, key interface{}) error

type Sr25519VerifyingKey

type Sr25519VerifyingKey []byte

func (Sr25519VerifyingKey) Verify

func (k Sr25519VerifyingKey) Verify(msg []byte, sig []byte) bool

type Twin

type Twin struct {
	ID        uint32
	PublicKey []byte
	Relay     *string
	E2EKey    []byte
}

Twin is used to store a twin id and its public key

type TwinDB

type TwinDB interface {
	Get(id uint32) (Twin, error)
	GetByPk(pk []byte) (uint32, error)
}

TwinDB is used to get Twin instances

func NewTwinDB

func NewTwinDB(sub *substrate.Substrate) TwinDB

NewTwinDB creates a new twinDBImpl instance, with a non expiring cache.

type Verifier

type Verifier interface {
	Verify(msg []byte, sig []byte) bool
}

type Writer

type Writer chan<- []byte

func (Writer) Write

func (w Writer) Write(data []byte)

Source Files

connection.go direct.go hashes.go jwt.go sig.go twindb.go

Directories

PathSynopsis
direct/types
Version
v1.0.1 (latest)
Published
Apr 26, 2023
Platform
linux/amd64
Imports
31 packages
Last checked
5 months ago

Tools for package owners.