viem 0.0.1-alpha.14 → 0.0.1-alpha.15

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.
Files changed (50) hide show
  1. package/dist/chains.js +5 -5
  2. package/dist/chains.mjs +1 -1
  3. package/dist/{chunk-KB6CBNKW.mjs → chunk-2HENAFQN.mjs} +16 -6
  4. package/dist/{chunk-E7IQYTLV.js → chunk-EMQSYKNY.js} +11 -11
  5. package/dist/{chunk-VUNR7KGG.js → chunk-HTYEJEWI.js} +145 -531
  6. package/dist/chunk-IMYI7Z6M.js +255 -0
  7. package/dist/chunk-KGXH5DYI.js +152 -0
  8. package/dist/chunk-NYXBQHNJ.mjs +255 -0
  9. package/dist/chunk-PHAG5KUF.mjs +152 -0
  10. package/dist/{chunk-DUNJAMH5.mjs → chunk-PPDHFNFM.mjs} +94 -480
  11. package/dist/{chunk-6Z62LPKB.js → chunk-QMLDI5JU.js} +16 -6
  12. package/dist/{chunk-5TCPFLFT.mjs → chunk-SX7GPOCZ.mjs} +1 -1
  13. package/dist/clients/index.d.ts +6 -3
  14. package/dist/clients/index.js +3 -3
  15. package/dist/clients/index.mjs +2 -2
  16. package/dist/createClient-cd948138.d.ts +62 -0
  17. package/dist/createPublicClient-989a0556.d.ts +19 -0
  18. package/dist/createTestClient-81507f58.d.ts +34 -0
  19. package/dist/createWalletClient-43f801b9.d.ts +30 -0
  20. package/dist/{eip1193-c001fcd5.d.ts → eip1193-4330b722.d.ts} +1 -1
  21. package/dist/index.d.ts +13 -6
  22. package/dist/index.js +8 -4
  23. package/dist/index.mjs +33 -29
  24. package/dist/{parseGwei-21f98a29.d.ts → parseGwei-f2d23de6.d.ts} +1 -1
  25. package/dist/public.d.ts +12 -0
  26. package/dist/public.js +58 -0
  27. package/dist/public.mjs +58 -0
  28. package/dist/sendTransaction-7a9d241a.d.ts +13 -0
  29. package/dist/stopImpersonatingAccount-8113150e.d.ts +156 -0
  30. package/dist/test.d.ts +7 -0
  31. package/dist/test.js +59 -0
  32. package/dist/test.mjs +59 -0
  33. package/dist/{transactionRequest-1d4e4385.d.ts → transactionReceipt-5d332aab.d.ts} +4 -32
  34. package/dist/transactionRequest-327eb7c2.d.ts +33 -0
  35. package/dist/utils/index.d.ts +4 -3
  36. package/dist/utils/index.js +2 -2
  37. package/dist/utils/index.mjs +1 -1
  38. package/dist/wallet.d.ts +9 -0
  39. package/dist/wallet.js +23 -0
  40. package/dist/wallet.mjs +23 -0
  41. package/dist/watchAsset-0088384c.d.ts +39 -0
  42. package/dist/{stopImpersonatingAccount-fcc5a678.d.ts → watchPendingTransactions-670a7ca3.d.ts} +7 -197
  43. package/dist/{webSocket-3385e295.d.ts → webSocket-9a3b0b26.d.ts} +1 -1
  44. package/dist/window.d.ts +1 -1
  45. package/package.json +16 -6
  46. package/actions/package.json +0 -4
  47. package/dist/actions/index.d.ts +0 -8
  48. package/dist/actions/index.js +0 -129
  49. package/dist/actions/index.mjs +0 -129
  50. package/dist/createWalletClient-3f9fa8b6.d.ts +0 -130
