signer

package
v0.0.0-...-6b88563 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const DirName = ".store"

DirName is the storage directory name

View Source
const (
	// SignatureChallenge byte iota
	SignatureChallenge = iota
)

Variables

This section is empty.

Functions

func StartServer

func StartServer(hold *Hold)

StartServer starts the server

Types

type Challenge

type Challenge interface {
	Check(tosign []byte) bool
	Bytes() []byte
}

Challenge interface

func NewSignatureChallenge

func NewSignatureChallenge(addresses []string, coinFamily CoinFamily) Challenge

NewSignatureChallenge creates a new signature challenge from a slice of addresses

func ReadChallenge

func ReadChallenge(data []byte, coinFamily CoinFamily) Challenge

ReadChallenge reads a challenge from bytes

type CoinFamily

type CoinFamily uint8

CoinFamily is an enum to describe the family of coin

const (
	// BitcoinFamily type (btc, ltc, bcy,doge ...)
	BitcoinFamily CoinFamily = iota
	// EthereumFamily type (eth, beth...)s
	EthereumFamily
	// UnknownCoinFamily for error purpose
	UnknownCoinFamily
)

func CoinPrefixToCoinFamily

func CoinPrefixToCoinFamily(coinPrefix string) CoinFamily

CoinPrefixToCoinFamily convert a coin family to a prefix

type FileStore

type FileStore struct{}

FileStore saves key data in files under a given directory

func MakeFileStore

func MakeFileStore() (*FileStore, error)

MakeFileStore creates the file store

func (*FileStore) Delete

func (fs *FileStore) Delete(key string) error

Delete deletes some data

func (*FileStore) ReadAll

func (fs *FileStore) ReadAll() ([][]byte, error)

ReadAll reads all the data in the file store

func (*FileStore) Save

func (fs *FileStore) Save(key string, data []byte) error

Save saves data with a key

type Hold

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

Hold holds the keys and handles their lifecycle. Decrypts the private key just for the time of computing a signature.

func MakeHold

func MakeHold(pass string, store Store, signer Signer) (*Hold, error)

MakeHold create the hold structure

func (*Hold) NewKey

func (h *Hold) NewKey(challenge Challenge, prefix byte, family CoinFamily) (string, error)

NewKey creates a new keypair and save it in the hold

func (*Hold) Sign

func (h *Hold) Sign(addr string, data []byte) ([]byte, []byte, error)

Sign an address iff the challenge pass

type KeyHold

type KeyHold interface {
	// Creates and keeps a new key pair. Unlocking it to produce a signature will require that the data
	// to sign pass the provided challenge.
	NewKey(challenge Challenge, prefix byte) (addr string, err error)

	// For a given source address and data that should pass the challenge provided when address keys were
	// created, signs that data.
	Sign(addr string, data []byte)
}

KeyHold interface

type Signer

type Signer interface {
	NewKey() (pub, priv []byte, err error)
	Sign(private, data []byte) ([]byte, error)
}

Signer interface

type SigningHandler

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

SigningHandler signing handler

func (*SigningHandler) ServeHTTP

func (sh *SigningHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Store

type Store interface {
	Save(key string, data []byte) error
	Delete(key string) error
	ReadAll() ([][]byte, error)
}

Store inteface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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