@aztec/foundation 0.6.7 → 0.7.2

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 (351) hide show
  1. package/Dockerfile +15 -0
  2. package/package.json +1 -1
  3. package/src/abi/abi.ts +1 -1
  4. package/src/abi/decoder.test.ts +77 -0
  5. package/src/abi/decoder.ts +33 -10
  6. package/.tsbuildinfo +0 -1
  7. package/dest/abi/abi.d.ts +0 -232
  8. package/dest/abi/abi.d.ts.map +0 -1
  9. package/dest/abi/abi.js +0 -37
  10. package/dest/abi/abi_coder.d.ts +0 -8
  11. package/dest/abi/abi_coder.d.ts.map +0 -1
  12. package/dest/abi/abi_coder.js +0 -24
  13. package/dest/abi/decoder.d.ts +0 -42
  14. package/dest/abi/decoder.d.ts.map +0 -1
  15. package/dest/abi/decoder.js +0 -129
  16. package/dest/abi/encoder.d.ts +0 -10
  17. package/dest/abi/encoder.d.ts.map +0 -1
  18. package/dest/abi/encoder.js +0 -89
  19. package/dest/abi/encoder.test.d.ts +0 -2
  20. package/dest/abi/encoder.test.d.ts.map +0 -1
  21. package/dest/abi/encoder.test.js +0 -74
  22. package/dest/abi/function_selector.d.ts +0 -73
  23. package/dest/abi/function_selector.d.ts.map +0 -1
  24. package/dest/abi/function_selector.js +0 -104
  25. package/dest/abi/index.d.ts +0 -6
  26. package/dest/abi/index.d.ts.map +0 -1
  27. package/dest/abi/index.js +0 -6
  28. package/dest/async-map/async_map.test.d.ts +0 -2
  29. package/dest/async-map/async_map.test.d.ts.map +0 -1
  30. package/dest/async-map/async_map.test.js +0 -9
  31. package/dest/async-map/index.d.ts +0 -13
  32. package/dest/async-map/index.d.ts.map +0 -1
  33. package/dest/async-map/index.js +0 -19
  34. package/dest/aztec-address/index.d.ts +0 -114
  35. package/dest/aztec-address/index.d.ts.map +0 -1
  36. package/dest/aztec-address/index.js +0 -148
  37. package/dest/bigint-buffer/bigint-buffer.test.d.ts +0 -2
  38. package/dest/bigint-buffer/bigint-buffer.test.d.ts.map +0 -1
  39. package/dest/bigint-buffer/bigint-buffer.test.js +0 -18
  40. package/dest/bigint-buffer/index.d.ts +0 -35
  41. package/dest/bigint-buffer/index.d.ts.map +0 -1
  42. package/dest/bigint-buffer/index.js +0 -68
  43. package/dest/collection/array.d.ts +0 -30
  44. package/dest/collection/array.d.ts.map +0 -1
  45. package/dest/collection/array.js +0 -47
  46. package/dest/collection/index.d.ts +0 -2
  47. package/dest/collection/index.d.ts.map +0 -1
  48. package/dest/collection/index.js +0 -2
  49. package/dest/committable/committable.d.ts +0 -28
  50. package/dest/committable/committable.d.ts.map +0 -1
  51. package/dest/committable/committable.js +0 -41
  52. package/dest/committable/committable.test.d.ts +0 -2
  53. package/dest/committable/committable.test.d.ts.map +0 -1
  54. package/dest/committable/committable.test.js +0 -26
  55. package/dest/committable/index.d.ts +0 -2
  56. package/dest/committable/index.d.ts.map +0 -1
  57. package/dest/committable/index.js +0 -2
  58. package/dest/crypto/index.d.ts +0 -4
  59. package/dest/crypto/index.d.ts.map +0 -1
  60. package/dest/crypto/index.js +0 -4
  61. package/dest/crypto/keccak/index.d.ts +0 -20
  62. package/dest/crypto/keccak/index.d.ts.map +0 -1
  63. package/dest/crypto/keccak/index.js +0 -31
  64. package/dest/crypto/random/index.d.ts +0 -3
  65. package/dest/crypto/random/index.d.ts.map +0 -1
  66. package/dest/crypto/random/index.js +0 -36
  67. package/dest/crypto/random/index.test.d.ts +0 -2
  68. package/dest/crypto/random/index.test.d.ts.map +0 -1
  69. package/dest/crypto/random/index.test.js +0 -13
  70. package/dest/crypto/sha256/index.d.ts +0 -11
  71. package/dest/crypto/sha256/index.d.ts.map +0 -1
  72. package/dest/crypto/sha256/index.js +0 -14
  73. package/dest/crypto/sha256/index.test.d.ts +0 -2
  74. package/dest/crypto/sha256/index.test.d.ts.map +0 -1
  75. package/dest/crypto/sha256/index.test.js +0 -11
  76. package/dest/errors/index.d.ts +0 -8
  77. package/dest/errors/index.d.ts.map +0 -1
  78. package/dest/errors/index.js +0 -8
  79. package/dest/eth-address/eth_address.test.d.ts +0 -2
  80. package/dest/eth-address/eth_address.test.d.ts.map +0 -1
  81. package/dest/eth-address/eth_address.test.js +0 -95
  82. package/dest/eth-address/index.d.ts +0 -144
  83. package/dest/eth-address/index.d.ts.map +0 -1
  84. package/dest/eth-address/index.js +0 -228
  85. package/dest/fields/coordinate.d.ts +0 -67
  86. package/dest/fields/coordinate.d.ts.map +0 -1
  87. package/dest/fields/coordinate.js +0 -95
  88. package/dest/fields/coordinate.test.d.ts +0 -2
  89. package/dest/fields/coordinate.test.d.ts.map +0 -1
  90. package/dest/fields/coordinate.test.js +0 -22
  91. package/dest/fields/fields.d.ts +0 -177
  92. package/dest/fields/fields.d.ts.map +0 -1
  93. package/dest/fields/fields.js +0 -219
  94. package/dest/fields/grumpkin_scalar.d.ts +0 -96
  95. package/dest/fields/grumpkin_scalar.d.ts.map +0 -1
  96. package/dest/fields/grumpkin_scalar.js +0 -125
  97. package/dest/fields/grumpkin_scalar.test.d.ts +0 -2
  98. package/dest/fields/grumpkin_scalar.test.d.ts.map +0 -1
  99. package/dest/fields/grumpkin_scalar.test.js +0 -45
  100. package/dest/fields/index.d.ts +0 -5
  101. package/dest/fields/index.d.ts.map +0 -1
  102. package/dest/fields/index.js +0 -5
  103. package/dest/fields/point.d.ts +0 -105
  104. package/dest/fields/point.d.ts.map +0 -1
  105. package/dest/fields/point.js +0 -125
  106. package/dest/fifo/bounded_serial_queue.d.ts +0 -56
  107. package/dest/fifo/bounded_serial_queue.d.ts.map +0 -1
  108. package/dest/fifo/bounded_serial_queue.js +0 -94
  109. package/dest/fifo/index.d.ts +0 -5
  110. package/dest/fifo/index.d.ts.map +0 -1
  111. package/dest/fifo/index.js +0 -5
  112. package/dest/fifo/memory_fifo.d.ts +0 -55
  113. package/dest/fifo/memory_fifo.d.ts.map +0 -1
  114. package/dest/fifo/memory_fifo.js +0 -109
  115. package/dest/fifo/semaphore.d.ts +0 -23
  116. package/dest/fifo/semaphore.d.ts.map +0 -1
  117. package/dest/fifo/semaphore.js +0 -30
  118. package/dest/fifo/serial_queue.d.ts +0 -48
  119. package/dest/fifo/serial_queue.d.ts.map +0 -1
  120. package/dest/fifo/serial_queue.js +0 -74
  121. package/dest/json-rpc/class_converter.d.ts +0 -144
  122. package/dest/json-rpc/class_converter.d.ts.map +0 -1
  123. package/dest/json-rpc/class_converter.js +0 -100
  124. package/dest/json-rpc/client/index.d.ts +0 -2
  125. package/dest/json-rpc/client/index.d.ts.map +0 -1
  126. package/dest/json-rpc/client/index.js +0 -2
  127. package/dest/json-rpc/client/json_rpc_client.d.ts +0 -29
  128. package/dest/json-rpc/client/json_rpc_client.d.ts.map +0 -1
  129. package/dest/json-rpc/client/json_rpc_client.js +0 -104
  130. package/dest/json-rpc/client/json_rpc_client.test.d.ts +0 -2
  131. package/dest/json-rpc/client/json_rpc_client.test.d.ts.map +0 -1
  132. package/dest/json-rpc/client/json_rpc_client.test.js +0 -20
  133. package/dest/json-rpc/convert.d.ts +0 -28
  134. package/dest/json-rpc/convert.d.ts.map +0 -1
  135. package/dest/json-rpc/convert.js +0 -139
  136. package/dest/json-rpc/convert.test.d.ts +0 -2
  137. package/dest/json-rpc/convert.test.d.ts.map +0 -1
  138. package/dest/json-rpc/convert.test.js +0 -68
  139. package/dest/json-rpc/fixtures/class_a.d.ts +0 -11
  140. package/dest/json-rpc/fixtures/class_a.d.ts.map +0 -1
  141. package/dest/json-rpc/fixtures/class_a.js +0 -17
  142. package/dest/json-rpc/fixtures/class_b.d.ts +0 -11
  143. package/dest/json-rpc/fixtures/class_b.d.ts.map +0 -1
  144. package/dest/json-rpc/fixtures/class_b.js +0 -17
  145. package/dest/json-rpc/fixtures/test_state.d.ts +0 -47
  146. package/dest/json-rpc/fixtures/test_state.d.ts.map +0 -1
  147. package/dest/json-rpc/fixtures/test_state.js +0 -62
  148. package/dest/json-rpc/index.d.ts +0 -3
  149. package/dest/json-rpc/index.d.ts.map +0 -1
  150. package/dest/json-rpc/index.js +0 -3
  151. package/dest/json-rpc/js_utils.d.ts +0 -13
  152. package/dest/json-rpc/js_utils.d.ts.map +0 -1
  153. package/dest/json-rpc/js_utils.js +0 -18
  154. package/dest/json-rpc/server/index.d.ts +0 -3
  155. package/dest/json-rpc/server/index.d.ts.map +0 -1
  156. package/dest/json-rpc/server/index.js +0 -3
  157. package/dest/json-rpc/server/json_proxy.d.ts +0 -18
  158. package/dest/json-rpc/server/json_proxy.d.ts.map +0 -1
  159. package/dest/json-rpc/server/json_proxy.js +0 -36
  160. package/dest/json-rpc/server/json_rpc_server.d.ts +0 -34
  161. package/dest/json-rpc/server/json_rpc_server.d.ts.map +0 -1
  162. package/dest/json-rpc/server/json_rpc_server.js +0 -133
  163. package/dest/json-rpc/server/json_rpc_server.test.d.ts +0 -2
  164. package/dest/json-rpc/server/json_rpc_server.test.d.ts.map +0 -1
  165. package/dest/json-rpc/server/json_rpc_server.test.js +0 -22
  166. package/dest/log/console.d.ts +0 -11
  167. package/dest/log/console.d.ts.map +0 -1
  168. package/dest/log/console.js +0 -38
  169. package/dest/log/debug.d.ts +0 -43
  170. package/dest/log/debug.d.ts.map +0 -1
  171. package/dest/log/debug.js +0 -75
  172. package/dest/log/index.d.ts +0 -9
  173. package/dest/log/index.d.ts.map +0 -1
  174. package/dest/log/index.js +0 -5
  175. package/dest/log/log_history.d.ts +0 -31
  176. package/dest/log/log_history.d.ts.map +0 -1
  177. package/dest/log/log_history.js +0 -42
  178. package/dest/log/log_history.test.d.ts +0 -2
  179. package/dest/log/log_history.test.d.ts.map +0 -1
  180. package/dest/log/log_history.test.js +0 -78
  181. package/dest/log/logger.d.ts +0 -34
  182. package/dest/log/logger.d.ts.map +0 -1
  183. package/dest/log/logger.js +0 -78
  184. package/dest/mutex/index.d.ts +0 -53
  185. package/dest/mutex/index.d.ts.map +0 -1
  186. package/dest/mutex/index.js +0 -74
  187. package/dest/mutex/mutex.test.d.ts +0 -9
  188. package/dest/mutex/mutex.test.d.ts.map +0 -1
  189. package/dest/mutex/mutex.test.js +0 -58
  190. package/dest/mutex/mutex_database.d.ts +0 -10
  191. package/dest/mutex/mutex_database.d.ts.map +0 -1
  192. package/dest/mutex/mutex_database.js +0 -2
  193. package/dest/retry/index.d.ts +0 -44
  194. package/dest/retry/index.d.ts.map +0 -1
  195. package/dest/retry/index.js +0 -89
  196. package/dest/running-promise/index.d.ts +0 -35
  197. package/dest/running-promise/index.d.ts.map +0 -1
  198. package/dest/running-promise/index.js +0 -59
  199. package/dest/serialize/buffer_reader.d.ts +0 -188
  200. package/dest/serialize/buffer_reader.d.ts.map +0 -1
  201. package/dest/serialize/buffer_reader.js +0 -229
  202. package/dest/serialize/buffer_reader.test.d.ts +0 -2
  203. package/dest/serialize/buffer_reader.test.d.ts.map +0 -1
  204. package/dest/serialize/buffer_reader.test.js +0 -156
  205. package/dest/serialize/deserializer.d.ts +0 -134
  206. package/dest/serialize/deserializer.d.ts.map +0 -1
  207. package/dest/serialize/deserializer.js +0 -145
  208. package/dest/serialize/free_funcs.d.ts +0 -203
  209. package/dest/serialize/free_funcs.d.ts.map +0 -1
  210. package/dest/serialize/free_funcs.js +0 -250
  211. package/dest/serialize/index.d.ts +0 -6
  212. package/dest/serialize/index.d.ts.map +0 -1
  213. package/dest/serialize/index.js +0 -6
  214. package/dest/serialize/serialize.test.d.ts +0 -2
  215. package/dest/serialize/serialize.test.d.ts.map +0 -1
  216. package/dest/serialize/serialize.test.js +0 -68
  217. package/dest/serialize/serializer.d.ts +0 -89
  218. package/dest/serialize/serializer.d.ts.map +0 -1
  219. package/dest/serialize/serializer.js +0 -111
  220. package/dest/serialize/types.d.ts +0 -33
  221. package/dest/serialize/types.d.ts.map +0 -1
  222. package/dest/serialize/types.js +0 -22
  223. package/dest/sleep/index.d.ts +0 -52
  224. package/dest/sleep/index.d.ts.map +0 -1
  225. package/dest/sleep/index.js +0 -70
  226. package/dest/timer/index.d.ts +0 -3
  227. package/dest/timer/index.d.ts.map +0 -1
  228. package/dest/timer/index.js +0 -3
  229. package/dest/timer/timeout.d.ts +0 -41
  230. package/dest/timer/timeout.d.ts.map +0 -1
  231. package/dest/timer/timeout.js +0 -62
  232. package/dest/timer/timer.d.ts +0 -33
  233. package/dest/timer/timer.d.ts.map +0 -1
  234. package/dest/timer/timer.js +0 -38
  235. package/dest/transport/browser/index.d.ts +0 -5
  236. package/dest/transport/browser/index.d.ts.map +0 -1
  237. package/dest/transport/browser/index.js +0 -5
  238. package/dest/transport/browser/message_port_socket.d.ts +0 -37
  239. package/dest/transport/browser/message_port_socket.d.ts.map +0 -1
  240. package/dest/transport/browser/message_port_socket.js +0 -46
  241. package/dest/transport/browser/shared_worker_connector.d.ts +0 -19
  242. package/dest/transport/browser/shared_worker_connector.d.ts.map +0 -1
  243. package/dest/transport/browser/shared_worker_connector.js +0 -21
  244. package/dest/transport/browser/shared_worker_listener.d.ts +0 -38
  245. package/dest/transport/browser/shared_worker_listener.d.ts.map +0 -1
  246. package/dest/transport/browser/shared_worker_listener.js +0 -37
  247. package/dest/transport/browser/worker_connector.d.ts +0 -26
  248. package/dest/transport/browser/worker_connector.d.ts.map +0 -1
  249. package/dest/transport/browser/worker_connector.js +0 -30
  250. package/dest/transport/browser/worker_listener.d.ts +0 -39
  251. package/dest/transport/browser/worker_listener.d.ts.map +0 -1
  252. package/dest/transport/browser/worker_listener.js +0 -39
  253. package/dest/transport/dispatch/create_dispatch_fn.d.ts +0 -25
  254. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +0 -1
  255. package/dest/transport/dispatch/create_dispatch_fn.js +0 -18
  256. package/dest/transport/dispatch/create_dispatch_proxy.d.ts +0 -102
  257. package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +0 -1
  258. package/dest/transport/dispatch/create_dispatch_proxy.js +0 -56
  259. package/dest/transport/dispatch/messages.d.ts +0 -52
  260. package/dest/transport/dispatch/messages.d.ts.map +0 -1
  261. package/dest/transport/dispatch/messages.js +0 -12
  262. package/dest/transport/index.d.ts +0 -12
  263. package/dest/transport/index.d.ts.map +0 -1
  264. package/dest/transport/index.js +0 -12
  265. package/dest/transport/interface/connector.d.ts +0 -8
  266. package/dest/transport/interface/connector.d.ts.map +0 -1
  267. package/dest/transport/interface/connector.js +0 -2
  268. package/dest/transport/interface/listener.d.ts +0 -13
  269. package/dest/transport/interface/listener.d.ts.map +0 -1
  270. package/dest/transport/interface/listener.js +0 -2
  271. package/dest/transport/interface/socket.d.ts +0 -13
  272. package/dest/transport/interface/socket.d.ts.map +0 -1
  273. package/dest/transport/interface/socket.js +0 -2
  274. package/dest/transport/interface/transferable.d.ts +0 -68
  275. package/dest/transport/interface/transferable.d.ts.map +0 -1
  276. package/dest/transport/interface/transferable.js +0 -63
  277. package/dest/transport/node/index.d.ts +0 -3
  278. package/dest/transport/node/index.d.ts.map +0 -1
  279. package/dest/transport/node/index.js +0 -3
  280. package/dest/transport/node/node_connector.d.ts +0 -28
  281. package/dest/transport/node/node_connector.d.ts.map +0 -1
  282. package/dest/transport/node/node_connector.js +0 -28
  283. package/dest/transport/node/node_connector_socket.d.ts +0 -42
  284. package/dest/transport/node/node_connector_socket.d.ts.map +0 -1
  285. package/dest/transport/node/node_connector_socket.js +0 -48
  286. package/dest/transport/node/node_listener.d.ts +0 -26
  287. package/dest/transport/node/node_listener.d.ts.map +0 -1
  288. package/dest/transport/node/node_listener.js +0 -30
  289. package/dest/transport/node/node_listener_socket.d.ts +0 -37
  290. package/dest/transport/node/node_listener_socket.d.ts.map +0 -1
  291. package/dest/transport/node/node_listener_socket.js +0 -44
  292. package/dest/transport/transport_client.d.ts +0 -61
  293. package/dest/transport/transport_client.d.ts.map +0 -1
  294. package/dest/transport/transport_client.js +0 -94
  295. package/dest/transport/transport_server.d.ts +0 -56
  296. package/dest/transport/transport_server.d.ts.map +0 -1
  297. package/dest/transport/transport_server.js +0 -101
  298. package/dest/types/index.d.ts +0 -7
  299. package/dest/types/index.d.ts.map +0 -1
  300. package/dest/types/index.js +0 -2
  301. package/dest/url/index.d.ts +0 -9
  302. package/dest/url/index.d.ts.map +0 -1
  303. package/dest/url/index.js +0 -66
  304. package/dest/wasm/empty_wasi_sdk.d.ts +0 -130
  305. package/dest/wasm/empty_wasi_sdk.d.ts.map +0 -1
  306. package/dest/wasm/empty_wasi_sdk.js +0 -166
  307. package/dest/wasm/index.d.ts +0 -2
  308. package/dest/wasm/index.d.ts.map +0 -1
  309. package/dest/wasm/index.js +0 -2
  310. package/dest/wasm/wasm_module.d.ts +0 -135
  311. package/dest/wasm/wasm_module.d.ts.map +0 -1
  312. package/dest/wasm/wasm_module.js +0 -205
  313. package/dest/wasm/wasm_module.test.d.ts +0 -2
  314. package/dest/wasm/wasm_module.test.d.ts.map +0 -1
  315. package/dest/wasm/wasm_module.test.js +0 -24
  316. package/dest/worker/browser/index.d.ts +0 -3
  317. package/dest/worker/browser/index.d.ts.map +0 -1
  318. package/dest/worker/browser/index.js +0 -3
  319. package/dest/worker/browser/start_web_module.d.ts +0 -7
  320. package/dest/worker/browser/start_web_module.d.ts.map +0 -1
  321. package/dest/worker/browser/start_web_module.js +0 -22
  322. package/dest/worker/browser/web_data_store.d.ts +0 -23
  323. package/dest/worker/browser/web_data_store.d.ts.map +0 -1
  324. package/dest/worker/browser/web_data_store.js +0 -32
  325. package/dest/worker/browser/web_worker.d.ts +0 -10
  326. package/dest/worker/browser/web_worker.d.ts.map +0 -1
  327. package/dest/worker/browser/web_worker.js +0 -23
  328. package/dest/worker/data_store.d.ts +0 -20
  329. package/dest/worker/data_store.d.ts.map +0 -1
  330. package/dest/worker/data_store.js +0 -2
  331. package/dest/worker/index.d.ts +0 -3
  332. package/dest/worker/index.d.ts.map +0 -1
  333. package/dest/worker/index.js +0 -2
  334. package/dest/worker/node/index.d.ts +0 -3
  335. package/dest/worker/node/index.d.ts.map +0 -1
  336. package/dest/worker/node/index.js +0 -3
  337. package/dest/worker/node/node_data_store.d.ts +0 -12
  338. package/dest/worker/node/node_data_store.d.ts.map +0 -1
  339. package/dest/worker/node/node_data_store.js +0 -21
  340. package/dest/worker/node/node_worker.d.ts +0 -6
  341. package/dest/worker/node/node_worker.d.ts.map +0 -1
  342. package/dest/worker/node/node_worker.js +0 -20
  343. package/dest/worker/node/start_node_module.d.ts +0 -7
  344. package/dest/worker/node/start_node_module.d.ts.map +0 -1
  345. package/dest/worker/node/start_node_module.js +0 -26
  346. package/dest/worker/wasm_worker.d.ts +0 -9
  347. package/dest/worker/wasm_worker.d.ts.map +0 -1
  348. package/dest/worker/wasm_worker.js +0 -2
  349. package/dest/worker/worker_pool.d.ts +0 -40
  350. package/dest/worker/worker_pool.d.ts.map +0 -1
  351. package/dest/worker/worker_pool.js +0 -62
