viem 0.0.0-portable-types-20230518183529 → 0.0.0-portable-types-20230523145621
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.
- package/README.md +1 -1
- package/abi/package.json +5 -0
- package/accounts/package.json +5 -0
- package/chains/package.json +5 -0
- package/contract/package.json +5 -0
- package/dist/cjs/actions/ens/getEnsAddress.js +1 -1
- package/dist/cjs/actions/ens/getEnsAddress.js.map +1 -1
- package/dist/cjs/actions/public/estimateGas.js +3 -2
- package/dist/cjs/actions/public/estimateGas.js.map +1 -1
- package/dist/cjs/actions/public/waitForTransactionReceipt.js +23 -12
- package/dist/cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/dist/cjs/actions/public/watchBlockNumber.js +2 -1
- package/dist/cjs/actions/public/watchBlockNumber.js.map +1 -1
- package/dist/cjs/actions/public/watchBlocks.js +2 -1
- package/dist/cjs/actions/public/watchBlocks.js.map +1 -1
- package/dist/cjs/actions/public/watchContractEvent.js +2 -1
- package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
- package/dist/cjs/actions/public/watchEvent.js +2 -1
- package/dist/cjs/actions/public/watchEvent.js.map +1 -1
- package/dist/cjs/actions/public/watchPendingTransactions.js +2 -1
- package/dist/cjs/actions/public/watchPendingTransactions.js.map +1 -1
- package/dist/cjs/errors/abi.js +0 -2
- package/dist/cjs/errors/abi.js.map +1 -1
- package/dist/cjs/errors/ccip.js +2 -1
- package/dist/cjs/errors/ccip.js.map +1 -1
- package/dist/cjs/errors/data.js +2 -2
- package/dist/cjs/errors/data.js.map +1 -1
- package/dist/cjs/errors/rpc.js +8 -2
- package/dist/cjs/errors/rpc.js.map +1 -1
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/eip1193.js +3 -3
- package/dist/cjs/types/eip1193.js.map +1 -1
- package/dist/cjs/utils/abi/decodeAbiParameters.js +22 -14
- package/dist/cjs/utils/abi/decodeAbiParameters.js.map +1 -1
- package/dist/cjs/utils/abi/decodeEventLog.js +5 -5
- package/dist/cjs/utils/abi/decodeEventLog.js.map +1 -1
- package/dist/cjs/utils/buildRequest.js.map +1 -1
- package/dist/cjs/utils/data/isHex.js +2 -2
- package/dist/cjs/utils/data/isHex.js.map +1 -1
- package/dist/cjs/utils/data/size.js +1 -1
- package/dist/cjs/utils/data/size.js.map +1 -1
- package/dist/cjs/utils/data/slice.js +36 -12
- package/dist/cjs/utils/data/slice.js.map +1 -1
- package/dist/cjs/utils/data/trim.js +1 -1
- package/dist/cjs/utils/data/trim.js.map +1 -1
- package/dist/cjs/utils/encoding/fromHex.js +2 -2
- package/dist/cjs/utils/encoding/fromHex.js.map +1 -1
- package/dist/cjs/utils/hash/keccak256.js +1 -1
- package/dist/cjs/utils/hash/keccak256.js.map +1 -1
- package/dist/cjs/utils/promise/createBatchScheduler.js.map +1 -1
- package/dist/cjs/utils/rpc.js +49 -40
- package/dist/cjs/utils/rpc.js.map +1 -1
- package/dist/cjs/utils/signature/recoverPublicKey.js +3 -1
- package/dist/cjs/utils/signature/recoverPublicKey.js.map +1 -1
- package/dist/cjs/utils/transaction/prepareRequest.js +1 -2
- package/dist/cjs/utils/transaction/prepareRequest.js.map +1 -1
- package/dist/cjs/utils/transaction/serializeTransaction.js +2 -1
- package/dist/cjs/utils/transaction/serializeTransaction.js.map +1 -1
- package/dist/esm/actions/ens/getEnsAddress.js +1 -1
- package/dist/esm/actions/ens/getEnsAddress.js.map +1 -1
- package/dist/esm/actions/public/estimateGas.js +3 -2
- package/dist/esm/actions/public/estimateGas.js.map +1 -1
- package/dist/esm/actions/public/waitForTransactionReceipt.js +23 -12
- package/dist/esm/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/dist/esm/actions/public/watchBlockNumber.js +2 -1
- package/dist/esm/actions/public/watchBlockNumber.js.map +1 -1
- package/dist/esm/actions/public/watchBlocks.js +2 -1
- package/dist/esm/actions/public/watchBlocks.js.map +1 -1
- package/dist/esm/actions/public/watchContractEvent.js +2 -1
- package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
- package/dist/esm/actions/public/watchEvent.js +2 -1
- package/dist/esm/actions/public/watchEvent.js.map +1 -1
- package/dist/esm/actions/public/watchPendingTransactions.js +2 -1
- package/dist/esm/actions/public/watchPendingTransactions.js.map +1 -1
- package/dist/esm/errors/abi.js +0 -2
- package/dist/esm/errors/abi.js.map +1 -1
- package/dist/esm/errors/ccip.js +2 -1
- package/dist/esm/errors/ccip.js.map +1 -1
- package/dist/esm/errors/data.js +2 -2
- package/dist/esm/errors/data.js.map +1 -1
- package/dist/esm/errors/rpc.js +8 -2
- package/dist/esm/errors/rpc.js.map +1 -1
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/eip1193.js +1 -1
- package/dist/esm/types/eip1193.js.map +1 -1
- package/dist/esm/utils/abi/decodeAbiParameters.js +23 -15
- package/dist/esm/utils/abi/decodeAbiParameters.js.map +1 -1
- package/dist/esm/utils/abi/decodeEventLog.js +5 -5
- package/dist/esm/utils/abi/decodeEventLog.js.map +1 -1
- package/dist/esm/utils/buildRequest.js.map +1 -1
- package/dist/esm/utils/data/isHex.js +2 -2
- package/dist/esm/utils/data/isHex.js.map +1 -1
- package/dist/esm/utils/data/size.js +1 -1
- package/dist/esm/utils/data/size.js.map +1 -1
- package/dist/esm/utils/data/slice.js +36 -12
- package/dist/esm/utils/data/slice.js.map +1 -1
- package/dist/esm/utils/data/trim.js +1 -1
- package/dist/esm/utils/data/trim.js.map +1 -1
- package/dist/esm/utils/encoding/fromHex.js +2 -2
- package/dist/esm/utils/encoding/fromHex.js.map +1 -1
- package/dist/esm/utils/hash/keccak256.js +1 -1
- package/dist/esm/utils/hash/keccak256.js.map +1 -1
- package/dist/esm/utils/promise/createBatchScheduler.js.map +1 -1
- package/dist/esm/utils/rpc.js +49 -40
- package/dist/esm/utils/rpc.js.map +1 -1
- package/dist/esm/utils/signature/recoverPublicKey.js +3 -1
- package/dist/esm/utils/signature/recoverPublicKey.js.map +1 -1
- package/dist/esm/utils/transaction/prepareRequest.js +1 -2
- package/dist/esm/utils/transaction/prepareRequest.js.map +1 -1
- package/dist/esm/utils/transaction/serializeTransaction.js +2 -1
- package/dist/esm/utils/transaction/serializeTransaction.js.map +1 -1
- package/dist/types/actions/public/createBlockFilter.d.ts +1 -1
- package/dist/types/actions/public/createContractEventFilter.d.ts +1 -1
- package/dist/types/actions/public/createEventFilter.d.ts +1 -1
- package/dist/types/actions/public/createPendingTransactionFilter.d.ts +1 -1
- package/dist/types/actions/public/estimateContractGas.d.ts +1 -1
- package/dist/types/actions/public/estimateGas.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterChanges.d.ts +4 -4
- package/dist/types/actions/public/getTransaction.d.ts +1 -1
- package/dist/types/actions/public/getTransactionCount.d.ts +1 -1
- package/dist/types/actions/public/getTransactionReceipt.d.ts +2 -2
- package/dist/types/actions/public/multicall.d.ts +1 -1
- package/dist/types/actions/public/readContract.d.ts +2 -2
- package/dist/types/actions/public/readContract.d.ts.map +1 -1
- package/dist/types/actions/public/simulateContract.d.ts +2 -2
- package/dist/types/actions/public/uninstallFilter.d.ts +3 -3
- package/dist/types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
- package/dist/types/actions/public/watchBlockNumber.d.ts.map +1 -1
- package/dist/types/actions/public/watchBlocks.d.ts.map +1 -1
- package/dist/types/actions/public/watchContractEvent.d.ts +1 -1
- package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/dist/types/actions/public/watchEvent.d.ts +2 -2
- package/dist/types/actions/public/watchEvent.d.ts.map +1 -1
- package/dist/types/actions/public/watchPendingTransactions.d.ts.map +1 -1
- package/dist/types/actions/test/setBlockTimestampInterval.d.ts +1 -1
- package/dist/types/actions/test/stopImpersonatingAccount.d.ts +1 -1
- package/dist/types/actions/wallet/deployContract.d.ts +1 -1
- package/dist/types/actions/wallet/signMessage.d.ts +2 -2
- package/dist/types/actions/wallet/writeContract.d.ts +3 -3
- package/dist/types/clients/createPublicClient.d.ts +1 -1
- package/dist/types/clients/createTestClient.d.ts +4 -4
- package/dist/types/clients/createTestClient.d.ts.map +1 -1
- package/dist/types/clients/createWalletClient.d.ts +2 -2
- package/dist/types/clients/decorators/public.d.ts +22 -22
- package/dist/types/clients/decorators/test.d.ts +2 -2
- package/dist/types/clients/decorators/wallet.d.ts +6 -6
- package/dist/types/errors/abi.d.ts.map +1 -1
- package/dist/types/errors/ccip.d.ts.map +1 -1
- package/dist/types/errors/data.d.ts +2 -1
- package/dist/types/errors/data.d.ts.map +1 -1
- package/dist/types/errors/rpc.d.ts +12 -8
- package/dist/types/errors/rpc.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/contract.d.ts +7 -33
- package/dist/types/types/contract.d.ts.map +1 -1
- package/dist/types/types/eip1193.d.ts +7 -8
- package/dist/types/types/eip1193.d.ts.map +1 -1
- package/dist/types/types/log.d.ts +0 -2
- package/dist/types/types/log.d.ts.map +1 -1
- package/dist/types/utils/abi/decodeAbiParameters.d.ts.map +1 -1
- package/dist/types/utils/buildRequest.d.ts.map +1 -1
- package/dist/types/utils/data/isHex.d.ts +3 -1
- package/dist/types/utils/data/isHex.d.ts.map +1 -1
- package/dist/types/utils/data/slice.d.ts +9 -3
- package/dist/types/utils/data/slice.d.ts.map +1 -1
- package/dist/types/utils/data/trim.d.ts.map +1 -1
- package/dist/types/utils/encoding/fromHex.d.ts +1 -1
- package/dist/types/utils/hash/keccak256.d.ts.map +1 -1
- package/dist/types/utils/promise/createBatchScheduler.d.ts +6 -4
- package/dist/types/utils/promise/createBatchScheduler.d.ts.map +1 -1
- package/dist/types/utils/rpc.d.ts.map +1 -1
- package/dist/types/utils/signature/recoverPublicKey.d.ts.map +1 -1
- package/dist/types/utils/transaction/prepareRequest.d.ts +1 -1
- package/dist/types/utils/transaction/prepareRequest.d.ts.map +1 -1
- package/dist/types/utils/transaction/serializeTransaction.d.ts.map +1 -1
- package/ens/package.json +5 -0
- package/ethers/package.json +5 -0
- package/package.json +13 -2
- package/public/package.json +5 -0
- package/src/actions/ens/getEnsAddress.ts +1 -1
- package/src/actions/public/createBlockFilter.ts +1 -1
- package/src/actions/public/createContractEventFilter.ts +1 -1
- package/src/actions/public/createEventFilter.ts +1 -1
- package/src/actions/public/createPendingTransactionFilter.ts +1 -1
- package/src/actions/public/estimateContractGas.ts +1 -1
- package/src/actions/public/estimateGas.ts +3 -2
- package/src/actions/public/getFilterChanges.ts +4 -4
- package/src/actions/public/getTransaction.ts +1 -1
- package/src/actions/public/getTransactionCount.ts +1 -1
- package/src/actions/public/getTransactionReceipt.ts +2 -2
- package/src/actions/public/multicall.ts +1 -1
- package/src/actions/public/readContract.ts +2 -2
- package/src/actions/public/simulateContract.ts +2 -2
- package/src/actions/public/uninstallFilter.ts +3 -3
- package/src/actions/public/waitForTransactionReceipt.ts +33 -11
- package/src/actions/public/watchBlockNumber.ts +2 -1
- package/src/actions/public/watchBlocks.ts +2 -1
- package/src/actions/public/watchContractEvent.ts +3 -2
- package/src/actions/public/watchEvent.ts +4 -3
- package/src/actions/public/watchPendingTransactions.ts +2 -1
- package/src/actions/test/setBlockTimestampInterval.ts +1 -1
- package/src/actions/test/stopImpersonatingAccount.ts +1 -1
- package/src/actions/wallet/deployContract.ts +1 -1
- package/src/actions/wallet/signMessage.ts +2 -2
- package/src/actions/wallet/writeContract.ts +3 -3
- package/src/clients/createPublicClient.ts +1 -1
- package/src/clients/createTestClient.ts +4 -4
- package/src/clients/createWalletClient.ts +2 -2
- package/src/clients/decorators/public.ts +22 -22
- package/src/clients/decorators/test.ts +2 -2
- package/src/clients/decorators/wallet.ts +6 -6
- package/src/errors/abi.ts +0 -2
- package/src/errors/ccip.ts +2 -1
- package/src/errors/data.ts +8 -2
- package/src/errors/rpc.ts +42 -15
- package/src/errors/version.ts +1 -1
- package/src/index.ts +8 -3
- package/src/types/contract.ts +11 -87
- package/src/types/eip1193.ts +10 -13
- package/src/types/log.ts +2 -2
- package/src/utils/abi/decodeAbiParameters.ts +36 -15
- package/src/utils/abi/decodeEventLog.ts +5 -5
- package/src/utils/buildRequest.ts +5 -1
- package/src/utils/data/isHex.ts +5 -2
- package/src/utils/data/size.ts +1 -1
- package/src/utils/data/slice.ts +43 -11
- package/src/utils/data/trim.ts +3 -1
- package/src/utils/encoding/fromHex.ts +3 -3
- package/src/utils/hash/keccak256.ts +3 -1
- package/src/utils/promise/createBatchScheduler.ts +24 -7
- package/src/utils/rpc.ts +59 -49
- package/src/utils/signature/recoverPublicKey.ts +2 -1
- package/src/utils/transaction/prepareRequest.ts +1 -2
- package/src/utils/transaction/serializeTransaction.ts +3 -2
- package/test/package.json +5 -0
- package/utils/package.json +5 -0
- package/wallet/package.json +5 -0
- package/window/package.json +5 -0
package/src/errors/rpc.ts
CHANGED
@@ -1,10 +1,27 @@
|
|
1
|
+
import type { Prettify } from '../types/utils.js'
|
1
2
|
import { BaseError } from './base.js'
|
2
3
|
import { RpcRequestError } from './request.js'
|
3
4
|
|
4
5
|
const unknownErrorCode = -1
|
5
6
|
|
6
|
-
type
|
7
|
-
|
7
|
+
export type RpcErrorCode =
|
8
|
+
| -1
|
9
|
+
| -32700 // Parse error
|
10
|
+
| -32600 // Invalid request
|
11
|
+
| -32601 // Method not found
|
12
|
+
| -32602 // Invalid params
|
13
|
+
| -32603 // Internal error
|
14
|
+
| -32000 // Invalid input
|
15
|
+
| -32001 // Resource not found
|
16
|
+
| -32002 // Resource unavailable
|
17
|
+
| -32003 // Transaction rejected
|
18
|
+
| -32004 // Method not supported
|
19
|
+
| -32005 // Limit exceeded
|
20
|
+
| -32006 // JSON-RPC version not supported
|
21
|
+
| -32042 // Method not found
|
22
|
+
|
23
|
+
type RpcErrorOptions<TCode extends number = RpcErrorCode> = {
|
24
|
+
code?: TCode
|
8
25
|
docsPath?: string
|
9
26
|
metaMessages?: string[]
|
10
27
|
shortMessage: string
|
@@ -15,17 +32,13 @@ type RpcErrorOptions = {
|
|
15
32
|
*
|
16
33
|
* - EIP https://eips.ethereum.org/EIPS/eip-1474
|
17
34
|
*/
|
18
|
-
export class RpcError extends BaseError {
|
19
|
-
|
35
|
+
export class RpcError<TCode extends number = RpcErrorCode> extends BaseError {
|
36
|
+
override name = 'RpcError'
|
37
|
+
code: TCode
|
20
38
|
|
21
39
|
constructor(
|
22
40
|
cause: Error,
|
23
|
-
{
|
24
|
-
code = unknownErrorCode,
|
25
|
-
docsPath,
|
26
|
-
metaMessages,
|
27
|
-
shortMessage,
|
28
|
-
}: RpcErrorOptions,
|
41
|
+
{ code, docsPath, metaMessages, shortMessage }: RpcErrorOptions<TCode>,
|
29
42
|
) {
|
30
43
|
super(shortMessage, {
|
31
44
|
cause,
|
@@ -34,25 +47,39 @@ export class RpcError extends BaseError {
|
|
34
47
|
metaMessages || (cause as { metaMessages?: string[] })?.metaMessages,
|
35
48
|
})
|
36
49
|
this.name = cause.name
|
37
|
-
this.code =
|
50
|
+
this.code = (
|
51
|
+
cause instanceof RpcRequestError ? cause.code : code ?? unknownErrorCode
|
52
|
+
) as TCode
|
38
53
|
}
|
39
54
|
}
|
40
55
|
|
56
|
+
export type ProviderRpcErrorCode =
|
57
|
+
| 4001 // User Rejected Request
|
58
|
+
| 4100 // Unauthorized
|
59
|
+
| 4200 // Unsupported Method
|
60
|
+
| 4900 // Disconnected
|
61
|
+
| 4901 // Chain Disconnected
|
62
|
+
| 4902 // Chain Not Recongnized
|
63
|
+
|
41
64
|
/**
|
42
65
|
* Error subclass implementing Ethereum Provider errors per EIP-1193.
|
43
66
|
*
|
44
67
|
* - EIP https://eips.ethereum.org/EIPS/eip-1193
|
45
68
|
*/
|
46
|
-
export class ProviderRpcError<
|
69
|
+
export class ProviderRpcError<
|
70
|
+
T = undefined,
|
71
|
+
> extends RpcError<ProviderRpcErrorCode> {
|
47
72
|
override name = 'ProviderRpcError'
|
48
73
|
|
49
74
|
data?: T
|
50
75
|
|
51
76
|
constructor(
|
52
77
|
cause: Error,
|
53
|
-
options:
|
54
|
-
|
55
|
-
|
78
|
+
options: Prettify<
|
79
|
+
RpcErrorOptions<ProviderRpcErrorCode> & {
|
80
|
+
data?: T
|
81
|
+
}
|
82
|
+
>,
|
56
83
|
) {
|
57
84
|
super(cause, options)
|
58
85
|
|
package/src/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '0.3.
|
1
|
+
export const version = '0.3.35'
|
package/src/index.ts
CHANGED
@@ -23,6 +23,10 @@ export {
|
|
23
23
|
type DeployContractReturnType,
|
24
24
|
} from './actions/wallet/deployContract.js'
|
25
25
|
export type { DropTransactionParameters } from './actions/test/dropTransaction.js'
|
26
|
+
export {
|
27
|
+
type EstimateContractGasParameters,
|
28
|
+
type EstimateContractGasReturnType,
|
29
|
+
} from './actions/public/estimateContractGas.js'
|
26
30
|
export {
|
27
31
|
type EstimateGasParameters,
|
28
32
|
type EstimateGasReturnType,
|
@@ -288,9 +292,11 @@ export {
|
|
288
292
|
ParseRpcError,
|
289
293
|
ProviderDisconnectedError,
|
290
294
|
ProviderRpcError,
|
295
|
+
type ProviderRpcErrorCode,
|
291
296
|
ResourceNotFoundRpcError,
|
292
297
|
ResourceUnavailableRpcError,
|
293
298
|
RpcError,
|
299
|
+
type RpcErrorCode,
|
294
300
|
TransactionRejectedRpcError,
|
295
301
|
SwitchChainError,
|
296
302
|
UnauthorizedProviderError,
|
@@ -436,11 +442,10 @@ export {
|
|
436
442
|
export type { Chain } from './types/chain.js'
|
437
443
|
export type {
|
438
444
|
EIP1193Provider,
|
439
|
-
|
440
|
-
RpcError as RpcError_,
|
445
|
+
ProviderRpcError as EIP1193ProviderRpcError,
|
441
446
|
ProviderConnectInfo,
|
442
447
|
ProviderMessage,
|
443
|
-
|
448
|
+
AddEthereumChainParameter,
|
444
449
|
NetworkSync,
|
445
450
|
PublicRequests,
|
446
451
|
Requests,
|
package/src/types/contract.ts
CHANGED
@@ -20,7 +20,7 @@ import type {
|
|
20
20
|
|
21
21
|
import type { Hex, LogTopic } from './misc.js'
|
22
22
|
import type { TransactionRequest } from './transaction.js'
|
23
|
-
import type { Filter,
|
23
|
+
import type { Filter, NoUndefined } from './utils.js'
|
24
24
|
|
25
25
|
export type AbiItem = Abi[number]
|
26
26
|
|
@@ -236,7 +236,10 @@ export type GetEventArgsFromTopics<
|
|
236
236
|
TAbiEvent extends AbiEvent & { type: 'event' } = TAbi extends Abi
|
237
237
|
? ExtractAbiEvent<TAbi, TEventName>
|
238
238
|
: AbiEvent & { type: 'event' },
|
239
|
-
TArgs =
|
239
|
+
TArgs = AbiEventParametersToPrimitiveTypes<
|
240
|
+
TAbiEvent['inputs'],
|
241
|
+
{ EnableUnion: false; IndexedOnly: false }
|
242
|
+
>,
|
240
243
|
> = TTopics extends readonly []
|
241
244
|
? TData extends undefined
|
242
245
|
? { args?: never }
|
@@ -249,12 +252,10 @@ export type GetEventArgsFromTopics<
|
|
249
252
|
type EventParameterOptions = {
|
250
253
|
EnableUnion?: boolean
|
251
254
|
IndexedOnly?: boolean
|
252
|
-
Required?: boolean
|
253
255
|
}
|
254
256
|
type DefaultEventParameterOptions = {
|
255
257
|
EnableUnion: true
|
256
258
|
IndexedOnly: true
|
257
|
-
Required: false
|
258
259
|
}
|
259
260
|
|
260
261
|
type HashedEventTypes = 'bytes' | 'string' | 'tuple' | `${string}[${string}]`
|
@@ -326,13 +327,11 @@ export type AbiEventParametersToPrimitiveTypes<
|
|
326
327
|
>
|
327
328
|
},
|
328
329
|
]
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
infer _,
|
335
|
-
]
|
330
|
+
// Distribute over tuple to represent optional parameters
|
331
|
+
| (Filtered extends readonly [
|
332
|
+
...infer Head extends readonly AbiParameter[],
|
333
|
+
infer _,
|
334
|
+
]
|
336
335
|
? AbiEventParametersToPrimitiveTypes<
|
337
336
|
readonly [...{ [K in keyof Head]: Omit<Head[K], 'name'> }],
|
338
337
|
Options
|
@@ -347,81 +346,6 @@ export type AbiEventParametersToPrimitiveTypes<
|
|
347
346
|
? Name
|
348
347
|
: never]?: AbiEventParameterToPrimitiveType<Parameter, Options>
|
349
348
|
} extends infer Mapped
|
350
|
-
?
|
351
|
-
Mapped,
|
352
|
-
Options['Required'] extends boolean ? Options['Required'] : false
|
353
|
-
>
|
349
|
+
? Mapped
|
354
350
|
: never
|
355
351
|
: never
|
356
|
-
|
357
|
-
/**
|
358
|
-
* @internal
|
359
|
-
*/
|
360
|
-
// TODO(@tmm): Simplify this type
|
361
|
-
export type AbiEventTopicsToPrimitiveTypes<
|
362
|
-
TAbiParameters extends readonly AbiParameter[],
|
363
|
-
TTopics extends LogTopic[] | undefined = undefined,
|
364
|
-
TData extends Hex | undefined = undefined,
|
365
|
-
TBase = TAbiParameters[0] extends { name: string } ? {} : [],
|
366
|
-
> = Prettify<
|
367
|
-
TAbiParameters extends readonly [
|
368
|
-
infer Head extends AbiParameter,
|
369
|
-
...infer Tail,
|
370
|
-
]
|
371
|
-
? TTopics extends readonly [infer TopicHead, ...infer TopicTail]
|
372
|
-
? Head extends { indexed: true }
|
373
|
-
? Head extends { name: infer Name extends string }
|
374
|
-
? {
|
375
|
-
[_ in Name]: TopicHead extends LogTopic
|
376
|
-
? AbiEventTopicToPrimitiveType<Head, TopicHead>
|
377
|
-
: never
|
378
|
-
} & (Tail extends readonly []
|
379
|
-
? {}
|
380
|
-
: Tail extends readonly AbiParameter[]
|
381
|
-
? TopicTail extends LogTopic[]
|
382
|
-
? AbiEventTopicsToPrimitiveTypes<Tail, TopicTail, TData>
|
383
|
-
: {}
|
384
|
-
: {})
|
385
|
-
: [
|
386
|
-
TopicHead extends LogTopic
|
387
|
-
? AbiEventTopicToPrimitiveType<Head, TopicHead>
|
388
|
-
: never,
|
389
|
-
...(Tail extends readonly []
|
390
|
-
? []
|
391
|
-
: Tail extends readonly AbiParameter[]
|
392
|
-
? TopicTail extends LogTopic[]
|
393
|
-
? AbiEventTopicsToPrimitiveTypes<Tail, TopicTail, TData>
|
394
|
-
: []
|
395
|
-
: []),
|
396
|
-
]
|
397
|
-
: TBase
|
398
|
-
: TTopics extends readonly []
|
399
|
-
? TData extends '0x'
|
400
|
-
? TBase
|
401
|
-
: TData extends Hex
|
402
|
-
? Head extends AbiParameter
|
403
|
-
? Head extends { indexed: true }
|
404
|
-
? Tail extends readonly AbiParameter[]
|
405
|
-
? AbiEventTopicsToPrimitiveTypes<Tail, [], TData>
|
406
|
-
: TBase
|
407
|
-
: Head extends { name: infer Name extends string }
|
408
|
-
? {
|
409
|
-
[_ in Name]: AbiParameterToPrimitiveType<Head>
|
410
|
-
} & (Tail extends readonly []
|
411
|
-
? {}
|
412
|
-
: Tail extends readonly AbiParameter[]
|
413
|
-
? AbiEventTopicsToPrimitiveTypes<Tail, [], TData>
|
414
|
-
: {})
|
415
|
-
: [
|
416
|
-
AbiParameterToPrimitiveType<Head>,
|
417
|
-
...(Tail extends readonly []
|
418
|
-
? []
|
419
|
-
: Tail extends readonly AbiParameter[]
|
420
|
-
? AbiEventTopicsToPrimitiveTypes<Tail, [], TData>
|
421
|
-
: []),
|
422
|
-
]
|
423
|
-
: TBase
|
424
|
-
: TBase
|
425
|
-
: TBase
|
426
|
-
: undefined
|
427
|
-
>
|
package/src/types/eip1193.ts
CHANGED
@@ -23,17 +23,11 @@ export type EIP1193Provider = Requests & Events
|
|
23
23
|
//////////////////////////////////////////////////
|
24
24
|
// Errors
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
// https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
29
|
-
| 4_001 | 4_100 | 4_200 | 4_900 | 4_901
|
30
|
-
// https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
31
|
-
| -32700 | -32600 | -32601 | -32602 | -32603 | -32000 | -32001 | -32002 | -32003 | -32004 | -32005 | -32006
|
32
|
-
export class RpcError extends Error {
|
33
|
-
code: RpcErrorCode | (number & {})
|
26
|
+
export class ProviderRpcError extends Error {
|
27
|
+
code: number
|
34
28
|
details: string
|
35
29
|
|
36
|
-
constructor(code:
|
30
|
+
constructor(code: number, message: string) {
|
37
31
|
super(message)
|
38
32
|
this.code = code
|
39
33
|
this.details = message
|
@@ -57,7 +51,7 @@ export type Events = {
|
|
57
51
|
event: 'connect',
|
58
52
|
listener: (connectInfo: ProviderConnectInfo) => void,
|
59
53
|
): void
|
60
|
-
on(event: 'disconnect', listener: (error:
|
54
|
+
on(event: 'disconnect', listener: (error: ProviderRpcError) => void): void
|
61
55
|
on(event: 'chainChanged', listener: (chainId: string) => void): void
|
62
56
|
on(event: 'accountsChanged', listener: (accounts: string[]) => void): void
|
63
57
|
on(event: 'message', listener: (message: ProviderMessage) => void): void
|
@@ -66,7 +60,10 @@ export type Events = {
|
|
66
60
|
event: 'connect',
|
67
61
|
listener: (connectInfo: ProviderConnectInfo) => void,
|
68
62
|
): void
|
69
|
-
removeListener(
|
63
|
+
removeListener(
|
64
|
+
event: 'disconnect',
|
65
|
+
listener: (error: ProviderRpcError) => void,
|
66
|
+
): void
|
70
67
|
removeListener(
|
71
68
|
event: 'chainChanged',
|
72
69
|
listener: (chainId: string) => void,
|
@@ -84,7 +81,7 @@ export type Events = {
|
|
84
81
|
//////////////////////////////////////////////////
|
85
82
|
// Provider Requests
|
86
83
|
|
87
|
-
export type
|
84
|
+
export type AddEthereumChainParameter = {
|
88
85
|
/** A 0x-prefixed hexadecimal string */
|
89
86
|
chainId: string
|
90
87
|
/** The chain name. */
|
@@ -1034,7 +1031,7 @@ export type WalletRequests = {
|
|
1034
1031
|
* // => { ... }
|
1035
1032
|
*/
|
1036
1033
|
method: 'wallet_addEthereumChain'
|
1037
|
-
params: [chain:
|
1034
|
+
params: [chain: AddEthereumChainParameter]
|
1038
1035
|
}): Promise<null>
|
1039
1036
|
request(args: {
|
1040
1037
|
/**
|
package/src/types/log.ts
CHANGED
@@ -93,7 +93,7 @@ type GetInferredLogValues<
|
|
93
93
|
args: GetEventArgs<
|
94
94
|
TAbi,
|
95
95
|
TEventName,
|
96
|
-
{ EnableUnion: false; IndexedOnly: false
|
96
|
+
{ EnableUnion: false; IndexedOnly: false }
|
97
97
|
>
|
98
98
|
/** The event name decoded from `topics`. */
|
99
99
|
eventName: TEventName
|
@@ -105,7 +105,7 @@ type GetInferredLogValues<
|
|
105
105
|
args: GetEventArgs<
|
106
106
|
TAbi,
|
107
107
|
string,
|
108
|
-
{ EnableUnion: false; IndexedOnly: false
|
108
|
+
{ EnableUnion: false; IndexedOnly: false }
|
109
109
|
>
|
110
110
|
/** The event name decoded from `topics`. */
|
111
111
|
eventName: TName
|
@@ -6,7 +6,6 @@ import type {
|
|
6
6
|
} from 'abitype'
|
7
7
|
|
8
8
|
import {
|
9
|
-
AbiDecodingDataSizeInvalidError,
|
10
9
|
AbiDecodingDataSizeTooSmallError,
|
11
10
|
AbiDecodingZeroDataError,
|
12
11
|
InvalidAbiDecodingTypeError,
|
@@ -38,8 +37,12 @@ export function decodeAbiParameters<
|
|
38
37
|
>(params: Narrow<TParams>, data: Hex): DecodeAbiParametersReturnType<TParams> {
|
39
38
|
if (data === '0x' && (params as unknown[]).length > 0)
|
40
39
|
throw new AbiDecodingZeroDataError()
|
41
|
-
if (size(data)
|
42
|
-
throw new
|
40
|
+
if (size(data) && size(data) < 32)
|
41
|
+
throw new AbiDecodingDataSizeTooSmallError({
|
42
|
+
data,
|
43
|
+
params: params as readonly AbiParameter[],
|
44
|
+
size: size(data),
|
45
|
+
})
|
43
46
|
return decodeParams({
|
44
47
|
data,
|
45
48
|
params: params as readonly AbiParameter[],
|
@@ -102,7 +105,7 @@ function decodeParam({
|
|
102
105
|
return decodeBytes(data, { param, position })
|
103
106
|
}
|
104
107
|
|
105
|
-
const value = slice(data, position, position + 32) as Hex
|
108
|
+
const value = slice(data, position, position + 32, { strict: true }) as Hex
|
106
109
|
if (param.type.startsWith('uint') || param.type.startsWith('int')) {
|
107
110
|
return decodeNumber(value, { param })
|
108
111
|
}
|
@@ -139,9 +142,13 @@ function decodeArray<TParam extends AbiParameter>(
|
|
139
142
|
// we will need to decode the offset of the array data.
|
140
143
|
if (!length) {
|
141
144
|
// Get the offset of the array data.
|
142
|
-
const offset = hexToNumber(
|
145
|
+
const offset = hexToNumber(
|
146
|
+
slice(data, position, position + 32, { strict: true }),
|
147
|
+
)
|
143
148
|
// Get the length of the array from the offset.
|
144
|
-
const length = hexToNumber(
|
149
|
+
const length = hexToNumber(
|
150
|
+
slice(data, offset, offset + 32, { strict: true }),
|
151
|
+
)
|
145
152
|
|
146
153
|
let consumed = 0
|
147
154
|
const value: AbiParameterToPrimitiveType<TParam>[] = []
|
@@ -169,7 +176,9 @@ function decodeArray<TParam extends AbiParameter>(
|
|
169
176
|
let consumed = 0
|
170
177
|
const value: AbiParameterToPrimitiveType<TParam>[] = []
|
171
178
|
for (let i = 0; i < length; ++i) {
|
172
|
-
const offset = hexToNumber(
|
179
|
+
const offset = hexToNumber(
|
180
|
+
slice(data, position, position + 32, { strict: true }),
|
181
|
+
)
|
173
182
|
const decodedChild = decodeParam({
|
174
183
|
data: slice(data, offset),
|
175
184
|
param,
|
@@ -210,15 +219,23 @@ function decodeBytes<TParam extends AbiParameter>(
|
|
210
219
|
if (!size) {
|
211
220
|
// If we don't have a size, we're dealing with a dynamic-size array
|
212
221
|
// so we need to read the offset of the data part first.
|
213
|
-
const offset = hexToNumber(
|
214
|
-
|
222
|
+
const offset = hexToNumber(
|
223
|
+
slice(data, position, position + 32, { strict: true }),
|
224
|
+
)
|
225
|
+
const length = hexToNumber(
|
226
|
+
slice(data, offset, offset + 32, { strict: true }),
|
227
|
+
)
|
215
228
|
// If there is no length, we have zero data.
|
216
229
|
if (length === 0) return { consumed: 32, value: '0x' }
|
217
|
-
const value = slice(data, offset + 32, offset + 32 + length
|
230
|
+
const value = slice(data, offset + 32, offset + 32 + length, {
|
231
|
+
strict: true,
|
232
|
+
})
|
218
233
|
return { consumed: 32, value }
|
219
234
|
}
|
220
235
|
|
221
|
-
const value = slice(data, position, position + parseInt(size)
|
236
|
+
const value = slice(data, position, position + parseInt(size), {
|
237
|
+
strict: true,
|
238
|
+
})
|
222
239
|
return { consumed: 32, value }
|
223
240
|
}
|
224
241
|
|
@@ -238,12 +255,14 @@ function decodeNumber<TParam extends AbiParameter>(
|
|
238
255
|
}
|
239
256
|
|
240
257
|
function decodeString(data: Hex, { position }: { position: number }) {
|
241
|
-
const offset = hexToNumber(
|
242
|
-
|
258
|
+
const offset = hexToNumber(
|
259
|
+
slice(data, position, position + 32, { strict: true }),
|
260
|
+
)
|
261
|
+
const length = hexToNumber(slice(data, offset, offset + 32, { strict: true }))
|
243
262
|
// If there is no length, we have zero data (empty string).
|
244
263
|
if (length === 0) return { consumed: 32, value: '' }
|
245
264
|
const value = hexToString(
|
246
|
-
trim(slice(data, offset + 32, offset + 32 + length)),
|
265
|
+
trim(slice(data, offset + 32, offset + 32 + length, { strict: true })),
|
247
266
|
)
|
248
267
|
return { consumed: 32, value }
|
249
268
|
}
|
@@ -266,7 +285,9 @@ function decodeTuple<
|
|
266
285
|
// If the tuple has a dynamic child, we must first decode the offset to the
|
267
286
|
// tuple data.
|
268
287
|
if (hasDynamicChild(param)) {
|
269
|
-
const offset = hexToNumber(
|
288
|
+
const offset = hexToNumber(
|
289
|
+
slice(data, position, position + 32, { strict: true }),
|
290
|
+
)
|
270
291
|
// Decode each component of the tuple, starting at the offset.
|
271
292
|
for (let i = 0; i < param.components.length; ++i) {
|
272
293
|
const component = param.components[i]
|
@@ -93,8 +93,8 @@ export function decodeEventLog<
|
|
93
93
|
let args: any = isUnnamed ? [] : {}
|
94
94
|
|
95
95
|
// Decode topics (indexed args).
|
96
|
+
const indexedInputs = inputs.filter((x) => 'indexed' in x && x.indexed)
|
96
97
|
if (argTopics.length > 0) {
|
97
|
-
const indexedInputs = inputs.filter((x) => 'indexed' in x && x.indexed)
|
98
98
|
for (let i = 0; i < indexedInputs.length; i++) {
|
99
99
|
const param = indexedInputs[i]
|
100
100
|
const topic = argTopics[i]
|
@@ -108,15 +108,15 @@ export function decodeEventLog<
|
|
108
108
|
}
|
109
109
|
|
110
110
|
// Decode data (non-indexed args).
|
111
|
+
const nonIndexedInputs = inputs.filter((x) => !('indexed' in x && x.indexed))
|
111
112
|
if (data && data !== '0x') {
|
112
|
-
const params = inputs.filter((x) => !('indexed' in x && x.indexed))
|
113
113
|
try {
|
114
|
-
const decodedData = decodeAbiParameters(
|
114
|
+
const decodedData = decodeAbiParameters(nonIndexedInputs, data)
|
115
115
|
if (decodedData) {
|
116
116
|
if (isUnnamed) args = [...args, ...decodedData]
|
117
117
|
else {
|
118
|
-
for (let i = 0; i <
|
119
|
-
args[
|
118
|
+
for (let i = 0; i < nonIndexedInputs.length; i++) {
|
119
|
+
args[nonIndexedInputs[i].name!] = decodedData[i]
|
120
120
|
}
|
121
121
|
}
|
122
122
|
}
|
@@ -12,9 +12,11 @@ import {
|
|
12
12
|
MethodNotSupportedRpcError,
|
13
13
|
ParseRpcError,
|
14
14
|
ProviderDisconnectedError,
|
15
|
+
type ProviderRpcErrorCode,
|
15
16
|
ResourceNotFoundRpcError,
|
16
17
|
ResourceUnavailableRpcError,
|
17
18
|
type RpcError,
|
19
|
+
type RpcErrorCode,
|
18
20
|
SwitchChainError,
|
19
21
|
TransactionRejectedRpcError,
|
20
22
|
UnauthorizedProviderError,
|
@@ -66,7 +68,9 @@ export function buildRequest<TRequest extends (args: any) => Promise<any>>(
|
|
66
68
|
try {
|
67
69
|
return await request(args)
|
68
70
|
} catch (err_) {
|
69
|
-
const err = err_ as unknown as RpcError
|
71
|
+
const err = err_ as unknown as RpcError<
|
72
|
+
RpcErrorCode | ProviderRpcErrorCode
|
73
|
+
>
|
70
74
|
if (err.code === -32700) throw new ParseRpcError(err)
|
71
75
|
if (err.code === -32600) throw new InvalidRequestRpcError(err)
|
72
76
|
if (err.code === -32601) throw new MethodNotFoundRpcError(err)
|
package/src/utils/data/isHex.ts
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
import type { Hex } from '../../types/misc.js'
|
2
2
|
|
3
|
-
export function isHex(
|
3
|
+
export function isHex(
|
4
|
+
value: unknown,
|
5
|
+
{ strict = true }: { strict?: boolean } = {},
|
6
|
+
): value is Hex {
|
4
7
|
if (!value) return false
|
5
8
|
if (typeof value !== 'string') return false
|
6
|
-
return /^0x[0-9a-fA-F]*$/.test(value)
|
9
|
+
return strict ? /^0x[0-9a-fA-F]*$/.test(value) : value.startsWith('0x')
|
7
10
|
}
|
package/src/utils/data/size.ts
CHANGED
@@ -9,6 +9,6 @@ import { isHex } from './isHex.js'
|
|
9
9
|
* @returns The size of the value (in bytes).
|
10
10
|
*/
|
11
11
|
export function size(value: Hex | ByteArray) {
|
12
|
-
if (isHex(value)) return Math.ceil((value.length - 2) / 2)
|
12
|
+
if (isHex(value, { strict: false })) return Math.ceil((value.length - 2) / 2)
|
13
13
|
return value.length
|
14
14
|
}
|
package/src/utils/data/slice.ts
CHANGED
@@ -19,15 +19,38 @@ export function slice<TValue extends ByteArray | Hex>(
|
|
19
19
|
value: TValue,
|
20
20
|
start?: number,
|
21
21
|
end?: number,
|
22
|
+
{ strict }: { strict?: boolean } = {},
|
22
23
|
): SliceReturnType<TValue> {
|
23
|
-
if (isHex(value))
|
24
|
-
return sliceHex(value as Hex, start, end
|
25
|
-
|
24
|
+
if (isHex(value, { strict: false }))
|
25
|
+
return sliceHex(value as Hex, start, end, {
|
26
|
+
strict,
|
27
|
+
}) as SliceReturnType<TValue>
|
28
|
+
return sliceBytes(value as ByteArray, start, end, {
|
29
|
+
strict,
|
30
|
+
}) as SliceReturnType<TValue>
|
26
31
|
}
|
27
32
|
|
28
33
|
function assertStartOffset(value: Hex | ByteArray, start?: number) {
|
29
34
|
if (typeof start === 'number' && start > 0 && start > size(value) - 1)
|
30
|
-
throw new SliceOffsetOutOfBoundsError({
|
35
|
+
throw new SliceOffsetOutOfBoundsError({
|
36
|
+
offset: start,
|
37
|
+
position: 'start',
|
38
|
+
size: size(value),
|
39
|
+
})
|
40
|
+
}
|
41
|
+
|
42
|
+
function assertEndOffset(value: Hex | ByteArray, start?: number, end?: number) {
|
43
|
+
if (
|
44
|
+
typeof start === 'number' &&
|
45
|
+
typeof end === 'number' &&
|
46
|
+
size(value) !== end - start
|
47
|
+
) {
|
48
|
+
throw new SliceOffsetOutOfBoundsError({
|
49
|
+
offset: end,
|
50
|
+
position: 'end',
|
51
|
+
size: size(value),
|
52
|
+
})
|
53
|
+
}
|
31
54
|
}
|
32
55
|
|
33
56
|
/**
|
@@ -38,12 +61,15 @@ function assertStartOffset(value: Hex | ByteArray, start?: number) {
|
|
38
61
|
* @param end The end offset (in bytes).
|
39
62
|
*/
|
40
63
|
export function sliceBytes(
|
41
|
-
|
64
|
+
value_: ByteArray,
|
42
65
|
start?: number,
|
43
66
|
end?: number,
|
67
|
+
{ strict }: { strict?: boolean } = {},
|
44
68
|
): ByteArray {
|
45
|
-
assertStartOffset(
|
46
|
-
|
69
|
+
assertStartOffset(value_, start)
|
70
|
+
const value = value_.slice(start, end)
|
71
|
+
if (strict) assertEndOffset(value, start, end)
|
72
|
+
return value
|
47
73
|
}
|
48
74
|
|
49
75
|
/**
|
@@ -53,10 +79,16 @@ export function sliceBytes(
|
|
53
79
|
* @param start The start offset (in bytes).
|
54
80
|
* @param end The end offset (in bytes).
|
55
81
|
*/
|
56
|
-
export function sliceHex(
|
82
|
+
export function sliceHex(
|
83
|
+
value_: Hex,
|
84
|
+
start?: number,
|
85
|
+
end?: number,
|
86
|
+
{ strict }: { strict?: boolean } = {},
|
87
|
+
): Hex {
|
57
88
|
assertStartOffset(value_, start)
|
58
|
-
const value = value_
|
89
|
+
const value = `0x${value_
|
59
90
|
.replace('0x', '')
|
60
|
-
.slice((start ?? 0) * 2, (end ?? value_.length) * 2)
|
61
|
-
|
91
|
+
.slice((start ?? 0) * 2, (end ?? value_.length) * 2)}` as const
|
92
|
+
if (strict) assertEndOffset(value, start, end)
|
93
|
+
return value
|
62
94
|
}
|
package/src/utils/data/trim.ts
CHANGED
@@ -27,7 +27,9 @@ export function trim<TValue extends ByteArray | Hex>(
|
|
27
27
|
|
28
28
|
if (typeof hexOrBytes === 'string') {
|
29
29
|
if (data.length === 1 && dir === 'right') data = `${data}0`
|
30
|
-
return `0x${
|
30
|
+
return `0x${
|
31
|
+
data.length % 2 === 1 ? `0${data}` : data
|
32
|
+
}` as TrimReturnType<TValue>
|
31
33
|
}
|
32
34
|
return data as TrimReturnType<TValue>
|
33
35
|
}
|
@@ -140,7 +140,7 @@ export type HexToBoolOpts = {
|
|
140
140
|
*
|
141
141
|
* @example
|
142
142
|
* import { hexToBool } from 'viem'
|
143
|
-
* const data = hexToBool('
|
143
|
+
* const data = hexToBool('0x01')
|
144
144
|
* // true
|
145
145
|
*
|
146
146
|
* @example
|
@@ -154,8 +154,8 @@ export function hexToBool(hex_: Hex, opts: HexToBoolOpts = {}): boolean {
|
|
154
154
|
assertSize(hex, { size: opts.size })
|
155
155
|
hex = trim(hex)
|
156
156
|
}
|
157
|
-
if (trim(hex) === '
|
158
|
-
if (trim(hex) === '
|
157
|
+
if (trim(hex) === '0x00') return false
|
158
|
+
if (trim(hex) === '0x01') return true
|
159
159
|
throw new InvalidHexBooleanError(hex)
|
160
160
|
}
|
161
161
|
|
@@ -16,7 +16,9 @@ export function keccak256<TTo extends To = 'hex'>(
|
|
16
16
|
to_?: TTo,
|
17
17
|
): Keccak256Hash<TTo> {
|
18
18
|
const to = to_ || 'hex'
|
19
|
-
const bytes = keccak_256(
|
19
|
+
const bytes = keccak_256(
|
20
|
+
isHex(value, { strict: false }) ? toBytes(value) : value,
|
21
|
+
)
|
20
22
|
if (to === 'bytes') return bytes as Keccak256Hash<TTo>
|
21
23
|
return toHex(bytes) as Keccak256Hash<TTo>
|
22
24
|
}
|