Documentation
¶
Index ¶
- func AddressFromPublicKey(pub *ecdsa.PublicKey) common.Address
- func DeserializePrivateKey(data []byte) (*ecdsa.PrivateKey, error)
- func GenerateSessionKey() (*ecdsa.PrivateKey, error)
- func SerializePrivateKey(key *ecdsa.PrivateKey) []byte
- func SerializePublicKey(pub *ecdsa.PublicKey) []byte
- type CryptoDecryptFunc
- type CryptoEncryptFunc
- type Manager
- func (m *Manager) CleanupExpired(ctx context.Context) (int, error)
- func (m *Manager) Create(ctx context.Context, policy sa.SessionPolicy, parentID string) (*sa.SessionKey, error)
- func (m *Manager) Get(ctx context.Context, id string) (*sa.SessionKey, error)
- func (m *Manager) List(ctx context.Context) ([]*sa.SessionKey, error)
- func (m *Manager) Revoke(ctx context.Context, id string) error
- func (m *Manager) RevokeAll(ctx context.Context) error
- func (m *Manager) SignUserOp(ctx context.Context, sessionID string, userOp *sa.UserOperation) ([]byte, error)
- type ManagerOption
- func WithChainID(id int64) ManagerOption
- func WithEncryption(encrypt CryptoEncryptFunc, decrypt CryptoDecryptFunc) ManagerOption
- func WithEntryPoint(addr common.Address) ManagerOption
- func WithMaxDuration(d time.Duration) ManagerOption
- func WithMaxKeys(n int) ManagerOption
- func WithOnChainRegistration(fn RegisterOnChainFunc) ManagerOption
- func WithOnChainRevocation(fn RevokeOnChainFunc) ManagerOption
- type MemoryStore
- func (s *MemoryStore) Delete(_ context.Context, id string) error
- func (s *MemoryStore) Get(_ context.Context, id string) (*sa.SessionKey, error)
- func (s *MemoryStore) List(_ context.Context) ([]*sa.SessionKey, error)
- func (s *MemoryStore) ListActive(_ context.Context) ([]*sa.SessionKey, error)
- func (s *MemoryStore) ListByParent(_ context.Context, parentID string) ([]*sa.SessionKey, error)
- func (s *MemoryStore) Save(_ context.Context, key *sa.SessionKey) error
- type RegisterOnChainFunc
- type RevokeOnChainFunc
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddressFromPublicKey ¶
AddressFromPublicKey derives the Ethereum address from a public key.
func DeserializePrivateKey ¶
func DeserializePrivateKey(data []byte) (*ecdsa.PrivateKey, error)
DeserializePrivateKey restores an ECDSA private key from bytes.
func GenerateSessionKey ¶
func GenerateSessionKey() (*ecdsa.PrivateKey, error)
GenerateSessionKey creates a new ECDSA key pair for session signing.
func SerializePrivateKey ¶
func SerializePrivateKey(key *ecdsa.PrivateKey) []byte
SerializePrivateKey serializes an ECDSA private key to bytes.
func SerializePublicKey ¶
SerializePublicKey serializes a public key to compressed bytes.
Types ¶
type CryptoDecryptFunc ¶
type CryptoDecryptFunc func( ctx context.Context, keyID string, ciphertext []byte, ) ([]byte, error)
CryptoDecryptFunc decrypts private key material.
type CryptoEncryptFunc ¶
CryptoEncryptFunc encrypts private key material.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles session key lifecycle.
func NewManager ¶
func NewManager(store Store, opts ...ManagerOption) *Manager
NewManager creates a session key manager.
func (*Manager) CleanupExpired ¶
CleanupExpired removes expired session keys and returns the count removed.
func (*Manager) Create ¶
func (m *Manager) Create( ctx context.Context, policy sa.SessionPolicy, parentID string, ) (*sa.SessionKey, error)
Create creates a new session key with the given policy. If parentID is non-empty, creates a task session (child) scoped within parent bounds.
func (*Manager) SignUserOp ¶
func (m *Manager) SignUserOp( ctx context.Context, sessionID string, userOp *sa.UserOperation, ) ([]byte, error)
SignUserOp signs a UserOperation with a session key.
type ManagerOption ¶
type ManagerOption interface {
// contains filtered or unexported methods
}
ManagerOption configures the Manager.
func WithChainID ¶ added in v0.6.0
func WithChainID(id int64) ManagerOption
WithChainID sets the chain ID for UserOp hash computation.
func WithEncryption ¶
func WithEncryption( encrypt CryptoEncryptFunc, decrypt CryptoDecryptFunc, ) ManagerOption
WithEncryption sets the encryption/decryption functions for key material.
func WithEntryPoint ¶ added in v0.6.0
func WithEntryPoint(addr common.Address) ManagerOption
WithEntryPoint sets the ERC-4337 EntryPoint address for UserOp hash computation.
func WithMaxDuration ¶
func WithMaxDuration(d time.Duration) ManagerOption
WithMaxDuration sets the maximum allowed session duration.
func WithMaxKeys ¶
func WithMaxKeys(n int) ManagerOption
WithMaxKeys sets the maximum number of active session keys.
func WithOnChainRegistration ¶
func WithOnChainRegistration(fn RegisterOnChainFunc) ManagerOption
WithOnChainRegistration sets the on-chain registration callback.
func WithOnChainRevocation ¶
func WithOnChainRevocation(fn RevokeOnChainFunc) ManagerOption
WithOnChainRevocation sets the on-chain revocation callback.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is an in-memory Store implementation.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore creates a new in-memory session key store.
func (*MemoryStore) Delete ¶
func (s *MemoryStore) Delete(_ context.Context, id string) error
Delete removes the session key with the given ID.
func (*MemoryStore) Get ¶
func (s *MemoryStore) Get(_ context.Context, id string) (*sa.SessionKey, error)
Get returns a copy of the session key with the given ID.
func (*MemoryStore) List ¶
func (s *MemoryStore) List(_ context.Context) ([]*sa.SessionKey, error)
List returns all session keys sorted by CreatedAt ascending.
func (*MemoryStore) ListActive ¶
func (s *MemoryStore) ListActive(_ context.Context) ([]*sa.SessionKey, error)
ListActive returns all session keys that are currently active.
func (*MemoryStore) ListByParent ¶
func (s *MemoryStore) ListByParent( _ context.Context, parentID string, ) ([]*sa.SessionKey, error)
ListByParent returns all session keys with the given parent ID.
func (*MemoryStore) Save ¶
func (s *MemoryStore) Save(_ context.Context, key *sa.SessionKey) error
Save stores a copy of the session key.
type RegisterOnChainFunc ¶
type RegisterOnChainFunc func( ctx context.Context, sessionAddr common.Address, policy sa.SessionPolicy, ) (string, error)
RegisterOnChainFunc registers a session key on-chain.
type RevokeOnChainFunc ¶
RevokeOnChainFunc revokes a session key on-chain.
type Store ¶
type Store interface {
Save(ctx context.Context, key *sa.SessionKey) error
Get(ctx context.Context, id string) (*sa.SessionKey, error)
List(ctx context.Context) ([]*sa.SessionKey, error)
Delete(ctx context.Context, id string) error
ListByParent(ctx context.Context, parentID string) ([]*sa.SessionKey, error)
ListActive(ctx context.Context) ([]*sa.SessionKey, error)
}
Store persists session keys.