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
8 changes: 4 additions & 4 deletions src/helpers/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('utils', () => {
});

it('should retry a function that never resolves until it succeeds', async () => {
expect(
await expect(
async () => await withRetry(mockMultichainApiRequest(), { maxRetries: 2, requestTimeout: 100 }),
).rejects.toThrow('Timeout reached');
});
Expand All @@ -57,9 +57,9 @@ describe('utils', () => {
});

it('should retry a throwing function until it succeeds', async () => {
expect(async () => await withRetry(mockThrowingFn(), { maxRetries: 2, requestTimeout: 100 })).rejects.toThrow(
'error',
);
await expect(
async () => await withRetry(mockThrowingFn(), { maxRetries: 2, requestTimeout: 100 }),
).rejects.toThrow('error');
});
});
});
308 changes: 304 additions & 4 deletions src/types/scopes/eip155.types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,310 @@
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;

// Complex types for method parameters and responses
interface AddEthereumChainParameter {
chainId: HexString;
chainName: string;
nativeCurrency: {
name?: string;
symbol: string;
decimals: number;
};
rpcUrls: string[];
blockExplorerUrls?: string[];
iconUrls?: string[];
}

interface TypedData {
types: {
EIP712Domain: Array<{
name: string;
type: string;
}>;
[key: string]: Array<{
name: string;
type: string;
}>;
};
primaryType: string;
domain: Record<string, any>;
message: Record<string, any>;
}

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

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

interface SendCallsParameter {
version: string;
id?: string;
from: Address;
chainId: HexString;
atomicRequired: boolean;
calls: Call[];
capabilities?: Record<string, any>;
}

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

interface BatchStatus {
version: string;
id: string;
chainId: HexString;
status: number;
atomic: boolean;
receipts?: Array<{
logs: Array<{
address: Address;
data: HexString;
topics: HexString[];
}>;
status: HexString;
blockHash: Hash32;
blockNumber: HexString;
gasUsed: HexString;
transactionHash: Hash32;
[key: string]: any;
}>;
capabilities?: Record<string, any>;
}

interface Transaction {
from: Address;
to?: Address;
gas?: HexString;
gasPrice?: HexString;
maxFeePerGas?: HexString;
maxPriorityFeePerGas?: HexString;
value?: HexString;
data?: HexString;
nonce?: HexString;
accessList?: Array<{
address: Address;
storageKeys: Hash32[];
}>;
type?: HexString;
chainId?: HexString;
}

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

interface Log {
removed?: boolean;
logIndex?: HexString;
transactionIndex?: HexString;
transactionHash: Hash32;
blockHash?: Hash32;
blockNumber?: HexString;
address: Address;
data: HexString;
topics: HexString[];
}

interface Block {
number: HexString;
hash: Hash32;
parentHash: Hash32;
nonce: HexString;
sha3Uncles: Hash32;
logsBloom: HexString;
transactionsRoot: Hash32;
stateRoot: Hash32;
receiptsRoot: Hash32;
miner: Address;
difficulty?: HexString;
totalDifficulty?: HexString;
extraData: HexString;
size: HexString;
gasLimit: HexString;
gasUsed: HexString;
timestamp: HexString;
transactions: Hash32[] | TransactionInfo[];
uncles: Hash32[];
baseFeePerGas?: HexString;
withdrawalsRoot?: Hash32;
withdrawals?: Array<{
index: HexString;
validatorIndex: HexString;
address: Address;
amount: HexString;
}>;
blobGasUsed?: HexString;
excessBlobGas?: HexString;
parentBeaconBlockRoot?: Hash32;
mixHash?: Hash32;
}

interface TransactionInfo {
blockHash: Hash32;
blockNumber: HexString;
from: Address;
gas: HexString;
gasPrice?: HexString;
maxFeePerGas?: HexString;
maxPriorityFeePerGas?: HexString;
hash: Hash32;
input: HexString;
nonce: HexString;
to?: Address;
transactionIndex: HexString;
value: HexString;
type?: HexString;
accessList?: Array<{
address: Address;
storageKeys: Hash32[];
}>;
chainId?: number;
v?: HexString;
r?: HexString;
s?: HexString;
yParity?: HexString;
}

interface TransactionReceipt {
transactionHash: Hash32;
transactionIndex: HexString;
blockHash: Hash32;
blockNumber: HexString;
from: Address;
to?: Address;
cumulativeGasUsed: HexString;
gasUsed: HexString;
contractAddress?: Address;
logs: Log[];
logsBloom: HexString;
status?: HexString;
effectiveGasPrice: HexString;
type?: HexString;
blobGasUsed?: HexString;
blobGasPrice?: HexString;
}

interface FeeHistory {
oldestBlock: HexString;
baseFeePerGas: HexString[];
baseFeePerBlobGas?: HexString[];
gasUsedRatio: number[];
blobGasUsedRatio?: number[];
reward?: HexString[][];
}

interface AccountProof {
address: Address;
accountProof: HexString[];
balance: HexString;
codeHash: Hash32;
nonce: HexString;
storageHash: Hash32;
storageProof: Array<{
key: HexString;
value: HexString;
proof: HexString[];
}>;
}

type SyncingStatus =
| boolean
| {
startingBlock: HexString;
currentBlock: HexString;
highestBlock: HexString;
};

