Skip to content

Commit b72fc5c

Browse files
authored
Add SID (Sovereign Identity) API implementation (#2)
* Add complete SID API methods for backup, recovery, and guardians - Add backup operations: export, import, verify - Add seed phrase operations: verify, export - Add guardian management: add, list, remove, accept, decline - Add guardian recovery flow: initiate, approve, status, cancel - Add citizenship application endpoint - Fix endpoint paths to match core API - Add all required TypeScript types for SID features * Add comprehensive unit tests for SID API methods - Add 22 tests for backup operations (export, import, verify) - Add tests for seed phrase operations (verify, export) - Add tests for guardian management (add, list, remove, accept, decline) - Add tests for guardian recovery flow (initiate, approve, status, cancel) - Add tests for citizenship application - Add error handling tests for HTTP errors - Increase zhtp-api-methods coverage from 47.65% to 59.37% - Increase overall test count from 168 to 190 tests * Add comprehensive ZHTP API integration tests
1 parent 34a676f commit b72fc5c

File tree

10 files changed

+1675
-8
lines changed

10 files changed

+1675
-8
lines changed

dist/core/types.d.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,71 @@ export interface CitizenshipResult {
248248
bonus_amount: number;
249249
};
250250
}
251+
export interface BackupData {
252+
version: string;
253+
encrypted_data: string;
254+
metadata: {
255+
created_at: number;
256+
identity_id: string;
257+
backup_type: string;
258+
};
259+
}
260+
export interface BackupVerification {
261+
valid: boolean;
262+
version: string;
263+
created_at: number;
264+
identity_id?: string;
265+
errors: string[];
266+
warnings: string[];
267+
}
268+
export interface SeedVerification {
269+
valid: boolean;
270+
wallet_id?: string;
271+
wallet_type?: string;
272+
}
273+
export interface SeedPhrases {
274+
primary?: string[];
275+
ubi?: string[];
276+
savings?: string[];
277+
master?: string[];
278+
}
279+
export interface Guardian {
280+
guardian_id: string;
281+
guardian_name?: string;
282+
status: 'pending' | 'active' | 'revoked';
283+
added_at: number;
284+
relationship?: string;
285+
}
286+
export interface GuardianResponse {
287+
status: string;
288+
guardian_id: string;
289+
message: string;
290+
}
291+
export interface RecoverySession {
292+
recovery_id: string;
293+
identity_id: string;
294+
status: 'initiated' | 'pending_approvals' | 'completed' | 'cancelled';
295+
required_approvals: number;
296+
current_approvals: number;
297+
guardian_ids: string[];
298+
created_at: number;
299+
expires_at: number;
300+
}
301+
export interface RecoveryStatus {
302+
recovery_id: string;
303+
status: 'initiated' | 'pending_approvals' | 'completed' | 'cancelled' | 'failed';
304+
progress: {
305+
required: number;
306+
approved: number;
307+
declined: number;
308+
};
309+
guardians: Array<{
310+
guardian_id: string;
311+
status: 'pending' | 'approved' | 'declined';
312+
responded_at?: number;
313+
}>;
314+
created_at: number;
315+
updated_at: number;
316+
expires_at: number;
317+
}
251318
//# 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: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* All API method implementations for various operations
44
*/
55
import { ZhtpApiCore } from './zhtp-api-core';
6-
import { Identity, Wallet, NetworkStatus, DaoProposal, DaoStats, Transaction, Delegate, ProposalDetails, TreasuryRecord, DApp, SmartContract, ContractDeploymentResult, ContractExecutionResult, Asset, NodeStatus, Proof, SignupRequest, LoginRequest } from './types';
6+
import { Identity, Wallet, NetworkStatus, DaoProposal, DaoStats, Transaction, Delegate, ProposalDetails, TreasuryRecord, DApp, SmartContract, ContractDeploymentResult, ContractExecutionResult, Asset, NodeStatus, Proof, SignupRequest, LoginRequest, BackupData, BackupVerification, SeedVerification, SeedPhrases, Guardian, GuardianResponse, RecoverySession, RecoveryStatus, CitizenshipResult } from './types';
77
export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
88
signIn(did: string, passphrase: string): Promise<Identity>;
99
createIdentity(data: any): Promise<Identity>;
@@ -27,6 +27,21 @@ export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
2727
recoverIdentityFromSeed(recoveryData: Record<string, any>): Promise<Identity>;
2828
restoreIdentityFromBackup(backupData: Record<string, any>): Promise<Identity>;
2929
recoverIdentityWithGuardians(guardianData: Record<string, any>): Promise<Identity>;
30+
exportBackup(identityId: string, password: string): Promise<BackupData>;
31+
importBackup(backupData: string, password: string): Promise<Identity>;
32+
verifyBackup(backupData: string): Promise<BackupVerification>;
33+
verifySeedPhrase(identityId: string, seedPhrase: string): Promise<SeedVerification>;
34+
exportSeedPhrases(identityId: string): Promise<SeedPhrases>;
35+
addGuardian(identityId: string, guardianId: string, guardianInfo?: Record<string, any>): Promise<GuardianResponse>;
36+
listGuardians(identityId: string): Promise<Guardian[]>;
37+
removeGuardian(identityId: string, guardianId: string): Promise<void>;
38+
acceptGuardianInvite(guardianId: string, identityId: string): Promise<void>;
39+
declineGuardianInvite(guardianId: string, identityId: string): Promise<void>;
40+
initiateRecovery(identityId: string, guardianIds: string[]): Promise<RecoverySession>;
41+
approveRecovery(guardianId: string, recoveryId: string, approval: boolean): Promise<void>;
42+
getRecoveryStatus(recoveryId: string): Promise<RecoveryStatus>;
43+
cancelRecovery(recoveryId: string): Promise<void>;
44+
applyCitizenship(identityId: string, applicationData?: Record<string, any>): Promise<CitizenshipResult>;
3045
createZkDid(didData?: Record<string, any>): Promise<any>;
3146
getIdentity(did: string): Promise<Identity>;
3247
verifyIdentity(did: string, requirements?: Record<string, any>): Promise<boolean>;

0 commit comments

Comments
 (0)