Skip to content

Commit 9cc4b7e

Browse files
authored
Merge pull request #2 from volaradlp/user-authentication-chain-flow
Add flow for user validation
2 parents be27311 + 07a6da7 commit 9cc4b7e

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

volara_proof/extract/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
import zipfile
2+
import json
3+
from volara_proof.models.user_data import UserData
24
from volara_proof.buffers.tweets import Tweets
35

46

7+
def extract_user_data(zip_file_path: str) -> UserData | None:
8+
with zipfile.ZipFile(zip_file_path, "r") as zip_ref:
9+
file_names = zip_ref.namelist()
10+
if "user_data.json" in file_names:
11+
with zip_ref.open("user_data.json", "r") as file:
12+
return UserData(**json.load(file))
13+
else:
14+
return None
15+
16+
517
def extract_data(zip_file_path: str):
618
"""
719
Extracts the data from the zip file

volara_proof/models/user_data.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
Contains the dataclass models for the Tweet data structure
3+
"""
4+
5+
from dataclasses import dataclass
6+
7+
8+
@dataclass
9+
class UserData:
10+
handle: str
11+
wallet_address: str

volara_proof/proofs/proof.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
import copy
22

3-
from volara_proof.extract import extract_data
3+
from volara_proof.extract import extract_data, extract_user_data
44
from volara_proof.proofs.proof_of_quality import proof_of_quality
55
from volara_proof.models.proof_response import ProofResponse
66
from volara_proof.models.proof_config import ProofConfig
77

88
from volara_proof.storage.rewards import RewardsStorage
9+
from volara_proof.storage.user_info import UserInfoStorage
910

1011
rewards_storage = RewardsStorage()
12+
user_info_storage = UserInfoStorage()
1113

1214

1315
def proof(
1416
input_file: str, proof_response: ProofResponse, config: ProofConfig
1517
) -> ProofResponse:
1618
proof_response = copy.deepcopy(proof_response)
19+
user_data = extract_user_data(input_file)
20+
if user_data is not None:
21+
proof_response.score = 0
22+
proof_response.valid = user_info_storage.verify_user(user_data)
23+
return proof_response
1724
tweets_data = extract_data(input_file)
1825
is_valid, file_score, tweet_info, unique_tweets, total_tweets = (
1926
proof_of_quality(tweets_data, config.file_id, config)

volara_proof/storage/user_info.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import logging
2+
import os
3+
import requests
4+
5+
from volara_proof.models.user_data import UserData
6+
from volara_proof.constants import VOLARA_API_URL
7+
8+
9+
class UserInfoStorage:
10+
def verify_user(self, user_info: UserData) -> bool:
11+
request_body = {
12+
"handle": user_info.handle,
13+
"walletAddress": user_info.wallet_address,
14+
}
15+
try:
16+
resp = requests.post(
17+
url=f"{VOLARA_API_URL}/v1/validator/validate-user",
18+
json=request_body,
19+
headers={"Authorization": f"Bearer {os.environ['VOLARA_API_KEY']}"},
20+
)
21+
resp.raise_for_status()
22+
logging.info("Succesfully determined if user exists.")
23+
return resp.json()["userValidated"]
24+
except Exception:
25+
logging.exception("[CRITICAL FAILURE] Failed to determine if user exists.")
26+
raise

0 commit comments

Comments
 (0)