cafe-utility 33.5.0 → 33.6.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.
- package/index.d.ts +15 -0
- package/index.js +154 -137
- package/module.mjs +1 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -788,6 +788,21 @@ export declare class Solver {
|
|
|
788
788
|
addStep(step: SolverStep): void
|
|
789
789
|
execute(): Promise<Map<string, unknown>>
|
|
790
790
|
}
|
|
791
|
+
interface LockOptions {
|
|
792
|
+
queryFunction: () => Promise<string>
|
|
793
|
+
lockFunction: (storable: string) => Promise<void>
|
|
794
|
+
unlockFunction: () => Promise<void>
|
|
795
|
+
timeoutMillis: number
|
|
796
|
+
}
|
|
797
|
+
export declare class Lock {
|
|
798
|
+
private queryFunction
|
|
799
|
+
private lockFunction
|
|
800
|
+
private unlockFunction
|
|
801
|
+
private timeoutMillis
|
|
802
|
+
constructor(options: LockOptions)
|
|
803
|
+
couldLock(): Promise<true | Date>
|
|
804
|
+
unlock(): Promise<void>
|
|
805
|
+
}
|
|
791
806
|
export declare const Binary: {
|
|
792
807
|
hexToUint8Array: typeof hexToUint8Array
|
|
793
808
|
uint8ArrayToHex: typeof uint8ArrayToHex
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
var _a
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: !0 }), (exports.Vector = exports.Cache = exports.Assertions = exports.Strings = exports.Types = exports.Objects = exports.Dates = exports.Promises = exports.Numbers = exports.System = exports.Arrays = exports.Random = exports.Elliptic = exports.Binary = exports.Solver = exports.RollingValueProvider = exports.TrieRouter = exports.AsyncQueue = exports.PubSubChannel = exports.FixedPointNumber = exports.MerkleTree = exports.Chunk = exports.Uint8ArrayWriter = exports.Uint8ArrayReader = exports.AsyncLazy = exports.Lazy = exports.Optional = void 0)
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: !0 }), (exports.Vector = exports.Cache = exports.Assertions = exports.Strings = exports.Types = exports.Objects = exports.Dates = exports.Promises = exports.Numbers = exports.System = exports.Arrays = exports.Random = exports.Elliptic = exports.Binary = exports.Lock = exports.Solver = exports.RollingValueProvider = exports.TrieRouter = exports.AsyncQueue = exports.PubSubChannel = exports.FixedPointNumber = exports.MerkleTree = exports.Chunk = exports.Uint8ArrayWriter = exports.Uint8ArrayReader = exports.AsyncLazy = exports.Lazy = exports.Optional = void 0)
|
|
4
4
|
async function invertPromise(n) {
|
|
5
5
|
return new Promise((e, t) => n.then(t, e))
|
|
6
6
|
}
|
|
@@ -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 u = n.filter(
|
|
131
|
-
|
|
132
|
-
for (e !== null &&
|
|
133
|
-
const
|
|
134
|
-
i(u[
|
|
130
|
+
const u = n.filter(c => c !== e && c !== t),
|
|
131
|
+
s = []
|
|
132
|
+
for (e !== null && s.push(e); u.length && s.length < r; ) {
|
|
133
|
+
const c = exports.Random.intBetween(0, u.length - 1, o)
|
|
134
|
+
i(u[c], s) && s.push(u[c]), u.splice(c, 1)
|
|
135
135
|
}
|
|
136
|
-
return shuffle(
|
|
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 u = r[o],
|
|
176
|
-
|
|
176
|
+
s = o < r.length - 1 && r[o + 1].includes(']'),
|
|
177
177
|
f = u.includes(']') ? u.replace(/\[|\]/g, '') : u
|
|
178
178
|
if (o === r.length - 1) return (i[f] = t), t
|
|
179
|
-
isObject(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 u = null
|
|
236
|
-
for (let
|
|
236
|
+
for (let s = 0; s <= e; s++)
|
|
237
237
|
try {
|
|
238
238
|
return await n()
|
|
239
|
-
} catch (
|
|
240
|
-
if (((u =
|
|
241
|
-
const f = t + (r - t) * (
|
|
242
|
-
i && i('Error in withRetries, retrying', { attempt:
|
|
239
|
+
} catch (c) {
|
|
240
|
+
if (((u = c), 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: c }), o && o(), await sleepMillis(f)
|
|
243
243
|
}
|
|
244
244
|
throw u
|
|
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
|
u = (t * Math.PI) / 180,
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
f = Math.sin(
|
|
263
|
+
s = ((t - n) * Math.PI) / 180,
|
|
264
|
+
c = ((r - e) * Math.PI) / 180,
|
|
265
|
+
f = Math.sin(s / 2) * Math.sin(s / 2) + Math.cos(o) * Math.cos(u) * Math.sin(c / 2) * Math.sin(c / 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
|
u = (t() + t() + t() + t() + t() + t() - 3) * Math.SQRT2,
|
|
286
|
-
|
|
287
|
-
return Math.max(0, Math.min(n,
|
|
286
|
+
s = Math.round(r + i * u)
|
|
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
|
|
302
|
-
|
|
303
|
-
return `${t}.${r.slice(0,
|
|
301
|
+
const s = r.match(/^0*/)?.[0].length ?? 0,
|
|
302
|
+
c = e + s
|
|
303
|
+
return `${t}.${r.slice(0, c)}`
|
|
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 == '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 u = []
|
|
787
|
-
for (const
|
|
788
|
-
const
|
|
789
|
-
u = u.concat(
|
|
787
|
+
for (const s of r) {
|
|
788
|
+
const c = expand(i + s + o)
|
|
789
|
+
u = u.concat(c)
|
|
790
790
|
}
|
|
791
791
|
return u
|
|
792
792
|
}
|
|
@@ -1032,11 +1032,11 @@ function baseToUint8Array(n, e) {
|
|
|
1032
1032
|
let i = 0,
|
|
1033
1033
|
o = 0
|
|
1034
1034
|
const u = []
|
|
1035
|
-
for (let
|
|
1036
|
-
const
|
|
1037
|
-
if (
|
|
1038
|
-
const f = e.indexOf(
|
|
1039
|
-
if (f === -1) throw new Error(`Invalid character: ${
|
|
1035
|
+
for (let s = 0; s < n.length; s++) {
|
|
1036
|
+
const c = n[s]
|
|
1037
|
+
if (c === t) break
|
|
1038
|
+
const f = e.indexOf(c)
|
|
1039
|
+
if (f === -1) throw new Error(`Invalid character: ${c}`)
|
|
1040
1040
|
;(o = (o << Math.log2(r)) | f), (i += Math.log2(r)), i >= 8 && ((i -= 8), u.push((o >> i) & 255))
|
|
1041
1041
|
}
|
|
1042
1042
|
return new Uint8Array(u)
|
|
@@ -1099,7 +1099,7 @@ function generateVariants(n, e, t, r = Math.random) {
|
|
|
1099
1099
|
const i = exports.Arrays.shuffle(
|
|
1100
1100
|
e.map(u => ({
|
|
1101
1101
|
variants: exports.Arrays.shuffle(
|
|
1102
|
-
u.variants.map(
|
|
1102
|
+
u.variants.map(s => s),
|
|
1103
1103
|
r
|
|
1104
1104
|
),
|
|
1105
1105
|
avoid: u.avoid
|
|
@@ -1108,14 +1108,14 @@ function generateVariants(n, e, t, r = Math.random) {
|
|
|
1108
1108
|
),
|
|
1109
1109
|
o = []
|
|
1110
1110
|
for (const u of i) {
|
|
1111
|
-
const
|
|
1112
|
-
|
|
1113
|
-
if (
|
|
1111
|
+
const s = u.variants.filter(f => f !== u.avoid),
|
|
1112
|
+
c = s.find(f => n.includes(f))
|
|
1113
|
+
if (c && (pushAll(o, explodeReplace(n, c, s)), o.length >= t)) break
|
|
1114
1114
|
}
|
|
1115
1115
|
if (o.length < t)
|
|
1116
1116
|
for (const u of i) {
|
|
1117
|
-
const
|
|
1118
|
-
if (
|
|
1117
|
+
const s = u.variants.find(c => n.includes(c))
|
|
1118
|
+
if (s && (pushAll(o, explodeReplace(n, s, u.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 u = 0; u < n.length; u++) {
|
|
1148
|
-
const
|
|
1149
|
-
|
|
1150
|
-
if (((i +=
|
|
1148
|
+
const s = n[u],
|
|
1149
|
+
c = t[s] || 1
|
|
1150
|
+
if (((i += s), (o += c), 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
|
|
1227
|
-
n = n.replace(`${r}${e}${i}${
|
|
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, u] = n.slice(r + 1, i).split(']('),
|
|
1255
|
-
|
|
1256
|
-
n = n.slice(0, r) +
|
|
1255
|
+
s = e(o, u)
|
|
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(u => u[e] === t),
|
|
1292
1292
|
o = n.find(u => u[e] === t + r)
|
|
1293
|
-
i && o ? ((i[e] = t + r), (o[e] = t)) : i && (i[e] = t + r), n.sort((u,
|
|
1293
|
+
i && o ? ((i[e] = t + r), (o[e] = t)) : i && (i[e] = t + r), n.sort((u, s) => asNumber(u[e]) - asNumber(s[e])), n.forEach((u, s) => (u[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 u = n.split('')
|
|
1321
|
-
for (const
|
|
1321
|
+
for (const s of u) 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
|
u = o / e,
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
return { deltaMs: o, progress: i, baseTimeMs: u, totalTimeMs:
|
|
1427
|
+
s = u * t,
|
|
1428
|
+
c = s - o
|
|
1429
|
+
return { deltaMs: o, progress: i, baseTimeMs: u, totalTimeMs: s, remainingTimeMs: c }
|
|
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) {
|
|
@@ -1578,9 +1578,9 @@ function organiseWithLimits(n, e, t, r, i) {
|
|
|
1578
1578
|
for (const u of Object.keys(e)) o[u] = []
|
|
1579
1579
|
;(o[r] = []), i && (n = n.sort(i))
|
|
1580
1580
|
for (const u of n) {
|
|
1581
|
-
const
|
|
1582
|
-
|
|
1583
|
-
o[
|
|
1581
|
+
const s = u[t],
|
|
1582
|
+
c = e[s] ? s : r
|
|
1583
|
+
o[c].length >= e[c] ? o[r].push(u) : o[c].push(u)
|
|
1584
1584
|
}
|
|
1585
1585
|
return o
|
|
1586
1586
|
}
|
|
@@ -1717,20 +1717,20 @@ function flip(n) {
|
|
|
1717
1717
|
}
|
|
1718
1718
|
function getAllPermutations(n) {
|
|
1719
1719
|
const e = Object.keys(n),
|
|
1720
|
-
t = e.map(
|
|
1721
|
-
r = t.reduce((
|
|
1720
|
+
t = e.map(s => n[s].length),
|
|
1721
|
+
r = t.reduce((s, c) => (s *= c))
|
|
1722
1722
|
let i = 1
|
|
1723
1723
|
const o = [1]
|
|
1724
|
-
for (let
|
|
1724
|
+
for (let s = 0; s < t.length - 1; s++) (i *= t[s]), o.push(i)
|
|
1725
1725
|
const u = []
|
|
1726
|
-
for (let
|
|
1727
|
-
const
|
|
1726
|
+
for (let s = 0; s < r; s++) {
|
|
1727
|
+
const c = {}
|
|
1728
1728
|
for (let f = 0; f < e.length; f++) {
|
|
1729
1729
|
const l = n[e[f]],
|
|
1730
|
-
a = Math.floor(
|
|
1731
|
-
|
|
1730
|
+
a = Math.floor(s / o[f]) % l.length
|
|
1731
|
+
c[e[f]] = l[a]
|
|
1732
1732
|
}
|
|
1733
|
-
u.push(
|
|
1733
|
+
u.push(c)
|
|
1734
1734
|
}
|
|
1735
1735
|
return u
|
|
1736
1736
|
}
|
|
@@ -1743,8 +1743,8 @@ function getFlatNotation(n, e, t) {
|
|
|
1743
1743
|
function flattenInner(n, e, t, r, i) {
|
|
1744
1744
|
if (!isObject(e)) return e
|
|
1745
1745
|
for (const [o, u] of Object.entries(e)) {
|
|
1746
|
-
const
|
|
1747
|
-
Array.isArray(u) ? (i ? flattenInner(n, u,
|
|
1746
|
+
const s = getFlatNotation(t, o, r)
|
|
1747
|
+
Array.isArray(u) ? (i ? flattenInner(n, u, s, !0, i) : (n[s] = u.map(c => flattenInner(Array.isArray(c) ? [] : {}, c, '', !1, i)))) : isObject(u) ? flattenInner(n, u, s, !1, i) : (n[s] = u)
|
|
1748
1748
|
}
|
|
1749
1749
|
return n
|
|
1750
1750
|
}
|
|
@@ -1810,9 +1810,9 @@ function makeUnique(n, e) {
|
|
|
1810
1810
|
function countUnique(n, e, t, r, i) {
|
|
1811
1811
|
const o = e ? n.map(e) : n,
|
|
1812
1812
|
u = {}
|
|
1813
|
-
for (const
|
|
1814
|
-
const
|
|
1815
|
-
return t ? Object.keys(
|
|
1813
|
+
for (const c of o) u[c] = (u[c] || 0) + 1
|
|
1814
|
+
const s = r ? sortObjectValues(u, i ? (c, f) => c[1] - f[1] : (c, f) => f[1] - c[1]) : u
|
|
1815
|
+
return t ? Object.keys(s) : s
|
|
1816
1816
|
}
|
|
1817
1817
|
function sortObjectValues(n, e) {
|
|
1818
1818
|
return Object.fromEntries(Object.entries(n).sort(e))
|
|
@@ -1965,28 +1965,28 @@ class Node {
|
|
|
1965
1965
|
function createHierarchy(n, e, t, r, i = !1) {
|
|
1966
1966
|
const o = new Map(),
|
|
1967
1967
|
u = []
|
|
1968
|
-
n.forEach(
|
|
1969
|
-
const f = new Node(
|
|
1970
|
-
o.set(
|
|
1968
|
+
n.forEach(c => {
|
|
1969
|
+
const f = new Node(c)
|
|
1970
|
+
o.set(c[e], f)
|
|
1971
1971
|
}),
|
|
1972
|
-
n.forEach(
|
|
1973
|
-
const f = o.get(
|
|
1972
|
+
n.forEach(c => {
|
|
1973
|
+
const f = o.get(c[e])
|
|
1974
1974
|
if (!f) return
|
|
1975
|
-
const l =
|
|
1975
|
+
const l = c[t]
|
|
1976
1976
|
if (l) {
|
|
1977
1977
|
const a = o.get(l)
|
|
1978
1978
|
a && a.children.push(f)
|
|
1979
1979
|
} else u.push(f)
|
|
1980
1980
|
})
|
|
1981
|
-
const
|
|
1982
|
-
|
|
1981
|
+
const s = c => {
|
|
1982
|
+
c.children.sort((f, l) => {
|
|
1983
1983
|
const a = f.value[r],
|
|
1984
1984
|
h = l.value[r]
|
|
1985
1985
|
return i ? h - a : a - h
|
|
1986
1986
|
}),
|
|
1987
|
-
|
|
1987
|
+
c.children.forEach(s)
|
|
1988
1988
|
}
|
|
1989
|
-
return u.forEach(
|
|
1989
|
+
return u.forEach(s), u
|
|
1990
1990
|
}
|
|
1991
1991
|
function log2Reduce(n, e) {
|
|
1992
1992
|
if (Math.log2(n.length) % 1 !== 0) throw new Error('Array length must be a power of 2')
|
|
@@ -2089,8 +2089,8 @@ function keccakPermutate(n) {
|
|
|
2089
2089
|
i = n[2] ^ n[12] ^ n[22] ^ n[32] ^ n[42],
|
|
2090
2090
|
o = n[3] ^ n[13] ^ n[23] ^ n[33] ^ n[43],
|
|
2091
2091
|
u = n[4] ^ n[14] ^ n[24] ^ n[34] ^ n[44],
|
|
2092
|
-
|
|
2093
|
-
|
|
2092
|
+
s = n[5] ^ n[15] ^ n[25] ^ n[35] ^ n[45],
|
|
2093
|
+
c = n[6] ^ n[16] ^ n[26] ^ n[36] ^ n[46],
|
|
2094
2094
|
f = n[7] ^ n[17] ^ n[27] ^ n[37] ^ n[47],
|
|
2095
2095
|
l = n[8] ^ n[18] ^ n[28] ^ n[38] ^ n[48],
|
|
2096
2096
|
a = n[9] ^ n[19] ^ n[29] ^ n[39] ^ n[49],
|
|
@@ -2098,28 +2098,28 @@ function keccakPermutate(n) {
|
|
|
2098
2098
|
bn = (o << 1) | (i >>> 31),
|
|
2099
2099
|
d = l ^ h,
|
|
2100
2100
|
p = a ^ bn,
|
|
2101
|
-
$n = (u << 1) | (
|
|
2102
|
-
En = (
|
|
2101
|
+
$n = (u << 1) | (s >>> 31),
|
|
2102
|
+
En = (s << 1) | (u >>> 31),
|
|
2103
2103
|
m = t ^ $n,
|
|
2104
2104
|
g = r ^ En,
|
|
2105
|
-
An = (
|
|
2106
|
-
Mn = (f << 1) | (
|
|
2105
|
+
An = (c << 1) | (f >>> 31),
|
|
2106
|
+
Mn = (f << 1) | (c >>> 31),
|
|
2107
2107
|
w = i ^ An,
|
|
2108
2108
|
x = o ^ Mn,
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
y = u ^
|
|
2112
|
-
b =
|
|
2113
|
-
|
|
2109
|
+
kn = (l << 1) | (a >>> 31),
|
|
2110
|
+
On = (a << 1) | (l >>> 31),
|
|
2111
|
+
y = u ^ kn,
|
|
2112
|
+
b = s ^ On,
|
|
2113
|
+
Sn = (t << 1) | (r >>> 31),
|
|
2114
2114
|
Tn = (r << 1) | (t >>> 31),
|
|
2115
|
-
$ =
|
|
2115
|
+
$ = c ^ Sn,
|
|
2116
2116
|
E = f ^ Tn
|
|
2117
2117
|
;(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] ^= E), (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] ^= E), (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] ^= E), (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] ^= E), (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] ^= E)
|
|
2118
2118
|
const A = n[0],
|
|
2119
2119
|
M = n[1],
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2120
|
+
k = (n[2] << 1) | (n[3] >>> 31),
|
|
2121
|
+
O = (n[3] << 1) | (n[2] >>> 31),
|
|
2122
|
+
S = (n[5] << 30) | (n[4] >>> 2),
|
|
2123
2123
|
T = (n[4] << 30) | (n[5] >>> 2),
|
|
2124
2124
|
C = (n[6] << 28) | (n[7] >>> 4),
|
|
2125
2125
|
R = (n[7] << 28) | (n[6] >>> 4),
|
|
@@ -2128,14 +2128,14 @@ function keccakPermutate(n) {
|
|
|
2128
2128
|
P = (n[11] << 4) | (n[10] >>> 28),
|
|
2129
2129
|
B = (n[10] << 4) | (n[11] >>> 28),
|
|
2130
2130
|
v = (n[13] << 12) | (n[12] >>> 20),
|
|
2131
|
-
|
|
2132
|
-
|
|
2131
|
+
L = (n[12] << 12) | (n[13] >>> 20),
|
|
2132
|
+
U = (n[14] << 6) | (n[15] >>> 26),
|
|
2133
2133
|
N = (n[15] << 6) | (n[14] >>> 26),
|
|
2134
2134
|
j = (n[17] << 23) | (n[16] >>> 9),
|
|
2135
2135
|
F = (n[16] << 23) | (n[17] >>> 9),
|
|
2136
2136
|
z = (n[18] << 20) | (n[19] >>> 12),
|
|
2137
|
-
|
|
2138
|
-
|
|
2137
|
+
q = (n[19] << 20) | (n[18] >>> 12),
|
|
2138
|
+
W = (n[20] << 3) | (n[21] >>> 29),
|
|
2139
2139
|
H = (n[21] << 3) | (n[20] >>> 29),
|
|
2140
2140
|
V = (n[22] << 10) | (n[23] >>> 22),
|
|
2141
2141
|
J = (n[23] << 10) | (n[22] >>> 22),
|
|
@@ -2152,8 +2152,8 @@ function keccakPermutate(n) {
|
|
|
2152
2152
|
rn = (n[34] << 15) | (n[35] >>> 17),
|
|
2153
2153
|
on = (n[35] << 15) | (n[34] >>> 17),
|
|
2154
2154
|
un = (n[36] << 21) | (n[37] >>> 11),
|
|
2155
|
-
|
|
2156
|
-
|
|
2155
|
+
cn = (n[37] << 21) | (n[36] >>> 11),
|
|
2156
|
+
sn = (n[38] << 8) | (n[39] >>> 24),
|
|
2157
2157
|
fn = (n[39] << 8) | (n[38] >>> 24),
|
|
2158
2158
|
ln = (n[40] << 18) | (n[41] >>> 14),
|
|
2159
2159
|
an = (n[41] << 18) | (n[40] >>> 14),
|
|
@@ -2165,7 +2165,7 @@ function keccakPermutate(n) {
|
|
|
2165
2165
|
wn = (n[46] << 24) | (n[47] >>> 8),
|
|
2166
2166
|
xn = (n[48] << 14) | (n[49] >>> 18),
|
|
2167
2167
|
yn = (n[49] << 14) | (n[48] >>> 18)
|
|
2168
|
-
;(n[0] = A ^ (~v & K)), (n[1] = M ^ (~
|
|
2168
|
+
;(n[0] = A ^ (~v & K)), (n[1] = M ^ (~L & Z)), (n[2] = v ^ (~K & un)), (n[3] = L ^ (~Z & cn)), (n[4] = K ^ (~un & xn)), (n[5] = Z ^ (~cn & yn)), (n[6] = un ^ (~xn & A)), (n[7] = cn ^ (~yn & M)), (n[8] = xn ^ (~A & v)), (n[9] = yn ^ (~M & L)), (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] = k ^ (~U & Q)), (n[21] = O ^ (~N & G)), (n[22] = U ^ (~Q & sn)), (n[23] = N ^ (~G & fn)), (n[24] = Q ^ (~sn & ln)), (n[25] = G ^ (~fn & an)), (n[26] = sn ^ (~ln & k)), (n[27] = fn ^ (~an & O)), (n[28] = ln ^ (~k & U)), (n[29] = an ^ (~O & N)), (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] = S ^ (~j & Y)), (n[41] = T ^ (~F & X)), (n[42] = j ^ (~Y & _)), (n[43] = F ^ (~X & nn)), (n[44] = Y ^ (~_ & hn)), (n[45] = X ^ (~nn & dn)), (n[46] = _ ^ (~hn & S)), (n[47] = nn ^ (~dn & T)), (n[48] = hn ^ (~S & j)), (n[49] = dn ^ (~T & F)), (n[0] ^= IOTA_CONSTANTS[e * 2]), (n[1] ^= IOTA_CONSTANTS[e * 2 + 1])
|
|
2169
2169
|
}
|
|
2170
2170
|
}
|
|
2171
2171
|
function bytesToNumbers(n) {
|
|
@@ -2318,8 +2318,8 @@ function ellipticAdd(n, e, t, r, i) {
|
|
|
2318
2318
|
if (n === t && e === r) return ellipticDouble(n, e, i)
|
|
2319
2319
|
const o = mod((r - e) * modInverse(t - n, i), i),
|
|
2320
2320
|
u = mod(o * o - n - t, i),
|
|
2321
|
-
|
|
2322
|
-
return [u,
|
|
2321
|
+
s = mod(o * (n - u) - e, i)
|
|
2322
|
+
return [u, s]
|
|
2323
2323
|
}
|
|
2324
2324
|
function privateKeyToPublicKey(n) {
|
|
2325
2325
|
if (n <= 0n || n >= SECP256K1_N) throw new Error('Invalid private key')
|
|
@@ -2354,7 +2354,7 @@ function doubleAndAdd(n, e, t, r) {
|
|
|
2354
2354
|
let i = [0n, 0n],
|
|
2355
2355
|
o = [n, e]
|
|
2356
2356
|
const u = t.toString(2)
|
|
2357
|
-
for (const
|
|
2357
|
+
for (const s of u) s === '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)))
|
|
2358
2358
|
return i
|
|
2359
2359
|
}
|
|
2360
2360
|
function signMessage(n, e, t) {
|
|
@@ -2368,28 +2368,28 @@ function signHash(n, e, t) {
|
|
|
2368
2368
|
o = mod(i[0], SECP256K1_N)
|
|
2369
2369
|
let u = mod((r + mod(o, SECP256K1_N) * e) * modInverse(t, SECP256K1_N), SECP256K1_N)
|
|
2370
2370
|
if (o === 0n || u === 0n) throw new Error('Invalid r or s value')
|
|
2371
|
-
let
|
|
2372
|
-
return u > SECP256K1_N / 2n && ((u = SECP256K1_N - u), (
|
|
2371
|
+
let s = i[1] % 2n === 0n ? 27n : 28n
|
|
2372
|
+
return u > SECP256K1_N / 2n && ((u = SECP256K1_N - u), (s = s === 27n ? 28n : 27n)), [o, u, s]
|
|
2373
2373
|
}
|
|
2374
2374
|
function recoverPublicKey(n, e, t, r) {
|
|
2375
2375
|
const i = modSqrt(mod(e ** 3n + 7n, SECP256K1_P), SECP256K1_P)
|
|
2376
2376
|
if (!i) throw new Error('Invalid r: does not correspond to a valid curve point')
|
|
2377
2377
|
const o = r === 27n ? 0n : 1n,
|
|
2378
2378
|
u = i % 2n === o ? i : SECP256K1_P - i,
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
f = doubleAndAdd(SECP256K1_X, SECP256K1_Y,
|
|
2382
|
-
l = ellipticAdd(
|
|
2379
|
+
s = mod(uint256ToNumber(keccak256(n), 'BE'), SECP256K1_N),
|
|
2380
|
+
c = doubleAndAdd(e, u, t, SECP256K1_P),
|
|
2381
|
+
f = doubleAndAdd(SECP256K1_X, SECP256K1_Y, s, SECP256K1_P),
|
|
2382
|
+
l = ellipticAdd(c[0], c[1], f[0], mod(-f[1], SECP256K1_P), SECP256K1_P)
|
|
2383
2383
|
return doubleAndAdd(l[0], l[1], modInverse(e, SECP256K1_N), SECP256K1_P)
|
|
2384
2384
|
}
|
|
2385
2385
|
function verifySignature(n, e, t, r) {
|
|
2386
2386
|
const i = mod(uint256ToNumber(keccak256(n), 'BE'), SECP256K1_N),
|
|
2387
2387
|
o = modInverse(r, SECP256K1_N),
|
|
2388
2388
|
u = mod(i * o, SECP256K1_N),
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
f = doubleAndAdd(e[0], e[1],
|
|
2392
|
-
l = ellipticAdd(
|
|
2389
|
+
s = mod(t * o, SECP256K1_N),
|
|
2390
|
+
c = doubleAndAdd(SECP256K1_X, SECP256K1_Y, u, SECP256K1_P),
|
|
2391
|
+
f = doubleAndAdd(e[0], e[1], s, SECP256K1_P),
|
|
2392
|
+
l = ellipticAdd(c[0], c[1], f[0], f[1], SECP256K1_P)
|
|
2393
2393
|
return t === mod(l[0], SECP256K1_N)
|
|
2394
2394
|
}
|
|
2395
2395
|
class Uint8ArrayReader {
|
|
@@ -2523,7 +2523,7 @@ function tickPlaybook(n) {
|
|
|
2523
2523
|
return e.ttlMax ? --e.ttl <= 0 && n.shift() : (e.ttlMax = e.ttl), { progress: (e.ttlMax - e.ttl) / e.ttlMax, data: e.data }
|
|
2524
2524
|
}
|
|
2525
2525
|
function getArgument(n, e, t, r) {
|
|
2526
|
-
const i = n.findIndex(
|
|
2526
|
+
const i = n.findIndex(s => s === `--${e}` || s.startsWith(`--${e}=`)),
|
|
2527
2527
|
o = n[i]
|
|
2528
2528
|
if (!o) return (t || {})[r || e || ''] || null
|
|
2529
2529
|
if (o.includes('=')) return o.split('=')[1]
|
|
@@ -2540,14 +2540,14 @@ function getNumberArgument(n, e, t, r) {
|
|
|
2540
2540
|
}
|
|
2541
2541
|
}
|
|
2542
2542
|
function getBooleanArgument(n, e, t, r) {
|
|
2543
|
-
const i = n.some(
|
|
2543
|
+
const i = n.some(c => c.endsWith('-' + e)),
|
|
2544
2544
|
o = getArgument(n, e, t, r)
|
|
2545
2545
|
if (!o && i) return !0
|
|
2546
2546
|
if (!o && !i) return null
|
|
2547
2547
|
const u = ['true', '1', 'yes', 'y', 'on'],
|
|
2548
|
-
|
|
2548
|
+
s = ['false', '0', 'no', 'n', 'off']
|
|
2549
2549
|
if (u.includes(o.toLowerCase())) return !0
|
|
2550
|
-
if (
|
|
2550
|
+
if (s.includes(o.toLowerCase())) return !1
|
|
2551
2551
|
throw Error(`Invalid boolean argument ${e}: ${o}`)
|
|
2552
2552
|
}
|
|
2553
2553
|
function requireStringArgument(n, e, t, r) {
|
|
@@ -2627,20 +2627,20 @@ function findCorners(n, e, t, r) {
|
|
|
2627
2627
|
]
|
|
2628
2628
|
for (let o = 0; o < n.length; o++)
|
|
2629
2629
|
for (let u = 0; u < n[0].length; u++) {
|
|
2630
|
-
const
|
|
2631
|
-
for (const
|
|
2630
|
+
const s = getCorners(n, o, u)
|
|
2631
|
+
for (const c of s) i.some(f => f.x === c.x && f.y === c.y) || i.push(c)
|
|
2632
2632
|
}
|
|
2633
2633
|
return i.map(o => ({ x: o.x * e, y: o.y * e }))
|
|
2634
2634
|
}
|
|
2635
2635
|
function findLines(n, e) {
|
|
2636
|
-
const t = filterCoordinates(n, (
|
|
2637
|
-
r = filterCoordinates(n, (
|
|
2638
|
-
i = filterCoordinates(n, (
|
|
2639
|
-
o = filterCoordinates(n, (
|
|
2640
|
-
t.forEach(
|
|
2641
|
-
const u = group([...i, ...o], (
|
|
2642
|
-
|
|
2643
|
-
return [...u, ...
|
|
2636
|
+
const t = filterCoordinates(n, (c, f) => n[c][f] === 0 && n[c][f + 1] !== 0, 'row-first').map(c => ({ ...c, dx: 1, dy: 0 })),
|
|
2637
|
+
r = filterCoordinates(n, (c, f) => n[c][f] === 0 && n[c][f - 1] !== 0, 'row-first').map(c => ({ ...c, dx: 1, dy: 0 })),
|
|
2638
|
+
i = filterCoordinates(n, (c, f) => n[c][f] === 0 && n[c - 1]?.[f] !== 0, 'column-first').map(c => ({ ...c, dx: 0, dy: 1 })),
|
|
2639
|
+
o = filterCoordinates(n, (c, f) => n[c][f] === 0 && n[c + 1]?.[f] !== 0, 'column-first').map(c => ({ ...c, dx: 0, dy: 1 }))
|
|
2640
|
+
t.forEach(c => c.y++), o.forEach(c => c.x++)
|
|
2641
|
+
const u = group([...i, ...o], (c, f) => c.x === f.x && c.y - 1 === f.y),
|
|
2642
|
+
s = group([...r, ...t], (c, f) => c.y === f.y && c.x - 1 === f.x)
|
|
2643
|
+
return [...u, ...s].map(c => ({ start: c[0], end: last(c) })).map(c => ({ start: multiplyPoint(c.start, e), end: multiplyPoint(addPoint(c.end, { x: c.start.dx, y: c.start.dy }), e) }))
|
|
2644
2644
|
}
|
|
2645
2645
|
function getAngleInRadians(n, e) {
|
|
2646
2646
|
return Math.atan2(e.y - n.y, e.x - n.x)
|
|
@@ -2653,9 +2653,9 @@ function getLineIntersectionPoint(n, e, t, r) {
|
|
|
2653
2653
|
if (i === 0) return null
|
|
2654
2654
|
let o = n.y - t.y,
|
|
2655
2655
|
u = n.x - t.x
|
|
2656
|
-
const
|
|
2657
|
-
|
|
2658
|
-
return (o =
|
|
2656
|
+
const s = (r.x - t.x) * o - (r.y - t.y) * u,
|
|
2657
|
+
c = (e.x - n.x) * o - (e.y - n.y) * u
|
|
2658
|
+
return (o = s / i), (u = c / i), o > 0 && o < 1 && u > 0 && u < 1 ? { x: n.x + o * (e.x - n.x), y: n.y + o * (e.y - n.y) } : null
|
|
2659
2659
|
}
|
|
2660
2660
|
function raycast(n, e, t) {
|
|
2661
2661
|
const r = [],
|
|
@@ -2666,9 +2666,9 @@ function raycast(n, e, t) {
|
|
|
2666
2666
|
}
|
|
2667
2667
|
return r.length
|
|
2668
2668
|
? r.reduce((o, u) => {
|
|
2669
|
-
const
|
|
2670
|
-
|
|
2671
|
-
return
|
|
2669
|
+
const s = getDistanceBetweenPoints(n, u),
|
|
2670
|
+
c = getDistanceBetweenPoints(n, o)
|
|
2671
|
+
return s < c ? u : o
|
|
2672
2672
|
})
|
|
2673
2673
|
: null
|
|
2674
2674
|
}
|
|
@@ -2676,9 +2676,9 @@ function raycastCircle(n, e, t) {
|
|
|
2676
2676
|
const i = getSortedRayAngles(n, t),
|
|
2677
2677
|
o = []
|
|
2678
2678
|
for (const u of i) {
|
|
2679
|
-
const
|
|
2680
|
-
|
|
2681
|
-
|
|
2679
|
+
const s = raycast(n, e, u - 0.001),
|
|
2680
|
+
c = raycast(n, e, u + 0.001)
|
|
2681
|
+
s && o.push(s), c && o.push(c)
|
|
2682
2682
|
}
|
|
2683
2683
|
return o
|
|
2684
2684
|
}
|
|
@@ -2761,10 +2761,10 @@ class TrieRouter {
|
|
|
2761
2761
|
const o = e[0],
|
|
2762
2762
|
u = this.forks.get(o)
|
|
2763
2763
|
if (u) return u.handle(e.slice(1), t, r, i)
|
|
2764
|
-
const
|
|
2765
|
-
if (
|
|
2766
|
-
const
|
|
2767
|
-
return
|
|
2764
|
+
const s = this.forks.get(':')
|
|
2765
|
+
if (s) return s.variableName && i.set(s.variableName, decodeURIComponent(o)), s.handle(e.slice(1), t, r, i)
|
|
2766
|
+
const c = this.forks.get('*')
|
|
2767
|
+
return c ? (i.set('wildcard', e.join('/')), c.handler ? (await c.handler(t, r, i), !0) : !1) : !1
|
|
2768
2768
|
}
|
|
2769
2769
|
}
|
|
2770
2770
|
exports.TrieRouter = TrieRouter
|
|
@@ -2821,7 +2821,24 @@ class Solver {
|
|
|
2821
2821
|
return (this.status = 'completed'), await this.onStatusChange(this.status), await this.onFinish(), this.context
|
|
2822
2822
|
}
|
|
2823
2823
|
}
|
|
2824
|
-
|
|
2824
|
+
exports.Solver = Solver
|
|
2825
|
+
class Lock {
|
|
2826
|
+
constructor(e) {
|
|
2827
|
+
;(this.queryFunction = e.queryFunction), (this.lockFunction = e.lockFunction), (this.unlockFunction = e.unlockFunction), (this.timeoutMillis = e.timeoutMillis)
|
|
2828
|
+
}
|
|
2829
|
+
async couldLock() {
|
|
2830
|
+
const e = await this.queryFunction()
|
|
2831
|
+
try {
|
|
2832
|
+
const t = asInteger(e)
|
|
2833
|
+
if (Date.now() < t + this.timeoutMillis) return new Date(t + this.timeoutMillis)
|
|
2834
|
+
} catch {}
|
|
2835
|
+
return await this.lockFunction(Date.now().toString()), !0
|
|
2836
|
+
}
|
|
2837
|
+
async unlock() {
|
|
2838
|
+
await this.unlockFunction()
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
;(exports.Lock = Lock),
|
|
2825
2842
|
(exports.Binary = { hexToUint8Array, uint8ArrayToHex, binaryToUint8Array, uint8ArrayToBinary, base64ToUint8Array, uint8ArrayToBase64, base32ToUint8Array, uint8ArrayToBase32, log2Reduce, partition, concatBytes, numberToUint8, uint8ToNumber, numberToUint16, uint16ToNumber, numberToUint32, uint32ToNumber, numberToUint64, uint64ToNumber, numberToUint256, uint256ToNumber, sliceBytes, keccak256, sha3_256, proximity, commonPrefix, setBit, getBit, indexOf: binaryIndexOf, equals: binaryEquals, padStart: binaryPadStart, padStartToMultiple: binaryPadStartToMultiple, padEnd: binaryPadEnd, padEndToMultiple: binaryPadEndToMultiple, xorCypher, isUtf8 }),
|
|
2826
2843
|
(exports.Elliptic = { privateKeyToPublicKey, compressPublicKey, publicKeyFromCompressed, publicKeyToAddress, signMessage, signHash, verifySignature, recoverPublicKey, checksumEncode }),
|
|
2827
2844
|
(exports.Random = { intBetween, floatBetween, chance, signed: signedRandom, makeSeededRng, point: randomPoint, procs }),
|
package/module.mjs
CHANGED