Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: add tron scope types
  • Loading branch information
EdouardBougon committed Dec 2, 2025
commit 9f6c2a29eba463cc73a55f05f4ea673a90d2f617
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ export { getMultichainClient, getDefaultTransport, getExternallyConnectableTrans
export type * from './types/transport';
export type * from './types/session';
export type * from './types/multichainApi';
export type * from './types/scopes';
export * from './types/errors';
2 changes: 2 additions & 0 deletions src/types/scopes/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Bip122Rpc } from './bip122.types';
import type { Eip155Rpc } from './eip155.types';
import type { SolanaRpc } from './solana.types';
import type { TronRpc } from './tron.types';

export type RpcApi = Record<
string,
Expand Down Expand Up @@ -34,4 +35,5 @@ export type DefaultRpcApi = {
eip155: Eip155Rpc;
solana: SolanaRpc;
bip122: Bip122Rpc;
tron: TronRpc;
};
64 changes: 64 additions & 0 deletions src/types/scopes/tron.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type { RpcMethod } from '.';

/**
* A Base64-encoded message string.
* @example
* ```typescript
* const message = "Hello, Tron!";
* const base64Message = Buffer.from(message).toString('base64');
* ```
*/
export type Base64Message = string;

/**
* A Tron address in Base58Check format, starting with 'T'.
* @example "TJRabPrwbZy45sbavfcjinPJC18kjpRTv8"
*/
export type TronAddress = `T${string}`;

/**
* A signature.
*/
export type Signature = `0x${string}`;

/**
* Signs a plain text message.
* The signature can be used to verify ownership of the account.
*
* @param address - The Tron address that will sign the message
* @param message - The message string in Base64 format to be signed
* @returns An object containing the hexadecimal signature of the message
*/
export type SignMessageMethod = RpcMethod<
{
address: TronAddress;
message: Base64Message;
},
{ signature: Signature }
>;

/**
* Signs a Tron transaction.
*
* @param address - The Tron address that will sign the transaction
* @param transaction - The Tron transaction object containing `raw_data_hex` and `type`
* @returns An object containing the hexadecimal signature of the transaction
*/
export type SignTransactionMethod = RpcMethod<
{
address: TronAddress;
transaction: {
rawDataHex: string;
type: string;
};
},
{ signature: Signature }
>;

export type TronRpc = {
methods: {
signMessage: SignMessageMethod;
signTransaction: SignTransactionMethod;
};
events: [];
};
15 changes: 15 additions & 0 deletions tests/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expectError, expectType } from 'tsd';
import { getMultichainClient } from '../src/index';
import type { Signature } from '../src/types/scopes/tron.types';
import { getMockTransport } from './mocks';

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

// Basic tron signMessage call with correct scope and parameters
expectType<{ signature: Signature }>(
await client.invokeMethod({
scope: 'tron:728126428',
request: {
method: 'signMessage',
params: {
address: 'TJRabPrwbZy45sbavfcjinPJC18kjpRTv8',
message: 'aGVsbG8gd29ybGQ=',
},
},
}),
);

// ==========================================
// Test error cases for invalid inputs
// ==========================================
Expand Down
Loading