source_weaver_3-contract-lab/docs/RepositoryInterface.md

59 lines
2.6 KiB
Markdown

## Overview
The `RepositoryInterface` defines a standardized smart contract interface for managing decentralized repositories in the Source Weaver research ecosystem. It provides a flexible mechanism for creating, updating, and managing repository entries with granular access controls.
## Interface
| Function | Parameters | Return | Description |
|----------|------------|--------|-------------|
| `createRepository` | `name` (string), `description` (string), `accessLevel` (AccessLevel) | `repositoryId` (bytes32) | Create a new repository with specified visibility |
| `addRepositoryEntry` | `repositoryId` (bytes32), `contentHash` (bytes32), `metadata` (string) | `entryId` (bytes32) | Add a new entry to an existing repository |
| `updateRepositoryEntry` | `repositoryId` (bytes32), `entryId` (bytes32), `newContentHash` (bytes32), `newMetadata` (string) | `void` | Update an existing repository entry |
| `getRepositoryEntry` | `repositoryId` (bytes32), `entryId` (bytes32) | `RepositoryEntry` | Retrieve details of a specific repository entry |
| `hasRepositoryPermission` | `repositoryId` (bytes32), `user` (address) | `bool` | Check user's permission to modify a repository |
| `getRepositoryEntryCount` | `repositoryId` (bytes32) | `uint256` | Get total number of entries in a repository |
## Events
- `RepositoryCreated`: Emitted when a new repository is created
- `RepositoryUpdated`: Triggered when a repository entry is modified
- `EntryAdded`: Fired when a new entry is added to a repository
## Storage Layout
- Repositories stored as mappings with `bytes32` identifiers
- Each repository contains:
- Owner address
- Content hash
- Creation timestamp
- Last update timestamp
- Active status
- Metadata
## Access Control
- Three access levels: PRIVATE, SHARED, PUBLIC
- Permission checks via `hasRepositoryPermission`
- Owner-based access management
- Granular entry-level controls
## Security Considerations
- Use `bytes32` for content hashing to prevent collision
- Implement strict permission checks
- Validate input parameters
- Use access modifiers to restrict sensitive functions
- Consider rate limiting repository modifications
## Deployment
- **Network**: ChunkNet DevNet
- **RPC URL**: https://rpc.chunknet.org
- **Chain ID**: 214562
- **Recommended Deployment Steps**:
1. Set environment variable `CHUNK_CHAIN_RPC_URL`
2. Use hardhat/foundry with correct network configuration
3. Verify contract on ChunkNet explorer
## Testing
- Unit test repository creation
- Validate access control scenarios
- Test entry addition and updates
- Verify event emissions
- Check boundary conditions and edge cases
- Perform security and gas optimization audits