Skip to content

This is a decentralized storage solution built on the Stacks blockchain using Clarity smart contract language. It provides users with sovereign control over their AI interaction data, enabling secure storage, granular access management, and personalized AI preferences,all while maintaining cryptographic security and blockchain immutability.

Notifications You must be signed in to change notification settings

ikeoluwaadeolu/Personal-AI-Assistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 

Repository files navigation

Personal AI Assistant Data Vault

A secure, decentralized smart contract on the Stacks blockchain for storing encrypted AI assistant interactions, user preferences, and private data with granular access control.

Overview

This Clarity smart contract provides a robust vault system where users can store encrypted data from AI interactions, manage access permissions, and configure AI preferences. All data is stored on-chain with cryptographic security and owner-controlled access.

Features

๐Ÿ” Vault Management

  • Create Vaults: Store encrypted data (up to 10,000 characters) with metadata
  • Update Vaults: Modify existing vault contents with version tracking
  • Access Tracking: Monitor vault access with automatic counter increments
  • Vault Control: Activate/deactivate vaults as needed

๐Ÿ‘ฅ Access Control System

  • Owner Permissions: Full control over vault operations
  • Shared Access: Grant read access to other principals
  • Permission Levels: Define custom permission types (read, write, admin, etc.)
  • Time-Based Expiration: Set temporary access with block-height expiration
  • Access Revocation: Remove permissions at any time

โš™๏ธ AI Preferences

  • Model Selection: Store preferred AI model configurations
  • Privacy Levels: Set privacy settings (0-3 scale)
  • Auto-Delete: Configure automatic data deletion schedules
  • Notifications: Toggle notification preferences

๐Ÿ’ฐ Economic Model

  • Storage Fees: 1 STX per vault creation (configurable)
  • Spam Prevention: Fee-based system prevents abuse
  • Admin Controls: Owner can adjust fees and size limits

Contract Functions

Public Functions

Vault Operations

(create-vault (encrypted-data (string-utf8 10000)) (metadata (string-utf8 500)))

Creates a new vault with encrypted data. Returns vault ID.

(update-vault (vault-id uint) (encrypted-data (string-utf8 10000)) (metadata (string-utf8 500)))

Updates existing vault contents. Only owner can update.

(access-vault (vault-id uint))

Retrieves vault data if caller has access permissions.

(deactivate-vault (vault-id uint))

Deactivates a vault, preventing further access.

Access Management

(grant-access (vault-id uint) (accessor principal) (permission (string-ascii 20)) (duration-blocks (optional uint)))

Grants access to another user with optional expiration.

(revoke-access (vault-id uint) (accessor principal))

Removes access permissions from a user.

Preferences

(set-preferences (model (string-ascii 50)) (privacy uint) (auto-delete (optional uint)) (notifications bool))

Configures AI assistant preferences.

Read-Only Functions

(get-vault-info (vault-id uint))

Returns complete vault information.

(get-user-vault-count (owner principal))

Returns total vaults owned by a principal.

(get-user-vault-by-index (owner principal) (index uint))

Retrieves vault ID by index for a user.

(get-access-info (vault-id uint) (accessor principal))

Returns access permission details.

(get-preferences (owner principal))

Returns AI preferences for a user.

(check-access (vault-id uint) (caller principal))

Checks if a principal has access to a vault.

Admin Functions

(set-storage-fee (new-fee uint))

Updates the storage fee. Owner only.

(set-max-data-size (new-size uint))

Adjusts maximum data size (1,000-50,000 characters). Owner only.

Error Codes

Code Constant Description
u100 err-owner-only Operation requires contract owner
u101 err-not-authorized Caller lacks required permissions
u102 err-vault-not-found Vault ID doesn't exist
u103 err-invalid-input Input validation failed
u104 err-quota-exceeded Data size exceeds limit
u105 err-already-shared Access already granted
u106 err-share-not-found Access permission not found

Data Structures

Vault Structure

{
  owner: principal,
  encrypted-data: (string-utf8 10000),
  metadata: (string-utf8 500),
  created-at: uint,
  updated-at: uint,
  access-count: uint,
  is-active: bool
}

Shared Access Structure

{
  granted-at: uint,
  permission-level: (string-ascii 20),
  expires-at: (optional uint)
}

AI Preferences Structure

{
  model-preference: (string-ascii 50),
  privacy-level: uint,
  auto-delete-days: (optional uint),
  notification-enabled: bool
}

Usage Examples

Creating a Vault

(contract-call? .ai-data-vault create-vault 
  u"encrypted_conversation_data_here" 
  u"AI chat from 2025-11-12")

Granting Temporary Access

;; Grant access for 1000 blocks (~1 week)
(contract-call? .ai-data-vault grant-access 
  u1 
  'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM 
  "read" 
  (some u1000))

Setting AI Preferences

(contract-call? .ai-data-vault set-preferences 
  "claude-sonnet-4" 
  u2 
  (some u90) 
  true)

Security Considerations

  1. Encryption Required: Always encrypt sensitive data before storing on-chain
  2. Access Control: Regularly audit granted permissions
  3. Time-Limited Access: Use expiration for temporary sharing
  4. Privacy Levels: Configure appropriate privacy settings
  5. Data Validation: All inputs are validated before processing

Deployment

  1. Deploy contract to Stacks blockchain
  2. Contract deployer becomes owner
  3. Set initial storage fee and size limits
  4. Users can immediately begin creating vaults

About

This is a decentralized storage solution built on the Stacks blockchain using Clarity smart contract language. It provides users with sovereign control over their AI interaction data, enabling secure storage, granular access management, and personalized AI preferences,all while maintaining cryptographic security and blockchain immutability.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published