Skip to content

feat(contracts): add access history tracking to AccessControl#132

Open
Mercy017 wants to merge 1 commit into
GuardZero144:mainfrom
Mercy017:feat/access-control-history-92
Open

feat(contracts): add access history tracking to AccessControl#132
Mercy017 wants to merge 1 commit into
GuardZero144:mainfrom
Mercy017:feat/access-control-history-92

Conversation

@Mercy017

Copy link
Copy Markdown

Summary

Closes #92.

AccessControl already covered permission definition, access checking, grant logic, and revocation logic — the one missing acceptance criterion was history tracking. This adds it.

Changes

  • New AccessHistoryEntry (permission_id, grantee, resource_id, actor, action, timestamp) appended on every grant_access / revoke_access / extend_access, plus a new get_access_history(permission_id) query returning the full log oldest-first.
  • New AccessControlEvent (Granted / Revoked / Extended) published on each action for off-chain observability — mirrors the env.events().publish pattern verification.rs already uses for revocation.
  • History entries live in persistent storage (TTL-bumped, ~31 day extend), not instance storage, so reading/writing history doesn't serialize the contract's entire instance data set — mirroring the perf pattern already established for verification.rs (see docs/PERFORMANCE.md). Existing permission records are left on instance storage as-is; refactoring those is a separate concern, out of scope here.
  • A dedicated AccessDataKey::History(u64) key type keeps the new persistent entries in their own storage namespace so they can't collide with the existing ad hoc tuple/string keys used for permission records.

Tests

4 new integration tests in integration_tests.rs:

  • a single grant records one history entry
  • grant + extend + revoke append three entries in the correct order
  • an unknown permission_id returns empty history
  • history is correctly isolated per permission_id

Acceptance criteria

  • Permissions are defined (pre-existing)
  • Access is checked (pre-existing)
  • Grants work (pre-existing)
  • Revocation works (pre-existing)
  • History is tracked (new, this PR)

Verification

  • cargo fmt -- --check — clean
  • cargo clippy --all-targets -- -D warnings — clean
  • cargo test --features testutils — 125 passed, 0 failed (includes the 4 new tests)
  • cargo build --release --target wasm32-unknown-unknown — succeeds

Note: only the test-snapshot files affected by this change are included. Several other pre-existing, unrelated tests in integration_tests.rs (credential-sharing flows) had no committed snapshot yet in this checkout and generated new local snapshot files on the full test run — those are left untouched here to keep this PR scoped to #92.

Adds the missing acceptance criterion from GuardZero144#92: grant_access, revoke_access,
and extend_access already covered permission definition, access checking,
grant logic, and revocation logic, but nothing tracked access history.

- New AccessHistoryEntry (permission_id, grantee, resource_id, actor, action,
  timestamp) appended on every grant/revoke/extend, plus a new
  get_access_history(permission_id) query returning the full log oldest-first.
- New AccessControlEvent (Granted/Revoked/Extended) published on each action
  for off-chain observability, following the same env.events().publish
  pattern verification.rs already uses for revocation.
- History entries live in persistent storage (TTL-bumped, ~31 day extend),
  not instance storage, so reading/writing history doesn't serialize the
  contract's whole instance data set - mirroring the perf pattern already
  established for verification.rs's persistent-storage migration
  (docs/PERFORMANCE.md). Existing permission records are left on instance
  storage as before; refactoring those is out of scope here.
- A dedicated AccessDataKey::History(u64) key type keeps the new persistent
  entries in their own storage namespace, so they can't collide with the
  existing ad hoc tuple/string keys used for permission records.

4 new integration tests cover: a single grant recording one entry, grant+
extend+revoke appending three entries in order, an empty history for an
unknown permission_id, and per-permission isolation of history.

Verified: cargo fmt --check, cargo clippy --all-targets -D warnings,
cargo test --features testutils (125 passed, includes the 4 new tests),
cargo build --release --target wasm32-unknown-unknown.

Closes GuardZero144#92
@vercel

vercel Bot commented Jul 25, 2026

Copy link
Copy Markdown

@Mercy017 is attempting to deploy a commit to the Josie's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

[Medium] Add credential access control mechanisms

1 participant