session

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddressFromPublicKey

func AddressFromPublicKey(pub *ecdsa.PublicKey) common.Address

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

func SerializePublicKey(pub *ecdsa.PublicKey) []byte

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

type CryptoEncryptFunc func(
	ctx context.Context, keyID string, plaintext []byte,
) ([]byte, error)

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

func (m *Manager) CleanupExpired(ctx context.Context) (int, error)

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) Get

func (m *Manager) Get(
	ctx context.Context, id string,
) (*sa.SessionKey, error)

Get retrieves a session key by ID.

func (*Manager) List

func (m *Manager) List(ctx context.Context) ([]*sa.SessionKey, error)

List returns all session keys.

func (*Manager) Revoke

func (m *Manager) Revoke(ctx context.Context, id string) error

Revoke revokes a session key and all its children.

func (*Manager) RevokeAll

func (m *Manager) RevokeAll(ctx context.Context) error

RevokeAll revokes all active session keys.

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

type RevokeOnChainFunc func(
	ctx context.Context, sessionAddr common.Address,
) (string, error)

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.

Jump to

Keyboard shortcuts

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