diff --git a/src/index.ts b/src/index.ts index 3dcf448..7476e29 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; diff --git a/src/types/scopes/eip155.types.ts b/src/types/scopes/eip155.types.ts index 659bf22..798cd1e 100644 --- a/src/types/scopes/eip155.types.ts +++ b/src/types/scopes/eip155.types.ts @@ -1,15 +1,15 @@ import type { RpcMethod } from '.'; // Base types -type HexString = `0x${string}`; -type Address = `0x${string}`; -type Hash32 = `0x${string}`; -type BlockTag = 'earliest' | 'finalized' | 'safe' | 'latest' | 'pending'; -type BlockNumberOrTag = HexString | BlockTag; -type BlockNumberOrTagOrHash = HexString | BlockTag | Hash32; +export type HexString = `0x${string}`; +export type Address = `0x${string}`; +export type Hash32 = `0x${string}`; +export type BlockTag = 'earliest' | 'finalized' | 'safe' | 'latest' | 'pending'; +export type BlockNumberOrTag = HexString | BlockTag; +export type BlockNumberOrTagOrHash = HexString | BlockTag | Hash32; // Complex types for method parameters and responses -interface AddEthereumChainParameter { +export interface AddEthereumChainParameter { chainId: HexString; chainName: string; nativeCurrency: { @@ -22,7 +22,7 @@ interface AddEthereumChainParameter { iconUrls?: string[]; } -interface TypedData { +export interface TypedData { types: { EIP712Domain: Array<{ name: string; @@ -38,7 +38,7 @@ interface TypedData { message: Record; } -interface WatchAssetOptions { +export interface WatchAssetOptions { address: string; symbol?: string; decimals?: number; @@ -46,14 +46,14 @@ interface WatchAssetOptions { tokenId?: string; } -interface Call { +export interface Call { to?: Address; data?: HexString; value?: HexString; capabilities?: Record; } -interface SendCallsParameter { +export interface SendCallsParameter { version: string; id?: string; from: Address; @@ -63,12 +63,12 @@ interface SendCallsParameter { capabilities?: Record; } -interface BatchResult { +export interface BatchResult { id: string; capabilities?: Record; } -interface BatchStatus { +export interface BatchStatus { version: string; id: string; chainId: HexString; @@ -90,7 +90,7 @@ interface BatchStatus { capabilities?: Record; } -interface Transaction { +export interface Transaction { from: Address; to?: Address; gas?: HexString; @@ -108,14 +108,14 @@ interface Transaction { chainId?: HexString; } -interface Filter { +export interface Filter { fromBlock?: HexString; toBlock?: HexString; address?: Address | Address[]; topics?: Array; } -interface Log { +export interface Log { removed?: boolean; logIndex?: HexString; transactionIndex?: HexString; @@ -127,7 +127,7 @@ interface Log { topics: HexString[]; } -interface Block { +export interface Block { number: HexString; hash: Hash32; parentHash: Hash32; @@ -161,7 +161,7 @@ interface Block { mixHash?: Hash32; } -interface TransactionInfo { +export interface TransactionInfo { blockHash: Hash32; blockNumber: HexString; from: Address; @@ -187,7 +187,7 @@ interface TransactionInfo { yParity?: HexString; } -interface TransactionReceipt { +export interface TransactionReceipt { transactionHash: Hash32; transactionIndex: HexString; blockHash: Hash32; @@ -206,7 +206,7 @@ interface TransactionReceipt { blobGasPrice?: HexString; } -interface FeeHistory { +export interface FeeHistory { oldestBlock: HexString; baseFeePerGas: HexString[]; baseFeePerBlobGas?: HexString[]; @@ -215,7 +215,7 @@ interface FeeHistory { reward?: HexString[][]; } -interface AccountProof { +export interface AccountProof { address: Address; accountProof: HexString[]; balance: HexString; @@ -229,7 +229,7 @@ interface AccountProof { }>; } -type SyncingStatus = +export type SyncingStatus = | boolean | { startingBlock: HexString; diff --git a/src/types/scopes/index.ts b/src/types/scopes/index.ts index c2b7932..06dc114 100644 --- a/src/types/scopes/index.ts +++ b/src/types/scopes/index.ts @@ -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, @@ -34,4 +35,5 @@ export type DefaultRpcApi = { eip155: Eip155Rpc; solana: SolanaRpc; bip122: Bip122Rpc; + tron: TronRpc; }; diff --git a/src/types/scopes/tron.types.ts b/src/types/scopes/tron.types.ts new file mode 100644 index 0000000..bc4cb67 --- /dev/null +++ b/src/types/scopes/tron.types.ts @@ -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: []; +}; diff --git a/src/types/session.ts b/src/types/session.ts index 1e94359..c3255f3 100644 --- a/src/types/session.ts +++ b/src/types/session.ts @@ -1,6 +1,21 @@ -type CaipAccountId = `${string}:${string}:${string}`; -type CaipChainId = `${string}:${string}`; -type Json = +/** + * CAIP-10 Account ID type. + * Format: `::
` + * Example: `eip155:1:0xabc123...` + */ +export type CaipAccountId = `${string}:${string}:${string}`; + +/** + * CAIP Chain ID type. + * Format: `:` + * Example: + * - `eip155:1` + * - `solana:mainnet` + * - `tron:728126428` + */ +export type CaipChainId = `${string}:${string}`; + +export type Json = | string | number | boolean diff --git a/tests/index.test-d.ts b/tests/index.test-d.ts index ce94dad..1dbbb9d 100644 --- a/tests/index.test-d.ts +++ b/tests/index.test-d.ts @@ -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() }); @@ -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 // ==========================================