app

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

AllAppStateUpdateIntents enumerates every defined intent. Kept beside the const block so adding a new intent here is the natural place to update consumers that iterate the full domain (metrics seeding, drift tests).

View Source
var ApplicationIDRegex = regexp.MustCompile(`^[a-z0-9_-]{1,66}$`)

ApplicationIDRegex bounds the advisory application identifier to lowercase letters, digits, dashes and underscores, 1..66 chars — matching the DB column width (VARCHAR(66), see nitronode/config/migrations/postgres/20260420000000_add_application_id_to_writes.sql).

Functions

func GenerateAppSessionIDV1

func GenerateAppSessionIDV1(definition AppDefinitionV1) (string, error)

GenerateAppSessionIDV1 generates a deterministic app session ID from the definition using ABI encoding.

func GenerateSessionKeyStateIDV1

func GenerateSessionKeyStateIDV1(userAddress, sessionKey string, version uint64) (string, error)

GenerateSessionKeyStateIDV1 generates a deterministic ID from user_address, session_key, and version.

func IsValidApplicationID added in v1.3.0

func IsValidApplicationID(id string) bool

IsValidApplicationID reports whether id is a well-formed advisory application identifier (see ApplicationIDRegex).

func PackAppSessionKeyStateV1

func PackAppSessionKeyStateV1(state AppSessionKeyStateV1) ([]byte, error)

PackAppSessionKeyStateV1 packs the session key state for signing using ABI encoding. This is used to generate a deterministic hash that the user signs when registering/updating a session key. The user_sig field is excluded from packing since it is the signature itself.

func PackAppStateUpdateV1

func PackAppStateUpdateV1(stateUpdate AppStateUpdateV1) ([]byte, error)

PackAppStateUpdateV1 packs the AppStateUpdate for signing using ABI encoding. This is used to generate a deterministic hash that participants sign when updating an app session state.

func PackCreateAppSessionRequestV1

func PackCreateAppSessionRequestV1(definition AppDefinitionV1, sessionData string) ([]byte, error)

PackCreateAppSessionRequestV1 packs the Definition and SessionData for signing using ABI encoding. This is used to generate a deterministic hash that participants sign when creating an app session.

func ValidateAppSessionKeyStateUserSigV1 added in v1.4.0

func ValidateAppSessionKeyStateUserSigV1(state AppSessionKeyStateV1) error

ValidateAppSessionKeyStateUserSigV1 verifies only UserSig over the registration payload: UserSig must recover to state.UserAddress (wallet authorizes the change). This is the revocation path (submitted expires_at <= now): the session-key holder's SessionKeySig is intentionally not required so a lost, unavailable, or malicious delegate cannot veto the wallet's revocation of its own delegation. The packed payload binds user_address, session_key, version and expires_at, so the signature authorizes exactly this revocation and cannot be replayed for another key, wallet, or version.

func ValidateAppSessionKeyStateV1 added in v1.3.0

func ValidateAppSessionKeyStateV1(state AppSessionKeyStateV1) error

ValidateAppSessionKeyStateV1 verifies both signatures over the registration payload: UserSig must recover to state.UserAddress (wallet authorizes the delegation) and SessionKeySig must recover to state.SessionKey (session-key holder proves possession). Both signatures sign the same PackAppSessionKeyStateV1(state) payload, which already binds user_address and session_key — so a signature minted for one (wallet, session_key) pair cannot be replayed for another. Used for activation, extension, and rotation (submitted expires_at > now); revocation uses ValidateAppSessionKeyStateUserSigV1.

Types

type AppAllocationV1

type AppAllocationV1 struct {
	Participant string
	Asset       string
	Amount      decimal.Decimal
}

AppAllocationV1 represents the allocation of assets to a participant in an app session.

type AppDefinitionV1

type AppDefinitionV1 struct {
	ApplicationID string
	Participants  []AppParticipantV1
	Quorum        uint8
	Nonce         uint64
}

AppDefinitionV1 represents the definition for an app session.

type AppParticipantV1

type AppParticipantV1 struct {
	WalletAddress   string
	SignatureWeight uint8
}

AppParticipantV1 represents the definition for an app participant.

type AppSessionInfoV1

type AppSessionInfoV1 struct {
	AppSessionID  string
	AppDefinition AppDefinitionV1
	IsClosed      bool
	SessionData   string
	Version       uint64
	Allocations   []AppAllocationV1
}

AppSessionInfoV1 represents information about an application session.

type AppSessionKeyStateV1