@@ -1,95 +0,0 @@
1
- import { EthAddress } from './index.js';
2
- describe('address', () => {
3
- it('should return correct string', () => {
4
- const address = EthAddress.fromString('0xc6d9d2cd449a754c494264e1809c50e34d64562b');
5
- expect(address.toChecksumString()).toBe('0xc6d9d2cD449A754c494264e1809c50e34D64562b');
6
- });
7
- it('should return correct buffer', () => {
8
- const address = EthAddress.fromString('0xc6d9d2cd449a754c494264e1809c50e34d64562b');
9
- expect(address.toBuffer20()).toEqual(Buffer.from('c6d9d2cD449A754c494264e1809c50e34D64562b', 'hex'));
10
- });
11
- it('should return correct 32 byte buffer', () => {
12
- const address = EthAddress.fromString('0xc6d9d2cd449a754c494264e1809c50e34d64562b');
13
- expect(address.toBuffer32()).toEqual(Buffer.from('000000000000000000000000c6d9d2cD449A754c494264e1809c50e34D64562b', 'hex'));
14
- });
15
- it('should create address from 32 byte buffer', () => {
16
- const buffer = Buffer.from('000000000000000000000000c6d9d2cD449A754c494264e1809c50e34D64562b', 'hex');
17
- expect(new EthAddress(buffer)).toEqual(EthAddress.fromString('0xc6d9d2cD449A754c494264e1809c50e34D64562b'));
18
- });
19
- it('should not create address from 32 byte buffer that does not start with 12 0 bytes', () => {
20
- const buffer = Buffer.from('010000000000000000000000c6d9d2cD449A754c494264e1809c50e34D64562b', 'hex');
21
- expect(() => new EthAddress(buffer)).toThrowError();
22
- });
23
- it('should have correct zero address', () => {
24
- expect(EthAddress.ZERO.toString()).toBe('0x0000000000000000000000000000000000000000');
25
- });
26
- it('should check if is zero', () => {
27
- const zero = EthAddress.fromString('0x0000000000000000000000000000000000000000');
28
- expect(zero.isZero()).toBeTruthy();
29
- });
30
- it('should encode and decode as field', () => {
31
- const address = EthAddress.fromString('0xc6d9d2cd449a754c494264e1809c50e34d64562b');
32
- expect(EthAddress.fromField(address.toField())).toEqual(address);
33
- });
34
- describe('isAddress', () => {
35
- it(`should return true for valid prefixed address`, () => {
36
- expect(EthAddress.isAddress('0xc6d9d2cd449a754c494264e1809c50e34d64562b')).toBe(true);
37
- });
38
- it(`should return true for valid unprefixed address`, () => {
39
- expect(EthAddress.isAddress('c6d9d2cd449a754c494264e1809c50e34d64562b')).toBe(true);
40
- });
41
- it(`should return true for valid all uppercase address`, () => {
42
- expect(EthAddress.isAddress('0xC6D9D2CD449A754C494264E1809C50E34D64562B')).toBe(true);
43
- });
44
- it(`should return true for correctly checksummed address`, () => {
45
- expect(EthAddress.isAddress('0xE247A45c287191d435A8a5D72A7C8dc030451E9F')).toBe(true);
46
- });
47
- it(`should return false for badly checksummed address`, () => {
48
- expect(EthAddress.isAddress('0xE247A45C287191d435A8a5D72A7C8dc030451E9F')).toBe(false);
49
- });
50
- it(`should return false for non hex characters`, () => {
51
- expect(EthAddress.isAddress('0xg6d9d2cd449a754c494264e1809c50e34d64562b')).toBe(false);
52
- });
53
- });
54
- describe('checkAddressChecksum', () => {
55
- const tests = [
56
- { value: '0x52908400098527886E0F7030069857D2E4169EE7', is: true },
57
- { value: '0x8617E340B3D01FA5F11F306F4090FD50E238070D', is: true },
58
- { value: '0xde709f2102306220921060314715629080e2fb77', is: true },
59
- { value: '0x27b1fdb04752bbc536007a920d24acb045561c26', is: true },
60
- { value: '0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed', is: true },
61
- { value: '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359', is: true },
62
- { value: '0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB', is: true },
63
- { value: '0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', is: true },
64
- { value: '0XD1220A0CF47C7B9BE7A2E6BA89F429762E7B9ADB', is: false },
65
- { value: '0xd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb', is: false },
66
- ];
67
- tests.forEach(test => {
68
- it(`should return ${test.is} for address ${test.value}`, () => {
69
- expect(EthAddress.checkAddressChecksum(test.value)).toBe(test.is);
70
- });
71
- });
72
- });
73
- describe('toChecksumAddress', () => {
74
- const tests = [
75
- {
76
- value: '0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed',
77
- is: '0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed',
78
- },
79
- {
80
- value: '0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359',
81
- is: '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359',
82
- },
83
- {
84
- value: '0xdbf03b407c01e7cd3cbea99509d93f8dddc8c6fb',
85
- is: '0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB',
86
- },
87
- ];
88
- tests.forEach(test => {
89
- it(`should return ${test.is} for address ${test.value}`, () => {
90
- expect(EthAddress.toChecksumAddress(test.value)).toBe(test.is);
91
- });
92
- });
93
- });
94
- });
95
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXRoX2FkZHJlc3MudGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ldGgtYWRkcmVzcy9ldGhfYWRkcmVzcy50ZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxZQUFZLENBQUM7QUFFeEMsUUFBUSxDQUFDLFNBQVMsRUFBRSxHQUFHLEVBQUU7SUFDdkIsRUFBR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O0FBQ0wsQ0FBQyxDQUFDLENBQUMifQ==
@@ -1,144 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import { Fr } from '../fields/index.js';
3
- import { BufferReader } from '../serialize/index.js';
4
- /**
5
- * Represents an Ethereum address as a 20-byte buffer and provides various utility methods
6
- * for converting between different representations, generating random addresses, validating
7
- * checksums, and comparing addresses. EthAddress can be instantiated using a buffer or string,
8
- * and can be serialized/deserialized from a buffer or BufferReader.
9
- */
10
- export declare class EthAddress {
11
- private buffer;
12
- /**
13
- * The size of an Ethereum address in bytes.
14
- */
15
- static SIZE_IN_BYTES: number;
16
- /**
17
- * Represents a zero Ethereum address with 20 bytes filled with zeros.
18
- */
19
- static ZERO: EthAddress;
20
- constructor(buffer: Buffer);
21
- /**
22
- * Creates an EthAddress instance from a valid Ethereum address string.
23
- * The input 'address' can be either in checksum format or lowercase, and it can be prefixed with '0x'.
24
- * Throws an error if the input is not a valid Ethereum address.
25
- *
26
- * @param address - The string representing the Ethereum address.
27
- * @returns An EthAddress instance.
28
- */
29
- static fromString(address: string): EthAddress;
30
- /**
31
- * Create a random EthAddress instance with 20 random bytes.
32
- * This method generates a new Ethereum address with a randomly generated set of 20 bytes.
33
- * It is useful for generating test addresses or unique identifiers.
34
- *
35
- * @returns A randomly generated EthAddress instance.
36
- */
37
- static random(): EthAddress;
38
- /**
39
- * Determines if the given string represents a valid Ethereum address.
40
- * A valid address should meet the following criteria:
41
- * 1. Contains exactly 40 hex characters (excluding an optional '0x' prefix).
42
- * 2. Is either all lowercase, all uppercase, or has a valid checksum based on EIP-55.
43
- *
44
- * @param address - The string to be checked for validity as an Ethereum address.
45
- * @returns True if the input string represents a valid Ethereum address, false otherwise.
46
- */
47
- static isAddress(address: string): boolean;
48
- /**
49
- * Checks if the EthAddress instance represents a zero address.
50
- * A zero address consists of 20 bytes filled with zeros and is considered an invalid address.
51
- *
52
- * @returns A boolean indicating whether the EthAddress instance is a zero address or not.
53
- */
54
- isZero(): boolean;
55
- /**
56
- * Checks if the given Ethereum address has a valid checksum.
57
- * The input 'address' should be prefixed with '0x' or not, and have exactly 40 hex characters.
58
- * Returns true if the address has a valid checksum, false otherwise.
59
- *
60
- * @param address - The hex-encoded string representing the Ethereum address.
61
- * @returns A boolean value indicating whether the address has a valid checksum.
62
- */
63
- static checkAddressChecksum(address: string): boolean;
64
- /**
65
- * Converts an Ethereum address to its checksum format.
66
- * The input 'address' should be prefixed with '0x' or not, and have exactly 40 hex characters.
67
- * The checksum format is created by capitalizing certain characters in the hex string
68
- * based on the hash of the lowercase address.
69
- * Throws an error if the input address is invalid.
70
- *
71
- * @param address - The Ethereum address as a hex-encoded string.
72
- * @returns The Ethereum address in its checksum format.
73
- */
74
- static toChecksumAddress(address: string): string;
75
- /**
76
- * Checks whether the given EthAddress instance is equal to the current instance.
77
- * Equality is determined by comparing the underlying byte buffers of both instances.
78
- *
79
- * @param rhs - The EthAddress instance to compare with the current instance.
80
- * @returns A boolean value indicating whether the two instances are equal (true) or not (false).
81
- */
82
- equals(rhs: EthAddress): boolean;
83
- /**
84
- * Converts the Ethereum address to a hex-encoded string.
85
- * The resulting string is prefixed with '0x' and has exactly 40 hex characters.
86
- * This method can be used to represent the EthAddress instance in the widely used hexadecimal format.
87
- *
88
- * @returns A hex-encoded string representation of the Ethereum address.
89
- */
90
- toString(): `0x${string}`;
91
- /**
92
- * Returns the Ethereum address as a checksummed string.
93
- * The output string will have characters in the correct upper or lowercase form, according to EIP-55.
94
- * This provides a way to verify if an address is typed correctly, by checking the character casing.
95
- *
96
- * @returns A checksummed Ethereum address string.
97
- */
98
- toChecksumString(): string;
99
- /**
100
- * Alias for toBuffer32.
101
- * @returns A 32-byte Buffer containing the padded Ethereum address.
102
- */
103
- toBuffer(): Buffer;
104
- /**
105
- * Returns the internal Buffer representation of the Ethereum address.
106
- * This method is useful when working with raw binary data or when
107
- * integrating with other modules that require a Buffer as input.
108
- *
109
- * @returns A Buffer instance containing the 20-byte Ethereum address.
110
- */
111
- toBuffer20(): Buffer;
112
- /**
113
- * Returns a 32-byte buffer representation of the Ethereum address, with the original 20-byte address
114
- * occupying the last 20 bytes and the first 12 bytes being zero-filled.
115
- * This format is commonly used in smart contracts when handling addresses as 32-byte values.
116
- *
117
- * @returns A 32-byte Buffer containing the padded Ethereum address.
118
- */
119
- toBuffer32(): Buffer;
120
- /**
121
- * Returns a new field with the same contents as this EthAddress.
122
- *
123
- * @returns An Fr instance.
124
- */
125
- toField(): Fr;
126
- /**
127
- * Converts a field to a eth address.
128
- * @param fr - The field to convert.
129
- * @returns The eth address.
130
- */
131
- static fromField(fr: Fr): EthAddress;
132
- /**
133
- * Deserializes from a buffer or reader, corresponding to a write in cpp.
134
- * @param buffer - Buffer to read from.
135
- * @returns The EthAdress.
136
- */
137
- static fromBuffer(buffer: Buffer | BufferReader): EthAddress;
138
- /**
139
- * Friendly representation for debugging purposes.
140
- * @returns A hex string representing the address.
141
- */
142
- toFriendlyJSON(): `0x${string}`;
143
- }
144
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/eth-address/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD;;;;;GAKG;AACH,qBAAa,UAAU;IAUT,OAAO,CAAC,MAAM;IAT1B;;OAEG;IACH,OAAc,aAAa,SAAM;IACjC;;OAEG;IACH,OAAc,IAAI,aAA0D;gBAExD,MAAM,EAAE,MAAM;IAYlC;;;;;;;OAOG;WACW,UAAU,CAAC,OAAO,EAAE,MAAM;IAOxC;;;;;;OAMG;WACW,MAAM;IAIpB;;;;;;;;OAQG;WACW,SAAS,CAAC,OAAO,EAAE,MAAM;IAYvC;;;;;OAKG;IACI,MAAM;IAIb;;;;;;;OAOG;WACW,oBAAoB,CAAC,OAAO,EAAE,MAAM;IAgBlD;;;;;;;;;OASG;WACW,iBAAiB,CAAC,OAAO,EAAE,MAAM;IAoB/C;;;;;;OAMG;IACI,MAAM,CAAC,GAAG,EAAE,UAAU;IAI7B;;;;;;OAMG;IACI,QAAQ;IAIf;;;;;;OAMG;IACI,gBAAgB;IAIvB;;;OAGG;IACI,QAAQ;IAIf;;;;;;OAMG;IACI,UAAU;IAIjB;;;;;;OAMG;IACI,UAAU;IAMjB;;;;OAIG;IACI,OAAO;IAId;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,GAAG,UAAU;IAIpC;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,UAAU;IAK5D;;;OAGG;IACH,cAAc;CAGf"}
@@ -1,228 +0,0 @@
1
- import { keccak256String, randomBytes } from '../crypto/index.js';
2
- import { Fr } from '../fields/index.js';
3
- import { BufferReader } from '../serialize/index.js';
4
- /**
5
- * Represents an Ethereum address as a 20-byte buffer and provides various utility methods
6
- * for converting between different representations, generating random addresses, validating
7
- * checksums, and comparing addresses. EthAddress can be instantiated using a buffer or string,
8
- * and can be serialized/deserialized from a buffer or BufferReader.
9
- */
10
- export class EthAddress {
11
- constructor(buffer) {
12
- this.buffer = buffer;
13
- if (buffer.length === 32) {
14
- if (!buffer.slice(0, 12).equals(Buffer.alloc(12))) {
15
- throw new Error(`Invalid address buffer: ${buffer.toString('hex')}`);
16
- }
17
- else {
18
- this.buffer = buffer.slice(12);
19
- }
20
- }
21
- else if (buffer.length !== EthAddress.SIZE_IN_BYTES) {
22
- throw new Error(`Expect buffer size to be ${EthAddress.SIZE_IN_BYTES}. Got ${buffer.length}.`);
23
- }
24
- }
25
- /**
26
- * Creates an EthAddress instance from a valid Ethereum address string.
27
- * The input 'address' can be either in checksum format or lowercase, and it can be prefixed with '0x'.
28
- * Throws an error if the input is not a valid Ethereum address.
29
- *
30
- * @param address - The string representing the Ethereum address.
31
- * @returns An EthAddress instance.
32
- */
33
- static fromString(address) {
34
- if (!EthAddress.isAddress(address)) {
35
- throw new Error(`Invalid address string: ${address}`);
36
- }
37
- return new EthAddress(Buffer.from(address.replace(/^0x/i, ''), 'hex'));
38
- }
39
- /**
40
- * Create a random EthAddress instance with 20 random bytes.
41
- * This method generates a new Ethereum address with a randomly generated set of 20 bytes.
42
- * It is useful for generating test addresses or unique identifiers.
43
- *
44
- * @returns A randomly generated EthAddress instance.
45
- */
46
- static random() {
47
- return new EthAddress(randomBytes(20));
48
- }
49
- /**
50
- * Determines if the given string represents a valid Ethereum address.
51
- * A valid address should meet the following criteria:
52
- * 1. Contains exactly 40 hex characters (excluding an optional '0x' prefix).
53
- * 2. Is either all lowercase, all uppercase, or has a valid checksum based on EIP-55.
54
- *
55
- * @param address - The string to be checked for validity as an Ethereum address.
56
- * @returns True if the input string represents a valid Ethereum address, false otherwise.
57
- */
58
- static isAddress(address) {
59
- if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) {
60
- // Does not have the basic requirements of an address.
61
- return false;
62
- }
63
- else if (/^(0x|0X)?[0-9a-f]{40}$/.test(address) || /^(0x|0X)?[0-9A-F]{40}$/.test(address)) {
64
- // It's ALL lowercase or ALL upppercase.
65
- return true;
66
- }
67
- else {
68
- return EthAddress.checkAddressChecksum(address);
69
- }
70
- }
71
- /**
72
- * Checks if the EthAddress instance represents a zero address.
73
- * A zero address consists of 20 bytes filled with zeros and is considered an invalid address.
74
- *
75
- * @returns A boolean indicating whether the EthAddress instance is a zero address or not.
76
- */
77
- isZero() {
78
- return this.equals(EthAddress.ZERO);
79
- }
80
- /**
81
- * Checks if the given Ethereum address has a valid checksum.
82
- * The input 'address' should be prefixed with '0x' or not, and have exactly 40 hex characters.
83
- * Returns true if the address has a valid checksum, false otherwise.
84
- *
85
- * @param address - The hex-encoded string representing the Ethereum address.
86
- * @returns A boolean value indicating whether the address has a valid checksum.
87
- */
88
- static checkAddressChecksum(address) {
89
- address = address.replace(/^0x/i, '');
90
- const addressHash = keccak256String(address.toLowerCase());
91
- for (let i = 0; i < 40; i++) {
92
- // The nth letter should be uppercase if the nth digit of casemap is 1.
93
- if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) ||
94
- (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) {
95
- return false;
96
- }
97
- }
98
- return true;
99
- }
100
- /**
101
- * Converts an Ethereum address to its checksum format.
102
- * The input 'address' should be prefixed with '0x' or not, and have exactly 40 hex characters.
103
- * The checksum format is created by capitalizing certain characters in the hex string
104
- * based on the hash of the lowercase address.
105
- * Throws an error if the input address is invalid.
106
- *
107
- * @param address - The Ethereum address as a hex-encoded string.
108
- * @returns The Ethereum address in its checksum format.
109
- */
110
- static toChecksumAddress(address) {
111
- if (!EthAddress.isAddress(address)) {
112
- throw new Error('Invalid address string.');
113
- }
114
- address = address.toLowerCase().replace(/^0x/i, '');
115
- const addressHash = keccak256String(address);
116
- let checksumAddress = '0x';
117
- for (let i = 0; i < address.length; i++) {
118
- // If ith character is 9 to f then make it uppercase.
119
- if (parseInt(addressHash[i], 16) > 7) {
120
- checksumAddress += address[i].toUpperCase();
121
- }
122
- else {
123
- checksumAddress += address[i];
124
- }
125
- }
126
- return checksumAddress;
127
- }
128
- /**
129
- * Checks whether the given EthAddress instance is equal to the current instance.
130
- * Equality is determined by comparing the underlying byte buffers of both instances.
131
- *
132
- * @param rhs - The EthAddress instance to compare with the current instance.
133
- * @returns A boolean value indicating whether the two instances are equal (true) or not (false).
134
- */
135
- equals(rhs) {
136
- return this.buffer.equals(rhs.buffer);
137
- }
138
- /**
139
- * Converts the Ethereum address to a hex-encoded string.
140
- * The resulting string is prefixed with '0x' and has exactly 40 hex characters.
141
- * This method can be used to represent the EthAddress instance in the widely used hexadecimal format.
142
- *
143
- * @returns A hex-encoded string representation of the Ethereum address.
144
- */
145
- toString() {
146
- return `0x${this.buffer.toString('hex')}`;
147
- }
148
- /**
149
- * Returns the Ethereum address as a checksummed string.
150
- * The output string will have characters in the correct upper or lowercase form, according to EIP-55.
151
- * This provides a way to verify if an address is typed correctly, by checking the character casing.
152
- *
153
- * @returns A checksummed Ethereum address string.
154
- */
155
- toChecksumString() {
156
- return EthAddress.toChecksumAddress(this.buffer.toString('hex'));
157
- }
158
- /**
159
- * Alias for toBuffer32.
160
- * @returns A 32-byte Buffer containing the padded Ethereum address.
161
- */
162
- toBuffer() {
163
- return this.toBuffer32();
164
- }
165
- /**
166
- * Returns the internal Buffer representation of the Ethereum address.
167
- * This method is useful when working with raw binary data or when
168
- * integrating with other modules that require a Buffer as input.
169
- *
170
- * @returns A Buffer instance containing the 20-byte Ethereum address.
171
- */
172
- toBuffer20() {
173
- return this.buffer;
174
- }
175
- /**
176
- * Returns a 32-byte buffer representation of the Ethereum address, with the original 20-byte address
177
- * occupying the last 20 bytes and the first 12 bytes being zero-filled.
178
- * This format is commonly used in smart contracts when handling addresses as 32-byte values.
179
- *
180
- * @returns A 32-byte Buffer containing the padded Ethereum address.
181
- */
182
- toBuffer32() {
183
- const buffer = Buffer.alloc(32);
184
- this.buffer.copy(buffer, 12);
185
- return buffer;
186
- }
187
- /**
188
- * Returns a new field with the same contents as this EthAddress.
189
- *
190
- * @returns An Fr instance.
191
- */
192
- toField() {
193
- return Fr.fromBuffer(this.toBuffer32());
194
- }
195
- /**
196
- * Converts a field to a eth address.
197
- * @param fr - The field to convert.
198
- * @returns The eth address.
199
- */
200
- static fromField(fr) {
201
- return new EthAddress(fr.toBuffer().slice(-EthAddress.SIZE_IN_BYTES));
202
- }
203
- /**
204
- * Deserializes from a buffer or reader, corresponding to a write in cpp.
205
- * @param buffer - Buffer to read from.
206
- * @returns The EthAdress.
207
- */
208
- static fromBuffer(buffer) {
209
- const reader = BufferReader.asReader(buffer);
210
- return new EthAddress(reader.readBuffer());
211
- }
212
- /**
213
- * Friendly representation for debugging purposes.
214
- * @returns A hex string representing the address.
215
- */
216
- toFriendlyJSON() {
217
- return this.toString();
218
- }
219
- }
220
- /**
221
- * The size of an Ethereum address in bytes.
222
- */
223
- EthAddress.SIZE_IN_BYTES = 20;
224
- /**
225
- * Represents a zero Ethereum address with 20 bytes filled with zeros.
226
- */
227
- EthAddress.ZERO = new EthAddress(Buffer.alloc(EthAddress.SIZE_IN_BYTES));
228
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZXRoLWFkZHJlc3MvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGVBQWUsRUFBRSxXQUFXLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUNsRSxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDeEMsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBRXJEOzs7OztHQUtHO0FBQ0gsTUFBTSxPQUFPLFVBQVU7SUFVckIsWUFBb0IsTUFBYztRQUFkLFdBQU0sR0FBTixNQUFNLENBQVE7UUFDaEMsSUFBSSxNQUFNLENBQUMsTUFBTSxLQUFLLEVBQUUsRUFBRTtZQUN4QixJQUFJLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQyxDQUFDLEVBQUUsRUFBRSxDQUFDLENBQUMsTUFBTSxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsRUFBRSxDQUFDLENBQUMsRUFBRTtnQkFDakQsTUFBTSxJQUFJLEtBQUssQ0FBQywyQkFBMkIsTUFBTSxDQUFDLFFBQVEsQ0FBQyxLQUFLLENBQUMsRUFBRSxDQUFDLENBQUM7YUFDdEU7aUJBQU07Z0JBQ0wsSUFBSSxDQUFDLE1BQU0sR0FBRyxNQUFNLENBQUMsS0FBSyxDQUFDLEVBQUUsQ0FBQyxDQUFDO2FBQ2hDO1NBQ0Y7YUFBTSxJQUFJLE1BQU0sQ0FBQyxNQU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EsQ0FBQyxNQUFNLENBQUMsQ0FBQztRQUM3QyxPQUFPLElBQUksVUFBVSxDQUFDLE1BQU0sQ0FBQyxVQUFVLEVBQUUsQ0FBQyxDQUFDO0lBQzdDLENBQUM7SUFFRDs7O09BR0c7SUFDSCxjQUFjO1FBQ1osT0FBTyxJQUFJLENBQUMsUUFBUSxFQUFFLENBQUM7SUFDekIsQ0FBQzs7QUF2T0Q7O0dBRUc7QUFDVyx3QkFBYSxHQUFHLEVBQUUsQ0FBQztBQUNqQzs7R0FFRztBQUNXLGVBQUksR0FBRyxJQUFJLFVBQVUsQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFDLFVBQVUsQ0FBQyxhQUFhLENBQUMsQ0FBQyxDQUFDIn0=
@@ -1,67 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import { Tuple } from '../serialize/types.js';
3
- import { Fr } from './fields.js';
4
- /**
5
- * Class to wrap a single point coordinate.
6
- * This class handles the complexities of representing point coordinates as 32 byte buffers as well as fields.
7
- * The coordinate value is split across 2 fields to ensure that the max size of a field is not breached.
8
- * This is achieved by placing the most significant byte of the lower field into the least significant byte of the higher field.
9
- * Calls to 'toBuffer' or 'toBigInt' undo this change and simply return the original 32 byte value.
10
- * Calls to 'toFieldsBuffer' will return a 64 bytes buffer containing the serialised fields.
11
- */
12
- export declare class Coordinate {
13
- /**
14
- * The fields of the coordinate value. Least significant limb at index 0.
15
- */
16
- fields: Tuple<Fr, 2>;
17
- static ZERO: Coordinate;
18
- constructor(
19
- /**
20
- * The fields of the coordinate value. Least significant limb at index 0.
21
- */
22
- fields: Tuple<Fr, 2>);
23
- /**
24
- * Converts the coordinate data into a tuple of fields
25
- * @returns A tuple of the coordinate fields
26
- */
27
- toFields(): Tuple<Fr, 2>;
28
- /**
29
- * Generates a random coordinate value
30
- * @returns The random coordinate
31
- */
32
- static random(): Coordinate;
33
- /**
34
- * Serialises the oblect to buffer of 2 fields.
35
- * @returns A buffer serialisation of the object.
36
- */
37
- toFieldsBuffer(): Buffer;
38
- /**
39
- * Serialises the coordinate to a single 32 byte buffer.
40
- * @returns A buffer serialisation of the object.
41
- */
42
- toBuffer(): Buffer;
43
- /**
44
- * Returns true if this coordinate is equal to the one provided
45
- * @param other - The coordinate against which to compare
46
- * @returns True if the coordinates are the same, false otherwise
47
- */
48
- equals(other: Coordinate): boolean;
49
- /**
50
- * Returns the coordinate's value as a bigint
51
- * @returns The coordinate value as a bigint
52
- */
53
- toBigInt(): bigint;
54
- /**
55
- * Creates a coordinate object from a 32 byte coordinate value
56
- * @param coordinate - A buffer containing the 32 byte coordinate value
57
- * @returns The new coordinate object
58
- */
59
- static fromBuffer(coordinate: Buffer): Coordinate;
60
- /**
61
- * Creates a coordinate object from a field
62
- * @param coordinate - The field containing the coordinate
63
- * @returns The new coordinate object
64
- */
65
- static fromField(coordinate: Fr): Coordinate;
66
- }
67
- //# sourceMappingURL=coordinate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"coordinate.d.ts","sourceRoot":"","sources":["../../src/fields/coordinate.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEjC;;;;;;;GAOG;AACH,qBAAa,UAAU;IAInB;;OAEG;IACI,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;IAN7B,MAAM,CAAC,IAAI,aAAsC;;IAG/C;;OAEG;IACI,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;IAG7B;;;OAGG;IACH,QAAQ,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;IAIxB;;;OAGG;IACH,MAAM,CAAC,MAAM,IAAI,UAAU;IAI3B;;;OAGG;IACH,cAAc,IAAI,MAAM;IAIxB;;;OAGG;IACH,QAAQ,IAAI,MAAM;IAOlB;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO;IAIlC;;;OAGG;IACH,QAAQ,IAAI,MAAM;IAIlB;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM;IAYpC;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE;CAOhC"}
@@ -1,95 +0,0 @@
1
- import { toBigIntBE } from '../bigint-buffer/index.js';
2
- import { Fr } from './fields.js';
3
- /**
4
- * Class to wrap a single point coordinate.
5
- * This class handles the complexities of representing point coordinates as 32 byte buffers as well as fields.
6
- * The coordinate value is split across 2 fields to ensure that the max size of a field is not breached.
7
- * This is achieved by placing the most significant byte of the lower field into the least significant byte of the higher field.
8
- * Calls to 'toBuffer' or 'toBigInt' undo this change and simply return the original 32 byte value.
9
- * Calls to 'toFieldsBuffer' will return a 64 bytes buffer containing the serialised fields.
10
- */
11
- export class Coordinate {
12
- constructor(
13
- /**
14
- * The fields of the coordinate value. Least significant limb at index 0.
15
- */
16
- fields) {
17
- this.fields = fields;
18
- }
19
- /**
20
- * Converts the coordinate data into a tuple of fields
21
- * @returns A tuple of the coordinate fields
22
- */
23
- toFields() {
24
- return this.fields;
25
- }
26
- /**
27
- * Generates a random coordinate value
28
- * @returns The random coordinate
29
- */
30
- static random() {
31
- return this.fromField(Fr.random());
32
- }
33
- /**
34
- * Serialises the oblect to buffer of 2 fields.
35
- * @returns A buffer serialisation of the object.
36
- */
37
- toFieldsBuffer() {
38
- return Buffer.concat([this.fields[0].toBuffer(), this.fields[1].toBuffer()]);
39
- }
40
- /**
41
- * Serialises the coordinate to a single 32 byte buffer.
42
- * @returns A buffer serialisation of the object.
43
- */
44
- toBuffer() {
45
- const buf0 = this.fields[0].toBuffer();
46
- const buf1 = this.fields[1].toBuffer();
47
- buf0[0] = buf1[31];
48
- return buf0;
49
- }
50
- /**
51
- * Returns true if this coordinate is equal to the one provided
52
- * @param other - The coordinate against which to compare
53
- * @returns True if the coordinates are the same, false otherwise
54
- */
55
- equals(other) {
56
- return this.toBigInt() === other.toBigInt();
57
- }
58
- /**
59
- * Returns the coordinate's value as a bigint
60
- * @returns The coordinate value as a bigint
61
- */
62
- toBigInt() {
63
- return toBigIntBE(this.toBuffer());
64
- }
65
- /**
66
- * Creates a coordinate object from a 32 byte coordinate value
67
- * @param coordinate - A buffer containing the 32 byte coordinate value
68
- * @returns The new coordinate object
69
- */
70
- static fromBuffer(coordinate) {
71
- if (coordinate.length != 32) {
72
- throw new Error(`Invalid size of coordinate buffer`);
73
- }
74
- const buf0 = Buffer.alloc(32);
75
- coordinate.copy(buf0, 0, 0, 32);
76
- const buf1 = Buffer.alloc(32);
77
- buf1[31] = buf0[0];
78
- buf0[0] = 0;
79
- return new Coordinate([Fr.fromBuffer(buf0), Fr.fromBuffer(buf1)]);
80
- }
81
- /**
82
- * Creates a coordinate object from a field
83
- * @param coordinate - The field containing the coordinate
84
- * @returns The new coordinate object
85
- */
86
- static fromField(coordinate) {
87
- const buf0 = coordinate.toBuffer();
88
- const buf1 = Buffer.alloc(32);
89
- buf1[31] = buf0[0];
90
- buf0[0] = 0;
91
- return new Coordinate([Fr.fromBuffer(buf0), Fr.fromBuffer(buf1)]);
92
- }
93
- }
94
- Coordinate.ZERO = new Coordinate([Fr.ZERO, Fr.ZERO]);
95
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29vcmRpbmF0ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9maWVsZHMvY29vcmRpbmF0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sMkJBQTJCLENBQUM7QUFFdkQsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQUVqQzs7Ozs7OztHQU9HO0FBQ0gsTUFBTSxPQUFPLFVBQVU7SUFHckI7SUFDRTs7T0FFRztJQUNJLE1BQW9CO1F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UNuQixJQUFJLENBQUMsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxDQUFDO1FBQ1osT0FBTyxJQUFJLFVBQVUsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLEVBQUUsRUFBRSxDQUFDLFVBQVUsQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFDcEUsQ0FBQzs7QUF6Rk0sZUFBSSxHQUFHLElBQUksVUFBVSxDQUFDLENBQUMsRUFBRSxDQUFDLElBQUksRUFBRSxFQUFFLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyJ9
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=coordinate.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"coordinate.test.d.ts","sourceRoot":"","sources":["../../src/fields/coordinate.test.ts"],"names":[],"mappings":""}