Documentation
¶
Index ¶
- func CreateHandshakeRequest(signer Manager, clientID string) (*pb.HandshakeRequest, error)
- func GetPrivateKeyHex(m Manager) string
- func VerifyHandshakeRequest(req *pb.HandshakeRequest, verifier Verifier, maxClockDrift time.Duration) error
- type Config
- type ECDSASigner
- type ECDSAVerifier
- type Manager
- type Signer
- type Verifier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateHandshakeRequest ¶
func CreateHandshakeRequest(signer Manager, clientID string) (*pb.HandshakeRequest, error)
CreateHandshakeRequest creates a handshake request with signature
func GetPrivateKeyHex ¶
GetPrivateKeyHex returns private key as hex (for saving)
func VerifyHandshakeRequest ¶
func VerifyHandshakeRequest(req *pb.HandshakeRequest, verifier Verifier, maxClockDrift time.Duration) error
VerifyHandshakeRequest verifies a handshake request
Types ¶
type Config ¶
type Config struct {
Enabled bool // Enable authentication
PrivateKey string // Hex-encoded private key
TrustedKeys map[string]string // ID -> hex public key
AllowUntrusted bool // Allow connections from untrusted keys
RequireAuth bool // Require all messages to be signed
}
Config holds auth configuration
type ECDSASigner ¶
type ECDSASigner struct {
// contains filtered or unexported fields
}
ECDSASigner implements Signer using secp256k1
func GenerateECDSASigner ¶
func GenerateECDSASigner() (*ECDSASigner, error)
GenerateECDSASigner generates a new random signer
func NewECDSASigner ¶
func NewECDSASigner(privateKey *ecdsa.PrivateKey) (*ECDSASigner, error)
NewECDSASigner creates a new signer from a private key
func NewECDSASignerFromHex ¶
func NewECDSASignerFromHex(hexKey string) (*ECDSASigner, error)
NewECDSASignerFromHex creates a signer from hex private key
func (*ECDSASigner) Address ¶
func (s *ECDSASigner) Address() string
Address returns Ethereum address
func (*ECDSASigner) PrivateKeyHex ¶
func (s *ECDSASigner) PrivateKeyHex() string
PrivateKeyHex returns the private key as hex string
func (*ECDSASigner) PublicKeyBytes ¶
func (s *ECDSASigner) PublicKeyBytes() []byte
PublicKeyBytes returns compressed public key
type ECDSAVerifier ¶
type ECDSAVerifier struct{}
ECDSAVerifier implements signature verification
func NewECDSAVerifier ¶
func NewECDSAVerifier() *ECDSAVerifier
NewECDSAVerifier creates a new verifier
func (*ECDSAVerifier) RecoverPublicKey ¶
func (v *ECDSAVerifier) RecoverPublicKey(data, signature []byte) ([]byte, error)
RecoverPublicKey recovers the public key from signature
func (*ECDSAVerifier) Verify ¶
func (v *ECDSAVerifier) Verify(data, signature, publicKey []byte) error
Verify checks if signature is valid
type Manager ¶
type Manager interface {
// Sign signs data with the private key
Sign(data []byte) (signature []byte, err error)
// Verify verifies a signature against data and public key
Verify(data, signature, publicKey []byte) error
// VerifyKnown verifies signature from a known/trusted entity
// Returns the ID of the signer if trusted, error otherwise
VerifyKnown(data, signature []byte) (signerID string, err error)
// RecoverPublicKey recovers public key from signature
RecoverPublicKey(data, signature []byte) ([]byte, error)
// AddTrustedKey adds a trusted public key with an identifier
AddTrustedKey(id string, publicKey []byte) error
// RemoveTrustedKey removes a trusted key
RemoveTrustedKey(id string) error
// IsTrusted checks if a public key is trusted
IsTrusted(publicKey []byte) bool
// PublicKeyBytes returns this manager's public key
PublicKeyBytes() []byte
// PublicKeyString returns this manager's public key as hex
PublicKeyString() string
// Address returns this manager's Ethereum address
Address() string
}
Manager manages authentication and authorization
func GenerateManager ¶
GenerateManager generates a new manager with random key
func NewManager ¶
func NewManager(privateKey *ecdsa.PrivateKey) Manager
NewManager creates a new auth manager
func NewManagerFromHex ¶
NewManagerFromHex creates manager from hex private key