Skip to content

Commit 5d8cfeb

Browse files
authored
Create hack.md
1 parent d9dec54 commit 5d8cfeb

1 file changed

Lines changed: 189 additions & 0 deletions

File tree

hack.md

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# vLEI Verifier Technical Documentation
2+
3+
## Overview
4+
The vLEI Verifier is a service that verifies vLEI credentials. It implements a robust verification system that handles cryptographic verification, authorization, and state management.
5+
6+
## Core Components
7+
8+
### 1. Cryptographic Verification (`/presentations` Endpoint)
9+
10+
The verification process in the `/presentations` endpoint follows these steps:
11+
12+
1. **Request Validation**
13+
- Accepts CESR format
14+
- Requires a witness URL (mandatory in production)
15+
- Validates content type as `application/json+cesr`
16+
17+
2. **Credential Processing**
18+
```python
19+
parsing.Parser().parse(ims=ims, kvy=self.hby.kvy, tvy=self.tvy, vry=self.vry)
20+
```
21+
- Parses the incoming CESR message
22+
- Verifies cryptographic signatures
23+
- Validates credential structure
24+
25+
3. **State Management**
26+
- Credentials can be in states:
27+
- `CRED_CRYPT_INVALID`: Cryptographic verification failed
28+
- `CRED_CRYPT_VALID`: Cryptographic verification passed
29+
- `AUTH_PENDING`: Awaiting authorization
30+
- `AUTH_SUCCESS`: Fully authorized
31+
- `AUTH_REVOKED`: Credential has been revoked
32+
- `AUTH_FAIL`: Credential unauthorized
33+
34+
4. **Witness Integration**
35+
- Witness URL is stored with credential state
36+
- Used for revocation checks
37+
- Mandatory in production environment
38+
39+
### 2. Authorization System (`authorizing.py`)
40+
41+
The authorization system implements a multi-layer verification process:
42+
43+
1. **Credential Filters**
44+
```python
45+
def cred_filters(self, creder) -> tuple[bool, str]:
46+
```
47+
- Validates credential schema
48+
- Checks credential type
49+
- Verifies issuer authorization
50+
51+
2. **Chain Filters**
52+
```python
53+
def chain_filters(self, creder) -> tuple[bool, str]:
54+
```
55+
- Validates credential chain
56+
- Verifies issuer hierarchy
57+
- Checks credential dependencies
58+
59+
3. **Edge Filters**
60+
```python
61+
def edge_filters(self, cred_type: str, edge, valid_edges: dict):
62+
```
63+
- Validates credential edges
64+
- Verifies relationships between credentials
65+
66+
4. **Attribute Filters**
67+
```python
68+
def attr_filters(self, cred, valid_attrs: dict):
69+
```
70+
- Validates credential attributes
71+
- Verifies attribute values
72+
- Checks attribute constraints
73+
74+
### 3. State Management (`basing.py`)
75+
76+
The state management system provides persistent storage and state tracking:
77+
78+
1. **Credential States**
79+
```python
80+
@dataclass
81+
class CredProcessState:
82+
said: Optional[str] = None
83+
aid: Optional[str] = None
84+
state: Optional[str] = None
85+
info: Optional[str] = None
86+
role: Optional[str] = None
87+
witness_url: Optional[str] = None
88+
date: str = field(default_factory=lambda: datetime.datetime.now(datetime.UTC).isoformat())
89+
```
90+
- Tracks credential processing state
91+
- Stores verification metadata
92+
- Maintains witness URL information
93+
94+
2. **State History**
95+
```python
96+
@dataclass
97+
class StateHistory:
98+
aid: Optional[str] = None
99+
last_update: float = field(default_factory=lambda: time.time())
100+
state_history: List[CredProcessState | AidProcessState] = field(default_factory=lambda: [])
101+
```
102+
- Maintains historical state changes
103+
- Tracks credential lifecycle
104+
- Supports audit trails
105+
106+
3. **Database Management**
107+
```python
108+
class VerifierBaser(dbing.LMDBer):
109+
```
110+
- Provides persistent storage
111+
- Manages credential states
112+
- Handles state transitions
113+
114+
## Usage Notes
115+
116+
1. **Production Requirements**
117+
- Witness URL is mandatory
118+
- All cryptographic verifications must pass
119+
- Authorization must be complete
120+
121+
2. **State Transitions**
122+
- States are immutable
123+
- History is preserved
124+
- Transitions are logged
125+
126+
3. **Error Handling**
127+
- Invalid credentials are rejected
128+
- Failed verifications are logged
129+
- State changes are tracked
130+
131+
## Implementation Details
132+
133+
### 1. Cryptographic Verification Flow
134+
135+
The verification process starts in the `PresentationResourceEndpoint.on_put` method:
136+
137+
**File:** `src/verifier/core/verifying.py`
138+
**Class:** `PresentationResourceEndpoint`
139+
**Method:** `on_put`
140+
**Lines:** ~280-400
141+
142+
The key steps are:
143+
1. Parse the CESR message using KERI's parser
144+
2. Check if the credential was found and valid
145+
3. Update the credential state in the database
146+
4. Store the witness URL for future revocation checks
147+
148+
### 2. Authorization Flow
149+
150+
The authorization process is handled by the `Authorizer` class:
151+
152+
**File:** `src/verifier/core/authorizing.py`
153+
**Class:** `Authorizer`
154+
**Method:** `processPresentations`
155+
**Lines:** ~70-150
156+
157+
The authorization process:
158+
1. Iterates through credentials in the database
159+
2. Applies credential filters to validate schema and type
160+
3. Applies chain filters to validate issuer hierarchy
161+
4. Updates credential state based on filter results
162+
163+
### 3. State Management Flow
164+
165+
State management is handled by the `VerifierBaser` class:
166+
167+
**File:** `src/verifier/core/basing.py`
168+
**Class:** `VerifierBaser`
169+
**Lines:** ~169-220
170+
171+
State transitions are managed through:
172+
1. Pinning new states to the database
173+
2. Updating state history
174+
3. Tracking state changes over time
175+
176+
### 4. Revocation Checking Flow
177+
178+
The revocation checking process is handled by the `CredentialRevocationChecker` class:
179+
180+
**File:** `src/verifier/core/observing.py`
181+
**Class:** `CredentialRevocationChecker`
182+
**Method:** `_check_revocations`
183+
**Lines:** ~35-63
184+
185+
The revocation checking process:
186+
1. Iterates through credentials in the database
187+
2. Checks with the witness for credential status
188+
3. Processes revocation information
189+
4. Updates credential state if revoked

0 commit comments

Comments
 (0)