voltaire-effect 0.3.0 → 1.0.1

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 (88) hide show
  1. package/dist/{X25519Test-D5Q-5fL9.d.ts → X25519Test-avt1DUgp.d.ts} +231 -6
  2. package/dist/crypto/index.d.ts +2 -2
  3. package/dist/crypto/index.js +72 -2
  4. package/dist/{index-3UKSP3cd.d.ts → index-DxwZo3xo.d.ts} +7781 -5513
  5. package/dist/index.d.ts +990 -3096
  6. package/dist/index.js +2374 -1652
  7. package/dist/native/index.d.ts +6 -6
  8. package/dist/native/index.js +2399 -1677
  9. package/dist/primitives/index.d.ts +7 -6
  10. package/dist/primitives/index.js +2966 -2361
  11. package/dist/services/index.d.ts +1631 -1255
  12. package/dist/services/index.js +4493 -3977
  13. package/package.json +7 -3
  14. package/src/crypto/Signers/SignersService.ts +1 -1
  15. package/src/crypto/Signers/errors.ts +29 -0
  16. package/src/crypto/Signers/index.ts +1 -0
  17. package/src/crypto/Signers/operations.ts +26 -8
  18. package/src/crypto/index.ts +10 -11
  19. package/src/index.ts +1 -2
  20. package/src/jsonrpc/Anvil.ts +13 -8
  21. package/src/jsonrpc/Eth.ts +13 -8
  22. package/src/jsonrpc/Hardhat.ts +13 -8
  23. package/src/jsonrpc/IdCounter.ts +21 -5
  24. package/src/jsonrpc/JsonRpc.test.ts +126 -61
  25. package/src/jsonrpc/Net.ts +13 -8
  26. package/src/jsonrpc/Request.ts +16 -8
  27. package/src/jsonrpc/Txpool.ts +13 -8
  28. package/src/jsonrpc/Wallet.ts +13 -8
  29. package/src/jsonrpc/Web3.ts +13 -8
  30. package/src/jsonrpc/index.ts +1 -1
  31. package/src/primitives/Abi/AbiSchema.ts +3 -4
  32. package/src/primitives/Abi/fromBytecode.test.ts +47 -0
  33. package/src/primitives/Abi/fromBytecode.ts +81 -0
  34. package/src/primitives/Abi/index.ts +3 -0
  35. package/src/primitives/AccessList/from.ts +12 -9
  36. package/src/primitives/Address/Checksummed.ts +21 -27
  37. package/src/primitives/Address/from.ts +12 -15
  38. package/src/primitives/Address/toHex.ts +2 -1
  39. package/src/primitives/Base64/from.ts +21 -4
  40. package/src/primitives/Blob/from.ts +12 -4
  41. package/src/primitives/BlockHash/index.ts +2 -2
  42. package/src/primitives/BlockNumber/index.ts +3 -3
  43. package/src/primitives/Bytecode/from.ts +11 -2
  44. package/src/primitives/ContractSignature/verifySignature.ts +3 -5
  45. package/src/primitives/Ens/from.ts +12 -11
  46. package/src/primitives/Hex/from.ts +12 -4
  47. package/src/primitives/Signature/from.ts +11 -2
  48. package/src/primitives/Transaction/EIP2930/index.ts +12 -12
  49. package/src/primitives/Transaction/EIP4844/index.ts +14 -14
  50. package/src/primitives/Transaction/EIP7702/index.ts +13 -13
  51. package/src/primitives/Transaction/Legacy/index.ts +13 -13
  52. package/src/primitives/TransactionHash/index.ts +3 -2
  53. package/src/primitives/TransactionIndex/index.ts +2 -2
  54. package/src/primitives/Trie/Trie.test.ts +70 -0
  55. package/src/primitives/Trie/TrieSchema.ts +26 -0
  56. package/src/primitives/Trie/clear.ts +16 -0
  57. package/src/primitives/Trie/del.ts +18 -0
  58. package/src/primitives/Trie/get.ts +18 -0
  59. package/src/primitives/Trie/index.ts +30 -0
  60. package/src/primitives/Trie/init.ts +13 -0
  61. package/src/primitives/Trie/prove.ts +19 -0
  62. package/src/primitives/Trie/put.ts +20 -0
  63. package/src/primitives/Trie/rootHash.ts +14 -0
  64. package/src/primitives/Trie/verify.ts +18 -0
  65. package/src/primitives/Uint/from.ts +11 -2
  66. package/src/primitives/Uint16/index.ts +5 -4
  67. package/src/primitives/Uint64/index.ts +5 -4
  68. package/src/primitives/Uint8/index.ts +5 -4
  69. package/src/primitives/index.ts +3 -2
  70. package/src/services/BlockExplorerApi/BlockExplorerApi.test.ts +789 -0
  71. package/src/services/BlockExplorerApi/BlockExplorerApi.ts +797 -0
  72. package/src/services/BlockExplorerApi/BlockExplorerApiErrors.ts +176 -0
  73. package/src/services/BlockExplorerApi/BlockExplorerApiService.ts +60 -0
  74. package/src/services/BlockExplorerApi/BlockExplorerApiTypes.ts +225 -0
  75. package/src/services/BlockExplorerApi/index.ts +42 -0
  76. package/src/services/Contract/Contract.test.ts +2 -6
  77. package/src/services/Contract/ContractTypes.ts +26 -8
  78. package/src/services/Contract/estimateGas.test.ts +4 -7
  79. package/src/services/Provider/actions/multicall.ts +28 -9
  80. package/src/services/Provider/actions/readContract.test.ts +8 -11
  81. package/src/services/Provider/actions/readContract.ts +28 -9
  82. package/src/services/Provider/functions/getBlock.ts +2 -1
  83. package/src/services/Provider/functions/getBlockReceipts.ts +2 -1
  84. package/src/services/Provider/functions/getBlockTransactionCount.ts +2 -1
  85. package/src/services/Provider/functions/getUncle.ts +2 -1
  86. package/src/services/Provider/functions/getUncleCount.ts +2 -1
  87. package/src/services/Signer/actions/deployContract.ts +1 -1
  88. package/src/services/index.ts +25 -0
