zkjson 0.1.4 → 0.1.6

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.
Files changed (2) hide show
  1. package/encoder.js +14 -3
  2. package/package.json +1 -1
package/encoder.js CHANGED
@@ -295,6 +295,8 @@ function encodeVal(v) {
295
295
  vals = [0]
296
296
  } else if (typeof v === "string") {
297
297
  vals = [3, v.length, ...v.split("").map(c => c.charCodeAt(0))]
298
+ } else {
299
+ vals = [4, ...encode(v)]
298
300
  }
299
301
  return vals
300
302
  }
@@ -317,6 +319,8 @@ function decodeVal(arr) {
317
319
  .slice(2)
318
320
  .map(c => String.fromCharCode(c))
319
321
  .join("")
322
+ } else if (type === 4) {
323
+ val = decode(arr.slice(1))
320
324
  }
321
325
  return val
322
326
  }
@@ -385,9 +389,12 @@ const str2id = str => {
385
389
  }
386
390
 
387
391
  const id2str = id => {
388
- id.shift()
389
- return splitEvery(2, id)
390
- .map(s => strMap[s])
392
+ let _id = id.toString().split("")
393
+ _id.shift()
394
+ return splitEvery(2, _id)
395
+ .map(s => {
396
+ return strMap[s.join("")]
397
+ })
391
398
  .join("")
392
399
  }
393
400
 
@@ -443,6 +450,8 @@ function str2val(arr) {
443
450
 
444
451
  const toSignal = val2str
445
452
  const fromSignal = str2val
453
+ const toIndex = str2id
454
+ const fromIndex = id2str
446
455
 
447
456
  module.exports = {
448
457
  encode,
@@ -460,4 +469,6 @@ module.exports = {
460
469
  id2str,
461
470
  toSignal,
462
471
  fromSignal,
472
+ toIndex,
473
+ fromIndex,
463
474
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zkjson",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Zero Knowledge Provable JSON",
5
5
  "main": "index.js",
6
6
  "license": "MIT",