security

package
v0.0.0-...-ea2125a Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package security provides request signing and verification for API authentication. It supports multiple key formats and signature algorithms.

Index

Constants

View Source
const (
	// KEY_FORMAT_HEX indicates hex-encoded keys.
	KEY_FORMAT_HEX = "hex"
	// KEY_FORMAT_JSON indicates JSON-formatted keys.
	KEY_FORMAT_JSON = "json"
	// KEY_FORMAT_BASE58 indicates Base58-encoded keys.
	KEY_FORMAT_BASE58 = "base58"

	// SIGNATURE_TYPE_SHA256 indicates SHA-256 hashing.
	SIGNATURE_TYPE_SHA256 = "SHA256"
	// SIGNATURE_TYPE_RIPEMD indicates RIPEMD-160 hashing.
	SIGNATURE_TYPE_RIPEMD = "RIPEMD"
	// SIGNATURE_TYPE_SHA512 indicates SHA-512 hashing.
	SIGNATURE_TYPE_SHA512 = "SHA512"
)

Key format and signature type constants.

Variables

View Source
var (
	// ErrConfigStorageEmpty is returned when config storage is not configured.
	ErrConfigStorageEmpty = errors.New("config storage is empty")
)

Error definitions for security operations.

Functions

This section is empty.

Types

type Config

type Config struct {
	Debug         bool   `json:"debug"`
	KeyFormat     string `json:"defaultKeyFormat"`
	SignatureType string `json:"signatureType"`
	// contains filtered or unexported fields
}

Config holds the security manager configuration.

func (*Config) Load

func (c *Config) Load() (err error)

Load reads the configuration from storage.

func (*Config) Save

func (c *Config) Save() (err error)

Save persists the configuration to storage as JSON.

type Manager

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

Manager handles request signing and security configuration.

func NewManager

func NewManager(opts ...Option) *Manager

NewManager creates a new security manager with the specified options.

func (*Manager) Init

func (m *Manager) Init() (err error)

Init initializes the security manager by loading configuration.

func (*Manager) Set

func (m *Manager) Set(opts ...Option)

Set applies additional options to the manager.

func (*Manager) SignRequest

func (m *Manager) SignRequest(apiKey string, method string, params json.RawMessage) (sign []byte, err error)

SignRequest generates a signature for an RPC request. Uses the configured key format and signature type.

type Option

type Option func(*Manager)

Option is a function that configures a Manager.

func WithStorageManager

func WithStorageManager(storageManager *storage.ModuleManager) Option

WithStorageManager sets the storage manager for configuration persistence.

Jump to

Keyboard shortcuts

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