hippius 0.2.16__py3-none-any.whl → 0.2.17__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hippius-0.2.16.dist-info → hippius-0.2.17.dist-info}/METADATA +1 -1
- {hippius-0.2.16.dist-info → hippius-0.2.17.dist-info}/RECORD +10 -5
- {hippius-0.2.16.dist-info → hippius-0.2.17.dist-info}/entry_points.txt +1 -0
- hippius_sdk/__init__.py +1 -1
- hippius_sdk/db/README.md +86 -0
- hippius_sdk/db/env.db.template +9 -0
- hippius_sdk/db/migrations/20241201000001_create_key_storage_tables.sql +37 -0
- hippius_sdk/db/setup_database.sh +84 -0
- hippius_sdk/db_utils.py +59 -0
- {hippius-0.2.16.dist-info → hippius-0.2.17.dist-info}/WHEEL +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
hippius_sdk/__init__.py,sha256=
|
1
|
+
hippius_sdk/__init__.py,sha256=HHYt8QWs75kFrAVpKrmE1DyKQF96FXt8dpqXamzuDE0,1392
|
2
2
|
hippius_sdk/cli.py,sha256=aqKOYSBSWt7UhcpFt7wf9yIPJ3bznpsJ6ehOnuZ4usI,18235
|
3
3
|
hippius_sdk/cli_assets.py,sha256=V3MX63QTiex6mCp0VDXQJ7cagm5v1s4xtsu8c1O4G_k,371
|
4
4
|
hippius_sdk/cli_handlers.py,sha256=TQNE9os87gRzRKLEO-SIwhFnBtEFMiaSESv-Bu7omfo,128909
|
@@ -6,13 +6,18 @@ hippius_sdk/cli_parser.py,sha256=z7UvgWvvy04ey-R56qZiCqYc_9RaNq1rVDkQyXoK3JU,211
|
|
6
6
|
hippius_sdk/cli_rich.py,sha256=_jTBYMdHi2--fIVwoeNi-EtkdOb6Zy_O2TUiGvU3O7s,7324
|
7
7
|
hippius_sdk/client.py,sha256=W1aVyvgMXRXVqjwSmRl03kZKB96PHMPcpq3cj1equ-8,20179
|
8
8
|
hippius_sdk/config.py,sha256=Hf_aUYzG9ylzqauA_ABUSSB5mBTYbp-VtB36VQt2XDw,21981
|
9
|
+
hippius_sdk/db/README.md,sha256=okDeI1qgkaZqXSlJ8L0xIE4UpuxO-qEGPIbXUvSHQjU,2030
|
10
|
+
hippius_sdk/db/env.db.template,sha256=_6hEC3IvkzCDOAzG1_yJUKRUfCTMciNaJUicZpMCat4,217
|
11
|
+
hippius_sdk/db/migrations/20241201000001_create_key_storage_tables.sql,sha256=mi4-6OofgsmJq3PTG4ew8VNucoeb7iejyqd-bado7Mc,1613
|
12
|
+
hippius_sdk/db/setup_database.sh,sha256=5Nc0VJ4WClxARGB2r7S5bvJVDgtyND3BXnhLLPc4Nto,2929
|
13
|
+
hippius_sdk/db_utils.py,sha256=-x0rbN0as7Tn3PJPZBYCgreZe52FLH40ppA1TLxsg90,1851
|
9
14
|
hippius_sdk/errors.py,sha256=LScJJmawVAx7aRzqqQguYSkf9iazSjEQEBNlD_GXZ6Y,1589
|
10
15
|
hippius_sdk/ipfs.py,sha256=by45dH1c2IxzkfU7B9-ZRkI5gwEAxE0bUB9KUhszlL8,84460
|
11
16
|
hippius_sdk/ipfs_core.py,sha256=eOOgLoyP9mvwndnCjldnTc7z94ImYCXY3nm7JU3e_Mo,12676
|
12
17
|
hippius_sdk/key_storage.py,sha256=7q5SL3Ls6Ho0xEwYSBpdci7e-bBMJnUMz2j7ROEBSVc,8947
|
13
18
|
hippius_sdk/substrate.py,sha256=AqfQNl5Qv_s6roOESSdwleX0-VGyu5sh3m5-dYZp5ek,49079
|
14
19
|
hippius_sdk/utils.py,sha256=rJ611yvwKSyiBpYU3w-SuyQxoghMGU-ePuslrPv5H5g,7388
|
15
|
-
hippius-0.2.
|
16
|
-
hippius-0.2.
|
17
|
-
hippius-0.2.
|
18
|
-
hippius-0.2.
|
20
|
+
hippius-0.2.17.dist-info/METADATA,sha256=wgS8li7sLw3RX9gQl3R6g4vj2Qfolg0IAf8UXBMNA6w,30088
|
21
|
+
hippius-0.2.17.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
22
|
+
hippius-0.2.17.dist-info/entry_points.txt,sha256=bFAZjW3vndretf9-8s587jA2ebMVI7puhn_lVs8jPc8,149
|
23
|
+
hippius-0.2.17.dist-info/RECORD,,
|
hippius_sdk/__init__.py
CHANGED
hippius_sdk/db/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Database Migrations for Hippius Key Storage
|
2
|
+
|
3
|
+
This directory contains database migrations for the Hippius SDK key storage feature.
|
4
|
+
|
5
|
+
## Setup for End Users
|
6
|
+
|
7
|
+
If you've installed hippius-sdk as a dependency, you can set up the database files in your project:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
# Copy database files to your project
|
11
|
+
hippius-setup-db
|
12
|
+
|
13
|
+
# Edit the database URL
|
14
|
+
cp env.db.template .env.db
|
15
|
+
# Edit .env.db with your database credentials
|
16
|
+
|
17
|
+
# Run the setup
|
18
|
+
./setup_database.sh
|
19
|
+
```
|
20
|
+
|
21
|
+
## Development Setup
|
22
|
+
|
23
|
+
1. **Install dbmate**:
|
24
|
+
```bash
|
25
|
+
brew install dbmate
|
26
|
+
# or download directly
|
27
|
+
curl -fsSL -o /usr/local/bin/dbmate https://github.com/amacneil/dbmate/releases/latest/download/dbmate-macos-amd64
|
28
|
+
chmod +x /usr/local/bin/dbmate
|
29
|
+
```
|
30
|
+
|
31
|
+
2. **Run the setup script**:
|
32
|
+
```bash
|
33
|
+
./setup_database.sh
|
34
|
+
```
|
35
|
+
|
36
|
+
## Manual Setup
|
37
|
+
|
38
|
+
If you prefer to run migrations manually:
|
39
|
+
|
40
|
+
```bash
|
41
|
+
# Set database URL
|
42
|
+
export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/hippius_keys?sslmode=disable
|
43
|
+
|
44
|
+
# Create database
|
45
|
+
createdb hippius_keys
|
46
|
+
|
47
|
+
# Run migrations
|
48
|
+
dbmate up
|
49
|
+
|
50
|
+
# Configure SDK
|
51
|
+
hippius config set key_storage database_url "postgresql://postgres:postgres@localhost:5432/hippius_keys?sslmode=disable"
|
52
|
+
hippius config set key_storage enabled true
|
53
|
+
```
|
54
|
+
|
55
|
+
## Database Schema
|
56
|
+
|
57
|
+
### Tables
|
58
|
+
|
59
|
+
- **`seed_phrases`**: Stores hashed seed phrases with base64 encoded values
|
60
|
+
- **`encryption_keys`**: Stores versioned encryption keys per seed phrase (never deleted)
|
61
|
+
|
62
|
+
### Key Features
|
63
|
+
|
64
|
+
- **Versioned keys**: New keys create new rows, old keys are never deleted
|
65
|
+
- **Efficient lookups**: Index on `(seed_hash, created_at DESC)` for fast retrieval of latest key
|
66
|
+
- **Secure storage**: Seed phrases are hashed for indexing, stored base64 encoded
|
67
|
+
- **Foreign key constraints**: Ensures data integrity between tables
|
68
|
+
|
69
|
+
## Migration Commands
|
70
|
+
|
71
|
+
```bash
|
72
|
+
# Check migration status
|
73
|
+
dbmate status
|
74
|
+
|
75
|
+
# Create new migration
|
76
|
+
dbmate new migration_name
|
77
|
+
|
78
|
+
# Run migrations
|
79
|
+
dbmate up
|
80
|
+
|
81
|
+
# Rollback last migration
|
82
|
+
dbmate down
|
83
|
+
|
84
|
+
# Reset database (drop and recreate)
|
85
|
+
dbmate drop && dbmate up
|
86
|
+
```
|
@@ -0,0 +1,37 @@
|
|
1
|
+
-- migrate:up
|
2
|
+
|
3
|
+
-- Table to store base64 encoded seed phrases (hashed for indexing)
|
4
|
+
CREATE TABLE seed_phrases (
|
5
|
+
id SERIAL PRIMARY KEY,
|
6
|
+
seed_hash VARCHAR(64) UNIQUE NOT NULL,
|
7
|
+
seed_phrase_b64 TEXT NOT NULL,
|
8
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
9
|
+
);
|
10
|
+
|
11
|
+
-- Table to store encryption keys associated with each seed phrase (versioned, never deleted)
|
12
|
+
CREATE TABLE encryption_keys (
|
13
|
+
id SERIAL PRIMARY KEY,
|
14
|
+
seed_hash VARCHAR(64) NOT NULL,
|
15
|
+
encryption_key_b64 TEXT NOT NULL,
|
16
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
17
|
+
FOREIGN KEY (seed_hash) REFERENCES seed_phrases(seed_hash) ON DELETE CASCADE
|
18
|
+
);
|
19
|
+
|
20
|
+
-- Index for efficient lookups of latest encryption key per seed phrase
|
21
|
+
CREATE INDEX idx_encryption_keys_seed_hash_created
|
22
|
+
ON encryption_keys(seed_hash, created_at DESC);
|
23
|
+
|
24
|
+
-- Comments for documentation
|
25
|
+
COMMENT ON TABLE seed_phrases IS 'Stores hashed seed phrases with base64 encoded values';
|
26
|
+
COMMENT ON TABLE encryption_keys IS 'Stores versioned encryption keys per seed phrase (never deleted, always use most recent)';
|
27
|
+
COMMENT ON COLUMN seed_phrases.seed_hash IS 'SHA-256 hash of the seed phrase for indexing';
|
28
|
+
COMMENT ON COLUMN seed_phrases.seed_phrase_b64 IS 'Base64 encoded seed phrase';
|
29
|
+
COMMENT ON COLUMN encryption_keys.seed_hash IS 'Reference to the seed phrase hash';
|
30
|
+
COMMENT ON COLUMN encryption_keys.encryption_key_b64 IS 'Base64 encoded encryption key';
|
31
|
+
|
32
|
+
-- migrate:down
|
33
|
+
|
34
|
+
-- Drop tables in reverse order due to foreign key constraints
|
35
|
+
DROP INDEX IF EXISTS idx_encryption_keys_seed_hash_created;
|
36
|
+
DROP TABLE IF EXISTS encryption_keys;
|
37
|
+
DROP TABLE IF EXISTS seed_phrases;
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
# Database setup script for Hippius key storage
|
3
|
+
|
4
|
+
set -e
|
5
|
+
|
6
|
+
echo "🗄️ Setting up Hippius key storage database..."
|
7
|
+
|
8
|
+
# Check if .env.db exists, if not create from template
|
9
|
+
if [ ! -f .env.db ]; then
|
10
|
+
if [ -f hippius_sdk/db/env.db.template ]; then
|
11
|
+
echo "📋 Creating .env.db from template..."
|
12
|
+
cp hippius_sdk/db/env.db.template .env.db
|
13
|
+
echo "✏️ Please edit .env.db with your database credentials"
|
14
|
+
elif [ -f env.db.template ]; then
|
15
|
+
cp env.db.template .env.db
|
16
|
+
echo "✏️ Please edit .env.db with your database credentials"
|
17
|
+
else
|
18
|
+
echo "❌ No .env.db file found and no template available"
|
19
|
+
echo "Please create .env.db with your database connection parameters:"
|
20
|
+
echo "DB_HOST=localhost"
|
21
|
+
echo "DB_PORT=5432"
|
22
|
+
echo "DB_USER=postgres"
|
23
|
+
echo "DB_PASSWORD=your_password"
|
24
|
+
echo "DB_NAME=hippius_keys"
|
25
|
+
echo "DB_SSLMODE=disable"
|
26
|
+
exit 1
|
27
|
+
fi
|
28
|
+
fi
|
29
|
+
|
30
|
+
# Load database connection parameters from env file
|
31
|
+
source .env.db
|
32
|
+
|
33
|
+
echo "📊 Database connection details:"
|
34
|
+
echo " Host: $DB_HOST"
|
35
|
+
echo " Port: $DB_PORT"
|
36
|
+
echo " User: $DB_USER"
|
37
|
+
echo " Database: $DB_NAME"
|
38
|
+
echo " SSL Mode: $DB_SSLMODE"
|
39
|
+
|
40
|
+
# Construct DATABASE_URL for dbmate
|
41
|
+
export DATABASE_URL="postgresql://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME?sslmode=$DB_SSLMODE"
|
42
|
+
|
43
|
+
# Create database if it doesn't exist
|
44
|
+
echo "📝 Creating database $DB_NAME..."
|
45
|
+
PGPASSWORD=$DB_PASSWORD createdb -h $DB_HOST -p $DB_PORT -U $DB_USER $DB_NAME 2>/dev/null || echo "Database $DB_NAME already exists"
|
46
|
+
|
47
|
+
# Run migrations with dbmate
|
48
|
+
echo "🚀 Running database migrations..."
|
49
|
+
if command -v dbmate &> /dev/null; then
|
50
|
+
dbmate up
|
51
|
+
echo "✅ Database migrations completed successfully!"
|
52
|
+
else
|
53
|
+
echo "❌ dbmate not found. Please install it first:"
|
54
|
+
echo " brew install dbmate"
|
55
|
+
echo " # or"
|
56
|
+
echo " curl -fsSL -o /usr/local/bin/dbmate https://github.com/amacneil/dbmate/releases/latest/download/dbmate-linux-amd64"
|
57
|
+
echo " chmod +x /usr/local/bin/dbmate"
|
58
|
+
exit 1
|
59
|
+
fi
|
60
|
+
|
61
|
+
# Configure Hippius SDK to use the database
|
62
|
+
echo "⚙️ Configuring Hippius SDK..."
|
63
|
+
if [ -f venv/bin/activate ]; then
|
64
|
+
source venv/bin/activate
|
65
|
+
python -c "
|
66
|
+
from hippius_sdk.config import set_config_value
|
67
|
+
set_config_value('key_storage', 'database_url', '$DATABASE_URL')
|
68
|
+
set_config_value('key_storage', 'enabled', True)
|
69
|
+
print('✅ Hippius SDK configured for key storage')
|
70
|
+
"
|
71
|
+
else
|
72
|
+
echo "⚠️ No virtual environment found. Please configure manually:"
|
73
|
+
echo "hippius config set key_storage database_url '$DATABASE_URL'"
|
74
|
+
echo "hippius config set key_storage enabled true"
|
75
|
+
fi
|
76
|
+
|
77
|
+
echo "🎉 Setup complete! Key storage is ready to use."
|
78
|
+
echo ""
|
79
|
+
echo "📋 What was set up:"
|
80
|
+
echo " - Database: hippius_keys"
|
81
|
+
echo " - Tables: seed_phrases, encryption_keys"
|
82
|
+
echo " - SDK config: key_storage enabled"
|
83
|
+
echo ""
|
84
|
+
echo "🧪 Test with: python test_key_storage.py"
|
hippius_sdk/db_utils.py
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
"""
|
2
|
+
Database utilities for Hippius SDK key storage.
|
3
|
+
"""
|
4
|
+
|
5
|
+
import shutil
|
6
|
+
from pathlib import Path
|
7
|
+
|
8
|
+
|
9
|
+
def get_db_path() -> Path:
|
10
|
+
"""Get the path to the database files."""
|
11
|
+
return Path(__file__).parent / "db"
|
12
|
+
|
13
|
+
|
14
|
+
def setup_db_cli() -> None:
|
15
|
+
"""CLI command to set up database files in current directory."""
|
16
|
+
db_path = get_db_path()
|
17
|
+
|
18
|
+
print("🗄️ Setting up Hippius database files...")
|
19
|
+
|
20
|
+
# Copy database files to current directory
|
21
|
+
current_dir = Path.cwd()
|
22
|
+
|
23
|
+
# Copy migrations to hippius_s3/sql/sdk_migrations
|
24
|
+
migrations_dest = current_dir / "hippius_s3" / "sql" / "sdk_migrations"
|
25
|
+
migrations_dest.mkdir(parents=True, exist_ok=True)
|
26
|
+
|
27
|
+
migrations_src = db_path / "migrations"
|
28
|
+
if migrations_src.exists():
|
29
|
+
for migration_file in migrations_src.glob("*.sql"):
|
30
|
+
shutil.copy2(migration_file, migrations_dest)
|
31
|
+
print(f"📁 Copied migrations to {migrations_dest}")
|
32
|
+
|
33
|
+
# Copy setup script
|
34
|
+
setup_script_src = db_path / "setup_database.sh"
|
35
|
+
setup_script_dest = current_dir / "setup_database.sh"
|
36
|
+
if setup_script_src.exists():
|
37
|
+
shutil.copy2(setup_script_src, setup_script_dest)
|
38
|
+
setup_script_dest.chmod(0o755)
|
39
|
+
print(f"🔧 Copied setup script to {setup_script_dest}")
|
40
|
+
|
41
|
+
# Copy env template
|
42
|
+
env_template_src = db_path / "env.db.template"
|
43
|
+
env_template_dest = current_dir / "env.db.template"
|
44
|
+
if env_template_src.exists():
|
45
|
+
shutil.copy2(env_template_src, env_template_dest)
|
46
|
+
print(f"📝 Copied env template to {env_template_dest}")
|
47
|
+
|
48
|
+
print()
|
49
|
+
print("✅ Database setup files copied successfully!")
|
50
|
+
print()
|
51
|
+
print("🚀 Next steps:")
|
52
|
+
print(
|
53
|
+
" 1. Copy env.db.template to .env.db and edit with your database credentials"
|
54
|
+
)
|
55
|
+
print(" 2. Run: ./setup_database.sh")
|
56
|
+
|
57
|
+
|
58
|
+
if __name__ == "__main__":
|
59
|
+
setup_db_cli()
|
File without changes
|