keychain

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Overview

Package keychain is an SDK for building Keychain on the Warden Protocol blockchain.

To learn more about the Warden Protocol, visit https://docs.wardenprotocol.com/.

For an example of an application built using this SDK, see the `wardenkms/` folder.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

App is the Keychain application. It is responsible for handling key requests and sign requests. Use NewApp to create a new instance.

func NewApp

func NewApp(config Config) *App

NewApp creates a new Keychain application, using the given configuration.

func (*App) ConnectionState

func (a *App) ConnectionState() connectivity.State

ConnectionState returns the current state of the gRPC connection.

func (*App) SetKeyRequestHandler

func (a *App) SetKeyRequestHandler(handler KeyRequestHandler)

SetKeyRequestHandler sets the handler for key requests.

func (*App) SetSignRequestHandler

func (a *App) SetSignRequestHandler(handler SignRequestHandler)

SetSignRequestHandler sets the handler for sign requests.

func (*App) Start

func (a *App) Start(ctx context.Context) error

Start starts the Keychain application and blocks until the context is done.

type Config

type Config struct {
	// Logger is the logger to use for the Keychain.
	// If nil, no logging will be done.
	Logger *slog.Logger

	// ChainID is the chain ID of the chain to connect to.
	ChainID string

	// GRPCURL is the URL of the gRPC server to connect to.
	// e.g. "localhost:9090"
	GRPCURL string

	// GRPCInsecure determines whether to allow an insecure connection to the
	// gRPC server.
	GRPCInsecure bool

	// KeychainID is the ID of the keychain this instance will fetch requests
	// for.
	KeychainID uint64

	// Mnemonic is the mnemonic to use to derive this Keychain's writer private
	// key.
	Mnemonic string

	// BatchInterval is the time to wait before sending a batch of requests to
	// the blockchain. Tipically, this interval should be set to the average
	// block time of the chain.
	BatchInterval time.Duration

	// BatchSize is the maximum number of requests to batch together before
	// sending them to the blockchain.
	BatchSize int

	// GasLimit is the maximum amount of gas to use for each transaction.
	//
	// This value is tied to [BatchSize], as the more messages in a batch, the
	// more gas is needed.
	GasLimit uint64

	// TxFees are the coins used as fees for the outgoing transactions of this
	// Keychain.
	TxFees sdk.Coins

	// TxTimeout is the amount of time to wait for a transaction to be included
	// in a block after having broadcasted it.
	//
	// If the transaction isn't included in a block, it will be considered as
	// failed (but the blockchain might still include in a block later).
	TxTimeout time.Duration
}

Config is the configuration for the Keychain.

type KeyRequest

type KeyRequest wardentypes.KeyRequest

KeyRequest is a key request.

type KeyRequestHandler

type KeyRequestHandler func(w KeyResponseWriter, req *KeyRequest)

KeyRequestHandler is a function that handles key requests.

type KeyResponseWriter

type KeyResponseWriter interface {
	// Fulfil writes a public key to the key request.
	Fulfil(publicKey []byte) error

	// Reject writes a human-readable reason for rejecting the key request.
	Reject(reason string) error
}

KeyResponseWriter is the interface for writing responses to key requests.

type SignRequest

type SignRequest wardentypes.SignRequest

SignRequest is a sign request.

type SignRequestHandler

type SignRequestHandler func(w SignResponseWriter, req *SignRequest)

SignRequestHandler is a function that handles sign requests.

type SignResponseWriter

type SignResponseWriter interface {
	// Fulfil writes the signature to the sign request.
	Fulfil(signature []byte) error

	// Reject writes a rejection to the sign request.
	Reject(reason string) error
}

SignaResponseWriter is the interface for writing responses to sign requests.

Directories

Path Synopsis
internal
enc

Jump to

Keyboard shortcuts

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