Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.DS_Store
node_modules
dist
348 changes: 269 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,116 +1,306 @@
# Demo Plugin - Plugin Development Framework
# πŸ” Secure Demo Plugin

This repository serves as a **template and development framework** for creating TopLocs plugins. It demonstrates how to build plugins that integrate with the TopLocs decentralized community platform.
A comprehensive demonstration of secure plugin development for the TopLocs decentralized P2P platform. This plugin showcases all security mechanisms, plugin architecture patterns, and best practices.

## Purpose
## 🎯 What This Demo Shows

The demo-plugin repository shows how to:
- Create federated Vue.js components using Module Federation
- Integrate with Gun.js for decentralized data storage
- Build plugin UIs that match the TopLocs design system
- Test plugin functionality in isolation
### **πŸ” Security Mechanisms Demonstrated:**

## Structure
1. **Plugin Identity & Signatures**
- Cryptographic plugin identity using Gun SEA
- Digital signatures for all plugin data
- Verification of data integrity and authenticity

```
demo-plugin/
β”œβ”€β”€ demo-frontend/ # Plugin host application (for testing)
β”œβ”€β”€ demo-plugin/ # Example plugin implementation
β”œβ”€β”€ events-plugin/ # Event management plugin example
└── wiki-plugin/ # Wiki plugin example
```
2. **User Encryption & Privacy**
- End-to-end encryption in user's private space
- Public signed data for transparent information
- Group encryption with shared secrets

3. **Permission System**
- Explicit user consent for plugin capabilities
- Granular permissions (read, write, encrypt, share)
- Capability verification before data access

4. **Content-Addressed Storage**
- IPFS-style content identification (CIDs)
- Tamper-proof data verification
- Decentralized content distribution

5. **Plugin-to-Plugin Communication**
- End-to-end encrypted messaging between plugins
- Secure data sharing across plugin boundaries
- Cryptographic channel establishment

### **πŸ—οΈ Plugin Architecture Patterns:**

1. **Component Exposure**
- `./Main` - Primary content area component
- `./Sidebar` - Sidebar widget component
- `./Settings` - Plugin configuration interface
- `./EntityProvider` - Data provider composable
- `./EntityTypes` - Custom entity definitions

## Getting Started
2. **Route Integration**
- Dynamic route registration via Gun.js
- Route-based component loading
- URL parameter handling

3. **Entity System Extension**
- Custom entity types (SecureNote)
- Custom relation definitions
- Cross-plugin entity references

4. **Data Provider Pattern**
- Vue composable for data management
- Reactive state management
- Encrypted data persistence

## πŸš€ Quick Start

### **For Plugin Developers:**

### 1. Clone and Setup
```bash
git clone https://github.com/toplocs/demo-plugin.git
# Clone and examine the demo plugin
cd demo-plugin
pnpm install
pnpm dev
```

### 2. Start Development Environment
```bash
pnpm dev # Starts plugin host and example plugins
```
### **For TopLocs Integration:**

### 3. Create Your Plugin
1. Copy one of the example plugins as a template
2. Modify `vite.config.ts` for Module Federation
3. Update plugin components and data integration
4. Test with the demo-frontend host
1. **Load Plugin in TopLocs:**
```typescript
// Plugin loads automatically via Gun.js discovery
gun.get('plugins').get('secure-demo-plugin').put({
name: 'Secure Demo Plugin',
url: 'http://localhost:3001/plugin.js',
author: 'plugin-public-key'
});
```

## Plugin Development Guide
2. **Access Plugin Components:**
```vue
<!-- Main content area -->
<PluginComponent plugin="secure-demo-plugin" position="Main" />

<!-- Sidebar widget -->
<PluginComponent plugin="secure-demo-plugin" position="Sidebar" />
```

