@gardenfi/utils 2.0.3 → 2.0.5

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 (243) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +35 -21
  3. package/dist/index10.cjs +1 -1
  4. package/dist/index10.js +21 -14
  5. package/dist/index100.cjs +1 -0
  6. package/dist/index100.js +9 -0
  7. package/dist/index101.cjs +2 -0
  8. package/dist/index101.js +5 -0
  9. package/dist/index102.cjs +1 -0
  10. package/dist/index102.js +115 -0
  11. package/dist/index103.cjs +1 -0
  12. package/dist/index103.js +81 -0
  13. package/dist/index104.cjs +1 -0
  14. package/dist/index104.js +4 -0
  15. package/dist/index105.cjs +1 -0
  16. package/dist/index105.js +20 -0
  17. package/dist/index106.cjs +1 -0
  18. package/dist/index106.js +21 -0
  19. package/dist/index107.cjs +1 -0
  20. package/dist/index107.js +19 -0
  21. package/dist/index108.cjs +1 -0
  22. package/dist/index108.js +226 -0
  23. package/dist/index109.cjs +1 -0
  24. package/dist/index109.js +37 -0
  25. package/dist/index11.cjs +1 -1
  26. package/dist/index11.js +126 -173
  27. package/dist/index110.cjs +1 -0
  28. package/dist/index110.js +21 -0
  29. package/dist/index111.cjs +1 -0
  30. package/dist/index111.js +72 -0
  31. package/dist/index112.cjs +1 -0
  32. package/dist/index112.js +70 -0
  33. package/dist/index113.cjs +1 -0
  34. package/dist/index113.js +4 -0
  35. package/dist/index114.cjs +1 -0
  36. package/dist/index114.js +43 -0
  37. package/dist/index115.cjs +1 -0
  38. package/dist/index115.js +646 -0
  39. package/dist/index116.cjs +1 -0
  40. package/dist/index116.js +234 -0
  41. package/dist/index117.cjs +1 -0
  42. package/dist/index117.js +175 -0
  43. package/dist/index12.cjs +1 -1
  44. package/dist/index12.js +14 -93
  45. package/dist/index13.cjs +1 -16
  46. package/dist/index13.js +2 -114
  47. package/dist/index14.cjs +1 -1
  48. package/dist/index14.js +33 -31
  49. package/dist/index15.cjs +1 -1
  50. package/dist/index15.js +19 -31
  51. package/dist/index16.cjs +1 -1
  52. package/dist/index16.js +187 -17
  53. package/dist/index17.cjs +1 -1
  54. package/dist/index17.js +93 -7
  55. package/dist/index18.cjs +1 -1
  56. package/dist/index18.js +35 -20
  57. package/dist/index19.cjs +1 -1
  58. package/dist/index19.js +32 -22
  59. package/dist/index20.cjs +16 -1
  60. package/dist/index20.js +113 -8
  61. package/dist/index21.cjs +1 -1
  62. package/dist/index21.js +30 -31
  63. package/dist/index22.cjs +1 -1
  64. package/dist/index22.js +17 -26
  65. package/dist/index23.cjs +1 -1
  66. package/dist/index23.js +6 -22
  67. package/dist/index24.cjs +1 -1
  68. package/dist/index24.js +44 -50
  69. package/dist/index25.cjs +1 -1
  70. package/dist/index25.js +21 -12
  71. package/dist/index26.cjs +1 -1
  72. package/dist/index26.js +8 -24
  73. package/dist/index27.cjs +1 -1
  74. package/dist/index27.js +31 -75
  75. package/dist/index28.cjs +1 -1
  76. package/dist/index28.js +25 -22
  77. package/dist/index29.cjs +2 -1
  78. package/dist/index29.js +65 -7
  79. package/dist/index3.cjs +1 -1
  80. package/dist/index3.js +30 -7
  81. package/dist/index30.cjs +1 -1
  82. package/dist/index30.js +51 -32
  83. package/dist/index31.cjs +1 -1
  84. package/dist/index31.js +12 -15
  85. package/dist/index32.cjs +1 -1
  86. package/dist/index32.js +25 -2
  87. package/dist/index33.cjs +1 -1
  88. package/dist/index33.js +75 -8
  89. package/dist/index34.cjs +1 -1
  90. package/dist/index34.js +23 -20
  91. package/dist/index35.cjs +1 -1
  92. package/dist/index35.js +7 -12
  93. package/dist/index36.cjs +1 -1
  94. package/dist/index36.js +32 -34
  95. package/dist/index37.cjs +1 -2
  96. package/dist/index37.js +15 -59
  97. package/dist/index38.cjs +1 -1
  98. package/dist/index38.js +2 -2
  99. package/dist/index39.cjs +1 -1
  100. package/dist/index39.js +8 -4
  101. package/dist/index4.cjs +1 -1
  102. package/dist/index4.js +2 -2
  103. package/dist/index40.cjs +1 -1
  104. package/dist/index40.js +20 -11
  105. package/dist/index41.cjs +1 -1
  106. package/dist/index41.js +12 -3
  107. package/dist/index42.cjs +1 -1
  108. package/dist/index42.js +33 -20
  109. package/dist/index43.cjs +2 -1
  110. package/dist/index43.js +58 -11
  111. package/dist/index44.cjs +1 -1
  112. package/dist/index44.js +2 -56
  113. package/dist/index45.cjs +1 -1
  114. package/dist/index45.js +6 -6
  115. package/dist/index46.cjs +1 -1
  116. package/dist/index46.js +6 -21
  117. package/dist/index47.cjs +1 -1
  118. package/dist/index47.js +4 -11
  119. package/dist/index48.cjs +1 -1
  120. package/dist/index48.js +11 -3
  121. package/dist/index49.cjs +5 -1
  122. package/dist/index49.js +53 -8
  123. package/dist/index5.cjs +1 -1
  124. package/dist/index5.js +43 -19
  125. package/dist/index50.cjs +1 -1
  126. package/dist/index50.js +3 -19
  127. package/dist/index51.cjs +2 -1
  128. package/dist/index51.js +33 -5
  129. package/dist/index52.cjs +1 -1
  130. package/dist/index52.js +5 -8
  131. package/dist/index53.cjs +1 -1
  132. package/dist/index53.js +20 -103
  133. package/dist/index54.cjs +1 -1
  134. package/dist/index54.js +12 -28
  135. package/dist/index55.cjs +1 -1
  136. package/dist/index55.js +53 -16
  137. package/dist/index56.cjs +1 -1
  138. package/dist/index56.js +8 -38
  139. package/dist/index57.cjs +1 -0
  140. package/dist/index57.js +24 -0
  141. package/dist/index58.cjs +1 -0
  142. package/dist/index58.js +14 -0
  143. package/dist/index59.cjs +1 -0
  144. package/dist/index59.js +11 -0
  145. package/dist/index6.cjs +1 -1
  146. package/dist/index6.js +19 -104
  147. package/dist/index60.cjs +1 -0
  148. package/dist/index60.js +13 -0
  149. package/dist/index61.cjs +1 -0
  150. package/dist/index61.js +14 -0
  151. package/dist/index62.cjs +1 -0
  152. package/dist/index62.js +9 -0
  153. package/dist/index63.cjs +1 -0
  154. package/dist/index63.js +16 -0
  155. package/dist/index64.cjs +1 -0
  156. package/dist/index64.js +35 -0
  157. package/dist/index65.cjs +1 -0
  158. package/dist/index65.js +17 -0
  159. package/dist/index66.cjs +1 -0
  160. package/dist/index66.js +67 -0
  161. package/dist/index67.cjs +1 -0
  162. package/dist/index67.js +30 -0
  163. package/dist/index68.cjs +1 -0
  164. package/dist/index68.js +5 -0
  165. package/dist/index69.cjs +1 -0
  166. package/dist/index69.js +8 -0
  167. package/dist/index7.cjs +1 -1
  168. package/dist/index7.js +2 -15
  169. package/dist/index70.cjs +1 -0
  170. package/dist/index70.js +11 -0
  171. package/dist/index71.cjs +1 -0
  172. package/dist/index71.js +6 -0
  173. package/dist/index72.cjs +1 -0
  174. package/dist/index72.js +16 -0
  175. package/dist/index73.cjs +1 -0
  176. package/dist/index73.js +44 -0
  177. package/dist/index74.cjs +1 -0
  178. package/dist/index74.js +106 -0
  179. package/dist/index75.cjs +1 -0
  180. package/dist/index75.js +194 -0
  181. package/dist/index76.cjs +1 -0
  182. package/dist/index76.js +21 -0
  183. package/dist/index77.cjs +1 -0
  184. package/dist/index77.js +14 -0
  185. package/dist/index78.cjs +1 -0
  186. package/dist/index78.js +22 -0
  187. package/dist/index79.cjs +1 -0
  188. package/dist/index79.js +28 -0
  189. package/dist/index8.cjs +1 -1
  190. package/dist/index8.js +100 -2
  191. package/dist/index80.cjs +1 -0
  192. package/dist/index80.js +9 -0
  193. package/dist/index81.cjs +1 -0
  194. package/dist/index81.js +16 -0
  195. package/dist/index82.cjs +1 -0
  196. package/dist/index82.js +18 -0
  197. package/dist/index83.cjs +1 -0
  198. package/dist/index83.js +8 -0
  199. package/dist/index84.cjs +1 -0
  200. package/dist/index84.js +16 -0
  201. package/dist/index85.cjs +1 -0
  202. package/dist/index85.js +13 -0
  203. package/dist/index86.cjs +1 -0
  204. package/dist/index86.js +19 -0
  205. package/dist/index87.cjs +1 -0
  206. package/dist/index87.js +174 -0
  207. package/dist/index88.cjs +1 -0
  208. package/dist/index88.js +11 -0
  209. package/dist/index89.cjs +1 -0
  210. package/dist/index89.js +15 -0
  211. package/dist/index9.cjs +1 -1
  212. package/dist/index9.js +42 -32
  213. package/dist/index90.cjs +1 -0
  214. package/dist/index90.js +107 -0
  215. package/dist/index91.cjs +1 -0
  216. package/dist/index91.js +41 -0
  217. package/dist/index92.cjs +1 -0
  218. package/dist/index92.js +4 -0
  219. package/dist/index93.cjs +1 -0
  220. package/dist/index93.js +7 -0
  221. package/dist/index94.cjs +1 -0
  222. package/dist/index94.js +13 -0
  223. package/dist/index95.cjs +1 -0
  224. package/dist/index95.js +45 -0
  225. package/dist/index96.cjs +1 -0
  226. package/dist/index96.js +23 -0
  227. package/dist/index97.cjs +1 -0
  228. package/dist/index97.js +7 -0
  229. package/dist/index98.cjs +1 -0
  230. package/dist/index98.js +40 -0
  231. package/dist/index99.cjs +1 -0
  232. package/dist/index99.js +130 -0
  233. package/dist/src/index.d.ts +1 -0
  234. package/dist/src/lib/auth/apikey/apikey.d.ts +12 -0
  235. package/dist/src/lib/auth/auth.types.d.ts +21 -8
  236. package/dist/src/lib/auth/index.d.ts +5 -1
  237. package/dist/src/lib/auth/passkey/passkey.d.ts +10 -0
  238. package/dist/src/lib/auth/passkey/passkey.types.d.ts +17 -0
  239. package/dist/src/lib/auth/passkey/passkeyLogin.d.ts +37 -0
  240. package/dist/src/lib/auth/{siwe.d.ts → siwe/siwe.d.ts} +4 -15
  241. package/dist/src/lib/result.d.ts +16 -0
  242. package/dist/src/lib/utils.d.ts +3 -0
  243. package/package.json +2 -1
