cafe-utility 36.1.3 → 36.1.5
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 +18 -11
- 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 pendingEntries
|
|
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
|
@@ -2161,8 +2161,8 @@ function keccakPermutate(n) {
|
|
|
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] = 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 ^ (~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.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,24 +2659,31 @@ 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] = []), await 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
|
+
async sealParities(t) {
|
|
2670
|
+
const e = this.pendingEntries[t]
|
|
2671
|
+
if (!e?.length) return
|
|
2672
|
+
this.pendingEntries[t] = []
|
|
2673
|
+
const r = await this.onBatch(e)
|
|
2674
|
+
if (r.length > 0) {
|
|
2675
|
+
this.hasParity[t] = !0
|
|
2676
|
+
for (const { chunk: i } of r) this.chunks[t].writer.write(new Uint8ArrayReader(i.hash()))
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2669
2679
|
async flushBatch(t) {
|
|
2670
2680
|
this.chunks[t + 1] || (this.chunks.push(new Chunk()), this.counters.push(1), this.pending.push([]), this.hasParity.push(!1))
|
|
2671
2681
|
const e = this.pending[t]
|
|
2672
|
-
this.pending[t] = []
|
|
2673
|
-
const r
|
|
2674
|
-
for (const { ref: i, span: o } of e) await this.append(i, t + 1, o)
|
|
2675
|
-
r.length > 0 && (this.hasParity[t + 1] = !0)
|
|
2676
|
-
for (const { chunk: i } of r) this.chunks[t + 1].writer.max() === 0 && (await this.elevate(t + 1)), this.chunks[t + 1].writer.write(new Uint8ArrayReader(i.hash()))
|
|
2682
|
+
;(this.pending[t] = []), this.pendingEntries[t + 1] || (this.pendingEntries[t + 1] = []), this.pendingEntries[t + 1].push(...e.map(r => r.entry))
|
|
2683
|
+
for (const { ref: r, span: i } of e) await this.append(r, t + 1, i)
|
|
2677
2684
|
}
|
|
2678
2685
|
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])
|
|
2686
|
+
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])
|
|
2680
2687
|
}
|
|
2681
2688
|
}
|
|
2682
2689
|
;(exports.ChunkSplitter = ChunkSplitter), (_a = ChunkSplitter), (ChunkSplitter.NOOP = async n => [])
|