type AppSessionKeyStateV1 struct {
	// ID Hash(user_address + session_key + version)
	// UserAddress is the user wallet address
	UserAddress string
	// SessionKey is the session key address for delegation
	SessionKey string
	// Version is the version of the session key format
	Version uint64
	// ApplicationID is the application IDs associated with this session key
	ApplicationIDs []string
	// AppSessionID is the application session IDs associated with this session key
	AppSessionIDs []string
	// ExpiresAt is Unix timestamp in seconds indicating when the session key expires
	ExpiresAt time.Time
	// UserSig is the user's signature over the session key metadata to authorize the registration/update of the session key
	UserSig string
	// SessionKeySig is the session-key holder's signature over the same packed state.
	// Required at submit time so that nobody can register a session key they do not control.
	SessionKeySig string
}

AppSessionKeyStateV1 represents the state of a session key.

type AppSessionKeyValidatorV1

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

func NewAppSessionKeySigValidatorV1

func NewAppSessionKeySigValidatorV1(ownerGetter GetAppSessionKeyOwnerFuncV1) *AppSessionKeyValidatorV1

func (*AppSessionKeyValidatorV1) Recover

func (s *AppSessionKeyValidatorV1) Recover(data, sig []byte) (string, error)

func (*AppSessionKeyValidatorV1) Verify

func (s *AppSessionKeyValidatorV1) Verify(wallet string, data, sig []byte) error

type AppSessionSignerTypeV1

type AppSessionSignerTypeV1 uint8
const (
	AppSessionSignerTypeV1_Wallet     AppSessionSignerTypeV1 = 0xA1
	AppSessionSignerTypeV1_SessionKey AppSessionSignerTypeV1 = 0xA2
)

func (AppSessionSignerTypeV1) String

func (t AppSessionSignerTypeV1) String() string

type AppSessionSignerV1

type AppSessionSignerV1 struct {
	sign.Signer
	// contains filtered or unexported fields
}

func NewAppSessionKeySignerV1

func NewAppSessionKeySignerV1(signer sign.Signer) (*AppSessionSignerV1, error)

func NewAppSessionWalletSignerV1

func NewAppSessionWalletSignerV1(signer sign.Signer) (*AppSessionSignerV1, error)

func (*AppSessionSignerV1) Sign

func (s *AppSessionSignerV1) Sign(data []byte) (sign.Signature, error)

type AppSessionStatus

type AppSessionStatus uint8
const (
	AppSessionStatusVoid AppSessionStatus = iota
	AppSessionStatusOpen
	AppSessionStatusClosed
)

func (*AppSessionStatus) Scan

func (s *AppSessionStatus) Scan(src any) error

func (AppSessionStatus) String

func (status AppSessionStatus) String() string

type AppSessionV1

type AppSessionV1 struct {
	SessionID     string
	ApplicationID string
	Participants  []AppParticipantV1
	Quorum        uint8
	Nonce         uint64
	Status        AppSessionStatus
	Version       uint64
	SessionData   string
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

AppSessionV1 represents an application session in the V1 API.

type AppStateUpdateIntent

type AppStateUpdateIntent uint8
const (
	AppStateUpdateIntentOperate AppStateUpdateIntent = iota
	AppStateUpdateIntentDeposit
	AppStateUpdateIntentWithdraw
	AppStateUpdateIntentClose
)

func (AppStateUpdateIntent) String

func (intent AppStateUpdateIntent) String() string

type AppStateUpdateV1

type AppStateUpdateV1 struct {
	AppSessionID string
	Intent       AppStateUpdateIntent
	Version      uint64
	Allocations  []AppAllocationV1
	SessionData  string
}

AppStateUpdateV1 represents the current state of an application session.

type AssetAllowanceV1

type AssetAllowanceV1 struct {
	Asset     string
	Allowance decimal.Decimal
	Used      decimal.Decimal
}

AssetAllowanceV1 represents an asset allowance with usage tracking.

type GetAppSessionKeyOwnerFuncV1

type GetAppSessionKeyOwnerFuncV1 func(sessionKeyAddr string) (string, error)

type SessionKeyV1

type SessionKeyV1 struct {
	ID          uint
	SessionKey  string
	Application string
	Allowances  []AssetAllowanceV1
	Scope       *string
	ExpiresAt   time.Time
	CreatedAt   time.Time
}

SessionKeyV1 represents a session key with spending allowances.

type SignedAppStateUpdateV1

type SignedAppStateUpdateV1 struct {
	AppStateUpdate AppStateUpdateV1
	QuorumSigs     []string
}

SignedAppStateUpdateV1 represents a signed application session state update.

Jump to

Keyboard shortcuts

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