cafe-utility 36.1.4 → 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 +1 -1
- package/index.js +16 -18
- 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
|
@@ -2154,8 +2154,8 @@ 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
|
+
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),
|
|
@@ -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 ^ (~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] =
|
|
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.
|
|
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,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] = []), this.sealParities(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
|
-
sealParities(t) {
|
|
2670
|
-
const e = this.
|
|
2671
|
-
if (e?.length)
|
|
2672
|
-
|
|
2673
|
-
|
|
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()))
|
|
2674
2677
|
}
|
|
2675
2678
|
}
|
|
2676
2679
|
async flushBatch(t) {
|
|
2677
2680
|
this.chunks[t + 1] || (this.chunks.push(new Chunk()), this.counters.push(1), this.pending.push([]), this.hasParity.push(!1))
|
|
2678
2681
|
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
|
-
}
|
|
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)
|
|
2686
2684
|
}
|
|
2687
2685
|
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])
|
|
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])
|
|
2689
2687
|
}
|
|
2690
2688
|
}
|
|
2691
2689
|
;(exports.ChunkSplitter = ChunkSplitter), (_a = ChunkSplitter), (ChunkSplitter.NOOP = async n => [])
|