@@ -10,7 +10,6 @@ import {
10
10
  BrandedAbi,
11
11
  type Abi as BrandedAbiType,
12
12
  type BrandedAddress,
13
- type BrandedHex,
14
13
  Hex,
15
14
  } from "@tevm/voltaire";
16
15
  import * as Effect from "effect/Effect";
@@ -26,7 +25,6 @@ import { call } from "../functions/call.js";
26
25
  import type { Abi } from "./readContract.js";
27
26
 
28
27
  type AddressType = BrandedAddress.AddressType;
29
- type HexType = BrandedHex.HexType;
30
28
 
31
29
  /**
32
30
  * Extracts function names from an ABI.
@@ -58,20 +56,41 @@ type GetFunctionInputs<
58
56
  * Maps ABI input types to TypeScript types.
59
57
  */
60
58
  type AbiInputsToArgs<TInputs extends readonly { type: string }[]> = {
61
- [K in keyof TInputs]: AbiTypeToTS<TInputs[K]["type"]>;
59
+ [K in keyof TInputs]: AbiTypeToInput<TInputs[K]["type"]>;
62
60
  };
63
61
 
64
62
  /**
65
- * Maps a single ABI type to TypeScript type.
63
+ * Maps a single ABI type to TypeScript input type.
66
64
  */
67
- type AbiTypeToTS<T extends string> = T extends `uint${string}` | `int${string}`
65
+ type BytesInput = Uint8Array | `0x${string}`;
66
+
67
+ type AbiTypeToInput<T extends string> = T extends `uint${string}` | `int${string}`
68
+ ? bigint
69
+ : T extends "address"
70
+ ? AddressType | `0x${string}`
71
+ : T extends "bool"
72
+ ? boolean
73
+ : T extends `bytes${string}` | "bytes"
74
+ ? BytesInput
75
+ : T extends "string"
76
+ ? string
77
+ : T extends `${string}[]`
78
+ ? readonly unknown[]
79
+ : T extends `(${string})`
80
+ ? readonly unknown[]
81
+ : unknown;
82
+
83
+ /**
84
+ * Maps a single ABI type to TypeScript output type.
85
+ */
86
+ type AbiTypeToOutput<T extends string> = T extends `uint${string}` | `int${string}`
68
87
  ? bigint
