aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpukkamustard <pukkamustard@posteo.net>2021-04-08 09:11:08 +0200
committerpukkamustard <pukkamustard@posteo.net>2021-04-08 09:11:08 +0200
commit5037957151a03d9ca59d78124a8850c4318740fd (patch)
tree96cfb0e77ea1ae5bba90f3d5dc6a39d5ada75f7f
parent5901269753519ad67e2bb42ec3d9a9d258bf7310 (diff)
eris.js: Fix bug when padding node
-rw-r--r--src/eris.js15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/eris.js b/src/eris.js
index 1eb9570..121131b 100644
--- a/src/eris.js
+++ b/src/eris.js
@@ -162,12 +162,13 @@ async function addRefKeyToLevels (levels, level, reference, key) {
async function * forceCollect (levels, level, arity, convergenceSecret) {
// get the reference key pairs and concat them
- const rkPairs = levels.get(level).map(async function ({ reference, key }) {
- return concatUint8Array([reference, key])
- })
+ const rkPairs = levels.get(level).flatMap((rk) => [rk.reference, rk.key])
+
+ // how much padding is required
+ const numOfPadding = arity - (rkPairs.length / 2)
// padding
- const padding = Array(arity - rkPairs.length).fill(new Uint8Array(arity * 64))
+ const padding = Array(numOfPadding).fill(new Uint8Array(64))
// concat all reference-key pairs on level
const node = await concatUint8Array(rkPairs.concat(padding))
@@ -255,6 +256,12 @@ function encode (content, blockSize, convergenceSecret = new Uint8Array(32)) {
} else if (prototype === '[object Uint8Array]') {
const blocks = blockGenerator(content, blockSize)
return streamEncode(blocks, blockSize, convergenceSecret)
+ } else if (prototype === '[object ArrayBuffer]') {
+ const contentAsUint8 = new Uint8Array(content)
+ const blocks = blockGenerator(contentAsUint8, blockSize)
+ return streamEncode(blocks, blockSize, convergenceSecret)
+ } else {
+ throw new Error('Can not encode object of type ' + prototype)
}
}