cafe-utility 35.0.0 → 35.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.d.ts +12 -0
  2. package/index.js +337 -202
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -661,7 +661,19 @@ declare function compressPublicKey(publicKey: [bigint, bigint]): Uint8Array
661
661
  declare function publicKeyFromCompressed(compressed: Uint8Array): [bigint, bigint]
662
662
  declare function publicKeyToAddress(publicKey: [bigint, bigint]): Uint8Array
663
663
  declare function checksumEncode(addressBytes: Uint8Array): string
664
+ /**
665
+ * @deprecated Use a constant-time signing implementation instead.
666
+ * The underlying scalar multiplication is variable-time and leaks private key
667
+ * bits through timing. Safe only in environments where the caller has no
668
+ * exposure to timing side channels.
669
+ */
664
670
  declare function signMessage(message: Uint8Array, privateKey: bigint, nonce?: bigint): [bigint, bigint, 27n | 28n]
671
+ /**
672
+ * @deprecated Use a constant-time signing implementation instead.
673
+ * The underlying scalar multiplication is variable-time and leaks private key
674
+ * bits through timing. Safe only in environments where the caller has no
675
+ * exposure to timing side channels.
676
+ */
665
677
  declare function signHash(hash: bigint, privateKey: bigint, nonce?: bigint): [bigint, bigint, 27n | 28n]
666
678
  declare function recoverPublicKey(message: Uint8Array, r: bigint, s: bigint, v: 27n | 28n): [bigint, bigint]
667
679
  declare function verifySignature(message: Uint8Array, publicKey: [bigint, bigint], r: bigint, s: bigint): boolean
package/index.js CHANGED
@@ -127,13 +127,13 @@ function pickManyUnique(n, e, t, r = Math.random) {
127
127
  return i
128
128
  }
