cafe-utility 26.15.1 → 27.0.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 (4) hide show
  1. package/index.d.ts +12 -6
  2. package/index.js +181 -173
  3. package/module.mjs +1 -0
  4. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -546,9 +546,18 @@ export declare class Chunk {
546
546
  build(): Uint8Array;
547
547
  hash(): Uint8Array;
548
548
  }
549
- declare function merkleStart(capacity: number): Chunk[];
550
- declare function merkleAppend(levels: Chunk[], data: Uint8Array, onChunk: (chunk: Chunk) => Promise<void>, level?: number, spanIncrement?: bigint): Promise<Chunk[]>;
551
- declare function merkleFinalize(levels: Chunk[], onChunk: (chunk: Chunk) => Promise<void>, level?: number): Promise<Chunk>;
549
+ export declare class MerkleTree {
550
+ static readonly NOOP: (_: Chunk) => Promise<void>;
551
+ count: number;
552
+ private capacity;
553
+ private chunks;
554
+ private onChunk;
555
+ constructor(onChunk: (chunk: Chunk) => Promise<void>, capacity?: number);
556
+ static root(data: Uint8Array, capacity?: number): Promise<Chunk>;
557
+ append(data: Uint8Array, level?: number, spanIncrement?: bigint): Promise<void>;
558
+ private elevate;
559
+ finalize(level?: number): Promise<Chunk>;
560
+ }
552
561
  type Playbook<T> = {
553
562
  ttl: number;
554
563
  ttlMax?: number;
@@ -614,9 +623,6 @@ export declare const Binary: {
614
623
  log2Reduce: typeof log2Reduce;
615
624
  partition: typeof partition;
616
625
  concatBytes: typeof concatBytes;
617
- merkleStart: typeof merkleStart;
618
- merkleAppend: typeof merkleAppend;
619
- merkleFinalize: typeof merkleFinalize;
620
626
  numberToUint8: typeof numberToUint8;
621
627
  uint8ToNumber: typeof uint8ToNumber;
622
628
  numberToUint16: typeof numberToUint16;
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  'use strict'
2
+ var _a
2
3
  Object.defineProperty(exports, '__esModule', { value: !0 }),
3
4
  (exports.Vector =
4
5
  exports.Cache =
@@ -16,6 +17,7 @@ Object.defineProperty(exports, '__esModule', { value: !0 }),
16
17
  exports.Binary =
17
18
  exports.AsyncQueue =
18
19
  exports.PubSubChannel =
20
+ exports.MerkleTree =
19
21
  exports.Chunk =
20
22
  exports.Uint8ArrayWriter =
21
23
  exports.Uint8ArrayReader =
@@ -151,12 +153,12 @@ function pickManyUnique(n, e, t, r = Math.random) {
151
153
  }
152
154
  function pickGuaranteed(n, e, t, r, o, i = Math.random) {
153
155
  const u = n.filter(c => c !== e && c !== t),
154
- f = []
155
- for (e !== null && f.push(e); u.length && f.length < r; ) {
156
+ s = []
157
+ for (e !== null && s.push(e); u.length && s.length < r; ) {
156
158
  const c = exports.Random.intBetween(0, u.length - 1, i)
157
- o(u[c], f) && f.push(u[c]), u.splice(c, 1)
159
+ o(u[c], s) && s.push(u[c]), u.splice(c, 1)
158
160
  }
159
- return shuffle(f, i), { values: f, indexOfGuaranteed: e !== null ? f.indexOf(e) : -1 }
161
+ return shuffle(s, i), { values: s, indexOfGuaranteed: e !== null ? s.indexOf(e) : -1 }
160
162
  }
161
163
  function last(n) {
162
164
  if (!n.length) throw Error('Received empty array')
@@ -196,10 +198,10 @@ function setDeep(n, e, t) {
196
198
  let o = n
197
199
  for (let i = 0; i < r.length; i++) {
198
200
  const u = r[i],
199
- f = i < r.length - 1 && r[i + 1].includes(']'),
200
- s = u.includes(']') ? u.replace(/\[|\]/g, '') : u
201
- if (i === r.length - 1) return (o[s] = t), t
202
- isObject(o[s]) || (f ? (o[s] = []) : (o[s] = {})), (o = o[s])
201
+ s = i < r.length - 1 && r[i + 1].includes(']'),
202
+ f = u.includes(']') ? u.replace(/\[|\]/g, '') : u
203
+ if (i === r.length - 1) return (o[f] = t), t
204
+ isObject(o[f]) || (s ? (o[f] = []) : (o[f] = {})), (o = o[f])
203
205
  }
204
206
  return t
205
207
  }
@@ -275,10 +277,10 @@ function rgbToHex(n) {
275
277
  function haversineDistanceToMeters(n, e, t, r) {
276
278
  const i = (n * Math.PI) / 180,
277
279
  u = (t * Math.PI) / 180,
278
- f = ((t - n) * Math.PI) / 180,
280
+ s = ((t - n) * Math.PI) / 180,
279
281
  c = ((r - e) * Math.PI) / 180,
280
- s = Math.sin(f / 2) * Math.sin(f / 2) + Math.cos(i) * Math.cos(u) * Math.sin(c / 2) * Math.sin(c / 2)
281
- return 6371e3 * (2 * Math.atan2(Math.sqrt(s), Math.sqrt(1 - s)))
282
+ f = Math.sin(s / 2) * Math.sin(s / 2) + Math.cos(i) * Math.cos(u) * Math.sin(c / 2) * Math.sin(c / 2)
283
+ return 6371e3 * (2 * Math.atan2(Math.sqrt(f), Math.sqrt(1 - f)))
282
284
  }
283
285
  function roundToNearest(n, e) {
284
286
  return Math.round(n / e) * e
@@ -814,8 +816,8 @@ function expand(n) {
814
816
  o = n.slice(0, t.index),
815
817
  i = n.slice(t.index + t[0].length)
816
818
  let u = []
817
- for (const f of r) {
818
- const c = expand(o + f + i)
819
+ for (const s of r) {
820
+ const c = expand(o + s + i)
819
821
  u = u.concat(c)
820
822
  }
821
823
  return u
@@ -1060,12 +1062,12 @@ function baseToUint8Array(n, e) {
1060
1062
  let o = 0,
1061
1063
  i = 0
1062
1064
  const u = []
1063
- for (let f = 0; f < n.length; f++) {
1064
- const c = n[f]
1065
+ for (let s = 0; s < n.length; s++) {
1066
+ const c = n[s]
1065
1067
  if (c === t) break
1066
- const s = e.indexOf(c)
1067
- if (s === -1) throw new Error(`Invalid character: ${c}`)
1068
- ;(i = (i << Math.log2(r)) | s), (o += Math.log2(r)), o >= 8 && ((o -= 8), u.push((i >> o) & 255))
1068
+ const f = e.indexOf(c)
1069
+ if (f === -1) throw new Error(`Invalid character: ${c}`)
1070
+ ;(i = (i << Math.log2(r)) | f), (o += Math.log2(r)), o >= 8 && ((o -= 8), u.push((i >> o) & 255))
1069
1071
  }
1070
1072
  return new Uint8Array(u)
1071
1073
  }
@@ -1118,7 +1120,7 @@ function generateVariants(n, e, t, r = Math.random) {
1118
1120
  const o = exports.Arrays.shuffle(
1119
1121
  e.map(u => ({
1120
1122
  variants: exports.Arrays.shuffle(
1121
- u.variants.map(f => f),
1123
+ u.variants.map(s => s),
1122
1124
  r
1123
1125
  ),
1124
1126
  avoid: u.avoid
@@ -1127,14 +1129,14 @@ function generateVariants(n, e, t, r = Math.random) {
1127
1129
  ),
1128
1130
  i = []
1129
1131
  for (const u of o) {
1130
- const f = u.variants.filter(s => s !== u.avoid),
1131
- c = f.find(s => n.includes(s))
1132
- if (c && (pushAll(i, explodeReplace(n, c, f)), i.length >= t)) break
1132
+ const s = u.variants.filter(f => f !== u.avoid),
1133
+ c = s.find(f => n.includes(f))
1134
+ if (c && (pushAll(i, explodeReplace(n, c, s)), i.length >= t)) break
1133
1135
  }
1134
1136
  if (i.length < t)
1135
1137
  for (const u of o) {
1136
- const f = u.variants.find(c => n.includes(c))
1137
- if (f && (pushAll(i, explodeReplace(n, f, u.variants)), i.length >= t)) break
1138
+ const s = u.variants.find(c => n.includes(c))
1139
+ if (s && (pushAll(i, explodeReplace(n, s, u.variants)), i.length >= t)) break
1138
1140
  }
1139
1141
  return i.slice(0, t)
1140
1142
  }
@@ -1164,11 +1166,11 @@ function toLines(n, e, t = {}) {
1164
1166
  let o = '',
1165
1167
  i = 0
1166
1168
  for (let u = 0; u < n.length; u++) {
1167
- const f = n[u],
1168
- c = t[f] || 1
1169
- if (((o += f), (i += c), i > e)) {
1170
- const { line: s, rest: l } = breakLine(o)
1171
- r.push(s),
1169
+ const s = n[u],
1170
+ c = t[s] || 1
1171
+ if (((o += s), (i += c), i > e)) {
1172
+ const { line: f, rest: l } = breakLine(o)
1173
+ r.push(f),
1172
1174
  (o = l),
1173
1175
  (i = l
1174
1176
  .split('')
@@ -1221,8 +1223,8 @@ function resolveVariableWithDefaultSyntax(n, e, t, r = '$', o = ':') {
1221
1223
  if (n[i + e.length + 1] === o)
1222
1224
  if (n[i + e.length + 2] === o) n = n.replace(`${r}${e}${o}${o}`, t)
1223
1225
  else {
1224
- const f = readNextWord(n, i + e.length + 2, ['_'])
1225
- n = n.replace(`${r}${e}${o}${f}`, t)
1226
+ const s = readNextWord(n, i + e.length + 2, ['_'])
1227
+ n = n.replace(`${r}${e}${o}${s}`, t)
1226
1228
  }
1227
1229
  else n = n.replace(`${r}${e}`, t)
1228
1230
  i = n.indexOf(`${r}${e}`, i + t.length)
@@ -1250,8 +1252,8 @@ function resolveMarkdownLinks(n, e) {
1250
1252
  o = n.indexOf(')', t)
1251
1253
  if (r !== -1 && o !== -1) {
1252
1254
  const [i, u] = n.slice(r + 1, o).split(']('),
1253
- f = e(i, u)
1254
- n = n.slice(0, r) + f + n.slice(o + 1)
1255
+ s = e(i, u)
1256
+ n = n.slice(0, r) + s + n.slice(o + 1)
1255
1257
  }
1256
1258
  t = n.indexOf('](', t + 1)
1257
1259
  }
@@ -1289,8 +1291,8 @@ function reposition(n, e, t, r) {
1289
1291
  const o = n.find(u => u[e] === t),
1290
1292
  i = n.find(u => u[e] === t + r)
1291
1293
  o && i ? ((o[e] = t + r), (i[e] = t)) : o && (o[e] = t + r),
1292
- n.sort((u, f) => asNumber(u[e]) - asNumber(f[e])),
1293
- n.forEach((u, f) => (u[e] = f + 1))
1294
+ n.sort((u, s) => asNumber(u[e]) - asNumber(s[e])),
1295
+ n.forEach((u, s) => (u[e] = s + 1))
1294
1296
  }
1295
1297
  function unwrapSingleKey(n) {
1296
1298
  const e = Object.keys(n)
@@ -1313,7 +1315,7 @@ function parseCsv(n, e = ',', t = '"') {
1313
1315
  let o = '',
1314
1316
  i = !1
1315
1317
  const u = n.split('')
1316
- for (const f of u) f === e && !i ? (r.push(o), (o = '')) : f === t && ((!o && !i) || i) ? (i = !i) : (o += f)
1318
+ for (const s of u) s === e && !i ? (r.push(o), (o = '')) : s === t && ((!o && !i) || i) ? (i = !i) : (o += s)
1317
1319
  return r.push(o), r
1318
1320
  }
1319
1321
  function humanizeProgress(n) {
@@ -1449,9 +1451,9 @@ function getProgress(n, e, t, r) {
1449
1451
  const o = e / t,
1450
1452
  i = r - n,
1451
1453
  u = i / e,
1452
- f = u * t,
1453
- c = f - i
1454
- return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs: f, remainingTimeMs: c }
1454
+ s = u * t,
1455
+ c = s - i
1456
+ return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs: s, remainingTimeMs: c }
1455
1457
  }
1456
1458
  const dayNumberIndex = {
1457
1459
  0: 'sunday',
@@ -1659,8 +1661,8 @@ function organiseWithLimits(n, e, t, r, o) {
1659
1661
  for (const u of Object.keys(e)) i[u] = []
1660
1662
  ;(i[r] = []), o && (n = n.sort(o))
1661
1663
  for (const u of n) {
1662
- const f = u[t],
1663
- c = e[f] ? f : r
1664
+ const s = u[t],
1665
+ c = e[s] ? s : r
1664
1666
  i[c].length >= e[c] ? i[r].push(u) : i[c].push(u)
1665
1667
  }
1666
1668
  return i
@@ -1818,18 +1820,18 @@ function flip(n) {
1818
1820
  }
1819
1821
  function getAllPermutations(n) {
1820
1822
  const e = Object.keys(n),
1821
- t = e.map(f => n[f].length),
1822
- r = t.reduce((f, c) => (f *= c))
1823
+ t = e.map(s => n[s].length),
1824
+ r = t.reduce((s, c) => (s *= c))
1823
1825
  let o = 1
1824
1826
  const i = [1]
1825
- for (let f = 0; f < t.length - 1; f++) (o *= t[f]), i.push(o)
1827
+ for (let s = 0; s < t.length - 1; s++) (o *= t[s]), i.push(o)
1826
1828
  const u = []
1827
- for (let f = 0; f < r; f++) {
1829
+ for (let s = 0; s < r; s++) {
1828
1830
  const c = {}
1829
- for (let s = 0; s < e.length; s++) {
1830
- const l = n[e[s]],
1831
- a = Math.floor(f / i[s]) % l.length
1832
- c[e[s]] = l[a]
1831
+ for (let f = 0; f < e.length; f++) {
1832
+ const l = n[e[f]],
1833
+ a = Math.floor(s / i[f]) % l.length
1834
+ c[e[f]] = l[a]
1833
1835
  }
1834
1836
  u.push(c)
1835
1837
  }
@@ -1844,14 +1846,14 @@ function getFlatNotation(n, e, t) {
1844
1846
  function flattenInner(n, e, t, r, o) {
1845
1847
  if (!isObject(e)) return e
1846
1848
  for (const [i, u] of Object.entries(e)) {
1847
- const f = getFlatNotation(t, i, r)
1849
+ const s = getFlatNotation(t, i, r)
1848
1850
  Array.isArray(u)
1849
1851
  ? o
1850
- ? flattenInner(n, u, f, !0, o)
1851
- : (n[f] = u.map(c => flattenInner(Array.isArray(c) ? [] : {}, c, '', !1, o)))
1852
+ ? flattenInner(n, u, s, !0, o)
1853
+ : (n[s] = u.map(c => flattenInner(Array.isArray(c) ? [] : {}, c, '', !1, o)))
1852
1854
  : isObject(u)
1853
- ? flattenInner(n, u, f, !1, o)
1854
- : (n[f] = u)
1855
+ ? flattenInner(n, u, s, !1, o)
1856
+ : (n[s] = u)
1855
1857
  }
1856
1858
  return n
1857
1859
  }
@@ -1918,8 +1920,8 @@ function countUnique(n, e, t, r, o) {
1918
1920
  const i = e ? n.map(e) : n,
1919
1921
  u = {}
1920
1922
  for (const c of i) u[c] = (u[c] || 0) + 1
1921
- const f = r ? sortObjectValues(u, o ? (c, s) => c[1] - s[1] : (c, s) => s[1] - c[1]) : u
1922
- return t ? Object.keys(f) : f
1923
+ const s = r ? sortObjectValues(u, o ? (c, f) => c[1] - f[1] : (c, f) => f[1] - c[1]) : u
1924
+ return t ? Object.keys(s) : s
1923
1925
  }
1924
1926
  function sortObjectValues(n, e) {
1925
1927
  return Object.fromEntries(Object.entries(n).sort(e))
@@ -2054,27 +2056,27 @@ function createHierarchy(n, e, t, r, o = !1) {
2054
2056
  const i = new Map(),
2055
2057
  u = []
2056
2058
  n.forEach(c => {
2057
- const s = new Node(c)
2058
- i.set(c[e], s)
2059
+ const f = new Node(c)
2060
+ i.set(c[e], f)
2059
2061
  }),
2060
2062
  n.forEach(c => {
2061
- const s = i.get(c[e])
2062
- if (!s) return
2063
+ const f = i.get(c[e])
2064
+ if (!f) return
2063
2065
  const l = c[t]
2064
2066
  if (l) {
2065
2067
  const a = i.get(l)
2066
- a && a.children.push(s)
2067
- } else u.push(s)
2068
+ a && a.children.push(f)
2069
+ } else u.push(f)
2068
2070
  })
2069
- const f = c => {
2070
- c.children.sort((s, l) => {
2071
- const a = s.value[r],
2071
+ const s = c => {
2072
+ c.children.sort((f, l) => {
2073
+ const a = f.value[r],
2072
2074
  h = l.value[r]
2073
2075
  return o ? h - a : a - h
2074
2076
  }),
2075
- c.children.forEach(f)
2077
+ c.children.forEach(s)
2076
2078
  }
2077
- return u.forEach(f), u
2079
+ return u.forEach(s), u
2078
2080
  }
2079
2081
  function log2Reduce(n, e) {
2080
2082
  if (Math.log2(n.length) % 1 !== 0) throw new Error('Array length must be a power of 2')
@@ -2182,33 +2184,33 @@ function keccakPermutate(n) {
2182
2184
  o = n[2] ^ n[12] ^ n[22] ^ n[32] ^ n[42],
2183
2185
  i = n[3] ^ n[13] ^ n[23] ^ n[33] ^ n[43],
2184
2186
  u = n[4] ^ n[14] ^ n[24] ^ n[34] ^ n[44],
2185
- f = n[5] ^ n[15] ^ n[25] ^ n[35] ^ n[45],
2187
+ s = n[5] ^ n[15] ^ n[25] ^ n[35] ^ n[45],
2186
2188
  c = n[6] ^ n[16] ^ n[26] ^ n[36] ^ n[46],
2187
- s = n[7] ^ n[17] ^ n[27] ^ n[37] ^ n[47],
2189
+ f = n[7] ^ n[17] ^ n[27] ^ n[37] ^ n[47],
2188
2190
  l = n[8] ^ n[18] ^ n[28] ^ n[38] ^ n[48],
2189
2191
  a = n[9] ^ n[19] ^ n[29] ^ n[39] ^ n[49],
2190
2192
  h = (o << 1) | (i >>> 31),
2191
2193
  bn = (i << 1) | (o >>> 31),
2192
- d = l ^ h,
2193
- p = a ^ bn,
2194
- $n = (u << 1) | (f >>> 31),
2195
- An = (f << 1) | (u >>> 31),
2194
+ p = l ^ h,
2195
+ d = a ^ bn,
2196
+ $n = (u << 1) | (s >>> 31),
2197
+ An = (s << 1) | (u >>> 31),
2196
2198
  m = t ^ $n,
2197
2199
  g = r ^ An,
2198
- En = (c << 1) | (s >>> 31),
2199
- Mn = (s << 1) | (c >>> 31),
2200
+ En = (c << 1) | (f >>> 31),
2201
+ Mn = (f << 1) | (c >>> 31),
2200
2202
  w = o ^ En,
2201
2203
  y = i ^ Mn,
2202
2204
  On = (l << 1) | (a >>> 31),
2203
2205
  Tn = (a << 1) | (l >>> 31),
2204
2206
  x = u ^ On,
2205
- b = f ^ Tn,
2207
+ b = s ^ Tn,
2206
2208
  kn = (t << 1) | (r >>> 31),
2207
2209
  Sn = (r << 1) | (t >>> 31),
2208
2210
  $ = c ^ kn,
2209
- A = s ^ Sn
2210
- ;(n[0] ^= d),
2211
- (n[1] ^= p),
2211
+ A = f ^ Sn
2212
+ ;(n[0] ^= p),
2213
+ (n[1] ^= d),
2212
2214
  (n[2] ^= m),
2213
2215
  (n[3] ^= g),
2214
2216
  (n[4] ^= w),
@@ -2217,8 +2219,8 @@ function keccakPermutate(n) {
2217
2219
  (n[7] ^= b),
2218
2220
  (n[8] ^= $),
2219
2221
  (n[9] ^= A),
2220
- (n[10] ^= d),
2221
- (n[11] ^= p),
2222
+ (n[10] ^= p),
2223
+ (n[11] ^= d),
2222
2224
  (n[12] ^= m),
2223
2225
  (n[13] ^= g),
2224
2226
  (n[14] ^= w),
@@ -2227,8 +2229,8 @@ function keccakPermutate(n) {
2227
2229
  (n[17] ^= b),
2228
2230
  (n[18] ^= $),
2229
2231
  (n[19] ^= A),
2230
- (n[20] ^= d),
2231
- (n[21] ^= p),
2232
+ (n[20] ^= p),
2233
+ (n[21] ^= d),
2232
2234
  (n[22] ^= m),
2233
2235
  (n[23] ^= g),
2234
2236
  (n[24] ^= w),
@@ -2237,8 +2239,8 @@ function keccakPermutate(n) {
2237
2239
  (n[27] ^= b),
2238
2240
  (n[28] ^= $),
2239
2241
  (n[29] ^= A),
2240
- (n[30] ^= d),
2241
- (n[31] ^= p),
2242
+ (n[30] ^= p),
2243
+ (n[31] ^= d),
2242
2244
  (n[32] ^= m),
2243
2245
  (n[33] ^= g),
2244
2246
  (n[34] ^= w),
@@ -2247,8 +2249,8 @@ function keccakPermutate(n) {
2247
2249
  (n[37] ^= b),
2248
2250
  (n[38] ^= $),
2249
2251
  (n[39] ^= A),
2250
- (n[40] ^= d),
2251
- (n[41] ^= p),
2252
+ (n[40] ^= p),
2253
+ (n[41] ^= d),
2252
2254
  (n[42] ^= m),
2253
2255
  (n[43] ^= g),
2254
2256
  (n[44] ^= w),
@@ -2270,13 +2272,13 @@ function keccakPermutate(n) {
2270
2272
  P = (n[11] << 4) | (n[10] >>> 28),
2271
2273
  B = (n[10] << 4) | (n[11] >>> 28),
2272
2274
  L = (n[13] << 12) | (n[12] >>> 20),
2273
- U = (n[12] << 12) | (n[13] >>> 20),
2274
- N = (n[14] << 6) | (n[15] >>> 26),
2275
+ N = (n[12] << 12) | (n[13] >>> 20),
2276
+ U = (n[14] << 6) | (n[15] >>> 26),
2275
2277
  j = (n[15] << 6) | (n[14] >>> 26),
2276
- F = (n[17] << 23) | (n[16] >>> 9),
2278
+ v = (n[17] << 23) | (n[16] >>> 9),
2277
2279
  z = (n[16] << 23) | (n[17] >>> 9),
2278
- q = (n[18] << 20) | (n[19] >>> 12),
2279
- v = (n[19] << 20) | (n[18] >>> 12),
2280
+ F = (n[18] << 20) | (n[19] >>> 12),
2281
+ q = (n[19] << 20) | (n[18] >>> 12),
2280
2282
  W = (n[20] << 3) | (n[21] >>> 29),
2281
2283
  H = (n[21] << 3) | (n[20] >>> 29),
2282
2284
  V = (n[22] << 10) | (n[23] >>> 22),
@@ -2295,47 +2297,47 @@ function keccakPermutate(n) {
2295
2297
  on = (n[35] << 15) | (n[34] >>> 17),
2296
2298
  un = (n[36] << 21) | (n[37] >>> 11),
2297
2299
  cn = (n[37] << 21) | (n[36] >>> 11),
2298
- fn = (n[38] << 8) | (n[39] >>> 24),
2299
- sn = (n[39] << 8) | (n[38] >>> 24),
2300
+ sn = (n[38] << 8) | (n[39] >>> 24),
2301
+ fn = (n[39] << 8) | (n[38] >>> 24),
2300
2302
  ln = (n[40] << 18) | (n[41] >>> 14),
2301
2303
  an = (n[41] << 18) | (n[40] >>> 14),
2302
2304
  hn = (n[42] << 2) | (n[43] >>> 30),
2303
- dn = (n[43] << 2) | (n[42] >>> 30),
2304
- pn = (n[45] << 29) | (n[44] >>> 3),
2305
+ pn = (n[43] << 2) | (n[42] >>> 30),
2306
+ dn = (n[45] << 29) | (n[44] >>> 3),
2305
2307
  mn = (n[44] << 29) | (n[45] >>> 3),
2306
2308
  gn = (n[47] << 24) | (n[46] >>> 8),
2307
2309
  wn = (n[46] << 24) | (n[47] >>> 8),
2308
2310
  yn = (n[48] << 14) | (n[49] >>> 18),
2309
2311
  xn = (n[49] << 14) | (n[48] >>> 18)
2310
2312
  ;(n[0] = E ^ (~L & J)),
2311
- (n[1] = M ^ (~U & K)),
2313
+ (n[1] = M ^ (~N & K)),
2312
2314
  (n[2] = L ^ (~J & un)),
2313
- (n[3] = U ^ (~K & cn)),
2315
+ (n[3] = N ^ (~K & cn)),
2314
2316
  (n[4] = J ^ (~un & yn)),
2315
2317
  (n[5] = K ^ (~cn & xn)),
2316
2318
  (n[6] = un ^ (~yn & E)),
2317
2319
  (n[7] = cn ^ (~xn & M)),
2318
2320
  (n[8] = yn ^ (~E & L)),
2319
- (n[9] = xn ^ (~M & U)),
2320
- (n[10] = R ^ (~q & W)),
2321
- (n[11] = D ^ (~v & H)),
2322
- (n[12] = q ^ (~W & en)),
2323
- (n[13] = v ^ (~H & tn)),
2324
- (n[14] = W ^ (~en & pn)),
2321
+ (n[9] = xn ^ (~M & N)),
2322
+ (n[10] = R ^ (~F & W)),
2323
+ (n[11] = D ^ (~q & H)),
2324
+ (n[12] = F ^ (~W & en)),
2325
+ (n[13] = q ^ (~H & tn)),
2326
+ (n[14] = W ^ (~en & dn)),
2325
2327
  (n[15] = H ^ (~tn & mn)),
2326
- (n[16] = en ^ (~pn & R)),
2328
+ (n[16] = en ^ (~dn & R)),
2327
2329
  (n[17] = tn ^ (~mn & D)),
2328
- (n[18] = pn ^ (~R & q)),
2329
- (n[19] = mn ^ (~D & v)),
2330
- (n[20] = O ^ (~N & Z)),
2330
+ (n[18] = dn ^ (~R & F)),
2331
+ (n[19] = mn ^ (~D & q)),
2332
+ (n[20] = O ^ (~U & Z)),
2331
2333
  (n[21] = T ^ (~j & Q)),
2332
- (n[22] = N ^ (~Z & fn)),
2333
- (n[23] = j ^ (~Q & sn)),
2334
- (n[24] = Z ^ (~fn & ln)),
2335
- (n[25] = Q ^ (~sn & an)),
2336
- (n[26] = fn ^ (~ln & O)),
2337
- (n[27] = sn ^ (~an & T)),
2338
- (n[28] = ln ^ (~O & N)),
2334
+ (n[22] = U ^ (~Z & sn)),
2335
+ (n[23] = j ^ (~Q & fn)),
2336
+ (n[24] = Z ^ (~sn & ln)),
2337
+ (n[25] = Q ^ (~fn & an)),
2338
+ (n[26] = sn ^ (~ln & O)),
2339
+ (n[27] = fn ^ (~an & T)),
2340
+ (n[28] = ln ^ (~O & U)),
2339
2341
  (n[29] = an ^ (~T & j)),
2340
2342
  (n[30] = C ^ (~P & V)),
2341
2343
  (n[31] = I ^ (~B & _)),
@@ -2347,16 +2349,16 @@ function keccakPermutate(n) {
2347
2349
  (n[37] = on ^ (~wn & I)),
2348
2350
  (n[38] = gn ^ (~C & P)),
2349
2351
  (n[39] = wn ^ (~I & B)),
2350
- (n[40] = k ^ (~F & G)),
2352
+ (n[40] = k ^ (~v & G)),
2351
2353
  (n[41] = S ^ (~z & Y)),
2352
- (n[42] = F ^ (~G & X)),
2354
+ (n[42] = v ^ (~G & X)),
2353
2355
  (n[43] = z ^ (~Y & nn)),
2354
2356
  (n[44] = G ^ (~X & hn)),
2355
- (n[45] = Y ^ (~nn & dn)),
2357
+ (n[45] = Y ^ (~nn & pn)),
2356
2358
  (n[46] = X ^ (~hn & k)),
2357
- (n[47] = nn ^ (~dn & S)),
2358
- (n[48] = hn ^ (~k & F)),
2359
- (n[49] = dn ^ (~S & z)),
2359
+ (n[47] = nn ^ (~pn & S)),
2360
+ (n[48] = hn ^ (~k & v)),
2361
+ (n[49] = pn ^ (~S & z)),
2360
2362
  (n[0] ^= IOTA_CONSTANTS[e * 2]),
2361
2363
  (n[1] ^= IOTA_CONSTANTS[e * 2 + 1])
2362
2364
  }
@@ -2528,8 +2530,8 @@ function ellipticAdd(n, e, t, r, o) {
2528
2530
  if (n === t && e === r) return ellipticDouble(n, e, o)
2529
2531
  const i = mod((r - e) * modInverse(t - n, o), o),
2530
2532
  u = mod(i * i - n - t, o),
2531
- f = mod(i * (n - u) - e, o)
2532
- return [u, f]
2533
+ s = mod(i * (n - u) - e, o)
2534
+ return [u, s]
2533
2535
  }
2534
2536
  function privateKeyToPublicKey(n) {
2535
2537
  if (n <= 0n || n >= SECP256K1_N) throw new Error('Invalid private key')
@@ -2544,8 +2546,8 @@ function doubleAndAdd(n, e, t, r) {
2544
2546
  let o = [0n, 0n],
2545
2547
  i = [n, e]
2546
2548
  const u = t.toString(2)
2547
- for (const f of u)
2548
- f === '0'
2549
+ for (const s of u)
2550
+ s === '0'
2549
2551
  ? ((i = ellipticAdd(o[0], o[1], i[0], i[1], r)), (o = ellipticDouble(o[0], o[1], r)))
2550
2552
  : ((o = ellipticAdd(o[0], o[1], i[0], i[1], r)), (i = ellipticDouble(i[0], i[1], r)))
2551
2553
  return o
@@ -2572,28 +2574,28 @@ function signHash(n, e, t) {
2572
2574
  i = mod(o[0], SECP256K1_N)
2573
2575
  let u = mod((r + mod(i, SECP256K1_N) * e) * modInverse(t, SECP256K1_N), SECP256K1_N)
2574
2576
  if (i === 0n || u === 0n) throw new Error('Invalid r or s value')
2575
- let f = o[1] % 2n === 0n ? 27n : 28n
2576
- return u > SECP256K1_N / 2n && ((u = SECP256K1_N - u), (f = f === 27n ? 28n : 27n)), [i, u, f]
2577
+ let s = o[1] % 2n === 0n ? 27n : 28n
2578
+ return u > SECP256K1_N / 2n && ((u = SECP256K1_N - u), (s = s === 27n ? 28n : 27n)), [i, u, s]
2577
2579
  }
2578
2580
  function recoverPublicKey(n, e, t, r) {
2579
2581
  const o = modSqrt(mod(e ** 3n + 7n, SECP256K1_P), SECP256K1_P)
2580
2582
  if (!o) throw new Error('Invalid r: does not correspond to a valid curve point')
2581
2583
  const i = r === 27n ? 0n : 1n,
2582
2584
  u = o % 2n === i ? o : SECP256K1_P - o,
2583
- f = mod(uint256ToNumber(keccak256(n), 'BE'), SECP256K1_N),
2585
+ s = mod(uint256ToNumber(keccak256(n), 'BE'), SECP256K1_N),
2584
2586
  c = doubleAndAdd(e, u, t, SECP256K1_P),
2585
- s = doubleAndAdd(SECP256K1_X, SECP256K1_Y, f, SECP256K1_P),
2586
- l = ellipticAdd(c[0], c[1], s[0], mod(-s[1], SECP256K1_P), SECP256K1_P)
2587
+ f = doubleAndAdd(SECP256K1_X, SECP256K1_Y, s, SECP256K1_P),
2588
+ l = ellipticAdd(c[0], c[1], f[0], mod(-f[1], SECP256K1_P), SECP256K1_P)
2587
2589
  return doubleAndAdd(l[0], l[1], modInverse(e, SECP256K1_N), SECP256K1_P)
2588
2590
  }
2589
2591
  function verifySignature(n, e, t, r) {
2590
2592
  const o = mod(uint256ToNumber(keccak256(n), 'BE'), SECP256K1_N),
2591
2593
  i = modInverse(r, SECP256K1_N),
2592
2594
  u = mod(o * i, SECP256K1_N),
2593
- f = mod(t * i, SECP256K1_N),
2595
+ s = mod(t * i, SECP256K1_N),
2594
2596
  c = doubleAndAdd(SECP256K1_X, SECP256K1_Y, u, SECP256K1_P),
2595
- s = doubleAndAdd(e[0], e[1], f, SECP256K1_P),
2596
- l = ellipticAdd(c[0], c[1], s[0], s[1], SECP256K1_P)
2597
+ f = doubleAndAdd(e[0], e[1], s, SECP256K1_P),
2598
+ l = ellipticAdd(c[0], c[1], f[0], f[1], SECP256K1_P)
2597
2599
  return t === mod(l[0], SECP256K1_N)
2598
2600
  }
2599
2601
  class Uint8ArrayReader {
@@ -2635,27 +2637,36 @@ class Chunk {
2635
2637
  }
2636
2638
  }
2637
2639
  exports.Chunk = Chunk
2638
- function merkleStart(n) {
2639
- return [new Chunk(n)]
2640
- }
2641
- async function merkleNext(n, e, t) {
2642
- await e(n[t]),
2643
- n[t + 1] || n.push(new Chunk(n[t].writer.buffer.length)),
2644
- await merkleAppend(n, n[t].hash(), e, t + 1, n[t].span),
2645
- (n[t] = new Chunk(n[t].writer.buffer.length))
2646
- }
2647
- async function merkleAppend(n, e, t, r = 0, o) {
2648
- const i = new Uint8ArrayReader(e)
2649
- for (; i.max() > 0; ) {
2650
- n[r].writer.max() === 0 && (await merkleNext(n, t, r))
2651
- const u = n[r].writer.write(i)
2652
- o ? (n[r].span += o) : (n[0].span += BigInt(u))
2640
+ class MerkleTree {
2641
+ constructor(e, t = 4096) {
2642
+ ;(this.count = 0), (this.capacity = t), (this.chunks = [new Chunk(t)]), (this.onChunk = e)
2643
+ }
2644
+ static async root(e, t = 4096) {
2645
+ const r = new _a(_a.NOOP, t)
2646
+ return await r.append(e), r.finalize()
2647
+ }
2648
+ async append(e, t = 0, r = 0n) {
2649
+ const o = new Uint8ArrayReader(e)
2650
+ for (; o.max() > 0; ) {
2651
+ this.chunks[t].writer.max() === 0 && (await this.elevate(t))
2652
+ const i = this.chunks[t].writer.write(o)
2653
+ r ? (this.chunks[t].span += r) : (this.chunks[0].span += BigInt(i))
2654
+ }
2655
+ }
2656
+ async elevate(e) {
2657
+ this.count++,
2658
+ await this.onChunk(this.chunks[e]),
2659
+ this.chunks[e + 1] || this.chunks.push(new Chunk(this.capacity)),
2660
+ await this.append(this.chunks[e].hash(), e + 1, this.chunks[e].span),
2661
+ (this.chunks[e] = new Chunk(this.capacity))
2662
+ }
2663
+ async finalize(e = 0) {
2664
+ return this.chunks[e + 1]
2665
+ ? (await this.elevate(e), this.finalize(e + 1))
2666
+ : (this.count++, await this.onChunk(this.chunks[e]), this.chunks[e])
2653
2667
  }
2654
- return n
2655
- }
2656
- async function merkleFinalize(n, e, t = 0) {
2657
- return n[t + 1] ? (await merkleNext(n, e, t), merkleFinalize(n, e, t + 1)) : (await e(n[t]), n[t])
2658
2668
  }
2669
+ ;(exports.MerkleTree = MerkleTree), (_a = MerkleTree), (MerkleTree.NOOP = async n => {})
2659
2670
  function tickPlaybook(n) {
2660
2671
  if (n.length === 0) return null
2661
2672
  const e = n[0]
@@ -2665,7 +2676,7 @@ function tickPlaybook(n) {
2665
2676
  )
2666
2677
  }
2667
2678
  function getArgument(n, e, t, r) {
2668
- const o = n.findIndex(f => f === `--${e}` || f.startsWith(`--${e}=`)),
2679
+ const o = n.findIndex(s => s === `--${e}` || s.startsWith(`--${e}=`)),
2669
2680
  i = n[o]
2670
2681
  if (!i) return (t || {})[r || e || ''] || null
2671
2682
  if (i.includes('=')) return i.split('=')[1]
@@ -2687,9 +2698,9 @@ function getBooleanArgument(n, e, t, r) {
2687
2698
  if (!i && o) return !0
2688
2699
  if (!i && !o) return null
2689
2700
  const u = ['true', '1', 'yes', 'y', 'on'],
2690
- f = ['false', '0', 'no', 'n', 'off']
2701
+ s = ['false', '0', 'no', 'n', 'off']
2691
2702
  if (u.includes(i.toLowerCase())) return !0
2692
- if (f.includes(i.toLowerCase())) return !1
2703
+ if (s.includes(i.toLowerCase())) return !1
2693
2704
  throw Error(`Invalid boolean argument ${e}: ${i}`)
2694
2705
  }
2695
2706
  function requireStringArgument(n, e, t, r) {
@@ -2782,36 +2793,36 @@ function findCorners(n, e, t, r) {
2782
2793
  ]
2783
2794
  for (let i = 0; i < n.length; i++)
2784
2795
  for (let u = 0; u < n[0].length; u++) {
2785
- const f = getCorners(n, i, u)
2786
- for (const c of f) o.some(s => s.x === c.x && s.y === c.y) || o.push(c)
2796
+ const s = getCorners(n, i, u)
2797
+ for (const c of s) o.some(f => f.x === c.x && f.y === c.y) || o.push(c)
2787
2798
  }
2788
2799
  return o.map(i => ({ x: i.x * e, y: i.y * e }))
2789
2800
  }
2790
2801
  function findLines(n, e) {
2791
- const t = filterCoordinates(n, (c, s) => n[c][s] === 0 && n[c][s + 1] !== 0, 'row-first').map(c => ({
2802
+ const t = filterCoordinates(n, (c, f) => n[c][f] === 0 && n[c][f + 1] !== 0, 'row-first').map(c => ({
2792
2803
  ...c,
2793
2804
  dx: 1,
2794
2805
  dy: 0
2795
2806
  })),
2796
- r = filterCoordinates(n, (c, s) => n[c][s] === 0 && n[c][s - 1] !== 0, 'row-first').map(c => ({
2807
+ r = filterCoordinates(n, (c, f) => n[c][f] === 0 && n[c][f - 1] !== 0, 'row-first').map(c => ({
2797
2808
  ...c,
2798
2809
  dx: 1,
2799
2810
  dy: 0
2800
2811
  })),
2801
- o = filterCoordinates(n, (c, s) => n[c][s] === 0 && n[c - 1]?.[s] !== 0, 'column-first').map(c => ({
2812
+ o = filterCoordinates(n, (c, f) => n[c][f] === 0 && n[c - 1]?.[f] !== 0, 'column-first').map(c => ({
2802
2813
  ...c,
2803
2814
  dx: 0,
2804
2815
  dy: 1
2805
2816
  })),
2806
- i = filterCoordinates(n, (c, s) => n[c][s] === 0 && n[c + 1]?.[s] !== 0, 'column-first').map(c => ({
2817
+ i = filterCoordinates(n, (c, f) => n[c][f] === 0 && n[c + 1]?.[f] !== 0, 'column-first').map(c => ({
2807
2818
  ...c,
2808
2819
  dx: 0,
2809
2820
  dy: 1
2810
2821
  }))
2811
2822
  t.forEach(c => c.y++), i.forEach(c => c.x++)
2812
- const u = group([...o, ...i], (c, s) => c.x === s.x && c.y - 1 === s.y),
2813
- f = group([...r, ...t], (c, s) => c.y === s.y && c.x - 1 === s.x)
2814
- return [...u, ...f]
2823
+ const u = group([...o, ...i], (c, f) => c.x === f.x && c.y - 1 === f.y),
2824
+ s = group([...r, ...t], (c, f) => c.y === f.y && c.x - 1 === f.x)
2825
+ return [...u, ...s]
2815
2826
  .map(c => ({ start: c[0], end: last(c) }))
2816
2827
  .map(c => ({
2817
2828
  start: multiplyPoint(c.start, e),
@@ -2829,10 +2840,10 @@ function getLineIntersectionPoint(n, e, t, r) {
2829
2840
  if (o === 0) return null
2830
2841
  let i = n.y - t.y,
2831
2842
  u = n.x - t.x
2832
- const f = (r.x - t.x) * i - (r.y - t.y) * u,
2843
+ const s = (r.x - t.x) * i - (r.y - t.y) * u,
2833
2844
  c = (e.x - n.x) * i - (e.y - n.y) * u
2834
2845
  return (
2835
- (i = f / o),
2846
+ (i = s / o),
2836
2847
  (u = c / o),
2837
2848
  i > 0 && i < 1 && u > 0 && u < 1 ? { x: n.x + i * (e.x - n.x), y: n.y + i * (e.y - n.y) } : null
2838
2849
  )
@@ -2846,9 +2857,9 @@ function raycast(n, e, t) {
2846
2857
  }
2847
2858
  return r.length
2848
2859
  ? r.reduce((i, u) => {
2849
- const f = getDistanceBetweenPoints(n, u),
2860
+ const s = getDistanceBetweenPoints(n, u),
2850
2861
  c = getDistanceBetweenPoints(n, i)
2851
- return f < c ? u : i
2862
+ return s < c ? u : i
2852
2863
  })
2853
2864
  : null
2854
2865
  }
@@ -2856,9 +2867,9 @@ function raycastCircle(n, e, t) {
2856
2867
  const o = getSortedRayAngles(n, t),
2857
2868
  i = []
2858
2869
  for (const u of o) {
2859
- const f = raycast(n, e, u - 0.001),
2870
+ const s = raycast(n, e, u - 0.001),
2860
2871
  c = raycast(n, e, u + 0.001)
2861
- f && i.push(f), c && i.push(c)
2872
+ s && i.push(s), c && i.push(c)
2862
2873
  }
2863
2874
  return i
2864
2875
  }
@@ -2936,9 +2947,6 @@ class AsyncQueue {
2936
2947
  log2Reduce,
2937
2948
  partition,
2938
2949
  concatBytes,
2939
- merkleStart,
2940
- merkleAppend,
2941
- merkleFinalize,
2942
2950
  numberToUint8,
2943
2951
  uint8ToNumber,
2944
2952
  numberToUint16,
package/module.mjs CHANGED
@@ -18,6 +18,7 @@ export const Optional = utility.Optional
18
18
  export const Vector = utility.Vector
19
19
  export const PubSubChannel = utility.PubSubChannel
20
20
  export const Chunk = utility.Chunk
21
+ export const MerkleTree = utility.MerkleTree
21
22
  export const Lazy = utility.Lazy
22
23
  export const AsyncLazy = utility.AsyncLazy
23
24
  export const AsyncQueue = utility.AsyncQueue
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "26.15.1",
3
+ "version": "27.0.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {