@waku/rln 0.0.1 → 0.0.2-c41b319.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 (401) 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 +54 -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/codec.d.ts +39 -0
  277. package/dist/codec.js +77 -0
  278. package/dist/codec.js.map +1 -0
  279. package/dist/contract/abi/rlnv2.d.ts +42 -0
  280. package/dist/contract/abi/rlnv2.js +393 -0
  281. package/dist/contract/abi/rlnv2.js.map +1 -0
  282. package/dist/contract/constants.d.ts +68 -0
  283. package/dist/contract/constants.js +31 -0
  284. package/dist/contract/constants.js.map +1 -0
  285. package/dist/contract/index.d.ts +2 -0
  286. package/dist/contract/index.js +3 -0
  287. package/dist/contract/index.js.map +1 -0
  288. package/dist/contract/rln_contract.d.ts +119 -0
  289. package/dist/contract/rln_contract.js +421 -0
  290. package/dist/contract/rln_contract.js.map +1 -0
  291. package/dist/create.d.ts +2 -0
  292. package/dist/create.js +8 -0
  293. package/dist/create.js.map +1 -0
  294. package/dist/identity.d.ts +10 -0
  295. package/dist/identity.js +51 -0
  296. package/dist/identity.js.map +1 -0
  297. package/dist/index.d.ts +11 -2
  298. package/dist/index.js +11 -8
  299. package/dist/index.js.map +1 -1
  300. package/dist/keystore/cipher.d.ts +4 -0
  301. package/dist/keystore/cipher.js +28 -0
  302. package/dist/keystore/cipher.js.map +1 -0
  303. package/dist/keystore/credential_validation_generated.d.ts +8 -0
  304. package/dist/keystore/credential_validation_generated.js +121 -0
  305. package/dist/keystore/credential_validation_generated.js.map +1 -0
  306. package/dist/keystore/index.d.ts +4 -0
  307. package/dist/keystore/index.js +3 -0
  308. package/dist/keystore/index.js.map +1 -0
  309. package/dist/keystore/keystore.d.ts +50 -0
  310. package/dist/keystore/keystore.js +205 -0
  311. package/dist/keystore/keystore.js.map +1 -0
  312. package/dist/keystore/keystore_validation_generated.d.ts +8 -0
  313. package/dist/keystore/keystore_validation_generated.js +75 -0
  314. package/dist/keystore/keystore_validation_generated.js.map +1 -0
  315. package/dist/keystore/schema_validator.d.ts +2 -0
  316. package/dist/keystore/schema_validator.js +18 -0
  317. package/dist/keystore/schema_validator.js.map +1 -0
  318. package/dist/keystore/types.d.ts +29 -0
  319. package/dist/keystore/types.js +2 -0
  320. package/dist/keystore/types.js.map +1 -0
  321. package/dist/message.d.ts +18 -0
  322. package/dist/message.js +49 -0
  323. package/dist/message.js.map +1 -0
  324. package/dist/proof.d.ts +21 -0
  325. package/dist/proof.js +50 -0
  326. package/dist/proof.js.map +1 -0
  327. package/dist/resources/rln.wasm +0 -0
  328. package/dist/resources/rln_final.zkey +0 -0
  329. package/dist/resources/verification_key.d.ts +13 -0
  330. package/dist/resources/verification_key.js +112 -0
  331. package/dist/resources/witness_calculator.d.ts +11 -0
  332. package/dist/resources/witness_calculator.js +328 -0
  333. package/dist/rln.d.ts +59 -13
  334. package/dist/rln.js +164 -81
  335. package/dist/rln.js.map +1 -1
  336. package/dist/root_tracker.d.ts +10 -0
  337. package/dist/root_tracker.js +75 -0
  338. package/dist/root_tracker.js.map +1 -0
  339. package/dist/utils/bytes.d.ts +20 -0
  340. package/dist/utils/bytes.js +64 -0
  341. package/dist/utils/bytes.js.map +1 -0
  342. package/dist/utils/epoch.d.ts +3 -0
  343. package/dist/utils/epoch.js +23 -0
  344. package/dist/utils/epoch.js.map +1 -0
  345. package/dist/utils/hash.d.ts +2 -0
  346. package/dist/utils/hash.js +13 -0
  347. package/dist/utils/hash.js.map +1 -0
  348. package/dist/utils/index.d.ts +4 -0
  349. package/dist/utils/index.js +5 -0
  350. package/dist/utils/index.js.map +1 -0
  351. package/dist/utils/metamask.d.ts +2 -0
  352. package/dist/utils/metamask.js +12 -0
  353. package/dist/utils/metamask.js.map +1 -0
  354. package/dist/zerokit.d.ts +19 -0
  355. package/dist/zerokit.js +119 -0
  356. package/dist/zerokit.js.map +1 -0
  357. package/package.json +1 -126
  358. package/src/codec.ts +134 -0
  359. package/src/contract/abi/rlnv2.ts +392 -0
  360. package/src/contract/constants.ts +35 -0
  361. package/src/contract/index.ts +2 -0
  362. package/src/contract/rln_contract.ts +673 -0
  363. package/src/create.ts +9 -0
  364. package/src/identity.ts +73 -0
  365. package/src/index.ts +24 -10
  366. package/src/keystore/cipher.ts +54 -0
  367. package/src/keystore/credential_validation_generated.ts +7 -0
  368. package/src/keystore/index.ts +5 -0
  369. package/src/keystore/keystore.ts +330 -0
  370. package/src/keystore/keystore_validation_generated.ts +7 -0
  371. package/src/keystore/schema_validator.ts +34 -0
  372. package/src/keystore/types.ts +36 -0
  373. package/src/message.ts +70 -0
  374. package/src/proof.ts +69 -0
  375. package/src/resources/verification_key.d.ts +13 -0
  376. package/src/resources/witness_calculator.d.ts +11 -0
  377. package/src/rln.ts +270 -106
  378. package/src/root_tracker.ts +92 -0
  379. package/src/utils/bytes.ts +84 -0
  380. package/src/utils/epoch.ts +30 -0
  381. package/src/utils/hash.ts +15 -0
  382. package/src/utils/index.ts +9 -0
  383. package/src/utils/metamask.ts +17 -0
  384. package/src/zerokit.ts +214 -0
  385. package/bundle/02bce7e5f3bcf834.wasm +0 -0
  386. package/bundle/rln-f87f6dbe.js +0 -563
  387. package/dist/resources.d.ts +0 -4
  388. package/dist/resources.js +0 -5
  389. package/dist/resources.js.map +0 -1
  390. package/dist/witness_calculator.d.ts +0 -16
  391. package/dist/witness_calculator.js +0 -291
  392. package/dist/witness_calculator.js.map +0 -1
  393. package/dist/zerokit/rln_wasm.d.ts +0 -1
  394. package/dist/zerokit/rln_wasm.js +0 -2
  395. package/dist/zerokit/rln_wasm.js.map +0 -1
  396. package/dist/zerokit/rln_wasm_bg.d.ts +0 -108
  397. package/dist/zerokit/rln_wasm_bg.js +0 -592
  398. package/dist/zerokit/rln_wasm_bg.js.map +0 -1
  399. package/dist/zerokit/rln_wasm_bg.wasm +0 -0
  400. package/src/resources.ts +0 -10
  401. package/src/witness_calculator.d.ts +0 -4
