lib0 0.2.77 → 0.2.79

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 (202) hide show
  1. package/README.md +1 -1
  2. package/array.d.ts +1 -0
  3. package/array.d.ts.map +1 -1
  4. package/array.js +18 -0
  5. package/binary.test.d.ts.map +1 -1
  6. package/buffer.d.ts +3 -0
  7. package/buffer.d.ts.map +1 -1
  8. package/buffer.js +40 -0
  9. package/buffer.test.d.ts +2 -1
  10. package/buffer.test.d.ts.map +1 -1
  11. package/cache.d.ts.map +1 -1
  12. package/cache.js +0 -1
  13. package/cache.test.d.ts.map +1 -1
  14. package/component.d.ts +5 -5
  15. package/component.d.ts.map +1 -1
  16. package/component.js +14 -11
  17. package/coverage/tmp/coverage-10499-1691528887100-0.json +1 -0
  18. package/decoding.d.ts +2 -0
  19. package/decoding.d.ts.map +1 -1
  20. package/decoding.js +26 -0
  21. package/dist/aes-gcm.cjs +161 -0
  22. package/dist/aes-gcm.cjs.map +1 -0
  23. package/dist/{array-fd99bc23.cjs → array-704ca50e.cjs} +22 -2
  24. package/dist/array-704ca50e.cjs.map +1 -0
  25. package/dist/array.cjs +2 -1
  26. package/dist/array.cjs.map +1 -1
  27. package/dist/array.d.ts +1 -0
  28. package/dist/array.d.ts.map +1 -1
  29. package/dist/binary.test.d.ts.map +1 -1
  30. package/dist/{broadcastchannel-fff713ef.cjs → broadcastchannel-7801969a.cjs} +2 -2
  31. package/dist/{broadcastchannel-fff713ef.cjs.map → broadcastchannel-7801969a.cjs.map} +1 -1
  32. package/dist/broadcastchannel.cjs +9 -9
  33. package/dist/{buffer-621617f6.cjs → buffer-c5d69c70.cjs} +126 -7
  34. package/dist/buffer-c5d69c70.cjs.map +1 -0
  35. package/dist/buffer.cjs +12 -9
  36. package/dist/buffer.cjs.map +1 -1
  37. package/dist/buffer.d.ts +3 -0
  38. package/dist/buffer.d.ts.map +1 -1
  39. package/dist/buffer.test.d.ts +2 -1
  40. package/dist/buffer.test.d.ts.map +1 -1
  41. package/dist/cache.cjs +5 -3
  42. package/dist/cache.cjs.map +1 -1
  43. package/dist/cache.d.ts.map +1 -1
  44. package/dist/cache.test.d.ts.map +1 -1
  45. package/dist/common.cjs +37 -0
  46. package/dist/common.cjs.map +1 -0
  47. package/dist/component.cjs +20 -17
  48. package/dist/component.cjs.map +1 -1
  49. package/dist/component.d.ts +5 -5
  50. package/dist/component.d.ts.map +1 -1
  51. package/dist/decoding.cjs +9 -7
  52. package/dist/decoding.cjs.map +1 -1
  53. package/dist/decoding.d.ts +2 -0
  54. package/dist/decoding.d.ts.map +1 -1
  55. package/dist/{diff-18852f48.cjs → diff-fbaa426b.cjs} +2 -2
  56. package/dist/{diff-18852f48.cjs.map → diff-fbaa426b.cjs.map} +1 -1
  57. package/dist/diff.cjs +4 -4
  58. package/dist/ecdsa.cjs +118 -0
  59. package/dist/ecdsa.cjs.map +1 -0
  60. package/dist/encoding.cjs +9 -7
  61. package/dist/encoding.cjs.map +1 -1
  62. package/dist/encoding.d.ts +2 -0
  63. package/dist/encoding.d.ts.map +1 -1
  64. package/dist/encoding.test.d.ts +1 -0
  65. package/dist/encoding.test.d.ts.map +1 -1
  66. package/dist/{environment-0c5ff22b.cjs → environment-ad129e4d.cjs} +3 -3
  67. package/dist/{environment-0c5ff22b.cjs.map → environment-ad129e4d.cjs.map} +1 -1
  68. package/dist/environment.cjs +5 -5
  69. package/dist/{function-831844d3.cjs → function-314fdc56.cjs} +3 -3
  70. package/dist/{function-831844d3.cjs.map → function-314fdc56.cjs.map} +1 -1
  71. package/dist/function.cjs +3 -3
  72. package/dist/hash/rabin-gf2-polynomial.d.ts +45 -0
  73. package/dist/hash/rabin-gf2-polynomial.d.ts.map +1 -0
  74. package/dist/hash/rabin-uncached.d.ts +29 -0
  75. package/dist/hash/rabin-uncached.d.ts.map +1 -0
  76. package/dist/hash/rabin.d.ts +27 -0
  77. package/dist/hash/rabin.d.ts.map +1 -0
  78. package/dist/hash/rabin.test.d.ts +8 -0
  79. package/dist/hash/rabin.test.d.ts.map +1 -0
  80. package/dist/hash/sha256.fallback.d.ts +2 -0
  81. package/dist/hash/sha256.fallback.d.ts.map +1 -0
  82. package/dist/hash/sha256.node.d.ts +2 -0
  83. package/dist/hash/sha256.node.d.ts.map +1 -0
  84. package/dist/hash/sha256.test.d.ts +6 -0
  85. package/dist/hash/sha256.test.d.ts.map +1 -0
  86. package/dist/index.cjs +11 -11
  87. package/dist/list.cjs +3 -3
  88. package/dist/logging.cjs +5 -5
  89. package/dist/logging.common.cjs +21 -21
  90. package/dist/logging.common.cjs.map +1 -1
  91. package/dist/logging.node.cjs +5 -5
  92. package/dist/logging.test.d.ts.map +1 -1
  93. package/dist/{number-dc113762.cjs → number-466d8922.cjs} +29 -10
  94. package/dist/number-466d8922.cjs.map +1 -0
  95. package/dist/number.cjs +2 -1
  96. package/dist/number.cjs.map +1 -1
  97. package/dist/number.d.ts +1 -0
  98. package/dist/number.d.ts.map +1 -1
  99. package/dist/number.test.d.ts +1 -1
  100. package/dist/number.test.d.ts.map +1 -1
  101. package/dist/{object-aad630ed.cjs → object-fecf6a7b.cjs} +2 -1
  102. package/dist/object-fecf6a7b.cjs.map +1 -0
  103. package/dist/object.cjs +1 -1
  104. package/dist/object.d.ts.map +1 -1
  105. package/dist/observable.cjs +1 -1
  106. package/dist/performance.node.cjs +3 -3
  107. package/dist/{prng-9ccc85f7.cjs → prng-1149c8c4.cjs} +3 -3
  108. package/dist/{prng-9ccc85f7.cjs.map → prng-1149c8c4.cjs.map} +1 -1
  109. package/dist/prng.cjs +8 -8
  110. package/dist/prng.test.d.ts.map +1 -1
  111. package/dist/queue.cjs.map +1 -1
  112. package/dist/queue.d.ts.map +1 -1
  113. package/dist/rabin-gf2-polynomial.cjs +437 -0
  114. package/dist/rabin-gf2-polynomial.cjs.map +1 -0
  115. package/dist/rabin-uncached.cjs +87 -0
  116. package/dist/rabin-uncached.cjs.map +1 -0
  117. package/dist/rabin.cjs +125 -0
  118. package/dist/rabin.cjs.map +1 -0
  119. package/dist/random.cjs +12 -0
  120. package/dist/random.cjs.map +1 -1
  121. package/dist/random.d.ts +1 -1
  122. package/dist/random.d.ts.map +1 -1
  123. package/dist/rsa-oaep.cjs +112 -0
  124. package/dist/rsa-oaep.cjs.map +1 -0
  125. package/dist/set.test.d.ts.map +1 -1
  126. package/dist/sha256.fallback.cjs +179 -0
  127. package/dist/sha256.fallback.cjs.map +1 -0
  128. package/dist/sha256.node.cjs +17 -0
  129. package/dist/sha256.node.cjs.map +1 -0
  130. package/dist/{string-e7eb0c1d.cjs → string-6d104757.cjs} +10 -2
  131. package/dist/string-6d104757.cjs.map +1 -0
  132. package/dist/string.cjs +3 -2
  133. package/dist/string.cjs.map +1 -1
  134. package/dist/string.d.ts +5 -0
  135. package/dist/string.d.ts.map +1 -1
  136. package/dist/testing.cjs +23 -17
  137. package/dist/testing.cjs.map +1 -1
  138. package/dist/testing.d.ts +13 -7
  139. package/dist/testing.d.ts.map +1 -1
  140. package/dist/url.cjs +1 -1
  141. package/dist/webcrypto.node.cjs.map +1 -1
  142. package/dist/webcrypto.node.d.ts.map +1 -1
  143. package/dist/{websocket-0632cb8c.cjs → websocket-44e4ead5.cjs} +1 -1
  144. package/dist/{websocket-0632cb8c.cjs.map → websocket-44e4ead5.cjs.map} +1 -1
  145. package/dist/websocket.cjs +2 -2
  146. package/encoding.d.ts +2 -0
  147. package/encoding.d.ts.map +1 -1
  148. package/encoding.js +42 -0
  149. package/encoding.test.d.ts +1 -0
  150. package/encoding.test.d.ts.map +1 -1
  151. package/hash/rabin-gf2-polynomial.d.ts +45 -0
  152. package/hash/rabin-gf2-polynomial.d.ts.map +1 -0
  153. package/hash/rabin-gf2-polynomial.js +379 -0
  154. package/hash/rabin-uncached.d.ts +29 -0
  155. package/hash/rabin-uncached.d.ts.map +1 -0
  156. package/hash/rabin-uncached.js +68 -0
  157. package/hash/rabin.d.ts +27 -0
  158. package/hash/rabin.d.ts.map +1 -0
  159. package/hash/rabin.js +100 -0
  160. package/hash/rabin.test.d.ts +8 -0
  161. package/hash/rabin.test.d.ts.map +1 -0
  162. package/hash/sha256.fallback.d.ts +2 -0
  163. package/hash/sha256.fallback.d.ts.map +1 -0
  164. package/hash/sha256.fallback.js +172 -0
  165. package/hash/sha256.node.d.ts +2 -0
  166. package/hash/sha256.node.d.ts.map +1 -0
  167. package/hash/sha256.node.js +10 -0
  168. package/hash/sha256.test.d.ts +6 -0
  169. package/hash/sha256.test.d.ts.map +1 -0
  170. package/logging.common.js +16 -16
  171. package/logging.test.d.ts.map +1 -1
  172. package/number.d.ts +1 -0
  173. package/number.d.ts.map +1 -1
  174. package/number.js +17 -0
  175. package/number.test.d.ts +1 -1
  176. package/number.test.d.ts.map +1 -1
  177. package/object.d.ts.map +1 -1
  178. package/object.js +1 -0
  179. package/package.json +24 -6
  180. package/prng.test.d.ts.map +1 -1
  181. package/queue.d.ts.map +1 -1
  182. package/queue.js +0 -1
  183. package/random.d.ts +1 -1
  184. package/random.d.ts.map +1 -1
  185. package/random.js +4 -1
  186. package/set.test.d.ts.map +1 -1
  187. package/string.d.ts +5 -0
  188. package/string.d.ts.map +1 -1
  189. package/string.js +6 -0
  190. package/test.html +2 -0
  191. package/test.js +4 -0
  192. package/testing.d.ts +13 -7
  193. package/testing.d.ts.map +1 -1
  194. package/testing.js +14 -8
  195. package/webcrypto.node.d.ts.map +1 -1
  196. package/webcrypto.node.js +0 -1
  197. package/coverage/tmp/coverage-36234-1685177795346-0.json +0 -1
  198. package/dist/array-fd99bc23.cjs.map +0 -1
  199. package/dist/buffer-621617f6.cjs.map +0 -1
  200. package/dist/number-dc113762.cjs.map +0 -1
  201. package/dist/object-aad630ed.cjs.map +0 -1
  202. package/dist/string-e7eb0c1d.cjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rabin.cjs","sources":["../hash/rabin.js"],"sourcesContent":["/**\n * @module rabin\n *\n * Very efficient & versatile fingerprint/hashing algorithm. However, it is not cryptographically\n * secure. Well suited for fingerprinting.\n */\n\nimport * as buffer from '../buffer.js'\nimport * as map from '../map.js'\n\nexport const StandardIrreducible8 = new Uint8Array([1, 221])\nexport const StandardIrreducible16 = new Uint8Array([1, 244, 157])\nexport const StandardIrreducible32 = new Uint8Array([1, 149, 183, 205, 191])\nexport const StandardIrreducible64 = new Uint8Array([1, 133, 250, 114, 193, 250, 28, 193, 231])\nexport const StandardIrreducible128 = new Uint8Array([1, 94, 109, 166, 228, 6, 222, 102, 239, 27, 128, 184, 13, 50, 112, 169, 199])\n\n/**\n * Maps from a modulo to the precomputed values.\n *\n * @type {Map<string,Uint8Array>}\n */\nconst _precomputedFingerprintCache = new Map()\n\n/**\n * @param {Uint8Array} m\n */\nconst ensureCache = m => map.setIfUndefined(_precomputedFingerprintCache, buffer.toBase64(m), () => {\n const byteLen = m.byteLength\n const cache = new Uint8Array(256 * byteLen)\n // Use dynamic computing to compute the cached results.\n // Starting values: cache(0) = 0; cache(1) = m\n cache.set(m, byteLen)\n for (let bit = 1; bit < 8; bit++) {\n const mBitShifted = buffer.shiftNBitsLeft(m, bit)\n const bitShifted = 1 << bit\n for (let j = 0; j < bitShifted; j++) {\n // apply the shifted result (reducing the degree of the polynomial)\n const msb = bitShifted | j\n const rest = msb ^ mBitShifted[0]\n for (let i = 0; i < byteLen; i++) {\n // rest is already precomputed in the cache\n cache[msb * byteLen + i] = cache[rest * byteLen + i] ^ mBitShifted[i]\n }\n // if (cache[(bitShifted | j) * byteLen] !== (bitShifted | j)) { error.unexpectedCase() }\n }\n }\n return cache\n})\n\nexport class RabinEncoder {\n /**\n * @param {Uint8Array} m assert(m[0] === 1)\n */\n constructor (m) {\n this.m = m\n this.blen = m.byteLength\n this.bs = new Uint8Array(this.blen)\n this.cache = ensureCache(m)\n /**\n * This describes the position of the most significant byte (starts with 0 and increases with\n * shift)\n */\n this.bpos = 0\n }\n\n /**\n * @param {number} byte\n */\n write (byte) {\n // assert(this.bs[0] === 0)\n // Shift one byte to the left, add b\n this.bs[this.bpos] = byte\n this.bpos = (this.bpos + 1) % this.blen\n const msb = this.bs[this.bpos]\n for (let i = 0; i < this.blen; i++) {\n this.bs[(this.bpos + i) % this.blen] ^= this.cache[msb * this.blen + i]\n }\n // assert(this.bs[this.bpos] === 0)\n }\n\n getFingerprint () {\n const result = new Uint8Array(this.blen - 1)\n for (let i = 0; i < result.byteLength; i++) {\n result[i] = this.bs[(this.bpos + i + 1) % this.blen]\n }\n return result\n }\n}\n\n/**\n * @param {Uint8Array} irreducible\n * @param {Uint8Array} data\n */\nexport const fingerprint = (irreducible, data) => {\n const encoder = new RabinEncoder(irreducible)\n for (let i = 0; i < data.length; i++) {\n encoder.write(data[i])\n }\n return encoder.getFingerprint()\n}\n"],"names":["map.setIfUndefined","buffer.toBase64","buffer.shiftNBitsLeft"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAIA;AACY,MAAC,oBAAoB,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAC;AAChD,MAAC,qBAAqB,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EAAC;AACtD,MAAC,qBAAqB,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAC;AAChE,MAAC,qBAAqB,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,EAAC;AACnF,MAAC,sBAAsB,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAA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C,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,EAAC;AAC1D,KAAK;AACL,IAAI,OAAO,MAAM;AACjB,GAAG;AACH,CAAC;AACD;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG,CAAC,WAAW,EAAE,IAAI,KAAK;AAClD,EAAE,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,WAAW,EAAC;AAC/C,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACxC,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAC;AAC1B,GAAG;AACH,EAAE,OAAO,OAAO,CAAC,cAAc,EAAE;AACjC;;;;;;;;;;"}
package/dist/random.cjs CHANGED
@@ -6,6 +6,14 @@ var math = require('./math-08e068f9.cjs');
6
6
  var binary = require('./binary-ac8e39e2.cjs');
7
7
  var webcrypto = require('lib0/webcrypto');
8
8
 
9
+ /**
10
+ * Isomorphic module for true random numbers / buffers / uuids.
11
+ *
12
+ * Attention: falls back to Math.random if the browser does not support crypto.
13
+ *
14
+ * @module random
15
+ */
16
+
9
17
  const rand = Math.random;
10
18
 
11
19
  const uint32 = () => webcrypto.getRandomValues(new Uint32Array(1))[0];
@@ -24,6 +32,10 @@ const oneOf = arr => arr[math.floor(rand() * arr.length)];
24
32
 
25
33
  // @ts-ignore
26
34
  const uuidv4Template = [1e7] + -1e3 + -4e3 + -8e3 + -1e11;
35
+
36
+ /**
37
+ * @return {string}
38
+ */
27
39
  const uuidv4 = () => uuidv4Template.replace(/[018]/g, /** @param {number} c */ c =>
28
40
  (c ^ uint32() & 15 >> c / 4).toString(16)
29
41
  );
@@ -1 +1 @@
1
- {"version":3,"file":"random.cjs","sources":["../random.js"],"sourcesContent":["\n/**\n * Isomorphic module for true random numbers / buffers / uuids.\n *\n * Attention: falls back to Math.random if the browser does not support crypto.\n *\n * @module random\n */\n\nimport * as math from './math.js'\nimport * as binary from './binary.js'\nimport { getRandomValues } from 'lib0/webcrypto'\n\nexport const rand = Math.random\n\nexport const uint32 = () => getRandomValues(new Uint32Array(1))[0]\n\nexport const uint53 = () => {\n const arr = getRandomValues(new Uint32Array(8))\n return (arr[0] & binary.BITS21) * (binary.BITS32 + 1) + (arr[1] >>> 0)\n}\n\n/**\n * @template T\n * @param {Array<T>} arr\n * @return {T}\n */\nexport const oneOf = arr => arr[math.floor(rand() * arr.length)]\n\n// @ts-ignore\nconst uuidv4Template = [1e7] + -1e3 + -4e3 + -8e3 + -1e11\nexport const uuidv4 = () => uuidv4Template.replace(/[018]/g, /** @param {number} c */ c =>\n (c ^ uint32() & 15 >> c / 4).toString(16)\n)\n"],"names":["getRandomValues","binary.BITS21","binary.BITS32","math.floor"],"mappings":";;;;;;;;AAaY,MAAC,IAAI,GAAG,IAAI,CAAC,OAAM;AAC/B;AACY,MAAC,MAAM,GAAG,MAAMA,yBAAe,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC;AAClE;AACY,MAAC,MAAM,GAAG,MAAM;AAC5B,EAAE,MAAM,GAAG,GAAGA,yBAAe,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,EAAC;AACjD,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAGC,aAAa,KAAKC,aAAa,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACxE,EAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,KAAK,GAAG,GAAG,IAAI,GAAG,CAACC,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,EAAC;AAChE;AACA;AACA,MAAM,cAAc,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,KAAI;AAC7C,MAAC,MAAM,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,QAAQ,2BAA2B,CAAC;AACvF,EAAE,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC;AAC3C;;;;;;;;"}
1
+ {"version":3,"file":"random.cjs","sources":["../random.js"],"sourcesContent":["/**\n * Isomorphic module for true random numbers / buffers / uuids.\n *\n * Attention: falls back to Math.random if the browser does not support crypto.\n *\n * @module random\n */\n\nimport * as math from './math.js'\nimport * as binary from './binary.js'\nimport { getRandomValues } from 'lib0/webcrypto'\n\nexport const rand = Math.random\n\nexport const uint32 = () => getRandomValues(new Uint32Array(1))[0]\n\nexport const uint53 = () => {\n const arr = getRandomValues(new Uint32Array(8))\n return (arr[0] & binary.BITS21) * (binary.BITS32 + 1) + (arr[1] >>> 0)\n}\n\n/**\n * @template T\n * @param {Array<T>} arr\n * @return {T}\n */\nexport const oneOf = arr => arr[math.floor(rand() * arr.length)]\n\n// @ts-ignore\nconst uuidv4Template = [1e7] + -1e3 + -4e3 + -8e3 + -1e11\n\n/**\n * @return {string}\n */\nexport const uuidv4 = () => uuidv4Template.replace(/[018]/g, /** @param {number} c */ c =>\n (c ^ uint32() & 15 >> c / 4).toString(16)\n)\n"],"names":["getRandomValues","binary.BITS21","binary.BITS32","math.floor"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAKA;AACY,MAAC,IAAI,GAAG,IAAI,CAAC,OAAM;AAC/B;AACY,MAAC,MAAM,GAAG,MAAMA,yBAAe,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC;AAClE;AACY,MAAC,MAAM,GAAG,MAAM;AAC5B,EAAE,MAAM,GAAG,GAAGA,yBAAe,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,EAAC;AACjD,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAGC,aAAa,KAAKC,aAAa,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACxE,EAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,KAAK,GAAG,GAAG,IAAI,GAAG,CAACC,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,EAAC;AAChE;AACA;AACA,MAAM,cAAc,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,KAAI;AACzD;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,QAAQ,2BAA2B,CAAC;AACvF,EAAE,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC;AAC3C;;;;;;;;"}
package/dist/random.d.ts CHANGED
@@ -2,5 +2,5 @@ export const rand: () => number;
2
2
  export function uint32(): number;
3
3
  export function uint53(): number;
4
4
  export function oneOf<T>(arr: T[]): T;
5
- export function uuidv4(): any;
5
+ export function uuidv4(): string;
6
6
  //# sourceMappingURL=random.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../random.js"],"names":[],"mappings":"AAaA,gCAA+B;AAExB,iCAA2D;AAE3D,iCAGN;AAOM,sCAAyD;AAIzD,8BAEN"}
1
+ {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../random.js"],"names":[],"mappings":"AAYA,gCAA+B;AAExB,iCAA2D;AAE3D,iCAGN;AAOM,sCAAyD;AAQzD,0BAFK,MAAM,CAIjB"}
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var webcrypto = require('lib0/webcrypto');
6
+ var common = require('./common.cjs');
7
+
8
+ function _interopNamespace(e) {
9
+ if (e && e.__esModule) return e;
10
+ var n = Object.create(null);
11
+ if (e) {
12
+ Object.keys(e).forEach(function (k) {
13
+ if (k !== 'default') {
14
+ var d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: function () { return e[k]; }
18
+ });
19
+ }
20
+ });
21
+ }
22
+ n["default"] = e;
23
+ return Object.freeze(n);
24
+ }
25
+
26
+ var webcrypto__namespace = /*#__PURE__*/_interopNamespace(webcrypto);
27
+
28
+ /**
29
+ * RSA-OAEP is an asymmetric keypair used for encryption
30
+ */
31
+
32
+ /**
33
+ * @typedef {Array<'encrypt'|'decrypt'>} Usages
34
+ */
35
+
36
+ /**
37
+ * @type {Usages}
38
+ */
39
+ const defaultUsages = ['encrypt', 'decrypt'];
40
+
41
+ /**
42
+ * Note that the max data size is limited by the size of the RSA key.
43
+ *
44
+ * @param {CryptoKey} key
45
+ * @param {Uint8Array} data
46
+ * @return {PromiseLike<Uint8Array>}
47
+ */
48
+ const encrypt = (key, data) =>
49
+ webcrypto__namespace.subtle.encrypt(
50
+ {
51
+ name: 'RSA-OAEP'
52
+ },
53
+ key,
54
+ data
55
+ ).then(buf => new Uint8Array(buf));
56
+
57
+ /**
58
+ * @experimental The API is not final!
59
+ *
60
+ * Decrypt some data using AES-GCM method.
61
+ *
62
+ * @param {CryptoKey} key
63
+ * @param {Uint8Array} data
64
+ * @return {PromiseLike<Uint8Array>} decrypted buffer
65
+ */
66
+ const decrypt = (key, data) =>
67
+ webcrypto__namespace.subtle.decrypt(
68
+ {
69
+ name: 'RSA-OAEP'
70
+ },
71
+ key,
72
+ data
73
+ ).then(data => new Uint8Array(data));
74
+
75
+ /**
76
+ * @param {Object} opts
77
+ * @param {boolean} [opts.extractable]
78
+ * @param {Usages} [opts.usages]
79
+ * @return {Promise<CryptoKeyPair>}
80
+ */
81
+ const generateKeyPair = ({ extractable = false, usages = defaultUsages } = {}) =>
82
+ webcrypto__namespace.subtle.generateKey(
83
+ {
84
+ name: 'RSA-OAEP',
85
+ modulusLength: 4096,
86
+ publicExponent: new Uint8Array([1, 0, 1]),
87
+ hash: 'SHA-256'
88
+ },
89
+ extractable,
90
+ usages
91
+ );
92
+
93
+ /**
94
+ * @param {any} jwk
95
+ * @param {Object} opts
96
+ * @param {boolean} [opts.extractable]
97
+ * @param {Usages} [opts.usages]
98
+ */
99
+ const importKey = (jwk, { extractable = false, usages } = {}) => {
100
+ if (usages == null) {
101
+ /* c8 ignore next */
102
+ usages = jwk.key_ops || defaultUsages;
103
+ }
104
+ return webcrypto__namespace.subtle.importKey('jwk', jwk, { name: 'RSA-OAEP', hash: 'SHA-256' }, extractable, /** @type {Usages} */ (usages))
105
+ };
106
+
107
+ exports.exportKey = common.exportKey;
108
+ exports.decrypt = decrypt;
109
+ exports.encrypt = encrypt;
110
+ exports.generateKeyPair = generateKeyPair;
111
+ exports.importKey = importKey;
112
+ //# sourceMappingURL=rsa-oaep.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rsa-oaep.cjs","sources":["../crypto/rsa-oaep.js"],"sourcesContent":["/**\n * RSA-OAEP is an asymmetric keypair used for encryption\n */\n\nimport * as webcrypto from 'lib0/webcrypto'\nexport { exportKey } from './common.js'\n\n/**\n * @typedef {Array<'encrypt'|'decrypt'>} Usages\n */\n\n/**\n * @type {Usages}\n */\nconst defaultUsages = ['encrypt', 'decrypt']\n\n/**\n * Note that the max data size is limited by the size of the RSA key.\n *\n * @param {CryptoKey} key\n * @param {Uint8Array} data\n * @return {PromiseLike<Uint8Array>}\n */\nexport const encrypt = (key, data) =>\n webcrypto.subtle.encrypt(\n {\n name: 'RSA-OAEP'\n },\n key,\n data\n ).then(buf => new Uint8Array(buf))\n\n/**\n * @experimental The API is not final!\n *\n * Decrypt some data using AES-GCM method.\n *\n * @param {CryptoKey} key\n * @param {Uint8Array} data\n * @return {PromiseLike<Uint8Array>} decrypted buffer\n */\nexport const decrypt = (key, data) =>\n webcrypto.subtle.decrypt(\n {\n name: 'RSA-OAEP'\n },\n key,\n data\n ).then(data => new Uint8Array(data))\n\n/**\n * @param {Object} opts\n * @param {boolean} [opts.extractable]\n * @param {Usages} [opts.usages]\n * @return {Promise<CryptoKeyPair>}\n */\nexport const generateKeyPair = ({ extractable = false, usages = defaultUsages } = {}) =>\n webcrypto.subtle.generateKey(\n {\n name: 'RSA-OAEP',\n modulusLength: 4096,\n publicExponent: new Uint8Array([1, 0, 1]),\n hash: 'SHA-256'\n },\n extractable,\n usages\n )\n\n/**\n * @param {any} jwk\n * @param {Object} opts\n * @param {boolean} [opts.extractable]\n * @param {Usages} [opts.usages]\n */\nexport const importKey = (jwk, { extractable = false, usages } = {}) => {\n if (usages == null) {\n /* c8 ignore next */\n usages = jwk.key_ops || defaultUsages\n }\n return webcrypto.subtle.importKey('jwk', jwk, { name: 'RSA-OAEP', hash: 'SHA-256' }, extractable, /** @type {Usages} */ (usages))\n}\n"],"names":["webcrypto"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,SAAS,EAAC;AAC5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,CAAC,GAAG,EAAE,IAAI;AACjC,EAAEA,oBAAS,CAAC,MAAM,CAAC,OAAO;AAC1B,IAAI;AACJ,MAAM,IAAI,EAAE,UAAU;AACtB,KAAK;AACL,IAAI,GAAG;AACP,IAAI,IAAI;AACR,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,UAAU,CAAC,GAAG,CAAC,EAAC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,CAAC,GAAG,EAAE,IAAI;AACjC,EAAEA,oBAAS,CAAC,MAAM,CAAC,OAAO;AAC1B,IAAI;AACJ,MAAM,IAAI,EAAE,UAAU;AACtB,KAAK;AACL,IAAI,GAAG;AACP,IAAI,IAAI;AACR,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,EAAC;AACtC;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,eAAe,GAAG,CAAC,EAAE,WAAW,GAAG,KAAK,EAAE,MAAM,GAAG,aAAa,EAAE,GAAG,EAAE;AACpF,EAAEA,oBAAS,CAAC,MAAM,CAAC,WAAW;AAC9B,IAAI;AACJ,MAAM,IAAI,EAAE,UAAU;AACtB,MAAM,aAAa,EAAE,IAAI;AACzB,MAAM,cAAc,EAAE,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/C,MAAM,IAAI,EAAE,SAAS;AACrB,KAAK;AACL,IAAI,WAAW;AACf,IAAI,MAAM;AACV,IAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG,CAAC,GAAG,EAAE,EAAE,WAAW,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK;AACxE,EAAE,IAAI,MAAM,IAAI,IAAI,EAAE;AACtB;AACA,IAAI,MAAM,GAAG,GAAG,CAAC,OAAO,IAAI,cAAa;AACzC,GAAG;AACH,EAAE,OAAOA,oBAAS,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,WAAW,yBAAyB,MAAM,EAAE;AACnI;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"set.test.d.ts","sourceRoot":"","sources":["../set.test.js"],"names":[],"mappings":"AAOO,+BAFI,EAAE,QAAQ,QAUpB;mBAdkB,cAAc"}
1
+ {"version":3,"file":"set.test.d.ts","sourceRoot":"","sources":["../set.test.js"],"names":[],"mappings":"AAMO,+BAFI,EAAE,QAAQ,QAUpB;mBAdkB,cAAc"}
@@ -0,0 +1,179 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var binary = require('./binary-ac8e39e2.cjs');
6
+
7
+ /**
8
+ * @module sha256
9
+ * Spec: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
10
+ * Resources:
11
+ * - https://web.archive.org/web/20150315061807/http://csrc.nist.gov/groups/STM/cavp/documents/shs/sha256-384-512.pdf
12
+ */
13
+
14
+ /**
15
+ * @param {number} w - a 32bit uint
16
+ * @param {number} shift
17
+ */
18
+ const rotr = (w, shift) => (w >>> shift) | (w << (32 - shift));
19
+
20
+ /**
21
+ * Helper for SHA-224 & SHA-256. See 4.1.2.
22
+ * @param {number} x
23
+ */
24
+ const sum0to256 = x => rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
25
+
26
+ /**
27
+ * Helper for SHA-224 & SHA-256. See 4.1.2.
28
+ * @param {number} x
29
+ */
30
+ const sum1to256 = x => rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
31
+
32
+ /**
33
+ * Helper for SHA-224 & SHA-256. See 4.1.2.
34
+ * @param {number} x
35
+ */
36
+ const sigma0to256 = x => rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
37
+
38
+ /**
39
+ * Helper for SHA-224 & SHA-256. See 4.1.2.
40
+ * @param {number} x
41
+ */
42
+ const sigma1to256 = x => rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
43
+
44
+ // @todo don't init these variables globally
45
+
46
+ /**
47
+ * See 4.2.2: Constant for sha256 & sha224
48
+ * These words represent the first thirty-two bits of the fractional parts of
49
+ * the cube roots of the first sixty-four prime numbers. In hex, these constant words are (from left to
50
+ * right)
51
+ */
52
+ const K = new Uint32Array([
53
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
54
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
55
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
56
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
57
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
58
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
59
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
60
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
61
+ ]);
62
+
63
+ /**
64
+ * See 5.3.3. Initial hash value.
65
+ *
66
+ * These words were obtained by taking the first thirty-two bits of the fractional parts of the
67
+ * square roots of the first eight prime numbers.
68
+ *
69
+ * @todo shouldn't be a global variable
70
+ */
71
+ const HINIT = new Uint32Array([
72
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
73
+ ]);
74
+
75
+ // time to beat: (large value < 4.35s)
76
+
77
+ class Hasher {
78
+ constructor () {
79
+ const buf = new ArrayBuffer(64 + 64 * 4);
80
+ // Init working variables using a single arraybuffer
81
+ this._H = new Uint32Array(buf, 0, 8);
82
+ this._H.set(HINIT);
83
+ // "Message schedule" - a working variable
84
+ this._W = new Uint32Array(buf, 64, 64);
85
+ }
86
+
87
+ _updateHash () {
88
+ const H = this._H;
89
+ const W = this._W;
90
+ for (let t = 16; t < 64; t++) {
91
+ W[t] = sigma1to256(W[t - 2]) + W[t - 7] + sigma0to256(W[t - 15]) + W[t - 16];
92
+ }
93
+ let a = H[0];
94
+ let b = H[1];
95
+ let c = H[2];
96
+ let d = H[3];
97
+ let e = H[4];
98
+ let f = H[5];
99
+ let g = H[6];
100
+ let h = H[7];
101
+ for (let tt = 0, T1, T2; tt < 64; tt++) {
102
+ T1 = (h + sum1to256(e) + ((e & f) ^ (~e & g)) + K[tt] + W[tt]) >>> 0;
103
+ T2 = (sum0to256(a) + ((a & b) ^ (a & c) ^ (b & c))) >>> 0;
104
+ h = g;
105
+ g = f;
106
+ f = e;
107
+ e = (d + T1) >>> 0;
108
+ d = c;
109
+ c = b;
110
+ b = a;
111
+ a = (T1 + T2) >>> 0;
112
+ }
113
+ H[0] += a;
114
+ H[1] += b;
115
+ H[2] += c;
116
+ H[3] += d;
117
+ H[4] += e;
118
+ H[5] += f;
119
+ H[6] += g;
120
+ H[7] += h;
121
+ }
122
+
123
+ /**
124
+ * @param {Uint8Array} data
125
+ */
126
+ digest (data) {
127
+ let i = 0;
128
+ for (; i + 56 <= data.length;) {
129
+ // write data in big endianess
130
+ let j = 0;
131
+ for (; j < 16 && i + 3 < data.length; j++) {
132
+ this._W[j] = data[i++] << 24 | data[i++] << 16 | data[i++] << 8 | data[i++];
133
+ }
134
+ if (i % 64 !== 0) { // there is still room to write partial content and the ending bit.
135
+ this._W.fill(0, j, 16);
136
+ while (i < data.length) {
137
+ this._W[j] |= data[i] << ((3 - (i % 4)) * 8);
138
+ i++;
139
+ }
140
+ this._W[j] |= binary.BIT8 << ((3 - (i % 4)) * 8);
141
+ }
142
+ this._updateHash();
143
+ }
144
+ // same check as earlier - the ending bit has been written
145
+ const isPaddedWith1 = i % 64 !== 0;
146
+ this._W.fill(0, 0, 16);
147
+ let j = 0;
148
+ for (; i < data.length; j++) {
149
+ for (let ci = 3; ci >= 0 && i < data.length; ci--) {
150
+ this._W[j] |= data[i++] << (ci * 8);
151
+ }
152
+ }
153
+ // Write padding of the message. See 5.1.2.
154
+ if (!isPaddedWith1) {
155
+ this._W[j - (i % 4 === 0 ? 0 : 1)] |= binary.BIT8 << ((3 - (i % 4)) * 8);
156
+ }
157
+ // write length of message (size in bits) as 64 bit uint
158
+ // @todo test that this works correctly
159
+ this._W[14] = data.byteLength / binary.BIT30; // same as data.byteLength >>> 30 - but works on floats
160
+ this._W[15] = data.byteLength * 8;
161
+ this._updateHash();
162
+ // correct H endianness to use big endiannes and return a Uint8Array
163
+ const dv = new Uint8Array(32);
164
+ for (let i = 0; i < this._H.length; i++) {
165
+ for (let ci = 0; ci < 4; ci++) {
166
+ dv[i * 4 + ci] = this._H[i] >>> (3 - ci) * 8;
167
+ }
168
+ }
169
+ return dv
170
+ }
171
+ }
172
+
173
+ /**
174
+ * @param {Uint8Array} data
175
+ */
176
+ const digest = data => new Hasher().digest(data);
177
+
178
+ exports.digest = digest;
179
+ //# sourceMappingURL=sha256.fallback.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256.fallback.cjs","sources":["../hash/sha256.fallback.js"],"sourcesContent":["/**\n * @module sha256\n * Spec: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf\n * Resources:\n * - https://web.archive.org/web/20150315061807/http://csrc.nist.gov/groups/STM/cavp/documents/shs/sha256-384-512.pdf\n */\n\nimport * as binary from '../binary.js'\n\n/**\n * @param {number} w - a 32bit uint\n * @param {number} shift\n */\nconst rotr = (w, shift) => (w >>> shift) | (w << (32 - shift))\n\n/**\n * Helper for SHA-224 & SHA-256. See 4.1.2.\n * @param {number} x\n */\nconst sum0to256 = x => rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22)\n\n/**\n * Helper for SHA-224 & SHA-256. See 4.1.2.\n * @param {number} x\n */\nconst sum1to256 = x => rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25)\n\n/**\n * Helper for SHA-224 & SHA-256. See 4.1.2.\n * @param {number} x\n */\nconst sigma0to256 = x => rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3\n\n/**\n * Helper for SHA-224 & SHA-256. See 4.1.2.\n * @param {number} x\n */\nconst sigma1to256 = x => rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10\n\n// @todo don't init these variables globally\n\n/**\n * See 4.2.2: Constant for sha256 & sha224\n * These words represent the first thirty-two bits of the fractional parts of\n * the cube roots of the first sixty-four prime numbers. In hex, these constant words are (from left to\n * right)\n */\nconst K = new Uint32Array([\n 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\n 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\n 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\n 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\n 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\n 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\n 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\n 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2\n])\n\n/**\n * See 5.3.3. Initial hash value.\n *\n * These words were obtained by taking the first thirty-two bits of the fractional parts of the\n * square roots of the first eight prime numbers.\n *\n * @todo shouldn't be a global variable\n */\nconst HINIT = new Uint32Array([\n 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19\n])\n\n// time to beat: (large value < 4.35s)\n\nclass Hasher {\n constructor () {\n const buf = new ArrayBuffer(64 + 64 * 4)\n // Init working variables using a single arraybuffer\n this._H = new Uint32Array(buf, 0, 8)\n this._H.set(HINIT)\n // \"Message schedule\" - a working variable\n this._W = new Uint32Array(buf, 64, 64)\n }\n\n _updateHash () {\n const H = this._H\n const W = this._W\n for (let t = 16; t < 64; t++) {\n W[t] = sigma1to256(W[t - 2]) + W[t - 7] + sigma0to256(W[t - 15]) + W[t - 16]\n }\n let a = H[0]\n let b = H[1]\n let c = H[2]\n let d = H[3]\n let e = H[4]\n let f = H[5]\n let g = H[6]\n let h = H[7]\n for (let tt = 0, T1, T2; tt < 64; tt++) {\n T1 = (h + sum1to256(e) + ((e & f) ^ (~e & g)) + K[tt] + W[tt]) >>> 0\n T2 = (sum0to256(a) + ((a & b) ^ (a & c) ^ (b & c))) >>> 0\n h = g\n g = f\n f = e\n e = (d + T1) >>> 0\n d = c\n c = b\n b = a\n a = (T1 + T2) >>> 0\n }\n H[0] += a\n H[1] += b\n H[2] += c\n H[3] += d\n H[4] += e\n H[5] += f\n H[6] += g\n H[7] += h\n }\n\n /**\n * @param {Uint8Array} data\n */\n digest (data) {\n let i = 0\n for (; i + 56 <= data.length;) {\n // write data in big endianess\n let j = 0\n for (; j < 16 && i + 3 < data.length; j++) {\n this._W[j] = data[i++] << 24 | data[i++] << 16 | data[i++] << 8 | data[i++]\n }\n if (i % 64 !== 0) { // there is still room to write partial content and the ending bit.\n this._W.fill(0, j, 16)\n while (i < data.length) {\n this._W[j] |= data[i] << ((3 - (i % 4)) * 8)\n i++\n }\n this._W[j] |= binary.BIT8 << ((3 - (i % 4)) * 8)\n }\n this._updateHash()\n }\n // same check as earlier - the ending bit has been written\n const isPaddedWith1 = i % 64 !== 0\n this._W.fill(0, 0, 16)\n let j = 0\n for (; i < data.length; j++) {\n for (let ci = 3; ci >= 0 && i < data.length; ci--) {\n this._W[j] |= data[i++] << (ci * 8)\n }\n }\n // Write padding of the message. See 5.1.2.\n if (!isPaddedWith1) {\n this._W[j - (i % 4 === 0 ? 0 : 1)] |= binary.BIT8 << ((3 - (i % 4)) * 8)\n }\n // write length of message (size in bits) as 64 bit uint\n // @todo test that this works correctly\n this._W[14] = data.byteLength / binary.BIT30 // same as data.byteLength >>> 30 - but works on floats\n this._W[15] = data.byteLength * 8\n this._updateHash()\n // correct H endianness to use big endiannes and return a Uint8Array\n const dv = new Uint8Array(32)\n for (let i = 0; i < this._H.length; i++) {\n for (let ci = 0; ci < 4; ci++) {\n dv[i * 4 + ci] = this._H[i] >>> (3 - ci) * 8\n }\n }\n return dv\n }\n}\n\n/**\n * @param {Uint8Array} data\n */\nexport const digest = data => new Hasher().digest(data)\n"],"names":["binary.BIT8","binary.BIT30"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA,MAAM,IAAI,GAAG,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,EAAC;AAC9D;AACA;AACA;AACA;AACA;AACA,MAAM,SAAS,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,EAAE,EAAC;AAC7D;AACA;AACA;AACA;AACA;AACA,MAAM,SAAS,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,EAAE,EAAC;AAC7D;AACA;AACA;AACA;AACA;AACA,MAAM,WAAW,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAA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AE,EAAE,EAAE;AACrC,QAAQ,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,IAAI,EAAC;AACpD,OAAO;AACP,KAAK;AACL,IAAI,OAAO,EAAE;AACb,GAAG;AACH,CAAC;AACD;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI;;;;"}
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var node_crypto = require('node:crypto');
6
+
7
+ /**
8
+ * @param {Uint8Array} data
9
+ */
10
+ const digest = data => {
11
+ const hasher = node_crypto.createHash('sha256');
12
+ hasher.update(data);
13
+ return hasher.digest()
14
+ };
15
+
16
+ exports.digest = digest;
17
+ //# sourceMappingURL=sha256.node.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256.node.cjs","sources":["../hash/sha256.node.js"],"sourcesContent":["import { createHash } from 'node:crypto'\n\n/**\n * @param {Uint8Array} data\n */\nexport const digest = data => {\n const hasher = createHash('sha256')\n hasher.update(data)\n return hasher.digest()\n}\n"],"names":["createHash"],"mappings":";;;;;;AAEA;AACA;AACA;AACY,MAAC,MAAM,GAAG,IAAI,IAAI;AAC9B,EAAE,MAAM,MAAM,GAAGA,sBAAU,CAAC,QAAQ,EAAC;AACrC,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAC;AACrB,EAAE,OAAO,MAAM,CAAC,MAAM,EAAE;AACxB;;;;"}
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var array = require('./array-fd99bc23.cjs');
3
+ var array = require('./array-704ca50e.cjs');
4
4
 
5
5
  /**
6
6
  * Utility module to work with strings.
@@ -11,6 +11,12 @@ var array = require('./array-fd99bc23.cjs');
11
11
  const fromCharCode = String.fromCharCode;
12
12
  const fromCodePoint = String.fromCodePoint;
13
13
 
14
+ /**
15
+ * The largest utf16 character.
16
+ * Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8)
17
+ */
18
+ const MAX_UTF16_CHARACTER = fromCharCode(65535);
19
+
14
20
  /**
15
21
  * @param {string} s
16
22
  * @return {string}
@@ -136,6 +142,7 @@ var string = /*#__PURE__*/Object.freeze({
136
142
  __proto__: null,
137
143
  fromCharCode: fromCharCode,
138
144
  fromCodePoint: fromCodePoint,
145
+ MAX_UTF16_CHARACTER: MAX_UTF16_CHARACTER,
139
146
  trimLeft: trimLeft,
140
147
  fromCamelCase: fromCamelCase,
141
148
  utf8ByteLength: utf8ByteLength,
@@ -151,6 +158,7 @@ var string = /*#__PURE__*/Object.freeze({
151
158
  repeat: repeat
152
159
  });
153
160
 
161
+ exports.MAX_UTF16_CHARACTER = MAX_UTF16_CHARACTER;
154
162
  exports._decodeUtf8Native = _decodeUtf8Native;
155
163
  exports._decodeUtf8Polyfill = _decodeUtf8Polyfill;
156
164
  exports._encodeUtf8Native = _encodeUtf8Native;
@@ -166,4 +174,4 @@ exports.string = string;
166
174
  exports.trimLeft = trimLeft;
167
175
  exports.utf8ByteLength = utf8ByteLength;
168
176
  exports.utf8TextEncoder = utf8TextEncoder;
169
- //# sourceMappingURL=string-e7eb0c1d.cjs.map
177
+ //# sourceMappingURL=string-6d104757.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-6d104757.cjs","sources":["../string.js"],"sourcesContent":["import * as array from './array.js'\n\n/**\n * Utility module to work with strings.\n *\n * @module string\n */\n\nexport const fromCharCode = String.fromCharCode\nexport const fromCodePoint = String.fromCodePoint\n\n/**\n * The largest utf16 character.\n * Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8)\n */\nexport const MAX_UTF16_CHARACTER = fromCharCode(65535)\n\n/**\n * @param {string} s\n * @return {string}\n */\nconst toLowerCase = s => s.toLowerCase()\n\nconst trimLeftRegex = /^\\s*/g\n\n/**\n * @param {string} s\n * @return {string}\n */\nexport const trimLeft = s => s.replace(trimLeftRegex, '')\n\nconst fromCamelCaseRegex = /([A-Z])/g\n\n/**\n * @param {string} s\n * @param {string} separator\n * @return {string}\n */\nexport const fromCamelCase = (s, separator) => trimLeft(s.replace(fromCamelCaseRegex, match => `${separator}${toLowerCase(match)}`))\n\n/**\n * Compute the utf8ByteLength\n * @param {string} str\n * @return {number}\n */\nexport const utf8ByteLength = str => unescape(encodeURIComponent(str)).length\n\n/**\n * @param {string} str\n * @return {Uint8Array}\n */\nexport const _encodeUtf8Polyfill = str => {\n const encodedString = unescape(encodeURIComponent(str))\n const len = encodedString.length\n const buf = new Uint8Array(len)\n for (let i = 0; i < len; i++) {\n buf[i] = /** @type {number} */ (encodedString.codePointAt(i))\n }\n return buf\n}\n\n/* c8 ignore next */\nexport const utf8TextEncoder = /** @type {TextEncoder} */ (typeof TextEncoder !== 'undefined' ? new TextEncoder() : null)\n\n/**\n * @param {string} str\n * @return {Uint8Array}\n */\nexport const _encodeUtf8Native = str => utf8TextEncoder.encode(str)\n\n/**\n * @param {string} str\n * @return {Uint8Array}\n */\n/* c8 ignore next */\nexport const encodeUtf8 = utf8TextEncoder ? _encodeUtf8Native : _encodeUtf8Polyfill\n\n/**\n * @param {Uint8Array} buf\n * @return {string}\n */\nexport const _decodeUtf8Polyfill = buf => {\n let remainingLen = buf.length\n let encodedString = ''\n let bufPos = 0\n while (remainingLen > 0) {\n const nextLen = remainingLen < 10000 ? remainingLen : 10000\n const bytes = buf.subarray(bufPos, bufPos + nextLen)\n bufPos += nextLen\n // Starting with ES5.1 we can supply a generic array-like object as arguments\n encodedString += String.fromCodePoint.apply(null, /** @type {any} */ (bytes))\n remainingLen -= nextLen\n }\n return decodeURIComponent(escape(encodedString))\n}\n\n/* c8 ignore next */\nexport let utf8TextDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8', { fatal: true, ignoreBOM: true })\n\n/* c8 ignore start */\nif (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) {\n // Safari doesn't handle BOM correctly.\n // This fixes a bug in Safari 13.0.5 where it produces a BOM the first time it is called.\n // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the first call and\n // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the second call\n // Another issue is that from then on no BOM chars are recognized anymore\n /* c8 ignore next */\n utf8TextDecoder = null\n}\n/* c8 ignore stop */\n\n/**\n * @param {Uint8Array} buf\n * @return {string}\n */\nexport const _decodeUtf8Native = buf => /** @type {TextDecoder} */ (utf8TextDecoder).decode(buf)\n\n/**\n * @param {Uint8Array} buf\n * @return {string}\n */\n/* c8 ignore next */\nexport const decodeUtf8 = utf8TextDecoder ? _decodeUtf8Native : _decodeUtf8Polyfill\n\n/**\n * @param {string} str The initial string\n * @param {number} index Starting position\n * @param {number} remove Number of characters to remove\n * @param {string} insert New content to insert\n */\nexport const splice = (str, index, remove, insert = '') => str.slice(0, index) + insert + str.slice(index + remove)\n\n/**\n * @param {string} source\n * @param {number} n\n */\nexport const repeat = (source, n) => array.unfold(n, () => source).join('')\n"],"names":["utf8TextDecoder","array.unfold"],"mappings":";;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,YAAY,GAAG,MAAM,CAAC,aAAY;AACnC,MAAC,aAAa,GAAG,MAAM,CAAC,cAAa;AACjD;AACA;AACA;AACA;AACA;AACY,MAAC,mBAAmB,GAAG,YAAY,CAAC,KAAK,EAAC;AACtD;AACA;AACA;AACA;AACA;AACA,MAAM,WAAW,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,GAAE;AACxC;AACA,MAAM,aAAa,GAAG,QAAO;AAC7B;AACA;AACA;AACA;AACA;AACY,MAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,EAAC;AACzD;AACA,MAAM,kBAAkB,GAAG,WAAU;AACrC;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,aAAa,GAAG,CA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,MAAM,EAAC;AACnH;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC,KAAKC,YAAY,CAAC,CAAC,EAAE,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/string.cjs CHANGED
@@ -2,12 +2,13 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- require('./array-fd99bc23.cjs');
6
- var string = require('./string-e7eb0c1d.cjs');
5
+ require('./array-704ca50e.cjs');
6
+ var string = require('./string-6d104757.cjs');
7
7
  require('./set-0f209abb.cjs');
8
8
 
9
9
 
10
10
 
11
+ exports.MAX_UTF16_CHARACTER = string.MAX_UTF16_CHARACTER;
11
12
  exports._decodeUtf8Native = string._decodeUtf8Native;
12
13
  exports._decodeUtf8Polyfill = string._decodeUtf8Polyfill;
13
14
  exports._encodeUtf8Native = string._encodeUtf8Native;
@@ -1 +1 @@
1
- {"version":3,"file":"string.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"string.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/string.d.ts CHANGED
@@ -5,6 +5,11 @@
5
5
  */
6
6
  export const fromCharCode: (...codes: number[]) => string;
7
7
  export const fromCodePoint: (...codePoints: number[]) => string;
8
+ /**
9
+ * The largest utf16 character.
10
+ * Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8)
11
+ */
12
+ export const MAX_UTF16_CHARACTER: string;
8
13
  export function trimLeft(s: string): string;
9
14
  export function fromCamelCase(s: string, separator: string): string;
10
15
  export function utf8ByteLength(str: string): number;
@@ -1 +1 @@
1
- {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../string.js"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,0DAA+C;AAC/C,gEAAiD;AAc1C,4BAHI,MAAM,GACL,MAAM,CAEuC;AASlD,iCAJI,MAAM,aACN,MAAM,GACL,MAAM,CAEkH;AAO7H,oCAHI,MAAM,GACL,MAAM,CAE2D;AAMtE,yCAHI,MAAM,GACL,UAAU,CAUrB;AAGD,0CAAyH;AAMlH,uCAHI,MAAM,GACL,UAAU,CAE6C;AAjB5D,gCAHI,MAAM,GACL,UAAU,CAUrB;AAsBM,yCAHI,UAAU,GACT,MAAM,CAejB;AAGD,+CAAmI;AAkB5H,uCAHI,UAAU,GACT,MAAM,CAE8E;AAlCzF,gCAHI,UAAU,GACT,MAAM,CAejB;AAoCM,4BALI,MAAM,SACN,MAAM,UACN,MAAM,WACN,MAAM,UAEkG;AAM5G,+BAHI,MAAM,KACN,MAAM,UAE0D"}
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../string.js"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,0DAA+C;AAC/C,gEAAiD;AAEjD;;;GAGG;AACH,yCAAsD;AAc/C,4BAHI,MAAM,GACL,MAAM,CAEuC;AASlD,iCAJI,MAAM,aACN,MAAM,GACL,MAAM,CAEkH;AAO7H,oCAHI,MAAM,GACL,MAAM,CAE2D;AAMtE,yCAHI,MAAM,GACL,UAAU,CAUrB;AAGD,0CAAyH;AAMlH,uCAHI,MAAM,GACL,UAAU,CAE6C;AAjB5D,gCAHI,MAAM,GACL,UAAU,CAUrB;AAsBM,yCAHI,UAAU,GACT,MAAM,CAejB;AAGD,+CAAmI;AAkB5H,uCAHI,UAAU,GACT,MAAM,CAE8E;AAlCzF,gCAHI,UAAU,GACT,MAAM,CAejB;AAoCM,4BALI,MAAM,SACN,MAAM,UACN,MAAM,WACN,MAAM,UAEkG;AAM5G,+BAHI,MAAM,KACN,MAAM,UAE0D"}
package/dist/testing.cjs CHANGED
@@ -3,24 +3,24 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var log = require('lib0/logging');
6
- var diff = require('./diff-18852f48.cjs');
7
- var object = require('./object-aad630ed.cjs');
8
- var string = require('./string-e7eb0c1d.cjs');
6
+ var diff = require('./diff-fbaa426b.cjs');
7
+ var object = require('./object-fecf6a7b.cjs');
8
+ var string = require('./string-6d104757.cjs');
9
9
  var math = require('./math-08e068f9.cjs');
10
10
  var random = require('./random.cjs');
11
- var prng = require('./prng-9ccc85f7.cjs');
11
+ var prng = require('./prng-1149c8c4.cjs');
12
12
  var statistics = require('./statistics-c2316dca.cjs');
13
- var array = require('./array-fd99bc23.cjs');
14
- var environment = require('./environment-0c5ff22b.cjs');
13
+ var array = require('./array-704ca50e.cjs');
14
+ var environment = require('./environment-ad129e4d.cjs');
15
15
  var json = require('./json-092190a1.cjs');
16
16
  var time = require('./time-bc2081b9.cjs');
17
17
  var promise = require('./promise-afe9dfc3.cjs');
18
18
  var performance = require('lib0/performance');
19
- require('./function-831844d3.cjs');
19
+ require('./function-314fdc56.cjs');
20
20
  require('./binary-ac8e39e2.cjs');
21
21
  require('lib0/webcrypto');
22
- require('./buffer-621617f6.cjs');
23
- require('./number-dc113762.cjs');
22
+ require('./buffer-c5d69c70.cjs');
23
+ require('./number-466d8922.cjs');
24
24
  require('./error-8582d695.cjs');
25
25
  require('./set-0f209abb.cjs');
26
26
  require('./map-9a5915e4.cjs');
@@ -113,6 +113,12 @@ class TestCase {
113
113
  * @type {string}
114
114
  */
115
115
  this.testName = testName;
116
+ /**
117
+ * This type can store custom information related to the TestCase
118
+ *
119
+ * @type {Map<string,any>}
120
+ */
121
+ this.meta = new Map();
116
122
  this._seed = null;
117
123
  this._prng = null;
118
124
  }
@@ -154,7 +160,7 @@ const repetitionTime = Number(environment.getParam('--repetition-time', '50'));
154
160
  const testFilter = environment.hasParam('--filter') ? environment.getParam('--filter', '') : null;
155
161
 
156
162
  /* c8 ignore next */
157
- const testFilterRegExp = testFilter !== null ? new RegExp(testFilter) : new RegExp('.*');
163
+ const testFilterRegExp = testFilter !== null ? new RegExp(testFilter) : /.*/;
158
164
 
159
165
  const repeatTestRegex = /^(repeat|repeating)\s/;
160
166
 
@@ -285,7 +291,7 @@ const printCanvas = log__namespace.printCanvas;
285
291
  * ```
286
292
  *
287
293
  * @param {string} description
288
- * @param {function(void):void} f
294
+ * @param {function(...any):void} f
289
295
  */
290
296
  const group = (description, f) => {
291
297
  log__namespace.group(log__namespace.BLUE, description);
@@ -312,7 +318,7 @@ const group = (description, f) => {
312
318
  * ```
313
319
  *
314
320
  * @param {string} description
315
- * @param {function(void):Promise<any>} f
321
+ * @param {function(...any):Promise<any>} f
316
322
  */
317
323
  const groupAsync = async (description, f) => {
318
324
  log__namespace.group(log__namespace.BLUE, description);
@@ -338,7 +344,7 @@ const groupAsync = async (description, f) => {
338
344
  * ```
339
345
  *
340
346
  * @param {string} message
341
- * @param {function():void} f
347
+ * @param {function(...any):void} f
342
348
  * @return {number} Returns a promise that resolves the measured duration to apply f
343
349
  */
344
350
  const measureTime = (message, f) => {
@@ -368,7 +374,7 @@ const measureTime = (message, f) => {
368
374
  * ```
369
375
  *
370
376
  * @param {string} message
371
- * @param {function():Promise<any>} f
377
+ * @param {function(...any):Promise<any>} f
372
378
  * @return {Promise<number>} Returns a promise that resolves the measured duration to apply f
373
379
  */
374
380
  const measureTimeAsync = async (message, f) => {
@@ -554,7 +560,7 @@ const compare = (a, b, message = null, customCompare = compareValues) => _compar
554
560
  const assert = (property, message = null) => { property || fail(`Assertion failed${message !== null ? `: ${message}` : ''}`); };
555
561
 
556
562
  /**
557
- * @param {function():Promise<any>} f
563
+ * @param {function(...any):Promise<any>} f
558
564
  */
559
565
  const promiseRejected = async f => {
560
566
  try {
@@ -566,7 +572,7 @@ const promiseRejected = async f => {
566
572
  };
567
573
 
568
574
  /**
569
- * @param {function():void} f
575
+ * @param {function(...any):void} f
570
576
  * @throws {TestError}
571
577
  */
572
578
  const fails = f => {
@@ -580,7 +586,7 @@ const fails = f => {
580
586
  };
581
587
 
582
588
  /**
583
- * @param {function():Promise<any>} f
589
+ * @param {function(...any):Promise<any>} f
584
590
  * @throws {TestError}
585
591
  */
586
592
  const failsAsync = async f => {