Skip to content

Commit 9ccd143

Browse files
feat: expand EIP155 RPC types and methods (#69)
* feat: expand EIP155 RPC types and methods * fix: enforce required properties in ScopeObject * test: await expect.toThrow * test: update eth_call parameters in index tests
1 parent 640f03e commit 9ccd143

File tree

4 files changed

+319
-15
lines changed

4 files changed

+319
-15
lines changed

src/helpers/utils.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('utils', () => {
4646
});
4747

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

5959
it('should retry a throwing function until it succeeds', async () => {
60-
expect(async () => await withRetry(mockThrowingFn(), { maxRetries: 2, requestTimeout: 100 })).rejects.toThrow(
61-
'error',
62-
);
60+
await expect(
61+
async () => await withRetry(mockThrowingFn(), { maxRetries: 2, requestTimeout: 100 }),
62+
).rejects.toThrow('error');
6363
});
6464
});
6565
});

src/types/scopes/eip155.types.ts

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

3+
// 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;
10+
11+
// Complex types for method parameters and responses
12+
interface AddEthereumChainParameter {
13+
chainId: HexString;
14+
chainName: string;
15+
nativeCurrency: {
16+
name?: string;
17+
symbol: string;
18+
decimals: number;
19+
};
20+
rpcUrls: string[];
21+
blockExplorerUrls?: string[];
22+
iconUrls?: string[];
23+
}
24+
25+
interface TypedData {
26+
types: {
27+
EIP712Domain: Array<{
28+
name: string;
29+
type: string;
30+
}>;
31+
[key: string]: Array<{
32+
name: string;
33+
type: string;
34+
}>;
35+
};
36+
primaryType: string;
37+
domain: Record<string, any>;
38+
message: Record<string, any>;
39+
}
40+
41+
interface WatchAssetOptions {
42+
address: string;
43+
symbol?: string;
44+
decimals?: number;
45+
image?: string;
46+
tokenId?: string;
47+
}
48+
49+
interface Call {
50+
to?: Address;
51+
data?: HexString;
52+
value?: HexString;
53+
capabilities?: Record<string, any>;
54+
}
55+
56+
interface SendCallsParameter {
57+
version: string;
58+
id?: string;
59+
from: Address;
60+
chainId: HexString;
61+
atomicRequired: boolean;
62+
calls: Call[];
63+
capabilities?: Record<string, any>;
64+
}
65+
66+
interface BatchResult {
67+
id: string;
68+
capabilities?: Record<string, any>;
69+
}
70+
71+
interface BatchStatus {
72+
version: string;
73+
id: string;
74+
chainId: HexString;
75+
status: number;
76+
atomic: boolean;
77+
receipts?: Array<{
78+
logs: Array<{
79+
address: Address;
80+
data: HexString;
81+
topics: HexString[];
82+
}>;
83+
status: HexString;
84+
blockHash: Hash32;
85+
blockNumber: HexString;
86+
gasUsed: HexString;
87+
transactionHash: Hash32;
88+
[key: string]: any;
89+
}>;
90+
capabilities?: Record<string, any>;
91+
}
92+
93+
interface Transaction {
94+
from: Address;
95+
to?: Address;
96+
gas?: HexString;
97+
gasPrice?: HexString;
98+
maxFeePerGas?: HexString;
99+
maxPriorityFeePerGas?: HexString;
100+
value?: HexString;
101+
data?: HexString;
102+
nonce?: HexString;
103+
accessList?: Array<{
104+
address: Address;
105+
storageKeys: Hash32[];
106+
}>;
107+
type?: HexString;
108+
chainId?: HexString;
109+
}
110+
111+
interface Filter {
112+
fromBlock?: HexString;
113+
toBlock?: HexString;
114+
address?: Address | Address[];
115+
topics?: Array<HexString | HexString[] | null>;
116+
}
117+
118+
interface Log {
119+
removed?: boolean;
120+
logIndex?: HexString;
121+
transactionIndex?: HexString;
122+
transactionHash: Hash32;
123+
blockHash?: Hash32;
124+
blockNumber?: HexString;
125+
address: Address;
126+
data: HexString;
127+
topics: HexString[];
128+
}
129+
130+
interface Block {
131+
number: HexString;
132+
hash: Hash32;
133+
parentHash: Hash32;
134+
nonce: HexString;
135+
sha3Uncles: Hash32;
136+
logsBloom: HexString;
137+
transactionsRoot: Hash32;
138+
stateRoot: Hash32;
139+
receiptsRoot: Hash32;
140+
miner: Address;
141+
difficulty?: HexString;
142+
totalDifficulty?: HexString;
143+
extraData: HexString;
144+
size: HexString;
145+
gasLimit: HexString;
146+
gasUsed: HexString;
147+
timestamp: HexString;
148+
transactions: Hash32[] | TransactionInfo[];
149+
uncles: Hash32[];
150+
baseFeePerGas?: HexString;
151+
withdrawalsRoot?: Hash32;
152+
withdrawals?: Array<{
153+
index: HexString;
154+
validatorIndex: HexString;
155+
address: Address;
156+
amount: HexString;
157+
}>;
158+
blobGasUsed?: HexString;
159+
excessBlobGas?: HexString;
160+
parentBeaconBlockRoot?: Hash32;
161+
mixHash?: Hash32;
162+
}
163+
164+
interface TransactionInfo {
165+
blockHash: Hash32;
166+
blockNumber: HexString;
167+
from: Address;
168+
gas: HexString;
169+
gasPrice?: HexString;
170+
maxFeePerGas?: HexString;
171+
maxPriorityFeePerGas?: HexString;
172+
hash: Hash32;
173+
input: HexString;
174+
nonce: HexString;
175+
to?: Address;
176+
transactionIndex: HexString;
177+
value: HexString;
178+
type?: HexString;
179+
accessList?: Array<{
180+
address: Address;
181+
storageKeys: Hash32[];
182+
}>;
183+
chainId?: number;
184+
v?: HexString;
185+
r?: HexString;
186+
s?: HexString;
187+
yParity?: HexString;
188+
}
189+
190+
interface TransactionReceipt {
191+
transactionHash: Hash32;
192+
transactionIndex: HexString;
193+
blockHash: Hash32;
194+
blockNumber: HexString;
195+
from: Address;
196+
to?: Address;
197+
cumulativeGasUsed: HexString;
198+
gasUsed: HexString;
199+
contractAddress?: Address;
200+
logs: Log[];
201+
logsBloom: HexString;
202+
status?: HexString;
203+
effectiveGasPrice: HexString;
204+
type?: HexString;
205+
blobGasUsed?: HexString;
206+
blobGasPrice?: HexString;
207+
}
208+
209+
interface FeeHistory {
210+
oldestBlock: HexString;
211+
baseFeePerGas: HexString[];
212+
baseFeePerBlobGas?: HexString[];
213+
gasUsedRatio: number[];
214+
blobGasUsedRatio?: number[];
215+
reward?: HexString[][];
216+
}
217+
218+
interface AccountProof {
219+
address: Address;
220+
accountProof: HexString[];
221+
balance: HexString;
222+
codeHash: Hash32;
223+
nonce: HexString;
224+
storageHash: Hash32;
225+
storageProof: Array<{
226+
key: HexString;
227+
value: HexString;
228+
proof: HexString[];
229+
}>;
230+
}
231+
232+
type SyncingStatus =
233+
| boolean
234+
| {
235+
startingBlock: HexString;
236+
currentBlock: HexString;
237+
highestBlock: HexString;
238+
};
239+
3240
export type Eip155Rpc = {
4241
methods: {
5-
eth_sendTransaction: RpcMethod<{ to: string; value?: string; data?: string }, string>;
6-
eth_call: RpcMethod<{ to: string; data?: string }, string>;
7-
eth_getBalance: RpcMethod<{ address: string; blockNumber: string }, string>;
242+
// Wallet methods
243+
wallet_addEthereumChain: RpcMethod<[AddEthereumChainParameter], null>;
244+
wallet_watchAsset: RpcMethod<{ type: string; options: WatchAssetOptions }, boolean>;
245+
wallet_scanQRCode: RpcMethod<[string?], string>;
246+
wallet_sendCalls: RpcMethod<[SendCallsParameter], BatchResult>;
247+
wallet_getCallsStatus: RpcMethod<[string], BatchStatus>;
248+
wallet_getCapabilities: RpcMethod<[Address, HexString[]?], Record<string, any>>;
249+
250+
// Signing methods
251+
personal_sign: RpcMethod<[HexString, Address], HexString>;
252+
eth_signTypedData_v4: RpcMethod<[Address, TypedData], HexString>;
253+
eth_decrypt: RpcMethod<[string, Address], string>;
254+
eth_getEncryptionPublicKey: RpcMethod<[Address], string>;
255+
256+
// Account methods
257+
eth_accounts: RpcMethod<[], Address[]>;
258+
259+
// Transaction methods
260+
eth_sendTransaction: RpcMethod<[Transaction], Hash32>;
261+
eth_sendRawTransaction: RpcMethod<[HexString], Hash32>;
262+
eth_estimateGas: RpcMethod<[Transaction, BlockNumberOrTagOrHash?], HexString>;
263+
264+
// Block methods
265+
eth_blockNumber: RpcMethod<[], HexString>;
266+
eth_getBlockByHash: RpcMethod<[Hash32, boolean], Block | null>;
267+
eth_getBlockByNumber: RpcMethod<[BlockNumberOrTag, boolean], Block | null>;
268+
eth_getBlockTransactionCountByHash: RpcMethod<[Hash32], HexString | null>;
269+
eth_getBlockTransactionCountByNumber: RpcMethod<[BlockNumberOrTag], HexString | null>;
270+
eth_getUncleCountByBlockHash: RpcMethod<[Hash32], HexString | null>;
271+
eth_getUncleCountByBlockNumber: RpcMethod<[BlockNumberOrTag], HexString | null>;
272+
273+
// Transaction info methods
274+
eth_getTransactionByHash: RpcMethod<[Hash32], TransactionInfo | null>;
275+
eth_getTransactionByBlockHashAndIndex: RpcMethod<[Hash32, HexString], TransactionInfo | null>;
276+
eth_getTransactionByBlockNumberAndIndex: RpcMethod<[BlockNumberOrTag, HexString], TransactionInfo | null>;
277+
eth_getTransactionCount: RpcMethod<[Address, BlockNumberOrTagOrHash], HexString>;
278+
eth_getTransactionReceipt: RpcMethod<[Hash32], TransactionReceipt | null>;
279+
280+
// State methods
281+
eth_getBalance: RpcMethod<[Address, BlockNumberOrTagOrHash], HexString>;
282+
eth_getCode: RpcMethod<[Address, BlockNumberOrTagOrHash], HexString>;
283+
eth_getStorageAt: RpcMethod<[Address, HexString, BlockNumberOrTagOrHash], HexString>;
284+
eth_call: RpcMethod<[Transaction, BlockNumberOrTagOrHash?], HexString>;
285+
eth_getProof: RpcMethod<[Address, HexString[], BlockNumberOrTagOrHash], AccountProof>;
286+
287+
// Gas and fee methods
288+
eth_gasPrice: RpcMethod<[], HexString>;
289+
eth_feeHistory: RpcMethod<[HexString, BlockNumberOrTag, number[]], FeeHistory>;
290+
291+
// Filter and log methods
292+
eth_newFilter: RpcMethod<[Filter], HexString>;
293+
eth_newBlockFilter: RpcMethod<[], HexString>;
294+
eth_newPendingTransactionFilter: RpcMethod<[], HexString>;
295+
eth_uninstallFilter: RpcMethod<[HexString], boolean>;
296+
eth_getFilterChanges: RpcMethod<[HexString], (Log | Hash32)[]>;
297+
eth_getFilterLogs: RpcMethod<[HexString], Log[]>;
298+
eth_getLogs: RpcMethod<[Filter], Log[]>;
299+
300+
// Subscription methods
301+
eth_subscribe: RpcMethod<[string, object?], HexString>;
302+
eth_unsubscribe: RpcMethod<[HexString], boolean>;
303+
304+
// Network info methods
305+
eth_chainId: RpcMethod<[], HexString>;
306+
eth_syncing: RpcMethod<[], SyncingStatus>;
307+
web3_clientVersion: RpcMethod<[], string>;
8308
};
9-
events: ['eth_subscription'];
309+
events: ['eth_subscription', 'accountsChanged', 'chainChanged', 'connect', 'disconnect'];
10310
};

src/types/session.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ type Json =
2121
*/
2222
export type ScopeObject = {
2323
references?: string[];
24-
methods?: string[];
25-
notifications?: string[];
24+
methods: string[];
25+
notifications: string[];
2626
accounts?: CaipAccountId[];
2727
};
2828

tests/index.test-d.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,19 @@ expectType<{
2929
);
3030

3131
// Basic eth_call with correct scope and parameters
32-
expectType<string>(
32+
expectType<`0x${string}`>(
3333
await client.invokeMethod({
3434
scope: 'eip155:1',
3535
request: {
3636
method: 'eth_call',
37-
params: {
38-
to: '0x1234567890',
39-
data: '0x1234567890',
40-
},
37+
params: [
38+
{
39+
from: '0x1234567890',
40+
to: '0x1234567890',
41+
data: '0x1234567890',
42+
},
43+
'latest',
44+
],
4145
},
4246
}),
4347
);

0 commit comments

Comments
 (0)