cafe-utility 34.0.0 → 35.0.1
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 +34 -6
- package/index.js +353 -235
- package/module.mjs +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -683,22 +683,50 @@ export declare class Chunk {
|
|
|
683
683
|
static hashFunction: (bytes: Uint8Array) => Uint8Array
|
|
684
684
|
span: bigint
|
|
685
685
|
writer: Uint8ArrayWriter
|
|
686
|
-
constructor(
|
|
686
|
+
constructor(span?: bigint)
|
|
687
687
|
build(): Uint8Array
|
|
688
688
|
hash(): Uint8Array
|
|
689
|
+
encryptedHash(key?: Uint8Array): {
|
|
690
|
+
address: Uint8Array
|
|
691
|
+
key: Uint8Array
|
|
692
|
+
}
|
|
693
|
+
static encryptSpan(key: Uint8Array, spanBytes: Uint8Array): Uint8Array
|
|
694
|
+
static encryptData(key: Uint8Array, data: Uint8Array): Uint8Array
|
|
695
|
+
static decrypt(
|
|
696
|
+
encBytes: Uint8Array,
|
|
697
|
+
key: Uint8Array
|
|
698
|
+
): {
|
|
699
|
+
span: bigint
|
|
700
|
+
data: Uint8Array
|
|
701
|
+
}
|
|
689
702
|
}
|
|
690
|
-
export declare class
|
|
691
|
-
static readonly NOOP: (_: Chunk) => Promise<void>
|
|
692
|
-
private
|
|
703
|
+
export declare class ChunkSplitter {
|
|
704
|
+
static readonly NOOP: (_: Chunk, _key?: Uint8Array) => Promise<void>
|
|
705
|
+
private refSize
|
|
706
|
+
private encrypted
|
|
693
707
|
private chunks
|
|
694
708
|
private counters
|
|
695
709
|
private onChunk
|
|
696
|
-
constructor(onChunk: (chunk: Chunk) => Promise<void>,
|
|
697
|
-
static root(data: Uint8Array
|
|
710
|
+
constructor(onChunk: (chunk: Chunk, key?: Uint8Array) => Promise<void>, encrypted?: boolean)
|
|
711
|
+
static root(data: Uint8Array): Promise<Chunk>
|
|
712
|
+
static encryptedRoot(data: Uint8Array): Promise<{
|
|
713
|
+
address: Uint8Array
|
|
714
|
+
key: Uint8Array
|
|
715
|
+
}>
|
|
698
716
|
append(data: Uint8Array, level?: number, spanIncrement?: bigint): Promise<void>
|
|
699
717
|
private elevate
|
|
700
718
|
finalize(level?: number): Promise<Chunk>
|
|
701
719
|
}
|
|
720
|
+
export declare class ChunkJoiner {
|
|
721
|
+
private refSize
|
|
722
|
+
private encrypted
|
|
723
|
+
private fetch
|
|
724
|
+
private onData
|
|
725
|
+
constructor(fetch: (address: Uint8Array) => Promise<Uint8Array>, onData: (data: Uint8Array) => Promise<void>, encrypted?: boolean)
|
|
726
|
+
static collect(address: Uint8Array, fetch: (address: Uint8Array) => Promise<Uint8Array>): Promise<Uint8Array>
|
|
727
|
+
static collectEncrypted(address: Uint8Array, key: Uint8Array, fetch: (address: Uint8Array) => Promise<Uint8Array>): Promise<Uint8Array>
|
|
728
|
+
join(address: Uint8Array, key?: Uint8Array): Promise<void>
|
|
729
|
+
}
|
|
702
730
|
export declare class FixedPointNumber {
|
|
703
731
|
value: bigint
|
|
704
732
|
scale: number
|
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.Lock = exports.Solver = exports.RollingValueProvider = exports.TrieRouter = exports.AsyncQueue = exports.PubSubChannel = exports.FixedPointNumber = exports.
|
|
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.ChunkJoiner = exports.ChunkSplitter = 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
|
}
|
|
@@ -11,7 +11,7 @@ async function runInParallelBatches(n, e = 1) {
|
|
|
11
11
|
const t = splitByCount(n, e),
|
|
12
12
|
r = [],
|
|
13
13
|
i = t.map(async o => {
|
|
14
|
-
for (const
|
|
14
|
+
for (const c of o) r.push(await c())
|
|
15
15
|
})
|
|
16
16
|
return await Promise.all(i), r
|
|
17
17
|
}
|
|
@@ -122,18 +122,18 @@ function pickManyUnique(n, e, t, r = Math.random) {
|
|
|
122
122
|
const i = []
|
|
123
123
|
for (; i.length < e; ) {
|
|
124
124
|
const o = pick(n, r)
|
|
125
|
-
i.some(
|
|
125
|
+
i.some(c => t(c, o)) || i.push(o)
|
|
126
126
|
}
|
|
127
127
|
return i
|
|
128
128
|
}
|
|
129
129
|
function pickGuaranteed(n, e, t, r, i, o = Math.random) {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
for (e !== null &&
|
|
133
|
-
const
|
|
134
|
-
i(
|
|
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)
|
|
135
135
|
}
|
|
136
|
-
return shuffle(
|
|
136
|
+
return shuffle(u, o), { values: u, indexOfGuaranteed: e !== null ? u.indexOf(e) : -1 }
|
|
137
137
|
}
|
|
138
138
|
function last(n) {
|
|
139
139
|
if (!n.length) throw Error('Received empty array')
|
|
@@ -147,7 +147,7 @@ function makePipe(n, e) {
|
|
|
147
147
|
}
|
|
148
148
|
function pickWeighted(n, e, t) {
|
|
149
149
|
if ((t === void 0 && (t = Math.random()), n.length !== e.length)) throw new Error('Array length mismatch')
|
|
150
|
-
let r = e.reduce((o,
|
|
150
|
+
let r = e.reduce((o, c) => o + c, 0)
|
|
151
151
|
const i = t * r
|
|
152
152
|
for (let o = 0; o < n.length - 1; o++) if (((r -= e[o]), i >= r)) return n[o]
|
|
153
153
|
return last(n)
|
|
@@ -156,7 +156,7 @@ function sortWeighted(n, e, t = Math.random) {
|
|
|
156
156
|
const r = e.map(o => t() * o),
|
|
157
157
|
i = []
|
|
158
158
|
for (let o = 0; o < n.length; o++) i.push([n[o], r[o]])
|
|
159
|
-
return i.sort((o,
|
|
159
|
+
return i.sort((o, c) => c[1] - o[1]).map(o => o[0])
|
|
160
160
|
}
|
|
161
161
|
function getDeep(n, e) {
|
|
162
162
|
if (n == null) return null
|
|
@@ -172,11 +172,11 @@ function setDeep(n, e, t) {
|
|
|
172
172
|
const r = e.split(/\.|\[/)
|
|
173
173
|
let i = n
|
|
174
174
|
for (let o = 0; o < r.length; o++) {
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
f =
|
|
175
|
+
const c = r[o],
|
|
176
|
+
u = o < r.length - 1 && r[o + 1].includes(']'),
|
|
177
|
+
f = c.includes(']') ? c.replace(/\[|\]/g, '') : c
|
|
178
178
|
if (o === r.length - 1) return (i[f] = t), t
|
|
179
|
-
isObject(i[f]) || (
|
|
179
|
+
isObject(i[f]) || (u ? (i[f] = []) : (i[f] = {})), (i = i[f])
|
|
180
180
|
}
|
|
181
181
|
return t
|
|
182
182
|
}
|
|
@@ -232,16 +232,16 @@ function whereAmI() {
|
|
|
232
232
|
return n ? (n.browser === !0 ? 'browser' : 'node') : 'browser'
|
|
233
233
|
}
|
|
234
234
|
async function withRetries(n, e, t, r, i, o) {
|
|
235
|
-
let
|
|
236
|
-
for (let
|
|
235
|
+
let c = null
|
|
236
|
+
for (let u = 0; u <= e; u++)
|
|
237
237
|
try {
|
|
238
238
|
return await n()
|
|
239
|
-
} catch (
|
|
240
|
-
if (((
|
|
241
|
-
const f = t + (r - t) * (
|
|
242
|
-
i && i('Error in withRetries, retrying', { attempt:
|
|
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)
|
|
243
243
|
}
|
|
244
|
-
throw
|
|
244
|
+
throw c
|
|
245
245
|
}
|
|
246
246
|
function asMegabytes(n) {
|
|
247
247
|
return n / 1024 / 1024
|
|
@@ -259,10 +259,10 @@ function rgbToHex(n) {
|
|
|
259
259
|
}
|
|
260
260
|
function haversineDistanceToMeters(n, e, t, r) {
|
|
261
261
|
const o = (n * Math.PI) / 180,
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
f = Math.sin(
|
|
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)
|
|
266
266
|
return 6371e3 * (2 * Math.atan2(Math.sqrt(f), Math.sqrt(1 - f)))
|
|
267
267
|
}
|
|
268
268
|
function roundToNearest(n, e) {
|
|
@@ -282,9 +282,9 @@ function searchFloat(n) {
|
|
|
282
282
|
function binomialSample(n, e, t = Math.random) {
|
|
283
283
|
const r = n * e,
|
|
284
284
|
i = Math.sqrt(n * e * (1 - e)),
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return Math.max(0, Math.min(n,
|
|
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))
|
|
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 u = r.match(/^0*/)?.[0].length ?? 0,
|
|
302
|
+
s = e + u
|
|
303
|
+
return `${t}.${r.slice(0, s)}`
|
|
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'
|
|
@@ -783,12 +783,12 @@ function expand(n) {
|
|
|
783
783
|
const r = t[1].split(','),
|
|
784
784
|
i = n.slice(0, t.index),
|
|
785
785
|
o = n.slice(t.index + t[0].length)
|
|
786
|
-
let
|
|
787
|
-
for (const
|
|
788
|
-
const
|
|
789
|
-
|
|
786
|
+
let c = []
|
|
787
|
+
for (const u of r) {
|
|
788
|
+
const s = expand(i + u + o)
|
|
789
|
+
c = c.concat(s)
|
|
790
790
|
}
|
|
791
|
-
return
|
|
791
|
+
return c
|
|
792
792
|
}
|
|
793
793
|
function shrinkTrim(n) {
|
|
794
794
|
return n
|
|
@@ -1031,22 +1031,22 @@ function baseToUint8Array(n, e) {
|
|
|
1031
1031
|
r = e.length
|
|
1032
1032
|
let i = 0,
|
|
1033
1033
|
o = 0
|
|
1034
|
-
const
|
|
1035
|
-
for (let
|
|
1036
|
-
const
|
|
1037
|
-
if (
|
|
1038
|
-
const f = e.indexOf(
|
|
1039
|
-
if (f === -1) throw new Error(`Invalid character: ${
|
|
1040
|
-
;(o = (o << Math.log2(r)) | f), (i += Math.log2(r)), i >= 8 && ((i -= 8),
|
|
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}`)
|
|
1040
|
+
;(o = (o << Math.log2(r)) | f), (i += Math.log2(r)), i >= 8 && ((i -= 8), c.push((o >> i) & 255))
|
|
1041
1041
|
}
|
|
1042
|
-
return new Uint8Array(
|
|
1042
|
+
return new Uint8Array(c)
|
|
1043
1043
|
}
|
|
1044
1044
|
function uint8ArrayToBase(n, e) {
|
|
1045
1045
|
const t = e.length
|
|
1046
1046
|
let r = 0,
|
|
1047
1047
|
i = 0,
|
|
1048
1048
|
o = ''
|
|
1049
|
-
for (let
|
|
1049
|
+
for (let c = 0; c < n.length; c++) for (i = (i << 8) | n[c], r += 8; r >= Math.log2(t); ) (r -= Math.log2(t)), (o += e[(i >> r) & (t - 1)])
|
|
1050
1050
|
return r > 0 && (o += e[(i << (Math.log2(t) - r)) & (t - 1)]), o.length % 4 !== 0 && (o += '='.repeat(4 - (o.length % 4))), o
|
|
1051
1051
|
}
|
|
1052
1052
|
function hexToUint8Array(n) {
|
|
@@ -1084,9 +1084,9 @@ function route(n, e) {
|
|
|
1084
1084
|
if (t.length !== r.length) return null
|
|
1085
1085
|
const i = {}
|
|
1086
1086
|
for (let o = 0; o < t.length; o++) {
|
|
1087
|
-
const
|
|
1088
|
-
if (
|
|
1089
|
-
else if (
|
|
1087
|
+
const c = t[o]
|
|
1088
|
+
if (c.startsWith(':')) i[c.slice(1)] = r[o]
|
|
1089
|
+
else if (c !== r[o]) return null
|
|
1090
1090
|
}
|
|
1091
1091
|
return i
|
|
1092
1092
|
}
|
|
@@ -1097,25 +1097,25 @@ function explodeReplace(n, e, t) {
|
|
|
1097
1097
|
}
|
|
1098
1098
|
function generateVariants(n, e, t, r = Math.random) {
|
|
1099
1099
|
const i = exports.Arrays.shuffle(
|
|
1100
|
-
e.map(
|
|
1100
|
+
e.map(c => ({
|
|
1101
1101
|
variants: exports.Arrays.shuffle(
|
|
1102
|
-
|
|
1102
|
+
c.variants.map(u => u),
|
|
1103
1103
|
r
|
|
1104
1104
|
),
|
|
1105
|
-
avoid:
|
|
1105
|
+
avoid: c.avoid
|
|
1106
1106
|
})),
|
|
1107
1107
|
r
|
|
1108
1108
|
),
|
|
1109
1109
|
o = []
|
|
1110
|
-
for (const
|
|
1111
|
-
const
|
|
1112
|
-
|
|
1113
|
-
if (
|
|
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
|
|
1114
1114
|
}
|
|
1115
1115
|
if (o.length < t)
|
|
1116
|
-
for (const
|
|
1117
|
-
const
|
|
1118
|
-
if (
|
|
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
|
|
1119
1119
|
}
|
|
1120
1120
|
return o.slice(0, t)
|
|
1121
1121
|
}
|
|
@@ -1144,10 +1144,10 @@ function toLines(n, e, t = {}) {
|
|
|
1144
1144
|
const r = []
|
|
1145
1145
|
let i = '',
|
|
1146
1146
|
o = 0
|
|
1147
|
-
for (let
|
|
1148
|
-
const
|
|
1149
|
-
|
|
1150
|
-
if (((i +=
|
|
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)) {
|
|
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 u = readNextWord(n, o + e.length + 2, ['_'])
|
|
1227
|
+
n = n.replace(`${r}${e}${i}${u}`, t)
|
|
1228
1228
|
}
|
|
1229
1229
|
else n = n.replace(`${r}${e}`, t)
|
|
1230
1230
|
o = n.indexOf(`${r}${e}`, o + t.length)
|
|
@@ -1238,8 +1238,8 @@ function resolveRemainingVariablesWithDefaults(n, e = '$', t = ':') {
|
|
|
1238
1238
|
if (n[r + i.length + 1] === t)
|
|
1239
1239
|
if (n[r + i.length + 2] === t) n = n.replace(`${e}${i}${t}${t}`, '')
|
|
1240
1240
|
else {
|
|
1241
|
-
const
|
|
1242
|
-
n = n.replace(`${e}${i}${t}${
|
|
1241
|
+
const c = readNextWord(n, r + i.length + 2)
|
|
1242
|
+
n = n.replace(`${e}${i}${t}${c}`, c)
|
|
1243
1243
|
}
|
|
1244
1244
|
r = n.indexOf(e, r + 1)
|
|
1245
1245
|
}
|
|
@@ -1251,9 +1251,9 @@ function resolveMarkdownLinks(n, e) {
|
|
|
1251
1251
|
const r = lastIndexOfBefore(n, '[', t),
|
|
1252
1252
|
i = n.indexOf(')', t)
|
|
1253
1253
|
if (r !== -1 && i !== -1) {
|
|
1254
|
-
const [o,
|
|
1255
|
-
|
|
1256
|
-
n = n.slice(0, r) +
|
|
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)
|
|
1257
1257
|
}
|
|
1258
1258
|
t = n.indexOf('](', t + 1)
|
|
1259
1259
|
}
|
|
@@ -1282,15 +1282,15 @@ function selectMax(n, e) {
|
|
|
1282
1282
|
let t = null,
|
|
1283
1283
|
r = -1 / 0
|
|
1284
1284
|
for (const [i, o] of Object.entries(n)) {
|
|
1285
|
-
const
|
|
1286
|
-
|
|
1285
|
+
const c = e(o)
|
|
1286
|
+
c > r && ((r = c), (t = i))
|
|
1287
1287
|
}
|
|
1288
1288
|
return t ? [t, n[t]] : null
|
|
1289
1289
|
}
|
|
1290
1290
|
function reposition(n, e, t, r) {
|
|
1291
|
-
const i = n.find(
|
|
1292
|
-
o = n.find(
|
|
1293
|
-
i && o ? ((i[e] = t + r), (o[e] = t)) : i && (i[e] = t + r), n.sort((
|
|
1291
|
+
const i = n.find(c => c[e] === t),
|
|
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))
|
|
1294
1294
|
}
|
|
1295
1295
|
function unwrapSingleKey(n) {
|
|
1296
1296
|
const e = Object.keys(n)
|
|
@@ -1317,8 +1317,8 @@ function parseCsv(n, e = ',', t = '"') {
|
|
|
1317
1317
|
const r = []
|
|
1318
1318
|
let i = '',
|
|
1319
1319
|
o = !1
|
|
1320
|
-
const
|
|
1321
|
-
for (const
|
|
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)
|
|
1322
1322
|
return r.push(i), r
|
|
1323
1323
|
}
|
|
1324
1324
|
function humanizeProgress(n) {
|
|
@@ -1408,8 +1408,8 @@ function secondsToHumanTime(n, e = DefaultTimeDeltaLabels) {
|
|
|
1408
1408
|
function countCycles(n, e, t) {
|
|
1409
1409
|
const i = (t?.now ?? Date.now()) - n,
|
|
1410
1410
|
o = Math.floor(i / e),
|
|
1411
|
-
|
|
1412
|
-
return { cycles: o, remaining:
|
|
1411
|
+
c = e / (t?.precision ?? 1) - Math.ceil((i % e) / (t?.precision ?? 1))
|
|
1412
|
+
return { cycles: o, remaining: c }
|
|
1413
1413
|
}
|
|
1414
1414
|
const throttleTimers = {}
|
|
1415
1415
|
function throttle(n, e) {
|
|
@@ -1423,10 +1423,10 @@ function getProgress(n, e, t, r) {
|
|
|
1423
1423
|
r || (r = Date.now())
|
|
1424
1424
|
const i = e / t,
|
|
1425
1425
|
o = r - n,
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
return { deltaMs: o, progress: i, baseTimeMs:
|
|
1426
|
+
c = o / e,
|
|
1427
|
+
u = c * t,
|
|
1428
|
+
s = u - o
|
|
1429
|
+
return { deltaMs: o, progress: i, baseTimeMs: c, totalTimeMs: u, remainingTimeMs: s }
|
|
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) {
|
|
@@ -1484,10 +1484,10 @@ async function getCached(n, e, t, r) {
|
|
|
1484
1484
|
if (o && o.validUntil > i) return o.value
|
|
1485
1485
|
r?.onMiss?.()
|
|
1486
1486
|
try {
|
|
1487
|
-
const
|
|
1488
|
-
return tinyCache.set(n, { value:
|
|
1489
|
-
} catch (
|
|
1490
|
-
throw (r?.onFailure?.(
|
|
1487
|
+
const c = await t()
|
|
1488
|
+
return tinyCache.set(n, { value: c, validUntil: i + e }), c
|
|
1489
|
+
} catch (c) {
|
|
1490
|
+
throw (r?.onFailure?.(c), c)
|
|
1491
1491
|
}
|
|
1492
1492
|
}
|
|
1493
1493
|
function getCachedDeferred(n, e, t, r) {
|
|
@@ -1495,13 +1495,13 @@ function getCachedDeferred(n, e, t, r) {
|
|
|
1495
1495
|
o = tinyCache.get(n)
|
|
1496
1496
|
if (o && o.validUntil > i) return o.value
|
|
1497
1497
|
r?.onMiss?.()
|
|
1498
|
-
const
|
|
1498
|
+
const c = t()
|
|
1499
1499
|
return (
|
|
1500
|
-
tinyCache.set(n, { value:
|
|
1501
|
-
|
|
1502
|
-
tinyCache.delete(n), r?.onFailure?.(
|
|
1500
|
+
tinyCache.set(n, { value: c, validUntil: i + e }),
|
|
1501
|
+
c.catch(u => {
|
|
1502
|
+
tinyCache.delete(n), r?.onFailure?.(u)
|
|
1503
1503
|
}),
|
|
1504
|
-
|
|
1504
|
+
c
|
|
1505
1505
|
)
|
|
1506
1506
|
}
|
|
1507
1507
|
function deleteFromCache(n) {
|
|
@@ -1528,9 +1528,9 @@ function joinUrl(n, e = !1) {
|
|
|
1528
1528
|
}
|
|
1529
1529
|
function replaceBetweenStrings(n, e, t, r, i = !0) {
|
|
1530
1530
|
const o = n.indexOf(e),
|
|
1531
|
-
|
|
1532
|
-
if (o === -1 ||
|
|
1533
|
-
return i ? n.substring(0, o + e.length) + r + n.substring(
|
|
1531
|
+
c = n.indexOf(t, o + e.length)
|
|
1532
|
+
if (o === -1 || c === -1) throw Error('Start or end not found')
|
|
1533
|
+
return i ? n.substring(0, o + e.length) + r + n.substring(c) : n.substring(0, o) + r + n.substring(c + t.length)
|
|
1534
1534
|
}
|
|
1535
1535
|
function describeMarkdown(n) {
|
|
1536
1536
|
let e = 'p'
|
|
@@ -1596,12 +1596,12 @@ function createStatefulToggle(n) {
|
|
|
1596
1596
|
}
|
|
1597
1597
|
function organiseWithLimits(n, e, t, r, i) {
|
|
1598
1598
|
const o = {}
|
|
1599
|
-
for (const
|
|
1599
|
+
for (const c of Object.keys(e)) o[c] = []
|
|
1600
1600
|
;(o[r] = []), i && (n = n.sort(i))
|
|
1601
|
-
for (const
|
|
1602
|
-
const
|
|
1603
|
-
|
|
1604
|
-
o[
|
|
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)
|
|
1605
1605
|
}
|
|
1606
1606
|
return o
|
|
1607
1607
|
}
|
|
@@ -1654,7 +1654,7 @@ function formatNumber(n, e) {
|
|
|
1654
1654
|
i = t ? longNumberUnits : shortNumberUnits,
|
|
1655
1655
|
o = e?.precision ?? 1
|
|
1656
1656
|
if (n < thresholds[0]) return `${n}${r}`
|
|
1657
|
-
for (let
|
|
1657
|
+
for (let c = 0; c < thresholds.length - 1; c++) if (n < thresholds[c + 1]) return `${(n / thresholds[c]).toFixed(o)}${t ? ' ' : ''}${i[c]}${r}`
|
|
1658
1658
|
return `${(n / thresholds[thresholds.length - 1]).toFixed(o)}${t ? ' ' : ''}${i[thresholds.length - 1]}${r}`
|
|
1659
1659
|
}
|
|
1660
1660
|
function makeNumber(n) {
|
|
@@ -1738,22 +1738,22 @@ function flip(n) {
|
|
|
1738
1738
|
}
|
|
1739
1739
|
function getAllPermutations(n) {
|
|
1740
1740
|
const e = Object.keys(n),
|
|
1741
|
-
t = e.map(
|
|
1742
|
-
r = t.reduce((
|
|
1741
|
+
t = e.map(u => n[u].length),
|
|
1742
|
+
r = t.reduce((u, s) => (u *= s))
|
|
1743
1743
|
let i = 1
|
|
1744
1744
|
const o = [1]
|
|
1745
|
-
for (let
|
|
1746
|
-
const
|
|
1747
|
-
for (let
|
|
1748
|
-
const
|
|
1745
|
+
for (let u = 0; u < t.length - 1; u++) (i *= t[u]), o.push(i)
|
|
1746
|
+
const c = []
|
|
1747
|
+
for (let u = 0; u < r; u++) {
|
|
1748
|
+
const s = {}
|
|
1749
1749
|
for (let f = 0; f < e.length; f++) {
|
|
1750
1750
|
const l = n[e[f]],
|
|
1751
|
-
a = Math.floor(
|
|
1752
|
-
|
|
1751
|
+
a = Math.floor(u / o[f]) % l.length
|
|
1752
|
+
s[e[f]] = l[a]
|
|
1753
1753
|
}
|
|
1754
|
-
|
|
1754
|
+
c.push(s)
|
|
1755
1755
|
}
|
|
1756
|
-
return
|
|
1756
|
+
return c
|
|
1757
1757
|
}
|
|
1758
1758
|
function countTruthyValues(n) {
|
|
1759
1759
|
return Object.values(n).filter(e => e).length
|
|
@@ -1763,9 +1763,9 @@ function getFlatNotation(n, e, t) {
|
|
|
1763
1763
|
}
|
|
1764
1764
|
function flattenInner(n, e, t, r, i) {
|
|
1765
1765
|
if (!isObject(e)) return e
|
|
1766
|
-
for (const [o,
|
|
1767
|
-
const
|
|
1768
|
-
Array.isArray(
|
|
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)
|
|
1769
1769
|
}
|
|
1770
1770
|
return n
|
|
1771
1771
|
}
|
|
@@ -1830,10 +1830,10 @@ function makeUnique(n, e) {
|
|
|
1830
1830
|
}
|
|
1831
1831
|
function countUnique(n, e, t, r, i) {
|
|
1832
1832
|
const o = e ? n.map(e) : n,
|
|
1833
|
-
|
|
1834
|
-
for (const
|
|
1835
|
-
const
|
|
1836
|
-
return t ? Object.keys(
|
|
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
|
|
1837
1837
|
}
|
|
1838
1838
|
function sortObjectValues(n, e) {
|
|
1839
1839
|
return Object.fromEntries(Object.entries(n).sort(e))
|
|
@@ -1844,7 +1844,7 @@ function transformToArray(n) {
|
|
|
1844
1844
|
r = n[t[0]].length
|
|
1845
1845
|
for (let i = 0; i < r; i++) {
|
|
1846
1846
|
const o = {}
|
|
1847
|
-
for (const
|
|
1847
|
+
for (const c of t) o[c] = n[c][i]
|
|
1848
1848
|
e.push(o)
|
|
1849
1849
|
}
|
|
1850
1850
|
return e
|
|
@@ -1997,29 +1997,29 @@ class Node {
|
|
|
1997
1997
|
}
|
|
1998
1998
|
function createHierarchy(n, e, t, r, i = !1) {
|
|
1999
1999
|
const o = new Map(),
|
|
2000
|
-
|
|
2001
|
-
n.forEach(
|
|
2002
|
-
const f = new Node(
|
|
2003
|
-
o.set(
|
|
2000
|
+
c = []
|
|
2001
|
+
n.forEach(s => {
|
|
2002
|
+
const f = new Node(s)
|
|
2003
|
+
o.set(s[e], f)
|
|
2004
2004
|
}),
|
|
2005
|
-
n.forEach(
|
|
2006
|
-
const f = o.get(
|
|
2005
|
+
n.forEach(s => {
|
|
2006
|
+
const f = o.get(s[e])
|
|
2007
2007
|
if (!f) return
|
|
2008
|
-
const l =
|
|
2008
|
+
const l = s[t]
|
|
2009
2009
|
if (l) {
|
|
2010
2010
|
const a = o.get(l)
|
|
2011
2011
|
a && a.children.push(f)
|
|
2012
|
-
} else
|
|
2012
|
+
} else c.push(f)
|
|
2013
2013
|
})
|
|
2014
|
-
const
|
|
2015
|
-
|
|
2014
|
+
const u = s => {
|
|
2015
|
+
s.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
|
-
|
|
2020
|
+
s.children.forEach(u)
|
|
2021
2021
|
}
|
|
2022
|
-
return
|
|
2022
|
+
return c.forEach(u), 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')
|
|
@@ -2121,9 +2121,9 @@ function keccakPermutate(n) {
|
|
|
2121
2121
|
r = n[1] ^ n[11] ^ n[21] ^ n[31] ^ n[41],
|
|
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
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
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],
|
|
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],
|
|
@@ -2131,40 +2131,40 @@ function keccakPermutate(n) {
|
|
|
2131
2131
|
bn = (o << 1) | (i >>> 31),
|
|
2132
2132
|
d = l ^ h,
|
|
2133
2133
|
p = a ^ bn,
|
|
2134
|
-
$n = (
|
|
2135
|
-
|
|
2134
|
+
$n = (c << 1) | (u >>> 31),
|
|
2135
|
+
An = (u << 1) | (c >>> 31),
|
|
2136
2136
|
m = t ^ $n,
|
|
2137
|
-
g = r ^
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
w = i ^
|
|
2141
|
-
x = o ^
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
y =
|
|
2145
|
-
b =
|
|
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),
|
|
2143
|
+
kn = (a << 1) | (l >>> 31),
|
|
2144
|
+
y = c ^ Mn,
|
|
2145
|
+
b = u ^ kn,
|
|
2146
2146
|
On = (t << 1) | (r >>> 31),
|
|
2147
2147
|
Tn = (r << 1) | (t >>> 31),
|
|
2148
|
-
$ =
|
|
2149
|
-
|
|
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] ^=
|
|
2151
|
-
const
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
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
2155
|
O = (n[5] << 30) | (n[4] >>> 2),
|
|
2156
2156
|
T = (n[4] << 30) | (n[5] >>> 2),
|
|
2157
2157
|
C = (n[6] << 28) | (n[7] >>> 4),
|
|
2158
2158
|
R = (n[7] << 28) | (n[6] >>> 4),
|
|
2159
2159
|
I = (n[8] << 27) | (n[9] >>> 5),
|
|
2160
2160
|
D = (n[9] << 27) | (n[8] >>> 5),
|
|
2161
|
-
|
|
2162
|
-
|
|
2161
|
+
P = (n[11] << 4) | (n[10] >>> 28),
|
|
2162
|
+
B = (n[10] << 4) | (n[11] >>> 28),
|
|
2163
2163
|
v = (n[13] << 12) | (n[12] >>> 20),
|
|
2164
2164
|
U = (n[12] << 12) | (n[13] >>> 20),
|
|
2165
2165
|
L = (n[14] << 6) | (n[15] >>> 26),
|
|
2166
|
-
|
|
2167
|
-
|
|
2166
|
+
j = (n[15] << 6) | (n[14] >>> 26),
|
|
2167
|
+
N = (n[17] << 23) | (n[16] >>> 9),
|
|
2168
2168
|
F = (n[16] << 23) | (n[17] >>> 9),
|
|
2169
2169
|
z = (n[18] << 20) | (n[19] >>> 12),
|
|
2170
2170
|
q = (n[19] << 20) | (n[18] >>> 12),
|
|
@@ -2184,9 +2184,9 @@ function keccakPermutate(n) {
|
|
|
2184
2184
|
tn = (n[32] << 13) | (n[33] >>> 19),
|
|
2185
2185
|
rn = (n[34] << 15) | (n[35] >>> 17),
|
|
2186
2186
|
on = (n[35] << 15) | (n[34] >>> 17),
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
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
2190
|
fn = (n[39] << 8) | (n[38] >>> 24),
|
|
2191
2191
|
ln = (n[40] << 18) | (n[41] >>> 14),
|
|
2192
2192
|
an = (n[41] << 18) | (n[40] >>> 14),
|
|
@@ -2198,7 +2198,7 @@ function keccakPermutate(n) {
|
|
|
2198
2198
|
wn = (n[46] << 24) | (n[47] >>> 8),
|
|
2199
2199
|
xn = (n[48] << 14) | (n[49] >>> 18),
|
|
2200
2200
|
yn = (n[49] << 14) | (n[48] >>> 18)
|
|
2201
|
-
;(n[0] =
|
|
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])
|
|
2202
2202
|
}
|
|
2203
2203
|
}
|
|
2204
2204
|
function bytesToNumbers(n) {
|
|
@@ -2233,9 +2233,52 @@ function absorb(n, e) {
|
|
|
2233
2233
|
function squeeze(n) {
|
|
2234
2234
|
return new Uint8Array([n[1], n[1] >> -24, n[1] >> -16, n[1] >> -8, n[0], n[0] >> 8, n[0] >> 16, n[0] >> 24, n[3], n[3] >> -24, n[3] >> -16, n[3] >> -8, n[2], n[2] >> 8, n[2] >> 16, n[2] >> 24, n[5], n[5] >> -24, n[5] >> -16, n[5] >> -8, n[4], n[4] >> 8, n[4] >> 16, n[4] >> 24, n[7], n[7] >> -24, n[7] >> -16, n[7] >> -8, n[6], n[6] >> 8, n[6] >> 16, n[6] >> 24])
|
|
2235
2235
|
}
|
|
2236
|
+
function squeezeInto(n, e, t) {
|
|
2237
|
+
;(e[t] = n[1]), (e[t + 1] = n[1] >> 8), (e[t + 2] = n[1] >> 16), (e[t + 3] = n[1] >> 24), (e[t + 4] = n[0]), (e[t + 5] = n[0] >> 8), (e[t + 6] = n[0] >> 16), (e[t + 7] = n[0] >> 24), (e[t + 8] = n[3]), (e[t + 9] = n[3] >> 8), (e[t + 10] = n[3] >> 16), (e[t + 11] = n[3] >> 24), (e[t + 12] = n[2]), (e[t + 13] = n[2] >> 8), (e[t + 14] = n[2] >> 16), (e[t + 15] = n[2] >> 24), (e[t + 16] = n[5]), (e[t + 17] = n[5] >> 8), (e[t + 18] = n[5] >> 16), (e[t + 19] = n[5] >> 24), (e[t + 20] = n[4]), (e[t + 21] = n[4] >> 8), (e[t + 22] = n[4] >> 16), (e[t + 23] = n[4] >> 24), (e[t + 24] = n[7]), (e[t + 25] = n[7] >> 8), (e[t + 26] = n[7] >> 16), (e[t + 27] = n[7] >> 24), (e[t + 28] = n[6]), (e[t + 29] = n[6] >> 8), (e[t + 30] = n[6] >> 16), (e[t + 31] = n[6] >> 24)
|
|
2238
|
+
}
|
|
2236
2239
|
function keccak256(n) {
|
|
2237
2240
|
return squeeze(absorb(new Array(50).fill(0), divideToBlocks(n, 1)))
|
|
2238
2241
|
}
|
|
2242
|
+
function bmtRoot(n) {
|
|
2243
|
+
const e = new Uint8Array(n),
|
|
2244
|
+
t = new Array(50).fill(0),
|
|
2245
|
+
r = new Uint8Array(136)
|
|
2246
|
+
;(r[64] = 1), (r[135] = 128)
|
|
2247
|
+
let i = e.length >>> 5
|
|
2248
|
+
for (; i > 1; ) {
|
|
2249
|
+
const o = i >>> 1
|
|
2250
|
+
for (let c = 0; c < o; c++) {
|
|
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))
|
|
2253
|
+
keccakPermutate(t), squeezeInto(t, e, c << 5)
|
|
2254
|
+
}
|
|
2255
|
+
i = o
|
|
2256
|
+
}
|
|
2257
|
+
return e.subarray(0, 32)
|
|
2258
|
+
}
|
|
2259
|
+
const SPAN_ENCRYPT_INIT_CTR = 128
|
|
2260
|
+
function encryptSegments(n, e, t) {
|
|
2261
|
+
const r = new Uint8Array(t.length),
|
|
2262
|
+
i = new Uint8Array(36)
|
|
2263
|
+
i.set(n)
|
|
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)),
|
|
2268
|
+
f = Math.min(c + 32, t.length)
|
|
2269
|
+
for (let l = c; l < f; l++) r[l] = t[l] ^ s[l - c]
|
|
2270
|
+
}
|
|
2271
|
+
return r
|
|
2272
|
+
}
|
|
2273
|
+
function encryptSpan(n, e) {
|
|
2274
|
+
return encryptSegments(n, SPAN_ENCRYPT_INIT_CTR, e)
|
|
2275
|
+
}
|
|
2276
|
+
function encryptData(n, e) {
|
|
2277
|
+
return encryptSegments(n, 0, e)
|
|
2278
|
+
}
|
|
2279
|
+
function decryptChunk(n, e) {
|
|
2280
|
+
return { span: uint64ToNumber(encryptSpan(e, n.subarray(0, 8)), 'LE'), data: encryptData(e, n.subarray(8, 4104)) }
|
|
2281
|
+
}
|
|
2239
2282
|
function sha3_256(n) {
|
|
2240
2283
|
return squeeze(absorb(new Array(50).fill(0), divideToBlocks(n, 6)))
|
|
2241
2284
|
}
|
|
@@ -2319,8 +2362,8 @@ function modInverse(n, e) {
|
|
|
2319
2362
|
let [t, r] = [0n, 1n],
|
|
2320
2363
|
[i, o] = [e, n]
|
|
2321
2364
|
for (; o !== 0n; ) {
|
|
2322
|
-
const
|
|
2323
|
-
;([t, r] = [r, t -
|
|
2365
|
+
const c = i / o
|
|
2366
|
+
;([t, r] = [r, t - c * r]), ([i, o] = [o, i - c * o])
|
|
2324
2367
|
}
|
|
2325
2368
|
if (i > 1n) throw new Error('a is not invertible')
|
|
2326
2369
|
return t < 0n && (t += e), t
|
|
@@ -2350,9 +2393,9 @@ function ellipticAdd(n, e, t, r, i) {
|
|
|
2350
2393
|
if (n === t && e === mod(-r, i)) return [0n, 0n]
|
|
2351
2394
|
if (n === t && e === r) return ellipticDouble(n, e, i)
|
|
2352
2395
|
const o = mod((r - e) * modInverse(t - n, i), i),
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
return [
|
|
2396
|
+
c = mod(o * o - n - t, i),
|
|
2397
|
+
u = mod(o * (n - c) - e, i)
|
|
2398
|
+
return [c, u]
|
|
2356
2399
|
}
|
|
2357
2400
|
function privateKeyToPublicKey(n) {
|
|
2358
2401
|
if (n <= 0n || n >= SECP256K1_N) throw new Error('Invalid private key')
|
|
@@ -2386,8 +2429,8 @@ function checksumEncode(n) {
|
|
|
2386
2429
|
function doubleAndAdd(n, e, t, r) {
|
|
2387
2430
|
let i = [0n, 0n],
|
|
2388
2431
|
o = [n, e]
|
|
2389
|
-
const
|
|
2390
|
-
for (const
|
|
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)))
|
|
2391
2434
|
return i
|
|
2392
2435
|
}
|
|
2393
2436
|
function signMessage(n, e, t) {
|
|
@@ -2399,30 +2442,30 @@ function signHash(n, e, t) {
|
|
|
2399
2442
|
const r = mod(n, SECP256K1_N),
|
|
2400
2443
|
i = doubleAndAdd(SECP256K1_X, SECP256K1_Y, t, SECP256K1_P),
|
|
2401
2444
|
o = mod(i[0], SECP256K1_N)
|
|
2402
|
-
let
|
|
2403
|
-
if (o === 0n ||
|
|
2404
|
-
let
|
|
2405
|
-
return
|
|
2445
|
+
let c = mod((r + mod(o, SECP256K1_N) * e) * modInverse(t, SECP256K1_N), SECP256K1_N)
|
|
2446
|
+
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]
|
|
2406
2449
|
}
|
|
2407
2450
|
function recoverPublicKey(n, e, t, r) {
|
|
2408
2451
|
const i = modSqrt(mod(e ** 3n + 7n, SECP256K1_P), SECP256K1_P)
|
|
2409
2452
|
if (!i) throw new Error('Invalid r: does not correspond to a valid curve point')
|
|
2410
2453
|
const o = r === 27n ? 0n : 1n,
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
f = doubleAndAdd(SECP256K1_X, SECP256K1_Y,
|
|
2415
|
-
l = ellipticAdd(
|
|
2454
|
+
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)
|
|
2416
2459
|
return doubleAndAdd(l[0], l[1], modInverse(e, SECP256K1_N), SECP256K1_P)
|
|
2417
2460
|
}
|
|
2418
2461
|
function verifySignature(n, e, t, r) {
|
|
2419
2462
|
const i = mod(uint256ToNumber(keccak256(n), 'BE'), SECP256K1_N),
|
|
2420
2463
|
o = modInverse(r, SECP256K1_N),
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
f = doubleAndAdd(e[0], e[1],
|
|
2425
|
-
l = ellipticAdd(
|
|
2464
|
+
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)
|
|
2426
2469
|
return t === mod(l[0], SECP256K1_N)
|
|
2427
2470
|
}
|
|
2428
2471
|
class Uint8ArrayReader {
|
|
@@ -2452,25 +2495,44 @@ class Uint8ArrayWriter {
|
|
|
2452
2495
|
}
|
|
2453
2496
|
exports.Uint8ArrayWriter = Uint8ArrayWriter
|
|
2454
2497
|
class Chunk {
|
|
2455
|
-
constructor(e
|
|
2456
|
-
;(this.span =
|
|
2498
|
+
constructor(e = 0n) {
|
|
2499
|
+
;(this.span = e), (this.writer = new Uint8ArrayWriter(new Uint8Array(4096)))
|
|
2457
2500
|
}
|
|
2458
2501
|
build() {
|
|
2459
2502
|
return concatBytes(numberToUint64(this.span, 'LE'), this.writer.buffer)
|
|
2460
2503
|
}
|
|
2461
2504
|
hash() {
|
|
2462
|
-
const e =
|
|
2463
|
-
return
|
|
2505
|
+
const e = new Uint8Array(40)
|
|
2506
|
+
return e.set(numberToUint64(this.span, 'LE')), e.set(bmtRoot(this.writer.buffer), 8), Chunk.hashFunction(e)
|
|
2507
|
+
}
|
|
2508
|
+
encryptedHash(e) {
|
|
2509
|
+
e || ((e = new Uint8Array(32)), crypto.getRandomValues(e))
|
|
2510
|
+
const t = encryptSpan(e, numberToUint64(this.span, 'LE')),
|
|
2511
|
+
r = new Uint8Array(40)
|
|
2512
|
+
return r.set(t), r.set(bmtRoot(encryptData(e, this.writer.buffer)), 8), { address: Chunk.hashFunction(r), key: e }
|
|
2513
|
+
}
|
|
2514
|
+
static encryptSpan(e, t) {
|
|
2515
|
+
return encryptSpan(e, t)
|
|
2516
|
+
}
|
|
2517
|
+
static encryptData(e, t) {
|
|
2518
|
+
return encryptData(e, t)
|
|
2519
|
+
}
|
|
2520
|
+
static decrypt(e, t) {
|
|
2521
|
+
return decryptChunk(e, t)
|
|
2464
2522
|
}
|
|
2465
2523
|
}
|
|
2466
2524
|
;(exports.Chunk = Chunk), (Chunk.hashFunction = keccak256)
|
|
2467
|
-
class
|
|
2468
|
-
constructor(e, t =
|
|
2469
|
-
;(this.counters = [1]), (this.
|
|
2525
|
+
class ChunkSplitter {
|
|
2526
|
+
constructor(e, t = !1) {
|
|
2527
|
+
;(this.counters = [1]), (this.encrypted = t), (this.refSize = t ? 64 : 32), (this.chunks = [new Chunk()]), (this.onChunk = e)
|
|
2470
2528
|
}
|
|
2471
|
-
static async root(e
|
|
2472
|
-
const
|
|
2473
|
-
return await
|
|
2529
|
+
static async root(e) {
|
|
2530
|
+
const t = new _a(_a.NOOP)
|
|
2531
|
+
return await t.append(e), t.finalize()
|
|
2532
|
+
}
|
|
2533
|
+
static async encryptedRoot(e) {
|
|
2534
|
+
const t = new _a(_a.NOOP, !0)
|
|
2535
|
+
return await t.append(e), (await t.finalize()).encryptedHash()
|
|
2474
2536
|
}
|
|
2475
2537
|
async append(e, t = 0, r = 0n) {
|
|
2476
2538
|
const i = new Uint8ArrayReader(e)
|
|
@@ -2481,13 +2543,69 @@ class MerkleTree {
|
|
|
2481
2543
|
}
|
|
2482
2544
|
}
|
|
2483
2545
|
async elevate(e) {
|
|
2484
|
-
|
|
2546
|
+
if (((this.counters[e] = ++this.counters[e] % (4096 / this.refSize)), this.chunks[e + 1] || (this.chunks.push(new Chunk()), this.counters.push(1)), this.encrypted)) {
|
|
2547
|
+
const { address: t, key: r } = this.chunks[e].encryptedHash(),
|
|
2548
|
+
i = new Uint8Array(64)
|
|
2549
|
+
i.set(t), i.set(r, 32), await this.append(i, e + 1, this.chunks[e].span), await this.onChunk(this.chunks[e], r)
|
|
2550
|
+
} else await this.append(this.chunks[e].hash(), e + 1, this.chunks[e].span), await this.onChunk(this.chunks[e])
|
|
2551
|
+
this.chunks[e] = new Chunk()
|
|
2485
2552
|
}
|
|
2486
2553
|
async finalize(e = 0) {
|
|
2487
|
-
|
|
2554
|
+
if (!this.chunks[e + 1]) {
|
|
2555
|
+
if (this.encrypted) {
|
|
2556
|
+
const { key: t } = this.chunks[e].encryptedHash()
|
|
2557
|
+
await this.onChunk(this.chunks[e], t)
|
|
2558
|
+
} else await this.onChunk(this.chunks[e])
|
|
2559
|
+
return this.chunks[e]
|
|
2560
|
+
}
|
|
2561
|
+
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))
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
;(exports.ChunkSplitter = ChunkSplitter), (_a = ChunkSplitter), (ChunkSplitter.NOOP = async (n, e) => {})
|
|
2565
|
+
function isAllZero(n) {
|
|
2566
|
+
for (let e = 0; e < n.length; e++) if (n[e] !== 0) return !1
|
|
2567
|
+
return !0
|
|
2568
|
+
}
|
|
2569
|
+
class ChunkJoiner {
|
|
2570
|
+
constructor(e, t, r = !1) {
|
|
2571
|
+
;(this.fetch = e), (this.onData = t), (this.encrypted = r), (this.refSize = r ? 64 : 32)
|
|
2572
|
+
}
|
|
2573
|
+
static async collect(e, t) {
|
|
2574
|
+
const r = []
|
|
2575
|
+
return (
|
|
2576
|
+
await new ChunkJoiner(t, async i => {
|
|
2577
|
+
r.push(i)
|
|
2578
|
+
}).join(e),
|
|
2579
|
+
concatBytes(...r)
|
|
2580
|
+
)
|
|
2581
|
+
}
|
|
2582
|
+
static async collectEncrypted(e, t, r) {
|
|
2583
|
+
const i = []
|
|
2584
|
+
return (
|
|
2585
|
+
await new ChunkJoiner(
|
|
2586
|
+
r,
|
|
2587
|
+
async o => {
|
|
2588
|
+
i.push(o)
|
|
2589
|
+
},
|
|
2590
|
+
!0
|
|
2591
|
+
).join(e, t),
|
|
2592
|
+
concatBytes(...i)
|
|
2593
|
+
)
|
|
2594
|
+
}
|
|
2595
|
+
async join(e, t) {
|
|
2596
|
+
const r = await this.fetch(e)
|
|
2597
|
+
let i, o
|
|
2598
|
+
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)))
|
|
2599
|
+
else
|
|
2600
|
+
for (let c = 0; c < 4096 / this.refSize; c++) {
|
|
2601
|
+
const u = o.subarray(c * this.refSize, (c + 1) * this.refSize),
|
|
2602
|
+
s = u.subarray(0, 32)
|
|
2603
|
+
if (isAllZero(s)) break
|
|
2604
|
+
await this.join(s, this.encrypted ? u.subarray(32, 64) : void 0)
|
|
2605
|
+
}
|
|
2488
2606
|
}
|
|
2489
2607
|
}
|
|
2490
|
-
|
|
2608
|
+
exports.ChunkJoiner = ChunkJoiner
|
|
2491
2609
|
class FixedPointNumber {
|
|
2492
2610
|
constructor(e, t) {
|
|
2493
2611
|
if (t < 0) throw Error('Scale must be non-negative')
|
|
@@ -2562,12 +2680,12 @@ function tickPlaybook(n) {
|
|
|
2562
2680
|
return e.ttlMax ? --e.ttl <= 0 && n.shift() : (e.ttlMax = e.ttl), { progress: (e.ttlMax - e.ttl) / e.ttlMax, data: e.data }
|
|
2563
2681
|
}
|
|
2564
2682
|
function getArgument(n, e, t, r) {
|
|
2565
|
-
const i = n.findIndex(
|
|
2683
|
+
const i = n.findIndex(u => u === `--${e}` || u.startsWith(`--${e}=`)),
|
|
2566
2684
|
o = n[i]
|
|
2567
2685
|
if (!o) return (t || {})[r || e || ''] || null
|
|
2568
2686
|
if (o.includes('=')) return o.split('=')[1]
|
|
2569
|
-
const
|
|
2570
|
-
return
|
|
2687
|
+
const c = n[i + 1]
|
|
2688
|
+
return c && !c.startsWith('-') ? c : (t || {})[r || e || ''] || null
|
|
2571
2689
|
}
|
|
2572
2690
|
function getNumberArgument(n, e, t, r) {
|
|
2573
2691
|
const i = getArgument(n, e, t, r)
|
|
@@ -2579,14 +2697,14 @@ function getNumberArgument(n, e, t, r) {
|
|
|
2579
2697
|
}
|
|
2580
2698
|
}
|
|
2581
2699
|
function getBooleanArgument(n, e, t, r) {
|
|
2582
|
-
const i = n.some(
|
|
2700
|
+
const i = n.some(s => s.endsWith('-' + e)),
|
|
2583
2701
|
o = getArgument(n, e, t, r)
|
|
2584
2702
|
if (!o && i) return !0
|
|
2585
2703
|
if (!o && !i) return null
|
|
2586
|
-
const
|
|
2587
|
-
|
|
2588
|
-
if (
|
|
2589
|
-
if (
|
|
2704
|
+
const c = ['true', '1', 'yes', 'y', 'on'],
|
|
2705
|
+
u = ['false', '0', 'no', 'n', 'off']
|
|
2706
|
+
if (c.includes(o.toLowerCase())) return !0
|
|
2707
|
+
if (u.includes(o.toLowerCase())) return !1
|
|
2590
2708
|
throw Error(`Invalid boolean argument ${e}: ${o}`)
|
|
2591
2709
|
}
|
|
2592
2710
|
function requireStringArgument(n, e, t, r) {
|
|
@@ -2665,21 +2783,21 @@ function findCorners(n, e, t, r) {
|
|
|
2665
2783
|
{ x: t, y: r }
|
|
2666
2784
|
]
|
|
2667
2785
|
for (let o = 0; o < n.length; o++)
|
|
2668
|
-
for (let
|
|
2669
|
-
const
|
|
2670
|
-
for (const
|
|
2786
|
+
for (let c = 0; c < n[0].length; c++) {
|
|
2787
|
+
const u = getCorners(n, o, c)
|
|
2788
|
+
for (const s of u) i.some(f => f.x === s.x && f.y === s.y) || i.push(s)
|
|
2671
2789
|
}
|
|
2672
2790
|
return i.map(o => ({ x: o.x * e, y: o.y * e }))
|
|
2673
2791
|
}
|
|
2674
2792
|
function findLines(n, e) {
|
|
2675
|
-
const t = filterCoordinates(n, (
|
|
2676
|
-
r = filterCoordinates(n, (
|
|
2677
|
-
i = filterCoordinates(n, (
|
|
2678
|
-
o = filterCoordinates(n, (
|
|
2679
|
-
t.forEach(
|
|
2680
|
-
const
|
|
2681
|
-
|
|
2682
|
-
return [...
|
|
2793
|
+
const t = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s][f + 1] !== 0, 'row-first').map(s => ({ ...s, dx: 1, dy: 0 })),
|
|
2794
|
+
r = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s][f - 1] !== 0, 'row-first').map(s => ({ ...s, dx: 1, dy: 0 })),
|
|
2795
|
+
i = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s - 1]?.[f] !== 0, 'column-first').map(s => ({ ...s, dx: 0, dy: 1 })),
|
|
2796
|
+
o = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s + 1]?.[f] !== 0, 'column-first').map(s => ({ ...s, dx: 0, dy: 1 }))
|
|
2797
|
+
t.forEach(s => s.y++), o.forEach(s => s.x++)
|
|
2798
|
+
const c = group([...i, ...o], (s, f) => s.x === f.x && s.y - 1 === f.y),
|
|
2799
|
+
u = group([...r, ...t], (s, f) => s.y === f.y && s.x - 1 === f.x)
|
|
2800
|
+
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) }))
|
|
2683
2801
|
}
|
|
2684
2802
|
function getAngleInRadians(n, e) {
|
|
2685
2803
|
return Math.atan2(e.y - n.y, e.x - n.x)
|
|
@@ -2691,33 +2809,33 @@ function getLineIntersectionPoint(n, e, t, r) {
|
|
|
2691
2809
|
const i = (r.y - t.y) * (e.x - n.x) - (r.x - t.x) * (e.y - n.y)
|
|
2692
2810
|
if (i === 0) return null
|
|
2693
2811
|
let o = n.y - t.y,
|
|
2694
|
-
|
|
2695
|
-
const
|
|
2696
|
-
|
|
2697
|
-
return (o =
|
|
2812
|
+
c = n.x - t.x
|
|
2813
|
+
const u = (r.x - t.x) * o - (r.y - t.y) * c,
|
|
2814
|
+
s = (e.x - n.x) * o - (e.y - n.y) * c
|
|
2815
|
+
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
|
|
2698
2816
|
}
|
|
2699
2817
|
function raycast(n, e, t) {
|
|
2700
2818
|
const r = [],
|
|
2701
2819
|
i = pushPoint(n, t, 1e4)
|
|
2702
2820
|
for (const o of e) {
|
|
2703
|
-
const
|
|
2704
|
-
|
|
2821
|
+
const c = getLineIntersectionPoint(n, i, o.start, o.end)
|
|
2822
|
+
c && r.push(c)
|
|
2705
2823
|
}
|
|
2706
2824
|
return r.length
|
|
2707
|
-
? r.reduce((o,
|
|
2708
|
-
const
|
|
2709
|
-
|
|
2710
|
-
return
|
|
2825
|
+
? r.reduce((o, c) => {
|
|
2826
|
+
const u = getDistanceBetweenPoints(n, c),
|
|
2827
|
+
s = getDistanceBetweenPoints(n, o)
|
|
2828
|
+
return u < s ? c : o
|
|
2711
2829
|
})
|
|
2712
2830
|
: null
|
|
2713
2831
|
}
|
|
2714
2832
|
function raycastCircle(n, e, t) {
|
|
2715
2833
|
const i = getSortedRayAngles(n, t),
|
|
2716
2834
|
o = []
|
|
2717
|
-
for (const
|
|
2718
|
-
const
|
|
2719
|
-
|
|
2720
|
-
|
|
2835
|
+
for (const c of i) {
|
|
2836
|
+
const u = raycast(n, e, c - 0.001),
|
|
2837
|
+
s = raycast(n, e, c + 0.001)
|
|
2838
|
+
u && o.push(u), s && o.push(s)
|
|
2721
2839
|
}
|
|
2722
2840
|
return o
|
|
2723
2841
|
}
|
|
@@ -2790,20 +2908,20 @@ class TrieRouter {
|
|
|
2790
2908
|
let i = r,
|
|
2791
2909
|
o
|
|
2792
2910
|
if ((r.startsWith(':') && ((i = ':'), (o = r.slice(1))), !this.forks.has(i))) {
|
|
2793
|
-
const
|
|
2794
|
-
o && (
|
|
2911
|
+
const c = new TrieRouter()
|
|
2912
|
+
o && (c.variableName = o), this.forks.set(i, c)
|
|
2795
2913
|
}
|
|
2796
2914
|
this.forks.get(i).insert(e.slice(1), t)
|
|
2797
2915
|
}
|
|
2798
2916
|
async handle(e, t, r, i) {
|
|
2799
2917
|
if (e.length === 0) return this.handler ? (await this.handler(t, r, i), !0) : !1
|
|
2800
2918
|
const o = e[0],
|
|
2801
|
-
|
|
2802
|
-
if (
|
|
2803
|
-
const
|
|
2804
|
-
if (
|
|
2805
|
-
const
|
|
2806
|
-
return
|
|
2919
|
+
c = this.forks.get(o)
|
|
2920
|
+
if (c) return c.handle(e.slice(1), t, r, i)
|
|
2921
|
+
const u = this.forks.get(':')
|
|
2922
|
+
if (u) return u.variableName && i.set(u.variableName, decodeURIComponent(o)), u.handle(e.slice(1), t, r, i)
|
|
2923
|
+
const s = this.forks.get('*')
|
|
2924
|
+
return s ? (i.set('wildcard', e.join('/')), s.handler ? (await s.handler(t, r, i), !0) : !1) : !1
|
|
2807
2925
|
}
|
|
2808
2926
|
}
|
|
2809
2927
|
exports.TrieRouter = TrieRouter
|
package/module.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Arrays, Assertions, AsyncLazy, AsyncQueue, Binary, Cache, Chunk, Dates, Elliptic, FixedPointNumber, Lazy, Lock,
|
|
1
|
+
export { Arrays, Assertions, AsyncLazy, AsyncQueue, Binary, Cache, Chunk, ChunkJoiner, ChunkSplitter, Dates, Elliptic, FixedPointNumber, Lazy, Lock, Numbers, Objects, Optional, Promises, PubSubChannel, Random, RollingValueProvider, Solver, Strings, System, TrieRouter, Types, Uint8ArrayReader, Uint8ArrayWriter, Vector } from './index.js'
|