zkjson 0.6.0 → 1.0.2

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 (187) hide show
  1. package/README.md +537 -0
  2. package/assets/collection.png +0 -0
  3. package/assets/db.png +0 -0
  4. package/assets/encode.png +0 -0
  5. package/assets/query.png +0 -0
  6. package/assets/rollup.png +0 -0
  7. package/assets/structure.png +0 -0
  8. package/assets/weavedb.png +0 -0
  9. package/assets/zkjson.png +0 -0
  10. package/benchmark/components/ui/avatar.jsx +49 -0
  11. package/benchmark/components/ui/checkbox.jsx +17 -0
  12. package/benchmark/components/ui/close-button.jsx +20 -0
  13. package/benchmark/components/ui/color-mode.jsx +89 -0
  14. package/benchmark/components/ui/dialog.jsx +54 -0
  15. package/benchmark/components/ui/drawer.jsx +44 -0
  16. package/benchmark/components/ui/field.jsx +22 -0
  17. package/benchmark/components/ui/input-group.jsx +39 -0
  18. package/benchmark/components/ui/popover.jsx +49 -0
  19. package/benchmark/components/ui/provider.jsx +12 -0
  20. package/benchmark/components/ui/radio.jsx +17 -0
  21. package/benchmark/components/ui/slider.jsx +107 -0
  22. package/benchmark/components/ui/tooltip.jsx +35 -0
  23. package/benchmark/jsconfig.json +7 -0
  24. package/benchmark/lib/cbor.js +387 -0
  25. package/benchmark/lib/msgpack.js +651 -0
  26. package/benchmark/next.config.mjs +6 -0
  27. package/benchmark/package.json +22 -0
  28. package/benchmark/pages/_app.js +9 -0
  29. package/benchmark/pages/_document.js +13 -0
  30. package/benchmark/pages/api/hello.js +5 -0
  31. package/benchmark/pages/index.js +438 -0
  32. package/benchmark/public/favicon.ico +0 -0
  33. package/benchmark/public/file.svg +1 -0
  34. package/benchmark/public/globe.svg +1 -0
  35. package/benchmark/public/next.svg +1 -0
  36. package/benchmark/public/vercel.svg +1 -0
  37. package/benchmark/public/window.svg +1 -0
  38. package/benchmark/yarn.lock +2448 -0
  39. package/circom/collection/collection.circom +32 -0
  40. package/circom/collection/compile.sh +10 -0
  41. package/circom/collection/gen.js +34 -0
  42. package/circom/collection/generateInput.js +10 -0
  43. package/circom/collection/index.circom +4 -0
  44. package/circom/collection/test.js +21 -0
  45. package/circom/collection/verifier.sol +247 -0
  46. package/circom/db/compile.sh +10 -0
  47. package/circom/db/db.circom +39 -0
  48. package/circom/db/gen.js +30 -0
  49. package/circom/db/generateInput.js +10 -0
  50. package/circom/db/index.circom +4 -0
  51. package/circom/db/test.js +21 -0
  52. package/circom/db/verifier.sol +261 -0
  53. package/circom/ipfs/calculate_total.circom +17 -0
  54. package/circom/ipfs/compile.sh +10 -0
  55. package/circom/ipfs/gen.js +18 -0
  56. package/circom/ipfs/generateInput.js +10 -0
  57. package/circom/ipfs/index.circom +4 -0
  58. package/circom/ipfs/ipfs.circom +62 -0
  59. package/circom/ipfs/parse.circom +289 -0
  60. package/circom/ipfs/sha256.circom +99 -0
  61. package/circom/ipfs/test.js +167 -0
  62. package/circom/ipfs/verifier.sol +261 -0
  63. package/circom/json/compile.sh +10 -0
  64. package/circom/json/gen.js +22 -0
  65. package/circom/json/gen2.js +21 -0
  66. package/circom/json/generateInput.js +20 -0
  67. package/circom/json/index.circom +4 -0
  68. package/circom/json/json.circom +81 -0
  69. package/circom/json/test.js +100 -0
  70. package/circom/json/verifier.sol +247 -0
  71. package/circom/query/compile.sh +10 -0
  72. package/circom/query/gen.js +28 -0
  73. package/circom/query/generateInput.js +11 -0
  74. package/circom/query/index.circom +4 -0
  75. package/circom/query/query.circom +58 -0
  76. package/circom/query/test.js +20 -0
  77. package/circom/query/verifier.sol +177 -0
  78. package/circom/rollup/compile.sh +10 -0
  79. package/circom/rollup/gen.js +36 -0
  80. package/circom/rollup/generateInput.js +11 -0
  81. package/circom/rollup/index.circom +4 -0
  82. package/circom/rollup/rollup.circom +43 -0
  83. package/circom/rollup/test.js +35 -0
  84. package/circom/rollup/verifier.sol +240 -0
  85. package/circom/scripts/ceremony.js +39 -0
  86. package/circom/scripts/ceremony.sh +6 -0
  87. package/circom/scripts/compile.js +113 -0
  88. package/circom/scripts/compile.sh +16 -0
  89. package/circom/utils/uint.circom +512 -0
  90. package/circom/utils/utils.circom +628 -0
  91. package/demos/arweave/jsconfig.json +7 -0
  92. package/demos/arweave/lib/ZKArweave.json +617 -0
  93. package/demos/arweave/lib/encoder.js +375 -0
  94. package/demos/arweave/next.config.js +6 -0
  95. package/demos/arweave/package.json +26 -0
  96. package/demos/arweave/pages/_app.js +9 -0
  97. package/demos/arweave/pages/_document.js +19 -0
  98. package/demos/arweave/pages/api/arweave.js +31 -0
  99. package/demos/arweave/pages/api/hello.js +5 -0
  100. package/demos/arweave/pages/index.js +869 -0
  101. package/demos/arweave/public/circuit.wasm +0 -0
  102. package/demos/arweave/public/circuit_final.zkey +0 -0
  103. package/demos/arweave/public/verification_key.json +149 -0
  104. package/demos/arweave/vercel.json +7 -0
  105. package/demos/arweave/yarn.lock +2510 -0
  106. package/demos/simple/jsconfig.json +7 -0
  107. package/demos/simple/lib/encoder.js +375 -0
  108. package/demos/simple/next.config.js +6 -0
  109. package/demos/simple/package.json +24 -0
  110. package/demos/simple/pages/_app.js +9 -0
  111. package/demos/simple/pages/_document.js +13 -0
  112. package/demos/simple/pages/api/hello.js +5 -0
  113. package/demos/simple/pages/index.js +342 -0
  114. package/demos/simple/public/circuit.wasm +0 -0
  115. package/demos/simple/public/circuit_final.zkey +0 -0
  116. package/demos/simple/public/verification_key.json +149 -0
  117. package/demos/simple/yarn.lock +2519 -0
  118. package/docs/README.md +17 -0
  119. package/docs/simple-zkjson.md +210 -0
  120. package/docs/solidity-contracts.md +216 -0
  121. package/docs/zk-circuits.md +125 -0
  122. package/docs/zkdb-rollup.md +218 -0
  123. package/docs/zkjson-sdk.md +254 -0
  124. package/docs/zkjson-v1_5.md +365 -0
  125. package/package.json +16 -7
  126. package/sdk/contracts/NORollup.sol +13 -0
  127. package/sdk/package.json +15 -0
  128. package/sdk/yarn.lock +881 -0
  129. package/solidity/README.md +13 -0
  130. package/solidity/arguments.js +4 -0
  131. package/solidity/contracts/NORollup.sol +13 -0
  132. package/solidity/contracts/OPRollup.sol +14 -0
  133. package/solidity/contracts/ZKIPFS.sol +95 -0
  134. package/solidity/contracts/ZKJson.sol +21 -0
  135. package/solidity/contracts/ZKQuery.sol +286 -0
  136. package/solidity/contracts/ZKRollup.sol +35 -0
  137. package/solidity/contracts/apps/NORU.sol +66 -0
  138. package/solidity/contracts/apps/SimpleJSON.sol +64 -0
  139. package/solidity/contracts/apps/SimpleOPRU.sol +67 -0
  140. package/solidity/contracts/apps/SimpleRU.sol +67 -0
  141. package/solidity/contracts/apps/Token.sol +12 -0
  142. package/solidity/contracts/apps/ZKArweave.sol +89 -0
  143. package/solidity/contracts/apps/ZKBridge.sol +74 -0
  144. package/solidity/contracts/apps/ZKNFT.sol +63 -0
  145. package/solidity/contracts/verifiers/verifier_db.sol +275 -0
  146. package/solidity/contracts/verifiers/verifier_ipfs.sol +464 -0
  147. package/solidity/contracts/verifiers/verifier_json.sol +261 -0
  148. package/solidity/contracts/verifiers/verifier_rollup.sol +240 -0
  149. package/solidity/package.json +27 -0
  150. package/solidity/scripts/deploy.js +33 -0
  151. package/solidity/test/NORU.js +66 -0
  152. package/solidity/test/ZKArweave.js +97 -0
  153. package/solidity/test/arweave.js +55 -0
  154. package/solidity/test/bridge.js +71 -0
  155. package/solidity/test/simple.js +76 -0
  156. package/solidity/test/simpleOPRU.js +98 -0
  157. package/solidity/test/simpleRU.js +94 -0
  158. package/solidity/test/zknft.js +98 -0
  159. package/solidity/yarn.lock +4152 -0
  160. package/test/test.js +304 -0
  161. /package/{circomlibjs.js → sdk/circomlibjs.js} +0 -0
  162. /package/{collection.js → sdk/collection.js} +0 -0
  163. /package/{contracts → sdk/contracts}/OPRollup.sol +0 -0
  164. /package/{contracts → sdk/contracts}/ZKIPFS.sol +0 -0
  165. /package/{contracts → sdk/contracts}/ZKJson.sol +0 -0
  166. /package/{contracts → sdk/contracts}/ZKQuery.sol +0 -0
  167. /package/{contracts → sdk/contracts}/ZKRollup.sol +0 -0
  168. /package/{contracts → sdk/contracts}/apps/SimpleJSON.sol +0 -0
  169. /package/{contracts → sdk/contracts}/apps/SimpleOPRU.sol +0 -0
  170. /package/{contracts → sdk/contracts}/apps/SimpleRU.sol +0 -0
  171. /package/{contracts → sdk/contracts}/apps/Token.sol +0 -0
  172. /package/{contracts → sdk/contracts}/apps/ZKArweave.sol +0 -0
  173. /package/{contracts → sdk/contracts}/apps/ZKBridge.sol +0 -0
  174. /package/{contracts → sdk/contracts}/apps/ZKNFT.sol +0 -0
  175. /package/{contracts → sdk/contracts}/verifiers/verifier_db.sol +0 -0
  176. /package/{contracts → sdk/contracts}/verifiers/verifier_ipfs.sol +0 -0
  177. /package/{contracts → sdk/contracts}/verifiers/verifier_json.sol +0 -0
  178. /package/{contracts → sdk/contracts}/verifiers/verifier_rollup.sol +0 -0
  179. /package/{db.js → sdk/db.js} +0 -0
  180. /package/{doc.js → sdk/doc.js} +0 -0
  181. /package/{encoder-v1_5.js → sdk/encoder-v1_5.js} +0 -0
  182. /package/{encoder.js → sdk/encoder.js} +0 -0
  183. /package/{index.js → sdk/index.js} +0 -0
  184. /package/{json.js → sdk/json.js} +0 -0
  185. /package/{nft.js → sdk/nft.js} +0 -0
  186. /package/{parse.js → sdk/parse.js} +0 -0
  187. /package/{uint.js → sdk/uint.js} +0 -0
