@waku/rln 0.0.1 → 0.0.2-ce9a6ae.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 (405) hide show
  1. package/README.md +12 -108
  2. package/bundle/_virtual/__node-resolve_empty.js +6 -0
  3. package/bundle/_virtual/_assert.js +3 -0
  4. package/bundle/_virtual/_commonjs-dynamic-modules.js +5 -0
  5. package/bundle/_virtual/_commonjsHelpers.js +32 -0
  6. package/bundle/_virtual/_node-resolve_empty.js +3 -0
  7. package/bundle/_virtual/_sha2.js +3 -0
  8. package/bundle/_virtual/_u64.js +3 -0
  9. package/bundle/_virtual/aes.js +3 -0
  10. package/bundle/_virtual/bn.js +3 -0
  11. package/bundle/_virtual/browser.js +3 -0
  12. package/bundle/_virtual/checksum.js +3 -0
  13. package/bundle/_virtual/cipher.js +3 -0
  14. package/bundle/_virtual/class.js +3 -0
  15. package/bundle/_virtual/common.js +3 -0
  16. package/bundle/_virtual/common2.js +3 -0
  17. package/bundle/_virtual/cryptoBrowser.js +3 -0
  18. package/bundle/_virtual/functional.js +3 -0
  19. package/bundle/_virtual/hash.js +3 -0
  20. package/bundle/_virtual/hmac.js +3 -0
  21. package/bundle/_virtual/index.js +3 -0
  22. package/bundle/_virtual/index2.js +6 -0
  23. package/bundle/_virtual/inherits_browser.js +3 -0
  24. package/bundle/_virtual/kdf.js +3 -0
  25. package/bundle/_virtual/lodash.js +3 -0
  26. package/bundle/_virtual/password.js +3 -0
  27. package/bundle/_virtual/pbkdf2.js +3 -0
  28. package/bundle/_virtual/pbkdf22.js +3 -0
  29. package/bundle/_virtual/random.js +3 -0
  30. package/bundle/_virtual/ripemd.js +3 -0
  31. package/bundle/_virtual/schema-validation-generated.js +3 -0
  32. package/bundle/_virtual/schema-validation.js +3 -0
  33. package/bundle/_virtual/scrypt.js +3 -0
  34. package/bundle/_virtual/scrypt2.js +3 -0
  35. package/bundle/_virtual/sha.js +3 -0
  36. package/bundle/_virtual/sha256.js +3 -0
  37. package/bundle/_virtual/sha2562.js +3 -0
  38. package/bundle/_virtual/sha3.js +3 -0
  39. package/bundle/_virtual/sha512.js +3 -0
  40. package/bundle/_virtual/types.js +3 -0
  41. package/bundle/_virtual/utils.js +3 -0
  42. package/bundle/_virtual/utils2.js +3 -0
  43. package/bundle/_virtual/utils3.js +3 -0
  44. package/bundle/index.js +12 -10
  45. package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +3 -0
  46. package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +96 -0
  47. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +148 -0
  48. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +26 -0
  49. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +20 -0
  50. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +210 -0
  51. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +18 -0
  52. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +30 -0
  53. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +26 -0
  54. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +22 -0
  55. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +43 -0
  56. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +19 -0
  57. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +58 -0
  58. package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +854 -0
  59. package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +609 -0
  60. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +3 -0
  61. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +66 -0
  62. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +3 -0
  63. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +302 -0
  64. package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +3 -0
  65. package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +110 -0
  66. package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +20 -0
  67. package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +120 -0
  68. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +3 -0
  69. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +287 -0
  70. package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +3 -0
  71. package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +402 -0
  72. package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +3 -0
  73. package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +8 -0
  74. package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +3 -0
  75. package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +3 -0
  76. package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +893 -0
  77. package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +3 -0
  78. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +256 -0
  79. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +36 -0
  80. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +135 -0
  81. package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +8 -0
  82. package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +64 -0
  83. package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +443 -0
  84. package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +8 -0
  85. package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +660 -0
  86. package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +3 -0
  87. package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +352 -0
  88. package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +3 -0
  89. package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +248 -0
  90. package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +3 -0
  91. package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +127 -0
  92. package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +3 -0
  93. package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +2007 -0
  94. package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +422 -0
  95. package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +674 -0
  96. package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +132 -0
  97. package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +3 -0
  98. package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +120 -0
  99. package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +8 -0
  100. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +3 -0
  101. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +2430 -0
  102. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +76 -0
  103. package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +3 -0
  104. package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +219 -0
  105. package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +3 -0
  106. package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +279 -0
  107. package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +3 -0
  108. package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +69 -0
  109. package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +404 -0
  110. package/bundle/node_modules/@iden3/js-crypto/dist/browser/esm/index.js +7 -0
  111. package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +15 -0
  112. package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +20 -0
  113. package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +92 -0
  114. package/bundle/node_modules/@noble/hashes/esm/_assert.js +37 -0
  115. package/bundle/node_modules/@noble/hashes/esm/_md.js +132 -0
  116. package/bundle/node_modules/@noble/hashes/esm/_u64.js +29 -0
  117. package/bundle/node_modules/@noble/hashes/esm/sha256.js +113 -0
  118. package/bundle/node_modules/@noble/hashes/esm/sha3.js +210 -0
  119. package/bundle/node_modules/@noble/hashes/esm/utils.js +144 -0
  120. package/bundle/node_modules/@stablelib/binary/lib/binary.js +22 -0
  121. package/bundle/node_modules/@stablelib/chacha/lib/chacha.js +245 -0
  122. package/bundle/node_modules/@stablelib/wipe/lib/wipe.js +26 -0
  123. package/bundle/node_modules/@waku/zerokit-rln-wasm/rln_wasm.js +756 -0
  124. package/bundle/node_modules/bech32/index.js +187 -0
  125. package/bundle/node_modules/bn.js/lib/bn.js +3361 -0
  126. package/bundle/node_modules/debug/src/browser.js +283 -0
  127. package/bundle/node_modules/debug/src/common.js +295 -0
  128. package/bundle/node_modules/ethereum-cryptography/esm/keccak.js +10 -0
  129. package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +6 -0
  130. package/bundle/node_modules/ethereum-cryptography/esm/utils.js +24 -0
  131. package/bundle/node_modules/hash.js/lib/hash/common.js +97 -0
  132. package/bundle/node_modules/hash.js/lib/hash/hmac.js +51 -0
  133. package/bundle/node_modules/hash.js/lib/hash/ripemd.js +152 -0
  134. package/bundle/node_modules/hash.js/lib/hash/sha/1.js +81 -0
  135. package/bundle/node_modules/hash.js/lib/hash/sha/224.js +33 -0
  136. package/bundle/node_modules/hash.js/lib/hash/sha/256.js +113 -0
  137. package/bundle/node_modules/hash.js/lib/hash/sha/384.js +39 -0
  138. package/bundle/node_modules/hash.js/lib/hash/sha/512.js +336 -0
  139. package/bundle/node_modules/hash.js/lib/hash/sha/common.js +53 -0
  140. package/bundle/node_modules/hash.js/lib/hash/sha.js +14 -0
  141. package/bundle/node_modules/hash.js/lib/hash/utils.js +282 -0
  142. package/bundle/node_modules/hash.js/lib/hash.js +33 -0
  143. package/bundle/node_modules/inherits/inherits_browser.js +33 -0
  144. package/bundle/node_modules/it-length-prefixed/dist/src/decode.js +6 -0
  145. package/bundle/node_modules/lodash/lodash.js +17207 -0
  146. package/bundle/node_modules/minimalistic-assert/index.js +13 -0
  147. package/bundle/node_modules/ms/index.js +172 -0
  148. package/bundle/node_modules/multiformats/dist/src/bases/base.js +205 -0
  149. package/bundle/node_modules/multiformats/dist/src/bases/base10.js +9 -0
  150. package/bundle/node_modules/multiformats/dist/src/bases/base16.js +16 -0
  151. package/bundle/node_modules/multiformats/dist/src/bases/base2.js +10 -0
  152. package/bundle/node_modules/multiformats/dist/src/bases/base256emoji.js +41 -0
  153. package/bundle/node_modules/multiformats/dist/src/bases/base32.js +58 -0
  154. package/bundle/node_modules/multiformats/dist/src/bases/base36.js +14 -0
  155. package/bundle/node_modules/multiformats/dist/src/bases/base58.js +14 -0
  156. package/bundle/node_modules/multiformats/dist/src/bases/base64.js +28 -0
  157. package/bundle/node_modules/multiformats/dist/src/bases/base8.js +10 -0
  158. package/bundle/node_modules/multiformats/dist/src/bases/identity.js +11 -0
  159. package/bundle/node_modules/multiformats/dist/src/basics.js +15 -0
  160. package/bundle/node_modules/multiformats/dist/src/bytes.js +18 -0
  161. package/bundle/node_modules/multiformats/dist/src/codecs/json.js +2 -0
  162. package/bundle/node_modules/multiformats/dist/src/vendor/base-x.js +170 -0
  163. package/bundle/node_modules/protons-runtime/dist/src/codec.js +20 -0
  164. package/bundle/node_modules/protons-runtime/dist/src/codecs/enum.js +24 -0
  165. package/bundle/node_modules/protons-runtime/dist/src/codecs/message.js +7 -0
  166. package/bundle/node_modules/protons-runtime/dist/src/decode.js +8 -0
  167. package/bundle/node_modules/protons-runtime/dist/src/encode.js +11 -0
  168. package/bundle/node_modules/protons-runtime/dist/src/index.js +30 -0
  169. package/bundle/node_modules/protons-runtime/dist/src/utils/float.js +54 -0
  170. package/bundle/node_modules/protons-runtime/dist/src/utils/longbits.js +175 -0
  171. package/bundle/node_modules/protons-runtime/dist/src/utils/pool.js +28 -0
  172. package/bundle/node_modules/protons-runtime/dist/src/utils/reader.js +367 -0
  173. package/bundle/node_modules/protons-runtime/dist/src/utils/utf8.js +99 -0
  174. package/bundle/node_modules/protons-runtime/dist/src/utils/writer.js +438 -0
  175. package/bundle/node_modules/uint8-varint/dist/src/index.js +124 -0
  176. package/bundle/node_modules/uint8arrays/dist/src/alloc.js +17 -0
  177. package/bundle/node_modules/uint8arrays/dist/src/from-string.js +19 -0
  178. package/bundle/node_modules/uint8arrays/dist/src/util/bases.js +49 -0
  179. package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +21 -0
  180. package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +18 -0
  181. package/bundle/packages/core/dist/lib/filter/filter.js +27 -0
  182. package/bundle/packages/core/dist/lib/light_push/light_push.js +27 -0
  183. package/bundle/packages/core/dist/lib/message/version_0.js +154 -0
  184. package/bundle/packages/core/dist/lib/metadata/metadata.js +27 -0
  185. package/bundle/packages/core/dist/lib/store/store.js +27 -0
  186. package/bundle/packages/interfaces/dist/connection_manager.js +19 -0
  187. package/bundle/packages/interfaces/dist/constants.js +6 -0
  188. package/bundle/packages/interfaces/dist/health_indicator.js +12 -0
  189. package/bundle/packages/interfaces/dist/protocols.js +97 -0
  190. package/bundle/packages/proto/dist/generated/filter.js +445 -0
  191. package/bundle/packages/proto/dist/generated/filter_v2.js +424 -0
  192. package/bundle/packages/proto/dist/generated/light_push.js +389 -0
  193. package/bundle/packages/proto/dist/generated/message.js +213 -0
  194. package/bundle/packages/proto/dist/generated/metadata.js +130 -0
  195. package/bundle/packages/proto/dist/generated/peer_exchange.js +209 -0
  196. package/bundle/packages/proto/dist/generated/sds_message.js +105 -0
  197. package/bundle/packages/proto/dist/generated/store_v3.js +490 -0
  198. package/bundle/packages/proto/dist/generated/topic_only_message.js +61 -0
  199. package/bundle/packages/rln/dist/codec.js +93 -0
  200. package/bundle/packages/rln/dist/contract/abi/rlnv2.js +394 -0
  201. package/bundle/packages/rln/dist/contract/constants.js +33 -0
  202. package/bundle/packages/rln/dist/contract/rln_contract.js +427 -0
  203. package/bundle/packages/rln/dist/create.js +9 -0
  204. package/bundle/packages/rln/dist/identity.js +76 -0
  205. package/bundle/packages/rln/dist/keystore/cipher.js +31 -0
  206. package/bundle/packages/rln/dist/keystore/credential_validation_generated.js +119 -0
  207. package/bundle/packages/rln/dist/keystore/keystore.js +223 -0
  208. package/bundle/packages/rln/dist/keystore/keystore_validation_generated.js +74 -0
  209. package/bundle/packages/rln/dist/keystore/schema_validator.js +20 -0
  210. package/bundle/packages/rln/dist/message.js +51 -0
  211. package/bundle/packages/rln/dist/proof.js +54 -0
  212. package/bundle/packages/rln/dist/resources/verification_key.js +112 -0
  213. package/bundle/packages/rln/dist/resources/witness_calculator.js +330 -0
  214. package/bundle/packages/rln/dist/rln.js +204 -0
  215. package/bundle/packages/rln/dist/root_tracker.js +76 -0
  216. package/bundle/packages/rln/dist/utils/bytes.js +65 -0
  217. package/bundle/packages/rln/dist/utils/epoch.js +39 -0
  218. package/bundle/packages/rln/dist/utils/hash.js +10 -0
  219. package/bundle/packages/rln/dist/utils/metamask.js +14 -0
  220. package/bundle/packages/rln/dist/zerokit.js +122 -0
  221. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +52 -0
  222. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +65 -0
  223. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +99 -0
  224. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +103 -0
  225. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/index.js +28 -0
  226. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +78 -0
  227. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +17 -0
  228. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1253 -0
  229. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +40 -0
  230. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/types.js +5 -0
  231. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +103 -0
  232. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +41 -0
  233. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +17 -0
  234. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +23 -0
  235. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +12 -0
  236. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +77 -0
  237. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +9 -0
  238. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +215 -0
  239. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +3 -0
  240. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +35 -0
  241. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +3 -0
  242. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +21 -0
  243. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
  244. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
  245. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +96 -0
  246. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +6 -0
  247. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +66 -0
  248. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +24 -0
  249. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +6 -0
  250. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +7 -0
  251. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +11 -0
  252. package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +52 -0
  253. package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +124 -0
  254. package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +71 -0
  255. package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +10 -0
  256. package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +88 -0
  257. package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +99 -0
  258. package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +233 -0
  259. package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +133 -0
  260. package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +243 -0
  261. package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +167 -0
  262. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/native.js +4 -0
  263. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/rng.js +13 -0
  264. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/stringify.js +28 -0
  265. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/v4.js +19 -0
  266. package/bundle/packages/utils/dist/bytes/index.js +44 -0
  267. package/bundle/packages/utils/dist/common/sharding/index.js +91 -0
  268. package/bundle/packages/utils/dist/logger/index.js +31 -0
  269. package/bundle/resources/rln.wasm +0 -0
  270. package/bundle/resources/rln_final.zkey +0 -0
  271. package/bundle/resources/verification_key.d.ts +13 -0
  272. package/bundle/resources/verification_key.js +112 -0
  273. package/bundle/resources/witness_calculator.d.ts +11 -0
  274. package/bundle/resources/witness_calculator.js +328 -0
  275. package/dist/.tsbuildinfo +1 -1
  276. package/dist/__tests__/identity.test.d.ts +1 -0
  277. package/dist/__tests__/identity.test.js +40 -0
  278. package/dist/__tests__/identity.test.js.map +1 -0
  279. package/dist/codec.d.ts +39 -0
  280. package/dist/codec.js +77 -0
  281. package/dist/codec.js.map +1 -0
  282. package/dist/contract/abi/rlnv2.d.ts +42 -0
  283. package/dist/contract/abi/rlnv2.js +393 -0
  284. package/dist/contract/abi/rlnv2.js.map +1 -0
  285. package/dist/contract/constants.d.ts +68 -0
  286. package/dist/contract/constants.js +31 -0
  287. package/dist/contract/constants.js.map +1 -0
  288. package/dist/contract/index.d.ts +2 -0
  289. package/dist/contract/index.js +3 -0
  290. package/dist/contract/index.js.map +1 -0
  291. package/dist/contract/rln_contract.d.ts +119 -0
  292. package/dist/contract/rln_contract.js +421 -0
  293. package/dist/contract/rln_contract.js.map +1 -0
  294. package/dist/create.d.ts +2 -0
  295. package/dist/create.js +8 -0
  296. package/dist/create.js.map +1 -0
  297. package/dist/identity.d.ts +16 -0
  298. package/dist/identity.js +73 -0
  299. package/dist/identity.js.map +1 -0
  300. package/dist/index.d.ts +11 -2
  301. package/dist/index.js +11 -8
  302. package/dist/index.js.map +1 -1
  303. package/dist/keystore/cipher.d.ts +4 -0
  304. package/dist/keystore/cipher.js +28 -0
  305. package/dist/keystore/cipher.js.map +1 -0
  306. package/dist/keystore/credential_validation_generated.d.ts +8 -0
  307. package/dist/keystore/credential_validation_generated.js +121 -0
  308. package/dist/keystore/credential_validation_generated.js.map +1 -0
  309. package/dist/keystore/index.d.ts +4 -0
  310. package/dist/keystore/index.js +3 -0
  311. package/dist/keystore/index.js.map +1 -0
  312. package/dist/keystore/keystore.d.ts +50 -0
  313. package/dist/keystore/keystore.js +205 -0
  314. package/dist/keystore/keystore.js.map +1 -0
  315. package/dist/keystore/keystore_validation_generated.d.ts +8 -0
  316. package/dist/keystore/keystore_validation_generated.js +75 -0
  317. package/dist/keystore/keystore_validation_generated.js.map +1 -0
  318. package/dist/keystore/schema_validator.d.ts +2 -0
  319. package/dist/keystore/schema_validator.js +18 -0
  320. package/dist/keystore/schema_validator.js.map +1 -0
  321. package/dist/keystore/types.d.ts +29 -0
  322. package/dist/keystore/types.js +2 -0
  323. package/dist/keystore/types.js.map +1 -0
  324. package/dist/message.d.ts +18 -0
  325. package/dist/message.js +49 -0
  326. package/dist/message.js.map +1 -0
  327. package/dist/proof.d.ts +21 -0
  328. package/dist/proof.js +50 -0
  329. package/dist/proof.js.map +1 -0
  330. package/dist/resources/rln.wasm +0 -0
  331. package/dist/resources/rln_final.zkey +0 -0
  332. package/dist/resources/verification_key.d.ts +13 -0
  333. package/dist/resources/verification_key.js +112 -0
  334. package/dist/resources/witness_calculator.d.ts +11 -0
  335. package/dist/resources/witness_calculator.js +328 -0
  336. package/dist/rln.d.ts +59 -13
  337. package/dist/rln.js +164 -81
  338. package/dist/rln.js.map +1 -1
  339. package/dist/root_tracker.d.ts +10 -0
  340. package/dist/root_tracker.js +75 -0
  341. package/dist/root_tracker.js.map +1 -0
  342. package/dist/utils/bytes.d.ts +20 -0
  343. package/dist/utils/bytes.js +64 -0
  344. package/dist/utils/bytes.js.map +1 -0
  345. package/dist/utils/epoch.d.ts +3 -0
  346. package/dist/utils/epoch.js +23 -0
  347. package/dist/utils/epoch.js.map +1 -0
  348. package/dist/utils/hash.d.ts +2 -0
  349. package/dist/utils/hash.js +13 -0
  350. package/dist/utils/hash.js.map +1 -0
  351. package/dist/utils/index.d.ts +4 -0
  352. package/dist/utils/index.js +5 -0
  353. package/dist/utils/index.js.map +1 -0
  354. package/dist/utils/metamask.d.ts +2 -0
  355. package/dist/utils/metamask.js +12 -0
  356. package/dist/utils/metamask.js.map +1 -0
  357. package/dist/zerokit.d.ts +19 -0
  358. package/dist/zerokit.js +119 -0
  359. package/dist/zerokit.js.map +1 -0
  360. package/package.json +1 -126
  361. package/src/__tests__/identity.test.ts +50 -0
  362. package/src/codec.ts +134 -0
  363. package/src/contract/abi/rlnv2.ts +392 -0
  364. package/src/contract/constants.ts +35 -0
  365. package/src/contract/index.ts +2 -0
  366. package/src/contract/rln_contract.ts +673 -0
  367. package/src/create.ts +9 -0
  368. package/src/identity.ts +101 -0
  369. package/src/index.ts +24 -10
  370. package/src/keystore/cipher.ts +54 -0
  371. package/src/keystore/credential_validation_generated.ts +7 -0
  372. package/src/keystore/index.ts +5 -0
  373. package/src/keystore/keystore.ts +330 -0
  374. package/src/keystore/keystore_validation_generated.ts +7 -0
  375. package/src/keystore/schema_validator.ts +34 -0
  376. package/src/keystore/types.ts +36 -0
  377. package/src/message.ts +70 -0
  378. package/src/proof.ts +69 -0
  379. package/src/resources/verification_key.d.ts +13 -0
  380. package/src/resources/witness_calculator.d.ts +11 -0
  381. package/src/rln.ts +270 -106
  382. package/src/root_tracker.ts +92 -0
  383. package/src/utils/bytes.ts +84 -0
  384. package/src/utils/epoch.ts +30 -0
  385. package/src/utils/hash.ts +15 -0
  386. package/src/utils/index.ts +9 -0
  387. package/src/utils/metamask.ts +17 -0
  388. package/src/zerokit.ts +214 -0
  389. package/bundle/02bce7e5f3bcf834.wasm +0 -0
  390. package/bundle/rln-f87f6dbe.js +0 -563
  391. package/dist/resources.d.ts +0 -4
  392. package/dist/resources.js +0 -5
  393. package/dist/resources.js.map +0 -1
  394. package/dist/witness_calculator.d.ts +0 -16
  395. package/dist/witness_calculator.js +0 -291
  396. package/dist/witness_calculator.js.map +0 -1
  397. package/dist/zerokit/rln_wasm.d.ts +0 -1
  398. package/dist/zerokit/rln_wasm.js +0 -2
  399. package/dist/zerokit/rln_wasm.js.map +0 -1
  400. package/dist/zerokit/rln_wasm_bg.d.ts +0 -108
  401. package/dist/zerokit/rln_wasm_bg.js +0 -592
  402. package/dist/zerokit/rln_wasm_bg.js.map +0 -1
  403. package/dist/zerokit/rln_wasm_bg.wasm +0 -0
  404. package/src/resources.ts +0 -10
  405. package/src/witness_calculator.d.ts +0 -4