69
88
  : T extends "address"
70
89
  ? AddressType | `0x${string}`
71
90
  : T extends "bool"
72
91
  ? boolean
73
- : T extends `bytes${string}`
74
- ? HexType | `0x${string}`
92
+ : T extends `bytes${string}` | "bytes"
93
+ ? Uint8Array
75
94
  : T extends "string"
76
95
  ? string
77
96
  : T extends `${string}[]`
@@ -96,9 +115,9 @@ type GetFunctionOutput<
96
115
  ? Outputs["length"] extends 0
97
116
  ? undefined
98
117
  : Outputs["length"] extends 1
99
- ? AbiTypeToTS<Outputs[0]["type"]>
118
+ ? AbiTypeToOutput<Outputs[0]["type"]>
100
119
  : {
101
- [K in keyof Outputs]: AbiTypeToTS<
120
+ [K in keyof Outputs]: AbiTypeToOutput<
102
121
  Outputs[K] extends { type: string } ? Outputs[K]["type"] : never
103
122
  >;
104
123
  }
@@ -1,17 +1,14 @@
1
- // @ts-nocheck - TODO: Fix ABI type inference issues
2
1
  import { beforeEach, describe, expect, it, vi } from "@effect/vitest";
3
2
  import { Address } from "@tevm/voltaire";
4
3
  import * as Effect from "effect/Effect";
5
4
  import * as Layer from "effect/Layer";
6
- import * as S from "effect/Schema";
7
- import { fromArray } from "../../../primitives/Abi/AbiSchema.js";
8
5
  import { TransportError } from "../../Transport/TransportService.js";
9
6
  import { ProviderService } from "../ProviderService.js";
10
7
  import { readContract } from "./readContract.js";
11
8
 
12
9
  type HexType = `0x${string}`;
13
10
 
