Commit 0982df8
authored
feat(permission0): implement re-delegation for namespaces (#127)
This patch introduces the first version of namespace permission
re-delegation.
Closes CHAIN-107.
# Interface Changes: Permission Redelegation and Cascading Revocation
## Extrinsic Signature Changes
### `delegate_namespace_permission` - BREAKING CHANGE
```rust
// BEFORE
pub fn delegate_namespace_permission(
origin: OriginFor<T>,
recipient: T::AccountId,
paths: BoundedBTreeSet<NamespacePathInner, T::MaxNamespacesPerPermission>,
duration: PermissionDuration<T>,
revocation: RevocationTerms<T>,
) -> DispatchResult
// AFTER
pub fn delegate_namespace_permission(
origin: OriginFor<T>,
recipient: T::AccountId,
paths: BoundedBTreeMap<
Option<PermissionId>, // Parent permission (None for root)
BoundedBTreeSet<NamespacePathInner, T::MaxNamespacesPerPermission>,
T::MaxNamespacesPerPermission,
>, // Now supports inheritance from parent permissions
duration: PermissionDuration<T>,
revocation: RevocationTerms<T>,
instances: u32, // ADDED: Max re-delegation capacity
) -> DispatchResult
```
## Structure Changes
### `PermissionContract<T>` - BREAKING CHANGES
```rust
// BEFORE
pub struct PermissionContract<T: Config> {
...
pub parent: Option<PermissionId>, // REMOVED
}
// AFTER
pub struct PermissionContract<T: Config> {
...
pub max_instances: u32, // ADDED: Controls re-delegation capacity
pub children: BoundedBTreeSet<H256, T::MaxChildrenPerPermission>, // ADDED: Enables cascading revocation
}
```
### `NamespaceScope<T>` - BREAKING CHANGE
```rust
// BEFORE
pub struct NamespaceScope<T: Config> {
pub paths: BoundedBTreeSet<NamespacePath, T::MaxNamespacesPerPermission>,
}
// AFTER
pub struct NamespaceScope<T: Config> {
pub paths: BoundedBTreeMap<
Option<PermissionId>, // Parent permission that granted these paths.
// None if path belongs to delegator itself
BoundedBTreeSet<NamespacePath, T::MaxNamespacesPerPermission>,
T::MaxNamespacesPerPermission,
>,
}
```
## Behavioral Changes
### Instance Management
- `max_instances` controls how many child permissions can be created
- Each child consumes instances from parent, preventing unlimited
delegation
### Inheritance Validation
- Child permissions must have weaker or equal revocation terms than
parent
- Namespace paths must be accessible through parent permissions
- Supports granular delegation of more specific namespaces
### Cascading Revocation
- Revoking a permission automatically revokes ALL child permissions
recursively
- Multiple `PermissionRevoked` events emitted for each revoked
permission
## Migration Impact
- All existing permissions get `max_instances = 1` and empty `children`
set
## Client SDK Requirements
1. Update `delegate_namespace_permission` call construction
2. Handle new error variants in error handling
3. Update struct parsing for `PermissionContract` and `NamespaceScope`
4. Change event listening from `Permissiondelegated` to
`PermissionDelegated`
5. Use accessor methods instead of direct field access
6. Implement cascading revocation event handling
7. Add hierarchy validation using `RevocationTerms::is_weaker()`1 parent ab724df commit 0982df8
File tree
23 files changed
+2258
-701
lines changed- .zed
- docs
- changes
- pallets
- faucet/tests
- governance/tests
- permission0
- src
- ext
- permission
- tests
- torus0
- api/src
- src
- tests
- runtime/src
- scripts
- test-utils/src
23 files changed
+2258
-701
lines changedWhitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
24 | 43 | | |
25 | 44 | | |
26 | 45 | | |
27 | 46 | | |
28 | 47 | | |
29 | 48 | | |
30 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
31 | 54 | | |
32 | 55 | | |
33 | 56 | | |
| |||
152 | 175 | | |
153 | 176 | | |
154 | 177 | | |
155 | | - | |
| 178 | + | |
0 commit comments