@alchemy/common 0.0.0-alpha.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.
Files changed (212) hide show
  1. package/LICENSE +21 -0
  2. package/dist/esm/actions/addBreadCrumb.d.ts +14 -0
  3. package/dist/esm/actions/addBreadCrumb.js +27 -0
  4. package/dist/esm/actions/addBreadCrumb.js.map +1 -0
  5. package/dist/esm/chains.d.ts +234 -0
  6. package/dist/esm/chains.js +113 -0
  7. package/dist/esm/chains.js.map +1 -0
  8. package/dist/esm/errors/AccountNotFoundError.d.ts +10 -0
  9. package/dist/esm/errors/AccountNotFoundError.js +19 -0
  10. package/dist/esm/errors/AccountNotFoundError.js.map +1 -0
  11. package/dist/esm/errors/BaseError.d.ts +23 -0
  12. package/dist/esm/errors/BaseError.js +40 -0
  13. package/dist/esm/errors/BaseError.js.map +1 -0
  14. package/dist/esm/errors/ChainNotFoundError.d.ts +11 -0
  15. package/dist/esm/errors/ChainNotFoundError.js +19 -0
  16. package/dist/esm/errors/ChainNotFoundError.js.map +1 -0
  17. package/dist/esm/errors/ConnectionConfigError.d.ts +13 -0
  18. package/dist/esm/errors/ConnectionConfigError.js +25 -0
  19. package/dist/esm/errors/ConnectionConfigError.js.map +1 -0
  20. package/dist/esm/errors/FetchError.d.ts +15 -0
  21. package/dist/esm/errors/FetchError.js +25 -0
  22. package/dist/esm/errors/FetchError.js.map +1 -0
  23. package/dist/esm/errors/InvalidRequestError.d.ts +13 -0
  24. package/dist/esm/errors/InvalidRequestError.js +22 -0
  25. package/dist/esm/errors/InvalidRequestError.js.map +1 -0
  26. package/dist/esm/errors/MethodUnsupportedError.d.ts +13 -0
  27. package/dist/esm/errors/MethodUnsupportedError.js +21 -0
  28. package/dist/esm/errors/MethodUnsupportedError.js.map +1 -0
  29. package/dist/esm/errors/ServerError.d.ts +15 -0
  30. package/dist/esm/errors/ServerError.js +25 -0
  31. package/dist/esm/errors/ServerError.js.map +1 -0
  32. package/dist/esm/index.d.ts +29 -0
  33. package/dist/esm/index.js +27 -0
  34. package/dist/esm/index.js.map +1 -0
  35. package/dist/esm/logging/config.d.ts +190 -0
  36. package/dist/esm/logging/config.js +279 -0
  37. package/dist/esm/logging/config.js.map +1 -0
  38. package/dist/esm/logging/index.d.ts +6 -0
  39. package/dist/esm/logging/index.js +5 -0
  40. package/dist/esm/logging/index.js.map +1 -0
  41. package/dist/esm/logging/local.d.ts +10 -0
  42. package/dist/esm/logging/local.js +35 -0
  43. package/dist/esm/logging/local.js.map +1 -0
  44. package/dist/esm/logging/logger.d.ts +80 -0
  45. package/dist/esm/logging/logger.js +111 -0
  46. package/dist/esm/logging/logger.js.map +1 -0
  47. package/dist/esm/logging/noop.d.ts +6 -0
  48. package/dist/esm/logging/noop.js +12 -0
  49. package/dist/esm/logging/noop.js.map +1 -0
  50. package/dist/esm/logging/sinks.d.ts +90 -0
  51. package/dist/esm/logging/sinks.js +111 -0
  52. package/dist/esm/logging/sinks.js.map +1 -0
  53. package/dist/esm/logging/types.d.ts +96 -0
  54. package/dist/esm/logging/types.js +2 -0
  55. package/dist/esm/logging/types.js.map +1 -0
  56. package/dist/esm/logging/utils.d.ts +7 -0
  57. package/dist/esm/logging/utils.js +21 -0
  58. package/dist/esm/logging/utils.js.map +1 -0
  59. package/dist/esm/rest/restClient.d.ts +34 -0
  60. package/dist/esm/rest/restClient.js +55 -0
  61. package/dist/esm/rest/restClient.js.map +1 -0
  62. package/dist/esm/rest/types.d.ts +24 -0
  63. package/dist/esm/rest/types.js +2 -0
  64. package/dist/esm/rest/types.js.map +1 -0
  65. package/dist/esm/tracing/traceHeader.d.ts +82 -0
  66. package/dist/esm/tracing/traceHeader.js +145 -0
  67. package/dist/esm/tracing/traceHeader.js.map +1 -0
  68. package/dist/esm/tracing/updateHeaders.d.ts +24 -0
  69. package/dist/esm/tracing/updateHeaders.js +61 -0
  70. package/dist/esm/tracing/updateHeaders.js.map +1 -0
  71. package/dist/esm/transport/alchemy.d.ts +110 -0
  72. package/dist/esm/transport/alchemy.js +164 -0
  73. package/dist/esm/transport/alchemy.js.map +1 -0
  74. package/dist/esm/transport/chainRegistry.d.ts +31 -0
  75. package/dist/esm/transport/chainRegistry.js +95 -0
  76. package/dist/esm/transport/chainRegistry.js.map +1 -0
  77. package/dist/esm/transport/connection.d.ts +20 -0
  78. package/dist/esm/transport/connection.js +2 -0
  79. package/dist/esm/transport/connection.js.map +1 -0
  80. package/dist/esm/transport/connectionSchema.d.ts +124 -0
  81. package/dist/esm/transport/connectionSchema.js +121 -0
  82. package/dist/esm/transport/connectionSchema.js.map +1 -0
  83. package/dist/esm/utils/assertNever.d.ts +8 -0
  84. package/dist/esm/utils/assertNever.js +12 -0
  85. package/dist/esm/utils/assertNever.js.map +1 -0
  86. package/dist/esm/utils/bigint.d.ts +24 -0
  87. package/dist/esm/utils/bigint.js +37 -0
  88. package/dist/esm/utils/bigint.js.map +1 -0
  89. package/dist/esm/utils/createEip1193HandlerFactory.d.ts +18 -0
  90. package/dist/esm/utils/createEip1193HandlerFactory.js +11 -0
  91. package/dist/esm/utils/createEip1193HandlerFactory.js.map +1 -0
  92. package/dist/esm/utils/headers.d.ts +7 -0
  93. package/dist/esm/utils/headers.js +29 -0
  94. package/dist/esm/utils/headers.js.map +1 -0
  95. package/dist/esm/utils/lowerAddress.d.ts +8 -0
  96. package/dist/esm/utils/lowerAddress.js +9 -0
  97. package/dist/esm/utils/lowerAddress.js.map +1 -0
  98. package/dist/esm/utils/raise.d.ts +8 -0
  99. package/dist/esm/utils/raise.js +14 -0
  100. package/dist/esm/utils/raise.js.map +1 -0
  101. package/dist/esm/utils/types.d.ts +10 -0
  102. package/dist/esm/utils/types.js +2 -0
  103. package/dist/esm/utils/types.js.map +1 -0
  104. package/dist/esm/version.d.ts +1 -0
  105. package/dist/esm/version.js +4 -0
  106. package/dist/esm/version.js.map +1 -0
  107. package/dist/types/actions/addBreadCrumb.d.ts +15 -0
  108. package/dist/types/actions/addBreadCrumb.d.ts.map +1 -0
  109. package/dist/types/chains.d.ts +235 -0
  110. package/dist/types/chains.d.ts.map +1 -0
  111. package/dist/types/errors/AccountNotFoundError.d.ts +11 -0
  112. package/dist/types/errors/AccountNotFoundError.d.ts.map +1 -0
  113. package/dist/types/errors/BaseError.d.ts +24 -0
  114. package/dist/types/errors/BaseError.d.ts.map +1 -0
  115. package/dist/types/errors/ChainNotFoundError.d.ts +12 -0
  116. package/dist/types/errors/ChainNotFoundError.d.ts.map +1 -0
  117. package/dist/types/errors/ConnectionConfigError.d.ts +14 -0
  118. package/dist/types/errors/ConnectionConfigError.d.ts.map +1 -0
  119. package/dist/types/errors/FetchError.d.ts +16 -0
  120. package/dist/types/errors/FetchError.d.ts.map +1 -0
  121. package/dist/types/errors/InvalidRequestError.d.ts +14 -0
  122. package/dist/types/errors/InvalidRequestError.d.ts.map +1 -0
  123. package/dist/types/errors/MethodUnsupportedError.d.ts +14 -0
  124. package/dist/types/errors/MethodUnsupportedError.d.ts.map +1 -0
  125. package/dist/types/errors/ServerError.d.ts +16 -0
  126. package/dist/types/errors/ServerError.d.ts.map +1 -0
  127. package/dist/types/index.d.ts +30 -0
  128. package/dist/types/index.d.ts.map +1 -0
  129. package/dist/types/logging/config.d.ts +191 -0
  130. package/dist/types/logging/config.d.ts.map +1 -0
  131. package/dist/types/logging/index.d.ts +7 -0
  132. package/dist/types/logging/index.d.ts.map +1 -0
  133. package/dist/types/logging/local.d.ts +11 -0
  134. package/dist/types/logging/local.d.ts.map +1 -0
  135. package/dist/types/logging/logger.d.ts +81 -0
  136. package/dist/types/logging/logger.d.ts.map +1 -0
  137. package/dist/types/logging/noop.d.ts +7 -0
  138. package/dist/types/logging/noop.d.ts.map +1 -0
  139. package/dist/types/logging/sinks.d.ts +91 -0
  140. package/dist/types/logging/sinks.d.ts.map +1 -0
  141. package/dist/types/logging/types.d.ts +97 -0
  142. package/dist/types/logging/types.d.ts.map +1 -0
  143. package/dist/types/logging/utils.d.ts +8 -0
  144. package/dist/types/logging/utils.d.ts.map +1 -0
  145. package/dist/types/rest/restClient.d.ts +35 -0
  146. package/dist/types/rest/restClient.d.ts.map +1 -0
  147. package/dist/types/rest/types.d.ts +25 -0
  148. package/dist/types/rest/types.d.ts.map +1 -0
  149. package/dist/types/tracing/traceHeader.d.ts +83 -0
  150. package/dist/types/tracing/traceHeader.d.ts.map +1 -0
  151. package/dist/types/tracing/updateHeaders.d.ts +25 -0
  152. package/dist/types/tracing/updateHeaders.d.ts.map +1 -0
  153. package/dist/types/transport/alchemy.d.ts +111 -0
  154. package/dist/types/transport/alchemy.d.ts.map +1 -0
  155. package/dist/types/transport/chainRegistry.d.ts +32 -0
  156. package/dist/types/transport/chainRegistry.d.ts.map +1 -0
  157. package/dist/types/transport/connection.d.ts +21 -0
  158. package/dist/types/transport/connection.d.ts.map +1 -0
  159. package/dist/types/transport/connectionSchema.d.ts +125 -0
  160. package/dist/types/transport/connectionSchema.d.ts.map +1 -0
  161. package/dist/types/utils/assertNever.d.ts +9 -0
  162. package/dist/types/utils/assertNever.d.ts.map +1 -0
  163. package/dist/types/utils/bigint.d.ts +25 -0
  164. package/dist/types/utils/bigint.d.ts.map +1 -0
  165. package/dist/types/utils/createEip1193HandlerFactory.d.ts +19 -0
  166. package/dist/types/utils/createEip1193HandlerFactory.d.ts.map +1 -0
  167. package/dist/types/utils/headers.d.ts +8 -0
  168. package/dist/types/utils/headers.d.ts.map +1 -0
  169. package/dist/types/utils/lowerAddress.d.ts +9 -0
  170. package/dist/types/utils/lowerAddress.d.ts.map +1 -0
  171. package/dist/types/utils/raise.d.ts +9 -0
  172. package/dist/types/utils/raise.d.ts.map +1 -0
  173. package/dist/types/utils/types.d.ts +11 -0
  174. package/dist/types/utils/types.d.ts.map +1 -0
  175. package/dist/types/version.d.ts +2 -0
  176. package/dist/types/version.d.ts.map +1 -0
  177. package/package.json +67 -0
  178. package/src/actions/addBreadCrumb.ts +38 -0
  179. package/src/chains.ts +118 -0
  180. package/src/errors/AccountNotFoundError.ts +16 -0
  181. package/src/errors/BaseError.ts +51 -0
  182. package/src/errors/ChainNotFoundError.ts +15 -0
  183. package/src/errors/ConnectionConfigError.ts +22 -0
  184. package/src/errors/FetchError.ts +21 -0
  185. package/src/errors/InvalidRequestError.ts +19 -0
  186. package/src/errors/MethodUnsupportedError.ts +17 -0
  187. package/src/errors/ServerError.ts +21 -0
  188. package/src/index.ts +60 -0
  189. package/src/logging/config.ts +365 -0
  190. package/src/logging/index.ts +20 -0
  191. package/src/logging/local.ts +39 -0
  192. package/src/logging/logger.ts +194 -0
  193. package/src/logging/noop.ts +13 -0
  194. package/src/logging/sinks.ts +115 -0
  195. package/src/logging/types.ts +111 -0
  196. package/src/logging/utils.ts +31 -0
  197. package/src/rest/restClient.ts +64 -0
  198. package/src/rest/types.ts +42 -0
  199. package/src/tracing/traceHeader.ts +154 -0
  200. package/src/tracing/updateHeaders.ts +66 -0
  201. package/src/transport/alchemy.ts +242 -0
  202. package/src/transport/chainRegistry.ts +115 -0
  203. package/src/transport/connection.ts +19 -0
  204. package/src/transport/connectionSchema.ts +145 -0
  205. package/src/utils/assertNever.ts +12 -0
  206. package/src/utils/bigint.ts +58 -0
  207. package/src/utils/createEip1193HandlerFactory.ts +25 -0
  208. package/src/utils/headers.ts +48 -0
  209. package/src/utils/lowerAddress.ts +10 -0
  210. package/src/utils/raise.ts +14 -0
  211. package/src/utils/types.ts +14 -0
  212. package/src/version.ts +3 -0
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Internal registry mapping chain IDs to Alchemy RPC base URLs.
3
+ * This replaces the need for custom chain exports with embedded Alchemy URLs.
4
+ */
5
+ export const ALCHEMY_RPC_MAPPING = {
6
+ // Ethereum networks
7
+ 1: "https://eth-mainnet.g.alchemy.com/v2", // mainnet
8
+ 11155111: "https://eth-sepolia.g.alchemy.com/v2", // sepolia
9
+ 5: "https://eth-goerli.g.alchemy.com/v2", // goerli
10
+ // Arbitrum networks
11
+ 42161: "https://arb-mainnet.g.alchemy.com/v2", // arbitrum
12
+ 421613: "https://arb-goerli.g.alchemy.com/v2", // arbitrumGoerli
13
+ 421614: "https://arb-sepolia.g.alchemy.com/v2", // arbitrumSepolia
14
+ // Optimism networks
15
+ 10: "https://opt-mainnet.g.alchemy.com/v2", // optimism
16
+ 420: "https://opt-goerli.g.alchemy.com/v2", // optimismGoerli
17
+ 11155420: "https://opt-sepolia.g.alchemy.com/v2", // optimismSepolia
18
+ // Base networks
19
+ 8453: "https://base-mainnet.g.alchemy.com/v2", // base
20
+ 84531: "https://base-goerli.g.alchemy.com/v2", // baseGoerli
21
+ 84532: "https://base-sepolia.g.alchemy.com/v2", // baseSepolia
22
+ // Polygon networks
23
+ 137: "https://polygon-mainnet.g.alchemy.com/v2", // polygon
24
+ 80001: "https://polygon-mumbai.g.alchemy.com/v2", // polygonMumbai
25
+ 80002: "https://polygon-amoy.g.alchemy.com/v2", // polygonAmoy
26
+ // World Chain networks
27
+ 480: "https://worldchain-mainnet.g.alchemy.com/v2", // worldChain
28
+ 4801: "https://worldchain-sepolia.g.alchemy.com/v2", // worldChainSepolia
29
+ // Shape networks
30
+ 360: "https://shape-mainnet.g.alchemy.com/v2", // shape
31
+ 11011: "https://shape-sepolia.g.alchemy.com/v2", // shapeSepolia
32
+ // Unichain networks
33
+ 130: "https://unichain-mainnet.g.alchemy.com/v2", // unichainMainnet
34
+ 1301: "https://unichain-sepolia.g.alchemy.com/v2", // unichainSepolia
35
+ // Soneium networks
36
+ 1868: "https://soneium-mainnet.g.alchemy.com/v2", // soneiumMainnet
37
+ 1946: "https://soneium-minato.g.alchemy.com/v2", // soneiumMinato
38
+ // OPBNB networks
39
+ 204: "https://opbnb-mainnet.g.alchemy.com/v2", // opbnbMainnet
40
+ 5611: "https://opbnb-testnet.g.alchemy.com/v2", // opbnbTestnet
41
+ // BeraChain networks
42
+ 80084: "https://berachain-bartio.g.alchemy.com/v2", // beraChainBartio
43
+ // Ink networks
44
+ 57073: "https://ink-mainnet.g.alchemy.com/v2", // inkMainnet
45
+ 763373: "https://ink-sepolia.g.alchemy.com/v2", // inkSepolia
46
+ // Monad networks
47
+ 10143: "https://monad-testnet.g.alchemy.com/v2", // monadTestnet
48
+ // Openloot networks
49
+ 905905: "https://openloot-sepolia.g.alchemy.com/v2", // openlootSepolia
50
+ // Gensyn networks
51
+ 685685: "https://gensyn-testnet.g.alchemy.com/v2", // gensynTestnet
52
+ // Rise networks
53
+ 11155931: "https://rise-testnet.g.alchemy.com/v2", // riseTestnet
54
+ // Story networks
55
+ 1514: "https://story-mainnet.g.alchemy.com/v2", // storyMainnet
56
+ 1315: "https://story-aeneid.g.alchemy.com/v2", // storyAeneid
57
+ // Celo networks
58
+ 42220: "https://celo-mainnet.g.alchemy.com/v2", // celoMainnet
59
+ 44787: "https://celo-alfajores.g.alchemy.com/v2", // celoAlfajores
60
+ // Tea networks
61
+ 10218: "https://tea-sepolia.g.alchemy.com/v2", // teaSepolia
62
+ };
63
+ /**
64
+ * Gets the Alchemy RPC base URL for a given chain ID.
65
+ *
66
+ * @param {number} chainId The chain ID to lookup
67
+ * @returns {string | undefined} The Alchemy RPC base URL or undefined if not supported
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * const rpcUrl = getAlchemyRpcUrl(1); // "https://eth-mainnet.g.alchemy.com/v2"
72
+ * const customUrl = getAlchemyRpcUrl(999); // undefined
73
+ * ```
74
+ */
75
+ export function getAlchemyRpcUrl(chainId) {
76
+ return ALCHEMY_RPC_MAPPING[chainId];
77
+ }
78
+ /**
79
+ * Checks if a chain ID is supported by the Alchemy RPC registry.
80
+ *
81
+ * @param {number} chainId The chain ID to check
82
+ * @returns {boolean} True if the chain is supported, false otherwise
83
+ */
84
+ export function isChainSupported(chainId) {
85
+ return chainId in ALCHEMY_RPC_MAPPING;
86
+ }
87
+ /**
88
+ * Gets all supported chain IDs from the registry.
89
+ *
90
+ * @returns {number[]} Array of supported chain IDs
91
+ */
92
+ export function getSupportedChainIds() {
93
+ return Object.keys(ALCHEMY_RPC_MAPPING).map(Number);
94
+ }
95
+ //# sourceMappingURL=chainRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chainRegistry.js","sourceRoot":"","sources":["../../../src/transport/chainRegistry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAA2B;IACzD,oBAAoB;IACpB,CAAC,EAAE,sCAAsC,EAAE,UAAU;IACrD,QAAQ,EAAE,sCAAsC,EAAE,UAAU;IAC5D,CAAC,EAAE,qCAAqC,EAAE,SAAS;IAEnD,oBAAoB;IACpB,KAAK,EAAE,sCAAsC,EAAE,WAAW;IAC1D,MAAM,EAAE,qCAAqC,EAAE,iBAAiB;IAChE,MAAM,EAAE,sCAAsC,EAAE,kBAAkB;IAElE,oBAAoB;IACpB,EAAE,EAAE,sCAAsC,EAAE,WAAW;IACvD,GAAG,EAAE,qCAAqC,EAAE,iBAAiB;IAC7D,QAAQ,EAAE,sCAAsC,EAAE,kBAAkB;IAEpE,gBAAgB;IAChB,IAAI,EAAE,uCAAuC,EAAE,OAAO;IACtD,KAAK,EAAE,sCAAsC,EAAE,aAAa;IAC5D,KAAK,EAAE,uCAAuC,EAAE,cAAc;IAE9D,mBAAmB;IACnB,GAAG,EAAE,0CAA0C,EAAE,UAAU;IAC3D,KAAK,EAAE,yCAAyC,EAAE,gBAAgB;IAClE,KAAK,EAAE,uCAAuC,EAAE,cAAc;IAE9D,uBAAuB;IACvB,GAAG,EAAE,6CAA6C,EAAE,aAAa;IACjE,IAAI,EAAE,6CAA6C,EAAE,oBAAoB;IAEzE,iBAAiB;IACjB,GAAG,EAAE,wCAAwC,EAAE,QAAQ;IACvD,KAAK,EAAE,wCAAwC,EAAE,eAAe;IAEhE,oBAAoB;IACpB,GAAG,EAAE,2CAA2C,EAAE,kBAAkB;IACpE,IAAI,EAAE,2CAA2C,EAAE,kBAAkB;IAErE,mBAAmB;IACnB,IAAI,EAAE,0CAA0C,EAAE,iBAAiB;IACnE,IAAI,EAAE,yCAAyC,EAAE,gBAAgB;IAEjE,iBAAiB;IACjB,GAAG,EAAE,wCAAwC,EAAE,eAAe;IAC9D,IAAI,EAAE,wCAAwC,EAAE,eAAe;IAE/D,qBAAqB;IACrB,KAAK,EAAE,2CAA2C,EAAE,kBAAkB;IAEtE,eAAe;IACf,KAAK,EAAE,sCAAsC,EAAE,aAAa;IAC5D,MAAM,EAAE,sCAAsC,EAAE,aAAa;IAE7D,iBAAiB;IACjB,KAAK,EAAE,wCAAwC,EAAE,eAAe;IAEhE,oBAAoB;IACpB,MAAM,EAAE,2CAA2C,EAAE,kBAAkB;IAEvE,kBAAkB;IAClB,MAAM,EAAE,yCAAyC,EAAE,gBAAgB;IAEnE,gBAAgB;IAChB,QAAQ,EAAE,uCAAuC,EAAE,cAAc;IAEjE,iBAAiB;IACjB,IAAI,EAAE,wCAAwC,EAAE,eAAe;IAC/D,IAAI,EAAE,uCAAuC,EAAE,cAAc;IAE7D,gBAAgB;IAChB,KAAK,EAAE,uCAAuC,EAAE,cAAc;IAC9D,KAAK,EAAE,yCAAyC,EAAE,gBAAgB;IAElE,eAAe;IACf,KAAK,EAAE,sCAAsC,EAAE,aAAa;CAC7D,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,OAAO,OAAO,IAAI,mBAAmB,CAAC;AACxC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC","sourcesContent":["/**\n * Internal registry mapping chain IDs to Alchemy RPC base URLs.\n * This replaces the need for custom chain exports with embedded Alchemy URLs.\n */\nexport const ALCHEMY_RPC_MAPPING: Record<number, string> = {\n // Ethereum networks\n 1: \"https://eth-mainnet.g.alchemy.com/v2\", // mainnet\n 11155111: \"https://eth-sepolia.g.alchemy.com/v2\", // sepolia\n 5: \"https://eth-goerli.g.alchemy.com/v2\", // goerli\n\n // Arbitrum networks\n 42161: \"https://arb-mainnet.g.alchemy.com/v2\", // arbitrum\n 421613: \"https://arb-goerli.g.alchemy.com/v2\", // arbitrumGoerli\n 421614: \"https://arb-sepolia.g.alchemy.com/v2\", // arbitrumSepolia\n\n // Optimism networks\n 10: \"https://opt-mainnet.g.alchemy.com/v2\", // optimism\n 420: \"https://opt-goerli.g.alchemy.com/v2\", // optimismGoerli\n 11155420: \"https://opt-sepolia.g.alchemy.com/v2\", // optimismSepolia\n\n // Base networks\n 8453: \"https://base-mainnet.g.alchemy.com/v2\", // base\n 84531: \"https://base-goerli.g.alchemy.com/v2\", // baseGoerli\n 84532: \"https://base-sepolia.g.alchemy.com/v2\", // baseSepolia\n\n // Polygon networks\n 137: \"https://polygon-mainnet.g.alchemy.com/v2\", // polygon\n 80001: \"https://polygon-mumbai.g.alchemy.com/v2\", // polygonMumbai\n 80002: \"https://polygon-amoy.g.alchemy.com/v2\", // polygonAmoy\n\n // World Chain networks\n 480: \"https://worldchain-mainnet.g.alchemy.com/v2\", // worldChain\n 4801: \"https://worldchain-sepolia.g.alchemy.com/v2\", // worldChainSepolia\n\n // Shape networks\n 360: \"https://shape-mainnet.g.alchemy.com/v2\", // shape\n 11011: \"https://shape-sepolia.g.alchemy.com/v2\", // shapeSepolia\n\n // Unichain networks\n 130: \"https://unichain-mainnet.g.alchemy.com/v2\", // unichainMainnet\n 1301: \"https://unichain-sepolia.g.alchemy.com/v2\", // unichainSepolia\n\n // Soneium networks\n 1868: \"https://soneium-mainnet.g.alchemy.com/v2\", // soneiumMainnet\n 1946: \"https://soneium-minato.g.alchemy.com/v2\", // soneiumMinato\n\n // OPBNB networks\n 204: \"https://opbnb-mainnet.g.alchemy.com/v2\", // opbnbMainnet\n 5611: \"https://opbnb-testnet.g.alchemy.com/v2\", // opbnbTestnet\n\n // BeraChain networks\n 80084: \"https://berachain-bartio.g.alchemy.com/v2\", // beraChainBartio\n\n // Ink networks\n 57073: \"https://ink-mainnet.g.alchemy.com/v2\", // inkMainnet\n 763373: \"https://ink-sepolia.g.alchemy.com/v2\", // inkSepolia\n\n // Monad networks\n 10143: \"https://monad-testnet.g.alchemy.com/v2\", // monadTestnet\n\n // Openloot networks\n 905905: \"https://openloot-sepolia.g.alchemy.com/v2\", // openlootSepolia\n\n // Gensyn networks\n 685685: \"https://gensyn-testnet.g.alchemy.com/v2\", // gensynTestnet\n\n // Rise networks\n 11155931: \"https://rise-testnet.g.alchemy.com/v2\", // riseTestnet\n\n // Story networks\n 1514: \"https://story-mainnet.g.alchemy.com/v2\", // storyMainnet\n 1315: \"https://story-aeneid.g.alchemy.com/v2\", // storyAeneid\n\n // Celo networks\n 42220: \"https://celo-mainnet.g.alchemy.com/v2\", // celoMainnet\n 44787: \"https://celo-alfajores.g.alchemy.com/v2\", // celoAlfajores\n\n // Tea networks\n 10218: \"https://tea-sepolia.g.alchemy.com/v2\", // teaSepolia\n};\n\n/**\n * Gets the Alchemy RPC base URL for a given chain ID.\n *\n * @param {number} chainId The chain ID to lookup\n * @returns {string | undefined} The Alchemy RPC base URL or undefined if not supported\n *\n * @example\n * ```ts\n * const rpcUrl = getAlchemyRpcUrl(1); // \"https://eth-mainnet.g.alchemy.com/v2\"\n * const customUrl = getAlchemyRpcUrl(999); // undefined\n * ```\n */\nexport function getAlchemyRpcUrl(chainId: number): string | undefined {\n return ALCHEMY_RPC_MAPPING[chainId];\n}\n\n/**\n * Checks if a chain ID is supported by the Alchemy RPC registry.\n *\n * @param {number} chainId The chain ID to check\n * @returns {boolean} True if the chain is supported, false otherwise\n */\nexport function isChainSupported(chainId: number): boolean {\n return chainId in ALCHEMY_RPC_MAPPING;\n}\n\n/**\n * Gets all supported chain IDs from the registry.\n *\n * @returns {number[]} Array of supported chain IDs\n */\nexport function getSupportedChainIds(): number[] {\n return Object.keys(ALCHEMY_RPC_MAPPING).map(Number);\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import type { Never } from "../utils/types";
2
+ type AlchemyConnectionBaseConfig = {
3
+ proxyUrl: string;
4
+ apiKey?: never;
5
+ jwt?: never;
6
+ } | {
7
+ proxyUrl?: never;
8
+ apiKey: string;
9
+ jwt?: never;
10
+ } | {
11
+ proxyUrl?: never;
12
+ apiKey?: never;
13
+ jwt: string;
14
+ };
15
+ type AAOnlyChainConfig = {
16
+ alchemyConnection: AlchemyConnectionBaseConfig;
17
+ nodeRpcUrl: string;
18
+ };
19
+ export type AlchemyConnectionConfig = (AlchemyConnectionBaseConfig & Never<AAOnlyChainConfig>) | (AAOnlyChainConfig & Never<AlchemyConnectionBaseConfig>);
20
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/transport/connection.ts"],"names":[],"mappings":"","sourcesContent":["import type { Never } from \"../utils/types\";\n\n// TODO(v5): remove this file and use connectionSchema.ts instead once other packages are migrated over\ntype AlchemyConnectionBaseConfig =\n // TODO(v5): is this really the best devex? can we do better?\n // basic configuration for connecting to alchemy.\n // proxyUrl is used when making calls to the developer backend.\n | { proxyUrl: string; apiKey?: never; jwt?: never }\n | { proxyUrl?: never; apiKey: string; jwt?: never }\n | { proxyUrl?: never; apiKey?: never; jwt: string };\n\ntype AAOnlyChainConfig = {\n alchemyConnection: AlchemyConnectionBaseConfig;\n nodeRpcUrl: string;\n};\n\nexport type AlchemyConnectionConfig =\n | (AlchemyConnectionBaseConfig & Never<AAOnlyChainConfig>)\n | (AAOnlyChainConfig & Never<AlchemyConnectionBaseConfig>);\n"]}
@@ -0,0 +1,124 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Alchemy Connection Configuration Schema
4
+ *
5
+ * Provides three authentication options for connecting to Alchemy services:
6
+ *
7
+ * 1. **API Key**: Authenticate using your Alchemy API key
8
+ * 2. **JWT**: Authenticate using a JWT token
9
+ * 3. **URL**: Connect directly using a full RPC URL
10
+ *
11
+ * @example
12
+ * Using API Key (uses chain's Alchemy URL):
13
+ * ```ts
14
+ * { apiKey: 'abc123' }
15
+ * ```
16
+ *
17
+ * @example
18
+ * Using JWT (uses chain's Alchemy URL):
19
+ * ```ts
20
+ * { jwt: 'eyJhbGc...' }
21
+ * ```
22
+ *
23
+ * @example
24
+ * Using direct URL only:
25
+ * ```ts
26
+ * { url: 'https://eth-mainnet.g.alchemy.com/v2/your-key' }
27
+ * ```
28
+ *
29
+ * @example
30
+ * Using custom URL with API key:
31
+ * ```ts
32
+ * { url: 'https://custom-alchemy.com/v2', apiKey: 'abc123' }
33
+ * ```
34
+ *
35
+ * @example
36
+ * Using custom URL with JWT:
37
+ * ```ts
38
+ * { url: 'https://custom-alchemy.com/v2', jwt: 'eyJhbGc...' }
39
+ * ```
40
+ */
41
+ /**
42
+ * Main connection configuration allowing flexible combinations.
43
+ * Can specify URL, auth method, or both together.
44
+ */
45
+ export declare const AlchemyConnectionConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
46
+ /** API key for Alchemy authentication */
47
+ apiKey: z.ZodOptional<z.ZodString>;
48
+ /** JWT token for authentication */
49
+ jwt: z.ZodOptional<z.ZodString>;
50
+ /** Custom RPC URL (optional - defaults to chain's Alchemy URL) */
51
+ url: z.ZodOptional<z.ZodString>;
52
+ }, "strict", z.ZodTypeAny, {
53
+ apiKey?: string | undefined;
54
+ jwt?: string | undefined;
55
+ url?: string | undefined;
56
+ }, {
57
+ apiKey?: string | undefined;
58
+ jwt?: string | undefined;
59
+ url?: string | undefined;
60
+ }>, {
61
+ apiKey?: string | undefined;
62
+ jwt?: string | undefined;
63
+ url?: string | undefined;
64
+ }, {
65
+ apiKey?: string | undefined;
66
+ jwt?: string | undefined;
67
+ url?: string | undefined;
68
+ }>, {
69
+ apiKey?: string | undefined;
70
+ jwt?: string | undefined;
71
+ url?: string | undefined;
72
+ }, {
73
+ apiKey?: string | undefined;
74
+ jwt?: string | undefined;
75
+ url?: string | undefined;
76
+ }>;
77
+ /**
78
+ * TypeScript type derived from the schema for external consumption.
79
+ * This provides clean type inference without exposing Zod implementation details.
80
+ */
81
+ export type AlchemyConnectionConfig = z.infer<typeof AlchemyConnectionConfigSchema>;
82
+ /**
83
+ * Validates an Alchemy connection configuration object.
84
+ *
85
+ * @param {unknown} config - The configuration object to validate
86
+ * @returns {AlchemyConnectionConfig} The validated configuration object
87
+ * @throws {ConnectionConfigError} If the configuration is invalid
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * try {
92
+ * const config = validateAlchemyConnectionConfig({
93
+ * apiKey: 'your-api-key'
94
+ * });
95
+ * // config is now typed as AlchemyConnectionConfig
96
+ * } catch (error) {
97
+ * if (error instanceof ConnectionConfigError) {
98
+ * console.error('Invalid config:', error.message);
99
+ * }
100
+ * }
101
+ * ```
102
+ */
103
+ export declare function validateAlchemyConnectionConfig(config: unknown): AlchemyConnectionConfig;
104
+ /**
105
+ * Type guard to check if a value is a valid Alchemy connection config.
106
+ *
107
+ * @param {unknown} value - The value to check for validity
108
+ * @returns {boolean} True if the value is a valid Alchemy connection config
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * const maybeConfig: unknown = { apiKey: 'test' };
113
+ * if (isAlchemyConnectionConfig(maybeConfig)) {
114
+ * // TypeScript knows maybeConfig is AlchemyConnectionConfig here
115
+ * if (maybeConfig.apiKey) {
116
+ * console.log('Using API key:', maybeConfig.apiKey);
117
+ * }
118
+ * if (maybeConfig.url) {
119
+ * console.log('Using custom URL:', maybeConfig.url);
120
+ * }
121
+ * }
122
+ * ```
123
+ */
124
+ export declare function isAlchemyConnectionConfig(value: unknown): value is AlchemyConnectionConfig;
@@ -0,0 +1,121 @@
1
+ import { z } from "zod";
2
+ import { ConnectionConfigError } from "../errors/ConnectionConfigError.js";
3
+ /**
4
+ * Alchemy Connection Configuration Schema
5
+ *
6
+ * Provides three authentication options for connecting to Alchemy services:
7
+ *
8
+ * 1. **API Key**: Authenticate using your Alchemy API key
9
+ * 2. **JWT**: Authenticate using a JWT token
10
+ * 3. **URL**: Connect directly using a full RPC URL
11
+ *
12
+ * @example
13
+ * Using API Key (uses chain's Alchemy URL):
14
+ * ```ts
15
+ * { apiKey: 'abc123' }
16
+ * ```
17
+ *
18
+ * @example
19
+ * Using JWT (uses chain's Alchemy URL):
20
+ * ```ts
21
+ * { jwt: 'eyJhbGc...' }
22
+ * ```
23
+ *
24
+ * @example
25
+ * Using direct URL only:
26
+ * ```ts
27
+ * { url: 'https://eth-mainnet.g.alchemy.com/v2/your-key' }
28
+ * ```
29
+ *
30
+ * @example
31
+ * Using custom URL with API key:
32
+ * ```ts
33
+ * { url: 'https://custom-alchemy.com/v2', apiKey: 'abc123' }
34
+ * ```
35
+ *
36
+ * @example
37
+ * Using custom URL with JWT:
38
+ * ```ts
39
+ * { url: 'https://custom-alchemy.com/v2', jwt: 'eyJhbGc...' }
40
+ * ```
41
+ */
42
+ /**
43
+ * Main connection configuration allowing flexible combinations.
44
+ * Can specify URL, auth method, or both together.
45
+ */
46
+ export const AlchemyConnectionConfigSchema = z
47
+ .object({
48
+ /** API key for Alchemy authentication */
49
+ apiKey: z.string().min(1, "API key cannot be empty").optional(),
50
+ /** JWT token for authentication */
51
+ jwt: z.string().min(1, "JWT cannot be empty").optional(),
52
+ /** Custom RPC URL (optional - defaults to chain's Alchemy URL) */
53
+ url: z.string().url("Invalid URL format").optional(),
54
+ })
55
+ .strict()
56
+ .refine((data) => {
57
+ // Must have at least one field
58
+ return data.apiKey || data.jwt || data.url;
59
+ }, {
60
+ message: "Must specify at least one of: apiKey, jwt, or url",
61
+ })
62
+ .refine((data) => {
63
+ // Cannot have both apiKey and jwt
64
+ return !(data.apiKey && data.jwt);
65
+ }, {
66
+ message: "Cannot specify both apiKey and jwt - choose only one authentication method",
67
+ });
68
+ /**
69
+ * Validates an Alchemy connection configuration object.
70
+ *
71
+ * @param {unknown} config - The configuration object to validate
72
+ * @returns {AlchemyConnectionConfig} The validated configuration object
73
+ * @throws {ConnectionConfigError} If the configuration is invalid
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * try {
78
+ * const config = validateAlchemyConnectionConfig({
79
+ * apiKey: 'your-api-key'
80
+ * });
81
+ * // config is now typed as AlchemyConnectionConfig
82
+ * } catch (error) {
83
+ * if (error instanceof ConnectionConfigError) {
84
+ * console.error('Invalid config:', error.message);
85
+ * }
86
+ * }
87
+ * ```
88
+ */
89
+ export function validateAlchemyConnectionConfig(config) {
90
+ const result = AlchemyConnectionConfigSchema.safeParse(config);
91
+ if (!result.success) {
92
+ const firstError = result.error.issues[0];
93
+ const details = firstError?.message || "Invalid connection configuration";
94
+ throw new ConnectionConfigError(details);
95
+ }
96
+ return result.data;
97
+ }
98
+ /**
99
+ * Type guard to check if a value is a valid Alchemy connection config.
100
+ *
101
+ * @param {unknown} value - The value to check for validity
102
+ * @returns {boolean} True if the value is a valid Alchemy connection config
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * const maybeConfig: unknown = { apiKey: 'test' };
107
+ * if (isAlchemyConnectionConfig(maybeConfig)) {
108
+ * // TypeScript knows maybeConfig is AlchemyConnectionConfig here
109
+ * if (maybeConfig.apiKey) {
110
+ * console.log('Using API key:', maybeConfig.apiKey);
111
+ * }
112
+ * if (maybeConfig.url) {
113
+ * console.log('Using custom URL:', maybeConfig.url);
114
+ * }
115
+ * }
116
+ * ```
117
+ */
118
+ export function isAlchemyConnectionConfig(value) {
119
+ return AlchemyConnectionConfigSchema.safeParse(value).success;
120
+ }
121
+ //# sourceMappingURL=connectionSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connectionSchema.js","sourceRoot":"","sources":["../../../src/transport/connectionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC;KAC3C,MAAM,CAAC;IACN,yCAAyC;IACzC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,yBAAyB,CAAC,CAAC,QAAQ,EAAE;IAC/D,mCAAmC;IACnC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC,QAAQ,EAAE;IACxD,kEAAkE;IAClE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,QAAQ,EAAE;CACrD,CAAC;KACD,MAAM,EAAE;KACR,MAAM,CACL,CAAC,IAAI,EAAE,EAAE;IACP,+BAA+B;IAC/B,OAAO,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;AAC7C,CAAC,EACD;IACE,OAAO,EAAE,mDAAmD;CAC7D,CACF;KACA,MAAM,CACL,CAAC,IAAI,EAAE,EAAE;IACP,kCAAkC;IAClC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;AACpC,CAAC,EACD;IACE,OAAO,EACL,4EAA4E;CAC/E,CACF,CAAC;AAUJ;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,+BAA+B,CAC7C,MAAe;IAEf,MAAM,MAAM,GAAG,6BAA6B,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAE/D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC1C,MAAM,OAAO,GAAG,UAAU,EAAE,OAAO,IAAI,kCAAkC,CAAC;QAC1E,MAAM,IAAI,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,yBAAyB,CACvC,KAAc;IAEd,OAAO,6BAA6B,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAChE,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { ConnectionConfigError } from \"../errors/ConnectionConfigError.js\";\n\n/**\n * Alchemy Connection Configuration Schema\n *\n * Provides three authentication options for connecting to Alchemy services:\n *\n * 1. **API Key**: Authenticate using your Alchemy API key\n * 2. **JWT**: Authenticate using a JWT token\n * 3. **URL**: Connect directly using a full RPC URL\n *\n * @example\n * Using API Key (uses chain's Alchemy URL):\n * ```ts\n * { apiKey: 'abc123' }\n * ```\n *\n * @example\n * Using JWT (uses chain's Alchemy URL):\n * ```ts\n * { jwt: 'eyJhbGc...' }\n * ```\n *\n * @example\n * Using direct URL only:\n * ```ts\n * { url: 'https://eth-mainnet.g.alchemy.com/v2/your-key' }\n * ```\n *\n * @example\n * Using custom URL with API key:\n * ```ts\n * { url: 'https://custom-alchemy.com/v2', apiKey: 'abc123' }\n * ```\n *\n * @example\n * Using custom URL with JWT:\n * ```ts\n * { url: 'https://custom-alchemy.com/v2', jwt: 'eyJhbGc...' }\n * ```\n */\n\n/**\n * Main connection configuration allowing flexible combinations.\n * Can specify URL, auth method, or both together.\n */\nexport const AlchemyConnectionConfigSchema = z\n .object({\n /** API key for Alchemy authentication */\n apiKey: z.string().min(1, \"API key cannot be empty\").optional(),\n /** JWT token for authentication */\n jwt: z.string().min(1, \"JWT cannot be empty\").optional(),\n /** Custom RPC URL (optional - defaults to chain's Alchemy URL) */\n url: z.string().url(\"Invalid URL format\").optional(),\n })\n .strict()\n .refine(\n (data) => {\n // Must have at least one field\n return data.apiKey || data.jwt || data.url;\n },\n {\n message: \"Must specify at least one of: apiKey, jwt, or url\",\n },\n )\n .refine(\n (data) => {\n // Cannot have both apiKey and jwt\n return !(data.apiKey && data.jwt);\n },\n {\n message:\n \"Cannot specify both apiKey and jwt - choose only one authentication method\",\n },\n );\n\n/**\n * TypeScript type derived from the schema for external consumption.\n * This provides clean type inference without exposing Zod implementation details.\n */\nexport type AlchemyConnectionConfig = z.infer<\n typeof AlchemyConnectionConfigSchema\n>;\n\n/**\n * Validates an Alchemy connection configuration object.\n *\n * @param {unknown} config - The configuration object to validate\n * @returns {AlchemyConnectionConfig} The validated configuration object\n * @throws {ConnectionConfigError} If the configuration is invalid\n *\n * @example\n * ```ts\n * try {\n * const config = validateAlchemyConnectionConfig({\n * apiKey: 'your-api-key'\n * });\n * // config is now typed as AlchemyConnectionConfig\n * } catch (error) {\n * if (error instanceof ConnectionConfigError) {\n * console.error('Invalid config:', error.message);\n * }\n * }\n * ```\n */\nexport function validateAlchemyConnectionConfig(\n config: unknown,\n): AlchemyConnectionConfig {\n const result = AlchemyConnectionConfigSchema.safeParse(config);\n\n if (!result.success) {\n const firstError = result.error.issues[0];\n const details = firstError?.message || \"Invalid connection configuration\";\n throw new ConnectionConfigError(details);\n }\n\n return result.data;\n}\n\n/**\n * Type guard to check if a value is a valid Alchemy connection config.\n *\n * @param {unknown} value - The value to check for validity\n * @returns {boolean} True if the value is a valid Alchemy connection config\n *\n * @example\n * ```ts\n * const maybeConfig: unknown = { apiKey: 'test' };\n * if (isAlchemyConnectionConfig(maybeConfig)) {\n * // TypeScript knows maybeConfig is AlchemyConnectionConfig here\n * if (maybeConfig.apiKey) {\n * console.log('Using API key:', maybeConfig.apiKey);\n * }\n * if (maybeConfig.url) {\n * console.log('Using custom URL:', maybeConfig.url);\n * }\n * }\n * ```\n */\nexport function isAlchemyConnectionConfig(\n value: unknown,\n): value is AlchemyConnectionConfig {\n return AlchemyConnectionConfigSchema.safeParse(value).success;\n}\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Asserts that a value is never.
3
+ *
4
+ * @param {never} _x - The value to assert.
5
+ * @param {string} msg - The message to throw if the value is not never.
6
+ * @returns {never} Always throws an error.
7
+ */
8
+ export declare const assertNever: (_x: never, msg: string) => never;
@@ -0,0 +1,12 @@
1
+ import { BaseError } from "../errors/BaseError.js";
2
+ /**
3
+ * Asserts that a value is never.
4
+ *
5
+ * @param {never} _x - The value to assert.
6
+ * @param {string} msg - The message to throw if the value is not never.
7
+ * @returns {never} Always throws an error.
8
+ */
9
+ export const assertNever = (_x, msg) => {
10
+ throw new BaseError(msg);
11
+ };
12
+ //# sourceMappingURL=assertNever.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertNever.js","sourceRoot":"","sources":["../../../src/utils/assertNever.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAAS,EAAE,GAAW,EAAS,EAAE;IAC3D,MAAM,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import { BaseError } from \"../errors/BaseError.js\";\n\n/**\n * Asserts that a value is never.\n *\n * @param {never} _x - The value to assert.\n * @param {string} msg - The message to throw if the value is not never.\n * @returns {never} Always throws an error.\n */\nexport const assertNever = (_x: never, msg: string): never => {\n throw new BaseError(msg);\n};\n"]}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * BigNumberish represents values that can be converted to BigInt
3
+ */
4
+ export type BigNumberish = string | number | bigint;
5
+ /**
6
+ * Multiplier configuration for bigint multiplication
7
+ */
8
+ export type Multiplier = {
9
+ multiplier: number;
10
+ };
11
+ export declare enum RoundingMode {
12
+ ROUND_DOWN = 0,
13
+ ROUND_UP = 1
14
+ }
15
+ /**
16
+ * Given a bigint and a number (which can be a float), returns the bigint value.
17
+ * Note: this function has loss and will round down to the nearest integer.
18
+ *
19
+ * @param {BigNumberish} base - the number to be multiplied
20
+ * @param {number} multiplier - the amount to multiply by
21
+ * @param {RoundingMode} roundingMode - the rounding mode to use when calculating the percent. defaults to ROUND_UP
22
+ * @returns {bigint} the bigint value of the multiplication with the number rounded by the rounding mode
23
+ */
24
+ export declare const bigIntMultiply: (base: BigNumberish, multiplier: Multiplier["multiplier"], roundingMode?: RoundingMode) => bigint;
@@ -0,0 +1,37 @@
1
+ export var RoundingMode;
2
+ (function (RoundingMode) {
3
+ RoundingMode[RoundingMode["ROUND_DOWN"] = 0] = "ROUND_DOWN";
4
+ RoundingMode[RoundingMode["ROUND_UP"] = 1] = "ROUND_UP";
5
+ })(RoundingMode || (RoundingMode = {}));
6
+ /**
7
+ * Validates if a multiplier has acceptable precision (max 4 decimal places)
8
+ *
9
+ * @param {Multiplier} multiplier - the multiplier to validate
10
+ * @returns {boolean} true if valid, false otherwise
11
+ */
12
+ function isValidMultiplier(multiplier) {
13
+ const decimalPlaces = multiplier.multiplier.toString().split(".")[1]?.length ?? 0;
14
+ return decimalPlaces <= 4;
15
+ }
16
+ /**
17
+ * Given a bigint and a number (which can be a float), returns the bigint value.
18
+ * Note: this function has loss and will round down to the nearest integer.
19
+ *
20
+ * @param {BigNumberish} base - the number to be multiplied
21
+ * @param {number} multiplier - the amount to multiply by
22
+ * @param {RoundingMode} roundingMode - the rounding mode to use when calculating the percent. defaults to ROUND_UP
23
+ * @returns {bigint} the bigint value of the multiplication with the number rounded by the rounding mode
24
+ */
25
+ export const bigIntMultiply = (base, multiplier, roundingMode = RoundingMode.ROUND_UP) => {
26
+ if (!isValidMultiplier({ multiplier })) {
27
+ throw new Error("bigIntMultiply requires a multiplier validated number as the second argument (max 4 decimal places)");
28
+ }
29
+ // Get decimal places of b. Max decimal places is defined by the validation above.
30
+ const decimalPlaces = multiplier.toString().split(".")[1]?.length ?? 0;
31
+ const result = BigInt(base) * BigInt(Math.round(multiplier * 10 ** decimalPlaces));
32
+ return roundingMode === RoundingMode.ROUND_UP &&
33
+ result % BigInt(10 ** decimalPlaces) > 0
34
+ ? result / BigInt(10 ** decimalPlaces) + 1n
35
+ : result / BigInt(10 ** decimalPlaces);
36
+ };
37
+ //# sourceMappingURL=bigint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bigint.js","sourceRoot":"","sources":["../../../src/utils/bigint.ts"],"names":[],"mappings":"AAYA,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,2DAAc,CAAA;IACd,uDAAY,CAAA;AACd,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB;AAED;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,UAAsB;IAC/C,MAAM,aAAa,GACjB,UAAU,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;IAC9D,OAAO,aAAa,IAAI,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,IAAkB,EAClB,UAAoC,EACpC,eAA6B,YAAY,CAAC,QAAQ,EAClD,EAAE;IACF,IAAI,CAAC,iBAAiB,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CACb,qGAAqG,CACtG,CAAC;IACJ,CAAC;IAED,kFAAkF;IAClF,MAAM,aAAa,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;IACvE,MAAM,MAAM,GACV,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,EAAE,IAAI,aAAa,CAAC,CAAC,CAAC;IACtE,OAAO,YAAY,KAAK,YAAY,CAAC,QAAQ;QAC3C,MAAM,GAAG,MAAM,CAAC,EAAE,IAAI,aAAa,CAAC,GAAG,CAAC;QACxC,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,IAAI,aAAa,CAAC,GAAG,EAAE;QAC3C,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,IAAI,aAAa,CAAC,CAAC;AAC3C,CAAC,CAAC","sourcesContent":["/**\n * BigNumberish represents values that can be converted to BigInt\n */\nexport type BigNumberish = string | number | bigint;\n\n/**\n * Multiplier configuration for bigint multiplication\n */\nexport type Multiplier = {\n multiplier: number;\n};\n\nexport enum RoundingMode {\n ROUND_DOWN = 0,\n ROUND_UP = 1,\n}\n\n/**\n * Validates if a multiplier has acceptable precision (max 4 decimal places)\n *\n * @param {Multiplier} multiplier - the multiplier to validate\n * @returns {boolean} true if valid, false otherwise\n */\nfunction isValidMultiplier(multiplier: Multiplier): boolean {\n const decimalPlaces =\n multiplier.multiplier.toString().split(\".\")[1]?.length ?? 0;\n return decimalPlaces <= 4;\n}\n\n/**\n * Given a bigint and a number (which can be a float), returns the bigint value.\n * Note: this function has loss and will round down to the nearest integer.\n *\n * @param {BigNumberish} base - the number to be multiplied\n * @param {number} multiplier - the amount to multiply by\n * @param {RoundingMode} roundingMode - the rounding mode to use when calculating the percent. defaults to ROUND_UP\n * @returns {bigint} the bigint value of the multiplication with the number rounded by the rounding mode\n */\nexport const bigIntMultiply = (\n base: BigNumberish,\n multiplier: Multiplier[\"multiplier\"],\n roundingMode: RoundingMode = RoundingMode.ROUND_UP,\n) => {\n if (!isValidMultiplier({ multiplier })) {\n throw new Error(\n \"bigIntMultiply requires a multiplier validated number as the second argument (max 4 decimal places)\",\n );\n }\n\n // Get decimal places of b. Max decimal places is defined by the validation above.\n const decimalPlaces = multiplier.toString().split(\".\")[1]?.length ?? 0;\n const result =\n BigInt(base) * BigInt(Math.round(multiplier * 10 ** decimalPlaces));\n return roundingMode === RoundingMode.ROUND_UP &&\n result % BigInt(10 ** decimalPlaces) > 0\n ? result / BigInt(10 ** decimalPlaces) + 1n\n : result / BigInt(10 ** decimalPlaces);\n};\n"]}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Creates a typed handler factory for EIP1193 request methods.
3
+ * This helps with Viem's typing within custom EIP1193 request functions by
4
+ * automatically casting input params and ensuring the result matches what is required.
5
+ *
6
+ * @returns {(params: unknown) => unknown} A function that creates a handler factory for specific methods
7
+ */
8
+ export declare const createEip1193HandlerFactory: <TMethods extends readonly {
9
+ Method: string;
10
+ Parameters?: unknown;
11
+ ReturnType?: unknown;
12
+ }[]>() => <TMethod extends TMethods[number]["Method"]>(handle: (params: Extract<TMethods[number], {
13
+ Method: TMethod;
14
+ }>["Parameters"]) => Promise<Extract<TMethods[number], {
15
+ Method: TMethod;
16
+ }>["ReturnType"]>) => (params: unknown) => Promise<Extract<TMethods[number], {
17
+ Method: TMethod;
18
+ }>["ReturnType"]>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Creates a typed handler factory for EIP1193 request methods.
3
+ * This helps with Viem's typing within custom EIP1193 request functions by
4
+ * automatically casting input params and ensuring the result matches what is required.
5
+ *
6
+ * @returns {(params: unknown) => unknown} A function that creates a handler factory for specific methods
7
+ */
8
+ export const createEip1193HandlerFactory = () => (handle) => (params) => {
9
+ return handle(params);
10
+ };
11
+ //# sourceMappingURL=createEip1193HandlerFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createEip1193HandlerFactory.js","sourceRoot":"","sources":["../../../src/utils/createEip1193HandlerFactory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GACtC,GAMI,EAAE,CACN,CACE,MAE0E,EAC1E,EAAE,CACJ,CAAC,MAAe,EAAE,EAAE;IAClB,OAAO,MAAM,CACX,MAAsE,CACvE,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/**\n * Creates a typed handler factory for EIP1193 request methods.\n * This helps with Viem's typing within custom EIP1193 request functions by\n * automatically casting input params and ensuring the result matches what is required.\n *\n * @returns {(params: unknown) => unknown} A function that creates a handler factory for specific methods\n */\nexport const createEip1193HandlerFactory =\n <\n TMethods extends readonly {\n Method: string;\n Parameters?: unknown;\n ReturnType?: unknown;\n }[],\n >() =>\n <TMethod extends TMethods[number][\"Method\"]>(\n handle: (\n params: Extract<TMethods[number], { Method: TMethod }>[\"Parameters\"],\n ) => Promise<Extract<TMethods[number], { Method: TMethod }>[\"ReturnType\"]>,\n ) =>\n (params: unknown) => {\n return handle(\n params as Extract<TMethods[number], { Method: TMethod }>[\"Parameters\"],\n );\n };\n"]}
@@ -0,0 +1,7 @@
1
+ export type WithAlchemyHeadersParams = {
2
+ headers?: HeadersInit;
3
+ apiKey?: string;
4
+ jwt?: string;
5
+ };
6
+ export declare function withAlchemyHeaders({ headers, apiKey, jwt, }: WithAlchemyHeadersParams): Record<string, string>;
7
+ export declare function convertHeadersToObject(headers?: HeadersInit): Record<string, string>;
@@ -0,0 +1,29 @@
1
+ import { VERSION } from "../version.js";
2
+ export function withAlchemyHeaders({ headers, apiKey, jwt, }) {
3
+ const bearerToken = jwt ?? apiKey;
4
+ return {
5
+ ...convertHeadersToObject(headers),
6
+ "Alchemy-AA-Sdk-Version": VERSION,
7
+ ...(bearerToken ? { Authorization: `Bearer ${bearerToken}` } : {}),
8
+ };
9
+ }
10
+ export function convertHeadersToObject(headers) {
11
+ if (!headers) {
12
+ return {};
13
+ }
14
+ if (headers instanceof Headers) {
15
+ const headersObject = {};
16
+ headers.forEach((value, key) => {
17
+ headersObject[key] = value;
18
+ });
19
+ return headersObject;
20
+ }
21
+ if (Array.isArray(headers)) {
22
+ return headers.reduce((acc, header) => {
23
+ acc[header[0]] = header[1];
24
+ return acc;
25
+ }, {});
26
+ }
27
+ return headers;
28
+ }
29
+ //# sourceMappingURL=headers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.js","sourceRoot":"","sources":["../../../src/utils/headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAQxC,MAAM,UAAU,kBAAkB,CAAC,EACjC,OAAO,EACP,MAAM,EACN,GAAG,GACsB;IACzB,MAAM,WAAW,GAAG,GAAG,IAAI,MAAM,CAAC;IAClC,OAAO;QACL,GAAG,sBAAsB,CAAC,OAAO,CAAC;QAClC,wBAAwB,EAAE,OAAO;QACjC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACnE,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,OAAqB;IAErB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,OAAO,YAAY,OAAO,EAAE,CAAC;QAC/B,MAAM,aAAa,GAAG,EAA4B,CAAC;QACnD,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YAC7B,aAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC7B,CAAC,CAAC,CAAC;QACH,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC,MAAM,CACnB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;YACd,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC3B,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAA4B,CAC7B,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { VERSION } from \"../version.js\";\n\nexport type WithAlchemyHeadersParams = {\n headers?: HeadersInit;\n apiKey?: string;\n jwt?: string;\n};\n\nexport function withAlchemyHeaders({\n headers,\n apiKey,\n jwt,\n}: WithAlchemyHeadersParams): Record<string, string> {\n const bearerToken = jwt ?? apiKey;\n return {\n ...convertHeadersToObject(headers),\n \"Alchemy-AA-Sdk-Version\": VERSION,\n ...(bearerToken ? { Authorization: `Bearer ${bearerToken}` } : {}),\n };\n}\n\nexport function convertHeadersToObject(\n headers?: HeadersInit,\n): Record<string, string> {\n if (!headers) {\n return {};\n }\n\n if (headers instanceof Headers) {\n const headersObject = {} as Record<string, string>;\n headers.forEach((value, key) => {\n headersObject[key] = value;\n });\n return headersObject;\n }\n\n if (Array.isArray(headers)) {\n return headers.reduce(\n (acc, header) => {\n acc[header[0]] = header[1];\n return acc;\n },\n {} as Record<string, string>,\n );\n }\n\n return headers;\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { type Address } from "viem";
2
+ /**
3
+ * Lowercase an address
4
+ *
5
+ * @param {Address} addr - The address to lowercase
6
+ * @returns {Address} The lowercase address
7
+ */
8
+ export declare const lowerAddress: (addr: Address) => Address;
@@ -0,0 +1,9 @@
1
+ import {} from "viem";
2
+ /**
3
+ * Lowercase an address
4
+ *
5
+ * @param {Address} addr - The address to lowercase
6
+ * @returns {Address} The lowercase address
7
+ */
8
+ export const lowerAddress = (addr) => addr.toLowerCase();
9
+ //# sourceMappingURL=lowerAddress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lowerAddress.js","sourceRoot":"","sources":["../../../src/utils/lowerAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,MAAM,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAa,EAAW,EAAE,CACrD,IAAI,CAAC,WAAW,EAAa,CAAC","sourcesContent":["import { type Address } from \"viem\";\n\n/**\n * Lowercase an address\n *\n * @param {Address} addr - The address to lowercase\n * @returns {Address} The lowercase address\n */\nexport const lowerAddress = (addr: Address): Address =>\n addr.toLowerCase() as Address;\n"]}
@@ -0,0 +1,8 @@
1
+ import { BaseError } from "viem";
2
+ /**
3
+ * Raises an error.
4
+ *
5
+ * @param {string | BaseError} err - The error to raise.
6
+ * @returns {never} Always throws an error.
7
+ */
8
+ export declare const raise: (err: string | BaseError) => never;
@@ -0,0 +1,14 @@
1
+ import { BaseError } from "viem";
2
+ /**
3
+ * Raises an error.
4
+ *
5
+ * @param {string | BaseError} err - The error to raise.
6
+ * @returns {never} Always throws an error.
7
+ */
8
+ export const raise = (err) => {
9
+ if (typeof err === "string") {
10
+ throw new BaseError(err);
11
+ }
12
+ throw err;
13
+ };
14
+ //# sourceMappingURL=raise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raise.js","sourceRoot":"","sources":["../../../src/utils/raise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAuB,EAAS,EAAE;IACtD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IACD,MAAM,GAAG,CAAC;AACZ,CAAC,CAAC","sourcesContent":["import { BaseError } from \"viem\";\n\n/**\n * Raises an error.\n *\n * @param {string | BaseError} err - The error to raise.\n * @returns {never} Always throws an error.\n */\nexport const raise = (err: string | BaseError): never => {\n if (typeof err === \"string\") {\n throw new BaseError(err);\n }\n throw err;\n};\n"]}