-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_nullifier_decrypt.py
More file actions
42 lines (32 loc) · 1.37 KB
/
Copy pathtest_nullifier_decrypt.py
File metadata and controls
42 lines (32 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import sys
# add backend path so imports work
sys.path.append(os.path.abspath('backend'))
from config import get_settings
from ecies_service import get_identity_blob, decrypt_identity
def test_nullifier(nullifier_hex):
# Get active private key from environment / config
settings = get_settings()
priv_hex = settings.issuer_private_key_hex
if not priv_hex:
print("Error: No ISSUER_PRIVATE_KEY_HEX set in backend config/env.")
return
priv_bytes = bytes.fromhex(priv_hex)
# Check if we have an encrypted blob for this nullifier in memory
blob_hex = get_identity_blob(nullifier_hex)
if not blob_hex:
print(f"Error: No in-memory encrypted blob found for nullifier '{nullifier_hex}'.")
print("Note: The backend must have captured the registration DURING THIS RUN to have the blob, as it is strictly stored in-memory and lost on restart.")
return
print(f"Found encrypted blob! Size: {len(blob_hex) // 2} bytes")
# Try decrypt
try:
dec = decrypt_identity(priv_bytes, blob_hex)
print(f"\nSUCCESS! Decrypted payload:\n{dec}")
except Exception as e:
print(f"\nFAILED! Exception during decryption: {e}")
if __name__ == "__main__":
if len(sys.argv) > 1:
test_nullifier(sys.argv[1])
else:
print("Provide nullifier hex as argument.")