zkjson 0.2.3 → 0.3.0

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/collection.js CHANGED
@@ -3,12 +3,7 @@ const { pad, toSignal, id2str, encode, toIndex } = require("./encoder")
3
3
  const Doc = require("./doc")
4
4
 
5
5
  class Collection {
6
- constructor({
7
- size_val = 256,
8
- size_path = 256,
9
- size_json = 256,
10
- level = 168,
11
- }) {
6
+ constructor({ size_val = 8, size_path = 4, size_json = 256, level = 168 }) {
12
7
  this.size_val = size_val
13
8
  this.size_path = size_path
14
9
  this.size_json = size_json
package/db.js CHANGED
@@ -1,13 +1,13 @@
1
1
  const newMemEmptyTrie = require("./circomlibjs").newMemEmptyTrie
2
2
  const snarkjs = require("snarkjs")
3
- const { range } = require("ramda")
3
+ const { indexOf, range, isNil } = require("ramda")
4
4
  const { pad, toSignal, encode, toIndex } = require("./encoder")
5
5
  const Collection = require("./collection")
6
6
 
7
7
  class DB {
8
8
  constructor({
9
- size_val = 256,
10
- size_path = 256,
9
+ size_val = 8,
10
+ size_path = 4,
11
11
  level = 168,
12
12
  size_json = 256,
13
13
  size_txs = 10,
@@ -28,6 +28,7 @@ class DB {
28
28
  this.size_json = size_json
29
29
  this.size_txs = size_txs
30
30
  this.count = 0
31
+ this.ids = []
31
32
  }
32
33
 
33
34
  async init() {
@@ -277,9 +278,23 @@ class DB {
277
278
  col_root,
278
279
  }
279
280
  }
280
-
281
- async addCollection() {
282
- const id = this.count++
281
+ getID(num) {
282
+ if (!isNil(num)) {
283
+ if (indexOf(+num)(this.ids) !== -1) {
284
+ throw Error("id exists")
285
+ }
286
+ } else {
287
+ while (indexOf(this.count)(this.ids) !== -1) {
288
+ this.count++
289
+ }
290
+ return this.count++
291
+ }
292
+ }
293
+ async addCollection(num) {
294
+ if (!isNil(num) && (Math.round(num) !== +num || Number.isNaN(+num))) {
295
+ throw Error("id is not numeric")
296
+ }
297
+ const id = this.getID(num)
283
298
  const col = await this.tree.find(id)
284
299
  if (col.found) throw Error("collection exists")
285
300
  const _col = new Collection({
package/doc.js CHANGED
@@ -11,13 +11,7 @@ const {
11
11
  } = require("./encoder")
12
12
 
13
13
  module.exports = class Doc {
14
- constructor({
15
- size_val = 256,
16
- size_path = 256,
17
- size_json = 256,
18
- wasm,
19
- zkey,
20
- }) {
14
+ constructor({ size_val = 8, size_path = 4, size_json = 256, wasm, zkey }) {
21
15
  this.size_val = size_val
22
16
  this.size_path = size_path
23
17
  this.size_json = size_json
package/json.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const { pad, toSignal, encode, encodePath, encodeVal } = require("./encoder")
2
2
 
3
3
  module.exports = class Json {
4
- constructor({ size_val = 256, size_path = 256, size_json = 256 }) {
4
+ constructor({ size_val = 8, size_path = 4, size_json = 256 }) {
5
5
  this.size_val = size_val
6
6
  this.size_path = size_path
7
7
  this.size_json = size_json
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zkjson",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "Zero Knowledge Provable JSON",
5
5
  "main": "index.js",
6
6
  "license": "MIT",