package/README.md CHANGED
@@ -1,121 +1,25 @@
1
- # js-rln
1
+ # @waku/rln
2
2
 
3
- Browser library providing the cryptographic functions for Waku RLN Relay
4
- https://rfc.vac.dev/spec/17/
5
-
6
- ### Install
7
- ```
8
- npm install @waku/rln
9
-
10
- # or with yarn
11
-
12
- yarn add @waku/rln
13
- ```
14
-
15
- ### Running example app
16
- ```
17
- git clone https://github.com/waku-org/js-rln
18
-
19
- cd js-rln/example
20
-
21
- npm install # or yarn
22
-
23
- npm start
24
-
25
- ```
26
-
27
- Browse http://localhost:8080 and open the dev tools console to see the proof being generated and its verification
28
-
29
-
30
- ### Usage
31
-
32
- #### Initializing the library
33
- ```js
34
- import * as rln from "@waku/rln";
35
-
36
- const rlnInstance = wait rln.create();
37
- ```
38
-
39
- #### Generating RLN membership keypair
40
- ```js
41
- let memKeys = rlnInstance.generateMembershipKey();
42
- ```
3
+ Rate Limiting Nullifier (RLN) implementation for Waku.
43
4
 
5
+ ## Description
44
6
 
45
- #### Adding membership keys into merkle tree
46
- ```js
47
- rlnInstance.inserMember(memKeys.IDCommitment);
48
- ```
49
-
50
- #### Generating a proof
51
- ```js
52
- // prepare the message
53
- const uint8Msg = Uint8Array.from("Hello World".split("").map(x => x.charCodeAt()));
54
-
55
- // setting up the epoch (With 0s for the test)
56
- const epoch = new Uint8Array(32);
7
+ This package provides RLN functionality for the Waku protocol, enabling rate-limiting capabilities while preserving privacy.
57
8
 
58
- // generating a proof
59
- const proof = await rlnInstance.generateProof(uint8Msg, index, epoch, memKeys.IDKey)
60
- ```
9
+ ## Installation
61
10
 
