Skip to content

feat: implement session key management contract#9

Open
Emmy123222 wants to merge 1 commit into
Exquisitech:mainfrom
Emmy123222:feat/session-key-contract
Open

feat: implement session key management contract#9
Emmy123222 wants to merge 1 commit into
Exquisitech:mainfrom
Emmy123222:feat/session-key-contract

Conversation

@Emmy123222

Copy link
Copy Markdown

Replaces the counter stub with a full session key contract that enables frontends to perform on-chain actions via scoped, time-bound session keys rather than requiring the wallet owner to sign every transaction.

Functions implemented:

  • create_session(user, session_key, expires_at, allowed_actions) Requires wallet owner auth. Stores session data keyed by session_key for O(1) lookup. Rejects sessions expiring in the past. Bumps persistent storage TTL to cover the full session lifetime.

  • revoke_session(user, session_key) Requires wallet owner auth. Validates caller is the session owner. Idempotent — silently succeeds if session already absent.

  • validate_session(session_key, action) → bool Never panics. Returns false for missing, expired, or out-of-scope sessions. Enforces action whitelist so session keys cannot transfer assets outside platform-defined scopes.

  • get_session(session_key) → Option Off-chain inspection helper.

Storage: DataKey::Session(Address) → SessionData gives direct O(1) key-value access with no secondary indexes.

Tests: 9 unit tests + 2 integration tests covering all acceptance criteria (scope enforcement, expiry, owner-only auth, idempotency).

Closes #6

Replaces the counter stub with a full session key contract that enables
frontends to perform on-chain actions via scoped, time-bound session keys
rather than requiring the wallet owner to sign every transaction.

Functions implemented:
- create_session(user, session_key, expires_at, allowed_actions)
  Requires wallet owner auth. Stores session data keyed by session_key
  for O(1) lookup. Rejects sessions expiring in the past. Bumps
  persistent storage TTL to cover the full session lifetime.

- revoke_session(user, session_key)
  Requires wallet owner auth. Validates caller is the session owner.
  Idempotent — silently succeeds if session already absent.

- validate_session(session_key, action) → bool
  Never panics. Returns false for missing, expired, or out-of-scope
  sessions. Enforces action whitelist so session keys cannot transfer
  assets outside platform-defined scopes.

- get_session(session_key) → Option<SessionData>
  Off-chain inspection helper.

Storage: DataKey::Session(Address) → SessionData gives direct O(1)
key-value access with no secondary indexes.

Tests: 9 unit tests + 2 integration tests covering all acceptance
criteria (scope enforcement, expiry, owner-only auth, idempotency).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

implement wallet authentication and session management

1 participant