@@ -21,7 +21,13 @@ use audit_trail::{
2121 record::{Self , Record },
2222 record_tags::{Self , RecordTags }
2323};
24- use iota::{clock::{Self , Clock }, event, linked_table::{Self , LinkedTable }, vec_map::{Self , VecMap }, vec_set::VecSet };
24+ use iota::{
25+ clock::{Self , Clock },
26+ event,
27+ linked_table::{Self , LinkedTable },
28+ vec_map::{Self , VecMap },
29+ vec_set::VecSet
30+ };
2531use std::string::String ;
2632use tf_components::{capability::Capability , role_map::{Self , RoleMap }, timelock::TimeLock };
2733
@@ -243,21 +249,21 @@ public fun initial_admin_role_name(): String {
243249
244250/// Migrate the trail to the latest package version
245251entry fun migrate <D : store + copy >(
246- trail : &mut AuditTrail <D >,
252+ self : &mut AuditTrail <D >,
247253 cap: &Capability ,
248254 clock: &Clock ,
249255 ctx: &TxContext ,
250256) {
251- assert ! (trail .version < PACKAGE_VERSION , EPackageVersionMismatch );
252- trail
257+ assert ! (self .version < PACKAGE_VERSION , EPackageVersionMismatch );
258+ self
253259 .roles
254260 .assert_capability_valid (
255261 cap,
256262 &permission::migrate_audit_trail (),
257263 clock,
258264 ctx,
259265 );
260- trail .version = PACKAGE_VERSION ;
266+ self .version = PACKAGE_VERSION ;
261267}
262268
263269fun assert_record_tag_allowed <D : store + copy >(
@@ -451,12 +457,14 @@ public fun delete_audit_trail<D: store + copy>(
451457 records,
452458 mut tags,
453459 locking_config: _,
454- roles: _roles ,
460+ roles,
455461 immutable_metadata: _,
456462 updatable_metadata: _,
457463 version: _,
458464 } = self;
459465
466+ roles.destroy ();
467+
460468 linked_table::destroy_empty (records);
461469 while (!vec_map::is_empty (&tags)) {
462470 let (_, _) = vec_map::pop (&mut tags);
@@ -771,17 +779,19 @@ public fun new_capability<D: store + copy>(
771779public fun revoke_capability <D : store + copy >(
772780 self: &mut AuditTrail <D >,
773781 cap: &Capability ,
774- capability_id: ID ,
782+ cap_to_revoke: ID ,
783+ cap_to_revoke_valid_until: Option <u64 >,
775784 clock: &Clock ,
776- ctx: &mut TxContext ,
785+ ctx: &TxContext ,
777786) {
778787 assert ! (self.version == PACKAGE_VERSION , EPackageVersionMismatch );
779788 role_map::revoke_capability (
780789 self.access_mut (),
781790 cap,
782- capability_id,
791+ cap_to_revoke,
792+ cap_to_revoke_valid_until,
783793 clock,
784- ctx,
794+ ctx
785795 );
786796}
787797
@@ -831,15 +841,49 @@ public fun destroy_initial_admin_capability<D: store + copy>(
831841public fun revoke_initial_admin_capability <D : store + copy >(
832842 self: &mut AuditTrail <D >,
833843 cap: &Capability ,
834- capability_id: ID ,
844+ cap_to_revoke: ID ,
845+ cap_to_revoke_valid_until: Option <u64 >,
835846 clock: &Clock ,
836847 ctx: &mut TxContext ,
837848) {
838849 assert ! (self.version == PACKAGE_VERSION , EPackageVersionMismatch );
839850 role_map::revoke_initial_admin_capability (
840851 self.access_mut (),
841852 cap,
842- capability_id,
853+ cap_to_revoke,
854+ cap_to_revoke_valid_until,
855+ clock,
856+ ctx);
857+ }
858+
859+ /// Remove expired entries from the `revoked_capabilities` denylist.
860+ ///
861+ /// Iterates through the revoked capabilities list and removes every entry whose
862+ /// `valid_until` timestamp is **non-zero** and **less than** the current clock time,
863+ /// because those capabilities are already naturally expired and no longer need to
864+ /// occupy space in the denylist.
865+ ///
866+ /// Entries with `valid_until == 0` (i.e. capabilities that had no expiry) are kept,
867+ /// since they remain potentially valid and must stay on the denylist.
868+ ///
869+ /// Parameters
870+ /// ----------
871+ /// - cap: Reference to the capability used to authorize this operation.
872+ /// Needs to grant the `CapabilityAdminPermissions::revoke` permission.
873+ /// - clock: Reference to a Clock instance for obtaining the current timestamp.
874+ /// - ctx: Reference to the transaction context.
875+ ///
876+ /// Errors:
877+ /// - Aborts with any error documented by `assert_capability_valid` if the provided capability fails authorization checks.
878+ public fun cleanup_revoked_capabilities <D : store + copy >(
879+ self: &mut AuditTrail <D >,
880+ cap: &Capability ,
881+ clock: &Clock ,
882+ ctx: &TxContext ,
883+ ) {
884+ assert ! (self.version == PACKAGE_VERSION , EPackageVersionMismatch );
885+ self.access_mut ().cleanup_revoked_capabilities (
886+ cap,
843887 clock,
844888 ctx,
845889 );
@@ -938,13 +982,13 @@ public fun records<D: store + copy>(self: &AuditTrail<D>): &LinkedTable<u64, Rec
938982}
939983// ===== Access Control Functions =====
940984
941- /// Returns the RoleMap managing access for the audit trail.
985+ /// Returns a reference to the RoleMap managing access (roles and capabilities) for the audit trail.
942986public fun access <D : store + copy >(self: &AuditTrail <D >): &RoleMap <Permission , RecordTags > {
943987 assert ! (self.version == PACKAGE_VERSION , EPackageVersionMismatch );
944988 &self.roles
945989}
946990
947- /// Returns a mutable reference to the RoleMap managing access for the audit trail.
991+ /// Returns a mutable reference to the RoleMap managing access (roles and capabilities) for the audit trail.
948992public (package ) fun access_mut <D : store + copy >(
949993 self: &mut AuditTrail <D >,
950994): &mut RoleMap <Permission , RecordTags > {
0 commit comments