Skip to content

Commit 798d20a

Browse files
authored
Implement 8 wallet API methods matching node implementation (#31)
Added new methods: - getWalletList() - List all wallets for identity - getWalletBalance() - Get specific wallet balance by type - getWalletStatistics() - Get comprehensive wallet stats - getWalletTransactionHistory() - Get transaction history - sendWalletPayment() - Send simple payment - transferBetweenWallets() - Transfer between wallets - stakeTokens() - Stake tokens - unstakeTokens() - Unstake tokens Fixed paths to match node (wallet/mod.rs): - /api/v1/wallet/list/{identity_id} - /api/v1/wallet/balance/{wallet_type}/{identity_id} - /api/v1/wallet/statistics/{identity_id} - /api/v1/wallet/transactions/{identity_id} - /api/v1/wallet/send - /api/v1/wallet/transfer/cross-wallet - /api/v1/wallet/staking/stake - /api/v1/wallet/staking/unstake Added types: WalletListResponse, WalletBalanceResponse, DetailedWalletInfo, WalletPermissions, SimpleSendRequest, CrossWalletTransferRequest, StakingRequest, TransactionRecord, TransactionHistoryResponse Kept legacy methods (getWallets, getTransactionHistory, sendTransaction) as deprecated wrappers for backward compatibility.
1 parent 22884c1 commit 798d20a

File tree

8 files changed

+505
-41
lines changed

8 files changed

+505
-41
lines changed

dist/core/types.d.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,77 @@ export interface VerifyProofResponse {
341341
claim: ProofType;
342342
verified_at: number;
343343
}
344+
export interface WalletPermissions {
345+
can_transfer_external: boolean;
346+
can_vote: boolean;
347+
can_stake: boolean;
348+
can_receive_rewards: boolean;
349+
daily_transaction_limit: number;
350+
requires_multisig_threshold: number | null;
351+
}
352+
export interface DetailedWalletInfo {
353+
wallet_type: string;
354+
wallet_id: string;
355+
available_balance: number;
356+
staked_balance: number;
357+
pending_rewards: number;
358+
total_balance: number;
359+
permissions: WalletPermissions;
360+
created_at: number;
361+
description: string;
362+
}
363+
export interface WalletListResponse {
364+
status: string;
365+
identity_id: string;
366+
total_wallets: number;
367+
total_balance: number;
368+
wallets: DetailedWalletInfo[];
369+
}
370+
export interface WalletBalanceResponse {
371+
status: string;
372+
wallet_type: string;
373+
identity_id: string;
374+
balance: {
375+
available_balance: number;
376+
staked_balance: number;
377+
pending_rewards: number;
378+
total_balance: number;
379+
};
380+
permissions: WalletPermissions;
381+
created_at: number;
382+
}
383+
export interface SimpleSendRequest {
384+
from_identity: string;
385+
to_address: string;
386+
amount: number;
387+
memo?: string;
388+
}
389+
export interface CrossWalletTransferRequest {
390+
identity_id: string;
391+
from_wallet: string;
392+
to_wallet: string;
393+
amount: number;
394+
purpose?: string;
395+
}
396+
export interface StakingRequest {
397+
identity_id: string;
398+
amount: number;
399+
}
400+
export interface TransactionRecord {
401+
tx_hash: string;
402+
tx_type: string;
403+
amount: number;
404+
fee: number;
405+
from_wallet: string | null;
406+
to_address: string | null;
407+
timestamp: number;
408+
block_height: number | null;
409+
status: string;
410+
memo: string | null;
411+
}
412+
export interface TransactionHistoryResponse {
413+
identity_id: string;
414+
total_transactions: number;
415+
transactions: TransactionRecord[];
416+
}
344417
//# 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: 61 additions & 2 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, GasInfo, SignupRequest, LoginRequest, BackupData, BackupVerification, BackupStatus, ImportBackupResponse, SeedVerification, SeedPhrases, Guardian, GuardianResponse, RecoverySession, RecoveryStatus, CitizenshipResult, ProofData, GenerateProofRequest, VerifyProofResponse } from './types';
6+
import { Identity, Wallet, NetworkStatus, DaoProposal, DaoStats, Transaction, Delegate, ProposalDetails, TreasuryRecord, DApp, SmartContract, ContractDeploymentResult, ContractExecutionResult, Asset, NodeStatus, GasInfo, SignupRequest, LoginRequest, BackupData, BackupVerification, BackupStatus, ImportBackupResponse, SeedVerification, SeedPhrases, Guardian, GuardianResponse, RecoverySession, RecoveryStatus, CitizenshipResult, ProofData, GenerateProofRequest, VerifyProofResponse, WalletListResponse, WalletBalanceResponse, SimpleSendRequest, CrossWalletTransferRequest, TransactionHistoryResponse } from './types';
77
export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
88
signIn(did: string, passphrase: string): Promise<Identity>;
99
createIdentity(data: any): Promise<Identity>;
@@ -117,10 +117,69 @@ export declare abstract class ZhtpApiMethods extends ZhtpApiCore {
117117
identity: Identity;
118118
}>;
119119
getNetworkInfo(): Promise<NetworkStatus>;
120+
/**
121+
* List all wallets for an identity
122+
* @param identityId - Identity ID (hex string)
123+
* @returns List of all wallets with balances and permissions
124+
*/
125+
getWalletList(identityId: string): Promise<WalletListResponse>;
126+
/**
127+
* Get balance for a specific wallet type
128+
* @param walletType - Wallet type (Primary, UBI, Savings, Staking, etc.)
129+
* @param identityId - Identity ID (hex string)
130+
* @returns Detailed balance information for the wallet
131+
*/
132+
getWalletBalance(walletType: string, identityId: string): Promise<WalletBalanceResponse>;
133+
/**
134+
* Get comprehensive wallet statistics for an identity
135+
* @param identityId - Identity ID (hex string)
136+
* @returns Wallet statistics
137+
*/
138+
getWalletStatistics(identityId: string): Promise<any>;
139+
/**
140+
* Get transaction history for an identity
141+
* @param identityId - Identity ID (hex string)
142+
* @returns Transaction history
143+
*/
144+
getWalletTransactionHistory(identityId: string): Promise<TransactionHistoryResponse>;
145+
/**
146+
* Send a simple payment from primary wallet
147+
* @param request - Send request with from_identity, to_address, amount, memo
148+
* @returns Transaction result
149+
*/
150+
sendWalletPayment(request: SimpleSendRequest): Promise<any>;
151+
/**
152+
* Transfer tokens between wallets of the same identity
153+
* @param request - Transfer request with identity_id, from_wallet, to_wallet, amount, purpose
154+
* @returns Transfer result with transaction ID
155+
*/
156+
transferBetweenWallets(request: CrossWalletTransferRequest): Promise<any>;
157+
/**
158+
* Stake tokens from Primary wallet to Staking wallet
159+
* @param identityId - Identity ID (hex string)
160+
* @param amount - Amount to stake
161+
* @returns Staking result
162+
*/
163+
stakeTokens(identityId: string, amount: number): Promise<any>;
164+
/**
165+
* Unstake tokens from Staking wallet back to Primary wallet
166+
* @param identityId - Identity ID (hex string)
167+
* @param amount - Amount to unstake
168+
* @returns Unstaking result
169+
*/
170+
unstakeTokens(identityId: string, amount: number): Promise<any>;
171+
/**
172+
* @deprecated Use getWalletList() instead
173+
*/
120174
getWallets(did: string): Promise<Wallet[]>;
121-
getWalletBalance(did: string): Promise<number>;
175+
/**
176+
* @deprecated Use getWalletTransactionHistory() instead
177+
*/
122178
getTransactionHistory(address: string, walletType?: string): Promise<Transaction[]>;
123179
getAssets(address: string): Promise<Asset[]>;
180+
/**
181+
* @deprecated Use sendWalletPayment() instead
182+
*/
124183
sendTransaction(from: string, to: string, amount: number, metadata?: Record<string, any>): Promise<Transaction>;
125184
getDaoProposals(): Promise<DaoProposal[]>;
126185
getDaoStats(): Promise<DaoStats>;

0 commit comments

Comments
 (0)