14
- const erc20Abi = S.decodeUnknownSync(fromArray)([
11
+ const erc20Abi = [
15
12
  {
16
13
  type: "function",
17
14
  name: "balanceOf",
@@ -50,9 +47,9 @@ const erc20Abi = S.decodeUnknownSync(fromArray)([
50
47
  ],
51
48
  outputs: [{ name: "", type: "uint256" }],
52
49
  },
53
- ]);
50
+ ] as const;
54
51
 
55
- const pairAbi = S.decodeUnknownSync(fromArray)([
52
+ const pairAbi = [
56
53
  {
57
54
  type: "function",
58
55
  name: "getReserves",
@@ -71,9 +68,9 @@ const pairAbi = S.decodeUnknownSync(fromArray)([
71
68
  inputs: [],
72
69
  outputs: [{ name: "", type: "address" }],
73
70
  },
74
- ]);
71
+ ] as const;
75
72
 
76
- const extendedAbi = S.decodeUnknownSync(fromArray)([
73
+ const extendedAbi = [
77
74
  {
78
75
  type: "function",
79
76
  name: "owner",
@@ -127,9 +124,9 @@ const extendedAbi = S.decodeUnknownSync(fromArray)([
127
124
  inputs: [{ name: "data", type: "bytes" }],
128
125
  outputs: [],
129
126
  },
130
- ]);
127
+ ] as const;
131
128
 
132
- const complexAbi = S.decodeUnknownSync(fromArray)([
129
+ const complexAbi = [
133
130
  {
134
131
  type: "function",
135
132
  name: "getPositions",
@@ -153,7 +150,7 @@ const complexAbi = S.decodeUnknownSync(fromArray)([
153
150
  { name: "nonce", type: "uint256" },
154
151
  ],
155
152
  },
156
- ]);
153
+ ] as const;
157
154
 
158
155
  const mockCallFn = vi.fn();
159
156
 
@@ -18,7 +18,6 @@ import {
18
18
  BrandedAbi,
19
19
  type Abi as BrandedAbiType,
20
20
  type BrandedAddress,
21
- type BrandedHex,
22
21
  Hex,
23
22
  } from "@tevm/voltaire";
24
23
  import * as Effect from "effect/Effect";
@@ -32,7 +31,6 @@ import {
32
31
  } from "../ProviderService.js";
33
32
 
34
33
  type AddressType = BrandedAddress.AddressType;
35
- type HexType = BrandedHex.HexType;
36
34
 
37
35
  /**
38
36
  * Represents a single ABI item.
@@ -88,20 +86,41 @@ type GetFunctionInputs<
88
86
  * Maps ABI input types to TypeScript types.
89
87
  */
90
88
  type AbiInputsToArgs<TInputs extends readonly { type: string }[]> = {
91
- [K in keyof TInputs]: AbiTypeToTS<TInputs[K]["type"]>;
89
+ [K in keyof TInputs]: AbiTypeToInput<TInputs[K]["type"]>;
92
90
  };
93
91
 
94
92
  /**
95
- * Maps a single ABI type to TypeScript type.
93
+ * Maps a single ABI type to TypeScript input type.
96
94
  */
97
- type AbiTypeToTS<T extends string> = T extends `uint${string}` | `int${string}`
95
+ type BytesInput = Uint8Array | `0x${string}`;
96
+
97
+ type AbiTypeToInput<T extends string> = T extends `uint${string}` | `int${string}`
98
+ ? bigint
99
+ : T extends "address"
100
+ ? AddressType | `0x${string}`
101
+ : T extends "bool"
102
+ ? boolean
103
+ : T extends `bytes${string}` | "bytes"
104
+ ? BytesInput
105
+ : T extends "string"
106
+ ? string
107
+ : T extends `${string}[]`
108
+ ? readonly unknown[]
109
+ : T extends `(${string})`
110
+ ? readonly unknown[]
111
+ : unknown;
112
+
113
+ /**
114
+ * Maps a single ABI type to TypeScript output type.
115
+ */
116
+ type AbiTypeToOutput<T extends string> = T extends `uint${string}` | `int${string}`
98
117
  ? bigint
99
118
  : T extends "address"
100
119
  ? AddressType | `0x${string}`
101
120
  : T extends "bool"
102
121
  ? boolean
103
- : T extends `bytes${string}`
104
- ? HexType | `0x${string}`
122
+ : T extends `bytes${string}` | "bytes"
123
+ ? Uint8Array
105
124
  : T extends "string"
106
125
  ? string
107
126
  : T extends `${string}[]`
@@ -126,9 +145,9 @@ type GetFunctionOutput<
126
145
  ? Outputs["length"] extends 0
127
146
  ? undefined
128
147
  : Outputs["length"] extends 1
129
- ? AbiTypeToTS<Outputs[0]["type"]>
148
+ ? AbiTypeToOutput<Outputs[0]["type"]>
130
149
  : {
131
- [K in keyof Outputs]: AbiTypeToTS<
150
+ [K in keyof Outputs]: AbiTypeToOutput<
132
151
  Outputs[K] extends { type: string } ? Outputs[K]["type"] : never
133
152
  >;
134
153
  }
@@ -5,6 +5,7 @@
5
5
  * @since 0.4.0
6
6
  */
7
7
 
8
+ import { Hex } from "@tevm/voltaire";
8
9
  import * as Effect from "effect/Effect";
9
10
  import { ProviderService } from "../ProviderService.js";
10
11
  import {
@@ -56,7 +57,7 @@ export const getBlock = (
56
57
  const hash =
57
58
  typeof args.blockHash === "string"
58
59
  ? args.blockHash
59
- : `0x${Buffer.from(args.blockHash).toString("hex")}`;
60
+ : Hex(args.blockHash);
60
61
  return svc
61
62
  .request<BlockType | null>("eth_getBlockByHash", [hash, includeTransactions])
62
63
  .pipe(
@@ -5,6 +5,7 @@
5
5
  * @since 0.4.0
6
6
  */
7
7
 
8
+ import { Hex } from "@tevm/voltaire";
8
9
  import * as Effect from "effect/Effect";
9
10
  import { ProviderService } from "../ProviderService.js";
10
11
  import {
@@ -57,7 +58,7 @@ export const getBlockReceipts = (
57
58
  blockId =
58
59
  typeof args.blockHash === "string"
59
60
  ? args.blockHash
60
- : `0x${Buffer.from(args.blockHash).toString("hex")}`;
61
+ : Hex(args.blockHash);
61
62
  } else if ("blockNumber" in args && args.blockNumber !== undefined) {
62
63
  blockId = `0x${args.blockNumber.toString(16)}`;
63
64
  } else {
@@ -5,6 +5,7 @@
5
5
  * @since 0.4.0
6
6
  */
7
7
 
8
+ import { Hex } from "@tevm/voltaire";
8
9
  import * as Effect from "effect/Effect";
9
10
  import { ProviderService } from "../ProviderService.js";
10
11
  import {
@@ -49,7 +50,7 @@ export const getBlockTransactionCount = (
49
50
  const hash =
50
51
  typeof args.blockHash === "string"
51
52
  ? args.blockHash
52
- : `0x${Buffer.from(args.blockHash).toString("hex")}`;
53
+ : Hex(args.blockHash);
53
54
  return svc
54
55
  .request<string>("eth_getBlockTransactionCountByHash", [hash])
55
56
  .pipe(
@@ -5,6 +5,7 @@
5
5
  * @since 0.4.0
6
6
  */
7
7
 
8
+ import { Hex } from "@tevm/voltaire";
8
9
  import * as Effect from "effect/Effect";
9
10
  import { ProviderService } from "../ProviderService.js";
10
11
  import {
@@ -54,7 +55,7 @@ export const getUncle = (
54
55
  const hash =
55
56
  typeof args.blockHash === "string"
56
57
  ? args.blockHash
57
- : `0x${Buffer.from(args.blockHash).toString("hex")}`;
58
+ : Hex(args.blockHash);
58
59
  return svc
59
60
  .request<UncleBlockType | null>("eth_getUncleByBlockHashAndIndex", [
60
61
  hash,
@@ -5,6 +5,7 @@
5
5
  * @since 0.4.0
6
6
  */
7
7
 
8
+ import { Hex } from "@tevm/voltaire";
8
9
  import * as Effect from "effect/Effect";
9
10
  import { ProviderService } from "../ProviderService.js";
10
11
  import {
@@ -49,7 +50,7 @@ export const getUncleCount = (
49
50
  const hash =
50
51
  typeof args.blockHash === "string"
51
52
  ? args.blockHash
52
- : `0x${Buffer.from(args.blockHash).toString("hex")}`;
53
+ : Hex(args.blockHash);
53
54
  return svc
54
55
  .request<string>("eth_getUncleCountByBlockHash", [hash])
55
56
  .pipe(
@@ -152,7 +152,7 @@ export const deployContract = <TAbi extends Abi>(
152
152
  WaitForTransactionReceiptError,
153
153
  ProviderService
154
154
  > = Effect.gen(function* () {
155
- const hashHex = `0x${Buffer.from(hash).toString("hex")}` as `0x${string}`;
155
+ const hashHex = Hex(hash) as `0x${string}`;
156
156
  const receipt = yield* waitForTransactionReceipt(hashHex);
157
157
  if (!receipt.contractAddress) {
158
158
  return yield* Effect.fail(
@@ -95,6 +95,31 @@ export {
95
95
  type AbiEncoderShape,
96
96
  DefaultAbiEncoder,
97
97
  } from "./AbiEncoder/index.js";
98
+ // BlockExplorerApi exports
99
+ export {
100
+ BlockExplorerApi,
101
+ BlockExplorerApiService,
102
+ type BlockExplorerApiShape,
103
+ type BlockExplorerApiConfig,
104
+ type BlockExplorerApiError,
105
+ BlockExplorerConfigError,
106
+ BlockExplorerDecodeError,
107
+ BlockExplorerNotFoundError,
108
+ BlockExplorerProxyResolutionError,
109
+ BlockExplorerRateLimitError,
110
+ BlockExplorerResponseError,
111
+ BlockExplorerUnexpectedError,
112
+ type ExplorerContractInstance,
113
+ type ExplorerSourceId,
114
+ type ResolvedExplorerContract,
115
+ type AbiItem as ExplorerAbiItem,
116
+ type AbiResolution,
117
+ type ContractSourceFile,
118
+ type GetAbiOptions,
119
+ type GetContractOptions,
120
+ type GetSourcesOptions,
121
+ type ProxyInfo,
122
+ } from "./BlockExplorerApi/index.js";
98
123
  // Account exports
99
124
  export {
100
125
  AccountError,