server

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadSchema

func LoadSchema(_db *sql.DB) error

Types

type AddDeviceParams

type AddDeviceParams struct {
	UserId    int64
	WalletId  int64
	UserAgent string
}

type AddWalletParams

type AddWalletParams struct {
	UserId        int64
	PublicAddress string
	Share         string
	Params        json.RawMessage
}

type Config

type Config struct {
	DevMode         bool
	Port            int
	DbConnectionUrl string
	ClientOrigin    string
	AuthType        string
	AuthServerUrl   string
	SupabaseUrl     string
	SupabaseApiKey  string
}

type DBTX

type DBTX interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

type Device

type Device struct {
	ID        int64
	UserID    int64
	WalletID  int64
	UserAgent string
}

type GetUserSigningParametersRow

type GetUserSigningParametersRow struct {
	ID            sql.NullInt64
	UserID        sql.NullInt64
	PublicAddress sql.NullString
	Share         sql.NullString
	Params        pqtype.NullRawMessage
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) AddDevice

func (q *Queries) AddDevice(ctx context.Context, arg AddDeviceParams) (Device, error)

func (*Queries) AddUser

func (q *Queries) AddUser(ctx context.Context, foreignKey string) (User, error)

----- INSERTS -------

func (*Queries) AddWallet

func (q *Queries) AddWallet(ctx context.Context, arg AddWalletParams) (Wallet, error)

func (*Queries) GetFirstUser

func (q *Queries) GetFirstUser(ctx context.Context) (User, error)

----- SELECTS -------

func (*Queries) GetUserByAddress

func (q *Queries) GetUserByAddress(ctx context.Context, publicaddress string) (User, error)

func (*Queries) GetUserByForeignKey

func (q *Queries) GetUserByForeignKey(ctx context.Context, foreignkey string) (User, error)

func (*Queries) GetUserDevices

func (q *Queries) GetUserDevices(ctx context.Context, userid int64) ([]Device, error)

func (*Queries) GetUserSigningParameters

func (q *Queries) GetUserSigningParameters(ctx context.Context, foreignkey string) (GetUserSigningParametersRow, error)

func (*Queries) GetUserWallets

func (q *Queries) GetUserWallets(ctx context.Context, userid int64) ([]Wallet, error)

func (*Queries) GetWalletByAddress

func (q *Queries) GetWalletByAddress(ctx context.Context, publicaddress string) (Wallet, error)

func (*Queries) Status

func (q *Queries) Status(ctx context.Context) (interface{}, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx *sql.Tx) *Queries

type Server

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

func NewServer

func NewServer(queries *Queries, config *Config, logging bool) *Server

NewServer creates a new server object used in the "cmd" package and in tests

func (*Server) AuthorizeHandler

func (server *Server) AuthorizeHandler(w http.ResponseWriter, r *http.Request)

AuthorizeHandler is responsible for creating an access token allowing for a tss request to be performed It uses identityMiddleware to get the userId from auth provider based on a generic bearer token provided by the client It then creates an access token linked to that userId, stores it in cache and returns it

func (*Server) CustomAuth

func (server *Server) CustomAuth(token string) (string, error)

CustomAuth gets the userId from a generic CustomAuth auth provider, based on a token representing a session or connexion Calls the generic CustomAuth auth provider using the webhook provided (server config) with pre-established API contract

func (*Server) DkgHandler

func (server *Server) DkgHandler(w http.ResponseWriter, r *http.Request)

DkgHandler performs the dkg process from the server side goes through the authMiddleware to confirm the access token and get the userId stores the result of dkg in DB (new wallet)

func (*Server) IdentifyHandler

func (server *Server) IdentifyHandler(w http.ResponseWriter, r *http.Request)

IdentifyHandler is responsible for getting a unique identifier of a user from the auth provider It uses identityMiddleware to get the userId from auth provider based on a generic bearer token provided by the client, then returns it

func (*Server) RetrieveWallet

func (server *Server) RetrieveWallet(foreignKey string) (*tss.DkgResult, error)

RetrieveWallet retrieves a wallet from DB based on the userID of the user (which is a loose foreign key, the format will depend on the auth provider) Tested in integration tests (with throw away db)

func (*Server) Router

func (server *Server) Router() http.Handler

Router returns the router of the server (useful for tests)

func (*Server) RpcHandler

func (server *Server) RpcHandler(w http.ResponseWriter, r *http.Request)

RpcHandler is used for debug operations : it logs every RPC-JSON requests and the return value

func (*Server) ServeWasm

func (server *Server) ServeWasm(w http.ResponseWriter, r *http.Request)

ServeWasm is responsible for serving the wasm module

func (*Server) SignHandler

func (server *Server) SignHandler(w http.ResponseWriter, r *http.Request)

SignHandler performs the signing process from the server side goes through the authMiddleware to confirm the access token and get the userId requires a hex-encoded message to be signed (provided in URL parameter)

func (*Server) Start

func (server *Server) Start()

Start starts the web server on given port

func (*Server) StoreWallet

func (server *Server) StoreWallet(userAgent string, userId string, dkgResults *tss.DkgResult) error

StoreWallet upserts a wallet (if it already exists, it does nothing, no error returned) Tested in integration tests (with throw away db)

func (*Server) Supabase

func (server *Server) Supabase(jwt string) (string, error)

Supabase calls Supabase server (address and API key in server config) to get the userId, based on the Supabase JWT provided

type SupabaseUser

type SupabaseUser struct {
	ID string `json:"id"`
}

type User

type User struct {
	ID         int64
	ForeignKey string
}

type Wallet

type Wallet struct {
	ID            int64
	UserID        int64
	PublicAddress string
	Share         string
	Params        json.RawMessage
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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