@@ -0,0 +1,387 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2014-2016 Patrick Gansterer <paroga@paroga.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ ;(function (global, undefined) {
26
+ "use strict"
27
+ var POW_2_24 = 5.960464477539063e-8,
28
+ POW_2_32 = 4294967296,
29
+ POW_2_53 = 9007199254740992
30
+
31
+ function encode(value) {
32
+ var data = new ArrayBuffer(256)
33
+ var dataView = new DataView(data)
34
+ var lastLength
35
+ var offset = 0
36
+
37
+ function prepareWrite(length) {
38
+ var newByteLength = data.byteLength
39
+ var requiredLength = offset + length
40
+ while (newByteLength < requiredLength) newByteLength <<= 1
41
+ if (newByteLength !== data.byteLength) {
42
+ var oldDataView = dataView
43
+ data = new ArrayBuffer(newByteLength)
44
+ dataView = new DataView(data)
45
+ var uint32count = (offset + 3) >> 2
46
+ for (var i = 0; i < uint32count; ++i)
47
+ dataView.setUint32(i << 2, oldDataView.getUint32(i << 2))
48
+ }
49
+
50
+ lastLength = length
51
+ return dataView
52
+ }
53
+ function commitWrite() {
54
+ offset += lastLength
55
+ }
56
+ function writeFloat64(value) {
57
+ commitWrite(prepareWrite(8).setFloat64(offset, value))
58
+ }
59
+ function writeUint8(value) {
60
+ commitWrite(prepareWrite(1).setUint8(offset, value))
61
+ }
62
+ function writeUint8Array(value) {
63
+ var dataView = prepareWrite(value.length)
64
+ for (var i = 0; i < value.length; ++i)
65
+ dataView.setUint8(offset + i, value[i])
66
+ commitWrite()
67
+ }
68
+ function writeUint16(value) {
69
+ commitWrite(prepareWrite(2).setUint16(offset, value))
70
+ }
71
+ function writeUint32(value) {
72
+ commitWrite(prepareWrite(4).setUint32(offset, value))
73
+ }
74
+ function writeUint64(value) {
75
+ var low = value % POW_2_32
76
+ var high = (value - low) / POW_2_32
77
+ var dataView = prepareWrite(8)
78
+ dataView.setUint32(offset, high)
79
+ dataView.setUint32(offset + 4, low)
80
+ commitWrite()
81
+ }
82
+ function writeTypeAndLength(type, length) {
83
+ if (length < 24) {
84
+ writeUint8((type << 5) | length)
85
+ } else if (length < 0x100) {
86
+ writeUint8((type << 5) | 24)
87
+ writeUint8(length)
88
+ } else if (length < 0x10000) {
89
+ writeUint8((type << 5) | 25)
90
+ writeUint16(length)
91
+ } else if (length < 0x100000000) {
92
+ writeUint8((type << 5) | 26)
93
+ writeUint32(length)
94
+ } else {
95
+ writeUint8((type << 5) | 27)
96
+ writeUint64(length)
97
+ }
98
+ }
99
+
100
+ function encodeItem(value) {
101
+ var i
102
+
103
+ if (value === false) return writeUint8(0xf4)
104
+ if (value === true) return writeUint8(0xf5)
105
+ if (value === null) return writeUint8(0xf6)
106
+ if (value === undefined) return writeUint8(0xf7)
107
+
108
+ switch (typeof value) {
109
+ case "number":
110
+ if (Math.floor(value) === value) {
111
+ if (0 <= value && value <= POW_2_53)
112
+ return writeTypeAndLength(0, value)
113
+ if (-POW_2_53 <= value && value < 0)
114
+ return writeTypeAndLength(1, -(value + 1))
115
+ }
116
+ writeUint8(0xfb)
117
+ return writeFloat64(value)
118
+
119
+ case "string":
120
+ var utf8data = []
121
+ for (i = 0; i < value.length; ++i) {
122
+ var charCode = value.charCodeAt(i)
123
+ if (charCode < 0x80) {
124
+ utf8data.push(charCode)
125
+ } else if (charCode < 0x800) {
126
+ utf8data.push(0xc0 | (charCode >> 6))
127
+ utf8data.push(0x80 | (charCode & 0x3f))
128
+ } else if (charCode < 0xd800) {
129
+ utf8data.push(0xe0 | (charCode >> 12))
130
+ utf8data.push(0x80 | ((charCode >> 6) & 0x3f))
131
+ utf8data.push(0x80 | (charCode & 0x3f))
132
+ } else {
133
+ charCode = (charCode & 0x3ff) << 10
134
+ charCode |= value.charCodeAt(++i) & 0x3ff
135
+ charCode += 0x10000
136
+
137
+ utf8data.push(0xf0 | (charCode >> 18))
138
+ utf8data.push(0x80 | ((charCode >> 12) & 0x3f))
139
+ utf8data.push(0x80 | ((charCode >> 6) & 0x3f))
140
+ utf8data.push(0x80 | (charCode & 0x3f))
141
+ }
142
+ }
143
+
144
+ writeTypeAndLength(3, utf8data.length)
145
+ return writeUint8Array(utf8data)
146
+
147
+ default:
148
+ var length
149
+ if (Array.isArray(value)) {
150
+ length = value.length
151
+ writeTypeAndLength(4, length)
152
+ for (i = 0; i < length; ++i) encodeItem(value[i])
153
+ } else if (value instanceof Uint8Array) {
154
+ writeTypeAndLength(2, value.length)
155
+ writeUint8Array(value)
156
+ } else {
157
+ var keys = Object.keys(value)
158
+ length = keys.length
159
+ writeTypeAndLength(5, length)
160
+ for (i = 0; i < length; ++i) {
161
+ var key = keys[i]
162
+ encodeItem(key)
163
+ encodeItem(value[key])
164
+ }
165
+ }
166
+ }
167
+ }
168
+
169
+ encodeItem(value)
170
+
171
+ if ("slice" in data) return data.slice(0, offset)
172
+
173
+ var ret = new ArrayBuffer(offset)
174
+ var retView = new DataView(ret)
175
+ for (var i = 0; i < offset; ++i) retView.setUint8(i, dataView.getUint8(i))
176
+ return ret
177
+ }
178
+
179
+ function decode(data, tagger, simpleValue) {
180
+ var dataView = new DataView(data)
181
+ var offset = 0
182
+
183
+ if (typeof tagger !== "function")
184
+ tagger = function (value) {
185
+ return value
186
+ }
187
+ if (typeof simpleValue !== "function")
188
+ simpleValue = function () {
189
+ return undefined
190
+ }
191
+
192
+ function commitRead(length, value) {
193
+ offset += length
194
+ return value
195
+ }
196
+ function readArrayBuffer(length) {
197
+ return commitRead(length, new Uint8Array(data, offset, length))
198
+ }
199
+ function readFloat16() {
200
+ var tempArrayBuffer = new ArrayBuffer(4)
201
+ var tempDataView = new DataView(tempArrayBuffer)
202
+ var value = readUint16()
203
+
204
+ var sign = value & 0x8000
205
+ var exponent = value & 0x7c00
206
+ var fraction = value & 0x03ff
207
+
208
+ if (exponent === 0x7c00) exponent = 0xff << 10
209
+ else if (exponent !== 0) exponent += (127 - 15) << 10
210
+ else if (fraction !== 0) return (sign ? -1 : 1) * fraction * POW_2_24
211
+
212
+ tempDataView.setUint32(
213
+ 0,
214
+ (sign << 16) | (exponent << 13) | (fraction << 13),
215
+ )
216
+ return tempDataView.getFloat32(0)
217
+ }
218
+ function readFloat32() {
219
+ return commitRead(4, dataView.getFloat32(offset))
220
+ }
221
+ function readFloat64() {
222
+ return commitRead(8, dataView.getFloat64(offset))
223
+ }
224
+ function readUint8() {
225
+ return commitRead(1, dataView.getUint8(offset))
226
+ }
227
+ function readUint16() {
228
+ return commitRead(2, dataView.getUint16(offset))
229
+ }
230
+ function readUint32() {
231
+ return commitRead(4, dataView.getUint32(offset))
232
+ }
233
+ function readUint64() {
234
+ return readUint32() * POW_2_32 + readUint32()
235
+ }
236
+ function readBreak() {
237
+ if (dataView.getUint8(offset) !== 0xff) return false
238
+ offset += 1
239
+ return true
240
+ }
241
+ function readLength(additionalInformation) {
242
+ if (additionalInformation < 24) return additionalInformation
243
+ if (additionalInformation === 24) return readUint8()
244
+ if (additionalInformation === 25) return readUint16()
245
+ if (additionalInformation === 26) return readUint32()
246
+ if (additionalInformation === 27) return readUint64()
247
+ if (additionalInformation === 31) return -1
248
+ throw "Invalid length encoding"
249
+ }
250
+ function readIndefiniteStringLength(majorType) {
251
+ var initialByte = readUint8()
252
+ if (initialByte === 0xff) return -1
253
+ var length = readLength(initialByte & 0x1f)
254
+ if (length < 0 || initialByte >> 5 !== majorType)
255
+ throw "Invalid indefinite length element"
256
+ return length
257
+ }
258
+
259
+ function appendUtf16Data(utf16data, length) {
260
+ for (var i = 0; i < length; ++i) {
261
+ var value = readUint8()
262
+ if (value & 0x80) {
263
+ if (value < 0xe0) {
264
+ value = ((value & 0x1f) << 6) | (readUint8() & 0x3f)
265
+ length -= 1
266
+ } else if (value < 0xf0) {
267
+ value =
268
+ ((value & 0x0f) << 12) |
269
+ ((readUint8() & 0x3f) << 6) |
270
+ (readUint8() & 0x3f)
271
+ length -= 2
272
+ } else {
273
+ value =
274
+ ((value & 0x0f) << 18) |
275
+ ((readUint8() & 0x3f) << 12) |
276
+ ((readUint8() & 0x3f) << 6) |
277
+ (readUint8() & 0x3f)
278
+ length -= 3
279
+ }
280
+ }
281
+
282
+ if (value < 0x10000) {
283
+ utf16data.push(value)
284
+ } else {
285
+ value -= 0x10000
286
+ utf16data.push(0xd800 | (value >> 10))
287
+ utf16data.push(0xdc00 | (value & 0x3ff))
288
+ }
289
+ }
290
+ }
291
+
292
+ function decodeItem() {
293
+ var initialByte = readUint8()
294
+ var majorType = initialByte >> 5
295
+ var additionalInformation = initialByte & 0x1f
296
+ var i
297
+ var length
298
+
299
+ if (majorType === 7) {
300
+ switch (additionalInformation) {
301
+ case 25:
302
+ return readFloat16()
303
+ case 26:
304
+ return readFloat32()
305
+ case 27:
306
+ return readFloat64()
307
+ }
308
+ }
309
+
310
+ length = readLength(additionalInformation)
311
+ if (length < 0 && (majorType < 2 || 6 < majorType)) throw "Invalid length"
312
+
313
+ switch (majorType) {
314
+ case 0:
315
+ return length
316
+ case 1:
317
+ return -1 - length
318
+ case 2:
319
+ if (length < 0) {
320
+ var elements = []
321
+ var fullArrayLength = 0
322
+ while ((length = readIndefiniteStringLength(majorType)) >= 0) {
323
+ fullArrayLength += length
324
+ elements.push(readArrayBuffer(length))
325
+ }
326
+ var fullArray = new Uint8Array(fullArrayLength)
327
+ var fullArrayOffset = 0
328
+ for (i = 0; i < elements.length; ++i) {
329
+ fullArray.set(elements[i], fullArrayOffset)
330
+ fullArrayOffset += elements[i].length
331
+ }
332
+ return fullArray
333
+ }
334
+ return readArrayBuffer(length)
335
+ case 3:
336
+ var utf16data = []
337
+ if (length < 0) {
338
+ while ((length = readIndefiniteStringLength(majorType)) >= 0)
339
+ appendUtf16Data(utf16data, length)
340
+ } else appendUtf16Data(utf16data, length)
341
+ return String.fromCharCode.apply(null, utf16data)
342
+ case 4:
343
+ var retArray
344
+ if (length < 0) {
345
+ retArray = []
346
+ while (!readBreak()) retArray.push(decodeItem())
347
+ } else {
348
+ retArray = new Array(length)
349
+ for (i = 0; i < length; ++i) retArray[i] = decodeItem()
350
+ }
351
+ return retArray
352
+ case 5:
353
+ var retObject = {}
354
+ for (i = 0; i < length || (length < 0 && !readBreak()); ++i) {
355
+ var key = decodeItem()
356
+ retObject[key] = decodeItem()
357
+ }
358
+ return retObject
359
+ case 6:
360
+ return tagger(decodeItem(), length)
361
+ case 7:
362
+ switch (length) {
363
+ case 20:
364
+ return false
365
+ case 21:
366
+ return true
367
+ case 22:
368
+ return null
369
+ case 23:
370
+ return undefined
371
+ default:
372
+ return simpleValue(length)
373
+ }
374
+ }
375
+ }
376
+
377
+ var ret = decodeItem()
378
+ if (offset !== data.byteLength) throw "Remaining bytes"
379
+ return ret
380
+ }
381
+
382
+ var obj = { encode: encode, decode: decode }
383
+
384
+ if (typeof define === "function" && define.amd) define("cbor/cbor", obj)
385
+ else if (typeof module !== "undefined" && module.exports) module.exports = obj
386
+ else if (!global.CBOR) global.CBOR = obj
387
+ })(this)