Skip to content

Commit 0d119f8

Browse files
umweltclaude
andcommitted
Merge development into main for v1.3.0 release
- Add registerIdentity() method for client-side key registration (iOS) - Add RegisterIdentityRequest and RegisterIdentityResponse types - Fix duplicate FetchAdapter type in zhtp-api-core.ts - Version bump to 1.3.0 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2 parents e05cbcf + d598235 commit 0d119f8

13 files changed

+821
-303
lines changed

dist/core/types.d.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,58 @@ export interface SignupResponse {
204204
created_at: number;
205205
citizenship_result?: CitizenshipResult;
206206
}
207+
/**
208+
* Request for registering an identity with client-generated keys.
209+
* Used by iOS/Android where private keys stay on device.
210+
* Calls POST /api/v1/identity/register
211+
*/
212+
export interface RegisterIdentityRequest {
213+
/** Decentralized Identifier: "did:zhtp:{64-char-hex}" */
214+
did: string;
215+
/** Base64-encoded Dilithium5 public key (~2592 bytes) */
216+
public_key: string;
217+
/** Base64-encoded Kyber1024 public key (~1568 bytes) - optional for PQC */
218+
kyber_public_key?: string;
219+
/** Base64-encoded node ID: Blake3(did || device_id) - 32 bytes */
220+
node_id: string;
221+
/** Device identifier (e.g., "5A63A821-595A-4A71-88FB-3A5448D2A8B6") */
222+
device_id: string;
223+
/** Optional display name */
224+
display_name?: string;
225+
/** Identity type: "human", "device", or "organization" (default: "human") */
226+
identity_type?: string;
227+
/**
228+
* Base64-encoded signature proving ownership of private key.
229+
* Signs the message: "ZHTP_REGISTER:{did}:{timestamp}"
230+
*/
231+
registration_proof: string;
232+
/** Unix timestamp in seconds when signature was created (must be within 300s of server time) */
233+
timestamp: number;
234+
}
235+
/**
236+
* Response from client-side identity registration.
237+
* Use identity_id for keystore path: Documents/keystore/{identity_id}/
238+
*/
239+
export interface RegisterIdentityResponse {
240+
/** Always "registered" on success */
241+
status: 'registered';
242+
/** 64-character hex string - USE THIS for keystore path */
243+
identity_id: string;
244+
/** Full DID: "did:zhtp:{identity_id}" */
245+
did: string;
246+
/** Device identifier echoed back */
247+
device_id: string;
248+
/** Identity type: "human", "device", or "organization" */
249+
identity_type: string;
250+
/** Blockchain transaction hash, or null if blockchain registration failed (non-fatal) */
251+
blockchain_tx: string | null;
252+
/** Welcome bonus amount (5000 for humans, 0 for others) */
253+
welcome_bonus: number;
254+
/** Unix timestamp when registered */
255+
registered_at: number;
256+
/** True if kyber_public_key was provided */
257+
pqc_enabled: boolean;
258+
}
207259
export interface LoginResponse {
208260
status: string;
209261
identity_id: string;

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: 173 additions & 7 deletions
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, 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';
77
export 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

Comments
 (0)