cafe-utility 36.1.4 → 36.1.6
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 +1 -1
- package/index.js +31 -31
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -727,7 +727,7 @@ export declare class ChunkSplitter {
|
|
|
727
727
|
private onBatch
|
|
728
728
|
private onIntermediateChunk?
|
|
729
729
|
private hasParity
|
|
730
|
-
private
|
|
730
|
+
private pendingEntries
|
|
731
731
|
constructor(onBatch: (batch: ChunkEntry[]) => Promise<ChunkEntry[]>, maxShards?: number, encrypted?: boolean, onIntermediateChunk?: (chunk: Chunk, hasParity: boolean) => void)
|
|
732
732
|
static root(data: Uint8Array): Promise<Chunk>
|
|
733
733
|
static encryptedRoot(data: Uint8Array): Promise<{
|
package/index.js
CHANGED
|
@@ -2136,33 +2136,33 @@ function keccakPermutate(n) {
|
|
|
2136
2136
|
g = e ^ w,
|
|
2137
2137
|
y = r ^ x,
|
|
2138
2138
|
En = (u << 1) | (f >>> 31),
|
|
2139
|
-
|
|
2139
|
+
Sn = (f << 1) | (u >>> 31),
|
|
2140
2140
|
b = i ^ En,
|
|
2141
|
-
A = o ^
|
|
2142
|
-
|
|
2141
|
+
A = o ^ Sn,
|
|
2142
|
+
Mn = (l << 1) | (a >>> 31),
|
|
2143
2143
|
kn = (a << 1) | (l >>> 31),
|
|
2144
|
-
$ = s ^
|
|
2144
|
+
$ = s ^ Mn,
|
|
2145
2145
|
E = c ^ kn,
|
|
2146
2146
|
On = (e << 1) | (r >>> 31),
|
|
2147
2147
|
Tn = (r << 1) | (e >>> 31),
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
;(n[0] ^= d), (n[1] ^= m), (n[2] ^= g), (n[3] ^= y), (n[4] ^= b), (n[5] ^= A), (n[6] ^= $), (n[7] ^= E), (n[8] ^=
|
|
2148
|
+
S = u ^ On,
|
|
2149
|
+
M = f ^ Tn
|
|
2150
|
+
;(n[0] ^= d), (n[1] ^= m), (n[2] ^= g), (n[3] ^= y), (n[4] ^= b), (n[5] ^= A), (n[6] ^= $), (n[7] ^= E), (n[8] ^= S), (n[9] ^= M), (n[10] ^= d), (n[11] ^= m), (n[12] ^= g), (n[13] ^= y), (n[14] ^= b), (n[15] ^= A), (n[16] ^= $), (n[17] ^= E), (n[18] ^= S), (n[19] ^= M), (n[20] ^= d), (n[21] ^= m), (n[22] ^= g), (n[23] ^= y), (n[24] ^= b), (n[25] ^= A), (n[26] ^= $), (n[27] ^= E), (n[28] ^= S), (n[29] ^= M), (n[30] ^= d), (n[31] ^= m), (n[32] ^= g), (n[33] ^= y), (n[34] ^= b), (n[35] ^= A), (n[36] ^= $), (n[37] ^= E), (n[38] ^= S), (n[39] ^= M), (n[40] ^= d), (n[41] ^= m), (n[42] ^= g), (n[43] ^= y), (n[44] ^= b), (n[45] ^= A), (n[46] ^= $), (n[47] ^= E), (n[48] ^= S), (n[49] ^= M)
|
|
2151
2151
|
const k = n[0],
|
|
2152
2152
|
O = n[1],
|
|
2153
2153
|
T = (n[2] << 1) | (n[3] >>> 31),
|
|
2154
2154
|
C = (n[3] << 1) | (n[2] >>> 31),
|
|
2155
2155
|
R = (n[5] << 30) | (n[4] >>> 2),
|
|
2156
2156
|
I = (n[4] << 30) | (n[5] >>> 2),
|
|
2157
|
-
|
|
2158
|
-
|
|
2157
|
+
D = (n[6] << 28) | (n[7] >>> 4),
|
|
2158
|
+
P = (n[7] << 28) | (n[6] >>> 4),
|
|
2159
2159
|
B = (n[8] << 27) | (n[9] >>> 5),
|
|
2160
2160
|
U = (n[9] << 27) | (n[8] >>> 5),
|
|
2161
2161
|
j = (n[11] << 4) | (n[10] >>> 28),
|
|
2162
2162
|
L = (n[10] << 4) | (n[11] >>> 28),
|
|
2163
2163
|
N = (n[13] << 12) | (n[12] >>> 20),
|
|
2164
|
-
|
|
2165
|
-
|
|
2164
|
+
v = (n[12] << 12) | (n[13] >>> 20),
|
|
2165
|
+
F = (n[14] << 6) | (n[15] >>> 26),
|
|
2166
2166
|
z = (n[15] << 6) | (n[14] >>> 26),
|
|
2167
2167
|
W = (n[17] << 23) | (n[16] >>> 9),
|
|
2168
2168
|
q = (n[16] << 23) | (n[17] >>> 9),
|
|
@@ -2198,7 +2198,7 @@ function keccakPermutate(n) {
|
|
|
2198
2198
|
bn = (n[46] << 24) | (n[47] >>> 8),
|
|
2199
2199
|
An = (n[48] << 14) | (n[49] >>> 18),
|
|
2200
2200
|
$n = (n[49] << 14) | (n[48] >>> 18)
|
|
2201
|
-
;(n[0] = k ^ (~N & G)), (n[1] = O ^ (~
|
|
2201
|
+
;(n[0] = k ^ (~N & G)), (n[1] = O ^ (~v & _)), (n[2] = N ^ (~G & fn)), (n[3] = v ^ (~_ & ln)), (n[4] = G ^ (~fn & An)), (n[5] = _ ^ (~ln & $n)), (n[6] = fn ^ (~An & k)), (n[7] = ln ^ (~$n & O)), (n[8] = An ^ (~k & N)), (n[9] = $n ^ (~O & v)), (n[10] = D ^ (~H & J)), (n[11] = P ^ (~V & K)), (n[12] = H ^ (~J & on)), (n[13] = V ^ (~K & sn)), (n[14] = J ^ (~on & wn)), (n[15] = K ^ (~sn & xn)), (n[16] = on ^ (~wn & D)), (n[17] = sn ^ (~xn & P)), (n[18] = wn ^ (~D & H)), (n[19] = xn ^ (~P & V)), (n[20] = T ^ (~F & Y)), (n[21] = C ^ (~z & X)), (n[22] = F ^ (~Y & an)), (n[23] = z ^ (~X & hn)), (n[24] = Y ^ (~an & dn)), (n[25] = X ^ (~hn & pn)), (n[26] = an ^ (~dn & T)), (n[27] = hn ^ (~pn & C)), (n[28] = dn ^ (~T & F)), (n[29] = pn ^ (~C & z)), (n[30] = B ^ (~j & Z)), (n[31] = U ^ (~L & Q)), (n[32] = j ^ (~Z & cn)), (n[33] = L ^ (~Q & un)), (n[34] = Z ^ (~cn & yn)), (n[35] = Q ^ (~un & bn)), (n[36] = cn ^ (~yn & B)), (n[37] = un ^ (~bn & U)), (n[38] = yn ^ (~B & j)), (n[39] = bn ^ (~U & L)), (n[40] = R ^ (~W & nn)), (n[41] = I ^ (~q & tn)), (n[42] = W ^ (~nn & en)), (n[43] = q ^ (~tn & rn)), (n[44] = nn ^ (~en & mn)), (n[45] = tn ^ (~rn & gn)), (n[46] = en ^ (~mn & R)), (n[47] = rn ^ (~gn & I)), (n[48] = mn ^ (~R & W)), (n[49] = gn ^ (~I & q)), (n[0] ^= IOTA_CONSTANTS[t * 2]), (n[1] ^= IOTA_CONSTANTS[t * 2 + 1])
|
|
2202
2202
|
}
|
|
2203
2203
|
}
|
|
2204
2204
|
function bytesToNumbers(n) {
|
|
@@ -2640,7 +2640,7 @@ class Chunk {
|
|
|
2640
2640
|
;(exports.Chunk = Chunk), (Chunk.hashFunction = keccak256)
|
|
2641
2641
|
class ChunkSplitter {
|
|
2642
2642
|
constructor(t, e, r = !1, i) {
|
|
2643
|
-
;(this.counters = [1]), (this.pending = [[]]), (this.hasParity = [!1]), (this.
|
|
2643
|
+
;(this.counters = [1]), (this.pending = [[]]), (this.hasParity = [!1]), (this.pendingEntries = []), (this.encrypted = r), (this.refSize = r ? 64 : 32), (this.maxShards = e ?? 4096 / this.refSize), (this.chunks = [new Chunk()]), (this.onBatch = t), (this.onIntermediateChunk = i)
|
|
2644
2644
|
}
|
|
2645
2645
|
static async root(t) {
|
|
2646
2646
|
const e = new _a(_a.NOOP)
|
|
@@ -2659,33 +2659,33 @@ class ChunkSplitter {
|
|
|
2659
2659
|
}
|
|
2660
2660
|
}
|
|
2661
2661
|
async elevate(t) {
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2662
|
+
;(this.counters[t] = ++this.counters[t] % (4096 / this.refSize)), this.pending[t] || (this.pending[t] = []), await this.sealParities(t)
|
|
2663
|
+
const e = this.chunks[t].span
|
|
2664
|
+
if ((t >= 1 && this.onIntermediateChunk && (this.onIntermediateChunk(this.chunks[t], this.hasParity[t] ?? !1), (this.hasParity[t] = !1)), this.encrypted)) {
|
|
2665
|
+
const { address: r, key: i } = this.chunks[t].encryptedHash(),
|
|
2666
|
+
o = new Uint8Array(64)
|
|
2667
|
+
o.set(r), o.set(i, 32), this.pending[t].push({ entry: { chunk: this.chunks[t], key: i }, ref: o, span: e })
|
|
2668
|
+
} else this.pending[t].push({ entry: { chunk: this.chunks[t] }, ref: this.chunks[t].hash(), span: e })
|
|
2667
2669
|
;(this.chunks[t] = new Chunk()), this.pending[t].length >= this.maxShards && (await this.flushBatch(t))
|
|
2668
2670
|
}
|
|
2669
|
-
sealParities(t) {
|
|
2670
|
-
const e = this.
|
|
2671
|
-
if (e?.length)
|
|
2672
|
-
|
|
2673
|
-
|
|
2671
|
+
async sealParities(t) {
|
|
2672
|
+
const e = this.pendingEntries[t]
|
|
2673
|
+
if (!e?.length) return
|
|
2674
|
+
this.pendingEntries[t] = []
|
|
2675
|
+
const r = await this.onBatch(e)
|
|
2676
|
+
if (r.length > 0) {
|
|
2677
|
+
this.hasParity[t] = !0
|
|
2678
|
+
for (const { chunk: i } of r) this.chunks[t].writer.write(new Uint8ArrayReader(i.hash()))
|
|
2674
2679
|
}
|
|
2675
2680
|
}
|
|
2676
2681
|
async flushBatch(t) {
|
|
2677
2682
|
this.chunks[t + 1] || (this.chunks.push(new Chunk()), this.counters.push(1), this.pending.push([]), this.hasParity.push(!1))
|
|
2678
2683
|
const e = this.pending[t]
|
|
2679
|
-
this.pending[t] = []
|
|
2680
|
-
const r
|
|
2681
|
-
for (const { ref: i, span: o } of e) await this.append(i, t + 1, o)
|
|
2682
|
-
if (r.length > 0) {
|
|
2683
|
-
;(this.hasParity[t + 1] = !0), this.pendingParities[t + 1] || (this.pendingParities[t + 1] = [])
|
|
2684
|
-
for (const { chunk: i } of r) this.pendingParities[t + 1].push(i.hash())
|
|
2685
|
-
}
|
|
2684
|
+
;(this.pending[t] = []), this.pendingEntries[t + 1] || (this.pendingEntries[t + 1] = []), this.pendingEntries[t + 1].push(...e.map(r => r.entry))
|
|
2685
|
+
for (const { ref: r, span: i } of e) await this.append(r, t + 1, i)
|
|
2686
2686
|
}
|
|
2687
2687
|
async finalize(t = 0) {
|
|
2688
|
-
return this.pending[t]?.length && (await this.flushBatch(t)), this.chunks[t + 1] ? (this.counters[t] === 1 ? (await this.elevate(t + 1), await this.flushBatch(t + 1), (this.chunks[t + 1] = this.chunks[t]), this.finalize(t + 1)) : (await this.elevate(t), await this.flushBatch(t), this.finalize(t + 1))) : (this.sealParities(t), t >= 1 && this.onIntermediateChunk && this.onIntermediateChunk(this.chunks[t], this.hasParity[t] ?? !1), this.chunks[t])
|
|
2688
|
+
return this.pending[t]?.length && (await this.flushBatch(t)), this.chunks[t + 1] ? (this.counters[t] === 1 ? (await this.elevate(t + 1), await this.flushBatch(t + 1), (this.chunks[t + 1] = this.chunks[t]), this.finalize(t + 1)) : (await this.elevate(t), await this.flushBatch(t), this.finalize(t + 1))) : (await this.sealParities(t), t >= 1 && this.onIntermediateChunk && this.onIntermediateChunk(this.chunks[t], this.hasParity[t] ?? !1), this.chunks[t])
|
|
2689
2689
|
}
|
|
2690
2690
|
}
|
|
2691
2691
|
;(exports.ChunkSplitter = ChunkSplitter), (_a = ChunkSplitter), (ChunkSplitter.NOOP = async n => [])
|