Skip to content

Commit

Permalink
consolidate types
Browse files Browse the repository at this point in the history
  • Loading branch information
bangtoven committed Nov 21, 2023
1 parent e8699b6 commit 2d97401
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 339 deletions.
179 changes: 179 additions & 0 deletions packages/wallet-sdk/src/provider/JSONRPC.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
// Copyright (c) 2018-2022 Coinbase, Inc. <https://www.coinbase.com/>
// Licensed under the Apache License, version 2.0

import { AddressString, HexString } from '../core/type';

export type JSONRPCMethodName = keyof typeof JSONRPCMethods;

export function isValidJSONRPCMethod(method: string): method is JSONRPCMethodName {
return method in JSONRPCMethods;
}

export type JSONRPCRequest<M extends JSONRPCMethodName> = {
jsonrpc: '2.0';
id: number;
method: M;
params: (typeof JSONRPCMethods)[M]['params'];
};

export type JSONRPCResponse<M extends JSONRPCMethodName> = {
jsonrpc: '2.0';
id: number;
} & (
| {
error: {
code: number;
message: string;
data?: unknown;
};
}
| {
result: (typeof JSONRPCMethods)[M]['result'];
}
);

const JSONRPCMethods = {
eth_accounts: {
params: {} as never,
result: {} as AddressString[],
},
eth_coinbase: {
params: {} as never,
result: {} as AddressString,
},
net_version: {
params: {} as never,
result: {} as string,
},
eth_chainId: {
params: {} as never,
result: {} as string,
},
eth_uninstallFilter: {
params: {} as [HexString],
result: {} as boolean,
},
eth_requestAccounts: {
params: {} as never,
result: {} as AddressString[],
},
eth_sign: {
params: {} as [AddressString, Buffer],
result: {} as HexString,
},
eth_ecRecover: {
params: {} as [Buffer, Buffer],
result: {} as AddressString,
},
personal_sign: {
params: {} as [Buffer, AddressString],
result: {} as HexString,
},
personal_ecRecover: {
params: {} as [Buffer, Buffer],
result: {} as AddressString,
},
eth_signTransaction: {
params: {} as EthereumTransactionParams,
result: {} as HexString,
},
eth_sendRawTransaction: {
params: {} as [Buffer],
result: {} as HexString,
},
eth_sendTransaction: {
params: {} as EthereumTransactionParams,
result: {} as HexString,
},
eth_signTypedData_v1: {
params: {} as [object, AddressString],
result: {} as HexString,
},
eth_signTypedData_v2: {
params: {} as never,
result: {} as never,
},
eth_signTypedData_v3: {
params: {} as [AddressString, object],
result: {} as HexString,
},
eth_signTypedData_v4: {
params: {} as [AddressString, object],
result: {} as HexString,
},
eth_signTypedData: {
params: {} as [AddressString, object],
result: {} as HexString,
},
wallet_addEthereumChain: {
params: {} as [
{
chainId: string;
blockExplorerUrls?: string[];
chainName?: string;
iconUrls?: string[];
rpcUrls?: string[];
nativeCurrency?: {
name: string;
symbol: string;
decimals: number;
};
},
],
result: null,
},
wallet_switchEthereumChain: {
params: {} as [
{
chainId: string;
},
],
result: null,
},
wallet_watchAsset: {
params: {} as {
type: string;
options: {
address: string;
symbol: string;
decimals: number;
image?: string;
};
},
result: {} as boolean,
},
eth_subscribe: {
params: {} as [
'newHeads' | 'logs' | 'newPendingTransactions' | 'syncing',
{
address?: AddressString;
topics?: string[];
},
],
result: {} as unknown,
},
eth_unsubscribe: {
params: {} as string[],
result: {} as unknown,
},
eth_newFilter: {
params: {} as unknown,
result: {} as HexString,
},
eth_newBlockFilter: {
params: {} as never,
result: {} as HexString,
},
eth_newPendingTransactionFilter: {
params: {} as never,
result: {} as HexString,
},
eth_getFilterChanges: {
params: {} as [HexString],
result: {} as unknown,
},
eth_getFilterLogs: {
params: {} as [HexString],
result: {} as unknown,
},
} as const;
39 changes: 0 additions & 39 deletions packages/wallet-sdk/src/provider/JSONRPCMethod.ts

This file was deleted.

172 changes: 0 additions & 172 deletions packages/wallet-sdk/src/provider/JSONRPCRequest.ts

This file was deleted.

Loading

0 comments on commit 2d97401

Please sign in to comment.