feat: implement session key management contract#9
Open
Emmy123222 wants to merge 1 commit into
Open
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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