@@ -0,0 +1,152 @@
1
+ import {
2
+ BaseError,
3
+ InvalidGasArgumentsError,
4
+ checksumAddress,
5
+ encodeHex,
6
+ extract,
7
+ format,
8
+ formatTransactionRequest,
9
+ getAddress,
10
+ numberToHex
11
+ } from "./chunk-2HENAFQN.mjs";
12
+
13
+ // src/actions/wallet/addChain.ts
14
+ async function addChain(client, chain) {
15
+ const { id, name, nativeCurrency, rpcUrls, blockExplorers } = chain;
16
+ await client.request({
17
+ method: "wallet_addEthereumChain",
18
+ params: [
19
+ {
20
+ chainId: numberToHex(id),
21
+ chainName: name,
22
+ nativeCurrency,
23
+ rpcUrls: rpcUrls.default.http,
24
+ blockExplorerUrls: blockExplorers ? Object.values(blockExplorers).map(({ url }) => url) : void 0
25
+ }
26
+ ]
27
+ });
28
+ }
29
+
30
+ // src/actions/wallet/getAccounts.ts
31
+ async function getAccounts(client) {
32
+ const addresses = await client.request({ method: "eth_accounts" });
33
+ return addresses.map((address) => checksumAddress(address));
34
+ }
35
+
36
+ // src/actions/wallet/getPermissions.ts
37
+ async function getPermissions(client) {
38
+ const permissions = await client.request({ method: "wallet_getPermissions" });
39
+ return permissions;
40
+ }
41
+
42
+ // src/actions/wallet/requestAccounts.ts
43
+ async function requestAccounts(client) {
44
+ const addresses = await client.request({ method: "eth_requestAccounts" });
45
+ return addresses.map((address) => getAddress(address));
46
+ }
47
+
48
+ // src/actions/wallet/requestPermissions.ts
49
+ async function requestPermissions(client, permissions) {
50
+ return client.request({
51
+ method: "wallet_requestPermissions",
52
+ params: [permissions]
53
+ });
54
+ }
55
+
56
+ // src/actions/wallet/sendTransaction.ts
57
+ async function sendTransaction(client, {
58
+ chain,
59
+ from,
60
+ accessList,
61
+ data,
62
+ gas,
63
+ gasPrice,
64
+ maxFeePerGas,
65
+ maxPriorityFeePerGas,
66
+ nonce,
67
+ to,
68
+ value,
69
+ ...rest
70
+ }) {
71
+ if (maxFeePerGas !== void 0 && maxPriorityFeePerGas !== void 0 && maxFeePerGas < maxPriorityFeePerGas)
72
+ throw new InvalidGasArgumentsError();
73
+ const formatter = chain?.formatters?.transactionRequest;
74
+ const request_ = format(
75
+ {
76
+ from,
77
+ accessList,
78
+ data,
79
+ gas,
80
+ gasPrice,
81
+ maxFeePerGas,
82
+ maxPriorityFeePerGas,
83
+ nonce,
84
+ to,
85
+ value,
86
+ ...extract(rest, { formatter })
87
+ },
88
+ {
89
+ formatter: formatter || formatTransactionRequest
90
+ }
91
+ );
92
+ const hash = await client.request({
93
+ method: "eth_sendTransaction",
94
+ params: [request_]
95
+ });
96
+ return hash;
97
+ }
98
+
99
+ // src/actions/wallet/signMessage.ts
100
+ async function signMessage(client, { from, data: data_ }) {
101
+ let data;
102
+ if (typeof data_ === "string") {
103
+ if (!data_.startsWith("0x"))
104
+ throw new BaseError(
105
+ `data ("${data_}") must be a hex value. Encode it first to a hex with the \`encodeHex\` util.`,
106
+ {
107
+ docsPath: "/TODO"
108
+ }
109
+ );
110
+ data = data_;
111
+ } else {
112
+ data = encodeHex(data_);
113
+ }
114
+ const signed = await client.request({
115
+ method: "personal_sign",
116
+ params: [data, from]
117
+ });
118
+ return signed;
119
+ }
120
+
121
+ // src/actions/wallet/switchChain.ts
122
+ async function switchChain(client, { id }) {
123
+ await client.request({
124
+ method: "wallet_switchEthereumChain",
125
+ params: [
126
+ {
127
+ chainId: numberToHex(id)
128
+ }
129
+ ]
130
+ });
131
+ }
132
+
133
+ // src/actions/wallet/watchAsset.ts
134
+ async function watchAsset(client, params) {
135
+ const added = await client.request({
136
+ method: "wallet_watchAsset",
137
+ params: [params]
138
+ });
139
+ return added;
140
+ }
141
+
142
+ export {
143
+ addChain,
144
+ getAccounts,
145
+ getPermissions,
146
+ requestAccounts,
147
+ requestPermissions,
148
+ sendTransaction,
149
+ signMessage,
150
+ switchChain,
151
+ watchAsset
152
+ };