package/dist/index20.js CHANGED
@@ -1,11 +1,116 @@
1
- import { withCache as t } from "./index21.js";
2
- const r = (e) => `blockNumber.${e}`;
3
- async function u(e, { cacheTime: c = e.cacheTime } = {}) {
4
- const o = await t(() => e.request({
5
- method: "eth_blockNumber"
6
- }), { cacheKey: r(e.uid), cacheTime: c });
7
- return BigInt(o);
1
+ import { SiweInvalidMessageFieldError as e } from "./index77.js";
2
+ import { getAddress as S } from "./index53.js";
3
+ import { isUri as $ } from "./index78.js";
4
+ function C(n) {
5
+ const { chainId: i, domain: s, expirationTime: u, issuedAt: g = /* @__PURE__ */ new Date(), nonce: a, notBefore: m, requestId: h, resources: w, scheme: o, uri: c, version: f } = n;
6
+ {
7
+ if (i !== Math.floor(i))
8
+ throw new e({
9
+ field: "chainId",
10
+ metaMessages: [
11
+ "- Chain ID must be a EIP-155 chain ID.",
12
+ "- See https://eips.ethereum.org/EIPS/eip-155",
13
+ "",
14
+ `Provided value: ${i}`
15
+ ]
16
+ });
17
+ if (!(p.test(s) || M.test(s) || x.test(s)))
18
+ throw new e({
19
+ field: "domain",
20
+ metaMessages: [
21
+ "- Domain must be an RFC 3986 authority.",
22
+ "- See https://www.rfc-editor.org/rfc/rfc3986",
23
+ "",
24
+ `Provided value: ${s}`
25
+ ]
26
+ });
27
+ if (!A.test(a))
28
+ throw new e({
29
+ field: "nonce",
30
+ metaMessages: [
31
+ "- Nonce must be at least 8 characters.",
32
+ "- Nonce must be alphanumeric.",
33
+ "",
34
+ `Provided value: ${a}`
35
+ ]
36
+ });
37
+ if (!$(c))
38
+ throw new e({
39
+ field: "uri",
40
+ metaMessages: [
41
+ "- URI must be a RFC 3986 URI referring to the resource that is the subject of the signing.",
42
+ "- See https://www.rfc-editor.org/rfc/rfc3986",
43
+ "",
44
+ `Provided value: ${c}`
45
+ ]
46
+ });
47
+ if (f !== "1")
48
+ throw new e({
49
+ field: "version",
50
+ metaMessages: [
51
+ "- Version must be '1'.",
52
+ "",
53
+ `Provided value: ${f}`
54
+ ]
55
+ });
56
+ if (o && !P.test(o))
57
+ throw new e({
58
+ field: "scheme",
59
+ metaMessages: [
60
+ "- Scheme must be an RFC 3986 URI scheme.",
61
+ "- See https://www.rfc-editor.org/rfc/rfc3986#section-3.1",
62
+ "",
63
+ `Provided value: ${o}`
64
+ ]
65
+ });
66
+ const t = n.statement;
67
+ if (t != null && t.includes(`
68
+ `))
69
+ throw new e({
70
+ field: "statement",
71
+ metaMessages: [
72
+ "- Statement must not include '\\n'.",
73
+ "",
74
+ `Provided value: ${t}`
75
+ ]
76
+ });
77
+ }
78
+ const l = S(n.address), v = o ? `${o}://${s}` : s, I = n.statement ? `${n.statement}
79
+ ` : "", R = `${v} wants you to sign in with your Ethereum account:
80
+ ${l}
81
+
82
+ ${I}`;
83
+ let r = `URI: ${c}
84
+ Version: ${f}
85
+ Chain ID: ${i}
86
+ Nonce: ${a}
87
+ Issued At: ${g.toISOString()}`;
88
+ if (u && (r += `
89
+ Expiration Time: ${u.toISOString()}`), m && (r += `
90
+ Not Before: ${m.toISOString()}`), h && (r += `
91
+ Request ID: ${h}`), w) {
92
+ let t = `
93
+ Resources:`;
94
+ for (const d of w) {
95
+ if (!$(d))
96
+ throw new e({
97
+ field: "resources",
98
+ metaMessages: [
99
+ "- Every resource must be a RFC 3986 URI.",
100
+ "- See https://www.rfc-editor.org/rfc/rfc3986",
101
+ "",
102
+ `Provided value: ${d}`
103
+ ]
104
+ });
105
+ t += `
106
+ - ${d}`;
107
+ }
108
+ r += t;
109
+ }
110
+ return `${R}
111
+ ${r}`;
8
112
  }
113
+ const p = /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(:[0-9]{1,5})?$/, M = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:[0-9]{1,5})?$/, x = /^localhost(:[0-9]{1,5})?$/, A = /^[a-zA-Z0-9]{8,}$/, P = /^([a-zA-Z][a-zA-Z0-9+-.]*)$/;
9
114
  export {
10
- u as getBlockNumber
115
+ C as createSiweMessage
11
116
  };
