33 * All API method implementations for various operations
44 */
55import { ZhtpApiCore } from './zhtp-api-core' ;
6- import { Identity , Wallet , NetworkStatus , DaoProposal , DaoStats , Transaction , Delegate , ProposalDetails , TreasuryRecord , DApp , SmartContract , ContractDeploymentResult , ContractExecutionResult , Asset , NodeStatus , SignupRequest , LoginRequest , BackupData , BackupVerification , BackupStatus , ImportBackupResponse , SeedVerification , SeedPhrases , Guardian , GuardianResponse , RecoverySession , RecoveryStatus , CitizenshipResult , ProofData , GenerateProofRequest , WalletListResponse , SimpleSendRequest , CrossWalletTransferRequest , TransactionHistoryResponse , NetworkPeersResponse , NetworkStatsResponse , GasInfoResponse , AddPeerRequest , AddPeerResponse , ProtocolInfoResponse , HealthCheckResponse , VersionResponse , CapabilitiesResponse , ProtocolStatsResponse , Web4RegisterRequest , Web4RegisterResponse , Web4ResolveResponse , Web4DomainLookupResponse } from './types' ;
6+ import { Identity , Wallet , NetworkStatus , DaoProposal , DaoStats , Transaction , Delegate , ProposalDetails , TreasuryRecord , DApp , SmartContract , ContractDeploymentResult , ContractExecutionResult , Asset , NodeStatus , SignupRequest , LoginRequest , RegisterIdentityRequest , RegisterIdentityResponse , BackupData , BackupVerification , BackupStatus , ImportBackupResponse , SeedVerification , SeedPhrases , Guardian , GuardianResponse , RecoverySession , RecoveryStatus , CitizenshipResult , ProofData , GenerateProofRequest , VerifyProofResponse , WalletListResponse , WalletBalanceResponse , SimpleSendRequest , CrossWalletTransferRequest , TransactionHistoryResponse , NetworkPeersResponse , NetworkStatsResponse , GasInfoResponse , AddPeerRequest , AddPeerResponse , ProtocolInfoResponse , HealthCheckResponse , VersionResponse , CapabilitiesResponse , ProtocolStatsResponse , Web4RegisterRequest , Web4RegisterResponse , Web4ResolveResponse , Web4DomainLookupResponse } from './types' ;
77export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
88 signIn ( did : string , passphrase : string ) : Promise < Identity > ;
99 createIdentity ( data : any ) : Promise < Identity > ;
@@ -15,6 +15,39 @@ export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
1515 * Login with existing identity
1616 */
1717 login ( request : LoginRequest ) : Promise < Identity > ;
18+ /**
19+ * Register identity with client-generated keys (iOS/Android)
20+ *
21+ * Use this for mobile apps where private keys are generated and stored on device.
22+ * Private keys NEVER leave the device - only public keys are sent to server.
23+ *
24+ * @param request - Registration request with public keys and proof
25+ * @returns Registration response with identity_id for keystore path
26+ *
27+ * @example
28+ * ```typescript
29+ * // iOS generates keys locally
30+ * const did = `did:zhtp:${identityHash}`;
31+ * const timestamp = Math.floor(Date.now() / 1000);
32+ * const message = `ZHTP_REGISTER:${did}:${timestamp}`;
33+ * const signature = sign(message, privateKey);
34+ *
35+ * const response = await api.registerIdentity({
36+ * did,
37+ * public_key: base64PublicKey,
38+ * kyber_public_key: base64KyberPublicKey,
39+ * node_id: base64NodeId, // Blake3(did || device_id)
40+ * device_id: deviceUUID,
41+ * display_name: "User's iPhone",
42+ * identity_type: "human",
43+ * registration_proof: base64Signature,
44+ * timestamp,
45+ * });
46+ *
47+ * // Store locally using: Documents/keystore/{response.identity_id}/
48+ * ```
49+ */
50+ registerIdentity ( request : RegisterIdentityRequest ) : Promise < RegisterIdentityResponse > ;
1851 /**
1952 * Map signup response from backend to Identity interface
2053 */
@@ -23,10 +56,94 @@ export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
2356 * Map login response from backend to Identity interface
2457 */
2558 private mapLoginResponseToIdentity ;
26- recoverIdentity ( method : 'seed' | 'backup' | 'social' , data : string ) : Promise < Identity > ;
27- recoverIdentityFromSeed ( recoveryData : Record < string , any > ) : Promise < Identity > ;
59+ /**
60+ * Recover identity from recovery phrase (20-word phrase)
61+ *
62+ * SECURITY WARNINGS:
63+ * 1. This endpoint is rate-limited to 3 attempts per hour per IP
64+ * 2. Requires exactly 20 words
65+ * 3. Creates a new session upon successful recovery
66+ *
67+ * @param recoveryPhrase - 20-word recovery phrase
68+ * @returns Recovered identity info and new session token
69+ * @throws Error if recovery phrase is invalid or rate limit exceeded
70+ */
71+ recoverIdentity ( recoveryPhrase : string ) : Promise < {
72+ status : string ;
73+ identity : {
74+ identity_id : string ;
75+ did : string ;
76+ } ;
77+ session_token : string ;
78+ } > ;
79+ /**
80+ * @deprecated Use recoverIdentity() with recovery phrase instead
81+ */
82+ recoverIdentityFromSeed ( recoveryData : Record < string , any > ) : Promise < any > ;
83+ /**
84+ * @deprecated Use importBackup() instead
85+ */
2886 restoreIdentityFromBackup ( backupData : Record < string , any > ) : Promise < Identity > ;
87+ /**
88+ * @deprecated Guardian recovery endpoints not yet implemented in node
89+ */
2990 recoverIdentityWithGuardians ( guardianData : Record < string , any > ) : Promise < Identity > ;
91+ /**
92+ * Generate a recovery phrase for identity backup
93+ *
94+ * SECURITY WARNINGS:
95+ * 1. Recovery phrase is returned ONCE and must be displayed immediately
96+ * 2. Client MUST display securely and NEVER store in logs/cache
97+ * 3. Use HTTPS only to prevent network sniffing
98+ * 4. Requires active authenticated session
99+ *
100+ * @param identityId - Identity ID to generate recovery phrase for
101+ * @param sessionToken - Active session token for authentication
102+ * @returns Recovery phrase hash, phrase (for display only), and instructions
103+ * @throws Error if session is invalid or identity not found
104+ */
105+ generateRecoveryPhrase ( identityId : string , sessionToken : string ) : Promise < {
106+ status : string ;
107+ phrase_hash : string ;
108+ recovery_phrase : string ;
109+ instructions : string ;
110+ } > ;
111+ /**
112+ * Verify a recovery phrase is correct (20 words)
113+ *
114+ * SECURITY WARNINGS:
115+ * 1. Recovery phrase must be exactly 20 words
116+ * 2. Never log or store recovery phrases
117+ * 3. This endpoint prevents typos before using for recovery
118+ *
119+ * @param identityId - Identity ID that owns the recovery phrase
120+ * @param recoveryPhrase - 20-word recovery phrase to verify
121+ * @returns Verification result (true if valid, false if invalid)
122+ * @throws Error if recovery phrase format is invalid
123+ */
124+ verifyRecoveryPhrase ( identityId : string , recoveryPhrase : string ) : Promise < {
125+ status : string ;
126+ verified : boolean ;
127+ } > ;
128+ /**
129+ * Reset password using recovery phrase
130+ *
131+ * SECURITY WARNINGS:
132+ * 1. This endpoint invalidates all existing sessions after successful reset
133+ * 2. Requires valid 20-word recovery phrase
134+ * 3. Use a strong new password (minimum 12 characters recommended)
135+ * 4. Cannot be reversed - old password will no longer work
136+ *
137+ * @param identityId - Identity ID (can also use DID format "did:zhtp:xxx")
138+ * @param recoveryPhrase - Valid 20-word recovery phrase
139+ * @param newPassword - New password to set
140+ * @returns Confirmation of password reset and session invalidation
141+ * @throws Error if recovery phrase is invalid or identity not found
142+ */
143+ resetPassword ( identityId : string , recoveryPhrase : string , newPassword : string ) : Promise < {
144+ status : string ;
145+ message : string ;
146+ } > ;
30147 /**
31148 * Export encrypted identity backup
32149 *
@@ -79,6 +196,9 @@ export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
79196 * @throws Error if seed phrase format is invalid
80197 */
81198 verifySeedPhrase ( identityId : string , seedPhrase : string ) : Promise < SeedVerification > ;
199+ /**
200+ * @deprecated This endpoint is not available in the node API
201+ */
82202 exportSeedPhrases ( identityId : string ) : Promise < SeedPhrases > ;
83203 addGuardian ( identityId : string , sessionToken : string , guardianDid : string , guardianPublicKey : number [ ] , guardianName : string ) : Promise < GuardianResponse > ;
84204 listGuardians ( sessionToken : string ) : Promise < {
@@ -107,16 +227,62 @@ export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
107227 expires_at : number ;
108228 } > ;
109229 } > ;
110- cancelRecovery ( recoveryId : string ) : Promise < void > ;
111230 applyCitizenship ( identityId : string , applicationData ?: Record < string , any > ) : Promise < CitizenshipResult > ;
231+ /**
232+ * @deprecated ZK DID endpoints not yet implemented in the node
233+ */
112234 createZkDid ( didData ?: Record < string , any > ) : Promise < any > ;
113- getIdentity ( did : string ) : Promise < Identity > ;
235+ /**
236+ * Get identity information by ID
237+ *
238+ * @param identityId - Identity ID (hex format) or DID
239+ * @returns Identity information including type, access level, and timestamps
240+ * @throws Error if identity not found
241+ */
242+ getIdentity ( identityId : string ) : Promise < {
243+ status : string ;
244+ identity_id : string ;
245+ identity_type : string ;
246+ access_level : string ;
247+ created_at : number ;
248+ last_active : number ;
249+ } > ;
250+ /**
251+ * @deprecated This endpoint is not available in the node API
252+ */
114253 verifyIdentity ( did : string , requirements ?: Record < string , any > ) : Promise < boolean > ;
254+ /**
255+ * @deprecated This endpoint is not available in the node API
256+ */
115257 checkIdentityExists ( identifier : string ) : Promise < boolean > ;
258+ /**
259+ * @deprecated This endpoint is not available in the node API. Use signIn() or login() instead.
260+ */
116261 signInWithIdentity ( identity : Identity , passphrase : string ) : Promise < {
117262 token : string ;
118263 identity : Identity ;
119264 } > ;
265+ /**
266+ * Sign a message with an identity's private key
267+ *
268+ * SECURITY NOTES:
269+ * 1. Uses post-quantum CRYSTALS-Dilithium2 algorithm
270+ * 2. Signature is 2420 bytes
271+ * 3. For verifying message authenticity and identity ownership
272+ *
273+ * @param identityId - Identity ID (hex format) to sign with
274+ * @param message - Message to sign
275+ * @returns Signature, algorithm, and public key
276+ * @throws Error if identity not found or signing fails
277+ */
278+ signMessage ( identityId : string , message : string ) : Promise < {
279+ success : boolean ;
280+ identity_id : string ;
281+ message : string ;
282+ signature : string ;
283+ signature_algorithm : string ;
284+ public_key : string ;
285+ } > ;
120286 /**
121287 * Get list of connected network peers
122288 * @returns Peer information including peer IDs, types, and connection status
@@ -160,7 +326,7 @@ export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
160326 * @param identityId - Identity ID (hex string)
161327 * @returns Detailed balance information for the wallet
162328 */
163- getWalletBalance ( walletType : string , identityId : string ) : Promise < number > ;
329+ getWalletBalance ( walletType : string , identityId : string ) : Promise < WalletBalanceResponse > ;
164330 /**
165331 * Get comprehensive wallet statistics for an identity
166332 * @param identityId - Identity ID (hex string)
@@ -321,7 +487,7 @@ export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
321487 * console.log(`Verified claim: ${verification.claim}`);
322488 * }
323489 */
324- verifyZkProof ( proof : ProofData ) : Promise < boolean > ;
490+ verifyZkProof ( proof : ProofData ) : Promise < VerifyProofResponse > ;
325491 testConnection ( ) : Promise < boolean > ;
326492 /**
327493 * Get protocol information including version, node ID, and supported features
0 commit comments