Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
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';
44 changes: 22 additions & 22 deletions src/types/scopes/eip155.types.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -22,7 +22,7 @@ interface AddEthereumChainParameter {
iconUrls?: string[];
}

interface TypedData {
export interface TypedData {
types: {
EIP712Domain: Array<{
name: string;
Expand All @@ -38,22 +38,22 @@ interface TypedData {
message: Record<string, any>;
}

interface WatchAssetOptions {
export interface WatchAssetOptions {
address: string;
symbol?: string;
decimals?: number;
image?: string;
tokenId?: string;
}

interface Call {
export interface Call {
to?: Address;
data?: HexString;
value?: HexString;
capabilities?: Record<string, any>;
}

interface SendCallsParameter {
export interface SendCallsParameter {
version: string;
id?: string;
from: Address;
Expand All @@ -63,12 +63,12 @@ interface SendCallsParameter {
capabilities?: Record<string, any>;
}

interface BatchResult {
export interface BatchResult {
id: string;
capabilities?: Record<string, any>;
}

interface BatchStatus {
export interface BatchStatus {
version: string;
id: string;
chainId: HexString;
Expand All @@ -90,7 +90,7 @@ interface BatchStatus {
capabilities?: Record<string, any>;
}

interface Transaction {
export interface Transaction {
from: Address;
to?: Address;
gas?: HexString;
Expand All @@ -108,14 +108,14 @@ interface Transaction {
chainId?: HexString;
}

interface Filter {
export interface Filter {
fromBlock?: HexString;
toBlock?: HexString;
address?: Address | Address[];
topics?: Array<HexString | HexString[] | null>;
}

interface Log {
export interface Log {
removed?: boolean;
logIndex?: HexString;
transactionIndex?: HexString;
Expand All @@ -127,7 +127,7 @@ interface Log {
topics: HexString[];
}

interface Block {
export interface Block {
number: HexString;
hash: Hash32;
parentHash: Hash32;
Expand Down Expand Up @@ -161,7 +161,7 @@ interface Block {
mixHash?: Hash32;
}

interface TransactionInfo {
export interface TransactionInfo {
blockHash: Hash32;
blockNumber: HexString;
from: Address;
Expand All @@ -187,7 +187,7 @@ interface TransactionInfo {
yParity?: HexString;
}

interface TransactionReceipt {
export interface TransactionReceipt {
transactionHash: Hash32;
transactionIndex: HexString;
blockHash: Hash32;
Expand All @@ -206,7 +206,7 @@ interface TransactionReceipt {
blobGasPrice?: HexString;
}

interface FeeHistory {
export interface FeeHistory {
oldestBlock: HexString;
baseFeePerGas: HexString[];
baseFeePerBlobGas?: HexString[];
Expand All @@ -215,7 +215,7 @@ interface FeeHistory {
reward?: HexString[][];
}

interface AccountProof {
export interface AccountProof {
address: Address;
accountProof: HexString[];
balance: HexString;
Expand All @@ -229,7 +229,7 @@ interface AccountProof {
}>;
}

type SyncingStatus =
export type SyncingStatus =
| boolean
| {
startingBlock: HexString;
Expand Down
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: [];
};
21 changes: 18 additions & 3 deletions src/types/session.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
type CaipAccountId = `${string}:${string}:${string}`;
type CaipChainId = `${string}:${string}`;
type Json =
/**
* CAIP-10 Account ID type.
* Format: `<namespace>:<reference>:<address>`
* Example: `eip155:1:0xabc123...`
*/
export type CaipAccountId = `${string}:${string}:${string}`;

/**
* CAIP Chain ID type.
* Format: `<namespace>:<reference>`
* Example:
* - `eip155:1`
* - `solana:mainnet`
* - `tron:728126428`
*/
export type CaipChainId = `${string}:${string}`;

export type Json =
| string
| number
| boolean
Expand Down
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