export type Eip155Rpc = {
methods: {
eth_sendTransaction: RpcMethod<{ to: string; value?: string; data?: string }, string>;
eth_call: RpcMethod<{ to: string; data?: string }, string>;
eth_getBalance: RpcMethod<{ address: string; blockNumber: string }, string>;
// Wallet methods
wallet_addEthereumChain: RpcMethod<[AddEthereumChainParameter], null>;
wallet_watchAsset: RpcMethod<{ type: string; options: WatchAssetOptions }, boolean>;
wallet_scanQRCode: RpcMethod<[string?], string>;
wallet_sendCalls: RpcMethod<[SendCallsParameter], BatchResult>;
wallet_getCallsStatus: RpcMethod<[string], BatchStatus>;
wallet_getCapabilities: RpcMethod<[Address, HexString[]?], Record<string, any>>;

// Signing methods
personal_sign: RpcMethod<[HexString, Address], HexString>;
eth_signTypedData_v4: RpcMethod<[Address, TypedData], HexString>;
eth_decrypt: RpcMethod<[string, Address], string>;
eth_getEncryptionPublicKey: RpcMethod<[Address], string>;

// Account methods
eth_accounts: RpcMethod<[], Address[]>;

// Transaction methods
eth_sendTransaction: RpcMethod<[Transaction], Hash32>;
eth_sendRawTransaction: RpcMethod<[HexString], Hash32>;
eth_estimateGas: RpcMethod<[Transaction, BlockNumberOrTagOrHash?], HexString>;

// Block methods
eth_blockNumber: RpcMethod<[], HexString>;
eth_getBlockByHash: RpcMethod<[Hash32, boolean], Block | null>;
eth_getBlockByNumber: RpcMethod<[BlockNumberOrTag, boolean], Block | null>;
eth_getBlockTransactionCountByHash: RpcMethod<[Hash32], HexString | null>;
eth_getBlockTransactionCountByNumber: RpcMethod<[BlockNumberOrTag], HexString | null>;
eth_getUncleCountByBlockHash: RpcMethod<[Hash32], HexString | null>;
eth_getUncleCountByBlockNumber: RpcMethod<[BlockNumberOrTag], HexString | null>;

// Transaction info methods
eth_getTransactionByHash: RpcMethod<[Hash32], TransactionInfo | null>;
eth_getTransactionByBlockHashAndIndex: RpcMethod<[Hash32, HexString], TransactionInfo | null>;
eth_getTransactionByBlockNumberAndIndex: RpcMethod<[BlockNumberOrTag, HexString], TransactionInfo | null>;
eth_getTransactionCount: RpcMethod<[Address, BlockNumberOrTagOrHash], HexString>;
eth_getTransactionReceipt: RpcMethod<[Hash32], TransactionReceipt | null>;

// State methods
eth_getBalance: RpcMethod<[Address, BlockNumberOrTagOrHash], HexString>;
eth_getCode: RpcMethod<[Address, BlockNumberOrTagOrHash], HexString>;
eth_getStorageAt: RpcMethod<[Address, HexString, BlockNumberOrTagOrHash], HexString>;
eth_call: RpcMethod<[Transaction, BlockNumberOrTagOrHash?], HexString>;
eth_getProof: RpcMethod<[Address, HexString[], BlockNumberOrTagOrHash], AccountProof>;

// Gas and fee methods
eth_gasPrice: RpcMethod<[], HexString>;
eth_feeHistory: RpcMethod<[HexString, BlockNumberOrTag, number[]], FeeHistory>;

// Filter and log methods
eth_newFilter: RpcMethod<[Filter], HexString>;
eth_newBlockFilter: RpcMethod<[], HexString>;
eth_newPendingTransactionFilter: RpcMethod<[], HexString>;
eth_uninstallFilter: RpcMethod<[HexString], boolean>;
eth_getFilterChanges: RpcMethod<[HexString], (Log | Hash32)[]>;
eth_getFilterLogs: RpcMethod<[HexString], Log[]>;
eth_getLogs: RpcMethod<[Filter], Log[]>;

// Subscription methods
eth_subscribe: RpcMethod<[string, object?], HexString>;
eth_unsubscribe: RpcMethod<[HexString], boolean>;

// Network info methods
eth_chainId: RpcMethod<[], HexString>;
eth_syncing: RpcMethod<[], SyncingStatus>;
web3_clientVersion: RpcMethod<[], string>;
};
events: ['eth_subscription'];
events: ['eth_subscription', 'accountsChanged', 'chainChanged', 'connect', 'disconnect'];
};
4 changes: 2 additions & 2 deletions src/types/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type Json =
*/
export type ScopeObject = {
references?: string[];
methods?: string[];
notifications?: string[];
methods: string[];
notifications: string[];
accounts?: CaipAccountId[];
};

Expand Down
14 changes: 9 additions & 5 deletions tests/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ expectType<{
);

// Basic eth_call with correct scope and parameters
expectType<string>(
expectType<`0x${string}`>(
await client.invokeMethod({
scope: 'eip155:1',
request: {
method: 'eth_call',
params: {
to: '0x1234567890',
data: '0x1234567890',
},
params: [
{
from: '0x1234567890',
to: '0x1234567890',
data: '0x1234567890',
},
'latest',
],
},
}),
);
Expand Down
Loading