@faremeter/wallet-evm 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,10 @@
1
1
  import { type WalletClient, type Hex, type Chain } from "viem";
2
2
  import { privateKeyToAccount } from "viem/accounts";
3
- interface NetworkConfig {
4
- chain: Chain;
5
- rpcUrl: string;
6
- }
7
- export declare function lookupNetworkConfig(network: string): NetworkConfig | undefined;
8
- export declare function isValidPrivateKey(privateKey: string): privateKey is Hex;
9
3
  export interface EvmWallet {
10
- network: string;
4
+ chain: Chain;
11
5
  address: Hex;
12
6
  client: WalletClient;
13
7
  account: ReturnType<typeof privateKeyToAccount>;
14
8
  }
15
- export declare function createLocalWallet(network: string, privateKey: string): Promise<EvmWallet>;
16
- export {};
9
+ export declare function createLocalWallet(chain: Chain, privateKey: string): Promise<EvmWallet>;
17
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,GAAG,EACR,KAAK,KAAK,EAEX,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGpD,UAAU,aAAa;IACrB,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAiCD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,6BAElD;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,IAAI,GAAG,CAEvE;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;CACjD;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,SAAS,CAAC,CA2BpB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,GAAG,EACR,KAAK,KAAK,EACX,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;CACjD;AAED,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,SAAS,CAAC,CAoBpB"}
package/dist/src/index.js CHANGED
@@ -1,58 +1,18 @@
1
- import { createWalletClient, http, isHex, } from "viem";
1
+ import { isPrivateKey } from "@faremeter/types/evm";
2
+ import { createWalletClient, http, } from "viem";
2
3
  import { privateKeyToAccount } from "viem/accounts";
3
- import { base, baseSepolia, mainnet, sepolia } from "viem/chains";
4
- const NETWORK_CONFIGS = new Map([
5
- [
6
- "base",
7
- {
8
- chain: base,
9
- rpcUrl: "https://mainnet.base.org",
10
- },
11
- ],
12
- [
13
- "base-sepolia",
14
- {
15
- chain: baseSepolia,
16
- rpcUrl: "https://sepolia.base.org",
17
- },
18
- ],
19
- [
20
- "ethereum",
21
- {
22
- chain: mainnet,
23
- rpcUrl: "https://ethereum-rpc.publicnode.com",
24
- },
25
- ],
26
- [
27
- "sepolia",
28
- {
29
- chain: sepolia,
30
- rpcUrl: "https://ethereum-sepolia-rpc.publicnode.com",
31
- },
32
- ],
33
- ]);
34
- export function lookupNetworkConfig(network) {
35
- return NETWORK_CONFIGS.get(network);
36
- }
37
- export function isValidPrivateKey(privateKey) {
38
- return isHex(privateKey) && privateKey.length == 66;
39
- }
40
- export async function createLocalWallet(network, privateKey) {
41
- const config = lookupNetworkConfig(network);
42
- if (!config) {
43
- throw new Error(`Unsupported network: ${network}. Supported networks: ${Array.from(NETWORK_CONFIGS.keys()).join(", ")}`);
44
- }
45
- if (!isValidPrivateKey(privateKey)) {
4
+ export async function createLocalWallet(chain, privateKey) {
5
+ if (!isPrivateKey(privateKey)) {
46
6
  throw new Error(`Invalid private key format. Expected 64-character hex string with '0x' prefix, got: ${privateKey.slice(0, 10)}...`);
47
7
  }
48
8
  const account = privateKeyToAccount(privateKey);
49
9
  const client = createWalletClient({
50
10
  account,
51
- chain: config.chain,
52
- transport: http(config.rpcUrl),
11
+ chain: chain,
12
+ transport: http(chain.rpcUrls.default.http[0]),
53
13
  });
54
14
  return {
55
- network,
15
+ chain,
56
16
  address: account.address,
57
17
  client,
58
18
  account,