Skip to content

Commit 92b0fdb

Browse files
feat: add tron scope types (#83)
* feat: export all types * feat: add tron scope types
1 parent 37a18d7 commit 92b0fdb

File tree

6 files changed

+122
-25
lines changed

6 files changed

+122
-25
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ export { getMultichainClient, getDefaultTransport, getExternallyConnectableTrans
3636
export type * from './types/transport';
3737
export type * from './types/session';
3838
export type * from './types/multichainApi';
39+
export type * from './types/scopes';
3940
export * from './types/errors';

src/types/scopes/eip155.types.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import type { RpcMethod } from '.';
22

33
// Base types
4-
type HexString = `0x${string}`;
5-
type Address = `0x${string}`;
6-
type Hash32 = `0x${string}`;
7-
type BlockTag = 'earliest' | 'finalized' | 'safe' | 'latest' | 'pending';
8-
type BlockNumberOrTag = HexString | BlockTag;
9-
type BlockNumberOrTagOrHash = HexString | BlockTag | Hash32;
4+
export type HexString = `0x${string}`;
5+
export type Address = `0x${string}`;
6+
export type Hash32 = `0x${string}`;
7+
export type BlockTag = 'earliest' | 'finalized' | 'safe' | 'latest' | 'pending';
8+
export type BlockNumberOrTag = HexString | BlockTag;
9+
export type BlockNumberOrTagOrHash = HexString | BlockTag | Hash32;
1010

1111
// Complex types for method parameters and responses
12-
interface AddEthereumChainParameter {
12+
export interface AddEthereumChainParameter {
1313
chainId: HexString;
1414
chainName: string;
1515
nativeCurrency: {
@@ -22,7 +22,7 @@ interface AddEthereumChainParameter {
2222
iconUrls?: string[];
2323
}
2424

25-
interface TypedData {
25+
export interface TypedData {
2626
types: {
2727
EIP712Domain: Array<{
2828
name: string;
@@ -38,22 +38,22 @@ interface TypedData {
3838
message: Record<string, any>;
3939
}
4040

41-
interface WatchAssetOptions {
41+
export interface WatchAssetOptions {
4242
address: string;
4343
symbol?: string;
4444
decimals?: number;
4545
image?: string;
4646
tokenId?: string;
4747
}
4848

49-
interface Call {
49+
export interface Call {
5050
to?: Address;
5151
data?: HexString;
5252
value?: HexString;
5353
capabilities?: Record<string, any>;
5454
}
5555

56-
interface SendCallsParameter {
56+
export interface SendCallsParameter {
5757
version: string;
5858
id?: string;
5959
from: Address;
@@ -63,12 +63,12 @@ interface SendCallsParameter {
6363
capabilities?: Record<string, any>;
6464
}
6565

66-
interface BatchResult {
66+
export interface BatchResult {
6767
id: string;
6868
capabilities?: Record<string, any>;
6969
}
7070

71-
interface BatchStatus {
71+
export interface BatchStatus {
7272
version: string;
7373
id: string;
7474
chainId: HexString;
@@ -90,7 +90,7 @@ interface BatchStatus {
9090
capabilities?: Record<string, any>;
9191
}
9292

93-
interface Transaction {
93+
export interface Transaction {
9494
from: Address;
9595
to?: Address;
9696
gas?: HexString;
@@ -108,14 +108,14 @@ interface Transaction {
108108
chainId?: HexString;
109109
}
110110

111-
interface Filter {
111+
export interface Filter {
112112
fromBlock?: HexString;
113113
toBlock?: HexString;
114114
address?: Address | Address[];
115115
topics?: Array<HexString | HexString[] | null>;
116116
}
117117

118-
interface Log {
118+
export interface Log {
119119
removed?: boolean;
120120
logIndex?: HexString;
121121
transactionIndex?: HexString;
@@ -127,7 +127,7 @@ interface Log {
127127
topics: HexString[];
128128
}
129129

130-
interface Block {
130+
export interface Block {
131131
number: HexString;
132132
hash: Hash32;
133133
parentHash: Hash32;
@@ -161,7 +161,7 @@ interface Block {
161161
mixHash?: Hash32;
162162
}
163163

164-
interface TransactionInfo {
164+
export interface TransactionInfo {
165165
blockHash: Hash32;
166166
blockNumber: HexString;
167167
from: Address;
@@ -187,7 +187,7 @@ interface TransactionInfo {
187187
yParity?: HexString;
188188
}
189189

190-
interface TransactionReceipt {
190+
export interface TransactionReceipt {
191191
transactionHash: Hash32;
192192
transactionIndex: HexString;
193193
blockHash: Hash32;
@@ -206,7 +206,7 @@ interface TransactionReceipt {
206206
blobGasPrice?: HexString;
207207
}
208208

209-
interface FeeHistory {
209+
export interface FeeHistory {
210210
oldestBlock: HexString;
211211
baseFeePerGas: HexString[];
212212
baseFeePerBlobGas?: HexString[];
@@ -215,7 +215,7 @@ interface FeeHistory {
215215
reward?: HexString[][];
216216
}
217217

218-
interface AccountProof {
218+
export interface AccountProof {
219219
address: Address;
220220
accountProof: HexString[];
221221
balance: HexString;
@@ -229,7 +229,7 @@ interface AccountProof {
229229
}>;
230230
}
231231

232-
type SyncingStatus =
232+
export type SyncingStatus =
233233
| boolean
234234
| {
235235
startingBlock: HexString;

src/types/scopes/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Bip122Rpc } from './bip122.types';
22
import type { Eip155Rpc } from './eip155.types';
33
import type { SolanaRpc } from './solana.types';
4+
import type { TronRpc } from './tron.types';
45

56
export type RpcApi = Record<
67
string,
@@ -34,4 +35,5 @@ export type DefaultRpcApi = {
3435
eip155: Eip155Rpc;
3536
solana: SolanaRpc;
3637
bip122: Bip122Rpc;
38+
tron: TronRpc;
3739
};

src/types/scopes/tron.types.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import type { RpcMethod } from '.';
2+
3+
/**
4+
* A Base64-encoded message string.
5+
* @example
6+
* ```typescript
7+
* const message = "Hello, Tron!";
8+
* const base64Message = Buffer.from(message).toString('base64');
9+
* ```
10+
*/
11+
export type Base64Message = string;
12+
13+
/**
14+
* A Tron address in Base58Check format, starting with 'T'.
15+
* @example "TJRabPrwbZy45sbavfcjinPJC18kjpRTv8"
16+
*/
17+
export type TronAddress = `T${string}`;
18+
19+
/**
20+
* A signature.
21+
*/
22+
export type Signature = `0x${string}`;
23+
24+
/**
25+
* Signs a plain text message.
26+
* The signature can be used to verify ownership of the account.
27+
*
28+
* @param address - The Tron address that will sign the message
29+
* @param message - The message string in Base64 format to be signed
30+
* @returns An object containing the hexadecimal signature of the message
31+
*/
32+
export type SignMessageMethod = RpcMethod<
33+
{
34+
address: TronAddress;
35+
message: Base64Message;
36+
},
37+
{ signature: Signature }
38+
>;
39+
40+
/**
41+
* Signs a Tron transaction.
42+
*
43+
* @param address - The Tron address that will sign the transaction
44+
* @param transaction - The Tron transaction object containing `raw_data_hex` and `type`
45+
* @returns An object containing the hexadecimal signature of the transaction
46+
*/
47+
export type SignTransactionMethod = RpcMethod<
48+
{
49+
address: TronAddress;
50+
transaction: {
51+
rawDataHex: string;
52+
type: string;
53+
};
54+
},
55+
{ signature: Signature }
56+
>;
57+
58+
export type TronRpc = {
59+
methods: {
60+
signMessage: SignMessageMethod;
61+
signTransaction: SignTransactionMethod;
62+
};
63+
events: [];
64+
};

src/types/session.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1-
type CaipAccountId = `${string}:${string}:${string}`;
2-
type CaipChainId = `${string}:${string}`;
3-
type Json =
1+
/**
2+
* CAIP-10 Account ID type.
3+
* Format: `<namespace>:<reference>:<address>`
4+
* Example: `eip155:1:0xabc123...`
5+
*/
6+
export type CaipAccountId = `${string}:${string}:${string}`;
7+
8+
/**
9+
* CAIP Chain ID type.
10+
* Format: `<namespace>:<reference>`
11+
* Example:
12+
* - `eip155:1`
13+
* - `solana:mainnet`
14+
* - `tron:728126428`
15+
*/
16+
export type CaipChainId = `${string}:${string}`;
17+
18+
export type Json =
419
| string
520
| number
621
| boolean

tests/index.test-d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expectError, expectType } from 'tsd';
22
import { getMultichainClient } from '../src/index';
3+
import type { Signature } from '../src/types/scopes/tron.types';
34
import { getMockTransport } from './mocks';
45

56
const client = getMultichainClient({ transport: getMockTransport() });
@@ -46,6 +47,20 @@ expectType<`0x${string}`>(
4647
}),
4748
);
4849

50+
// Basic tron signMessage call with correct scope and parameters
51+
expectType<{ signature: Signature }>(
52+
await client.invokeMethod({
53+
scope: 'tron:728126428',
54+
request: {
55+
method: 'signMessage',
56+
params: {
57+
address: 'TJRabPrwbZy45sbavfcjinPJC18kjpRTv8',
58+
message: 'aGVsbG8gd29ybGQ=',
59+
},
60+
},
61+
}),
62+
);
63+
4964
// ==========================================
5065
// Test error cases for invalid inputs
5166
// ==========================================

0 commit comments

Comments
 (0)