cafe-utility 36.1.3 → 36.1.4
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 +2 -0
- package/index.js +19 -10
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -727,6 +727,7 @@ export declare class ChunkSplitter {
|
|
|
727
727
|
private onBatch
|
|
728
728
|
private onIntermediateChunk?
|
|
729
729
|
private hasParity
|
|
730
|
+
private pendingParities
|
|
730
731
|
constructor(onBatch: (batch: ChunkEntry[]) => Promise<ChunkEntry[]>, maxShards?: number, encrypted?: boolean, onIntermediateChunk?: (chunk: Chunk, hasParity: boolean) => void)
|
|
731
732
|
static root(data: Uint8Array): Promise<Chunk>
|
|
732
733
|
static encryptedRoot(data: Uint8Array): Promise<{
|
|
@@ -735,6 +736,7 @@ export declare class ChunkSplitter {
|
|
|
735
736
|
}>
|
|
736
737
|
append(data: Uint8Array, level?: number, spanIncrement?: bigint): Promise<void>
|
|
737
738
|
private elevate
|
|
739
|
+
private sealParities
|
|
738
740
|
private flushBatch
|
|
739
741
|
finalize(level?: number): Promise<Chunk>
|
|
740
742
|
}
|
package/index.js
CHANGED
|
@@ -2154,15 +2154,15 @@ function keccakPermutate(n) {
|
|
|
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
|
+
P = (n[6] << 28) | (n[7] >>> 4),
|
|
2158
|
+
D = (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
|
+
F = (n[12] << 12) | (n[13] >>> 20),
|
|
2165
|
+
v = (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 ^ (~F & _)), (n[2] = N ^ (~G & fn)), (n[3] = F ^ (~_ & 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 & F)), (n[10] = P ^ (~H & J)), (n[11] = D ^ (~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 & P)), (n[17] = sn ^ (~xn & D)), (n[18] = wn ^ (~P & H)), (n[19] = xn ^ (~D & V)), (n[20] = T ^ (~v & Y)), (n[21] = C ^ (~z & X)), (n[22] = v ^ (~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 & v)), (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.encrypted = r), (this.refSize = r ? 64 : 32), (this.maxShards = e ?? 4096 / this.refSize), (this.chunks = [new Chunk()]), (this.onBatch = t), (this.onIntermediateChunk = i)
|
|
2643
|
+
;(this.counters = [1]), (this.pending = [[]]), (this.hasParity = [!1]), (this.pendingParities = []), (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,24 +2659,33 @@ class ChunkSplitter {
|
|
|
2659
2659
|
}
|
|
2660
2660
|
}
|
|
2661
2661
|
async elevate(t) {
|
|
2662
|
-
if (((this.counters[t] = ++this.counters[t] % (4096 / this.refSize)), this.pending[t] || (this.pending[t] = []), t >= 1 && this.onIntermediateChunk && (this.onIntermediateChunk(this.chunks[t], this.hasParity[t] ?? !1), (this.hasParity[t] = !1)), this.encrypted)) {
|
|
2662
|
+
if (((this.counters[t] = ++this.counters[t] % (4096 / this.refSize)), this.pending[t] || (this.pending[t] = []), this.sealParities(t), t >= 1 && this.onIntermediateChunk && (this.onIntermediateChunk(this.chunks[t], this.hasParity[t] ?? !1), (this.hasParity[t] = !1)), this.encrypted)) {
|
|
2663
2663
|
const { address: e, key: r } = this.chunks[t].encryptedHash(),
|
|
2664
2664
|
i = new Uint8Array(64)
|
|
2665
2665
|
i.set(e), i.set(r, 32), this.pending[t].push({ entry: { chunk: this.chunks[t], key: r }, ref: i, span: this.chunks[t].span })
|
|
2666
2666
|
} else this.pending[t].push({ entry: { chunk: this.chunks[t] }, ref: this.chunks[t].hash(), span: this.chunks[t].span })
|
|
2667
2667
|
;(this.chunks[t] = new Chunk()), this.pending[t].length >= this.maxShards && (await this.flushBatch(t))
|
|
2668
2668
|
}
|
|
2669
|
+
sealParities(t) {
|
|
2670
|
+
const e = this.pendingParities[t]
|
|
2671
|
+
if (e?.length) {
|
|
2672
|
+
this.pendingParities[t] = []
|
|
2673
|
+
for (const r of e) this.chunks[t].writer.write(new Uint8ArrayReader(r))
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2669
2676
|
async flushBatch(t) {
|
|
2670
2677
|
this.chunks[t + 1] || (this.chunks.push(new Chunk()), this.counters.push(1), this.pending.push([]), this.hasParity.push(!1))
|
|
2671
2678
|
const e = this.pending[t]
|
|
2672
2679
|
this.pending[t] = []
|
|
2673
2680
|
const r = await this.onBatch(e.map(i => i.entry))
|
|
2674
2681
|
for (const { ref: i, span: o } of e) await this.append(i, t + 1, o)
|
|
2675
|
-
r.length > 0
|
|
2676
|
-
|
|
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
|
+
}
|
|
2677
2686
|
}
|
|
2678
2687
|
async finalize(t = 0) {
|
|
2679
|
-
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))) : (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))) : (this.sealParities(t), t >= 1 && this.onIntermediateChunk && this.onIntermediateChunk(this.chunks[t], this.hasParity[t] ?? !1), this.chunks[t])
|
|
2680
2689
|
}
|
|
2681
2690
|
}
|
|
2682
2691
|
;(exports.ChunkSplitter = ChunkSplitter), (_a = ChunkSplitter), (ChunkSplitter.NOOP = async n => [])
|