cafe-utility 26.8.0 → 26.10.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 +7 -1
- package/index.js +146 -128
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -415,6 +415,7 @@ declare function removeEmptyValues(object: CafeObject): CafeObject;
|
|
|
415
415
|
declare function filterObjectKeys<T>(object: CafeObject<T>, predicate: (key: string) => boolean): CafeObject<T>;
|
|
416
416
|
declare function filterObjectValues<T>(object: CafeObject<T>, predicate: (value: T) => boolean): CafeObject<T>;
|
|
417
417
|
declare function mapObject<T, K>(object: CafeObject<T>, mapper: (value: T) => K): CafeObject<K>;
|
|
418
|
+
declare function mapIterable<T, K>(iterable: Iterable<T>, mapper: (value: T, index: number) => K): K[];
|
|
418
419
|
declare function rethrow<T>(asyncFn: () => Promise<T>, throwable: Error): Promise<T>;
|
|
419
420
|
declare function setSomeOnObject(object: CafeObject, key: string, value: unknown): void;
|
|
420
421
|
declare function setSomeDeep(target: CafeObject, targetPath: string, source: CafeObject, sourcePath: string): void;
|
|
@@ -511,7 +512,9 @@ declare function proximity(one: Uint8Array, other: Uint8Array, max: number): num
|
|
|
511
512
|
declare function commonPrefix(one: Uint8Array, other: Uint8Array): Uint8Array;
|
|
512
513
|
declare function setBit(bytes: Uint8Array, index: number, value: 0 | 1): void;
|
|
513
514
|
declare function getBit(bytes: Uint8Array, index: number): 0 | 1;
|
|
514
|
-
declare function binaryIndexOf(
|
|
515
|
+
declare function binaryIndexOf(bytes: Uint8Array, value: Uint8Array, start?: number): number;
|
|
516
|
+
declare function binaryPad(bytes: Uint8Array, size: number): Uint8Array;
|
|
517
|
+
declare function binaryPadToMultiple(bytes: Uint8Array, multiple: number): Uint8Array;
|
|
515
518
|
declare function binaryEquals(a: Uint8Array, b: Uint8Array): boolean;
|
|
516
519
|
declare function privateKeyToPublicKey(privateKey: bigint): [bigint, bigint];
|
|
517
520
|
declare function publicKeyToAddress(publicKey: [bigint, bigint]): Uint8Array;
|
|
@@ -633,6 +636,8 @@ export declare const Binary: {
|
|
|
633
636
|
getBit: typeof getBit;
|
|
634
637
|
indexOf: typeof binaryIndexOf;
|
|
635
638
|
equals: typeof binaryEquals;
|
|
639
|
+
pad: typeof binaryPad;
|
|
640
|
+
padToMultiple: typeof binaryPadToMultiple;
|
|
636
641
|
};
|
|
637
642
|
export declare const Elliptic: {
|
|
638
643
|
privateKeyToPublicKey: typeof privateKeyToPublicKey;
|
|
@@ -801,6 +806,7 @@ export declare const Objects: {
|
|
|
801
806
|
match: typeof match;
|
|
802
807
|
sort: typeof sortObjectValues;
|
|
803
808
|
map: typeof mapObject;
|
|
809
|
+
mapIterable: typeof mapIterable;
|
|
804
810
|
filterKeys: typeof filterObjectKeys;
|
|
805
811
|
filterValues: typeof filterObjectValues;
|
|
806
812
|
rethrow: typeof rethrow;
|
package/index.js
CHANGED
|
@@ -149,12 +149,12 @@ function pickManyUnique(n, e, t, r = Math.random) {
|
|
|
149
149
|
}
|
|
150
150
|
function pickGuaranteed(n, e, t, r, o, i = Math.random) {
|
|
151
151
|
const u = n.filter(c => c !== e && c !== t),
|
|
152
|
-
|
|
153
|
-
for (e !== null &&
|
|
152
|
+
f = []
|
|
153
|
+
for (e !== null && f.push(e); u.length && f.length < r; ) {
|
|
154
154
|
const c = exports.Random.intBetween(0, u.length - 1, i)
|
|
155
|
-
o(u[c],
|
|
155
|
+
o(u[c], f) && f.push(u[c]), u.splice(c, 1)
|
|
156
156
|
}
|
|
157
|
-
return shuffle(
|
|
157
|
+
return shuffle(f, i), { values: f, indexOfGuaranteed: e !== null ? f.indexOf(e) : -1 }
|
|
158
158
|
}
|
|
159
159
|
function last(n) {
|
|
160
160
|
if (!n.length) throw Error('Received empty array')
|
|
@@ -194,10 +194,10 @@ function setDeep(n, e, t) {
|
|
|
194
194
|
let o = n
|
|
195
195
|
for (let i = 0; i < r.length; i++) {
|
|
196
196
|
const u = r[i],
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (i === r.length - 1) return (o[
|
|
200
|
-
isObject(o[
|
|
197
|
+
f = i < r.length - 1 && r[i + 1].includes(']'),
|
|
198
|
+
s = u.includes(']') ? u.replace(/\[|\]/g, '') : u
|
|
199
|
+
if (i === r.length - 1) return (o[s] = t), t
|
|
200
|
+
isObject(o[s]) || (f ? (o[s] = []) : (o[s] = {})), (o = o[s])
|
|
201
201
|
}
|
|
202
202
|
return t
|
|
203
203
|
}
|
|
@@ -273,10 +273,10 @@ function rgbToHex(n) {
|
|
|
273
273
|
function haversineDistanceToMeters(n, e, t, r) {
|
|
274
274
|
const i = (n * Math.PI) / 180,
|
|
275
275
|
u = (t * Math.PI) / 180,
|
|
276
|
-
|
|
276
|
+
f = ((t - n) * Math.PI) / 180,
|
|
277
277
|
c = ((r - e) * Math.PI) / 180,
|
|
278
|
-
|
|
279
|
-
return 6371e3 * (2 * Math.atan2(Math.sqrt(
|
|
278
|
+
s = Math.sin(f / 2) * Math.sin(f / 2) + Math.cos(i) * Math.cos(u) * Math.sin(c / 2) * Math.sin(c / 2)
|
|
279
|
+
return 6371e3 * (2 * Math.atan2(Math.sqrt(s), Math.sqrt(1 - s)))
|
|
280
280
|
}
|
|
281
281
|
function roundToNearest(n, e) {
|
|
282
282
|
return Math.round(n / e) * e
|
|
@@ -812,8 +812,8 @@ function expand(n) {
|
|
|
812
812
|
o = n.slice(0, t.index),
|
|
813
813
|
i = n.slice(t.index + t[0].length)
|
|
814
814
|
let u = []
|
|
815
|
-
for (const
|
|
816
|
-
const c = expand(o +
|
|
815
|
+
for (const f of r) {
|
|
816
|
+
const c = expand(o + f + i)
|
|
817
817
|
u = u.concat(c)
|
|
818
818
|
}
|
|
819
819
|
return u
|
|
@@ -1058,12 +1058,12 @@ function baseToUint8Array(n, e) {
|
|
|
1058
1058
|
let o = 0,
|
|
1059
1059
|
i = 0
|
|
1060
1060
|
const u = []
|
|
1061
|
-
for (let
|
|
1062
|
-
const c = n[
|
|
1061
|
+
for (let f = 0; f < n.length; f++) {
|
|
1062
|
+
const c = n[f]
|
|
1063
1063
|
if (c === t) break
|
|
1064
|
-
const
|
|
1065
|
-
if (
|
|
1066
|
-
;(i = (i << Math.log2(r)) |
|
|
1064
|
+
const s = e.indexOf(c)
|
|
1065
|
+
if (s === -1) throw new Error(`Invalid character: ${c}`)
|
|
1066
|
+
;(i = (i << Math.log2(r)) | s), (o += Math.log2(r)), o >= 8 && ((o -= 8), u.push((i >> o) & 255))
|
|
1067
1067
|
}
|
|
1068
1068
|
return new Uint8Array(u)
|
|
1069
1069
|
}
|
|
@@ -1116,7 +1116,7 @@ function generateVariants(n, e, t, r = Math.random) {
|
|
|
1116
1116
|
const o = exports.Arrays.shuffle(
|
|
1117
1117
|
e.map(u => ({
|
|
1118
1118
|
variants: exports.Arrays.shuffle(
|
|
1119
|
-
u.variants.map(
|
|
1119
|
+
u.variants.map(f => f),
|
|
1120
1120
|
r
|
|
1121
1121
|
),
|
|
1122
1122
|
avoid: u.avoid
|
|
@@ -1125,14 +1125,14 @@ function generateVariants(n, e, t, r = Math.random) {
|
|
|
1125
1125
|
),
|
|
1126
1126
|
i = []
|
|
1127
1127
|
for (const u of o) {
|
|
1128
|
-
const
|
|
1129
|
-
c =
|
|
1130
|
-
if (c && (pushAll(i, explodeReplace(n, c,
|
|
1128
|
+
const f = u.variants.filter(s => s !== u.avoid),
|
|
1129
|
+
c = f.find(s => n.includes(s))
|
|
1130
|
+
if (c && (pushAll(i, explodeReplace(n, c, f)), i.length >= t)) break
|
|
1131
1131
|
}
|
|
1132
1132
|
if (i.length < t)
|
|
1133
1133
|
for (const u of o) {
|
|
1134
|
-
const
|
|
1135
|
-
if (
|
|
1134
|
+
const f = u.variants.find(c => n.includes(c))
|
|
1135
|
+
if (f && (pushAll(i, explodeReplace(n, f, u.variants)), i.length >= t)) break
|
|
1136
1136
|
}
|
|
1137
1137
|
return i.slice(0, t)
|
|
1138
1138
|
}
|
|
@@ -1162,11 +1162,11 @@ function toLines(n, e, t = {}) {
|
|
|
1162
1162
|
let o = '',
|
|
1163
1163
|
i = 0
|
|
1164
1164
|
for (let u = 0; u < n.length; u++) {
|
|
1165
|
-
const
|
|
1166
|
-
c = t[
|
|
1167
|
-
if (((o +=
|
|
1168
|
-
const { line:
|
|
1169
|
-
r.push(
|
|
1165
|
+
const f = n[u],
|
|
1166
|
+
c = t[f] || 1
|
|
1167
|
+
if (((o += f), (i += c), i > e)) {
|
|
1168
|
+
const { line: s, rest: l } = breakLine(o)
|
|
1169
|
+
r.push(s),
|
|
1170
1170
|
(o = l),
|
|
1171
1171
|
(i = l
|
|
1172
1172
|
.split('')
|
|
@@ -1219,8 +1219,8 @@ function resolveVariableWithDefaultSyntax(n, e, t, r = '$', o = ':') {
|
|
|
1219
1219
|
if (n[i + e.length + 1] === o)
|
|
1220
1220
|
if (n[i + e.length + 2] === o) n = n.replace(`${r}${e}${o}${o}`, t)
|
|
1221
1221
|
else {
|
|
1222
|
-
const
|
|
1223
|
-
n = n.replace(`${r}${e}${o}${
|
|
1222
|
+
const f = readNextWord(n, i + e.length + 2, ['_'])
|
|
1223
|
+
n = n.replace(`${r}${e}${o}${f}`, t)
|
|
1224
1224
|
}
|
|
1225
1225
|
else n = n.replace(`${r}${e}`, t)
|
|
1226
1226
|
i = n.indexOf(`${r}${e}`, i + t.length)
|
|
@@ -1248,8 +1248,8 @@ function resolveMarkdownLinks(n, e) {
|
|
|
1248
1248
|
o = n.indexOf(')', t)
|
|
1249
1249
|
if (r !== -1 && o !== -1) {
|
|
1250
1250
|
const [i, u] = n.slice(r + 1, o).split(']('),
|
|
1251
|
-
|
|
1252
|
-
n = n.slice(0, r) +
|
|
1251
|
+
f = e(i, u)
|
|
1252
|
+
n = n.slice(0, r) + f + n.slice(o + 1)
|
|
1253
1253
|
}
|
|
1254
1254
|
t = n.indexOf('](', t + 1)
|
|
1255
1255
|
}
|
|
@@ -1287,8 +1287,8 @@ function reposition(n, e, t, r) {
|
|
|
1287
1287
|
const o = n.find(u => u[e] === t),
|
|
1288
1288
|
i = n.find(u => u[e] === t + r)
|
|
1289
1289
|
o && i ? ((o[e] = t + r), (i[e] = t)) : o && (o[e] = t + r),
|
|
1290
|
-
n.sort((u,
|
|
1291
|
-
n.forEach((u,
|
|
1290
|
+
n.sort((u, f) => asNumber(u[e]) - asNumber(f[e])),
|
|
1291
|
+
n.forEach((u, f) => (u[e] = f + 1))
|
|
1292
1292
|
}
|
|
1293
1293
|
function unwrapSingleKey(n) {
|
|
1294
1294
|
const e = Object.keys(n)
|
|
@@ -1311,7 +1311,7 @@ function parseCsv(n, e = ',', t = '"') {
|
|
|
1311
1311
|
let o = '',
|
|
1312
1312
|
i = !1
|
|
1313
1313
|
const u = n.split('')
|
|
1314
|
-
for (const
|
|
1314
|
+
for (const f of u) f === e && !i ? (r.push(o), (o = '')) : f === t && ((!o && !i) || i) ? (i = !i) : (o += f)
|
|
1315
1315
|
return r.push(o), r
|
|
1316
1316
|
}
|
|
1317
1317
|
function humanizeProgress(n) {
|
|
@@ -1447,9 +1447,9 @@ function getProgress(n, e, t, r) {
|
|
|
1447
1447
|
const o = e / t,
|
|
1448
1448
|
i = r - n,
|
|
1449
1449
|
u = i / e,
|
|
1450
|
-
|
|
1451
|
-
c =
|
|
1452
|
-
return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs:
|
|
1450
|
+
f = u * t,
|
|
1451
|
+
c = f - i
|
|
1452
|
+
return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs: f, remainingTimeMs: c }
|
|
1453
1453
|
}
|
|
1454
1454
|
const dayNumberIndex = {
|
|
1455
1455
|
0: 'sunday',
|
|
@@ -1657,8 +1657,8 @@ function organiseWithLimits(n, e, t, r, o) {
|
|
|
1657
1657
|
for (const u of Object.keys(e)) i[u] = []
|
|
1658
1658
|
;(i[r] = []), o && (n = n.sort(o))
|
|
1659
1659
|
for (const u of n) {
|
|
1660
|
-
const
|
|
1661
|
-
c = e[
|
|
1660
|
+
const f = u[t],
|
|
1661
|
+
c = e[f] ? f : r
|
|
1662
1662
|
i[c].length >= e[c] ? i[r].push(u) : i[c].push(u)
|
|
1663
1663
|
}
|
|
1664
1664
|
return i
|
|
@@ -1789,6 +1789,12 @@ function mapObject(n, e) {
|
|
|
1789
1789
|
for (const r of Object.entries(n)) t[r[0]] = e(r[1])
|
|
1790
1790
|
return t
|
|
1791
1791
|
}
|
|
1792
|
+
function mapIterable(n, e) {
|
|
1793
|
+
const t = []
|
|
1794
|
+
let r = 0
|
|
1795
|
+
for (const o of n) t.push(e(o, r++))
|
|
1796
|
+
return t
|
|
1797
|
+
}
|
|
1792
1798
|
async function rethrow(n, e) {
|
|
1793
1799
|
try {
|
|
1794
1800
|
return await n()
|
|
@@ -1810,18 +1816,18 @@ function flip(n) {
|
|
|
1810
1816
|
}
|
|
1811
1817
|
function getAllPermutations(n) {
|
|
1812
1818
|
const e = Object.keys(n),
|
|
1813
|
-
t = e.map(
|
|
1814
|
-
r = t.reduce((
|
|
1819
|
+
t = e.map(f => n[f].length),
|
|
1820
|
+
r = t.reduce((f, c) => (f *= c))
|
|
1815
1821
|
let o = 1
|
|
1816
1822
|
const i = [1]
|
|
1817
|
-
for (let
|
|
1823
|
+
for (let f = 0; f < t.length - 1; f++) (o *= t[f]), i.push(o)
|
|
1818
1824
|
const u = []
|
|
1819
|
-
for (let
|
|
1825
|
+
for (let f = 0; f < r; f++) {
|
|
1820
1826
|
const c = {}
|
|
1821
|
-
for (let
|
|
1822
|
-
const l = n[e[
|
|
1823
|
-
a = Math.floor(
|
|
1824
|
-
c[e[
|
|
1827
|
+
for (let s = 0; s < e.length; s++) {
|
|
1828
|
+
const l = n[e[s]],
|
|
1829
|
+
a = Math.floor(f / i[s]) % l.length
|
|
1830
|
+
c[e[s]] = l[a]
|
|
1825
1831
|
}
|
|
1826
1832
|
u.push(c)
|
|
1827
1833
|
}
|
|
@@ -1836,14 +1842,14 @@ function getFlatNotation(n, e, t) {
|
|
|
1836
1842
|
function flattenInner(n, e, t, r, o) {
|
|
1837
1843
|
if (!isObject(e)) return e
|
|
1838
1844
|
for (const [i, u] of Object.entries(e)) {
|
|
1839
|
-
const
|
|
1845
|
+
const f = getFlatNotation(t, i, r)
|
|
1840
1846
|
Array.isArray(u)
|
|
1841
1847
|
? o
|
|
1842
|
-
? flattenInner(n, u,
|
|
1843
|
-
: (n[
|
|
1848
|
+
? flattenInner(n, u, f, !0, o)
|
|
1849
|
+
: (n[f] = u.map(c => flattenInner(Array.isArray(c) ? [] : {}, c, '', !1, o)))
|
|
1844
1850
|
: isObject(u)
|
|
1845
|
-
? flattenInner(n, u,
|
|
1846
|
-
: (n[
|
|
1851
|
+
? flattenInner(n, u, f, !1, o)
|
|
1852
|
+
: (n[f] = u)
|
|
1847
1853
|
}
|
|
1848
1854
|
return n
|
|
1849
1855
|
}
|
|
@@ -1910,8 +1916,8 @@ function countUnique(n, e, t, r, o) {
|
|
|
1910
1916
|
const i = e ? n.map(e) : n,
|
|
1911
1917
|
u = {}
|
|
1912
1918
|
for (const c of i) u[c] = (u[c] || 0) + 1
|
|
1913
|
-
const
|
|
1914
|
-
return t ? Object.keys(
|
|
1919
|
+
const f = r ? sortObjectValues(u, o ? (c, s) => c[1] - s[1] : (c, s) => s[1] - c[1]) : u
|
|
1920
|
+
return t ? Object.keys(f) : f
|
|
1915
1921
|
}
|
|
1916
1922
|
function sortObjectValues(n, e) {
|
|
1917
1923
|
return Object.fromEntries(Object.entries(n).sort(e))
|
|
@@ -2046,27 +2052,27 @@ function createHierarchy(n, e, t, r, o = !1) {
|
|
|
2046
2052
|
const i = new Map(),
|
|
2047
2053
|
u = []
|
|
2048
2054
|
n.forEach(c => {
|
|
2049
|
-
const
|
|
2050
|
-
i.set(c[e],
|
|
2055
|
+
const s = new Node(c)
|
|
2056
|
+
i.set(c[e], s)
|
|
2051
2057
|
}),
|
|
2052
2058
|
n.forEach(c => {
|
|
2053
|
-
const
|
|
2054
|
-
if (!
|
|
2059
|
+
const s = i.get(c[e])
|
|
2060
|
+
if (!s) return
|
|
2055
2061
|
const l = c[t]
|
|
2056
2062
|
if (l) {
|
|
2057
2063
|
const a = i.get(l)
|
|
2058
|
-
a && a.children.push(
|
|
2059
|
-
} else u.push(
|
|
2064
|
+
a && a.children.push(s)
|
|
2065
|
+
} else u.push(s)
|
|
2060
2066
|
})
|
|
2061
|
-
const
|
|
2062
|
-
c.children.sort((
|
|
2063
|
-
const a =
|
|
2067
|
+
const f = c => {
|
|
2068
|
+
c.children.sort((s, l) => {
|
|
2069
|
+
const a = s.value[r],
|
|
2064
2070
|
h = l.value[r]
|
|
2065
2071
|
return o ? h - a : a - h
|
|
2066
2072
|
}),
|
|
2067
|
-
c.children.forEach(
|
|
2073
|
+
c.children.forEach(f)
|
|
2068
2074
|
}
|
|
2069
|
-
return u.forEach(
|
|
2075
|
+
return u.forEach(f), u
|
|
2070
2076
|
}
|
|
2071
2077
|
function log2Reduce(n, e) {
|
|
2072
2078
|
if (Math.log2(n.length) % 1 !== 0) throw new Error('Array length must be a power of 2')
|
|
@@ -2174,31 +2180,31 @@ function keccakPermutate(n) {
|
|
|
2174
2180
|
o = n[2] ^ n[12] ^ n[22] ^ n[32] ^ n[42],
|
|
2175
2181
|
i = n[3] ^ n[13] ^ n[23] ^ n[33] ^ n[43],
|
|
2176
2182
|
u = n[4] ^ n[14] ^ n[24] ^ n[34] ^ n[44],
|
|
2177
|
-
|
|
2183
|
+
f = n[5] ^ n[15] ^ n[25] ^ n[35] ^ n[45],
|
|
2178
2184
|
c = n[6] ^ n[16] ^ n[26] ^ n[36] ^ n[46],
|
|
2179
|
-
|
|
2185
|
+
s = n[7] ^ n[17] ^ n[27] ^ n[37] ^ n[47],
|
|
2180
2186
|
l = n[8] ^ n[18] ^ n[28] ^ n[38] ^ n[48],
|
|
2181
2187
|
a = n[9] ^ n[19] ^ n[29] ^ n[39] ^ n[49],
|
|
2182
2188
|
h = (o << 1) | (i >>> 31),
|
|
2183
2189
|
bn = (i << 1) | (o >>> 31),
|
|
2184
2190
|
p = l ^ h,
|
|
2185
2191
|
d = a ^ bn,
|
|
2186
|
-
$n = (u << 1) | (
|
|
2187
|
-
An = (
|
|
2192
|
+
$n = (u << 1) | (f >>> 31),
|
|
2193
|
+
An = (f << 1) | (u >>> 31),
|
|
2188
2194
|
m = t ^ $n,
|
|
2189
2195
|
g = r ^ An,
|
|
2190
|
-
En = (c << 1) | (
|
|
2191
|
-
Mn = (
|
|
2196
|
+
En = (c << 1) | (s >>> 31),
|
|
2197
|
+
Mn = (s << 1) | (c >>> 31),
|
|
2192
2198
|
w = o ^ En,
|
|
2193
2199
|
y = i ^ Mn,
|
|
2194
2200
|
On = (l << 1) | (a >>> 31),
|
|
2195
2201
|
Tn = (a << 1) | (l >>> 31),
|
|
2196
2202
|
x = u ^ On,
|
|
2197
|
-
b =
|
|
2203
|
+
b = f ^ Tn,
|
|
2198
2204
|
kn = (t << 1) | (r >>> 31),
|
|
2199
2205
|
Sn = (r << 1) | (t >>> 31),
|
|
2200
2206
|
$ = c ^ kn,
|
|
2201
|
-
A =
|
|
2207
|
+
A = s ^ Sn
|
|
2202
2208
|
;(n[0] ^= p),
|
|
2203
2209
|
(n[1] ^= d),
|
|
2204
2210
|
(n[2] ^= m),
|
|
@@ -2263,10 +2269,10 @@ function keccakPermutate(n) {
|
|
|
2263
2269
|
B = (n[10] << 4) | (n[11] >>> 28),
|
|
2264
2270
|
L = (n[13] << 12) | (n[12] >>> 20),
|
|
2265
2271
|
N = (n[12] << 12) | (n[13] >>> 20),
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2272
|
+
U = (n[14] << 6) | (n[15] >>> 26),
|
|
2273
|
+
j = (n[15] << 6) | (n[14] >>> 26),
|
|
2274
|
+
F = (n[17] << 23) | (n[16] >>> 9),
|
|
2275
|
+
z = (n[16] << 23) | (n[17] >>> 9),
|
|
2270
2276
|
q = (n[18] << 20) | (n[19] >>> 12),
|
|
2271
2277
|
v = (n[19] << 20) | (n[18] >>> 12),
|
|
2272
2278
|
H = (n[20] << 3) | (n[21] >>> 29),
|
|
@@ -2287,8 +2293,8 @@ function keccakPermutate(n) {
|
|
|
2287
2293
|
on = (n[35] << 15) | (n[34] >>> 17),
|
|
2288
2294
|
un = (n[36] << 21) | (n[37] >>> 11),
|
|
2289
2295
|
cn = (n[37] << 21) | (n[36] >>> 11),
|
|
2290
|
-
|
|
2291
|
-
|
|
2296
|
+
fn = (n[38] << 8) | (n[39] >>> 24),
|
|
2297
|
+
sn = (n[39] << 8) | (n[38] >>> 24),
|
|
2292
2298
|
ln = (n[40] << 18) | (n[41] >>> 14),
|
|
2293
2299
|
an = (n[41] << 18) | (n[40] >>> 14),
|
|
2294
2300
|
hn = (n[42] << 2) | (n[43] >>> 30),
|
|
@@ -2319,16 +2325,16 @@ function keccakPermutate(n) {
|
|
|
2319
2325
|
(n[17] = tn ^ (~mn & D)),
|
|
2320
2326
|
(n[18] = dn ^ (~R & q)),
|
|
2321
2327
|
(n[19] = mn ^ (~D & v)),
|
|
2322
|
-
(n[20] = O ^ (~
|
|
2323
|
-
(n[21] = T ^ (~
|
|
2324
|
-
(n[22] =
|
|
2325
|
-
(n[23] =
|
|
2326
|
-
(n[24] = Z ^ (~
|
|
2327
|
-
(n[25] = Q ^ (~
|
|
2328
|
-
(n[26] =
|
|
2329
|
-
(n[27] =
|
|
2330
|
-
(n[28] = ln ^ (~O &
|
|
2331
|
-
(n[29] = an ^ (~T &
|
|
2328
|
+
(n[20] = O ^ (~U & Z)),
|
|
2329
|
+
(n[21] = T ^ (~j & Q)),
|
|
2330
|
+
(n[22] = U ^ (~Z & fn)),
|
|
2331
|
+
(n[23] = j ^ (~Q & sn)),
|
|
2332
|
+
(n[24] = Z ^ (~fn & ln)),
|
|
2333
|
+
(n[25] = Q ^ (~sn & an)),
|
|
2334
|
+
(n[26] = fn ^ (~ln & O)),
|
|
2335
|
+
(n[27] = sn ^ (~an & T)),
|
|
2336
|
+
(n[28] = ln ^ (~O & U)),
|
|
2337
|
+
(n[29] = an ^ (~T & j)),
|
|
2332
2338
|
(n[30] = I ^ (~P & V)),
|
|
2333
2339
|
(n[31] = C ^ (~B & _)),
|
|
2334
2340
|
(n[32] = P ^ (~V & rn)),
|
|
@@ -2339,16 +2345,16 @@ function keccakPermutate(n) {
|
|
|
2339
2345
|
(n[37] = on ^ (~wn & C)),
|
|
2340
2346
|
(n[38] = gn ^ (~I & P)),
|
|
2341
2347
|
(n[39] = wn ^ (~C & B)),
|
|
2342
|
-
(n[40] = k ^ (~
|
|
2343
|
-
(n[41] = S ^ (~
|
|
2344
|
-
(n[42] =
|
|
2345
|
-
(n[43] =
|
|
2348
|
+
(n[40] = k ^ (~F & G)),
|
|
2349
|
+
(n[41] = S ^ (~z & Y)),
|
|
2350
|
+
(n[42] = F ^ (~G & X)),
|
|
2351
|
+
(n[43] = z ^ (~Y & nn)),
|
|
2346
2352
|
(n[44] = G ^ (~X & hn)),
|
|
2347
2353
|
(n[45] = Y ^ (~nn & pn)),
|
|
2348
2354
|
(n[46] = X ^ (~hn & k)),
|
|
2349
2355
|
(n[47] = nn ^ (~pn & S)),
|
|
2350
|
-
(n[48] = hn ^ (~k &
|
|
2351
|
-
(n[49] = pn ^ (~S &
|
|
2356
|
+
(n[48] = hn ^ (~k & F)),
|
|
2357
|
+
(n[49] = pn ^ (~S & z)),
|
|
2352
2358
|
(n[0] ^= IOTA_CONSTANTS[e * 2]),
|
|
2353
2359
|
(n[1] ^= IOTA_CONSTANTS[e * 2 + 1])
|
|
2354
2360
|
}
|
|
@@ -2452,6 +2458,15 @@ function binaryIndexOf(n, e, t = 0) {
|
|
|
2452
2458
|
for (let o = 0; o < e.length && n[r + o] === e[o]; o++) if (o === e.length - 1) return r
|
|
2453
2459
|
return -1
|
|
2454
2460
|
}
|
|
2461
|
+
function binaryPad(n, e) {
|
|
2462
|
+
if (n.length >= e) return n
|
|
2463
|
+
const t = new Uint8Array(e)
|
|
2464
|
+
return t.set(n, 0), t
|
|
2465
|
+
}
|
|
2466
|
+
function binaryPadToMultiple(n, e) {
|
|
2467
|
+
const t = n.length % e
|
|
2468
|
+
return t === 0 ? n : binaryPad(n, n.length + e - t)
|
|
2469
|
+
}
|
|
2455
2470
|
function binaryEquals(n, e) {
|
|
2456
2471
|
if (n.length !== e.length) return !1
|
|
2457
2472
|
for (let t = 0; t < n.length; t++) if (n[t] !== e[t]) return !1
|
|
@@ -2497,8 +2512,8 @@ function ellipticAdd(n, e, t, r, o) {
|
|
|
2497
2512
|
if (n === t && e === r) return ellipticDouble(n, e, o)
|
|
2498
2513
|
const i = mod((r - e) * modInverse(t - n, o), o),
|
|
2499
2514
|
u = mod(i * i - n - t, o),
|
|
2500
|
-
|
|
2501
|
-
return [u,
|
|
2515
|
+
f = mod(i * (n - u) - e, o)
|
|
2516
|
+
return [u, f]
|
|
2502
2517
|
}
|
|
2503
2518
|
function privateKeyToPublicKey(n) {
|
|
2504
2519
|
if (n <= 0n || n >= SECP256K1_N) throw new Error('Invalid private key')
|
|
@@ -2513,8 +2528,8 @@ function doubleAndAdd(n, e, t, r) {
|
|
|
2513
2528
|
let o = [0n, 0n],
|
|
2514
2529
|
i = [n, e]
|
|
2515
2530
|
const u = t.toString(2)
|
|
2516
|
-
for (const
|
|
2517
|
-
|
|
2531
|
+
for (const f of u)
|
|
2532
|
+
f === '0'
|
|
2518
2533
|
? ((i = ellipticAdd(o[0], o[1], i[0], i[1], r)), (o = ellipticDouble(o[0], o[1], r)))
|
|
2519
2534
|
: ((o = ellipticAdd(o[0], o[1], i[0], i[1], r)), (i = ellipticDouble(i[0], i[1], r)))
|
|
2520
2535
|
return o
|
|
@@ -2541,28 +2556,28 @@ function signHash(n, e, t) {
|
|
|
2541
2556
|
i = mod(o[0], SECP256K1_N)
|
|
2542
2557
|
let u = mod((r + mod(i, SECP256K1_N) * e) * modInverse(t, SECP256K1_N), SECP256K1_N)
|
|
2543
2558
|
if (i === 0n || u === 0n) throw new Error('Invalid r or s value')
|
|
2544
|
-
let
|
|
2545
|
-
return u > SECP256K1_N / 2n && ((u = SECP256K1_N - u), (
|
|
2559
|
+
let f = o[1] % 2n === 0n ? 27n : 28n
|
|
2560
|
+
return u > SECP256K1_N / 2n && ((u = SECP256K1_N - u), (f = f === 27n ? 28n : 27n)), [i, u, f]
|
|
2546
2561
|
}
|
|
2547
2562
|
function recoverPublicKey(n, e, t, r) {
|
|
2548
2563
|
const o = modSqrt(mod(e ** 3n + 7n, SECP256K1_P), SECP256K1_P)
|
|
2549
2564
|
if (!o) throw new Error('Invalid r: does not correspond to a valid curve point')
|
|
2550
2565
|
const i = r === 27n ? 0n : 1n,
|
|
2551
2566
|
u = o % 2n === i ? o : SECP256K1_P - o,
|
|
2552
|
-
|
|
2567
|
+
f = mod(uint256ToNumber(keccak256(n), 'BE'), SECP256K1_N),
|
|
2553
2568
|
c = doubleAndAdd(e, u, t, SECP256K1_P),
|
|
2554
|
-
|
|
2555
|
-
l = ellipticAdd(c[0], c[1],
|
|
2569
|
+
s = doubleAndAdd(SECP256K1_X, SECP256K1_Y, f, SECP256K1_P),
|
|
2570
|
+
l = ellipticAdd(c[0], c[1], s[0], mod(-s[1], SECP256K1_P), SECP256K1_P)
|
|
2556
2571
|
return doubleAndAdd(l[0], l[1], modInverse(e, SECP256K1_N), SECP256K1_P)
|
|
2557
2572
|
}
|
|
2558
2573
|
function verifySignature(n, e, t, r) {
|
|
2559
2574
|
const o = mod(uint256ToNumber(keccak256(n), 'BE'), SECP256K1_N),
|
|
2560
2575
|
i = modInverse(r, SECP256K1_N),
|
|
2561
2576
|
u = mod(o * i, SECP256K1_N),
|
|
2562
|
-
|
|
2577
|
+
f = mod(t * i, SECP256K1_N),
|
|
2563
2578
|
c = doubleAndAdd(SECP256K1_X, SECP256K1_Y, u, SECP256K1_P),
|
|
2564
|
-
|
|
2565
|
-
l = ellipticAdd(c[0], c[1],
|
|
2579
|
+
s = doubleAndAdd(e[0], e[1], f, SECP256K1_P),
|
|
2580
|
+
l = ellipticAdd(c[0], c[1], s[0], s[1], SECP256K1_P)
|
|
2566
2581
|
return t === mod(l[0], SECP256K1_N)
|
|
2567
2582
|
}
|
|
2568
2583
|
class Uint8ArrayReader {
|
|
@@ -2633,7 +2648,7 @@ function tickPlaybook(n) {
|
|
|
2633
2648
|
)
|
|
2634
2649
|
}
|
|
2635
2650
|
function getArgument(n, e, t, r) {
|
|
2636
|
-
const o = n.findIndex(
|
|
2651
|
+
const o = n.findIndex(f => f === `--${e}` || f.startsWith(`--${e}=`)),
|
|
2637
2652
|
i = n[o]
|
|
2638
2653
|
if (!i) return (t || {})[r || e || ''] || null
|
|
2639
2654
|
if (i.includes('=')) return i.split('=')[1]
|
|
@@ -2655,9 +2670,9 @@ function getBooleanArgument(n, e, t, r) {
|
|
|
2655
2670
|
if (!i && o) return !0
|
|
2656
2671
|
if (!i && !o) return null
|
|
2657
2672
|
const u = ['true', '1', 'yes', 'y', 'on'],
|
|
2658
|
-
|
|
2673
|
+
f = ['false', '0', 'no', 'n', 'off']
|
|
2659
2674
|
if (u.includes(i.toLowerCase())) return !0
|
|
2660
|
-
if (
|
|
2675
|
+
if (f.includes(i.toLowerCase())) return !1
|
|
2661
2676
|
throw Error(`Invalid boolean argument ${e}: ${i}`)
|
|
2662
2677
|
}
|
|
2663
2678
|
function requireStringArgument(n, e, t, r) {
|
|
@@ -2750,36 +2765,36 @@ function findCorners(n, e, t, r) {
|
|
|
2750
2765
|
]
|
|
2751
2766
|
for (let i = 0; i < n.length; i++)
|
|
2752
2767
|
for (let u = 0; u < n[0].length; u++) {
|
|
2753
|
-
const
|
|
2754
|
-
for (const c of
|
|
2768
|
+
const f = getCorners(n, i, u)
|
|
2769
|
+
for (const c of f) o.some(s => s.x === c.x && s.y === c.y) || o.push(c)
|
|
2755
2770
|
}
|
|
2756
2771
|
return o.map(i => ({ x: i.x * e, y: i.y * e }))
|
|
2757
2772
|
}
|
|
2758
2773
|
function findLines(n, e) {
|
|
2759
|
-
const t = filterCoordinates(n, (c,
|
|
2774
|
+
const t = filterCoordinates(n, (c, s) => n[c][s] === 0 && n[c][s + 1] !== 0, 'row-first').map(c => ({
|
|
2760
2775
|
...c,
|
|
2761
2776
|
dx: 1,
|
|
2762
2777
|
dy: 0
|
|
2763
2778
|
})),
|
|
2764
|
-
r = filterCoordinates(n, (c,
|
|
2779
|
+
r = filterCoordinates(n, (c, s) => n[c][s] === 0 && n[c][s - 1] !== 0, 'row-first').map(c => ({
|
|
2765
2780
|
...c,
|
|
2766
2781
|
dx: 1,
|
|
2767
2782
|
dy: 0
|
|
2768
2783
|
})),
|
|
2769
|
-
o = filterCoordinates(n, (c,
|
|
2784
|
+
o = filterCoordinates(n, (c, s) => n[c][s] === 0 && n[c - 1]?.[s] !== 0, 'column-first').map(c => ({
|
|
2770
2785
|
...c,
|
|
2771
2786
|
dx: 0,
|
|
2772
2787
|
dy: 1
|
|
2773
2788
|
})),
|
|
2774
|
-
i = filterCoordinates(n, (c,
|
|
2789
|
+
i = filterCoordinates(n, (c, s) => n[c][s] === 0 && n[c + 1]?.[s] !== 0, 'column-first').map(c => ({
|
|
2775
2790
|
...c,
|
|
2776
2791
|
dx: 0,
|
|
2777
2792
|
dy: 1
|
|
2778
2793
|
}))
|
|
2779
2794
|
t.forEach(c => c.y++), i.forEach(c => c.x++)
|
|
2780
|
-
const u = group([...o, ...i], (c,
|
|
2781
|
-
|
|
2782
|
-
return [...u, ...
|
|
2795
|
+
const u = group([...o, ...i], (c, s) => c.x === s.x && c.y - 1 === s.y),
|
|
2796
|
+
f = group([...r, ...t], (c, s) => c.y === s.y && c.x - 1 === s.x)
|
|
2797
|
+
return [...u, ...f]
|
|
2783
2798
|
.map(c => ({ start: c[0], end: last(c) }))
|
|
2784
2799
|
.map(c => ({
|
|
2785
2800
|
start: multiplyPoint(c.start, e),
|
|
@@ -2797,10 +2812,10 @@ function getLineIntersectionPoint(n, e, t, r) {
|
|
|
2797
2812
|
if (o === 0) return null
|
|
2798
2813
|
let i = n.y - t.y,
|
|
2799
2814
|
u = n.x - t.x
|
|
2800
|
-
const
|
|
2815
|
+
const f = (r.x - t.x) * i - (r.y - t.y) * u,
|
|
2801
2816
|
c = (e.x - n.x) * i - (e.y - n.y) * u
|
|
2802
2817
|
return (
|
|
2803
|
-
(i =
|
|
2818
|
+
(i = f / o),
|
|
2804
2819
|
(u = c / o),
|
|
2805
2820
|
i > 0 && i < 1 && u > 0 && u < 1 ? { x: n.x + i * (e.x - n.x), y: n.y + i * (e.y - n.y) } : null
|
|
2806
2821
|
)
|
|
@@ -2814,9 +2829,9 @@ function raycast(n, e, t) {
|
|
|
2814
2829
|
}
|
|
2815
2830
|
return r.length
|
|
2816
2831
|
? r.reduce((i, u) => {
|
|
2817
|
-
const
|
|
2832
|
+
const f = getDistanceBetweenPoints(n, u),
|
|
2818
2833
|
c = getDistanceBetweenPoints(n, i)
|
|
2819
|
-
return
|
|
2834
|
+
return f < c ? u : i
|
|
2820
2835
|
})
|
|
2821
2836
|
: null
|
|
2822
2837
|
}
|
|
@@ -2824,9 +2839,9 @@ function raycastCircle(n, e, t) {
|
|
|
2824
2839
|
const o = getSortedRayAngles(n, t),
|
|
2825
2840
|
i = []
|
|
2826
2841
|
for (const u of o) {
|
|
2827
|
-
const
|
|
2842
|
+
const f = raycast(n, e, u - 0.001),
|
|
2828
2843
|
c = raycast(n, e, u + 0.001)
|
|
2829
|
-
|
|
2844
|
+
f && i.push(f), c && i.push(c)
|
|
2830
2845
|
}
|
|
2831
2846
|
return i
|
|
2832
2847
|
}
|
|
@@ -2925,7 +2940,9 @@ class AsyncQueue {
|
|
|
2925
2940
|
setBit,
|
|
2926
2941
|
getBit,
|
|
2927
2942
|
indexOf: binaryIndexOf,
|
|
2928
|
-
equals: binaryEquals
|
|
2943
|
+
equals: binaryEquals,
|
|
2944
|
+
pad: binaryPad,
|
|
2945
|
+
padToMultiple: binaryPadToMultiple
|
|
2929
2946
|
}),
|
|
2930
2947
|
(exports.Elliptic = {
|
|
2931
2948
|
privateKeyToPublicKey,
|
|
@@ -3083,6 +3100,7 @@ class AsyncQueue {
|
|
|
3083
3100
|
match,
|
|
3084
3101
|
sort: sortObjectValues,
|
|
3085
3102
|
map: mapObject,
|
|
3103
|
+
mapIterable,
|
|
3086
3104
|
filterKeys: filterObjectKeys,
|
|
3087
3105
|
filterValues: filterObjectValues,
|
|
3088
3106
|
rethrow,
|