Skip to content

Commit ce2fcd0

Browse files
committed
feat: add typed wallets.tron() interface for signTransaction and sendTransaction
Adds PrivyTronService with typed methods mirroring the existing wallets.ethereum() and wallets.solana() pattern: - wallets.tron().signTransaction(walletId, input) - signs a Tron transaction without broadcasting - wallets.tron().sendTransaction(walletId, input) - signs and broadcasts a Tron transaction Both methods leverage the existing typed Tron RPC schemas (TronSignTransactionRpcInput, TronSendTransactionRpcInput) and route through the standard wallets.rpc() infrastructure. Committed-By-Agent: goose
1 parent 6a330ef commit ce2fcd0

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export {
66
export { type PrivyWalletsService } from './public-api/services/wallets';
77
export { type PrivyEthereumService } from './public-api/services/ethereum';
88
export { type PrivySolanaService } from './public-api/services/solana';
9+
export { type PrivyTronService } from './public-api/services/tron';
910
export { type PrivyPoliciesService } from './public-api/services/policies';
1011
export { type PrivyTransactionsService } from './public-api/services/transactions';
1112
export { type PrivyKeyQuorumsService } from './public-api/services/key-quorums';

src/public-api/services/tron.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import {
2+
TronSendTransactionRpcResponseData,
3+
TronSignTransactionRpcResponseData,
4+
WalletRpcParams,
5+
} from '../../resources';
6+
import { PrivyWalletsService } from './wallets';
7+
import { PrivyWalletsRpcInput } from './wallets';
8+
9+
export class PrivyTronService {
10+
private privyWalletsService: PrivyWalletsService;
11+
12+
constructor(privyWalletsService: PrivyWalletsService) {
13+
this.privyWalletsService = privyWalletsService;
14+
}
15+
16+
public async signTransaction(
17+
walletId: string,
18+
input: PrivyTronService.SignTransactionInput,
19+
): Promise<TronSignTransactionRpcResponseData> {
20+
const response = await this.privyWalletsService.rpc(walletId, {
21+
...input,
22+
method: 'tron_signTransaction',
23+
});
24+
25+
return response.data;
26+
}
27+
28+
public async sendTransaction(
29+
walletId: string,
30+
input: PrivyTronService.SendTransactionInput,
31+
): Promise<TronSendTransactionRpcResponseData> {
32+
const response = await this.privyWalletsService.rpc(walletId, {
33+
...input,
34+
method: 'tron_sendTransaction',
35+
});
36+
37+
return response.data;
38+
}
39+
}
40+
41+
// prettier-ignore
42+
/**
43+
* The namespace for types related to the Tron service class.
44+
* @see {@link PrivyTronService} class.
45+
* @see {@link PrivyWalletsRpcInput} type.
46+
*/
47+
export namespace PrivyTronService {
48+
/** The input type for the {@link PrivyTronService.signTransaction} method. */
49+
export type SignTransactionInput = PrivyWalletsRpcInput<WalletRpcParams.TronSignTransactionRpcInput>;
50+
/** The input type for the {@link PrivyTronService.sendTransaction} method. */
51+
export type SendTransactionInput = PrivyWalletsRpcInput<WalletRpcParams.TronSendTransactionRpcInput>;
52+
}

src/public-api/services/wallets.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ import { PrivyClient } from '../PrivyClient';
2424
import { PrivyEarnService } from './earn';
2525
import { PrivyEthereumService } from './ethereum';
2626
import { PrivySolanaService } from './solana';
27+
import { PrivyTronService } from './tron';
2728
import { PrivySwapsService } from './swaps';
2829
import { Prettify, WithAuthorization, WithExpiry, WithIdempotency } from './types';
2930

3031
export class PrivyWalletsService extends Wallets {
3132
private ethereumService: PrivyEthereumService;
3233
private solanaService: PrivySolanaService;
34+
private tronService: PrivyTronService;
3335
private earnService: PrivyEarnService;
3436
private swapsService: PrivySwapsService;
3537
private privyClient: PrivyClient;
@@ -39,6 +41,7 @@ export class PrivyWalletsService extends Wallets {
3941
this.privyClient = privyClient;
4042
this.ethereumService = new PrivyEthereumService(this);
4143
this.solanaService = new PrivySolanaService(this);
44+
this.tronService = new PrivyTronService(this);
4245
this.earnService = new PrivyEarnService(privyApiClient, privyClient);
4346
this.swapsService = new PrivySwapsService(privyApiClient, privyClient);
4447
}
@@ -55,6 +58,10 @@ export class PrivyWalletsService extends Wallets {
5558
return this.solanaService;
5659
}
5760

61+
public tron(): PrivyTronService {
62+
return this.tronService;
63+
}
64+
5865
public swaps(): PrivySwapsService {
5966
return this.swapsService;
6067
}

0 commit comments

Comments
 (0)