62
- #### Verifying a proof
63
- ```js
64
- try {
65
- // verify the proof
66
- const verifResult = rlnInstance.verifyProof(proof);
67
- console.log("Is proof verified?", verifResult ? "yes" : "no");
68
- } catch (err) {
69
- console.log("Invalid proof")
70
- }
11
+ ```bash
12
+ npm install @waku/rln
71
13
  ```
72
14
 
15
+ ## Usage
73
16
 
17
+ ```typescript
18
+ import { RLN } from '@waku/rln';
74
19
 
75
- ### Updating circuit, verification key and zkey
76
- The RLN specs defines the defaults. These values are fixed and should not
77
- change. Currently, these [resources](https://github.com/vacp2p/zerokit/tree/master/rln/resources/tree_height_20) are being used.
78
- If they change, this file needs to be updated in `resources.ts` which
79
- contains these values encoded in base64 in this format:
80
-
20
+ // Usage examples coming soon
81
21
  ```
82
- const verification_key = "...";
83
- const circuit = "..."; // wasm file generated by circom
84
- const zkey = "...";
85
- export {verification_key, circuit, zkey};
86
- ```
87
-
88
- A tool like GNU's `base64` could be used to encode this data.
89
-
90
- ### Updating zerokit
91
- 1. Make sure you have nodejs installed and a C compiler
92
- 2. Install wasm-pack
93
- ```
94
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
95
- ```
96
- 3. Compile RLN for wasm
97
- ```
98
- git clone https://github.com/vacp2p/zerokit
99
- cd zerokit/rln-wasm
100
- wasm-pack build --release
101
- ```
102
- 4. Copy `pkg/rln*` into `src/zerokit`
103
-
104
-
105
- ## Bugs, Questions & Features
106
-
107
- If you encounter any bug or would like to propose new features, feel free to [open an issue](https://github.com/waku-org/js-rln/issues/new/).
108
-
109
- For more general discussion, help and latest news, join [Vac Discord](https://discord.gg/PQFdubGt6d) or [Telegram](https://t.me/vacp2p).
110
-
111
22
 
112
23
  ## License
113
- Licensed and distributed under either of
114
-
115
- * MIT license: [LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT
116
-
117
- or
118
-
119
- * Apache License, Version 2.0, ([LICENSE-APACHEv2](LICENSE-APACHEv2) or http://www.apache.org/licenses/LICENSE-2.0)
120
24
 
121
- at your option. These files may not be copied, modified, or distributed except according to those terms.
25
+ MIT OR Apache-2.0
@@ -0,0 +1,6 @@
1
+ import * as _nodeResolve_empty from './_node-resolve_empty.js';
2
+ import { getAugmentedNamespace } from './_commonjsHelpers.js';
3
+
4
+ var require$$0 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty);
5
+
6
+ export { require$$0 as default };
@@ -0,0 +1,3 @@
1
+ var _assert = {};
2
+
3
+ export { _assert as __exports };
@@ -0,0 +1,5 @@
1
+ function commonjsRequire(path) {
2
+ throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
3
+ }
4
+
5
+ export { commonjsRequire };
@@ -0,0 +1,32 @@
1
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2
+
3
+ function getDefaultExportFromCjs (x) {
4
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
+ }
6
+
7
+ function getAugmentedNamespace(n) {
8
+ if (n.__esModule) return n;
9
+ var f = n.default;
10
+ if (typeof f == "function") {
11
+ var a = function a () {
12
+ if (this instanceof a) {
13
+ return Reflect.construct(f, arguments, this.constructor);
14
+ }
15
+ return f.apply(this, arguments);
16
+ };
17
+ a.prototype = f.prototype;
18
+ } else a = {};
19
+ Object.defineProperty(a, '__esModule', {value: true});
20
+ Object.keys(n).forEach(function (k) {
21
+ var d = Object.getOwnPropertyDescriptor(n, k);
22
+ Object.defineProperty(a, k, d.get ? d : {
23
+ enumerable: true,
24
+ get: function () {
25
+ return n[k];
26
+ }
27
+ });
28
+ });
29
+ return a;
30
+ }
31
+
32
+ export { commonjsGlobal, getAugmentedNamespace, getDefaultExportFromCjs };
@@ -0,0 +1,3 @@
1
+ var _nodeResolve_empty = {};
2
+
3
+ export { _nodeResolve_empty as default };
@@ -0,0 +1,3 @@
1
+ var _sha2 = {};
2
+
3
+ export { _sha2 as __exports };
@@ -0,0 +1,3 @@
1
+ var _u64 = {};
2
+
3
+ export { _u64 as __exports };
@@ -0,0 +1,3 @@
1
+ var aes = {};
2
+
3
+ export { aes as __exports };
@@ -0,0 +1,3 @@
1
+ var bn = {exports: {}};
2
+
3
+ export { bn as __module };
@@ -0,0 +1,3 @@
1
+ var browser = {exports: {}};
2
+
3
+ export { browser as __module };
@@ -0,0 +1,3 @@
1
+ var checksum = {};
2
+
3
+ export { checksum as __exports };
@@ -0,0 +1,3 @@
1
+ var cipher = {};
2
+
3
+ export { cipher as __exports };
@@ -0,0 +1,3 @@
1
+ var _class = {};
2
+
3
+ export { _class as __exports };
@@ -0,0 +1,3 @@
1
+ var common = {};
2
+
3
+ export { common as __exports };
@@ -0,0 +1,3 @@
1
+ var common = {};
2
+
3
+ export { common as __exports };
@@ -0,0 +1,3 @@
1
+ var cryptoBrowser = {};
2
+
3
+ export { cryptoBrowser as __exports };
@@ -0,0 +1,3 @@
1
+ var functional = {};
2
+
3
+ export { functional as __exports };
@@ -0,0 +1,3 @@
1
+ var hash = {};
2
+
3
+ export { hash as __exports };
@@ -0,0 +1,3 @@
1
+ var hmac = {};
2
+
3
+ export { hmac as __exports };
@@ -0,0 +1,3 @@
1
+ var lib = {};
2
+
3
+ export { lib as __exports };
@@ -0,0 +1,6 @@
1
+ import { getAugmentedNamespace } from './_commonjsHelpers.js';
2
+ import * as index from '../packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js';
3
+
4
+ var require$$0 = /*@__PURE__*/getAugmentedNamespace(index);
5
+
6
+ export { require$$0 as default };
@@ -0,0 +1,3 @@
1
+ var inherits_browser = {exports: {}};
2
+
3
+ export { inherits_browser as __module };
@@ -0,0 +1,3 @@
1
+ var kdf = {};
2
+
3
+ export { kdf as __exports };
@@ -0,0 +1,3 @@
1
+ var lodash = {exports: {}};
2
+
3
+ export { lodash as __module };
@@ -0,0 +1,3 @@
1
+ var password = {};
2
+
3
+ export { password as __exports };
@@ -0,0 +1,3 @@
1
+ var pbkdf2 = {};
2
+
3
+ export { pbkdf2 as __exports };
@@ -0,0 +1,3 @@
1
+ var pbkdf2 = {};
2
+
3
+ export { pbkdf2 as __exports };
@@ -0,0 +1,3 @@
1
+ var random = {};
2
+
3
+ export { random as __exports };
@@ -0,0 +1,3 @@
1
+ var ripemd = {};
2
+
3
+ export { ripemd as __exports };
@@ -0,0 +1,3 @@
1
+ var schemaValidationGenerated = {};
2
+
3
+ export { schemaValidationGenerated as __exports };
@@ -0,0 +1,3 @@
1
+ var schemaValidation = {};
2
+
3
+ export { schemaValidation as __exports };
@@ -0,0 +1,3 @@
1
+ var scrypt = {};
2
+
3
+ export { scrypt as __exports };
@@ -0,0 +1,3 @@
1
+ var scrypt = {};
2
+
3
+ export { scrypt as __exports };
@@ -0,0 +1,3 @@
1
+ var sha = {};
2
+
3
+ export { sha as __exports };
@@ -0,0 +1,3 @@
1
+ var sha256 = {};
2
+
3
+ export { sha256 as __exports };
@@ -0,0 +1,3 @@
1
+ var sha256 = {};
2
+
3
+ export { sha256 as __exports };
@@ -0,0 +1,3 @@
1
+ var sha3 = {exports: {}};
2
+
3
+ export { sha3 as __module };
@@ -0,0 +1,3 @@
1
+ var sha512 = {};
2
+
3
+ export { sha512 as __exports };
@@ -0,0 +1,3 @@
1
+ var types = {};
2
+
3
+ export { types as __exports };
@@ -0,0 +1,3 @@
1
+ var utils = {exports: {}};
2
+
3
+ export { utils as __module };
@@ -0,0 +1,3 @@
1
+ var utils = {};
2
+
3
+ export { utils as __exports };
@@ -0,0 +1,3 @@
1
+ var utils = {};
2
+
3
+ export { utils as __exports };
package/bundle/index.js CHANGED
@@ -1,10 +1,12 @@
1
- // reexport the create function, dynamically imported from rln.ts
2
- async function create() {
3
- // A dependency graph that contains any wasm must all be imported
4
- // asynchronously. This file does the single async import, so
5
- // that no one else needs to worry about it again.
6
- const rlnModule = await import('./rln-f87f6dbe.js');
7
- return await rlnModule.create();
8
- }
9
-
10
- export { create };
1
+ export { RLNDecoder, RLNEncoder } from './packages/rln/dist/codec.js';
2
+ export { RLN_V2_ABI } from './packages/rln/dist/contract/abi/rlnv2.js';
3
+ export { RLNContract } from './packages/rln/dist/contract/rln_contract.js';
4
+ export { SEPOLIA_CONTRACT } from './packages/rln/dist/contract/constants.js';
5
+ export { createRLN } from './packages/rln/dist/create.js';
6
+ export { IdentityCredential } from './packages/rln/dist/identity.js';
7
+ export { Keystore } from './packages/rln/dist/keystore/keystore.js';
8
+ export { Proof } from './packages/rln/dist/proof.js';
9
+ export { RLNInstance } from './packages/rln/dist/rln.js';
10
+ export { MerkleRootTracker } from './packages/rln/dist/root_tracker.js';
11
+ export { extractMetaMaskSigner } from './packages/rln/dist/utils/metamask.js';
12
+ import './packages/rln/dist/utils/epoch.js';
@@ -0,0 +1,3 @@
1
+ const version = "abi/5.7.0";
2
+
3
+ export { version };
@@ -0,0 +1,96 @@
1
+ import { arrayify } from '../../bytes/lib.esm/index.js';
2
+ import { defineReadOnly } from '../../properties/lib.esm/index.js';
3
+ import { Logger } from '../../logger/lib.esm/index.js';
4
+ import { version } from './_version.js';
5
+ import { Reader, Writer } from './coders/abstract-coder.js';
6
+ import { AddressCoder } from './coders/address.js';
7
+ import { ArrayCoder } from './coders/array.js';
8
+ import { BooleanCoder } from './coders/boolean.js';
9
+ import { BytesCoder } from './coders/bytes.js';
10
+ import { FixedBytesCoder } from './coders/fixed-bytes.js';
11
+ import { NullCoder } from './coders/null.js';
12
+ import { NumberCoder } from './coders/number.js';
13
+ import { StringCoder } from './coders/string.js';
14
+ import { TupleCoder } from './coders/tuple.js';
15
+ import { ParamType } from './fragments.js';
16
+
17
+ const logger = new Logger(version);
18
+ const paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
19
+ const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
20
+ class AbiCoder {
21
+ constructor(coerceFunc) {
22
+ defineReadOnly(this, "coerceFunc", coerceFunc || null);
23
+ }
24
+ _getCoder(param) {
25
+ switch (param.baseType) {
26
+ case "address":
27
+ return new AddressCoder(param.name);
28
+ case "bool":
29
+ return new BooleanCoder(param.name);
30
+ case "string":
31
+ return new StringCoder(param.name);
32
+ case "bytes":
33
+ return new BytesCoder(param.name);
34
+ case "array":
35
+ return new ArrayCoder(this._getCoder(param.arrayChildren), param.arrayLength, param.name);
36
+ case "tuple":
37
+ return new TupleCoder((param.components || []).map((component) => {
38
+ return this._getCoder(component);
39
+ }), param.name);
40
+ case "":
41
+ return new NullCoder(param.name);
42
+ }
43
+ // u?int[0-9]*
44
+ let match = param.type.match(paramTypeNumber);
45
+ if (match) {
46
+ let size = parseInt(match[2] || "256");
47
+ if (size === 0 || size > 256 || (size % 8) !== 0) {
48
+ logger.throwArgumentError("invalid " + match[1] + " bit length", "param", param);
49
+ }
50
+ return new NumberCoder(size / 8, (match[1] === "int"), param.name);
51
+ }
52
+ // bytes[0-9]+
53
+ match = param.type.match(paramTypeBytes);
54
+ if (match) {
55
+ let size = parseInt(match[1]);
56
+ if (size === 0 || size > 32) {
57
+ logger.throwArgumentError("invalid bytes length", "param", param);
58
+ }
59
+ return new FixedBytesCoder(size, param.name);
60
+ }
61
+ return logger.throwArgumentError("invalid type", "type", param.type);
62
+ }
63
+ _getWordSize() { return 32; }
64
+ _getReader(data, allowLoose) {
65
+ return new Reader(data, this._getWordSize(), this.coerceFunc, allowLoose);
66
+ }
67
+ _getWriter() {
68
+ return new Writer(this._getWordSize());
69
+ }
70
+ getDefaultValue(types) {
71
+ const coders = types.map((type) => this._getCoder(ParamType.from(type)));
72
+ const coder = new TupleCoder(coders, "_");
73
+ return coder.defaultValue();
74
+ }
75
+ encode(types, values) {
76
+ if (types.length !== values.length) {
77
+ logger.throwError("types/values length mismatch", Logger.errors.INVALID_ARGUMENT, {
78
+ count: { types: types.length, values: values.length },
79
+ value: { types: types, values: values }
80
+ });
81
+ }
82
+ const coders = types.map((type) => this._getCoder(ParamType.from(type)));
83
+ const coder = (new TupleCoder(coders, "_"));
84
+ const writer = this._getWriter();
85
+ coder.encode(writer, values);
86
+ return writer.data;
87
+ }
88
+ decode(types, data, loose) {
89
+ const coders = types.map((type) => this._getCoder(ParamType.from(type)));
90
+ const coder = new TupleCoder(coders, "_");
91
+ return coder.decode(this._getReader(arrayify(data), loose));
92
+ }
93
+ }
94
+ const defaultAbiCoder = new AbiCoder();
95
+
96
+ export { AbiCoder, defaultAbiCoder };
@@ -0,0 +1,148 @@
1
+ import { hexConcat, concat, arrayify, hexlify } from '../../../bytes/lib.esm/index.js';
2
+ import { defineReadOnly } from '../../../properties/lib.esm/index.js';
3
+ import { Logger } from '../../../logger/lib.esm/index.js';
4
+ import { version } from '../_version.js';
5
+ import { BigNumber } from '../../../bignumber/lib.esm/bignumber.js';
6
+
7
+ const logger = new Logger(version);
8
+ function checkResultErrors(result) {
9
+ // Find the first error (if any)
10
+ const errors = [];
11
+ const checkErrors = function (path, object) {
12
+ if (!Array.isArray(object)) {
13
+ return;
14
+ }
15
+ for (let key in object) {
16
+ const childPath = path.slice();
17
+ childPath.push(key);
18
+ try {
19
+ checkErrors(childPath, object[key]);
20
+ }
21
+ catch (error) {
22
+ errors.push({ path: childPath, error: error });
23
+ }
24
+ }
25
+ };
26
+ checkErrors([], result);
27
+ return errors;
28
+ }
29
+ class Coder {
30
+ constructor(name, type, localName, dynamic) {
31
+ // @TODO: defineReadOnly these
32
+ this.name = name;
33
+ this.type = type;
34
+ this.localName = localName;
35
+ this.dynamic = dynamic;
36
+ }
37
+ _throwError(message, value) {
38
+ logger.throwArgumentError(message, this.localName, value);
39
+ }
40
+ }
41
+ class Writer {
42
+ constructor(wordSize) {
43
+ defineReadOnly(this, "wordSize", wordSize || 32);
44
+ this._data = [];
45
+ this._dataLength = 0;
46
+ this._padding = new Uint8Array(wordSize);
47
+ }
48
+ get data() {
49
+ return hexConcat(this._data);
50
+ }
51
+ get length() { return this._dataLength; }
52
+ _writeData(data) {
53
+ this._data.push(data);
54
+ this._dataLength += data.length;
55
+ return data.length;
56
+ }
57
+ appendWriter(writer) {
58
+ return this._writeData(concat(writer._data));
59
+ }
60
+ // Arrayish items; padded on the right to wordSize
61
+ writeBytes(value) {
62
+ let bytes = arrayify(value);
63
+ const paddingOffset = bytes.length % this.wordSize;
64
+ if (paddingOffset) {
65
+ bytes = concat([bytes, this._padding.slice(paddingOffset)]);
66
+ }
67
+ return this._writeData(bytes);
68
+ }
69
+ _getValue(value) {
70
+ let bytes = arrayify(BigNumber.from(value));
71
+ if (bytes.length > this.wordSize) {
72
+ logger.throwError("value out-of-bounds", Logger.errors.BUFFER_OVERRUN, {
73
+ length: this.wordSize,
74
+ offset: bytes.length
75
+ });
76
+ }
77
+ if (bytes.length % this.wordSize) {
78
+ bytes = concat([this._padding.slice(bytes.length % this.wordSize), bytes]);
79
+ }
80
+ return bytes;
81
+ }
82
+ // BigNumberish items; padded on the left to wordSize
83
+ writeValue(value) {
84
+ return this._writeData(this._getValue(value));
85
+ }
86
+ writeUpdatableValue() {
87
+ const offset = this._data.length;
88
+ this._data.push(this._padding);
89
+ this._dataLength += this.wordSize;
90
+ return (value) => {
91
+ this._data[offset] = this._getValue(value);
92
+ };
93
+ }
94
+ }
95
+ class Reader {
96
+ constructor(data, wordSize, coerceFunc, allowLoose) {
97
+ defineReadOnly(this, "_data", arrayify(data));
98
+ defineReadOnly(this, "wordSize", wordSize || 32);
99
+ defineReadOnly(this, "_coerceFunc", coerceFunc);
100
+ defineReadOnly(this, "allowLoose", allowLoose);
101
+ this._offset = 0;
102
+ }
103
+ get data() { return hexlify(this._data); }
104
+ get consumed() { return this._offset; }
105
+ // The default Coerce function
106
+ static coerce(name, value) {
107
+ let match = name.match("^u?int([0-9]+)$");
108
+ if (match && parseInt(match[1]) <= 48) {
109
+ value = value.toNumber();
110
+ }
111
+ return value;
112
+ }
113
+ coerce(name, value) {
114
+ if (this._coerceFunc) {
115
+ return this._coerceFunc(name, value);
116
+ }
117
+ return Reader.coerce(name, value);
118
+ }
119
+ _peekBytes(offset, length, loose) {
120
+ let alignedLength = Math.ceil(length / this.wordSize) * this.wordSize;
121
+ if (this._offset + alignedLength > this._data.length) {
122
+ if (this.allowLoose && loose && this._offset + length <= this._data.length) {
123
+ alignedLength = length;
124
+ }
125
+ else {
126
+ logger.throwError("data out-of-bounds", Logger.errors.BUFFER_OVERRUN, {
127
+ length: this._data.length,
128
+ offset: this._offset + alignedLength
129
+ });
130
+ }
131
+ }
132
+ return this._data.slice(this._offset, this._offset + alignedLength);
133
+ }
134
+ subReader(offset) {
135
+ return new Reader(this._data.slice(this._offset + offset), this.wordSize, this._coerceFunc, this.allowLoose);
136
+ }
137
+ readBytes(length, loose) {
138
+ let bytes = this._peekBytes(0, length, !!loose);
139
+ this._offset += bytes.length;
140
+ // @TODO: Make sure the length..end bytes are all 0?
141
+ return bytes.slice(0, length);
142
+ }
143
+ readValue() {
144
+ return BigNumber.from(this.readBytes(this.wordSize));
145
+ }
146
+ }
147
+
148
+ export { Coder, Reader, Writer, checkResultErrors };