129
129
  function pickGuaranteed(n, e, t, r, i, o = Math.random) {
130
- const c = n.filter(s => s !== e && s !== t),
131
- u = []
132
- for (e !== null && u.push(e); c.length && u.length < r; ) {
133
- const s = exports.Random.intBetween(0, c.length - 1, o)
134
- i(c[s], u) && u.push(c[s]), c.splice(s, 1)
130
+ const c = n.filter(u => u !== e && u !== t),
131
+ s = []
132
+ for (e !== null && s.push(e); c.length && s.length < r; ) {
133
+ const u = exports.Random.intBetween(0, c.length - 1, o)
134
+ i(c[u], s) && s.push(c[u]), c.splice(u, 1)
135
135
  }
136
- return shuffle(u, o), { values: u, indexOfGuaranteed: e !== null ? u.indexOf(e) : -1 }
136
+ return shuffle(s, o), { values: s, indexOfGuaranteed: e !== null ? s.indexOf(e) : -1 }
137
137
  }
138
138
  function last(n) {
139
139
  if (!n.length) throw Error('Received empty array')
@@ -173,10 +173,10 @@ function setDeep(n, e, t) {
173
173
  let i = n
174
174
  for (let o = 0; o < r.length; o++) {
175
175
  const c = r[o],
176
- u = o < r.length - 1 && r[o + 1].includes(']'),
176
+ s = o < r.length - 1 && r[o + 1].includes(']'),
177
177
  f = c.includes(']') ? c.replace(/\[|\]/g, '') : c
178
178
  if (o === r.length - 1) return (i[f] = t), t
179
- isObject(i[f]) || (u ? (i[f] = []) : (i[f] = {})), (i = i[f])
179
+ isObject(i[f]) || (s ? (i[f] = []) : (i[f] = {})), (i = i[f])
180
180
  }
181
181
  return t
182
182
  }
@@ -233,13 +233,13 @@ function whereAmI() {
233
233
  }
234
234
  async function withRetries(n, e, t, r, i, o) {
235
235
  let c = null
236
- for (let u = 0; u <= e; u++)
236
+ for (let s = 0; s <= e; s++)
237
237
  try {
238
238
  return await n()
239
- } catch (s) {
240
- if (((c = s), u === e)) break
241
- const f = t + (r - t) * (u / (e - 1))
242
- i && i('Error in withRetries, retrying', { attempt: u + 1, allowedFailures: e, delayMillis: f, error: s }), o && o(), await sleepMillis(f)
239
+ } catch (u) {
240
+ if (((c = u), s === e)) break
241
+ const f = t + (r - t) * (s / (e - 1))
242
+ i && i('Error in withRetries, retrying', { attempt: s + 1, allowedFailures: e, delayMillis: f, error: u }), o && o(), await sleepMillis(f)
243
243
  }
244
244
  throw c
245
245
  }
@@ -260,9 +260,9 @@ function rgbToHex(n) {
260
260
  function haversineDistanceToMeters(n, e, t, r) {
261
261
  const o = (n * Math.PI) / 180,
262
262
  c = (t * Math.PI) / 180,
263
- u = ((t - n) * Math.PI) / 180,
264
- s = ((r - e) * Math.PI) / 180,
265
- f = Math.sin(u / 2) * Math.sin(u / 2) + Math.cos(o) * Math.cos(c) * Math.sin(s / 2) * Math.sin(s / 2)
263
+ s = ((t - n) * Math.PI) / 180,
264
+ u = ((r - e) * Math.PI) / 180,
265
+ f = Math.sin(s / 2) * Math.sin(s / 2) + Math.cos(o) * Math.cos(c) * Math.sin(u / 2) * Math.sin(u / 2)
266
266
  return 6371e3 * (2 * Math.atan2(Math.sqrt(f), Math.sqrt(1 - f)))
267
267
  }
268
268
  function roundToNearest(n, e) {
@@ -283,8 +283,8 @@ function binomialSample(n, e, t = Math.random) {
283
283
  const r = n * e,
284
284
  i = Math.sqrt(n * e * (1 - e)),
285
285
  c = (t() + t() + t() + t() + t() + t() - 3) * Math.SQRT2,
286
- u = Math.round(r + i * c)
287
- return Math.max(0, Math.min(n, u))
286
+ s = Math.round(r + i * c)
287
+ return Math.max(0, Math.min(n, s))
288
288
  }
289
289
  function toSignificantDigits(n, e) {
290
290
  if (!n.includes('.')) return n
@@ -298,9 +298,9 @@ function toSignificantDigits(n, e) {
298
298
  l = r.slice(0, f)
299
299
  return /[1-9]/.test(l) ? `${t}.${l.replace(/0+$/, '')}` : t
300
300
  }
301
- const u = r.match(/^0*/)?.[0].length ?? 0,
302
- s = e + u
303
- return `${t}.${r.slice(0, s)}`
301
+ const s = r.match(/^0*/)?.[0].length ?? 0,
302
+ u = e + s
303
+ return `${t}.${r.slice(0, u)}`
304
304
  }
305
305
  function isObject(n, e = !0) {
306
306
  return !n || (e && !isUndefined(n._readableState)) || (e && n.constructor && (n.constructor.isBuffer || n.constructor.name == 'AbortController' || n.constructor.name == 'AbortSignal' || n.constructor.name == 'Uint8Array' || n.constructor.name === 'ArrayBuffer' || n.constructor.name === 'ReadableStream')) ? !1 : typeof n == 'object'
@@ -784,9 +784,9 @@ function expand(n) {
784
784
  i = n.slice(0, t.index),
785
785
  o = n.slice(t.index + t[0].length)
786
786
  let c = []
787
- for (const u of r) {
788
- const s = expand(i + u + o)
789
- c = c.concat(s)
787
+ for (const s of r) {
788
+ const u = expand(i + s + o)
789
+ c = c.concat(u)
790
790
  }
791
791
  return c
792
792
  }
@@ -1032,11 +1032,11 @@ function baseToUint8Array(n, e) {
1032
1032
  let i = 0,
1033
1033
  o = 0
1034
1034
  const c = []
1035
- for (let u = 0; u < n.length; u++) {
1036
- const s = n[u]
1037
- if (s === t) break
1038
- const f = e.indexOf(s)
1039
- if (f === -1) throw new Error(`Invalid character: ${s}`)
1035
+ for (let s = 0; s < n.length; s++) {
1036
+ const u = n[s]
1037
+ if (u === t) break
1038
+ const f = e.indexOf(u)
1039
+ if (f === -1) throw new Error(`Invalid character: ${u}`)
1040
1040
  ;(o = (o << Math.log2(r)) | f), (i += Math.log2(r)), i >= 8 && ((i -= 8), c.push((o >> i) & 255))
1041
1041
  }
1042
1042
  return new Uint8Array(c)
@@ -1099,7 +1099,7 @@ function generateVariants(n, e, t, r = Math.random) {
1099
1099
  const i = exports.Arrays.shuffle(
1100
1100
  e.map(c => ({
1101
1101
  variants: exports.Arrays.shuffle(
1102
- c.variants.map(u => u),
1102
+ c.variants.map(s => s),
1103
1103
  r
1104
1104
  ),
1105
1105
  avoid: c.avoid
@@ -1108,14 +1108,14 @@ function generateVariants(n, e, t, r = Math.random) {
1108
1108
  ),
1109
1109
  o = []
1110
1110
  for (const c of i) {
1111
- const u = c.variants.filter(f => f !== c.avoid),
1112
- s = u.find(f => n.includes(f))
1113
- if (s && (pushAll(o, explodeReplace(n, s, u)), o.length >= t)) break
1111
+ const s = c.variants.filter(f => f !== c.avoid),
1112
+ u = s.find(f => n.includes(f))
1113
+ if (u && (pushAll(o, explodeReplace(n, u, s)), o.length >= t)) break
1114
1114
  }
1115
1115
  if (o.length < t)
1116
1116
  for (const c of i) {
1117
- const u = c.variants.find(s => n.includes(s))
1118
- if (u && (pushAll(o, explodeReplace(n, u, c.variants)), o.length >= t)) break
1117
+ const s = c.variants.find(u => n.includes(u))
1118
+ if (s && (pushAll(o, explodeReplace(n, s, c.variants)), o.length >= t)) break
1119
1119
  }
1120
1120
  return o.slice(0, t)
1121
1121
  }
@@ -1145,9 +1145,9 @@ function toLines(n, e, t = {}) {
1145
1145
  let i = '',
1146
1146
  o = 0
1147
1147
  for (let c = 0; c < n.length; c++) {
1148
- const u = n[c],
1149
- s = t[u] || 1
1150
- if (((i += u), (o += s), o > e)) {
1148
+ const s = n[c],
1149
+ u = t[s] || 1
1150
+ if (((i += s), (o += u), o > e)) {
1151
1151
  const { line: f, rest: l } = breakLine(i)
1152
1152
  r.push(f),
1153
1153
  (i = l),
@@ -1223,8 +1223,8 @@ function resolveVariableWithDefaultSyntax(n, e, t, r = '$', i = ':') {
1223
1223
  if (n[o + e.length + 1] === i)
1224
1224
  if (n[o + e.length + 2] === i) n = n.replace(`${r}${e}${i}${i}`, t)
1225
1225
  else {
1226
- const u = readNextWord(n, o + e.length + 2, ['_'])
1227
- n = n.replace(`${r}${e}${i}${u}`, t)
1226
+ const s = readNextWord(n, o + e.length + 2, ['_'])
1227
+ n = n.replace(`${r}${e}${i}${s}`, t)
1228
1228
  }
1229
1229
  else n = n.replace(`${r}${e}`, t)
1230
1230
  o = n.indexOf(`${r}${e}`, o + t.length)
@@ -1252,8 +1252,8 @@ function resolveMarkdownLinks(n, e) {
1252
1252
  i = n.indexOf(')', t)
1253
1253
  if (r !== -1 && i !== -1) {
1254
1254
  const [o, c] = n.slice(r + 1, i).split(']('),
1255
- u = e(o, c)
1256
- n = n.slice(0, r) + u + n.slice(i + 1)
1255
+ s = e(o, c)
1256
+ n = n.slice(0, r) + s + n.slice(i + 1)
1257
1257
  }
1258
1258
  t = n.indexOf('](', t + 1)
1259
1259
  }
@@ -1290,7 +1290,7 @@ function selectMax(n, e) {
1290
1290
  function reposition(n, e, t, r) {
1291
1291
  const i = n.find(c => c[e] === t),
1292
1292
  o = n.find(c => c[e] === t + r)
1293
- i && o ? ((i[e] = t + r), (o[e] = t)) : i && (i[e] = t + r), n.sort((c, u) => asNumber(c[e]) - asNumber(u[e])), n.forEach((c, u) => (c[e] = u + 1))
1293
+ i && o ? ((i[e] = t + r), (o[e] = t)) : i && (i[e] = t + r), n.sort((c, s) => asNumber(c[e]) - asNumber(s[e])), n.forEach((c, s) => (c[e] = s + 1))
1294
1294
  }
1295
1295
  function unwrapSingleKey(n) {
1296
1296
  const e = Object.keys(n)
@@ -1318,7 +1318,7 @@ function parseCsv(n, e = ',', t = '"') {
1318
1318
  let i = '',
1319
1319
  o = !1
1320
1320
  const c = n.split('')
1321
- for (const u of c) u === e && !o ? (r.push(i), (i = '')) : u === t && ((!i && !o) || o) ? (o = !o) : (i += u)
1321
+ for (const s of c) s === e && !o ? (r.push(i), (i = '')) : s === t && ((!i && !o) || o) ? (o = !o) : (i += s)
1322
1322
  return r.push(i), r
1323
1323
  }
1324
1324
  function humanizeProgress(n) {
@@ -1424,9 +1424,9 @@ function getProgress(n, e, t, r) {
1424
1424
  const i = e / t,
1425
1425
  o = r - n,
1426
1426
  c = o / e,
1427
- u = c * t,
1428
- s = u - o
1429
- return { deltaMs: o, progress: i, baseTimeMs: c, totalTimeMs: u, remainingTimeMs: s }
1427
+ s = c * t,
1428
+ u = s - o
1429
+ return { deltaMs: o, progress: i, baseTimeMs: c, totalTimeMs: s, remainingTimeMs: u }
1430
1430
  }
1431
1431
  const dayNumberIndex = { 0: 'sunday', 1: 'monday', 2: 'tuesday', 3: 'wednesday', 4: 'thursday', 5: 'friday', 6: 'saturday' }
1432
1432
  function mapDayNumber(n) {
@@ -1498,8 +1498,8 @@ function getCachedDeferred(n, e, t, r) {
1498
1498
  const c = t()
1499
1499
  return (
1500
1500
  tinyCache.set(n, { value: c, validUntil: i + e }),
1501
- c.catch(u => {
1502
- tinyCache.delete(n), r?.onFailure?.(u)
1501
+ c.catch(s => {
1502
+ tinyCache.delete(n), r?.onFailure?.(s)
1503
1503
  }),
1504
1504
  c
1505
1505
  )
@@ -1599,9 +1599,9 @@ function organiseWithLimits(n, e, t, r, i) {
1599
1599
  for (const c of Object.keys(e)) o[c] = []
1600
1600
  ;(o[r] = []), i && (n = n.sort(i))
1601
1601
  for (const c of n) {
1602
- const u = c[t],
1603
- s = e[u] ? u : r
1604
- o[s].length >= e[s] ? o[r].push(c) : o[s].push(c)
1602
+ const s = c[t],
1603
+ u = e[s] ? s : r
1604
+ o[u].length >= e[u] ? o[r].push(c) : o[u].push(c)
1605
1605
  }
1606
1606
  return o
1607
1607
  }
@@ -1738,20 +1738,20 @@ function flip(n) {
1738
1738
  }
1739
1739
  function getAllPermutations(n) {
1740
1740
  const e = Object.keys(n),
1741
- t = e.map(u => n[u].length),
1742
- r = t.reduce((u, s) => (u *= s))
1741
+ t = e.map(s => n[s].length),
1742
+ r = t.reduce((s, u) => (s *= u))
1743
1743
  let i = 1
1744
1744
  const o = [1]
1745
- for (let u = 0; u < t.length - 1; u++) (i *= t[u]), o.push(i)
1745
+ for (let s = 0; s < t.length - 1; s++) (i *= t[s]), o.push(i)
1746
1746
  const c = []
1747
- for (let u = 0; u < r; u++) {
1748
- const s = {}
1747
+ for (let s = 0; s < r; s++) {
1748
+ const u = {}
1749
1749
  for (let f = 0; f < e.length; f++) {
1750
1750
  const l = n[e[f]],
1751
- a = Math.floor(u / o[f]) % l.length
1752
- s[e[f]] = l[a]
1751
+ a = Math.floor(s / o[f]) % l.length
1752
+ u[e[f]] = l[a]
1753
1753
  }
1754
- c.push(s)
1754
+ c.push(u)
1755
1755
  }
1756
1756
  return c
1757
1757
  }
@@ -1764,8 +1764,8 @@ function getFlatNotation(n, e, t) {
1764
1764
  function flattenInner(n, e, t, r, i) {
1765
1765
  if (!isObject(e)) return e
1766
1766
  for (const [o, c] of Object.entries(e)) {
1767
- const u = getFlatNotation(t, o, r)
1768
- Array.isArray(c) ? (i ? flattenInner(n, c, u, !0, i) : (n[u] = c.map(s => flattenInner(Array.isArray(s) ? [] : {}, s, '', !1, i)))) : isObject(c) ? flattenInner(n, c, u, !1, i) : (n[u] = c)
1767
+ const s = getFlatNotation(t, o, r)
1768
+ Array.isArray(c) ? (i ? flattenInner(n, c, s, !0, i) : (n[s] = c.map(u => flattenInner(Array.isArray(u) ? [] : {}, u, '', !1, i)))) : isObject(c) ? flattenInner(n, c, s, !1, i) : (n[s] = c)
1769
1769
  }
1770
1770
  return n
1771
1771
  }
@@ -1831,9 +1831,9 @@ function makeUnique(n, e) {
1831
1831
  function countUnique(n, e, t, r, i) {
1832
1832
  const o = e ? n.map(e) : n,
1833
1833
  c = {}
1834
- for (const s of o) c[s] = (c[s] || 0) + 1
1835
- const u = r ? sortObjectValues(c, i ? (s, f) => s[1] - f[1] : (s, f) => f[1] - s[1]) : c
1836
- return t ? Object.keys(u) : u
1834
+ for (const u of o) c[u] = (c[u] || 0) + 1
1835
+ const s = r ? sortObjectValues(c, i ? (u, f) => u[1] - f[1] : (u, f) => f[1] - u[1]) : c
1836
+ return t ? Object.keys(s) : s
1837
1837
  }
1838
1838
  function sortObjectValues(n, e) {
1839
1839
  return Object.fromEntries(Object.entries(n).sort(e))
@@ -1998,28 +1998,28 @@ class Node {
1998
1998
  function createHierarchy(n, e, t, r, i = !1) {
1999
1999
  const o = new Map(),
2000
2000
  c = []
2001
- n.forEach(s => {
2002
- const f = new Node(s)
2003
- o.set(s[e], f)
2001
+ n.forEach(u => {
2002
+ const f = new Node(u)
2003
+ o.set(u[e], f)
2004
2004
  }),
2005
- n.forEach(s => {
2006
- const f = o.get(s[e])
2005
+ n.forEach(u => {
2006
+ const f = o.get(u[e])
2007
2007
  if (!f) return
2008
- const l = s[t]
2008
+ const l = u[t]
2009
2009
  if (l) {
2010
2010
  const a = o.get(l)
2011
2011
  a && a.children.push(f)
2012
2012
  } else c.push(f)
2013
2013
  })
2014
- const u = s => {
2015
- s.children.sort((f, l) => {
2014
+ const s = u => {
2015
+ u.children.sort((f, l) => {
2016
2016
  const a = f.value[r],
2017
2017
  h = l.value[r]
2018
2018
  return i ? h - a : a - h
2019
2019
  }),
2020
- s.children.forEach(u)
2020
+ u.children.forEach(s)
2021
2021
  }
2022
- return c.forEach(u), c
2022
+ return c.forEach(s), c
2023
2023
  }
2024
2024
  function log2Reduce(n, e) {
2025
2025
  if (Math.log2(n.length) % 1 !== 0) throw new Error('Array length must be a power of 2')
@@ -2122,83 +2122,83 @@ function keccakPermutate(n) {
2122
2122
  i = n[2] ^ n[12] ^ n[22] ^ n[32] ^ n[42],
2123
2123
  o = n[3] ^ n[13] ^ n[23] ^ n[33] ^ n[43],
2124
2124
  c = n[4] ^ n[14] ^ n[24] ^ n[34] ^ n[44],
2125
- u = n[5] ^ n[15] ^ n[25] ^ n[35] ^ n[45],
2126
- s = n[6] ^ n[16] ^ n[26] ^ n[36] ^ n[46],
2125
+ s = n[5] ^ n[15] ^ n[25] ^ n[35] ^ n[45],
2126
+ u = n[6] ^ n[16] ^ n[26] ^ n[36] ^ n[46],
2127
2127
  f = n[7] ^ n[17] ^ n[27] ^ n[37] ^ n[47],
2128
2128
  l = n[8] ^ n[18] ^ n[28] ^ n[38] ^ n[48],
2129
2129
  a = n[9] ^ n[19] ^ n[29] ^ n[39] ^ n[49],
2130
2130
  h = (i << 1) | (o >>> 31),
2131
- bn = (o << 1) | (i >>> 31),
2131
+ p = (o << 1) | (i >>> 31),
2132
2132
  d = l ^ h,
2133
- p = a ^ bn,
2134
- $n = (c << 1) | (u >>> 31),
2135
- An = (u << 1) | (c >>> 31),
2136
- m = t ^ $n,
2137
- g = r ^ An,
2138
- En = (s << 1) | (f >>> 31),
2139
- Sn = (f << 1) | (s >>> 31),
2140
- w = i ^ En,
2141
- x = o ^ Sn,
2142
- Mn = (l << 1) | (a >>> 31),
2133
+ m = a ^ p,
2134
+ w = (c << 1) | (s >>> 31),
2135
+ x = (s << 1) | (c >>> 31),
2136
+ g = t ^ w,
2137
+ y = r ^ x,
2138
+ En = (u << 1) | (f >>> 31),
2139
+ Mn = (f << 1) | (u >>> 31),
2140
+ b = i ^ En,
2141
+ A = o ^ Mn,
2142
+ Sn = (l << 1) | (a >>> 31),
2143
2143
  kn = (a << 1) | (l >>> 31),
2144
- y = c ^ Mn,
2145
- b = u ^ kn,
2144
+ $ = c ^ Sn,
2145
+ E = s ^ kn,
2146
2146
  On = (t << 1) | (r >>> 31),
2147
2147
  Tn = (r << 1) | (t >>> 31),
2148
- $ = s ^ On,
2149
- A = f ^ Tn
2150
- ;(n[0] ^= d), (n[1] ^= p), (n[2] ^= m), (n[3] ^= g), (n[4] ^= w), (n[5] ^= x), (n[6] ^= y), (n[7] ^= b), (n[8] ^= $), (n[9] ^= A), (n[10] ^= d), (n[11] ^= p), (n[12] ^= m), (n[13] ^= g), (n[14] ^= w), (n[15] ^= x), (n[16] ^= y), (n[17] ^= b), (n[18] ^= $), (n[19] ^= A), (n[20] ^= d), (n[21] ^= p), (n[22] ^= m), (n[23] ^= g), (n[24] ^= w), (n[25] ^= x), (n[26] ^= y), (n[27] ^= b), (n[28] ^= $), (n[29] ^= A), (n[30] ^= d), (n[31] ^= p), (n[32] ^= m), (n[33] ^= g), (n[34] ^= w), (n[35] ^= x), (n[36] ^= y), (n[37] ^= b), (n[38] ^= $), (n[39] ^= A), (n[40] ^= d), (n[41] ^= p), (n[42] ^= m), (n[43] ^= g), (n[44] ^= w), (n[45] ^= x), (n[46] ^= y), (n[47] ^= b), (n[48] ^= $), (n[49] ^= A)
2151
- const E = n[0],
2152
- S = n[1],
2153
- M = (n[2] << 1) | (n[3] >>> 31),
2154
- k = (n[3] << 1) | (n[2] >>> 31),
2155
- O = (n[5] << 30) | (n[4] >>> 2),
2156
- T = (n[4] << 30) | (n[5] >>> 2),
2157
- C = (n[6] << 28) | (n[7] >>> 4),
2158
- R = (n[7] << 28) | (n[6] >>> 4),
2159
- I = (n[8] << 27) | (n[9] >>> 5),
2160
- D = (n[9] << 27) | (n[8] >>> 5),
2161
- P = (n[11] << 4) | (n[10] >>> 28),
2162
- B = (n[10] << 4) | (n[11] >>> 28),
2163
- v = (n[13] << 12) | (n[12] >>> 20),
2164
- U = (n[12] << 12) | (n[13] >>> 20),
2165
- L = (n[14] << 6) | (n[15] >>> 26),
2166
- j = (n[15] << 6) | (n[14] >>> 26),
2167
- N = (n[17] << 23) | (n[16] >>> 9),
2168
- F = (n[16] << 23) | (n[17] >>> 9),
2169
- z = (n[18] << 20) | (n[19] >>> 12),
2170
- q = (n[19] << 20) | (n[18] >>> 12),
2171
- W = (n[20] << 3) | (n[21] >>> 29),
2172
- H = (n[21] << 3) | (n[20] >>> 29),
2173
- V = (n[22] << 10) | (n[23] >>> 22),
2174
- J = (n[23] << 10) | (n[22] >>> 22),
2175
- K = (n[25] << 11) | (n[24] >>> 21),
2176
- Z = (n[24] << 11) | (n[25] >>> 21),
2177
- Q = (n[26] << 25) | (n[27] >>> 7),
2178
- G = (n[27] << 25) | (n[26] >>> 7),
2179
- Y = (n[29] << 7) | (n[28] >>> 25),
2180
- X = (n[28] << 7) | (n[29] >>> 25),
2181
- _ = (n[31] << 9) | (n[30] >>> 23),
2182
- nn = (n[30] << 9) | (n[31] >>> 23),
2183
- en = (n[33] << 13) | (n[32] >>> 19),
2184
- tn = (n[32] << 13) | (n[33] >>> 19),
2185
- rn = (n[34] << 15) | (n[35] >>> 17),
2186
- on = (n[35] << 15) | (n[34] >>> 17),
2187
- cn = (n[36] << 21) | (n[37] >>> 11),
2188
- sn = (n[37] << 21) | (n[36] >>> 11),
2189
- un = (n[38] << 8) | (n[39] >>> 24),
2190
- fn = (n[39] << 8) | (n[38] >>> 24),
2191
- ln = (n[40] << 18) | (n[41] >>> 14),
2192
- an = (n[41] << 18) | (n[40] >>> 14),
2193
- hn = (n[42] << 2) | (n[43] >>> 30),
2194
- dn = (n[43] << 2) | (n[42] >>> 30),
2195
- pn = (n[45] << 29) | (n[44] >>> 3),
2196
- mn = (n[44] << 29) | (n[45] >>> 3),
2197
- gn = (n[47] << 24) | (n[46] >>> 8),
2198
- wn = (n[46] << 24) | (n[47] >>> 8),
2199
- xn = (n[48] << 14) | (n[49] >>> 18),
2200
- yn = (n[49] << 14) | (n[48] >>> 18)
2201
- ;(n[0] = E ^ (~v & K)), (n[1] = S ^ (~U & Z)), (n[2] = v ^ (~K & cn)), (n[3] = U ^ (~Z & sn)), (n[4] = K ^ (~cn & xn)), (n[5] = Z ^ (~sn & yn)), (n[6] = cn ^ (~xn & E)), (n[7] = sn ^ (~yn & S)), (n[8] = xn ^ (~E & v)), (n[9] = yn ^ (~S & U)), (n[10] = C ^ (~z & W)), (n[11] = R ^ (~q & H)), (n[12] = z ^ (~W & en)), (n[13] = q ^ (~H & tn)), (n[14] = W ^ (~en & pn)), (n[15] = H ^ (~tn & mn)), (n[16] = en ^ (~pn & C)), (n[17] = tn ^ (~mn & R)), (n[18] = pn ^ (~C & z)), (n[19] = mn ^ (~R & q)), (n[20] = M ^ (~L & Q)), (n[21] = k ^ (~j & G)), (n[22] = L ^ (~Q & un)), (n[23] = j ^ (~G & fn)), (n[24] = Q ^ (~un & ln)), (n[25] = G ^ (~fn & an)), (n[26] = un ^ (~ln & M)), (n[27] = fn ^ (~an & k)), (n[28] = ln ^ (~M & L)), (n[29] = an ^ (~k & j)), (n[30] = I ^ (~P & V)), (n[31] = D ^ (~B & J)), (n[32] = P ^ (~V & rn)), (n[33] = B ^ (~J & on)), (n[34] = V ^ (~rn & gn)), (n[35] = J ^ (~on & wn)), (n[36] = rn ^ (~gn & I)), (n[37] = on ^ (~wn & D)), (n[38] = gn ^ (~I & P)), (n[39] = wn ^ (~D & B)), (n[40] = O ^ (~N & Y)), (n[41] = T ^ (~F & X)), (n[42] = N ^ (~Y & _)), (n[43] = F ^ (~X & nn)), (n[44] = Y ^ (~_ & hn)), (n[45] = X ^ (~nn & dn)), (n[46] = _ ^ (~hn & O)), (n[47] = nn ^ (~dn & T)), (n[48] = hn ^ (~O & N)), (n[49] = dn ^ (~T & F)), (n[0] ^= IOTA_CONSTANTS[e * 2]), (n[1] ^= IOTA_CONSTANTS[e * 2 + 1])
2148
+ M = u ^ On,
2149
+ S = f ^ Tn
2150
+ ;(n[0] ^= d), (n[1] ^= m), (n[2] ^= g), (n[3] ^= y), (n[4] ^= b), (n[5] ^= A), (n[6] ^= $), (n[7] ^= E), (n[8] ^= M), (n[9] ^= S), (n[10] ^= d), (n[11] ^= m), (n[12] ^= g), (n[13] ^= y), (n[14] ^= b), (n[15] ^= A), (n[16] ^= $), (n[17] ^= E), (n[18] ^= M), (n[19] ^= S), (n[20] ^= d), (n[21] ^= m), (n[22] ^= g), (n[23] ^= y), (n[24] ^= b), (n[25] ^= A), (n[26] ^= $), (n[27] ^= E), (n[28] ^= M), (n[29] ^= S), (n[30] ^= d), (n[31] ^= m), (n[32] ^= g), (n[33] ^= y), (n[34] ^= b), (n[35] ^= A), (n[36] ^= $), (n[37] ^= E), (n[38] ^= M), (n[39] ^= S), (n[40] ^= d), (n[41] ^= m), (n[42] ^= g), (n[43] ^= y), (n[44] ^= b), (n[45] ^= A), (n[46] ^= $), (n[47] ^= E), (n[48] ^= M), (n[49] ^= S)
2151
+ const k = n[0],
2152
+ O = n[1],
2153
+ T = (n[2] << 1) | (n[3] >>> 31),
2154
+ C = (n[3] << 1) | (n[2] >>> 31),
2155
+ R = (n[5] << 30) | (n[4] >>> 2),
2156
+ I = (n[4] << 30) | (n[5] >>> 2),
2157
+ D = (n[6] << 28) | (n[7] >>> 4),
2158
+ P = (n[7] << 28) | (n[6] >>> 4),
2159
+ B = (n[8] << 27) | (n[9] >>> 5),
2160
+ v = (n[9] << 27) | (n[8] >>> 5),
2161
+ U = (n[11] << 4) | (n[10] >>> 28),
2162
+ j = (n[10] << 4) | (n[11] >>> 28),
2163
+ L = (n[13] << 12) | (n[12] >>> 20),
2164
+ N = (n[12] << 12) | (n[13] >>> 20),
2165
+ F = (n[14] << 6) | (n[15] >>> 26),
2166
+ z = (n[15] << 6) | (n[14] >>> 26),
2167
+ W = (n[17] << 23) | (n[16] >>> 9),
2168
+ H = (n[16] << 23) | (n[17] >>> 9),
2169
+ q = (n[18] << 20) | (n[19] >>> 12),
2170
+ V = (n[19] << 20) | (n[18] >>> 12),
2171
+ J = (n[20] << 3) | (n[21] >>> 29),
2172
+ K = (n[21] << 3) | (n[20] >>> 29),
2173
+ Z = (n[22] << 10) | (n[23] >>> 22),
2174
+ Q = (n[23] << 10) | (n[22] >>> 22),
2175
+ G = (n[25] << 11) | (n[24] >>> 21),
2176
+ _ = (n[24] << 11) | (n[25] >>> 21),
2177
+ Y = (n[26] << 25) | (n[27] >>> 7),
2178
+ X = (n[27] << 25) | (n[26] >>> 7),
2179
+ nn = (n[29] << 7) | (n[28] >>> 25),
2180
+ en = (n[28] << 7) | (n[29] >>> 25),
2181
+ tn = (n[31] << 9) | (n[30] >>> 23),
2182
+ rn = (n[30] << 9) | (n[31] >>> 23),
2183
+ on = (n[33] << 13) | (n[32] >>> 19),
2184
+ cn = (n[32] << 13) | (n[33] >>> 19),
2185
+ sn = (n[34] << 15) | (n[35] >>> 17),
2186
+ un = (n[35] << 15) | (n[34] >>> 17),
2187
+ fn = (n[36] << 21) | (n[37] >>> 11),
2188
+ ln = (n[37] << 21) | (n[36] >>> 11),
2189
+ an = (n[38] << 8) | (n[39] >>> 24),
2190
+ hn = (n[39] << 8) | (n[38] >>> 24),
2191
+ dn = (n[40] << 18) | (n[41] >>> 14),
2192
+ pn = (n[41] << 18) | (n[40] >>> 14),
2193
+ mn = (n[42] << 2) | (n[43] >>> 30),
2194
+ gn = (n[43] << 2) | (n[42] >>> 30),
2195
+ wn = (n[45] << 29) | (n[44] >>> 3),
2196
+ xn = (n[44] << 29) | (n[45] >>> 3),
2197
+ yn = (n[47] << 24) | (n[46] >>> 8),
2198
+ bn = (n[46] << 24) | (n[47] >>> 8),
2199
+ An = (n[48] << 14) | (n[49] >>> 18),
2200
+ $n = (n[49] << 14) | (n[48] >>> 18)
2201
+ ;(n[0] = k ^ (~L & G)), (n[1] = O ^ (~N & _)), (n[2] = L ^ (~G & fn)), (n[3] = N ^ (~_ & ln)), (n[4] = G ^ (~fn & An)), (n[5] = _ ^ (~ln & $n)), (n[6] = fn ^ (~An & k)), (n[7] = ln ^ (~$n & O)), (n[8] = An ^ (~k & L)), (n[9] = $n ^ (~O & N)), (n[10] = D ^ (~q & J)), (n[11] = P ^ (~V & K)), (n[12] = q ^ (~J & on)), (n[13] = V ^ (~K & cn)), (n[14] = J ^ (~on & wn)), (n[15] = K ^ (~cn & xn)), (n[16] = on ^ (~wn & D)), (n[17] = cn ^ (~xn & P)), (n[18] = wn ^ (~D & q)), (n[19] = xn ^ (~P & V)), (n[20] = T ^ (~F & Y)), (n[21] = C ^ (~z & X)), (n[22] = F ^ (~Y & an)), (n[23] = z ^ (~X & hn)), (n[24] = Y ^ (~an & dn)), (n[25] = X ^ (~hn & pn)), (n[26] = an ^ (~dn & T)), (n[27] = hn ^ (~pn & C)), (n[28] = dn ^ (~T & F)), (n[29] = pn ^ (~C & z)), (n[30] = B ^ (~U & Z)), (n[31] = v ^ (~j & Q)), (n[32] = U ^ (~Z & sn)), (n[33] = j ^ (~Q & un)), (n[34] = Z ^ (~sn & yn)), (n[35] = Q ^ (~un & bn)), (n[36] = sn ^ (~yn & B)), (n[37] = un ^ (~bn & v)), (n[38] = yn ^ (~B & U)), (n[39] = bn ^ (~v & j)), (n[40] = R ^ (~W & nn)), (n[41] = I ^ (~H & en)), (n[42] = W ^ (~nn & tn)), (n[43] = H ^ (~en & rn)), (n[44] = nn ^ (~tn & mn)), (n[45] = en ^ (~rn & gn)), (n[46] = tn ^ (~mn & R)), (n[47] = rn ^ (~gn & I)), (n[48] = mn ^ (~R & W)), (n[49] = gn ^ (~I & H)), (n[0] ^= IOTA_CONSTANTS[e * 2]), (n[1] ^= IOTA_CONSTANTS[e * 2 + 1])
2202
2202
  }
2203
2203
  }
2204
2204
  function bytesToNumbers(n) {
@@ -2249,7 +2249,7 @@ function bmtRoot(n) {
2249
2249
  const o = i >>> 1
2250
2250
  for (let c = 0; c < o; c++) {
2251
2251
  r.set(e.subarray(c << 6, (c + 1) << 6)), t.fill(0)
2252
- for (let u = 0, s = 0; u < 34; u += 2, s += 8) (t[u] ^= r[s + 4] | (r[s + 5] << 8) | (r[s + 6] << 16) | (r[s + 7] << 24)), (t[u + 1] ^= r[s] | (r[s + 1] << 8) | (r[s + 2] << 16) | (r[s + 3] << 24))
2252
+ for (let s = 0, u = 0; s < 34; s += 2, u += 8) (t[s] ^= r[u + 4] | (r[u + 5] << 8) | (r[u + 6] << 16) | (r[u + 7] << 24)), (t[s + 1] ^= r[u] | (r[u + 1] << 8) | (r[u + 2] << 16) | (r[u + 3] << 24))
2253
2253
  keccakPermutate(t), squeezeInto(t, e, c << 5)
2254
2254
  }
2255
2255
  i = o
@@ -2262,11 +2262,11 @@ function encryptSegments(n, e, t) {
2262
2262
  i = new Uint8Array(36)
2263
2263
  i.set(n)
2264
2264
  for (let o = 0, c = 0; c < t.length; o++, c += 32) {
2265
- const u = (e + o) >>> 0
2266
- ;(i[32] = u & 255), (i[33] = (u >>> 8) & 255), (i[34] = (u >>> 16) & 255), (i[35] = (u >>> 24) & 255)
2267
- const s = keccak256(keccak256(i)),
2265
+ const s = (e + o) >>> 0
2266
+ ;(i[32] = s & 255), (i[33] = (s >>> 8) & 255), (i[34] = (s >>> 16) & 255), (i[35] = (s >>> 24) & 255)
2267
+ const u = keccak256(keccak256(i)),
2268
2268
  f = Math.min(c + 32, t.length)
2269
- for (let l = c; l < f; l++) r[l] = t[l] ^ s[l - c]
2269
+ for (let l = c; l < f; l++) r[l] = t[l] ^ u[l - c]
2270
2270
  }
2271
2271
  return r
2272
2272
  }
@@ -2379,7 +2379,8 @@ function modSqrt(n, e) {
2379
2379
  const SECP256K1_P = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,
2380
2380
  SECP256K1_N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,
2381
2381
  SECP256K1_X = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,
2382
- SECP256K1_Y = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n
2382
+ SECP256K1_Y = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,
2383
+ SECP256K1_BETA = 0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501een
2383
2384
  function ellipticDouble(n, e, t) {
2384
2385
  if (e === 0n) return [0n, 0n]
2385
2386
  const r = mod(3n * n * n * modInverse(2n * e, t), t),
@@ -2394,12 +2395,12 @@ function ellipticAdd(n, e, t, r, i) {
2394
2395
  if (n === t && e === r) return ellipticDouble(n, e, i)
2395
2396
  const o = mod((r - e) * modInverse(t - n, i), i),
2396
2397
  c = mod(o * o - n - t, i),
2397
- u = mod(o * (n - c) - e, i)
2398
- return [c, u]
2398
+ s = mod(o * (n - c) - e, i)
2399
+ return [c, s]
2399
2400
  }
2400
2401
  function privateKeyToPublicKey(n) {
2401
2402
  if (n <= 0n || n >= SECP256K1_N) throw new Error('Invalid private key')
2402
- return doubleAndAdd(SECP256K1_X, SECP256K1_Y, n, SECP256K1_P)
2403
+ return doubleAndAdd(SECP256K1_X, SECP256K1_Y, n)
2403
2404
  }
2404
2405
  function compressPublicKey(n) {
2405
2406
  const t = n[1] % 2n === 0n ? 2 : 3
@@ -2426,46 +2427,173 @@ function checksumEncode(n) {
2426
2427
  for (let i = 0; i < e.length; i++) parseInt(t[i], 16) > 7 ? (r += e[i].toUpperCase()) : (r += e[i])
2427
2428
  return r
2428
2429
  }
2429
- function doubleAndAdd(n, e, t, r) {
2430
- let i = [0n, 0n],
2431
- o = [n, e]
2432
- const c = t.toString(2)
2433
- for (const u of c) u === '0' ? ((o = ellipticAdd(i[0], i[1], o[0], o[1], r)), (i = ellipticDouble(i[0], i[1], r))) : ((i = ellipticAdd(i[0], i[1], o[0], o[1], r)), (o = ellipticDouble(o[0], o[1], r)))
2430
+ function jacobianDouble(n, e, t) {
2431
+ if (t === 0n) return [0n, 0n, 0n]
2432
+ const r = SECP256K1_P,
2433
+ i = (e * e) % r,
2434
+ o = (4n * n * i) % r,
2435
+ c = (3n * n * n) % r,
2436
+ s = mod(c * c - 2n * o, r),
2437
+ u = mod(c * (o - s) - 8n * i * i, r),
2438
+ f = (2n * e * t) % r
2439
+ return [s, u, f]
2440
+ }
2441
+ function jacobianAddMixed(n, e, t, r, i) {
2442
+ if (t === 0n) return [r, i, 1n]
2443
+ const o = SECP256K1_P,
2444
+ c = (t * t) % o,
2445
+ s = (r * c) % o,
2446
+ u = (((i * c) % o) * t) % o,
2447
+ f = mod(s - n, o),
2448
+ l = mod(u - e, o)
2449
+ if (f === 0n) return l === 0n ? jacobianDouble(n, e, t) : [0n, 0n, 0n]
2450
+ const a = (f * f) % o,
2451
+ h = (f * a) % o,
2452
+ p = (n * a) % o,
2453
+ d = mod(l * l - h - 2n * p, o),
2454
+ m = mod(l * (p - d) - e * h, o),
2455
+ w = (f * t) % o
2456
+ return [d, m, w]
2457
+ }
2458
+ function jacobianToAffine(n, e, t) {
2459
+ if (t === 0n) return [0n, 0n]
2460
+ const r = SECP256K1_P,
2461
+ i = modInverse(t, r),
2462
+ o = (i * i) % r
2463
+ return [(n * o) % r, (((e * o) % r) * i) % r]
2464
+ }
2465
+ function glvDecompose(n) {
2466
+ const e = SECP256K1_N,
2467
+ t = 0x3086d221a7d46bcde86c90e49284eb15n,
2468
+ r = 0xe4437ed6010e88286f547fa90abfe4c3n,
2469
+ i = 0x114ca50f7a8e2f3f657c1108d9d44cfd8n,
2470
+ o = 0x3086d221a7d46bcde86c90e49284eb15n,
2471
+ c = (o * n + e / 2n) / e,
2472
+ s = (r * n + e / 2n) / e
2473
+ let u = mod(n - c * t - s * i, e),
2474
+ f = mod(c * r - s * o, e)
2475
+ const l = u > 1n << 128n,
2476
+ a = f > 1n << 128n
2477
+ return l && (u = e - u), a && (f = e - f), [u, l, f, a]
2478
+ }
2479
+ const WNAF_W = 4
2480
+ function toWNAF(n) {
2481
+ const e = 1 << WNAF_W,
2482
+ t = e >> 1,
2483
+ r = BigInt(e - 1),
2484
+ i = []
2485
+ for (; n > 0n; ) {
2486
+ if (n & 1n) {
2487
+ let o = Number(n & r)
2488
+ o >= t && (o -= e), i.push(o), (n -= BigInt(o))
2489
+ } else i.push(0)
2490
+ n >>= 1n
2491
+ }
2434
2492
  return i
2435
2493
  }
2494
+ function batchToAffine(n) {
2495
+ const e = SECP256K1_P,
2496
+ t = n.length
2497
+ if (t === 1) return [jacobianToAffine(n[0][0], n[0][1], n[0][2])]
2498
+ const r = new Array(t)
2499
+ r[0] = n[0][2]
2500
+ for (let s = 1; s < t; s++) r[s] = (r[s - 1] * n[s][2]) % e
2501
+ let i = modInverse(r[t - 1], e)
2502
+ const o = new Array(t)
2503
+ for (let s = t - 1; s > 0; s--) {
2504
+ const u = (i * r[s - 1]) % e,
2505
+ f = (u * u) % e
2506
+ ;(o[s] = [(n[s][0] * f) % e, (((n[s][1] * f) % e) * u) % e]), (i = (i * n[s][2]) % e)
2507
+ }
2508
+ const c = (i * i) % e
2509
+ return (o[0] = [(n[0][0] * c) % e, (((n[0][1] * c) % e) * i) % e]), o
2510
+ }
2511
+ function precomputeOddMultiples(n, e) {
2512
+ const t = 1 << (WNAF_W - 2),
2513
+ [r, i] = jacobianToAffine(...jacobianDouble(n, e, 1n)),
2514
+ o = [[n, e, 1n]]
2515
+ for (let c = 1; c < t; c++) {
2516
+ const [s, u, f] = o[c - 1]
2517
+ o.push(jacobianAddMixed(s, u, f, r, i))
2518
+ }
2519
+ return batchToAffine(o)
2520
+ }
2521
+ function shamirWNAF(n, e, t, r, i, o) {
2522
+ const c = toWNAF(n),
2523
+ s = toWNAF(r),
2524
+ u = precomputeOddMultiples(e, t),
2525
+ f = precomputeOddMultiples(i, o),
2526
+ l = Math.max(c.length, s.length)
2527
+ let a = 0n,
2528
+ h = 0n,
2529
+ p = 0n
2530
+ for (let d = l - 1; d >= 0; d--) {
2531
+ ;[a, h, p] = jacobianDouble(a, h, p)
2532
+ const m = d < c.length ? c[d] : 0
2533
+ if (m !== 0) {
2534
+ const [x, g] = u[(Math.abs(m) - 1) >> 1]
2535
+ ;[a, h, p] = jacobianAddMixed(a, h, p, x, m > 0 ? g : SECP256K1_P - g)
2536
+ }
2537
+ const w = d < s.length ? s[d] : 0
2538
+ if (w !== 0) {
2539
+ const [x, g] = f[(Math.abs(w) - 1) >> 1]
2540
+ ;[a, h, p] = jacobianAddMixed(a, h, p, x, w > 0 ? g : SECP256K1_P - g)
2541
+ }
2542
+ }
2543
+ return jacobianToAffine(a, h, p)
2544
+ }
2545
+ function doubleAndAdd(n, e, t) {
2546
+ const [r, i, o, c] = glvDecompose(t),
2547
+ s = i ? SECP256K1_P - e : e,
2548
+ u = (SECP256K1_BETA * n) % SECP256K1_P,
2549
+ f = c ? SECP256K1_P - e : e
2550
+ return shamirWNAF(r, n, s, o, u, f)
2551
+ }
2552
+ /**
2553
+ * @deprecated Use a constant-time signing implementation instead.
2554
+ * The underlying scalar multiplication is variable-time and leaks private key
2555
+ * bits through timing. Safe only in environments where the caller has no
2556
+ * exposure to timing side channels.
2557
+ */
2436
2558
  function signMessage(n, e, t) {
2437
2559
  return signHash(uint256ToNumber(keccak256(n), 'BE'), e, t)
2438
2560
  }
2561
+ /**
2562
+ * @deprecated Use a constant-time signing implementation instead.
2563
+ * The underlying scalar multiplication is variable-time and leaks private key
2564
+ * bits through timing. Safe only in environments where the caller has no
2565
+ * exposure to timing side channels.
2566
+ */
2439
2567
  function signHash(n, e, t) {
2440
2568
  if (e <= 0n || e >= SECP256K1_N) throw new Error('Invalid private key')
2441
2569
  if ((t || (t = mod(uint256ToNumber(keccak256(concatBytes(keccak256(numberToUint256(e, 'BE')), numberToUint256(n, 'BE'))), 'BE'), SECP256K1_N)), t <= 0n || t >= SECP256K1_N)) throw new Error('Invalid nonce')
2442
2570
  const r = mod(n, SECP256K1_N),
2443
- i = doubleAndAdd(SECP256K1_X, SECP256K1_Y, t, SECP256K1_P),
2571
+ i = doubleAndAdd(SECP256K1_X, SECP256K1_Y, t),
2444
2572
  o = mod(i[0], SECP256K1_N)
2445
2573
  let c = mod((r + mod(o, SECP256K1_N) * e) * modInverse(t, SECP256K1_N), SECP256K1_N)
2446
2574
  if (o === 0n || c === 0n) throw new Error('Invalid r or s value')
2447
- let u = i[1] % 2n === 0n ? 27n : 28n
2448
- return c > SECP256K1_N / 2n && ((c = SECP256K1_N - c), (u = u === 27n ? 28n : 27n)), [o, c, u]
2575
+ let s = i[1] % 2n === 0n ? 27n : 28n
2576
+ return c > SECP256K1_N / 2n && ((c = SECP256K1_N - c), (s = s === 27n ? 28n : 27n)), [o, c, s]
2449
2577
  }
2450
2578
  function recoverPublicKey(n, e, t, r) {
2451
2579
  const i = modSqrt(mod(e ** 3n + 7n, SECP256K1_P), SECP256K1_P)
2452
2580
  if (!i) throw new Error('Invalid r: does not correspond to a valid curve point')
2453
2581
  const o = r === 27n ? 0n : 1n,
2454
2582
  c = i % 2n === o ? i : SECP256K1_P - i,
2455
- u = mod(uint256ToNumber(keccak256(n), 'BE'), SECP256K1_N),
2456
- s = doubleAndAdd(e, c, t, SECP256K1_P),
2457
- f = doubleAndAdd(SECP256K1_X, SECP256K1_Y, u, SECP256K1_P),
2458
- l = ellipticAdd(s[0], s[1], f[0], mod(-f[1], SECP256K1_P), SECP256K1_P)
2459
- return doubleAndAdd(l[0], l[1], modInverse(e, SECP256K1_N), SECP256K1_P)
2583
+ s = mod(uint256ToNumber(keccak256(n), 'BE'), SECP256K1_N),
2584
+ u = doubleAndAdd(e, c, t),
2585
+ f = doubleAndAdd(SECP256K1_X, SECP256K1_Y, s),
2586
+ l = ellipticAdd(u[0], u[1], f[0], mod(-f[1], SECP256K1_P), SECP256K1_P)
2587
+ return doubleAndAdd(l[0], l[1], modInverse(e, SECP256K1_N))
2460
2588
  }
2461
2589
  function verifySignature(n, e, t, r) {
2462
2590
  const i = mod(uint256ToNumber(keccak256(n), 'BE'), SECP256K1_N),
2463
2591
  o = modInverse(r, SECP256K1_N),
2464
2592
  c = mod(i * o, SECP256K1_N),
2465
- u = mod(t * o, SECP256K1_N),
2466
- s = doubleAndAdd(SECP256K1_X, SECP256K1_Y, c, SECP256K1_P),
2467
- f = doubleAndAdd(e[0], e[1], u, SECP256K1_P),
2468
- l = ellipticAdd(s[0], s[1], f[0], f[1], SECP256K1_P)
2593
+ s = mod(t * o, SECP256K1_N),
2594
+ u = doubleAndAdd(SECP256K1_X, SECP256K1_Y, c),
2595
+ f = doubleAndAdd(e[0], e[1], s),
2596
+ l = ellipticAdd(u[0], u[1], f[0], f[1], SECP256K1_P)
2469
2597
  return t === mod(l[0], SECP256K1_N)
2470
2598
  }
2471
2599
  class Uint8ArrayReader {
@@ -2551,7 +2679,14 @@ class ChunkSplitter {
2551
2679
  this.chunks[e] = new Chunk()
2552
2680
  }
2553
2681
  async finalize(e = 0) {
2554
- return this.chunks[e + 1] ? (this.counters[e] === 1 ? (await this.elevate(e + 1), (this.chunks[e + 1] = this.chunks[e]), this.finalize(e + 1)) : (await this.elevate(e), this.finalize(e + 1))) : (await this.onChunk(this.chunks[e]), this.chunks[e])
2682
+ if (!this.chunks[e + 1]) {
2683
+ if (this.encrypted) {
2684
+ const { key: t } = this.chunks[e].encryptedHash()
2685
+ await this.onChunk(this.chunks[e], t)
2686
+ } else await this.onChunk(this.chunks[e])
2687
+ return this.chunks[e]
2688
+ }
2689
+ return this.counters[e] === 1 ? (await this.elevate(e + 1), (this.chunks[e + 1] = this.chunks[e]), this.finalize(e + 1)) : (await this.elevate(e), this.finalize(e + 1))
2555
2690
  }
2556
2691
  }
2557
2692
  ;(exports.ChunkSplitter = ChunkSplitter), (_a = ChunkSplitter), (ChunkSplitter.NOOP = async (n, e) => {})
@@ -2591,10 +2726,10 @@ class ChunkJoiner {
2591
2726
  if ((this.encrypted && t ? ({ span: i, data: o } = decryptChunk(r, t)) : ((i = uint64ToNumber(r.subarray(0, 8), 'LE')), (o = r.subarray(8, 4104))), i <= 4096n)) await this.onData(o.subarray(0, Number(i)))
2592
2727
  else
2593
2728
  for (let c = 0; c < 4096 / this.refSize; c++) {
2594
- const u = o.subarray(c * this.refSize, (c + 1) * this.refSize),
2595
- s = u.subarray(0, 32)
2596
- if (isAllZero(s)) break
2597
- await this.join(s, this.encrypted ? u.subarray(32, 64) : void 0)
2729
+ const s = o.subarray(c * this.refSize, (c + 1) * this.refSize),
2730
+ u = s.subarray(0, 32)
2731
+ if (isAllZero(u)) break
2732
+ await this.join(u, this.encrypted ? s.subarray(32, 64) : void 0)
2598
2733
  }
2599
2734
  }
2600
2735
  }
@@ -2673,7 +2808,7 @@ function tickPlaybook(n) {
2673
2808
  return e.ttlMax ? --e.ttl <= 0 && n.shift() : (e.ttlMax = e.ttl), { progress: (e.ttlMax - e.ttl) / e.ttlMax, data: e.data }
2674
2809
  }
2675
2810
  function getArgument(n, e, t, r) {
2676
- const i = n.findIndex(u => u === `--${e}` || u.startsWith(`--${e}=`)),
2811
+ const i = n.findIndex(s => s === `--${e}` || s.startsWith(`--${e}=`)),
2677
2812
  o = n[i]
2678
2813
  if (!o) return (t || {})[r || e || ''] || null
2679
2814
  if (o.includes('=')) return o.split('=')[1]
@@ -2690,14 +2825,14 @@ function getNumberArgument(n, e, t, r) {
2690
2825
  }
2691
2826
  }
2692
2827
  function getBooleanArgument(n, e, t, r) {
2693
- const i = n.some(s => s.endsWith('-' + e)),
2828
+ const i = n.some(u => u.endsWith('-' + e)),
2694
2829
  o = getArgument(n, e, t, r)
2695
2830
  if (!o && i) return !0
2696
2831
  if (!o && !i) return null
2697
2832
  const c = ['true', '1', 'yes', 'y', 'on'],
2698
- u = ['false', '0', 'no', 'n', 'off']
2833
+ s = ['false', '0', 'no', 'n', 'off']
2699
2834
  if (c.includes(o.toLowerCase())) return !0
2700
- if (u.includes(o.toLowerCase())) return !1
2835
+ if (s.includes(o.toLowerCase())) return !1
2701
2836
  throw Error(`Invalid boolean argument ${e}: ${o}`)
2702
2837
  }
2703
2838
  function requireStringArgument(n, e, t, r) {
@@ -2777,20 +2912,20 @@ function findCorners(n, e, t, r) {
2777
2912
  ]
2778
2913
  for (let o = 0; o < n.length; o++)
2779
2914
  for (let c = 0; c < n[0].length; c++) {
2780
- const u = getCorners(n, o, c)
2781
- for (const s of u) i.some(f => f.x === s.x && f.y === s.y) || i.push(s)
2915
+ const s = getCorners(n, o, c)
2916
+ for (const u of s) i.some(f => f.x === u.x && f.y === u.y) || i.push(u)
2782
2917
  }
2783
2918
  return i.map(o => ({ x: o.x * e, y: o.y * e }))
2784
2919
  }
2785
2920
  function findLines(n, e) {
2786
- const t = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s][f + 1] !== 0, 'row-first').map(s => ({ ...s, dx: 1, dy: 0 })),
2787
- r = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s][f - 1] !== 0, 'row-first').map(s => ({ ...s, dx: 1, dy: 0 })),
2788
- i = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s - 1]?.[f] !== 0, 'column-first').map(s => ({ ...s, dx: 0, dy: 1 })),
2789
- o = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s + 1]?.[f] !== 0, 'column-first').map(s => ({ ...s, dx: 0, dy: 1 }))
2790
- t.forEach(s => s.y++), o.forEach(s => s.x++)
2791
- const c = group([...i, ...o], (s, f) => s.x === f.x && s.y - 1 === f.y),
2792
- u = group([...r, ...t], (s, f) => s.y === f.y && s.x - 1 === f.x)
2793
- return [...c, ...u].map(s => ({ start: s[0], end: last(s) })).map(s => ({ start: multiplyPoint(s.start, e), end: multiplyPoint(addPoint(s.end, { x: s.start.dx, y: s.start.dy }), e) }))
2921
+ const t = filterCoordinates(n, (u, f) => n[u][f] === 0 && n[u][f + 1] !== 0, 'row-first').map(u => ({ ...u, dx: 1, dy: 0 })),
2922
+ r = filterCoordinates(n, (u, f) => n[u][f] === 0 && n[u][f - 1] !== 0, 'row-first').map(u => ({ ...u, dx: 1, dy: 0 })),
2923
+ i = filterCoordinates(n, (u, f) => n[u][f] === 0 && n[u - 1]?.[f] !== 0, 'column-first').map(u => ({ ...u, dx: 0, dy: 1 })),
2924
+ o = filterCoordinates(n, (u, f) => n[u][f] === 0 && n[u + 1]?.[f] !== 0, 'column-first').map(u => ({ ...u, dx: 0, dy: 1 }))
2925
+ t.forEach(u => u.y++), o.forEach(u => u.x++)
2926
+ const c = group([...i, ...o], (u, f) => u.x === f.x && u.y - 1 === f.y),
2927
+ s = group([...r, ...t], (u, f) => u.y === f.y && u.x - 1 === f.x)
2928
+ return [...c, ...s].map(u => ({ start: u[0], end: last(u) })).map(u => ({ start: multiplyPoint(u.start, e), end: multiplyPoint(addPoint(u.end, { x: u.start.dx, y: u.start.dy }), e) }))
2794
2929
  }
2795
2930
  function getAngleInRadians(n, e) {
2796
2931
  return Math.atan2(e.y - n.y, e.x - n.x)
@@ -2803,9 +2938,9 @@ function getLineIntersectionPoint(n, e, t, r) {
2803
2938
  if (i === 0) return null
2804
2939
  let o = n.y - t.y,
2805
2940
  c = n.x - t.x
2806
- const u = (r.x - t.x) * o - (r.y - t.y) * c,
2807
- s = (e.x - n.x) * o - (e.y - n.y) * c
2808
- return (o = u / i), (c = s / i), o > 0 && o < 1 && c > 0 && c < 1 ? { x: n.x + o * (e.x - n.x), y: n.y + o * (e.y - n.y) } : null
2941
+ const s = (r.x - t.x) * o - (r.y - t.y) * c,
2942
+ u = (e.x - n.x) * o - (e.y - n.y) * c
2943
+ return (o = s / i), (c = u / i), o > 0 && o < 1 && c > 0 && c < 1 ? { x: n.x + o * (e.x - n.x), y: n.y + o * (e.y - n.y) } : null
2809
2944
  }
2810
2945
  function raycast(n, e, t) {
2811
2946
  const r = [],
@@ -2816,9 +2951,9 @@ function raycast(n, e, t) {
2816
2951
  }
2817
2952
  return r.length
2818
2953
  ? r.reduce((o, c) => {
2819
- const u = getDistanceBetweenPoints(n, c),
2820
- s = getDistanceBetweenPoints(n, o)
2821
- return u < s ? c : o
2954
+ const s = getDistanceBetweenPoints(n, c),
2955
+ u = getDistanceBetweenPoints(n, o)
2956
+ return s < u ? c : o
2822
2957
  })
2823
2958
  : null
2824
2959
  }
@@ -2826,9 +2961,9 @@ function raycastCircle(n, e, t) {
2826
2961
  const i = getSortedRayAngles(n, t),
2827
2962
  o = []
2828
2963
  for (const c of i) {
2829
- const u = raycast(n, e, c - 0.001),
2830
- s = raycast(n, e, c + 0.001)
2831
- u && o.push(u), s && o.push(s)
2964
+ const s = raycast(n, e, c - 0.001),
2965
+ u = raycast(n, e, c + 0.001)
2966
+ s && o.push(s), u && o.push(u)
2832
2967
  }
2833
2968
  return o
2834
2969
  }
@@ -2911,10 +3046,10 @@ class TrieRouter {
2911
3046
  const o = e[0],
2912
3047
  c = this.forks.get(o)
2913
3048
  if (c) return c.handle(e.slice(1), t, r, i)
2914
- const u = this.forks.get(':')
2915
- if (u) return u.variableName && i.set(u.variableName, decodeURIComponent(o)), u.handle(e.slice(1), t, r, i)
2916
- const s = this.forks.get('*')
2917
- return s ? (i.set('wildcard', e.join('/')), s.handler ? (await s.handler(t, r, i), !0) : !1) : !1
3049
+ const s = this.forks.get(':')
3050
+ if (s) return s.variableName && i.set(s.variableName, decodeURIComponent(o)), s.handle(e.slice(1), t, r, i)
3051
+ const u = this.forks.get('*')
3052
+ return u ? (i.set('wildcard', e.join('/')), u.handler ? (await u.handler(t, r, i), !0) : !1) : !1
2918
3053
  }
2919
3054
  }
2920
3055
  exports.TrieRouter = TrieRouter
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "35.0.0",
3
+ "version": "35.0.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {