viem 2.33.4-canary-20250807091217 → 2.34.0-canary-20250813141309

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 (39) hide show
  1. package/CHANGELOG.md +8 -2
  2. package/_cjs/accounts/utils/sign.js +8 -1
  3. package/_cjs/accounts/utils/sign.js.map +1 -1
  4. package/_cjs/chains/definitions/humanity.js +27 -0
  5. package/_cjs/chains/definitions/humanity.js.map +1 -0
  6. package/_cjs/chains/index.js +11 -9
  7. package/_cjs/chains/index.js.map +1 -1
  8. package/_cjs/errors/version.js +1 -1
  9. package/_cjs/experimental/erc7811/actions/getAssets.js +2 -2
  10. package/_cjs/experimental/erc7811/actions/getAssets.js.map +1 -1
  11. package/_cjs/experimental/erc7811/decorators/erc7811.js.map +1 -1
  12. package/_esm/accounts/utils/sign.js +8 -1
  13. package/_esm/accounts/utils/sign.js.map +1 -1
  14. package/_esm/chains/definitions/humanity.js +24 -0
  15. package/_esm/chains/definitions/humanity.js.map +1 -0
  16. package/_esm/chains/index.js +1 -0
  17. package/_esm/chains/index.js.map +1 -1
  18. package/_esm/errors/version.js +1 -1
  19. package/_esm/experimental/erc7811/actions/getAssets.js +2 -2
  20. package/_esm/experimental/erc7811/actions/getAssets.js.map +1 -1
  21. package/_esm/experimental/erc7811/decorators/erc7811.js.map +1 -1
  22. package/_types/accounts/utils/sign.d.ts +3 -1
  23. package/_types/accounts/utils/sign.d.ts.map +1 -1
  24. package/_types/chains/definitions/humanity.d.ts +40 -0
  25. package/_types/chains/definitions/humanity.d.ts.map +1 -0
  26. package/_types/chains/index.d.ts +1 -0
  27. package/_types/chains/index.d.ts.map +1 -1
  28. package/_types/errors/version.d.ts +1 -1
  29. package/_types/experimental/erc7811/actions/getAssets.d.ts +45 -49
  30. package/_types/experimental/erc7811/actions/getAssets.d.ts.map +1 -1
  31. package/_types/experimental/erc7811/decorators/erc7811.d.ts +2 -2
  32. package/_types/experimental/erc7811/decorators/erc7811.d.ts.map +1 -1
  33. package/accounts/utils/sign.ts +16 -2
  34. package/chains/definitions/humanity.ts +24 -0
  35. package/chains/index.ts +1 -0
  36. package/errors/version.ts +1 -1
  37. package/experimental/erc7811/actions/getAssets.ts +54 -53
  38. package/experimental/erc7811/decorators/erc7811.ts +1 -2
  39. package/package.json +4 -4
@@ -25,15 +25,10 @@ import {
25
25
  numberToHex,
26
26
  } from '../../../utils/encoding/toHex.js'
27
27
 
28
- export type Asset<chainIds extends boolean = false> = OneOf<
29
- CustomAsset | Erc20Asset | Erc721Asset | NativeAsset
30
- > &
31
- (chainIds extends true ? { chainIds: readonly number[] } : {})
32
-
33
28
  export type GetAssetsParameters<
34
29
  aggregate extends
35
30
  | boolean
36
- | ((asset: Asset) => string)
31
+ | ((asset: getAssets.Asset) => string)
37
32
  | undefined = undefined,
38
33
  account extends Account | undefined = Account | undefined,
39
34
  > = GetAccountParameter<account> & {
@@ -42,7 +37,11 @@ export type GetAssetsParameters<
42
37
  * and assign them to a '0' key.
43
38
  * @default true
44
39
  */
45
- aggregate?: aggregate | boolean | ((asset: Asset) => string) | undefined
40
+ aggregate?:
41
+ | aggregate
42
+ | boolean
43
+ | ((asset: getAssets.Asset) => string)
44
+ | undefined
46
45
  /** Filter by assets. */
47
46
  assets?:
48
47
  | {
@@ -53,13 +52,13 @@ export type GetAssetsParameters<
53
52
  }
54
53
  | {
55
54
  address: Address
56
- type: AssetType
55
+ type: getAssets.AssetType
57
56
  }
58
57
  )[]
59
58
  }
60
59
  | undefined
61
60
  /** Filter by asset types. */
62
- assetTypes?: readonly AssetType[] | undefined
61
+ assetTypes?: readonly getAssets.AssetType[] | undefined
63
62
  /** Filter by chain IDs. */
64
63
  chainIds?: readonly number[] | undefined
65
64
  }
@@ -67,11 +66,11 @@ export type GetAssetsParameters<
67
66
  export type GetAssetsReturnType<
68
67
  aggregate extends
69
68
  | boolean
70
- | ((asset: Asset) => string)
69
+ | ((asset: getAssets.Asset) => string)
71
70
  | undefined = undefined,
72
71
  > = {
73
- [chainId: number]: readonly Asset<false>[]
74
- } & (aggregate extends false ? {} : { 0: readonly Asset<true>[] })
72
+ [chainId: number]: readonly getAssets.Asset<false>[]
73
+ } & (aggregate extends false ? {} : { 0: readonly getAssets.Asset<true>[] })
75
74
 
76
75
  export type GetAssetsErrorType =
77
76
  | HexToBigIntErrorType
@@ -105,7 +104,7 @@ export async function getAssets<
105
104
  account extends Account | undefined = Account | undefined,
106
105
  aggregate extends
107
106
  | boolean
108
- | ((asset: Asset) => string)
107
+ | ((asset: getAssets.Asset) => string)
109
108
  | undefined = undefined,