@@ -0,0 +1,144 @@
1
+ import { abytes } from './_assert.js';
2
+
3
+ /**
4
+ * Utilities for hex, bytes, CSPRNG.
5
+ * @module
6
+ */
7
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
8
+ // We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
9
+ // node.js versions earlier than v19 don't declare it in global scope.
10
+ // For node.js, package.json#exports field mapping rewrites import
11
+ // from `crypto` to `cryptoNode`, which imports native module.
12
+ // Makes the utils un-importable in browsers without a bundler.
13
+ // Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
14
+ function u32(arr) {
15
+ return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
16
+ }
17
+ // Cast array to view
18
+ function createView(arr) {
19
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
20
+ }
21
+ /** The rotate right (circular right shift) operation for uint32 */
22
+ function rotr(word, shift) {
23
+ return (word << (32 - shift)) | (word >>> shift);
24
+ }
25
+ /** Is current platform little-endian? Most are. Big-Endian platform: IBM */
26
+ const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();
27
+ // The byte swap operation for uint32
28
+ function byteSwap(word) {
29
+ return (((word << 24) & 0xff000000) |
30
+ ((word << 8) & 0xff0000) |
31
+ ((word >>> 8) & 0xff00) |
32
+ ((word >>> 24) & 0xff));
33
+ }
34
+ /** In place byte swap for Uint32Array */
35
+ function byteSwap32(arr) {
36
+ for (let i = 0; i < arr.length; i++) {
37
+ arr[i] = byteSwap(arr[i]);
38
+ }
39
+ }
40
+ // Array where index 0xf0 (240) is mapped to string 'f0'
41
+ const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
42
+ /**
43
+ * Convert byte array to hex string.
44
+ * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
45
+ */
46
+ function bytesToHex(bytes) {
47
+ abytes(bytes);
48
+ // pre-caching improves the speed 6x
49
+ let hex = '';
50
+ for (let i = 0; i < bytes.length; i++) {
51
+ hex += hexes[bytes[i]];
52
+ }
53
+ return hex;
54
+ }
55
+ // We use optimized technique to convert hex string to byte array
56
+ const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
57
+ function asciiToBase16(ch) {
58
+ if (ch >= asciis._0 && ch <= asciis._9)
59
+ return ch - asciis._0; // '2' => 50-48
60
+ if (ch >= asciis.A && ch <= asciis.F)
61
+ return ch - (asciis.A - 10); // 'B' => 66-(65-10)
62
+ if (ch >= asciis.a && ch <= asciis.f)
63
+ return ch - (asciis.a - 10); // 'b' => 98-(97-10)
64
+ return;
65
+ }
66
+ /**
67
+ * Convert hex string to byte array.
68
+ * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
69
+ */
70
+ function hexToBytes(hex) {
71
+ if (typeof hex !== 'string')
72
+ throw new Error('hex string expected, got ' + typeof hex);
73
+ const hl = hex.length;
74
+ const al = hl / 2;
75
+ if (hl % 2)
76
+ throw new Error('hex string expected, got unpadded hex of length ' + hl);
77
+ const array = new Uint8Array(al);
78
+ for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
79
+ const n1 = asciiToBase16(hex.charCodeAt(hi));
80
+ const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
81
+ if (n1 === undefined || n2 === undefined) {
82
+ const char = hex[hi] + hex[hi + 1];
83
+ throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
84
+ }
85
+ array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163
86
+ }
87
+ return array;
88
+ }
89
+ /**
90
+ * Convert JS string to byte array.
91
+ * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
92
+ */
93
+ function utf8ToBytes(str) {
94
+ if (typeof str !== 'string')
95
+ throw new Error('utf8ToBytes expected string, got ' + typeof str);
96
+ return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
97
+ }
98
+ /**
99
+ * Normalizes (non-hex) string or Uint8Array to Uint8Array.
100
+ * Warning: when Uint8Array is passed, it would NOT get copied.
101
+ * Keep in mind for future mutable operations.
102
+ */
103
+ function toBytes(data) {
104
+ if (typeof data === 'string')
105
+ data = utf8ToBytes(data);
106
+ abytes(data);
107
+ return data;
108
+ }
109
+ /**
110
+ * Copies several Uint8Arrays into one.
111
+ */
112
+ function concatBytes(...arrays) {
113
+ let sum = 0;
114
+ for (let i = 0; i < arrays.length; i++) {
115
+ const a = arrays[i];
116
+ abytes(a);
117
+ sum += a.length;
118
+ }
119
+ const res = new Uint8Array(sum);
120
+ for (let i = 0, pad = 0; i < arrays.length; i++) {
121
+ const a = arrays[i];
122
+ res.set(a, pad);
123
+ pad += a.length;
124
+ }
125
+ return res;
126
+ }
127
+ /** For runtime check if class implements interface */
128
+ class Hash {
129
+ // Safe version that clones internal state
130
+ clone() {
131
+ return this._cloneInto();
132
+ }
133
+ }
134
+ /** Wraps hash function, creating an interface on top of it */
135
+ function wrapConstructor(hashCons) {
136
+ const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
137
+ const tmp = hashCons();
138
+ hashC.outputLen = tmp.outputLen;
139
+ hashC.blockLen = tmp.blockLen;
140
+ hashC.create = () => hashCons();
141
+ return hashC;
142
+ }
143
+
144
+ export { Hash, byteSwap, byteSwap32, bytesToHex, concatBytes, createView, hexToBytes, isLE, rotr, toBytes, u32, utf8ToBytes, wrapConstructor };
@@ -0,0 +1,22 @@
1
+ // Copyright (C) 2016 Dmitry Chestnykh
2
+ // MIT License. See LICENSE file for details.
3
+ /**
4
+ * Package binary provides functions for encoding and decoding numbers in byte arrays.
5
+ */
6
+ /**
7
+ * Writes 4-byte little-endian representation of 32-bit unsigned
8
+ * value to array starting at offset.
9
+ *
10
+ * If byte array is not given, creates a new 4-byte one.
11
+ *
12
+ * Returns the output byte array.
13
+ */
14
+ function writeUint32LE(value, out = new Uint8Array(4), offset = 0) {
15
+ out[offset + 0] = value >>> 0;
16
+ out[offset + 1] = value >>> 8;
17
+ out[offset + 2] = value >>> 16;
18
+ out[offset + 3] = value >>> 24;
19
+ return out;
20
+ }
21
+
22
+ export { writeUint32LE };
@@ -0,0 +1,245 @@
1
+ import { writeUint32LE } from '../../binary/lib/binary.js';
2
+ import { wipe } from '../../wipe/lib/wipe.js';
3
+
4
+ // Copyright (C) 2016 Dmitry Chestnykh
5
+ // MIT License. See LICENSE file for details.
6
+ /**
7
+ * Package chacha implements ChaCha stream cipher.
8
+ */
9
+ // Number of ChaCha rounds (ChaCha20).
10
+ const ROUNDS = 20;
11
+ // Applies the ChaCha core function to 16-byte input,
12
+ // 32-byte key key, and puts the result into 64-byte array out.
13
+ function core(out, input, key) {
14
+ let j0 = 0x61707865; // "expa" -- ChaCha's "sigma" constant
15
+ let j1 = 0x3320646E; // "nd 3" for 32-byte keys
16
+ let j2 = 0x79622D32; // "2-by"
17
+ let j3 = 0x6B206574; // "te k"
18
+ let j4 = (key[3] << 24) | (key[2] << 16) | (key[1] << 8) | key[0];
19
+ let j5 = (key[7] << 24) | (key[6] << 16) | (key[5] << 8) | key[4];
20
+ let j6 = (key[11] << 24) | (key[10] << 16) | (key[9] << 8) | key[8];
21
+ let j7 = (key[15] << 24) | (key[14] << 16) | (key[13] << 8) | key[12];
22
+ let j8 = (key[19] << 24) | (key[18] << 16) | (key[17] << 8) | key[16];
23
+ let j9 = (key[23] << 24) | (key[22] << 16) | (key[21] << 8) | key[20];
24
+ let j10 = (key[27] << 24) | (key[26] << 16) | (key[25] << 8) | key[24];
25
+ let j11 = (key[31] << 24) | (key[30] << 16) | (key[29] << 8) | key[28];
26
+ let j12 = (input[3] << 24) | (input[2] << 16) | (input[1] << 8) | input[0];
27
+ let j13 = (input[7] << 24) | (input[6] << 16) | (input[5] << 8) | input[4];
28
+ let j14 = (input[11] << 24) | (input[10] << 16) | (input[9] << 8) | input[8];
29
+ let j15 = (input[15] << 24) | (input[14] << 16) | (input[13] << 8) | input[12];
30
+ let x0 = j0;
31
+ let x1 = j1;
32
+ let x2 = j2;
33
+ let x3 = j3;
34
+ let x4 = j4;
35
+ let x5 = j5;
36
+ let x6 = j6;
37
+ let x7 = j7;
38
+ let x8 = j8;
39
+ let x9 = j9;
40
+ let x10 = j10;
41
+ let x11 = j11;
42
+ let x12 = j12;
43
+ let x13 = j13;
44
+ let x14 = j14;
45
+ let x15 = j15;
46
+ for (let i = 0; i < ROUNDS; i += 2) {
47
+ x0 = x0 + x4 | 0;
48
+ x12 ^= x0;
49
+ x12 = x12 >>> (32 - 16) | x12 << 16;
50
+ x8 = x8 + x12 | 0;
51
+ x4 ^= x8;
52
+ x4 = x4 >>> (32 - 12) | x4 << 12;
53
+ x1 = x1 + x5 | 0;
54
+ x13 ^= x1;
55
+ x13 = x13 >>> (32 - 16) | x13 << 16;
56
+ x9 = x9 + x13 | 0;
57
+ x5 ^= x9;
58
+ x5 = x5 >>> (32 - 12) | x5 << 12;
59
+ x2 = x2 + x6 | 0;
60
+ x14 ^= x2;
61
+ x14 = x14 >>> (32 - 16) | x14 << 16;
62
+ x10 = x10 + x14 | 0;
63
+ x6 ^= x10;
64
+ x6 = x6 >>> (32 - 12) | x6 << 12;
65
+ x3 = x3 + x7 | 0;
66
+ x15 ^= x3;
67
+ x15 = x15 >>> (32 - 16) | x15 << 16;
68
+ x11 = x11 + x15 | 0;
69
+ x7 ^= x11;
70
+ x7 = x7 >>> (32 - 12) | x7 << 12;
71
+ x2 = x2 + x6 | 0;
72
+ x14 ^= x2;
73
+ x14 = x14 >>> (32 - 8) | x14 << 8;
74
+ x10 = x10 + x14 | 0;
75
+ x6 ^= x10;
76
+ x6 = x6 >>> (32 - 7) | x6 << 7;
77
+ x3 = x3 + x7 | 0;
78
+ x15 ^= x3;
79
+ x15 = x15 >>> (32 - 8) | x15 << 8;
80
+ x11 = x11 + x15 | 0;
81
+ x7 ^= x11;
82
+ x7 = x7 >>> (32 - 7) | x7 << 7;
83
+ x1 = x1 + x5 | 0;
84
+ x13 ^= x1;
85
+ x13 = x13 >>> (32 - 8) | x13 << 8;
86
+ x9 = x9 + x13 | 0;
87
+ x5 ^= x9;
88
+ x5 = x5 >>> (32 - 7) | x5 << 7;
89
+ x0 = x0 + x4 | 0;
90
+ x12 ^= x0;
91
+ x12 = x12 >>> (32 - 8) | x12 << 8;
92
+ x8 = x8 + x12 | 0;
93
+ x4 ^= x8;
94
+ x4 = x4 >>> (32 - 7) | x4 << 7;
95
+ x0 = x0 + x5 | 0;
96
+ x15 ^= x0;
97
+ x15 = x15 >>> (32 - 16) | x15 << 16;
98
+ x10 = x10 + x15 | 0;
99
+ x5 ^= x10;
100
+ x5 = x5 >>> (32 - 12) | x5 << 12;
101
+ x1 = x1 + x6 | 0;
102
+ x12 ^= x1;
103
+ x12 = x12 >>> (32 - 16) | x12 << 16;
104
+ x11 = x11 + x12 | 0;
105
+ x6 ^= x11;
106
+ x6 = x6 >>> (32 - 12) | x6 << 12;
107
+ x2 = x2 + x7 | 0;
108
+ x13 ^= x2;
109
+ x13 = x13 >>> (32 - 16) | x13 << 16;
110
+ x8 = x8 + x13 | 0;
111
+ x7 ^= x8;
112
+ x7 = x7 >>> (32 - 12) | x7 << 12;
113
+ x3 = x3 + x4 | 0;
114
+ x14 ^= x3;
115
+ x14 = x14 >>> (32 - 16) | x14 << 16;
116
+ x9 = x9 + x14 | 0;
117
+ x4 ^= x9;
118
+ x4 = x4 >>> (32 - 12) | x4 << 12;
119
+ x2 = x2 + x7 | 0;
120
+ x13 ^= x2;
121
+ x13 = x13 >>> (32 - 8) | x13 << 8;
122
+ x8 = x8 + x13 | 0;
123
+ x7 ^= x8;
124
+ x7 = x7 >>> (32 - 7) | x7 << 7;
125
+ x3 = x3 + x4 | 0;
126
+ x14 ^= x3;
127
+ x14 = x14 >>> (32 - 8) | x14 << 8;
128
+ x9 = x9 + x14 | 0;
129
+ x4 ^= x9;
130
+ x4 = x4 >>> (32 - 7) | x4 << 7;
131
+ x1 = x1 + x6 | 0;
132
+ x12 ^= x1;
133
+ x12 = x12 >>> (32 - 8) | x12 << 8;
134
+ x11 = x11 + x12 | 0;
135
+ x6 ^= x11;
136
+ x6 = x6 >>> (32 - 7) | x6 << 7;
137
+ x0 = x0 + x5 | 0;
138
+ x15 ^= x0;
139
+ x15 = x15 >>> (32 - 8) | x15 << 8;
140
+ x10 = x10 + x15 | 0;
141
+ x5 ^= x10;
142
+ x5 = x5 >>> (32 - 7) | x5 << 7;
143
+ }
144
+ writeUint32LE(x0 + j0 | 0, out, 0);
145
+ writeUint32LE(x1 + j1 | 0, out, 4);
146
+ writeUint32LE(x2 + j2 | 0, out, 8);
147
+ writeUint32LE(x3 + j3 | 0, out, 12);
148
+ writeUint32LE(x4 + j4 | 0, out, 16);
149
+ writeUint32LE(x5 + j5 | 0, out, 20);
150
+ writeUint32LE(x6 + j6 | 0, out, 24);
151
+ writeUint32LE(x7 + j7 | 0, out, 28);
152
+ writeUint32LE(x8 + j8 | 0, out, 32);
153
+ writeUint32LE(x9 + j9 | 0, out, 36);
154
+ writeUint32LE(x10 + j10 | 0, out, 40);
155
+ writeUint32LE(x11 + j11 | 0, out, 44);
156
+ writeUint32LE(x12 + j12 | 0, out, 48);
157
+ writeUint32LE(x13 + j13 | 0, out, 52);
158
+ writeUint32LE(x14 + j14 | 0, out, 56);
159
+ writeUint32LE(x15 + j15 | 0, out, 60);
160
+ }
161
+ /**
162
+ * Encrypt src with ChaCha20 stream generated for the given 32-byte key and
163
+ * 8-byte (as in original implementation) or 12-byte (as in RFC7539) nonce and
164
+ * write the result into dst and return it.
165
+ *
166
+ * dst and src may be the same, but otherwise must not overlap.
167
+ *
168
+ * If nonce is 12 bytes, users should not encrypt more than 256 GiB with the
169
+ * same key and nonce, otherwise the stream will repeat. The function will
170
+ * throw error if counter overflows to prevent this.
171
+ *
172
+ * If nonce is 8 bytes, the output is practically unlimited (2^70 bytes, which
173
+ * is more than a million petabytes). However, it is not recommended to
174
+ * generate 8-byte nonces randomly, as the chance of collision is high.
175
+ *
176
+ * Never use the same key and nonce to encrypt more than one message.
177
+ *
178
+ * If nonceInplaceCounterLength is not 0, the nonce is assumed to be a 16-byte
179
+ * array with stream counter in first nonceInplaceCounterLength bytes and nonce
180
+ * in the last remaining bytes. The counter will be incremented inplace for
181
+ * each ChaCha block. This is useful if you need to encrypt one stream of data
182
+ * in chunks.
183
+ */
184
+ function streamXOR(key, nonce, src, dst, nonceInplaceCounterLength = 0) {
185
+ // We only support 256-bit keys.
186
+ if (key.length !== 32) {
187
+ throw new Error("ChaCha: key size must be 32 bytes");
188
+ }
189
+ if (dst.length < src.length) {
190
+ throw new Error("ChaCha: destination is shorter than source");
191
+ }
192
+ let nc;
193
+ let counterLength;
194
+ if (nonceInplaceCounterLength === 0) {
195
+ if (nonce.length !== 8 && nonce.length !== 12) {
196
+ throw new Error("ChaCha nonce must be 8 or 12 bytes");
197
+ }
198
+ nc = new Uint8Array(16);
199
+ // First counterLength bytes of nc are counter, starting with zero.
200
+ counterLength = nc.length - nonce.length;
201
+ // Last bytes of nc after counterLength are nonce, set them.
202
+ nc.set(nonce, counterLength);
203
+ }
204
+ else {
205
+ if (nonce.length !== 16) {
206
+ throw new Error("ChaCha nonce with counter must be 16 bytes");
207
+ }
208
+ // This will update passed nonce with counter inplace.
209
+ nc = nonce;
210
+ counterLength = nonceInplaceCounterLength;
211
+ }
212
+ // Allocate temporary space for ChaCha block.
213
+ const block = new Uint8Array(64);
214
+ for (let i = 0; i < src.length; i += 64) {
215
+ // Generate a block.
216
+ core(block, nc, key);
217
+ // XOR block bytes with src into dst.
218
+ for (let j = i; j < i + 64 && j < src.length; j++) {
219
+ dst[j] = src[j] ^ block[j - i];
220
+ }
221
+ // Increment counter.
222
+ incrementCounter(nc, 0, counterLength);
223
+ }
224
+ // Cleanup temporary space.
225
+ wipe(block);
226
+ if (nonceInplaceCounterLength === 0) {
227
+ // Cleanup counter.
228
+ wipe(nc);
229
+ }
230
+ return dst;
231
+ }
232
+ function incrementCounter(counter, pos, len) {
233
+ let carry = 1;
234
+ while (len--) {
235
+ carry = carry + (counter[pos] & 0xff) | 0;
236
+ counter[pos] = carry & 0xff;
237
+ carry >>>= 8;
238
+ pos++;
239
+ }
240
+ if (carry > 0) {
241
+ throw new Error("ChaCha: counter overflow");
242
+ }
243
+ }
244
+
245
+ export { streamXOR };
@@ -0,0 +1,26 @@
1
+ // Copyright (C) 2016 Dmitry Chestnykh
2
+ // MIT License. See LICENSE file for details.
3
+ /**
4
+ * Sets all values in the given array to zero and returns it.
5
+ *
6
+ * The fact that it sets bytes to zero can be relied on.
7
+ *
8
+ * There is no guarantee that this function makes data disappear from memory,
9
+ * as runtime implementation can, for example, have copying garbage collector
10
+ * that will make copies of sensitive data before we wipe it. Or that an
11
+ * operating system will write our data to swap or sleep image. Another thing
12
+ * is that an optimizing compiler can remove calls to this function or make it
13
+ * no-op. There's nothing we can do with it, so we just do our best and hope
14
+ * that everything will be okay and good will triumph over evil.
15
+ */
16
+ function wipe(array) {
17
+ // Right now it's similar to array.fill(0). If it turns
18
+ // out that runtimes optimize this call away, maybe
19
+ // we can try something else.
20
+ for (let i = 0; i < array.length; i++) {
21
+ array[i] = 0;
22
+ }
23
+ return array;
24
+ }
25
+
26
+ export { wipe };