Ver3.5 ๐ ํ์ด์ฌ๊ณผ IPFS๋กํ์ค์ ๋ฌธ์ ์ ์ฅ ์์คํ ๊ตฌ์ถ

๐ ํ์ด์ฌ๊ณผ IPFS๋ก
ํ์ค์ ๋ฌธ์ ์ ์ฅ ์์คํ
๊ตฌ์ถ
์ผ ์์งํ ๋งํด๋ด. ๊ตฌ๊ธ ๋๋ผ์ด๋ธ๋ ๋๋กญ๋ฐ์ค์ ์ค์ํ ํ์ผ ์ฌ๋ ค๋๊ณ "์ด๊ฑฐ ์์ ํ๊ฒ ์ง~" ํ๊ณ ์์ฌํ ์ ์์ง? ๐ค
๊ทผ๋ฐ ์๊ฐํด๋ด. ๊ทธ ์๋ฒ๊ฐ ๊ฐ์๊ธฐ ํฐ์ง๊ฑฐ๋, ํ์ฌ๊ฐ ๋งํ๊ฑฐ๋, ์๋๋ฉด ๊ทธ๋ฅ ๋ ๊ณ์ ์ด ์ ์ง๋๋ฉด? ํ์ผ ๊ทธ๋ฅ ์ฆ๋ฐ์ด์ผ ใ
ใ
ใ
๊ทธ๋์ ์ค๋ ์ฐ๋ฆฌ๊ฐ ๋ฐฐ์ธ ๊ฒ ๋ฐ๋ก IPFS(InterPlanetary File System)๋ Python์ ์กฐํฉํด์ ๋ง๋๋ ํ์ค์ ๋ฌธ์ ์ ์ฅ ์์คํ
์ด์ผ.
์ค์ ์๋ฒ ์์ด, ์๋ฌด๋ ๋ด ํ์ผ ๋ชป ๊ฑด๋๋ฆฌ๊ณ , ๊ฒ์ด๋ ์๊ณ , ์๊ตฌ ๋ณด์กด ๊ฐ๋ฅํ ๊ทธ ์์คํ
๋ง์ด์ผ. ์์ Web3 ๊ฐ์ฑ ๋ฟ๋ฟ ๐
IPFS๋ InterPlanetary File System์ ์ฝ์์ผ. ์ง์ญํ๋ฉด "ํ์ฑ ๊ฐ ํ์ผ ์์คํ
"์ธ๋ฐ, ์ด๋ฆ๋ถํฐ ์ค์ผ์ผ์ด ์ฐ์ฃผ๊ธ์ด์ง? ๐
2015๋
์ Protocol Labs์ Juan Benet์ด ๋ง๋ค์๊ณ , ์ง๊ธ์ Web3 ์ํ๊ณ์์ ์์ด์๋ ์ ๋ ํต์ฌ ์ธํ๋ผ๊ฐ ๋์ด.
๊ธฐ์กด ์ธํฐ๋ท(HTTP)์ ์์น ๊ธฐ๋ฐ ์ฃผ์์ผ. ์๋ฅผ ๋ค์ด https://example.com/file.pdf ์ด๋ฐ ์์ผ๋ก "์ด๋์" ์๋์ง๋ก ํ์ผ์ ์ฐพ์.
๊ทผ๋ฐ IPFS๋ ์ฝํ
์ธ ๊ธฐ๋ฐ ์ฃผ์(Content Addressing)์ผ. ํ์ผ์ ๋ด์ฉ ์์ฒด๋ฅผ ํด์ํด์ ๊ทธ ํด์๊ฐ์ด ์ฃผ์๊ฐ ๋ผ.
์:
QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG์ด๊ฒ ๋ฐ๋ก IPFS์ CID(Content Identifier)์ผ. ํ์ผ ๋ด์ฉ์ด ๊ฐ์ผ๋ฉด CID๋ ํญ์ ๊ฐ๊ณ , ๋ด์ฉ์ด 1๋นํธ๋ผ๋ ๋ค๋ฅด๋ฉด ์์ ํ ๋ค๋ฅธ CID๊ฐ ๋์. ์๋ณ์กฐ ๊ฐ์ง ์๋ ๋ด์ฅ ใทใท
์ด๋ค ๋ ธ๋๊ฐ ์ด๋ค ํ์ผ์ ๊ฐ๊ณ ์๋์ง ๋ถ์ฐ ์ ์ฅํ๋ ๋ผ์ฐํ ํ ์ด๋ธ์ด์ผ. ์ค์ ์๋ฒ ์์ด "์ด CID ๊ฐ์ง ๋ ธ๋ ์ด๋จ์ด?" ํ๊ณ ๋คํธ์ํฌ ์ ์ฒด์ ๋ฌผ์ด๋ณด๋ ๋ฐฉ์.
ํ์ผ์ 256KB ๋จ์ ์ฒญํฌ๋ก ์ชผ๊ฐ์ ํธ๋ฆฌ ๊ตฌ์กฐ๋ก ์ฐ๊ฒฐํด. ๊ฐ ์ฒญํฌ๊ฐ ํด์๋ก ์ฐ๊ฒฐ๋๋๊น ๋ฐ์ดํฐ ๋ฌด๊ฒฐ์ฑ์ด ์ํ์ ์ผ๋ก ๋ณด์ฅ๋ผ. ๋ธ๋ก์ฒด์ธ์ด๋ ๊ฐ์ ์๋ฆฌ์ผ!
๋ ธ๋๋ค๋ผ๋ฆฌ ํ์ผ ์กฐ๊ฐ์ ๊ตํํ๋ ํ๋กํ ์ฝ์ด์ผ. BitTorrent๋ ๋น์ทํ ๊ฐ๋ ์ธ๋ฐ, ๋ด๊ฐ ํ์ผ ์กฐ๊ฐ์ ๊ณต์ ํ๋ฉด ๋ค๋ฅธ ์กฐ๊ฐ์ ๋ฐ์ ์ ์๋ ์ผ์ข ์ ๋ฌผ๋ฌผ๊ตํ ์์คํ .
์ ์ด์ ์ง์ง ์ฝ๋ฉ ๋ค์ด๊ฐ๊ธฐ ์ ์ ํ๊ฒฝ๋ถํฐ ์ธํ ํ์. ํ์ํ ๊ฑฐ ๋ฆฌ์คํธ์ ํด์ค๊ฒ ๐
Python 3.8+ IPFS Desktop ๋๋ IPFS CLI ipfshttpclient ๋ผ์ด๋ธ๋ฌ๋ฆฌ web3.py (์ ํ) requests
๋จผ์ IPFS ๊ณต์ ์ฌ์ดํธ(dist.ipfs.tech)์์ Kubo(๊ตฌ go-ipfs)๋ฅผ ๋ค์ด๋ฐ์. ์ค์น ํ ์ด๊ธฐํ:
# IPFS ์ด๊ธฐํ (์ฒ์ ํ ๋ฒ๋ง)
ipfs init
# IPFS ๋ฐ๋ชฌ ์คํ (๋ฐฑ๊ทธ๋ผ์ด๋์์ ๊ณ์ ๋์์ผ ํด)
ipfs daemon
# ์ ์ ์คํ๋๋ฉด ์ด๋ฐ ๋ฉ์์ง ๋์ด:
# Daemon is ready
# API server listening on /ip4/127.0.0.1/tcp/5001
http://127.0.0.1:5001๋ก API ์ ๊ทผ ๊ฐ๋ฅํ๊ณ ,http://127.0.0.1:8080์ผ๋ก ๊ฒ์ดํธ์จ์ด ์ ๊ทผ์ด ๊ฐ๋ฅํด. ํ์ด์ฌ์์ ์ด API๋ฅผ ํตํด ํต์ ํ ๊ฑฐ์ผ!
# ๊ฐ์ํ๊ฒฝ ๋ง๋ค๊ณ (๊ถ์ฅ)
python -m venv ipfs-env
source ipfs-env/bin/activate # Windows: ipfs-env\Scripts\activate
# ํ์ํ ํจํค์ง ์ค์น
pip install ipfshttpclient
pip install requests
pip install web3
pip install python-dotenv
pip install cryptography # ์ํธํ ๊ธฐ๋ฅ ์ธ ๋
ipfshttpclient๋ IPFS API ๋ฒ์ ์ ๋ฏผ๊ฐํด.Kubo 0.11.0 ์ด์์ด๋ฉด
ipfshttpclient==0.8.0a2 ์ด์ ์จ์ผ ํด.๋ฒ์ ์ ๋ง์ผ๋ฉด ์ฐ๊ฒฐ ์๋ฌ ๋จ๋๊น ๊ผญ ํ์ธํ๊ณ !
์ ์ด์ ์ง์ง ์ฝ๋ ์ง๋ณด์! ์ฒ์์ ๊ธฐ๋ณธ์ ์ธ ํ์ผ ์ ๋ก๋/๋ค์ด๋ก๋๋ถํฐ ์์ํด์ ์ ์ ๊ณ ๋ํํ ๊ฑฐ์ผ ๐ช
import ipfshttpclient
import json
import os
from datetime import datetime
class IPFSClient:
"""IPFS ํด๋ผ์ด์ธํธ ๊ธฐ๋ณธ ํด๋์ค"""
def __init__(self, api_url='/ip4/127.0.0.1/tcp/5001'):
"""
IPFS ๋ฐ๋ชฌ์ ์ฐ๊ฒฐ
api_url: ๋ก์ปฌ IPFS ๋ฐ๋ชฌ API ์ฃผ์
"""
try:
self.client = ipfshttpclient.connect(api_url)
print(f"โ
IPFS ์ฐ๊ฒฐ ์ฑ๊ณต!")
# ์ฐ๊ฒฐ๋ ๋
ธ๋ ์ ๋ณด ์ถ๋ ฅ
node_info = self.client.id()
print(f"๐ ๋
ธ๋ ID: {node_info['ID'][:20]}...")
except Exception as e:
print(f"โ IPFS ์ฐ๊ฒฐ ์คํจ: {e}")
raise
def upload_file(self, file_path: str) -> dict:
"""
ํ์ผ์ IPFS์ ์
๋ก๋
Returns: {'cid': str, 'size': int, 'timestamp': str}
"""
if not os.path.exists(file_path):
raise FileNotFoundError(f"ํ์ผ ์์: {file_path}")
print(f"๐ค ์
๋ก๋ ์ค: {file_path}")
# IPFS์ ํ์ผ ์ถ๊ฐ
result = self.client.add(file_path)
# ๊ฒฐ๊ณผ ์ ๋ฆฌ
upload_info = {
'cid': result['Hash'], # Content Identifier
'name': result['Name'], # ํ์ผ๋ช
'size': int(result['Size']), # ๋ฐ์ดํธ ํฌ๊ธฐ
'timestamp': datetime.now().isoformat(),
'ipfs_url': f"ipfs://{result['Hash']}",
'gateway_url': f"https://ipfs.io/ipfs/{result['Hash']}"
}
print(f"โ
์
๋ก๋ ์๋ฃ!")
print(f" CID: {upload_info['cid']}")
print(f" ํฌ๊ธฐ: {upload_info['size']:,} bytes")
print(f" ๊ฒ์ดํธ์จ์ด: {upload_info['gateway_url']}")
return upload_info
def upload_text(self, text: str, filename: str = "document.txt") -> dict:
"""
ํ
์คํธ ๋ด์ฉ์ ์ง์ IPFS์ ์
๋ก๋
"""
# ์์ ํ์ผ๋ก ์ ์ฅ ํ ์
๋ก๋
temp_path = f"/tmp/{filename}"
with open(temp_path, 'w', encoding='utf-8') as f:
f.write(text)
result = self.upload_file(temp_path)
os.remove(temp_path) # ์์ ํ์ผ ์ญ์
return result
def upload_json(self, data: dict, filename: str = "data.json") -> dict:
"""
๋์
๋๋ฆฌ๋ฅผ JSON์ผ๋ก ๋ณํํด์ IPFS์ ์
๋ก๋
๋ฉํ๋ฐ์ดํฐ ์ ์ฅ์ ์ ์ฉ!
"""
json_str = json.dumps(data, ensure_ascii=False, indent=2)
return self.upload_text(json_str, filename)
def download_file(self, cid: str, output_path: str) -> str:
"""
CID๋ก ํ์ผ ๋ค์ด๋ก๋
"""
print(f"๐ฅ ๋ค์ด๋ก๋ ์ค: {cid}")
self.client.get(cid, target=output_path)
print(f"โ
๋ค์ด๋ก๋ ์๋ฃ: {output_path}")
return output_path
def read_content(self, cid: str) -> bytes:
"""
CID์ ๋ด์ฉ์ ๋ฐ์ดํธ๋ก ์ฝ๊ธฐ
"""
return self.client.cat(cid)
def read_text(self, cid: str, encoding: str = 'utf-8') -> str:
"""
CID์ ๋ด์ฉ์ ํ
์คํธ๋ก ์ฝ๊ธฐ
"""
return self.read_content(cid).decode(encoding)
def pin_file(self, cid: str) -> bool:
"""
ํ์ผ ํ(Pin) - ๋ก์ปฌ ๋
ธ๋์์ ์ญ์ ๋ฐฉ์ง
ํ ์ ํ๋ฉด ๊ฐ๋น์ง ์ปฌ๋ ์
์ผ๋ก ์ฌ๋ผ์ง ์ ์์ด!
"""
try:
self.client.pin.add(cid)
print(f"๐ ํ ์๋ฃ: {cid}")
return True
except Exception as e:
print(f"โ ํ ์คํจ: {e}")
return False
def get_node_stats(self) -> dict:
"""๋
ธ๋ ํต๊ณ ์ ๋ณด"""
stats = self.client.stats.repo()
return {
'num_objects': stats['NumObjects'],
'repo_size': stats['RepoSize'],
'storage_max': stats['StorageMax']
}
# ์ฌ์ฉ ์์
if __name__ == "__main__":
# ํด๋ผ์ด์ธํธ ์์ฑ
ipfs = IPFSClient()
# ํ
์คํธ ๋ฌธ์ ์
๋ก๋
result = ipfs.upload_text(
"์๋
ํ์ธ์! ์ด ๋ฌธ์๋ IPFS์ ์ ์ฅ๋ฉ๋๋ค. ํ์ค์ํ ๋ง์ธ!",
"hello_ipfs.txt"
)
# CID๋ก ๋ด์ฉ ์ฝ๊ธฐ
content = ipfs.read_text(result['cid'])
print(f"\n๐ ์ฝ์ ๋ด์ฉ: {content}")
# ํ์ผ๋ก ์๊ตฌ ๋ณด์กด
ipfs.pin_file(result['cid'])
"hello world"๋ฅผ ์ฌ๋ฆฌ๋ฉด ์ ์ธ๊ณ ์ด๋์ ์ฌ๋ ค๋ ๊ฐ์ CID๊ฐ ๋์จ๋ค๋ ๊ฑฐ ใทใท
๊ธฐ๋ณธ ์
/๋ค์ด๋ก๋๋ ๋๊ณ , ์ด์ ์ง์ง ์ธ๋งํ ๋ฌธ์ ๊ด๋ฆฌ ์์คํ
์ ๋ง๋ค์ด๋ณด์.
๋ฉํ๋ฐ์ดํฐ ๊ด๋ฆฌ, ๋ฒ์ ๊ด๋ฆฌ, ๊ฒ์ ๊ธฐ๋ฅ๊น์ง ๋ฃ์ ๊ฑฐ์ผ. ์ด๊ฑฐ ์์ฑํ๋ฉด ์ง์ง ์ธ ์ ์๋ ๋ ๋ฒจ์ ๐ฅ
from dataclasses import dataclass, asdict
from typing import Optional, List
from datetime import datetime
import hashlib
import json
@dataclass
class DocumentMetadata:
"""๋ฌธ์ ๋ฉํ๋ฐ์ดํฐ ์คํค๋ง"""
# ๊ธฐ๋ณธ ์ ๋ณด
title: str # ๋ฌธ์ ์ ๋ชฉ
author: str # ์์ฑ์
description: str # ์ค๋ช
tags: List[str] # ํ๊ทธ ๋ชฉ๋ก
# IPFS ์ ๋ณด
content_cid: str # ์ค์ ๋ฌธ์ ๋ด์ฉ์ CID
# ๋ฒ์ ๊ด๋ฆฌ
version: int = 1 # ๋ฒ์ ๋ฒํธ
previous_cid: Optional[str] = None # ์ด์ ๋ฒ์ CID (๋ฒ์ ์ฒด์ธ)
# ํ์์คํฌํ
created_at: str = ""
updated_at: str = ""
# ํ์ผ ์ ๋ณด
file_type: str = "text/plain" # MIME ํ์
file_size: int = 0 # ๋ฐ์ดํธ
# ์ ๊ทผ ์ ์ด
is_public: bool = True # ๊ณต๊ฐ ์ฌ๋ถ
owner_address: Optional[str] = None # ์ด๋๋ฆฌ์ ์ฃผ์ (์ ํ)
def __post_init__(self):
now = datetime.now().isoformat()
if not self.created_at:
self.created_at = now
self.updated_at = now
def to_dict(self) -> dict:
return asdict(self)
def to_json(self) -> str:
return json.dumps(self.to_dict(), ensure_ascii=False, indent=2)
@classmethod
def from_dict(cls, data: dict) -> 'DocumentMetadata':
return cls(**data)
def get_fingerprint(self) -> str:
"""๋ฉํ๋ฐ์ดํฐ์ ๊ณ ์ ์ง๋ฌธ ์์ฑ"""
key_data = f"{self.title}{self.author}{self.content_cid}{self.version}"
return hashlib.sha256(key_data.encode()).hexdigest()[:16]
import ipfshttpclient
import json
import sqlite3
import os
from typing import Optional, List, Dict
from document_schema import DocumentMetadata
from datetime import datetime
class DecentralizedDocumentStore:
"""
ํ์ค์ ๋ฌธ์ ์ ์ฅ์
- IPFS: ์ค์ ํ์ผ ์ ์ฅ
- SQLite: ๋ก์ปฌ ์ธ๋ฑ์ค (CID, ๋ฉํ๋ฐ์ดํฐ ๊ฒ์์ฉ)
"""
def __init__(self,
ipfs_url: str = '/ip4/127.0.0.1/tcp/5001',
db_path: str = 'doc_index.db'):
# IPFS ์ฐ๊ฒฐ
self.ipfs = ipfshttpclient.connect(ipfs_url)
# ๋ก์ปฌ SQLite ์ธ๋ฑ์ค ์ด๊ธฐํ
self.db_path = db_path
self._init_database()
print("๐ ํ์ค์ ๋ฌธ์ ์ ์ฅ์ ์ด๊ธฐํ ์๋ฃ!")
def _init_database(self):
"""SQLite ์ธ๋ฑ์ค DB ์ด๊ธฐํ"""
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS documents (
id INTEGER PRIMARY KEY AUTOINCREMENT,
meta_cid TEXT UNIQUE NOT NULL, -- ๋ฉํ๋ฐ์ดํฐ CID
content_cid TEXT NOT NULL, -- ๋ด์ฉ CID
title TEXT NOT NULL,
author TEXT NOT NULL,
description TEXT,
tags TEXT, -- JSON ๋ฐฐ์ด๋ก ์ ์ฅ
version INTEGER DEFAULT 1,
previous_cid TEXT,
created_at TEXT,
updated_at TEXT,
file_type TEXT,
file_size INTEGER,
is_public INTEGER DEFAULT 1,
owner_address TEXT
)
''')
# ๊ฒ์ ์ฑ๋ฅ์ ์ํ ์ธ๋ฑ์ค
cursor.execute('CREATE INDEX IF NOT EXISTS idx_title ON documents(title)')
cursor.execute('CREATE INDEX IF NOT EXISTS idx_author ON documents(author)')
cursor.execute('CREATE INDEX IF NOT EXISTS idx_content_cid ON documents(content_cid)')
conn.commit()
conn.close()
def store_document(self,
content: str,
metadata: DocumentMetadata,
pin: bool = True) -> Dict:
"""
๋ฌธ์๋ฅผ IPFS์ ์ ์ฅํ๊ณ ์ธ๋ฑ์ค์ ๋ฑ๋ก
Args:
content: ๋ฌธ์ ๋ด์ฉ (ํ
์คํธ)
metadata: ๋ฌธ์ ๋ฉํ๋ฐ์ดํฐ
pin: ๋ก์ปฌ ํ ์ฌ๋ถ
Returns:
{'meta_cid': str, 'content_cid': str, 'success': bool}
"""
print(f"\n๐ ๋ฌธ์ ์ ์ฅ ์์: '{metadata.title}'")
# 1๋จ๊ณ: ๋ฌธ์ ๋ด์ฉ IPFS ์
๋ก๋
content_bytes = content.encode('utf-8')
content_result = self.ipfs.add_bytes(content_bytes)
content_cid = content_result
print(f" โ
๋ด์ฉ ์
๋ก๋: {content_cid}")
# 2๋จ๊ณ: ๋ฉํ๋ฐ์ดํฐ ์
๋ฐ์ดํธ ๋ฐ ์
๋ก๋
metadata.content_cid = content_cid
metadata.file_size = len(content_bytes)
metadata.updated_at = datetime.now().isoformat()
meta_json = metadata.to_json()
meta_result = self.ipfs.add_bytes(meta_json.encode('utf-8'))
meta_cid = meta_result
print(f" โ
๋ฉํ๋ฐ์ดํฐ ์
๋ก๋: {meta_cid}")
# 3๋จ๊ณ: ํ ์ค์ (์๊ตฌ ๋ณด์กด)
if pin:
self.ipfs.pin.add(content_cid)
self.ipfs.pin.add(meta_cid)
print(f" ๐ ํ ์๋ฃ")
# 4๋จ๊ณ: ๋ก์ปฌ ์ธ๋ฑ์ค์ ๋ฑ๋ก
self._index_document(meta_cid, metadata)
print(f" ๐ ์ธ๋ฑ์ค ๋ฑ๋ก ์๋ฃ")
result = {
'meta_cid': meta_cid,
'content_cid': content_cid,
'title': metadata.title,
'version': metadata.version,
'gateway_url': f"https://ipfs.io/ipfs/{content_cid}",
'success': True
}
print(f"\n๐ ์ ์ฅ ์๋ฃ!")
print(f" ๋ฉํ CID: {meta_cid}")
print(f" ๋ด์ฉ CID: {content_cid}")
return result
def _index_document(self, meta_cid: str, metadata: DocumentMetadata):
"""๋ก์ปฌ SQLite์ ๋ฌธ์ ์ธ๋ฑ์ฑ"""
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute('''
INSERT OR REPLACE INTO documents
(meta_cid, content_cid, title, author, description, tags,
version, previous_cid, created_at, updated_at,
file_type, file_size, is_public, owner_address)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (
meta_cid,
metadata.content_cid,
metadata.title,
metadata.author,
metadata.description,
json.dumps(metadata.tags, ensure_ascii=False),
metadata.version,
metadata.previous_cid,
metadata.created_at,
metadata.updated_at,
metadata.file_type,
metadata.file_size,
1 if metadata.is_public else 0,
metadata.owner_address
))
conn.commit()
conn.close()
def retrieve_document(self, cid: str) -> Dict:
"""
CID๋ก ๋ฌธ์ ์กฐํ (๋ฉํ CID ๋๋ ๋ด์ฉ CID ๋ชจ๋ ๊ฐ๋ฅ)
"""
# ๋ก์ปฌ ์ธ๋ฑ์ค์์ ๋จผ์ ์ฐพ๊ธฐ
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute('''
SELECT * FROM documents
WHERE meta_cid = ? OR content_cid = ?
''', (cid, cid))
row = cursor.fetchone()
conn.close()
if not row:
print(f"โ ๏ธ ์ธ๋ฑ์ค์ ์์. IPFS์์ ์ง์ ์กฐํ ์๋...")
# ์ธ๋ฑ์ค์ ์์ผ๋ฉด IPFS์์ ์ง์ ์ฝ๊ธฐ
try:
content = self.ipfs.cat(cid).decode('utf-8')
return {'content': content, 'cid': cid, 'from_ipfs': True}
except:
raise ValueError(f"CID๋ฅผ ์ฐพ์ ์ ์์: {cid}")
# ์ธ๋ฑ์ค์์ ์ฐพ์ ๊ฒฝ์ฐ
columns = ['id', 'meta_cid', 'content_cid', 'title', 'author',
'description', 'tags', 'version', 'previous_cid',
'created_at', 'updated_at', 'file_type', 'file_size',
'is_public', 'owner_address']
doc_info = dict(zip(columns, row))
doc_info['tags'] = json.loads(doc_info['tags'])
# ์ค์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ
content = self.ipfs.cat(doc_info['content_cid']).decode('utf-8')
doc_info['content'] = content
return doc_info
def search_documents(self,
query: str = None,
author: str = None,
tags: List[str] = None) -> List[Dict]:
"""
๋ฌธ์ ๊ฒ์ (์ ๋ชฉ, ์์ฑ์, ํ๊ทธ ๊ธฐ๋ฐ)
"""
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
conditions = []
params = []
if query:
conditions.append("(title LIKE ? OR description LIKE ?)")
params.extend([f"%{query}%", f"%{query}%"])
if author:
conditions.append("author LIKE ?")
params.append(f"%{author}%")
if tags:
for tag in tags:
conditions.append("tags LIKE ?")
params.append(f"%{tag}%")
where_clause = " AND ".join(conditions) if conditions else "1=1"
cursor.execute(f'''
SELECT meta_cid, content_cid, title, author, description,
tags, version, created_at, file_size
FROM documents
WHERE {where_clause}
ORDER BY updated_at DESC
''', params)
rows = cursor.fetchall()
conn.close()
results = []
for row in rows:
results.append({
'meta_cid': row[0],
'content_cid': row[1],
'title': row[2],
'author': row[3],
'description': row[4],
'tags': json.loads(row[5]),
'version': row[6],
'created_at': row[7],
'file_size': row[8],
'gateway_url': f"https://ipfs.io/ipfs/{row[1]}"
})
return results
def update_document(self,
original_meta_cid: str,
new_content: str,
update_note: str = "") -> Dict:
"""
๋ฌธ์ ์
๋ฐ์ดํธ (๋ฒ์ ์ฒด์ธ ์ ์ง)
์ด์ ๋ฒ์ ์ IPFS์ ์๊ตฌ ๋ณด์กด๋จ!
"""
# ๊ธฐ์กด ๋ฌธ์ ์กฐํ
old_doc = self.retrieve_document(original_meta_cid)
# ์ ๋ฉํ๋ฐ์ดํฐ ์์ฑ (๋ฒ์ ์ฆ๊ฐ)
new_metadata = DocumentMetadata(
title=old_doc['title'],
author=old_doc['author'],
description=f"{old_doc['description']} | ์
๋ฐ์ดํธ: {update_note}",
tags=old_doc['tags'],
content_cid="", # store_document์์ ์ฑ์์ง
version=old_doc['version'] + 1,
previous_cid=original_meta_cid, # ์ด์ ๋ฒ์ ์ฐ๊ฒฐ!
file_type=old_doc['file_type'],
owner_address=old_doc.get('owner_address')
)
return self.store_document(new_content, new_metadata)
def get_version_history(self, meta_cid: str) -> List[Dict]:
"""
๋ฌธ์์ ๋ฒ์ ํ์คํ ๋ฆฌ ์กฐํ (์ฒด์ธ ์ญ์ถ์ )
"""
history = []
current_cid = meta_cid
while current_cid:
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute(
'SELECT meta_cid, title, version, created_at, previous_cid FROM documents WHERE meta_cid = ?',
(current_cid,)
)
row = cursor.fetchone()
conn.close()
if not row:
break
history.append({
'meta_cid': row[0],
'title': row[1],
'version': row[2],
'created_at': row[3]
})
current_cid = row[4] # previous_cid๋ก ์ด๋
return history
๊ทธ๋์ ์ ๋ฐ์ดํธํ ๋๋ง๋ค ์ CID๊ฐ ์๊ธฐ๊ณ ,
previous_cid๋ก ์ด์ ๋ฒ์ ์ ์ฐ๊ฒฐํ๋ฉด๋ธ๋ก์ฒด์ธ์ฒ๋ผ ๋ณ๊ฒฝ ๋ถ๊ฐ๋ฅํ ๋ฒ์ ํ์คํ ๋ฆฌ๊ฐ ๋ง๋ค์ด์ ธ. ์์ ์ฉ์ง? ๐
IPFS์ ์ฌ๋ฆฐ ํ์ผ์ CID๋ง ์๋ฉด ๋๊ตฌ๋ ๋ณผ ์ ์์ด. ๊ณต๊ฐ ํ์ผ์ด๋ฉด ์๊ด์๋๋ฐ,
๋ฏผ๊ฐํ ๋ฌธ์๋ผ๋ฉด? ์ํธํ ํ์์ผ! ํ์ด์ฌ์ cryptography ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก AES-256 ์ํธํ ๊ตฌํํด๋ณด์ ๐
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.backends import default_backend
import os
import base64
import json
class DocumentEncryptor:
"""
AES-256-GCM ๊ธฐ๋ฐ ๋ฌธ์ ์ํธํ/๋ณตํธํ
- AES-GCM: ์ํธํ + ๋ฌด๊ฒฐ์ฑ ๊ฒ์ฆ ๋์์!
- PBKDF2: ํจ์ค์๋ ๊ธฐ๋ฐ ํค ์ ๋
"""
def __init__(self):
self.backend = default_backend()
def _derive_key(self, password: str, salt: bytes) -> bytes:
"""
ํจ์ค์๋์์ 256๋นํธ ํค ์ ๋ (PBKDF2-SHA256)
"""
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32, # 256๋นํธ
salt=salt,
iterations=100000, # 10๋ง ๋ฒ ๋ฐ๋ณต (๋ธ๋ฃจํธํฌ์ค ๋ฐฉ์ด)
backend=self.backend
)
return kdf.derive(password.encode('utf-8'))
def encrypt(self, content: str, password: str) -> dict:
"""
๋ฌธ์ ๋ด์ฉ ์ํธํ
Returns:
{
'encrypted_data': base64 ์ธ์ฝ๋ฉ๋ ์ํธ๋ฌธ,
'salt': base64 ์ธ์ฝ๋ฉ๋ ์ํธ,
'nonce': base64 ์ธ์ฝ๋ฉ๋ ๋
ผ์ค,
'algorithm': 'AES-256-GCM'
}
"""
# ๋๋ค ์ํธ์ ๋
ผ์ค ์์ฑ
salt = os.urandom(16) # 128๋นํธ ์ํธ
nonce = os.urandom(12) # 96๋นํธ ๋
ผ์ค (GCM ํ์ค)
# ํค ์ ๋
key = self._derive_key(password, salt)
# AES-GCM ์ํธํ
aesgcm = AESGCM(key)
encrypted = aesgcm.encrypt(nonce, content.encode('utf-8'), None)
return {
'encrypted_data': base64.b64encode(encrypted).decode(),
'salt': base64.b64encode(salt).decode(),
'nonce': base64.b64encode(nonce).decode(),
'algorithm': 'AES-256-GCM',
'kdf': 'PBKDF2-SHA256',
'iterations': 100000
}
def decrypt(self, encrypted_package: dict, password: str) -> str:
"""
์ํธํ๋ ํจํค์ง ๋ณตํธํ
"""
# base64 ๋์ฝ๋ฉ
encrypted_data = base64.b64decode(encrypted_package['encrypted_data'])
salt = base64.b64decode(encrypted_package['salt'])
nonce = base64.b64decode(encrypted_package['nonce'])
# ํค ์ ๋
key = self._derive_key(password, salt)
# AES-GCM ๋ณตํธํ (๋ฌด๊ฒฐ์ฑ ๊ฒ์ฆ ํฌํจ)
aesgcm = AESGCM(key)
try:
decrypted = aesgcm.decrypt(nonce, encrypted_data, None)
return decrypted.decode('utf-8')
except Exception:
raise ValueError("โ ๋ณตํธํ ์คํจ! ํจ์ค์๋๊ฐ ํ๋ ธ๊ฑฐ๋ ๋ฐ์ดํฐ๊ฐ ๋ณ์กฐ๋จ")
def encrypt_to_json(self, content: str, password: str) -> str:
"""์ํธํ ๊ฒฐ๊ณผ๋ฅผ JSON ๋ฌธ์์ด๋ก ๋ฐํ (IPFS ์
๋ก๋์ฉ)"""
encrypted = self.encrypt(content, password)
return json.dumps(encrypted, ensure_ascii=False)
def decrypt_from_json(self, json_str: str, password: str) -> str:
"""JSON ๋ฌธ์์ด์์ ๋ณตํธํ"""
encrypted_package = json.loads(json_str)
return self.decrypt(encrypted_package, password)
# ์ํธํ + IPFS ํตํฉ ์ฌ์ฉ ์์
class EncryptedDocumentStore:
"""์ํธํ๋ ๋ฌธ์๋ฅผ IPFS์ ์ ์ฅํ๋ ํตํฉ ํด๋์ค"""
def __init__(self, ipfs_client, encryptor: DocumentEncryptor):
self.ipfs = ipfs_client
self.encryptor = encryptor
def store_encrypted(self, content: str, password: str,
metadata: dict = None) -> dict:
"""
๋ฌธ์๋ฅผ ์ํธํํด์ IPFS์ ์ ์ฅ
"""
print("๐ ์ํธํ ์ค...")
encrypted_json = self.encryptor.encrypt_to_json(content, password)
print("๐ค IPFS ์
๋ก๋ ์ค...")
import ipfshttpclient
result = self.ipfs.add_bytes(encrypted_json.encode('utf-8'))
cid = result
print(f"โ
์ํธํ ์ ์ฅ ์๋ฃ!")
print(f" CID: {cid}")
print(f" โ ๏ธ ์ด CID์ ๋ด์ฉ์ ํจ์ค์๋ ์์ด ์ฝ์ ์ ์์")
return {
'cid': cid,
'encrypted': True,
'algorithm': 'AES-256-GCM',
'metadata': metadata
}
def retrieve_encrypted(self, cid: str, password: str) -> str:
"""
IPFS์์ ์ํธํ๋ ๋ฌธ์ ๊ฐ์ ธ์์ ๋ณตํธํ
"""
print(f"๐ฅ IPFS์์ ๊ฐ์ ธ์ค๋ ์ค: {cid}")
encrypted_json = self.ipfs.cat(cid).decode('utf-8')
print("๐ ๋ณตํธํ ์ค...")
content = self.encryptor.decrypt_from_json(encrypted_json, password)
print("โ
๋ณตํธํ ์๋ฃ!")
return content
์ค์ ์๋น์ค๋ผ๋ฉด ๋น๋์นญ ์ํธํ(RSA/ECDH)๋ ์๊ณ๊ฐ ์ํธํ(Threshold Encryption)๋ฅผ ๊ณ ๋ คํด๋ด.
๋๋ ์ด๋๋ฆฌ์ ์ง๊ฐ์ ๊ฐ์ธํค๋ก ์ํธํํ๋ ๋ฐฉ๋ฒ๋ Web3 ์ํ๊ณ์์ ๋ง์ด ์จ!
๋ก์ปฌ IPFS ๋
ธ๋์๋ง ํ์ผ ์ฌ๋ฆฌ๋ฉด ๋ด ์ปดํจํฐ ๊บผ์ง๋ฉด ํ์ผ ์ ๊ทผ ๋ถ๊ฐ์ผ ใ
ใ
ใ
๊ทธ๋์ Pinning ์๋น์ค๋ฅผ ์จ์ผ ํด. ๋ํ์ ์ธ ๊ฒ Pinata์ธ๋ฐ, ๋ฌด๋ฃ ํ๋๋ ์์ด์ ํ
์คํธํ๊ธฐ ์ข์.
Pinata๊ฐ 24/7 ํ์ผ์ ํํด์ค์ ํญ์ ์ ๊ทผ ๊ฐ๋ฅํ๊ฒ ํด์ค ๐
import requests
import json
import os
from typing import Optional
class PinataClient:
"""
Pinata IPFS Pinning ์๋น์ค ํด๋ผ์ด์ธํธ
https://pinata.cloud - ๋ฌด๋ฃ 1GB๊น์ง!
"""
BASE_URL = "https://api.pinata.cloud"
GATEWAY_URL = "https://gateway.pinata.cloud/ipfs"
def __init__(self, api_key: str, api_secret: str):
"""
Pinata API ํค ์ค์
pinata.cloud์์ ๋ฐ๊ธ๋ฐ์์ผ ํด!
"""
self.headers = {
'pinata_api_key': api_key,
'pinata_secret_api_key': api_secret
}
# ์ฐ๊ฒฐ ํ
์คํธ
self._test_connection()
def _test_connection(self):
"""API ์ฐ๊ฒฐ ํ
์คํธ"""
response = requests.get(
f"{self.BASE_URL}/data/testAuthentication",
headers=self.headers
)
if response.status_code == 200:
print("โ
Pinata ์ฐ๊ฒฐ ์ฑ๊ณต!")
else:
raise ConnectionError(f"Pinata ์ฐ๊ฒฐ ์คํจ: {response.text}")
def pin_file(self, file_path: str,
name: str = None,
metadata: dict = None) -> dict:
"""
ํ์ผ์ Pinata์ ์ง์ ์
๋ก๋ & ํ
"""
if not os.path.exists(file_path):
raise FileNotFoundError(f"ํ์ผ ์์: {file_path}")
filename = name or os.path.basename(file_path)
# ํ ๋ฉํ๋ฐ์ดํฐ ์ค์
pin_options = {
'pinataMetadata': {
'name': filename,
'keyvalues': metadata or {}
},
'pinataOptions': {
'cidVersion': 1 # CIDv1 ์ฌ์ฉ (์ต์ ๋ฒ์ )
}
}
with open(file_path, 'rb') as f:
files = {
'file': (filename, f),
'pinataOptions': (None, json.dumps(pin_options['pinataOptions'])),
'pinataMetadata': (None, json.dumps(pin_options['pinataMetadata']))
}
response = requests.post(
f"{self.BASE_URL}/pinning/pinFileToIPFS",
files=files,
headers={k: v for k, v in self.headers.items()}
)
if response.status_code == 200:
result = response.json()
return {
'cid': result['IpfsHash'],
'size': result['PinSize'],
'timestamp': result['Timestamp'],
'gateway_url': f"{self.GATEWAY_URL}/{result['IpfsHash']}",
'public_url': f"https://ipfs.io/ipfs/{result['IpfsHash']}"
}
else:
raise Exception(f"์
๋ก๋ ์คํจ: {response.text}")
def pin_json(self, data: dict, name: str = "document") -> dict:
"""
JSON ๋ฐ์ดํฐ๋ฅผ ์ง์ Pinata์ ํ
๋ฉํ๋ฐ์ดํฐ ์ ์ฅ์ ์ต์ !
"""
payload = {
'pinataContent': data,
'pinataMetadata': {'name': name},
'pinataOptions': {'cidVersion': 1}
}
response = requests.post(
f"{self.BASE_URL}/pinning/pinJSONToIPFS",
json=payload,
headers={**self.headers, 'Content-Type': 'application/json'}
)
if response.status_code == 200:
result = response.json()
return {
'cid': result['IpfsHash'],
'gateway_url': f"{self.GATEWAY_URL}/{result['IpfsHash']}"
}
else:
raise Exception(f"JSON ํ ์คํจ: {response.text}")
def pin_by_cid(self, cid: str, name: str = "") -> dict:
"""
์ด๋ฏธ IPFS์ ์๋ CID๋ฅผ Pinata๋ก ํ
๋ก์ปฌ ๋
ธ๋์์ ์ฌ๋ฆฐ ํ์ผ์ Pinata๋ก ์๊ตฌ ๋ณด์กดํ ๋!
"""
payload = {
'hashToPin': cid,
'pinataMetadata': {'name': name or cid}
}
response = requests.post(
f"{self.BASE_URL}/pinning/pinByHash",
json=payload,
headers={**self.headers, 'Content-Type': 'application/json'}
)
if response.status_code == 200:
print(f"๐ Pinata ํ ์๋ฃ: {cid}")
return response.json()
else:
raise Exception(f"ํ ์คํจ: {response.text}")
def list_pins(self, status: str = "pinned") -> list:
"""ํ๋ ํ์ผ ๋ชฉ๋ก ์กฐํ"""
response = requests.get(
f"{self.BASE_URL}/data/pinList?status={status}",
headers=self.headers
)
if response.status_code == 200:
data = response.json()
return data.get('rows', [])
return []
def unpin(self, cid: str) -> bool:
"""ํ ํด์ (์ ์ฅ ๊ณต๊ฐ ์ ์ฝ)"""
response = requests.delete(
f"{self.BASE_URL}/pinning/unpin/{cid}",
headers=self.headers
)
return response.status_code == 200
def get_usage(self) -> dict:
"""์ฌ์ฉ๋ ์กฐํ"""
response = requests.get(
f"{self.BASE_URL}/data/userPinnedDataTotal",
headers=self.headers
)
if response.status_code == 200:
data = response.json()
return {
'pin_count': data['pin_count'],
'pin_size_total': data['pin_size_total'],
'pin_size_with_replications': data['pin_size_with_replications_total']
}
return {}
# ํ๊ฒฝ๋ณ์๋ก API ํค ๊ด๋ฆฌ (๋ณด์!)
# .env ํ์ผ์ ์ ์ฅ:
# PINATA_API_KEY=your_api_key
# PINATA_API_SECRET=your_api_secret
from dotenv import load_dotenv
load_dotenv()
def create_pinata_client() -> PinataClient:
api_key = os.getenv('PINATA_API_KEY')
api_secret = os.getenv('PINATA_API_SECRET')
if not api_key or not api_secret:
raise ValueError("Pinata API ํค๊ฐ ์ค์ ๋์ง ์์! .env ํ์ผ ํ์ธํด")
return PinataClient(api_key, api_secret)
์๊ฐ ๊ฒ์ดํธ์จ์ด ์์ฒญ: 100GB
ํ ๊ฐ์: ๋ฌด์ ํ
๊ฐ์ธ ํ๋ก์ ํธ๋ ํ ์คํธ์ฉ์ผ๋ก๋ ์ถฉ๋ถํด! ์ค์ ์๋น์ค๋ ์ ๋ฃ ํ๋ ๊ณ ๋ คํด๋ด.
์ ์ด์ ์ง๊ธ๊น์ง ๋ง๋ ๋ชจ๋ ์ปดํฌ๋ํธ๋ฅผ ํ๋๋ก ํฉ์ณ์ ์์ฑ๋ ์์คํ
์ ๋ง๋ค์ด๋ณด์!
์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ์ฌ์ฉ์๋ค์ด ์์ ์ ํฌํธํด๋ฆฌ์ค๋ ์์
๋ฌผ์ ํ์ค์ํ ๋ฐฉ์์ผ๋ก ์ ์ฅํ ๋ ์ด๋ฐ ๊ตฌ์กฐ๋ฅผ ์ธ ์ ์์ด ๐
"""
ํ์ค์ ๋ฌธ์ ์ ์ฅ ์์คํ
- ๋ฉ์ธ ํตํฉ ๋ชจ๋
Python + IPFS + Pinata + ์ํธํ ์์ ์ฒด
"""
import os
import json
from datetime import datetime
from typing import Optional, List
# ์์ ๋ง๋ ๋ชจ๋๋ค ์ํฌํธ
# from ipfs_basic import IPFSClient
# from document_store import DecentralizedDocumentStore
# from document_schema import DocumentMetadata
# from encryption import DocumentEncryptor
# from pinata_client import PinataClient, create_pinata_client
class TotalDocumentSystem:
"""
์์ ํ ํ์ค์ ๋ฌธ์ ์ ์ฅ ์์คํ
๋ก์ปฌ IPFS + Pinata ์ด์ค ๋ณด์กด + ์ ํ์ ์ํธํ
"""
def __init__(self, use_pinata: bool = True, use_encryption: bool = False):
print("๐ ํ์ค์ ๋ฌธ์ ์์คํ
์ด๊ธฐํ ์ค...")
# ๋ก์ปฌ IPFS ์ฐ๊ฒฐ
import ipfshttpclient
self.ipfs = ipfshttpclient.connect('/ip4/127.0.0.1/tcp/5001')
# Pinata ํด๋ผ์ด์ธํธ (์ ํ)
self.pinata = None
if use_pinata:
try:
self.pinata = create_pinata_client()
print("๐ Pinata ์ฐ๊ฒฐ๋จ - ์ด์ค ๋ณด์กด ํ์ฑํ")
except Exception as e:
print(f"โ ๏ธ Pinata ์ฐ๊ฒฐ ์คํจ (๋ก์ปฌ๋ง ์ฌ์ฉ): {e}")
# ์ํธํ ๋ชจ๋ (์ ํ)
self.encryptor = None
if use_encryption:
self.encryptor = DocumentEncryptor()
print("๐ ์ํธํ ๋ชจ๋ ํ์ฑํ")
# ๋ก์ปฌ ์ธ๋ฑ์ค DB
self.db_path = "documents.db"
self._init_db()
print("โ
์์คํ
์ค๋น ์๋ฃ!\n")
def _init_db(self):
"""SQLite ์ธ๋ฑ์ค ์ด๊ธฐํ"""
import sqlite3
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS doc_registry (
id INTEGER PRIMARY KEY AUTOINCREMENT,
doc_id TEXT UNIQUE,
title TEXT,
author TEXT,
content_cid TEXT,
meta_cid TEXT,
is_encrypted INTEGER DEFAULT 0,
is_pinned INTEGER DEFAULT 0,
created_at TEXT,
tags TEXT
)
''')
conn.commit()
conn.close()
def save_document(self,
title: str,
content: str,
author: str,
tags: List[str] = None,
password: Optional[str] = None) -> dict:
"""
๋ฌธ์ ์ ์ฅ ๋ฉ์ธ ํจ์
Args:
title: ๋ฌธ์ ์ ๋ชฉ
content: ๋ฌธ์ ๋ด์ฉ
author: ์์ฑ์
tags: ํ๊ทธ ๋ชฉ๋ก
password: ์ํธํ ํจ์ค์๋ (None์ด๋ฉด ํ๋ฌธ ์ ์ฅ)
Returns:
์ ์ฅ ๊ฒฐ๊ณผ ๋์
๋๋ฆฌ
"""
print(f"๐ ๋ฌธ์ ์ ์ฅ: '{title}'")
print(f" ์์ฑ์: {author}")
print(f" ํฌ๊ธฐ: {len(content):,} ๊ธ์")
# 1. ์ํธํ (ํจ์ค์๋ ์์ ๋)
if password and self.encryptor:
print("๐ ์ํธํ ์ ์ฉ ์ค...")
upload_content = self.encryptor.encrypt_to_json(content, password)
is_encrypted = True
else:
upload_content = content
is_encrypted = False
# 2. IPFS์ ๋ด์ฉ ์
๋ก๋
content_cid = self.ipfs.add_bytes(upload_content.encode('utf-8'))
print(f"๐ค ๋ด์ฉ CID: {content_cid}")
# 3. ๋ฉํ๋ฐ์ดํฐ ์์ฑ ๋ฐ ์
๋ก๋
doc_id = f"doc_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
metadata = {
'doc_id': doc_id,
'title': title,
'author': author,
'tags': tags or [],
'content_cid': content_cid,
'is_encrypted': is_encrypted,
'created_at': datetime.now().isoformat(),
'system': 'TotalDocumentSystem v1.0'
}
meta_json = json.dumps(metadata, ensure_ascii=False)
meta_cid = self.ipfs.add_bytes(meta_json.encode('utf-8'))
print(f"๐ ๋ฉํ CID: {meta_cid}")
# 4. ๋ก์ปฌ ํ
self.ipfs.pin.add(content_cid)
self.ipfs.pin.add(meta_cid)
print("๐ ๋ก์ปฌ ํ ์๋ฃ")
# 5. Pinata ์ด์ค ๋ณด์กด
is_pinned = False
if self.pinata:
try:
self.pinata.pin_by_cid(content_cid, f"{title}_content")
self.pinata.pin_by_cid(meta_cid, f"{title}_meta")
is_pinned = True
print("โ๏ธ Pinata ์ด์ค ๋ณด์กด ์๋ฃ")
except Exception as e:
print(f"โ ๏ธ Pinata ํ ์คํจ (๋ก์ปฌ๋ง ๋ณด์กด): {e}")
# 6. ๋ก์ปฌ ์ธ๋ฑ์ค ๋ฑ๋ก
import sqlite3
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute('''
INSERT OR REPLACE INTO doc_registry
(doc_id, title, author, content_cid, meta_cid,
is_encrypted, is_pinned, created_at, tags)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (
doc_id, title, author, content_cid, meta_cid,
1 if is_encrypted else 0,
1 if is_pinned else 0,
datetime.now().isoformat(),
json.dumps(tags or [])
))
conn.commit()
conn.close()
result = {
'success': True,
'doc_id': doc_id,
'content_cid': content_cid,
'meta_cid': meta_cid,
'is_encrypted': is_encrypted,
'is_pinned': is_pinned,
'gateway_url': f"https://ipfs.io/ipfs/{content_cid}",
'pinata_url': f"https://gateway.pinata.cloud/ipfs/{content_cid}"
}
print(f"\n๐ ์ ์ฅ ์๋ฃ!")
print(f" ๋ฌธ์ ID: {doc_id}")
print(f" ๊ฒ์ดํธ์จ์ด: {result['gateway_url']}")
return result
def load_document(self,
cid: str,
password: Optional[str] = None) -> dict:
"""
CID๋ก ๋ฌธ์ ๋ก๋
"""
print(f"๐ฅ ๋ฌธ์ ๋ก๋: {cid}")
# IPFS์์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ
raw_content = self.ipfs.cat(cid).decode('utf-8')
# ์ํธํ ์ฌ๋ถ ํ์ธ ๋ฐ ๋ณตํธํ
try:
# JSON ํ์ฑ ์๋ (์ํธํ๋ ํจํค์ง์ธ์ง ํ์ธ)
parsed = json.loads(raw_content)
if 'encrypted_data' in parsed and 'algorithm' in parsed:
# ์ํธํ๋ ๋ฌธ์
if not password:
raise ValueError("๐ ์ด ๋ฌธ์๋ ์ํธํ๋จ. ํจ์ค์๋ ํ์!")
if not self.encryptor:
self.encryptor = DocumentEncryptor()
content = self.encryptor.decrypt_from_json(raw_content, password)
print("๐ ๋ณตํธํ ์๋ฃ")
else:
content = raw_content
except json.JSONDecodeError:
# ์ผ๋ฐ ํ
์คํธ
content = raw_content
return {
'cid': cid,
'content': content,
'length': len(content)
}
def list_documents(self, author: str = None) -> list:
"""์ ์ฅ๋ ๋ฌธ์ ๋ชฉ๋ก"""
import sqlite3
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
if author:
cursor.execute(
'SELECT doc_id, title, author, content_cid, created_at, tags FROM doc_registry WHERE author = ? ORDER BY created_at DESC',
(author,)
)
else:
cursor.execute(
'SELECT doc_id, title, author, content_cid, created_at, tags FROM doc_registry ORDER BY created_at DESC'
)
rows = cursor.fetchall()
conn.close()
return [{
'doc_id': r[0],
'title': r[1],
'author': r[2],
'content_cid': r[3],
'created_at': r[4],
'tags': json.loads(r[5]),
'gateway_url': f"https://ipfs.io/ipfs/{r[3]}"
} for r in rows]
# ===== ์ค์ ์ฌ์ฉ ์์ =====
if __name__ == "__main__":
# ์์คํ
์ด๊ธฐํ
system = TotalDocumentSystem(
use_pinata=False, # Pinata API ํค ์์ผ๋ฉด False
use_encryption=True # ์ํธํ ํ์ฑํ
)
# 1. ์ผ๋ฐ ๋ฌธ์ ์ ์ฅ
result1 = system.save_document(
title="ํ์ด์ฌ IPFS ํํ ๋ฆฌ์ผ",
content="์ด ๋ฌธ์๋ ํ์ค์ํ ์ ์ฅ ์์คํ
์ ์ ์ฅ๋ฉ๋๋ค. ๊ฒ์ด ๋ถ๊ฐ!",
author="๊ฐ๋ฐ์๊น์จ",
tags=["python", "ipfs", "web3", "tutorial"]
)
print("\n" + "="*50)
# 2. ์ํธํ ๋ฌธ์ ์ ์ฅ
result2 = system.save_document(
title="๋น๋ฐ ํ๋ก์ ํธ ๊ณํ์",
content="์ด ๋ด์ฉ์ ์ํธํ๋์ด ์ ์ฅ๋ฉ๋๋ค. ํจ์ค์๋ ์์ด๋ ์ฝ๊ธฐ ๋ถ๊ฐ!",
author="๊ฐ๋ฐ์๊น์จ",
tags=["secret", "encrypted"],
password="my_super_secret_password_123"
)
print("\n" + "="*50)
# 3. ๋ฌธ์ ๋ชฉ๋ก ์กฐํ
docs = system.list_documents()
print(f"\n๐ ์ ์ฅ๋ ๋ฌธ์ ์: {len(docs)}๊ฐ")
for doc in docs:
print(f" - [{doc['doc_id']}] {doc['title']} by {doc['author']}")
print("\n" + "="*50)
# 4. ๋ฌธ์ ๋ก๋
loaded = system.load_document(result1['content_cid'])
print(f"\n๐ ๋ก๋๋ ๋ด์ฉ: {loaded['content']}")
# 5. ์ํธํ ๋ฌธ์ ๋ก๋
loaded_enc = system.load_document(
result2['content_cid'],
password="my_super_secret_password_123"
)
print(f"๐ ๋ณตํธํ๋ ๋ด์ฉ: {loaded_enc['content']}")
๋งค๋ฒ ํ์ด์ฌ ์คํฌ๋ฆฝํธ ์ง์ ์คํํ๊ธฐ ๊ท์ฐฎ์์? CLI ๋๊ตฌ๋ก ๋ง๋ค๋ฉด ํฐ๋ฏธ๋์์ ๋ช
๋ น์ด ํ๋๋ก ๋๋ผ ์ ์์ด ใ
ใ
argparse ์จ์ ๊น๋ํ๊ฒ ๋ง๋ค์ด๋ณด์!
#!/usr/bin/env python3
"""
ํ์ค์ ๋ฌธ์ ์ ์ฅ ์์คํ
CLI ๋๊ตฌ
์ฌ์ฉ๋ฒ: python cli.py [command] [options]
"""
import argparse
import sys
import json
import os
def cmd_save(args):
"""๋ฌธ์ ์ ์ฅ ๋ช
๋ น"""
system = TotalDocumentSystem(
use_pinata=args.pinata,
use_encryption=bool(args.password)
)
# ํ์ผ์์ ์ฝ๊ธฐ ๋๋ ์ง์ ์
๋ ฅ
if args.file:
with open(args.file, 'r', encoding='utf-8') as f:
content = f.read()
else:
print("๋ด์ฉ์ ์
๋ ฅํ์ธ์ (Ctrl+D๋ก ์๋ฃ):")
content = sys.stdin.read()
tags = args.tags.split(',') if args.tags else []
result = system.save_document(
title=args.title,
content=content,
author=args.author,
tags=tags,
password=args.password
)
print(f"\nโ
์ ์ฅ ์๋ฃ!")
print(f"CID: {result['content_cid']}")
print(f"URL: {result['gateway_url']}")
def cmd_load(args):
"""๋ฌธ์ ๋ก๋ ๋ช
๋ น"""
system = TotalDocumentSystem(use_encryption=True)
result = system.load_document(args.cid, password=args.password)
if args.output:
with open(args.output, 'w', encoding='utf-8') as f:
f.write(result['content'])
print(f"โ
์ ์ฅ๋จ: {args.output}")
else:
print(result['content'])
def cmd_list(args):
"""๋ฌธ์ ๋ชฉ๋ก ๋ช
๋ น"""
system = TotalDocumentSystem()
docs = system.list_documents(author=args.author)
if not docs:
print("๐ญ ์ ์ฅ๋ ๋ฌธ์ ์์")
return
print(f"\n๐ ๋ฌธ์ ๋ชฉ๋ก ({len(docs)}๊ฐ):")
print("-" * 60)
for doc in docs:
print(f"์ ๋ชฉ: {doc['title']}")
print(f"์์ฑ์: {doc['author']}")
print(f"CID: {doc['content_cid'][:20]}...")
print(f"๋ ์ง: {doc['created_at'][:10]}")
print(f"ํ๊ทธ: {', '.join(doc['tags'])}")
print("-" * 60)
def main():
parser = argparse.ArgumentParser(
description='๐ ํ์ค์ ๋ฌธ์ ์ ์ฅ ์์คํ
',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
์ฌ์ฉ ์์:
python cli.py save -t "์ ๋ชฉ" -a "์์ฑ์" -f document.txt
python cli.py save -t "์ ๋ชฉ" -a "์์ฑ์" -f doc.txt -p "ํจ์ค์๋"
python cli.py load QmXxx...
python cli.py load QmXxx... -p "ํจ์ค์๋" -o output.txt
python cli.py list
python cli.py list -a "์์ฑ์๋ช
"
"""
)
subparsers = parser.add_subparsers(dest='command')
# save ๋ช
๋ น
save_parser = subparsers.add_parser('save', help='๋ฌธ์ ์ ์ฅ')
save_parser.add_argument('-t', '--title', required=True, help='๋ฌธ์ ์ ๋ชฉ')
save_parser.add_argument('-a', '--author', required=True, help='์์ฑ์')
save_parser.add_argument('-f', '--file', help='ํ์ผ ๊ฒฝ๋ก')
save_parser.add_argument('--tags', help='ํ๊ทธ (์ผํ ๊ตฌ๋ถ)')
save_parser.add_argument('-p', '--password', help='์ํธํ ํจ์ค์๋')
save_parser.add_argument('--pinata', action='store_true', help='Pinata ์ด์ค ๋ณด์กด')
# load ๋ช
๋ น
load_parser = subparsers.add_parser('load', help='๋ฌธ์ ๋ก๋')
load_parser.add_argument('cid', help='IPFS CID')
load_parser.add_argument('-p', '--password', help='๋ณตํธํ ํจ์ค์๋')
load_parser.add_argument('-o', '--output', help='์ถ๋ ฅ ํ์ผ ๊ฒฝ๋ก')
# list ๋ช
๋ น
list_parser = subparsers.add_parser('list', help='๋ฌธ์ ๋ชฉ๋ก')
list_parser.add_argument('-a', '--author', help='์์ฑ์ ํํฐ')
args = parser.parse_args()
if args.command == 'save':
cmd_save(args)
elif args.command == 'load':
cmd_load(args)
elif args.command == 'list':
cmd_list(args)
else:
parser.print_help()
if __name__ == '__main__':
main()
python cli.py save -t "๋ด ํฌํธํด๋ฆฌ์ค" -a "ํ๊ธธ๋" -f portfolio.pdf --pinatapython cli.py load QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdGpython cli.py list -a "ํ๊ธธ๋"
์ฝ๋ ์ง๋ค ๋ณด๋ฉด ๋ฐ๋์ ๋ง์ฃผ์น๋ ๋ฌธ์ ๋ค์ด ์์ด. ๋ฏธ๋ฆฌ ์๊ณ ๊ฐ๋ฉด ์๊ฐ ์ ์ฝ ์์ฒญ ๋ผ ๐ค
IPFS ๊ฐ๋น์ง ์ปฌ๋ ์ ์ด ๋๋ฉด ํ ์ ๋ ํ์ผ์ ์ญ์ ๋ผ. ์ ๋ก๋ ํ ๋ฐ๋์
ipfs.pin.add(cid) ํธ์ถํด์ผ ํด!Pinata ๊ฐ์ ์ธ๋ถ ํ๋ ์๋น์ค๋ ๊ฐ์ด ์ฐ๋ฉด ๋ ์์ .
IPFS๋ CID๊ฐ ์์ผ๋ฉด ํ์ผ ์ฐพ์ ๋ฐฉ๋ฒ์ด ์์ด. ๋ฐ๋์ ๋ก์ปฌ DB๋ ๋ธ๋ก์ฒด์ธ์ CID๋ฅผ ๊ธฐ๋กํด๋ฌ์ผ ํด.
SQLite ์ธ๋ฑ์ค + ๋ธ๋ก์ฒด์ธ ์จ์ฒด์ธ ๊ธฐ๋ก ์ด์ค์ผ๋ก ํ๋ ๊ฒ ๋ฒ ์คํธ.
IPFS๋ 256KB ์ฒญํฌ๋ก ์๋ ๋ถํ ํ์ง๋ง, ๋๋ฌด ํฐ ํ์ผ์ ์ ๋ก๋ ์๊ฐ์ด ๊ธธ์ด.
100MB ์ด์์ด๋ฉด
ipfs.add(file, chunker='size-1048576')๋ก ์ฒญํฌ ํฌ๊ธฐ ์กฐ์ ํ๊ฑฐ๋ ์คํธ๋ฆฌ๋ฐ ์
๋ก๋ ์จ.
๋น์ฐํ ๋ง์ด์ง๋ง
ipfs daemon์ด ์คํ ์ค์ด์ด์ผ ํด.ํ๋ก๋์ ํ๊ฒฝ์์๋ systemd ์๋น์ค๋ก ๋ฑ๋กํด์ ์๋ ์์๋๊ฒ ํด์ผ ํจ.
์ํธํ ํจ์ค์๋๋ฅผ ์ฝ๋์ ํ๋์ฝ๋ฉํ๊ฑฐ๋ ํ๋ฌธ ํ์ผ์ ์ ์ฅํ๋ฉด ์ ๋ผ.
๋ฐ๋์ ํ๊ฒฝ๋ณ์(
.env)๋ ์ํฌ๋ฆฟ ๋งค๋์ (AWS Secrets Manager, HashiCorp Vault ๋ฑ) ์ฌ์ฉ!
1. ๋ฐฐ์น ์
๋ก๋
์ฌ๋ฌ ํ์ผ ์ฌ๋ฆด ๋ ํ๋์ฉ ์ฌ๋ฆฌ์ง ๋ง๊ณ ipfs.add_multiple() ์จ์ ํ ๋ฒ์ ์ฒ๋ฆฌํด.
2. ๋ก์ปฌ ์บ์ฑ
์์ฃผ ์ฝ๋ ํ์ผ์ ๋ก์ปฌ์ ์บ์ํด๋๋ฉด IPFS ๋คํธ์ํฌ ์์ฒญ ์ค์ผ ์ ์์ด.
functools.lru_cache๋ Redis ์จ๋ด.
3. ๊ฒ์ดํธ์จ์ด ์ ํ
๊ณต๊ฐ ๊ฒ์ดํธ์จ์ด(ipfs.io, cloudflare-ipfs.com)๋ ๋๋ฆด ์ ์์ด.
Pinata ์ ์ฉ ๊ฒ์ดํธ์จ์ด๋ ์์ฒด ๊ฒ์ดํธ์จ์ด ์ด์ํ๋ฉด ํจ์ฌ ๋น ๋ฆ.
4. CIDv1 ์ฌ์ฉ
ipfs.add(file, cid_version=1)๋ก CIDv1 ์ฐ๋ฉด base32 ์ธ์ฝ๋ฉ์ด๋ผ URL์์ ๋ ์์ ํ๊ณ ๋์๋ฌธ์ ๊ตฌ๋ถ ์์ด.
IPFS๋ง์ผ๋ก๋ ์ถฉ๋ถํ์ง๋ง, CID๋ฅผ ์ด๋๋ฆฌ์ ๋ธ๋ก์ฒด์ธ์ ๊ธฐ๋กํ๋ฉด ์์ ๊ถ ์ฆ๋ช
+ ํ์์คํฌํ + ๋ถ๋ณ์ฑ๊น์ง ์๋ฒฝํ๊ฒ ๋ณด์ฅ๋ผ.
์ด๊ฒ ์ง์ง Web3 ์คํ์ด์ผ! ๐ฅ
from web3 import Web3
import json
import os
# ๊ฐ๋จํ ์ค๋งํธ ์ปจํธ๋ํธ ABI (Solidity๋ก ๋ฐฐํฌํ ๊ฒ)
DOCUMENT_REGISTRY_ABI = [
{
"inputs": [
{"name": "cid", "type": "string"},
{"name": "title", "type": "string"},
{"name": "docHash", "type": "bytes32"}
],
"name": "registerDocument",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{"name": "cid", "type": "string"}],
"name": "getDocument",
"outputs": [
{"name": "owner", "type": "address"},
{"name": "title", "type": "string"},
{"name": "timestamp", "type": "uint256"},
{"name": "docHash", "type": "bytes32"}
],
"stateMutability": "view",
"type": "function"
}
]
class BlockchainAnchor:
"""
IPFS CID๋ฅผ ์ด๋๋ฆฌ์ ๋ธ๋ก์ฒด์ธ์ ์ต์ปค๋ง
์์ ๊ถ ์ฆ๋ช
+ ํ์์คํฌํ ๋ถ๋ณ ๊ธฐ๋ก
"""
def __init__(self,
rpc_url: str, # ์ด๋๋ฆฌ์ RPC (Infura, Alchemy ๋ฑ)
contract_address: str, # ๋ฐฐํฌ๋ ์ปจํธ๋ํธ ์ฃผ์
private_key: str): # ์๋ช
์ฉ ๊ฐ์ธํค
self.w3 = Web3(Web3.HTTPProvider(rpc_url))
if not self.w3.is_connected():
raise ConnectionError("์ด๋๋ฆฌ์ ๋
ธ๋ ์ฐ๊ฒฐ ์คํจ!")
print(f"โ
์ด๋๋ฆฌ์ ์ฐ๊ฒฐ: ์ฒด์ธ ID {self.w3.eth.chain_id}")
# ์ปจํธ๋ํธ ์ธ์คํด์ค
self.contract = self.w3.eth.contract(
address=Web3.to_checksum_address(contract_address),
abi=DOCUMENT_REGISTRY_ABI
)
# ๊ณ์ ์ค์
self.account = self.w3.eth.account.from_key(private_key)
print(f"๐ ๊ณ์ : {self.account.address}")
def anchor_cid(self, cid: str, title: str, content: str) -> dict:
"""
CID๋ฅผ ๋ธ๋ก์ฒด์ธ์ ๊ธฐ๋ก
"""
import hashlib
# ๋ฌธ์ ํด์ (bytes32)
doc_hash = hashlib.sha256(content.encode()).digest()
doc_hash_bytes32 = doc_hash[:32]
print(f"โ๏ธ ๋ธ๋ก์ฒด์ธ ์ต์ปค๋ง: {cid[:20]}...")
# ํธ๋์ญ์
๋น๋
nonce = self.w3.eth.get_transaction_count(self.account.address)
tx = self.contract.functions.registerDocument(
cid, title, doc_hash_bytes32
).build_transaction({
'from': self.account.address,
'nonce': nonce,
'gas': 200000,
'gasPrice': self.w3.eth.gas_price
})
# ์๋ช
๋ฐ ์ ์ก
signed_tx = self.w3.eth.account.sign_transaction(tx, self.account.key)
tx_hash = self.w3.eth.send_raw_transaction(signed_tx.rawTransaction)
print(f"๐จ ํธ๋์ญ์
์ ์ก: {tx_hash.hex()}")
# ์์์ฆ ๋๊ธฐ
receipt = self.w3.eth.wait_for_transaction_receipt(tx_hash, timeout=120)
result = {
'tx_hash': tx_hash.hex(),
'block_number': receipt['blockNumber'],
'gas_used': receipt['gasUsed'],
'cid': cid,
'anchored': receipt['status'] == 1
}
if result['anchored']:
print(f"โ
์ต์ปค๋ง ์๋ฃ! ๋ธ๋ก #{result['block_number']}")
else:
print("โ ํธ๋์ญ์
์คํจ!")
return result
def verify_cid(self, cid: str) -> dict:
"""
๋ธ๋ก์ฒด์ธ์์ CID ์์ ๊ถ ๋ฐ ํ์์คํฌํ ๊ฒ์ฆ
"""
try:
owner, title, timestamp, doc_hash = self.contract.functions.getDocument(cid).call()
from datetime import datetime
registered_time = datetime.fromtimestamp(timestamp)
return {
'verified': True,
'owner': owner,
'title': title,
'registered_at': registered_time.isoformat(),
'doc_hash': doc_hash.hex()
}
except Exception as e:
return {'verified': False, 'error': str(e)}
๊ฐ๋ฐ ์ค์๋ Sepolia๋ Mumbai(Polygon ํ ์คํธ๋ท) ์จ์ ๋ฌด๋ฃ๋ก ํ ์คํธํด.
Infura๋ Alchemy์์ ๋ฌด๋ฃ RPC ์๋ํฌ์ธํธ ๋ฐ์ ์ ์์ด!
์ ์ค๋ ๋ฐฐ์ด ๋ด์ฉ ์ ๋ฆฌํด๋ณด์. ํ์ด์ฌ + IPFS ์กฐํฉ์ผ๋ก ๋ง๋ค ์ ์๋ ๊ฒ๋ค์ด ์ง์ง ๋ง์ ๐คฉ
๐ ํ์ค์ ํฌํธํด๋ฆฌ์ค ํ๋ซํผ
์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ํ๋ฆฌ๋์๋ค์ด ์์ ์ ์์
๋ฌผ์ IPFS์ ์ฌ๋ฆฌ๋ฉด, ํ๋ซํผ์ด ๋งํด๋ ํฌํธํด๋ฆฌ์ค๋ ์๊ตฌ ๋ณด์กด๋ผ. ์ง์ง ๋ด ๊ฒ์ด ๋๋ ๊ฑฐ์ผ!
๐ฐ ๊ฒ์ด ์ ํญ ๋ฏธ๋์ด
์ธ๋ก ์์ ๊ฐ ์ ํ๋ ํ๊ฒฝ์์ ๊ธฐ์ฌ๋ ๋ฌธ์๋ฅผ IPFS์ ์ฌ๋ฆฌ๋ฉด ์ญ์ ๋ถ๊ฐ. ์ค์ ๋ก ํ์ฝฉ ์์ ๋ IPFS ๋ง์ด ์ผ์ด.
๐ ํ์ ๋
ผ๋ฌธ ์์นด์ด๋ธ
๋
ผ๋ฌธ์ IPFS์ ์ฌ๋ฆฌ๊ณ DOI ๋์ CID ์ฌ์ฉ. ์๊ตฌ ์ ๊ทผ ๊ฐ๋ฅํ๊ณ ์๋ณ์กฐ ๋ถ๊ฐ.
โ๏ธ ๋ฒ์ ๋ฌธ์ ํ์์คํฌํ
๊ณ์ฝ์, ํนํ ์์ด๋์ด ๋ฑ์ IPFS + ๋ธ๋ก์ฒด์ธ์ ๊ธฐ๋กํ๋ฉด ๋ฒ์ ์ฆ๊ฑฐ๋ ฅ ์๋ ํ์์คํฌํ ์์ฑ.
๐ฎ NFT ๋ฉํ๋ฐ์ดํฐ ์ ์ฅ
NFT์ ์ด๋ฏธ์ง์ ๋ฉํ๋ฐ์ดํฐ๋ฅผ IPFS์ ์ ์ฅํ๋ฉด ์ค์ ์๋ฒ ์์กด ์์ด ์๊ตฌ ๋ณด์กด. ์ง์ง ํ์ค์ NFT!
Python 3.8+ โ ๋ฉ์ธ ๊ฐ๋ฐ ์ธ์ด
ipfshttpclient โ IPFS API ํต์
Kubo (go-ipfs) โ ๋ก์ปฌ IPFS ๋
ธ๋
Pinata โ ํด๋ผ์ฐ๋ ํ๋ ์๋น์ค
cryptography โ AES-256-GCM ์ํธํ
SQLite โ ๋ก์ปฌ CID ์ธ๋ฑ์ค
web3.py โ ๋ธ๋ก์ฒด์ธ ์ฐ๋ (์ ํ)
argparse โ CLI ์ธํฐํ์ด์ค
์ด ์์คํ
๊ตฌ์ถํ๋ ๋ฐ ๊ด์ฌ ์๋ ๋ถ๋ค, ํน์ ํ์ด์ฌ์ด๋ Web3 ๊ฐ๋ฐ ๋์์ด ํ์ํ๋ค๋ฉด ์ฌ๋ฅ๋ท์์ ๊ด๋ จ ์ ๋ฌธ๊ฐ๋ฅผ ์ฐพ์๋ณผ ์ ์์ด. ๋ธ๋ก์ฒด์ธ ๊ฐ๋ฐ์๋ค์ด ๊ฝค ๋ง์ด ํ๋ํ๊ณ ์๊ฑฐ๋ ๐
ํ์ค์ํ ๊ธฐ์ ์ ์์ง ๋ฐ์ ์ค์ด๊ณ , IPFS๋ ๊ณ์ ์
๋ฐ์ดํธ๋๊ณ ์์ด. ํนํ Filecoin๊ณผ์ ํตํฉ์ผ๋ก ๊ฒฝ์ ์ ์ธ์ผํฐ๋ธ ๊ธฐ๋ฐ ์๊ตฌ ์ ์ฅ์ด ๊ฐ๋ฅํด์ง๊ณ ์๊ณ , IPFS Cluster๋ก ์ฌ๋ฌ ๋
ธ๋๋ฅผ ๋ฌถ์ด์ ๋ ์์ ์ ์ธ ์๋น์ค๋ ๋ง๋ค ์ ์์ด.
Web3 ์ธ๊ณ์์ "๋ด ๋ฐ์ดํฐ๋ ๋ด๊ฐ ์์ ํ๋ค"๋ ์ฒ ํ, ์ด์ ์ฝ๋๋ก ์ง์ ๊ตฌํํ ์ ์๊ฒ ๋์ง? ๐
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.