Skip to content

Commit 8c45393

Browse files
Hugo PerezHugo Perez
authored andcommitted
feat: add platform-specific config providers and API client
Add configuration providers for Electron, React Native, and Vanilla JS environments Implement core API client with request handling and retry logic Include type definitions for all API methods and shared types
1 parent 89dfec0 commit 8c45393

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1237
-0
lines changed

dist/core/config-provider.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Abstract configuration provider interface
3+
* Implemented differently for each platform
4+
*/
5+
import { ApiConfig } from './types';
6+
export interface ConfigProvider {
7+
/**
8+
* Get configuration from platform-specific source
9+
* - Electron: IPC from main process
10+
* - React Native: AsyncStorage or environment
11+
* - Browser: API endpoint or localStorage
12+
*/
13+
getConfig(): Promise<ApiConfig>;
14+
}
15+
//# sourceMappingURL=config-provider.d.ts.map

dist/core/config-provider.d.ts.map

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

dist/core/config-provider.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core/config-provider.js.map

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

dist/core/types.d.ts

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/**
2+
* Shared types for all platforms
3+
*/
4+
export interface Identity {
5+
did: string;
6+
displayName: string;
7+
username?: string;
8+
identityType: 'citizen' | 'organization' | 'developer' | 'validator';
9+
avatar?: string;
10+
createdAt: string;
11+
citizenship?: boolean;
12+
publicKey?: string;
13+
biometricHash?: string;
14+
wallets?: Wallet[];
15+
votingPower?: number;
16+
ubiEarned?: number;
17+
}
18+
export interface Wallet {
19+
id: string;
20+
name: string;
21+
balance: number;
22+
address: string;
23+
}
24+
export interface NetworkStatus {
25+
peers: number;
26+
meshConnected: boolean;
27+
latency: number;
28+
version: string;
29+
quantumResistant: boolean;
30+
}
31+
export interface DaoProposal {
32+
id: string;
33+
title: string;
34+
description: string;
35+
status: 'active' | 'passed' | 'rejected' | 'executed';
36+
votesFor: number;
37+
votesAgainst: number;
38+
creator: string;
39+
createdAt: string;
40+
deadline: string;
41+
}
42+
export interface Transaction {
43+
id: string;
44+
from: string;
45+
to: string;
46+
amount: number;
47+
status: 'pending' | 'confirmed' | 'failed';
48+
timestamp: string;
49+
blockNumber?: number;
50+
hash?: string;
51+
}
52+
export interface DaoStats {
53+
totalProposals: number;
54+
activeProposals: number;
55+
treasury: number;
56+
delegates: number;
57+
participationRate: number;
58+
}
59+
export interface ApiConfig {
60+
zhtpNodeUrl: string;
61+
networkType: 'testnet' | 'mainnet';
62+
debugMode: boolean;
63+
enableBiometrics: boolean;
64+
}
65+
export interface ApiResponse<T = any> {
66+
success: boolean;
67+
data?: T;
68+
error?: string;
69+
}
70+
export interface IdentityRecoveryData {
71+
method: 'seed' | 'backup' | 'social' | 'guardians';
72+
data: string | Record<string, any>;
73+
}
74+
export interface Delegate {
75+
id: string;
76+
name: string;
77+
votingPower: number;
78+
delegators: number;
79+
activeProposals: number;
80+
reputation: number;
81+
}
82+
export interface ProposalDetails {
83+
id: string;
84+
title: string;
85+
description: string;
86+
status: 'active' | 'passed' | 'rejected' | 'executed';
87+
votesFor: number;
88+
votesAgainst: number;
89+
creator: string;
90+
createdAt: string;
91+
deadline: string;
92+
executionData?: Record<string, any>;
93+
discussionUrl?: string;
94+
}
95+
export interface TreasuryRecord {
96+
id: string;
97+
from: string;
98+
to: string;
99+
amount: number;
100+
reason: string;
101+
timestamp: string;
102+
status: 'pending' | 'approved' | 'executed';
103+
}
104+
export interface DApp {
105+
domain: string;
106+
owner: string;
107+
contentHash: string;
108+
description?: string;
109+
metadata?: Record<string, any>;
110+
}
111+
export interface SmartContract {
112+
id: string;
113+
name: string;
114+
version: string;
115+
author?: string;
116+
description?: string;
117+
bytecode?: string;
118+
abi?: any[];
119+
deployedAt?: string;
120+
ownerDid?: string;
121+
permissions?: ContractPermissions;
122+
}
123+
export interface ContractPermissions {
124+
executePolicy: 'Public' | 'Authenticated' | 'OwnerOnly';
125+
queryPolicy: 'Public' | 'Authenticated' | 'OwnerOnly';
126+
upgradePolicy: 'Public' | 'Authenticated' | 'OwnerOnly';
127+
}
128+
export interface ContractDeploymentResult {
129+
contractId: string;
130+
transactionHash: string;
131+
blockNumber: number;
132+
status: 'pending' | 'confirmed' | 'failed';
133+
}
134+
export interface ContractExecutionResult {
135+
success: boolean;
136+
output?: any;
137+
gasUsed?: number;
138+
error?: string;
139+
}
140+
export interface Asset {
141+
id: string;
142+
name: string;
143+
symbol: string;
144+
balance: number;
145+
decimals: number;
146+
contractAddress?: string;
147+
}
148+
export interface NodeStatus {
149+
isOnline: boolean;
150+
version: string;
151+
peersConnected: number;
152+
blockHeight: number;
153+
syncStatus: 'synced' | 'syncing' | 'stalled';
154+
uptime: number;
155+
}
156+
export interface GasInfo {
157+
baseGasPrice: number;
158+
priorityFee: number;
159+
maxGasPrice: number;
160+
estimatedGasByOperation?: Record<string, number>;
161+
}
162+
export interface Proof {
163+
type: string;
164+
data: string;
165+
timestamp: string;
166+
signature?: string;
167+
}
168+
//# sourceMappingURL=types.d.ts.map

dist/core/types.d.ts.map

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

dist/core/types.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core/types.js.map

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

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Core ZHTP API functionality
3+
* Handles request/response, retry logic, and timeouts
4+
*/
5+
import { ApiConfig } from './types';
6+
export declare abstract class ZhtpApiCore {
7+
protected baseUrl: string;
8+
protected config: ApiConfig | null;
9+
protected maxRetries: number;
10+
protected requestTimeout: number;
11+
protected retryDelays: number[];
12+
/**
13+
* Generic request method with retry logic and timeout
14+
*/
15+
protected request<T>(endpoint: string, options?: RequestInit, retryCount?: number): Promise<T>;
16+
protected shouldRetry(error: any): boolean;
17+
}
18+
//# sourceMappingURL=zhtp-api-core.d.ts.map

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

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

0 commit comments

Comments
 (0)