Skip to content

Commit fdcd642

Browse files
umweltclaude
andauthored
[P3] Implement Guardian Social Recovery Methods (#28)
* Fix guardian API paths and implement missing methods - Fixed all 6 existing guardian methods to use correct /api/v1/identity paths - Changed removeGuardian() to use DELETE method - Implemented completeRecovery() method - Implemented rejectRecovery() method - Implemented getPendingRecoveries() method - Updated method signatures to match node implementation All 9 guardian endpoints now implemented correctly. * Fix critical guardian method mismatches with node implementation Fixed 6 critical issues where client methods didn't match node API: 1. addGuardian(): Added session_token and guardian_public_key parameters 2. listGuardians(): Changed to use Authorization header instead of query params 3. removeGuardian(): Changed to use Authorization header, removed identity_id param 4. approveRecovery(): Added session_token, changed signature from string to number[] 5. rejectRecovery(): Added session_token and signature parameters 6. getPendingRecoveries(): Added Authorization header with session_token Updated types to match node responses: - Guardian interface now matches GuardianInfo from node - GuardianResponse includes total_guardians - RecoverySession matches InitiateRecoveryResponse - RecoveryStatus matches RecoveryStatusResponse All methods now correctly implement node's guardian.rs API contract. Verified against zhtp/src/api/handlers/guardian.rs lines 200-946. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 45e8cad commit fdcd642

File tree

8 files changed

+172
-125
lines changed

8 files changed

+172
-125
lines changed

dist/core/types.d.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -284,41 +284,29 @@ export interface BackupStatus {
284284
}
285285
export interface Guardian {
286286
guardian_id: string;
287-
guardian_name?: string;
288-
status: 'pending' | 'active' | 'revoked';
287+
guardian_did: string;
288+
name: string;
289289
added_at: number;
290-
relationship?: string;
290+
status: string;
291291
}
292292
export interface GuardianResponse {
293293
status: string;
294294
guardian_id: string;
295-
message: string;
295+
total_guardians: number;
296296
}
297297
export interface RecoverySession {
298+
status: string;
298299
recovery_id: string;
299-
identity_id: string;
300-
status: 'initiated' | 'pending_approvals' | 'completed' | 'cancelled';
301-
required_approvals: number;
302-
current_approvals: number;
303-
guardian_ids: string[];
304-
created_at: number;
300+
guardians_required: number;
301+
guardians_approved: number;
305302
expires_at: number;
306303
}
307304
export interface RecoveryStatus {
308305
recovery_id: string;
309-
status: 'initiated' | 'pending_approvals' | 'completed' | 'cancelled' | 'failed';
310-
progress: {
311-
required: number;
312-
approved: number;
313-
declined: number;
314-
};
315-
guardians: Array<{
316-
guardian_id: string;
317-
status: 'pending' | 'approved' | 'declined';
318-
responded_at?: number;
319-
}>;
320-
created_at: number;
321-
updated_at: number;
306+
status: string;
307+
approvals: number;
308+
required: number;
322309
expires_at: number;
310+
identity_did: string;
323311
}
324312
//# sourceMappingURL=types.d.ts.map

dist/core/types.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core/zhtp-api-methods.d.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,33 @@ export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
8080
*/
8181
verifySeedPhrase(identityId: string, seedPhrase: string): Promise<SeedVerification>;
8282
exportSeedPhrases(identityId: string): Promise<SeedPhrases>;
83-
addGuardian(identityId: string, guardianId: string, guardianInfo?: Record<string, any>): Promise<GuardianResponse>;
84-
listGuardians(identityId: string): Promise<Guardian[]>;
85-
removeGuardian(identityId: string, guardianId: string): Promise<void>;
86-
acceptGuardianInvite(guardianId: string, identityId: string): Promise<void>;
87-
declineGuardianInvite(guardianId: string, identityId: string): Promise<void>;
88-
initiateRecovery(identityId: string, guardianIds: string[]): Promise<RecoverySession>;
89-
approveRecovery(guardianId: string, recoveryId: string, approval: boolean): Promise<void>;
83+
addGuardian(identityId: string, sessionToken: string, guardianDid: string, guardianPublicKey: number[], guardianName: string): Promise<GuardianResponse>;
84+
listGuardians(sessionToken: string): Promise<{
85+
guardians: Guardian[];
86+
threshold: number;
87+
}>;
88+
removeGuardian(guardianId: string, sessionToken: string): Promise<void>;
89+
initiateRecovery(identityDid: string, requesterDevice: string): Promise<RecoverySession>;
90+
approveRecovery(recoveryId: string, guardianDid: string, sessionToken: string, signature: number[]): Promise<{
91+
status: string;
92+
approvals: number;
93+
required: number;
94+
}>;
95+
rejectRecovery(recoveryId: string, guardianDid: string, sessionToken: string, signature: number[]): Promise<void>;
96+
completeRecovery(recoveryId: string): Promise<{
97+
status: string;
98+
session_token: string;
99+
identity_did: string;
100+
}>;
90101
getRecoveryStatus(recoveryId: string): Promise<RecoveryStatus>;
91-
cancelRecovery(recoveryId: string): Promise<void>;
102+
getPendingRecoveries(sessionToken: string): Promise<{
103+
pending_requests: Array<{
104+
recovery_id: string;
105+
identity_did: string;
106+
initiated_at: number;
107+
expires_at: number;
108+
}>;
109+
}>;
92110
applyCitizenship(identityId: string, applicationData?: Record<string, any>): Promise<CitizenshipResult>;
93111
createZkDid(didData?: Record<string, any>): Promise<any>;
94112
getIdentity(did: string): Promise<Identity>;

0 commit comments

Comments
 (0)