For comprehensive plugin development documentation, see:
- [TopLocs Plugin Development Guide](https://github.com/toplocs/tribelike/blob/main/docs/plugin-development.md)
- [TopLocs Architecture Overview](https://github.com/toplocs/tribelike/blob/main/docs/architecture.md)
## πŸ”§ Plugin Development Guide

## Key Concepts
### **1. Security-First Development:**

### Module Federation
Plugins use Webpack Module Federation to load dynamically:
```typescript
// Always sign plugin data
const signedData = await SEA.sign(data, pluginKeys);
gun.get(`plugin-${pluginId}/${id}`).put({
data,
signature: signedData,
author: pluginKeys.pub
});

// Request user permissions explicitly
const permission = await requestUserPermission('write', 'user-data');

// Encrypt sensitive data
const encrypted = await gun.user()._.sea.encrypt(sensitiveData);
```

### **2. Component Architecture:**

```typescript
// vite.config.ts
federation({
name: 'your-plugin',
filename: 'plugin.js',
// Export multiple component types
export default {
exposes: {
'./Main': './src/components/Main.vue',
'./Settings': './src/components/Settings.vue'
},
shared: ['vue', 'tailwindcss']
})
'./Main': './src/components/MainComponent.vue',
'./Sidebar': './src/components/SidebarWidget.vue',
'./Settings': './src/components/PluginSettings.vue',
'./Modal': './src/components/ModalComponent.vue'
}
};
```

### **3. Entity System Integration:**

```typescript
// Define custom entities
export interface CustomEntity extends BaseEntity {
pluginId: string;
customField: string;
}

// Register custom relations
export const customRelations = [
{
id: 'custom-relation',
accepts: ['CustomEntity', 'Topic'],
icon: 'link'
}
];
```

### **4. Data Provider Pattern:**

```typescript
export function customProvider() {
const data = ref([]);

// Gun.js integration
onMounted(() => {
gun.get(`plugin-${pluginId}`)
.map()
.once((item) => data.value.push(item));
});

provide('customData', { data, createItem, updateItem });
}
```

### Gun.js Integration
All plugins share the Gun.js decentralized database:
## πŸ”’ Security Best Practices

### **βœ… DO:**
- Sign all public plugin data
- Request explicit user permissions
- Encrypt sensitive data at rest
- Verify signatures on incoming data
- Use content addressing for immutable data
- Implement capability-based security

### **❌ DON'T:**
- Store unencrypted sensitive data
- Access data without user permission
- Trust unsigned plugin data
- Hardcode cryptographic keys
- Bypass Gun.js encryption
- Use eval() or similar dynamic execution

## πŸ“Š Plugin Slot System

### **Available Plugin Slots:**

| Slot | Usage | Component | Description |
|------|--------|-----------|-------------|
| `Main` | Content area | `./Main` | Primary plugin interface |
| `Sidebar` | Right sidebar | `./Sidebar` | Quick actions/status |
| `Settings` | Settings page | `./Settings` | Plugin configuration |
| `Modal` | Dialog/popup | `./Modal` | Overlay interactions |

### **Route Integration:**

```typescript
// Routes are registered automatically via Gun.js
gun.get('plugins').get(pluginId).get('paths').put({
path: '/secure-demo/:id?',
component: 'Main',
name: 'SecureDemoView'
});
```

## 🌐 Entity & Relation System

### **Custom Entity Definition:**

```typescript
export const pluginEntityDefinition = {
pluginId: 'secure-demo-plugin',
entities: [{
type: 'SecureNote',
name: 'Secure Note',
namespace: 'secure-notes',
schema: {
required: ['title', 'content'],
optional: ['tags', 'sharedWith']
}
}],
relations: secureNoteRelations
};
```

### **Cross-Plugin Relations:**

```typescript
// Relate plugin entities to core entities
const relation = {
from: 'secure-note-id',
to: 'topic-id',
type: 'tags',
pluginId: 'secure-demo-plugin'
};

gun.get('relations').get(relation.from).get(relation.type).set(relation);
```

## πŸ› οΈ Development Tools

### **Debug Commands (Dev Mode):**

```javascript
// Plugin data integration
gun.get('plugins').get('your-plugin').put(data)
// Available in browser console
gun.debug.showPluginData('secure-demo-plugin');
gun.debug.showUserData();
gun.debug.clearPluginData('secure-demo-plugin');

// Security utilities
gun.secure.verifyPlugin(pluginData);
gun.secure.createCID(data);
gun.secure.hasCapability(userPub, pluginId, 'write');
```

### **Testing Patterns:**

```typescript
// Test encrypted data
const encrypted = await storeEncryptedData(testData, true);
const decrypted = await gun.user()._.sea.decrypt(encrypted);
assert(decrypted.content === testData.content);

// Test signatures
const signed = await SEA.sign(testData, pluginKeys);
const verified = await SEA.verify(signed, pluginKeys.pub);
assert(verified === testData);
```

### Plugin Components
Standard plugin components:
- **Main.vue** - Primary plugin interface
- **Settings.vue** - Plugin configuration
- **Sidebar.vue** - Navigation integration
## πŸ“‹ Plugin Checklist

## Example Plugins
### **Before Publishing:**

### Events Plugin
Demonstrates:
- Real-time event management
- Complex UI interactions
- Backend integration (optional)
- [ ] All public data is cryptographically signed
- [ ] User permissions are requested explicitly
- [ ] Sensitive data is encrypted
- [ ] Plugin identity is established with key pair
- [ ] Components are properly exposed via federation
- [ ] Entity definitions are valid and complete
- [ ] Cross-plugin compatibility is tested
- [ ] Security audit is completed

### Wiki Plugin
Demonstrates:
- Content creation and editing
- Search functionality
- Collaborative features
### **Security Audit:**

## Testing
- [ ] No hardcoded secrets or keys
- [ ] No eval() or dynamic code execution
- [ ] All user data access is permission-gated
- [ ] Signatures are verified on data reads
- [ ] Encryption is used for sensitive operations
- [ ] Plugin-to-plugin communication is secured

Use the demo-frontend to test your plugins:
1. Start the development environment
2. Load your plugin in the host application
3. Test federation, data integration, and UI components
## πŸŽ“ Learning Resources

## Contributing
- **[Gun.js Documentation](https://gun.eco/docs/)** - P2P database fundamentals
- **[Gun SEA Guide](https://gun.eco/docs/SEA)** - Security, Encryption, Authorization
- **[Module Federation](https://module-federation.github.io/)** - Plugin system architecture
- **[Vue Composables](https://vuejs.org/guide/reusability/composables.html)** - Reactive data patterns
- **[TopLocs Architecture](../docs/project/architecture.md)** - Platform overview

This repository serves as the foundation for all TopLocs plugins. Improvements to the development framework benefit the entire plugin ecosystem.
## 🀝 Contributing

## Related Repositories
This demo plugin serves as the reference implementation for secure TopLocs plugins. When contributing:

- **tribelike** - Core TopLocs platform
- **event-plugin** - Production event management plugin
- **wiki-plugin** - Production wiki plugin
- **location-plugin** - Location management plugin
- **link-plugin** - Link sharing plugin
1. Maintain security-first principles
2. Document all security mechanisms
3. Provide clear examples for each pattern
4. Test across multiple scenarios
5. Keep the demo comprehensive but focused

## License
---

MIT License - See the main TopLocs project for details.
**πŸ” Remember: In a decentralized system, security is everyone's responsibility. This demo shows how to build plugins that are secure by design, not as an afterthought.**
6 changes: 0 additions & 6 deletions demo-frontend/.editorconfig

This file was deleted.

Loading