110
109
  >(
111
110
  client: Client<Transport, chain, account>,
@@ -113,17 +112,17 @@ export async function getAssets<
113
112
  ? [GetAssetsParameters<aggregate, account>] | []
114
113
  : [GetAssetsParameters<aggregate, account>]
115
114
  ): Promise<Prettify<GetAssetsReturnType<aggregate>>> {
116
- const { aggregate = true } = parameters ?? {}
115
+ const { account = client.account, aggregate = true } = parameters ?? {}
117
116
 
118
117
  const result = await client.request({
119
118
  method: 'wallet_getAssets',
120
- params: [formatRequest(parameters)],
119
+ params: [formatRequest({ ...parameters, account })],
121
120
  })
122
121
  const response = formatResponse(result)
123
122
 
124
123
  const aggregated = (() => {
125
124
  if (!aggregate) return undefined
126
- const aggregated = {} as Record<string, Asset<boolean>>
125
+ const aggregated = {} as Record<string, getAssets.Asset<boolean>>
127
126
  for (const [chainId, assets] of Object.entries(response)) {
128
127
  if (chainId === '0') continue
129
128
  for (const asset of assets) {
@@ -131,7 +130,7 @@ export async function getAssets<
131
130
  typeof aggregate === 'function'
132
131
  ? aggregate(asset)
133
132
  : (asset.address ?? ethAddress)
134
- const item = (aggregated[key] ?? {}) as Asset<true>
133
+ const item = (aggregated[key] ?? {}) as getAssets.Asset<true>
135
134
  aggregated[key] = {
136
135
  ...asset,
137
136
  balance: asset.balance + (item?.balance ?? 0n),
@@ -146,48 +145,50 @@ export async function getAssets<
146
145
  return response as never
147
146
  }
148
147
 
149
- /** @internal */
150
- type AssetType = 'native' | 'erc20' | 'erc721' | (string & {})
148
+ export declare namespace getAssets {
149
+ type Asset<chainIds extends boolean = false> = OneOf<
150
+ CustomAsset | Erc20Asset | Erc721Asset | NativeAsset
151
+ > &
152
+ (chainIds extends true ? { chainIds: readonly number[] } : {})
151
153
 
152
- /** @internal */
153
- type CustomAsset = {
154
- address: Address
155
- balance: bigint
156
- metadata: {
157
- [key: string]: unknown
154
+ type AssetType = 'native' | 'erc20' | 'erc721' | (string & {})
155
+
156
+ type CustomAsset = {
157
+ address: Address
158
+ balance: bigint
159
+ metadata: {
160
+ [key: string]: unknown
161
+ }
162
+ type: { custom: string }
158
163
  }
159
- type: { custom: string }
160
- }
161
164
 
162
- /** @internal */
163
- type Erc20Asset = {
164
- address: Address
165
- balance: bigint
166
- metadata: {
167
- name: string
168
- symbol: string
169
- decimals: number
165
+ type Erc20Asset = {
166
+ address: Address
167
+ balance: bigint
168
+ metadata: {
169
+ name: string
170
+ symbol: string
171
+ decimals: number
172
+ }
173
+ type: 'erc20'
170
174
  }
171
- type: 'erc20'
172
- }
173
175
 
174
- /** @internal */
175
- type Erc721Asset = {
176
- address: Address
177
- balance: bigint
178
- metadata: {
179
- name: string
180
- symbol: string
181
- tokenId: bigint
182
- tokenUri?: string | undefined
176
+ type Erc721Asset = {
177
+ address: Address
178
+ balance: bigint
179
+ metadata: {
180
+ name: string
181
+ symbol: string
182
+ tokenId: bigint
183
+ tokenUri?: string | undefined
184
+ }
185
+ type: 'erc721'
183
186
  }
184
- type: 'erc721'
185
- }
186
187
 
187
- /** @internal */
188
- type NativeAsset = {
189
- balance: bigint
190
- type: 'native'
188
+ type NativeAsset = {
189
+ balance: bigint
190
+ type: 'native'
191
+ }
191
192
  }
192
193
 
193
194
  /** @internal */
@@ -219,7 +220,7 @@ function formatResponse(
219
220
  Number(chainId),
220
221
  assets.map((asset) => {
221
222
  const balance = hexToBigInt(asset.balance)
222
- const metadata = asset.metadata as Asset['metadata']
223
+ const metadata = asset.metadata as getAssets.Asset['metadata']
223
224
  const type = (() => {
224
225
  if (asset.type === 'native') return 'native'
225
226
  if (asset.type === 'erc20') return 'erc20'
@@ -3,7 +3,6 @@ import type { Transport } from '../../../clients/transports/createTransport.js'
3
3
  import type { Account } from '../../../types/account.js'
4
4
  import type { Chain } from '../../../types/chain.js'
5
5
  import {
6
- type Asset,
7
6
  type GetAssetsParameters,
8
7
  type GetAssetsReturnType,
9
8
  getAssets,
@@ -38,7 +37,7 @@ export type Erc7811Actions<
38
37
  getAssets: <
39
38
  aggregate extends
40
39
  | boolean
41
- | ((asset: Asset) => string)
40
+ | ((asset: getAssets.Asset) => string)
42
41
  | undefined = undefined,
43
42
  >(
44
43
  ...[parameters]: account extends Account
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.33.4-canary-20250807091217",
4
+ "version": "2.34.0-canary-20250813141309",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -195,14 +195,14 @@
195
195
  }
196
196
  },
197
197
  "dependencies": {
198
- "@noble/curves": "1.9.2",
198
+ "@noble/curves": "1.9.6",
199
199
  "@noble/hashes": "1.8.0",
200
200
  "@scure/bip32": "1.7.0",
201
201
  "@scure/bip39": "1.6.0",
202
202
  "abitype": "1.0.8",
203
203
  "isows": "1.0.7",
204
- "ox": "0.8.6",
205
- "ws": "8.18.2"
204
+ "ox": "0.8.7",
205
+ "ws": "8.18.3"
206
206
  },
207
207
  "license": "MIT",
208
208
  "homepage": "https://viem.sh",