aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpukkamustard <pukkamustard@posteo.net>2020-06-05 15:48:47 +0200
committerpukkamustard <pukkamustard@posteo.net>2020-06-05 15:48:47 +0200
commit8732b575759469c38b2280f720d2ff34205ad0f6 (patch)
treeaae0d0bd49e47990e7c35375fcab9edcc0929b2e
parentd73659c8ee4931687357f12cfc79e3e966cd20c7 (diff)
compute nonce from position
-rw-r--r--eris/index.js20
1 files changed, 17 insertions, 3 deletions
diff --git a/eris/index.js b/eris/index.js
index 988f91e..bb26b0d 100644
--- a/eris/index.js
+++ b/eris/index.js
@@ -32,11 +32,24 @@ async function * blockGenerator (buffer, blockSize = 4096) {
if (buffer.lenght > 0) yield buffer
}
+function baseEncode (n, encoded = []) {
+ if (n > 0) {
+ const r = n % 128
+ encoded.push(r)
+ return baseEncode((n - r) / 128, encoded)
+ } else {
+ return encoded.reverse()
+ }
+}
+
/* Compute nonce from node position (level and count)
*/
function nodeNonce (level, count) {
- // TODO
- return new Uint8Array(12)
+ const baseEncoded = baseEncode(count)
+ const levelShift = new Array(level - 1).fill(255)
+ const padding = new Array(12 - level + 1 - baseEncoded.length).fill(0)
+
+ return Uint8Array.from(padding.concat(baseEncoded).concat(levelShift))
}
async function buildMerkleTree (input, verificationKey, cas) {
@@ -161,5 +174,6 @@ async function put (content, cas = new NullContentAddressableStorage()) {
module.exports = {
ContentAddressableStorage: ContentAddressableStorage,
NullContentAddressableStorage: NullContentAddressableStorage,
- put: put
+ put: put,
+ blockGenerator: blockGenerator
}