package/dist/index21.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=new Map,c=new Map;function p(o){const a=(s,t)=>({clear:()=>t.delete(s),get:()=>t.get(s),set:n=>t.set(s,n)}),r=a(o,i),e=a(o,c);return{clear:()=>{r.clear(),e.clear()},promise:r,response:e}}async function l(o,{cacheKey:a,cacheTime:r=Number.POSITIVE_INFINITY}){const e=p(a),s=e.response.get();if(s&&r>0&&new Date().getTime()-s.created.getTime()<r)return s.data;let t=e.promise.get();t||(t=o(),e.promise.set(t));try{const n=await t;return e.response.set({created:new Date,data:n}),n}finally{e.promise.clear()}}exports.getCache=p;exports.promiseCache=i;exports.responseCache=c;exports.withCache=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index88.cjs"),a=e.defineChain({id:11155111,name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia.drpc.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io",apiUrl:"https://api-sepolia.etherscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:751532},ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xc8Af999e38273D658BE1b921b88A9Ddf005769cC",blockCreated:5317080}},testnet:!0});exports.sepolia=a;
package/dist/index21.js CHANGED
@@ -1,34 +1,33 @@
1
- const i = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
2
- function p(o) {
3
- const a = (s, t) => ({
4
- clear: () => t.delete(s),
5
- get: () => t.get(s),
6
- set: (r) => t.set(s, r)
7
- }), n = a(o, i), e = a(o, c);
8
- return {
9
- clear: () => {
10
- n.clear(), e.clear();
1
+ import { defineChain as e } from "./index88.js";
2
+ const s = /* @__PURE__ */ e({
3
+ id: 11155111,
4
+ name: "Sepolia",
5
+ nativeCurrency: { name: "Sepolia Ether", symbol: "ETH", decimals: 18 },
6
+ rpcUrls: {
7
+ default: {
8
+ http: ["https://sepolia.drpc.org"]
9
+ }
10
+ },
11
+ blockExplorers: {
12
+ default: {
13
+ name: "Etherscan",
14
+ url: "https://sepolia.etherscan.io",
15
+ apiUrl: "https://api-sepolia.etherscan.io/api"
16
+ }
17
+ },
18
+ contracts: {
19
+ multicall3: {
20
+ address: "0xca11bde05977b3631167028862be2a173976ca11",
21
+ blockCreated: 751532
11
22
  },
12
- promise: n,
13
- response: e
14
- };
15
- }
16
- async function l(o, { cacheKey: a, cacheTime: n = Number.POSITIVE_INFINITY }) {
17
- const e = p(a), s = e.response.get();
18
- if (s && n > 0 && (/* @__PURE__ */ new Date()).getTime() - s.created.getTime() < n)
19
- return s.data;
20
- let t = e.promise.get();
21
- t || (t = o(), e.promise.set(t));
22
- try {
23
- const r = await t;
24
- return e.response.set({ created: /* @__PURE__ */ new Date(), data: r }), r;
25
- } finally {
26
- e.promise.clear();
27
- }
28
- }
23
+ ensRegistry: { address: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e" },
24
+ ensUniversalResolver: {
25
+ address: "0xc8Af999e38273D658BE1b921b88A9Ddf005769cC",
26
+ blockCreated: 5317080
27
+ }
28
+ },
29
+ testnet: !0
30
+ });
29
31
  export {
30
- p as getCache,
31
- i as promiseCache,
32
- c as responseCache,
33
- l as withCache
32
+ s as sepolia
34
33
  };
package/dist/index22.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("./index23.cjs"),u=require("./index18.cjs"),g=require("./index24.cjs");async function l(t,{blockHash:a,blockNumber:n,blockTag:f,hash:r,index:o}){var c,d,m;const s=f||"latest",i=n!==void 0?u.numberToHex(n):void 0;let e=null;if(r?e=await t.request({method:"eth_getTransactionByHash",params:[r]},{dedupe:!0}):a?e=await t.request({method:"eth_getTransactionByBlockHashAndIndex",params:[a,u.numberToHex(o)]},{dedupe:!0}):(i||s)&&(e=await t.request({method:"eth_getTransactionByBlockNumberAndIndex",params:[i||s,u.numberToHex(o)]},{dedupe:!!i})),!e)throw new T.TransactionNotFoundError({blockHash:a,blockNumber:n,blockTag:s,hash:r,index:o});return(((m=(d=(c=t.chain)==null?void 0:c.formatters)==null?void 0:d.transaction)==null?void 0:m.format)||g.formatTransaction)(e)}exports.getTransaction=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./index23.cjs"),m=require("./index24.cjs"),k=require("./index25.cjs");async function B(t,{blockHash:o,blockNumber:r,blockTag:l,includeTransactions:i}={}){var c,s,u;const d=l??"latest",n=i??!1,a=r!==void 0?m.numberToHex(r):void 0;let e=null;if(o?e=await t.request({method:"eth_getBlockByHash",params:[o,n]},{dedupe:!0}):e=await t.request({method:"eth_getBlockByNumber",params:[a||d,n]},{dedupe:!!a}),!e)throw new f.BlockNotFoundError({blockHash:o,blockNumber:r});return(((u=(s=(c=t.chain)==null?void 0:c.formatters)==null?void 0:s.block)==null?void 0:u.format)||k.formatBlock)(e)}exports.getBlock=B;
package/dist/index22.js CHANGED
@@ -1,29 +1,20 @@
1
- import { TransactionNotFoundError as p } from "./index23.js";
2
- import { numberToHex as i } from "./index18.js";
3
- import { formatTransaction as T } from "./index24.js";
4
- async function h(e, { blockHash: a, blockNumber: r, blockTag: c, hash: o, index: n }) {
5
- var d, f, u;
6
- const s = c || "latest", m = r !== void 0 ? i(r) : void 0;
7
- let t = null;
8
- if (o ? t = await e.request({
9
- method: "eth_getTransactionByHash",
10
- params: [o]
11
- }, { dedupe: !0 }) : a ? t = await e.request({
12
- method: "eth_getTransactionByBlockHashAndIndex",
13
- params: [a, i(n)]
14
- }, { dedupe: !0 }) : (m || s) && (t = await e.request({
15
- method: "eth_getTransactionByBlockNumberAndIndex",
16
- params: [m || s, i(n)]
17
- }, { dedupe: !!m })), !t)
18
- throw new p({
19
- blockHash: a,
20
- blockNumber: r,
21
- blockTag: s,
22
- hash: o,
23
- index: n
24
- });
25
- return (((u = (f = (d = e.chain) == null ? void 0 : d.formatters) == null ? void 0 : f.transaction) == null ? void 0 : u.format) || T)(t);
1
+ import { BlockNotFoundError as i } from "./index23.js";
2
+ import { numberToHex as l } from "./index24.js";
3
+ import { formatBlock as p } from "./index25.js";
4
+ async function T(e, { blockHash: t, blockNumber: r, blockTag: f, includeTransactions: u } = {}) {
5
+ var m, s, c;
6
+ const d = f ?? "latest", a = u ?? !1, n = r !== void 0 ? l(r) : void 0;
7
+ let o = null;
8
+ if (t ? o = await e.request({
9
+ method: "eth_getBlockByHash",
10
+ params: [t, a]
11
+ }, { dedupe: !0 }) : o = await e.request({
12
+ method: "eth_getBlockByNumber",
13
+ params: [n || d, a]
14
+ }, { dedupe: !!n }), !o)
15
+ throw new i({ blockHash: t, blockNumber: r });
16
+ return (((c = (s = (m = e.chain) == null ? void 0 : m.formatters) == null ? void 0 : s.block) == null ? void 0 : c.format) || p)(o);
26
17
  }
27
18
  export {
28
- h as getTransaction
19
+ T as getBlock
29
20
  };
package/dist/index23.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index37.cjs");class c extends n.BaseError{constructor({blockHash:r,blockNumber:a,blockTag:i,hash:s,index:o}){let t="Transaction";i&&o!==void 0&&(t=`Transaction at block time "${i}" at index "${o}"`),r&&o!==void 0&&(t=`Transaction at block hash "${r}" at index "${o}"`),a&&o!==void 0&&(t=`Transaction at block number "${a}" at index "${o}"`),s&&(t=`Transaction with hash "${s}"`),super(`${t} could not be found.`,{name:"TransactionNotFoundError"})}}class u extends n.BaseError{constructor({hash:r}){super(`Transaction receipt with hash "${r}" could not be found. The Transaction may not be processed on a block yet.`,{name:"TransactionReceiptNotFoundError"})}}class d extends n.BaseError{constructor({hash:r}){super(`Timed out while waiting for transaction with hash "${r}" to be confirmed.`,{name:"WaitForTransactionReceiptTimeoutError"})}}exports.TransactionNotFoundError=c;exports.TransactionReceiptNotFoundError=u;exports.WaitForTransactionReceiptTimeoutError=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index43.cjs");class n extends t.BaseError{constructor({blockHash:r,blockNumber:e}){let o="Block";r&&(o=`Block at hash "${r}"`),e&&(o=`Block at number "${e}"`),super(`${o} could not be found.`,{name:"BlockNotFoundError"})}}exports.BlockNotFoundError=n;
package/dist/index23.js CHANGED
@@ -1,26 +1,10 @@
1
- import { BaseError as r } from "./index37.js";
2
- class u extends r {
3
- constructor({ blockHash: t, blockNumber: e, blockTag: i, hash: s, index: o }) {
4
- let n = "Transaction";
5
- i && o !== void 0 && (n = `Transaction at block time "${i}" at index "${o}"`), t && o !== void 0 && (n = `Transaction at block hash "${t}" at index "${o}"`), e && o !== void 0 && (n = `Transaction at block number "${e}" at index "${o}"`), s && (n = `Transaction with hash "${s}"`), super(`${n} could not be found.`, {
6
- name: "TransactionNotFoundError"
7
- });
8
- }
9
- }
10
- class d extends r {
11
- constructor({ hash: t }) {
12
- super(`Transaction receipt with hash "${t}" could not be found. The Transaction may not be processed on a block yet.`, {
13
- name: "TransactionReceiptNotFoundError"
14
- });
15
- }
16
- }
17
- class T extends r {
18
- constructor({ hash: t }) {
19
- super(`Timed out while waiting for transaction with hash "${t}" to be confirmed.`, { name: "WaitForTransactionReceiptTimeoutError" });
1
+ import { BaseError as e } from "./index43.js";
2
+ class d extends e {
3
+ constructor({ blockHash: r, blockNumber: t }) {
4
+ let o = "Block";
5
+ r && (o = `Block at hash "${r}"`), t && (o = `Block at number "${t}"`), super(`${o} could not be found.`, { name: "BlockNotFoundError" });
20
6
  }
21
7
  }
22
8
  export {
23
- u as TransactionNotFoundError,
24
- d as TransactionReceiptNotFoundError,
25
- T as WaitForTransactionReceiptTimeoutError
9
+ d as BlockNotFoundError
26
10
  };
package/dist/index24.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index28.cjs"),i={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function u(e){const d={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?r.hexToNumber(e.chainId):void 0,gas:e.gas?BigInt(e.gas):void 0,gasPrice:e.gasPrice?BigInt(e.gasPrice):void 0,maxFeePerBlobGas:e.maxFeePerBlobGas?BigInt(e.maxFeePerBlobGas):void 0,maxFeePerGas:e.maxFeePerGas?BigInt(e.maxFeePerGas):void 0,maxPriorityFeePerGas:e.maxPriorityFeePerGas?BigInt(e.maxPriorityFeePerGas):void 0,nonce:e.nonce?r.hexToNumber(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?i[e.type]:void 0,typeHex:e.type?e.type:void 0,value:e.value?BigInt(e.value):void 0,v:e.v?BigInt(e.v):void 0};return e.authorizationList&&(d.authorizationList=l(e.authorizationList)),d.yParity=(()=>{if(e.yParity)return Number(e.yParity);if(typeof d.v=="bigint"){if(d.v===0n||d.v===27n)return 0;if(d.v===1n||d.v===28n)return 1;if(d.v>=35n)return d.v%2n===0n?1:0}})(),d.type==="legacy"&&(delete d.accessList,delete d.maxFeePerBlobGas,delete d.maxFeePerGas,delete d.maxPriorityFeePerGas,delete d.yParity),d.type==="eip2930"&&(delete d.maxFeePerBlobGas,delete d.maxFeePerGas,delete d.maxPriorityFeePerGas),d.type==="eip1559"&&delete d.maxFeePerBlobGas,d}function l(e){return e.map(d=>({contractAddress:d.address,chainId:Number(d.chainId),nonce:Number(d.nonce),r:d.r,s:d.s,yParity:Number(d.yParity)}))}exports.formatTransaction=u;exports.transactionType=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("./index41.cjs"),f=require("./index42.cjs"),x=require("./index34.cjs"),z=Array.from({length:256},(e,n)=>n.toString(16).padStart(2,"0"));function H(e,n={}){return typeof e=="number"||typeof e=="bigint"?d(e,n):typeof e=="string"?m(e,n):typeof e=="boolean"?b(e,n):u(e,n)}function b(e,n={}){const t=`0x${Number(e)}`;return typeof n.size=="number"?(x.assertSize(t,{size:n.size}),f.pad(t,{size:n.size})):t}function u(e,n={}){let t="";for(let i=0;i<e.length;i++)t+=z[e[i]];const r=`0x${t}`;return typeof n.size=="number"?(x.assertSize(r,{size:n.size}),f.pad(r,{dir:"right",size:n.size})):r}function d(e,n={}){const{signed:t,size:r}=n,i=BigInt(e);let o;r?t?o=(1n<<BigInt(r)*8n-1n)-1n:o=2n**(BigInt(r)*8n)-1n:typeof e=="number"&&(o=BigInt(Number.MAX_SAFE_INTEGER));const c=typeof o=="bigint"&&t?-o-1n:0;if(o&&i>o||i<c){const s=typeof e=="bigint"?"n":"";throw new y.IntegerOutOfRangeError({max:o?`${o}${s}`:void 0,min:`${c}${s}`,signed:t,size:r,value:`${e}${s}`})}const g=`0x${(t&&i<0?(1n<<BigInt(r*8))+BigInt(i):i).toString(16)}`;return r?f.pad(g,{size:r}):g}const T=new TextEncoder;function m(e,n={}){const t=T.encode(e);return u(t,n)}exports.boolToHex=b;exports.bytesToHex=u;exports.numberToHex=d;exports.stringToHex=m;exports.toHex=H;
package/dist/index24.js CHANGED
@@ -1,54 +1,48 @@
1
- import { hexToNumber as i } from "./index28.js";
2
- const r = {
3
- "0x0": "legacy",
4
- "0x1": "eip2930",
5
- "0x2": "eip1559",
6
- "0x3": "eip4844",
7
- "0x4": "eip7702"
8
- };
9
- function m(e) {
10
- const d = {
11
- ...e,
12
- blockHash: e.blockHash ? e.blockHash : null,
13
- blockNumber: e.blockNumber ? BigInt(e.blockNumber) : null,
14
- chainId: e.chainId ? i(e.chainId) : void 0,
15
- gas: e.gas ? BigInt(e.gas) : void 0,
16
- gasPrice: e.gasPrice ? BigInt(e.gasPrice) : void 0,
17
- maxFeePerBlobGas: e.maxFeePerBlobGas ? BigInt(e.maxFeePerBlobGas) : void 0,
18
- maxFeePerGas: e.maxFeePerGas ? BigInt(e.maxFeePerGas) : void 0,
19
- maxPriorityFeePerGas: e.maxPriorityFeePerGas ? BigInt(e.maxPriorityFeePerGas) : void 0,
20
- nonce: e.nonce ? i(e.nonce) : void 0,
21
- to: e.to ? e.to : null,
22
- transactionIndex: e.transactionIndex ? Number(e.transactionIndex) : null,
23
- type: e.type ? r[e.type] : void 0,
24
- typeHex: e.type ? e.type : void 0,
25
- value: e.value ? BigInt(e.value) : void 0,
26
- v: e.v ? BigInt(e.v) : void 0
27
- };
28
- return e.authorizationList && (d.authorizationList = u(e.authorizationList)), d.yParity = (() => {
29
- if (e.yParity)
30
- return Number(e.yParity);
31
- if (typeof d.v == "bigint") {
32
- if (d.v === 0n || d.v === 27n)
33
- return 0;
34
- if (d.v === 1n || d.v === 28n)
35
- return 1;
36
- if (d.v >= 35n)
37
- return d.v % 2n === 0n ? 1 : 0;
38
- }
39
- })(), d.type === "legacy" && (delete d.accessList, delete d.maxFeePerBlobGas, delete d.maxFeePerGas, delete d.maxPriorityFeePerGas, delete d.yParity), d.type === "eip2930" && (delete d.maxFeePerBlobGas, delete d.maxFeePerGas, delete d.maxPriorityFeePerGas), d.type === "eip1559" && delete d.maxFeePerBlobGas, d;
1
+ import { IntegerOutOfRangeError as x } from "./index41.js";
2
+ import { pad as s } from "./index42.js";
3
+ import { assertSize as c } from "./index34.js";
4
+ const b = /* @__PURE__ */ Array.from({ length: 256 }, (n, e) => e.toString(16).padStart(2, "0"));
5
+ function B(n, e = {}) {
6
+ return typeof n == "number" || typeof n == "bigint" ? y(n, e) : typeof n == "string" ? $(n, e) : typeof n == "boolean" ? z(n, e) : m(n, e);
7
+ }
8
+ function z(n, e = {}) {
9
+ const t = `0x${Number(n)}`;
10
+ return typeof e.size == "number" ? (c(t, { size: e.size }), s(t, { size: e.size })) : t;
11
+ }
12
+ function m(n, e = {}) {
13
+ let t = "";
14
+ for (let i = 0; i < n.length; i++)
15
+ t += b[n[i]];
16
+ const r = `0x${t}`;
17
+ return typeof e.size == "number" ? (c(r, { size: e.size }), s(r, { dir: "right", size: e.size })) : r;
18
+ }
19
+ function y(n, e = {}) {
20
+ const { signed: t, size: r } = e, i = BigInt(n);
21
+ let o;
22
+ r ? t ? o = (1n << BigInt(r) * 8n - 1n) - 1n : o = 2n ** (BigInt(r) * 8n) - 1n : typeof n == "number" && (o = BigInt(Number.MAX_SAFE_INTEGER));
23
+ const g = typeof o == "bigint" && t ? -o - 1n : 0;
24
+ if (o && i > o || i < g) {
25
+ const f = typeof n == "bigint" ? "n" : "";
26
+ throw new x({
27
+ max: o ? `${o}${f}` : void 0,
28
+ min: `${g}${f}`,
29
+ signed: t,
30
+ size: r,
31
+ value: `${n}${f}`
32
+ });
33
+ }
34
+ const u = `0x${(t && i < 0 ? (1n << BigInt(r * 8)) + BigInt(i) : i).toString(16)}`;
35
+ return r ? s(u, { size: r }) : u;
40
36
  }
41
- function u(e) {
42
- return e.map((d) => ({
43
- contractAddress: d.address,
44
- chainId: Number(d.chainId),
45
- nonce: Number(d.nonce),
46
- r: d.r,
47
- s: d.s,
48
- yParity: Number(d.yParity)
49
- }));
37
+ const d = /* @__PURE__ */ new TextEncoder();
38
+ function $(n, e = {}) {
39
+ const t = d.encode(n);
40
+ return m(t, e);
50
41
  }
51
42
  export {
52
- m as formatTransaction,
53
- r as transactionType
43
+ z as boolToHex,
44
+ m as bytesToHex,
45
+ y as numberToHex,
46
+ $ as stringToHex,
47
+ B as toHex
54
48
  };
package/dist/index25.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./index23.cjs"),i=require("./index26.cjs");async function s(t,{hash:e}){var a,n,o;const r=await t.request({method:"eth_getTransactionReceipt",params:[e]},{dedupe:!0});if(!r)throw new c.TransactionReceiptNotFoundError({hash:e});return(((o=(n=(a=t.chain)==null?void 0:a.formatters)==null?void 0:n.transactionReceipt)==null?void 0:o.format)||i.formatTransactionReceipt)(r)}exports.getTransactionReceipt=s;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index30.cjs");function i(e){const s=(e.transactions??[]).map(n=>typeof n=="string"?n:t.formatTransaction(n));return{...e,baseFeePerGas:e.baseFeePerGas?BigInt(e.baseFeePerGas):null,blobGasUsed:e.blobGasUsed?BigInt(e.blobGasUsed):void 0,difficulty:e.difficulty?BigInt(e.difficulty):void 0,excessBlobGas:e.excessBlobGas?BigInt(e.excessBlobGas):void 0,gasLimit:e.gasLimit?BigInt(e.gasLimit):void 0,gasUsed:e.gasUsed?BigInt(e.gasUsed):void 0,hash:e.hash?e.hash:null,logsBloom:e.logsBloom?e.logsBloom:null,nonce:e.nonce?e.nonce:null,number:e.number?BigInt(e.number):null,size:e.size?BigInt(e.size):void 0,timestamp:e.timestamp?BigInt(e.timestamp):void 0,transactions:s,totalDifficulty:e.totalDifficulty?BigInt(e.totalDifficulty):null}}exports.formatBlock=i;
package/dist/index25.js CHANGED
@@ -1,15 +1,24 @@
1
- import { TransactionReceiptNotFoundError as i } from "./index23.js";
2
- import { formatTransactionReceipt as c } from "./index26.js";
3
- async function f(t, { hash: r }) {
4
- var o, a, n;
5
- const e = await t.request({
6
- method: "eth_getTransactionReceipt",
7
- params: [r]
8
- }, { dedupe: !0 });
9
- if (!e)
10
- throw new i({ hash: r });
11
- return (((n = (a = (o = t.chain) == null ? void 0 : o.formatters) == null ? void 0 : a.transactionReceipt) == null ? void 0 : n.format) || c)(e);
1
+ import { formatTransaction as i } from "./index30.js";
2
+ function a(e) {
3
+ const s = (e.transactions ?? []).map((n) => typeof n == "string" ? n : i(n));
4
+ return {
5
+ ...e,
6
+ baseFeePerGas: e.baseFeePerGas ? BigInt(e.baseFeePerGas) : null,
7
+ blobGasUsed: e.blobGasUsed ? BigInt(e.blobGasUsed) : void 0,
8
+ difficulty: e.difficulty ? BigInt(e.difficulty) : void 0,
9
+ excessBlobGas: e.excessBlobGas ? BigInt(e.excessBlobGas) : void 0,
10
+ gasLimit: e.gasLimit ? BigInt(e.gasLimit) : void 0,
11
+ gasUsed: e.gasUsed ? BigInt(e.gasUsed) : void 0,
12
+ hash: e.hash ? e.hash : null,
13
+ logsBloom: e.logsBloom ? e.logsBloom : null,
14
+ nonce: e.nonce ? e.nonce : null,
15
+ number: e.number ? BigInt(e.number) : null,
16
+ size: e.size ? BigInt(e.size) : void 0,
17
+ timestamp: e.timestamp ? BigInt(e.timestamp) : void 0,
18
+ transactions: s,
19
+ totalDifficulty: e.totalDifficulty ? BigInt(e.totalDifficulty) : null
20
+ };
12
21
  }
13
22
  export {
14
- f as getTransactionReceipt
23
+ a as formatBlock
15
24
  };
package/dist/index26.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./index28.cjs"),d=require("./index40.cjs"),r=require("./index24.cjs"),u={"0x0":"reverted","0x1":"success"};function o(l){const s={...l,blockNumber:l.blockNumber?BigInt(l.blockNumber):null,contractAddress:l.contractAddress?l.contractAddress:null,cumulativeGasUsed:l.cumulativeGasUsed?BigInt(l.cumulativeGasUsed):null,effectiveGasPrice:l.effectiveGasPrice?BigInt(l.effectiveGasPrice):null,gasUsed:l.gasUsed?BigInt(l.gasUsed):null,logs:l.logs?l.logs.map(e=>d.formatLog(e)):null,to:l.to?l.to:null,transactionIndex:l.transactionIndex?b.hexToNumber(l.transactionIndex):null,status:l.status?u[l.status]:null,type:l.type?r.transactionType[l.type]||l.type:null};return l.blobGasPrice&&(s.blobGasPrice=BigInt(l.blobGasPrice)),l.blobGasUsed&&(s.blobGasUsed=BigInt(l.blobGasUsed)),s}exports.formatTransactionReceipt=o;exports.receiptStatuses=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index27.cjs"),r=e=>`blockNumber.${e}`;async function u(e,{cacheTime:c=e.cacheTime}={}){const t=await o.withCache(()=>e.request({method:"eth_blockNumber"}),{cacheKey:r(e.uid),cacheTime:c});return BigInt(t)}exports.getBlockNumber=u;
package/dist/index26.js CHANGED
@@ -1,27 +1,11 @@
1
- import { hexToNumber as b } from "./index28.js";
2
- import { formatLog as d } from "./index40.js";
3
- import { transactionType as m } from "./index24.js";
4
- const f = {
5
- "0x0": "reverted",
6
- "0x1": "success"
7
- };
8
- function r(l) {
9
- const u = {
10
- ...l,
11
- blockNumber: l.blockNumber ? BigInt(l.blockNumber) : null,
12
- contractAddress: l.contractAddress ? l.contractAddress : null,
13
- cumulativeGasUsed: l.cumulativeGasUsed ? BigInt(l.cumulativeGasUsed) : null,
14
- effectiveGasPrice: l.effectiveGasPrice ? BigInt(l.effectiveGasPrice) : null,
15
- gasUsed: l.gasUsed ? BigInt(l.gasUsed) : null,
16
- logs: l.logs ? l.logs.map((s) => d(s)) : null,
17
- to: l.to ? l.to : null,
18
- transactionIndex: l.transactionIndex ? b(l.transactionIndex) : null,
19
- status: l.status ? f[l.status] : null,
20
- type: l.type ? m[l.type] || l.type : null
21
- };
22
- return l.blobGasPrice && (u.blobGasPrice = BigInt(l.blobGasPrice)), l.blobGasUsed && (u.blobGasUsed = BigInt(l.blobGasUsed)), u;
1
+ import { withCache as t } from "./index27.js";
2
+ const r = (e) => `blockNumber.${e}`;
3
+ async function u(e, { cacheTime: c = e.cacheTime } = {}) {
4
+ const o = await t(() => e.request({
5
+ method: "eth_blockNumber"
6
+ }), { cacheKey: r(e.uid), cacheTime: c });
7
+ return BigInt(o);
23
8
  }
24
9
  export {
25
- r as formatTransactionReceipt,
26
- f as receiptStatuses
10
+ u as getBlockNumber
27
11
  };
package/dist/index27.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./index28.cjs"),d=require("./index29.cjs"),y=require("./index30.cjs"),h=require("./index31.cjs"),B=require("./index32.cjs"),m=require("./index20.cjs");function q(t,{emitOnBegin:b=!1,emitMissed:l=!1,onBlockNumber:p,onError:a,poll:k,pollingInterval:i=t.pollingInterval}){const g=typeof k<"u"?k:!(t.transport.type==="webSocket"||t.transport.type==="fallback"&&t.transport.transports[0].config.type==="webSocket");let r;return g?(()=>{const f=B.stringify(["watchBlockNumber",t.uid,b,l,i]);return y.observe(f,{onBlockNumber:p,onError:a},o=>h.poll(async()=>{var c;try{const e=await d.getAction(t,m.getBlockNumber,"getBlockNumber")({cacheTime:0});if(r){if(e===r)return;if(e-r>1&&l)for(let s=r+1n;s<e;s++)o.onBlockNumber(s,r),r=s}(!r||e>r)&&(o.onBlockNumber(e,r),r=e)}catch(e){(c=o.onError)==null||c.call(o,e)}},{emitOnBegin:b,interval:i}))})():(()=>{const f=B.stringify(["watchBlockNumber",t.uid,b,l]);return y.observe(f,{onBlockNumber:p,onError:a},o=>{let c=!0,e=()=>c=!1;return(async()=>{try{const s=(()=>{if(t.transport.type==="fallback"){const n=t.transport.transports.find(u=>u.config.type==="webSocket");return n?n.value:t.transport}return t.transport})(),{unsubscribe:v}=await s.subscribe({params:["newHeads"],onData(n){var N;if(!c)return;const u=w.hexToBigInt((N=n.result)==null?void 0:N.number);o.onBlockNumber(u,r),r=u},onError(n){var u;(u=o.onError)==null||u.call(o,n)}});e=v,c||e()}catch(s){a==null||a(s)}})(),()=>e()})})()}exports.watchBlockNumber=q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=new Map,c=new Map;function p(o){const a=(s,t)=>({clear:()=>t.delete(s),get:()=>t.get(s),set:n=>t.set(s,n)}),r=a(o,i),e=a(o,c);return{clear:()=>{r.clear(),e.clear()},promise:r,response:e}}async function l(o,{cacheKey:a,cacheTime:r=Number.POSITIVE_INFINITY}){const e=p(a),s=e.response.get();if(s&&r>0&&new Date().getTime()-s.created.getTime()<r)return s.data;let t=e.promise.get();t||(t=o(),e.promise.set(t));try{const n=await t;return e.response.set({created:new Date,data:n}),n}finally{e.promise.clear()}}exports.getCache=p;exports.promiseCache=i;exports.responseCache=c;exports.withCache=l;
package/dist/index27.js CHANGED
@@ -1,78 +1,34 @@
1
- import { hexToBigInt as h } from "./index28.js";
2
- import { getAction as v } from "./index29.js";
3
- import { observe as i } from "./index30.js";
4
- import { poll as d } from "./index31.js";
5
- import { stringify as y } from "./index32.js";
6
- import { getBlockNumber as g } from "./index20.js";
7
- function j(t, { emitOnBegin: b = !1, emitMissed: f = !1, onBlockNumber: p, onError: n, poll: k, pollingInterval: m = t.pollingInterval }) {
8
- const B = typeof k < "u" ? k : !(t.transport.type === "webSocket" || t.transport.type === "fallback" && t.transport.transports[0].config.type === "webSocket");
9
- let r;
10
- return B ? (() => {
11
- const l = y([
12
- "watchBlockNumber",
13
- t.uid,
14
- b,
15
- f,
16
- m
17
- ]);
18
- return i(l, { onBlockNumber: p, onError: n }, (e) => d(async () => {
19
- var a;
20
- try {
21
- const o = await v(t, g, "getBlockNumber")({ cacheTime: 0 });
22
- if (r) {
23
- if (o === r)
24
- return;
25
- if (o - r > 1 && f)
26
- for (let s = r + 1n; s < o; s++)
27
- e.onBlockNumber(s, r), r = s;
28
- }
29
- (!r || o > r) && (e.onBlockNumber(o, r), r = o);
30
- } catch (o) {
31
- (a = e.onError) == null || a.call(e, o);
32
- }
33
- }, {
34
- emitOnBegin: b,
35
- interval: m
36
- }));
37
- })() : (() => {
38
- const l = y([
39
- "watchBlockNumber",
40
- t.uid,
41
- b,
42
- f
43
- ]);
44
- return i(l, { onBlockNumber: p, onError: n }, (e) => {
45
- let a = !0, o = () => a = !1;
46
- return (async () => {
47
- try {
48
- const s = (() => {
49
- if (t.transport.type === "fallback") {
50
- const c = t.transport.transports.find((u) => u.config.type === "webSocket");
51
- return c ? c.value : t.transport;
52
- }
53
- return t.transport;
54
- })(), { unsubscribe: w } = await s.subscribe({
55
- params: ["newHeads"],
56
- onData(c) {
57
- var N;
58
- if (!a)
59
- return;
60
- const u = h((N = c.result) == null ? void 0 : N.number);
61
- e.onBlockNumber(u, r), r = u;
62
- },
63
- onError(c) {
64
- var u;
65
- (u = e.onError) == null || u.call(e, c);
66
- }
67
- });
68
- o = w, a || o();
69
- } catch (s) {
70
- n == null || n(s);
71
- }
72
- })(), () => o();
73
- });
74
- })();
1
+ const i = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
2
+ function p(o) {
3
+ const a = (s, t) => ({
4
+ clear: () => t.delete(s),
5
+ get: () => t.get(s),
6
+ set: (r) => t.set(s, r)
7
+ }), n = a(o, i), e = a(o, c);
8
+ return {
9
+ clear: () => {
10
+ n.clear(), e.clear();
11
+ },
12
+ promise: n,
13
+ response: e
14
+ };
15
+ }
16
+ async function l(o, { cacheKey: a, cacheTime: n = Number.POSITIVE_INFINITY }) {
17
+ const e = p(a), s = e.response.get();
18
+ if (s && n > 0 && (/* @__PURE__ */ new Date()).getTime() - s.created.getTime() < n)
19
+ return s.data;
20
+ let t = e.promise.get();
21
+ t || (t = o(), e.promise.set(t));
22
+ try {
23
+ const r = await t;
24
+ return e.response.set({ created: /* @__PURE__ */ new Date(), data: r }), r;
25
+ } finally {
26
+ e.promise.clear();
27
+ }
75
28
  }
76
29
  export {
77
- j as watchBlockNumber
30
+ p as getCache,
31
+ i as promiseCache,
32
+ c as responseCache,
33
+ l as withCache
78
34
  };