viz-js-lib 0.9.31 → 0.10.3

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.
Binary file
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.encrypt = encrypt;
7
7
  exports.decrypt = decrypt;
8
+ exports.simpleDecoder = simpleDecoder;
9
+ exports.simpleEncoder = simpleEncoder;
8
10
 
9
11
  var _secureRandom = require('secure-random');
10
12
 
@@ -126,6 +128,36 @@ function crypt(private_key, public_key, nonce, message, checksum) {
126
128
  return { nonce: nonce, message: message, checksum: check };
127
129
  }
128
130
 
131
+ /**
132
+ @data {string} base64
133
+ @passphrase {string} utf8
134
+ @return {string} utf8
135
+ */
136
+ function simpleDecoder(data, passphrase) {
137
+ var buff = new Buffer(data, 'base64');
138
+ var passphrase_sha512 = _hash2.default.sha512(passphrase);
139
+ var key = passphrase_sha512.slice(0, 32);
140
+ var iv = passphrase_sha512.slice(32, 48);
141
+ var decipher = _browserifyAes2.default.createDecipheriv('aes-256-cbc', key, iv);
142
+ var message = Buffer.concat([decipher.update(buff), decipher.final()]);
143
+ return new TextDecoder('utf-8', { fatal: true }).decode(message);
144
+ }
145
+
146
+ /**
147
+ @data {string} utf8
148
+ @passphrase {string} utf8
149
+ @return {string} base64
150
+ */
151
+ function simpleEncoder(data, passphrase) {
152
+ var passphrase_sha512 = _hash2.default.sha512(passphrase);
153
+ var key = passphrase_sha512.slice(0, 32);
154
+ var iv = passphrase_sha512.slice(32, 48);
155
+ var buff = new Buffer(data, 'utf-8');
156
+ var cipher = _browserifyAes2.default.createCipheriv('aes-256-cbc', key, iv);
157
+ var encrypted = Buffer.concat([cipher.update(buff), cipher.final()]);
158
+ return encrypted.toString('base64');
159
+ }
160
+
129
161
  /** This method does not use a checksum, the returned data must be validated some other way.
130
162
  @arg {string|Buffer} ciphertext - binary format
131
163
  @return {Buffer}
package/lib/browser.js CHANGED
@@ -1,12 +1,13 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- var api = require("./api");
4
- var auth = require("./auth");
5
- var broadcast = require("./broadcast");
6
- var config = require("./config");
7
- var formatter = require("./formatter")(api);
3
+ var api = require('./api');
4
+ var auth = require('./auth');
5
+ var broadcast = require('./broadcast');
6
+ var formatter = require('./formatter')(api);
8
7
  var memo = require('./auth/memo');
9
- var utils = require("./utils");
8
+ var aes = require('./auth/ecc/src/aes');
9
+ var config = require('./config');
10
+ var utils = require('./utils');
10
11
 
11
12
  var viz = {
12
13
  api: api,
@@ -15,14 +16,15 @@ var viz = {
15
16
  config: config,
16
17
  formatter: formatter,
17
18
  memo: memo,
19
+ aes: aes,
18
20
  utils: utils
19
21
  };
20
22
 
21
- if (typeof window !== "undefined") {
23
+ if (typeof window !== 'undefined') {
22
24
  window.viz = viz;
23
25
  }
24
26
 
25
- if (typeof global !== "undefined") {
27
+ if (typeof global !== 'undefined') {
26
28
  global.viz = viz;
27
29
  }
28
30
 
package/lib/index.js CHANGED
@@ -5,6 +5,7 @@ var auth = require('./auth');
5
5
  var broadcast = require('./broadcast');
6
6
  var formatter = require('./formatter')(api);
7
7
  var memo = require('./auth/memo');
8
+ var aes = require('./auth/ecc/src/aes');
8
9
  var config = require('./config');
9
10
  var utils = require('./utils');
10
11
 
@@ -14,6 +15,7 @@ module.exports = {
14
15
  broadcast: broadcast,
15
16
  formatter: formatter,
16
17
  memo: memo,
18
+ aes: aes,
17
19
  config: config,
18
20
  utils: utils
19
21
  };
package/lib/utils.js CHANGED
@@ -3,8 +3,19 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+
7
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
8
+
6
9
  exports.camelCase = camelCase;
7
10
  exports.validateAccountName = validateAccountName;
11
+ exports.voiceEvent = voiceEvent;
12
+ exports.voiceText = voiceText;
13
+ exports.voiceEncodedText = voiceEncodedText;
14
+ exports.voicePublication = voicePublication;
15
+ exports.voiceEncodedPublication = voiceEncodedPublication;
16
+
17
+ var _ecc = require("./auth/ecc");
18
+
8
19
  var snakeCaseRe = /_([a-z])/g;
9
20
  function camelCase(str) {
10
21
  return str.replace(snakeCaseRe, function (_m, l) {
@@ -52,4 +63,295 @@ function validateAccountName(value) {
52
63
  }
53
64
  }
54
65
  return null;
66
+ }
67
+
68
+ function voiceEvent(wif, account, event_type, target_account, target_block, data, loop, callback) {
69
+ loop = typeof loop === 'undefined' ? false : loop;
70
+ callback = typeof callback === 'undefined' ? function () {} : callback;
71
+
72
+ var use_previous = function use_previous(wif, account, event_type, target_account, target_block, data, previous, callback) {
73
+ var object = {
74
+ 'p': previous,
75
+ 'e': event_type, //h - hide, e - edit, a - append
76
+ 'b': target_block //block to hide, edit or append
77
+ };
78
+ if (target_account !== account) {
79
+ object['a'] = target_account;
80
+ }
81
+ if (typeof data !== 'undefined') {
82
+ object['d'] = data; //optional
83
+ }
84
+ viz.broadcast.custom(wif, [], [account], 'VE', JSON.stringify(object), function (err, result) {
85
+ callback(!err);
86
+ });
87
+ };
88
+ if (false !== loop) {
89
+ use_previous(wif, account, event_type, target_account, target_block, data, loop, callback);
90
+ } else {
91
+ viz.api.getAccount(account, 'VE', function (err, result) {
92
+ if (!err) {
93
+ use_previous(wif, account, event_type, target_account, target_block, data, result.custom_sequence_block_num, callback);
94
+ } else {
95
+ callback(false);
96
+ }
97
+ });
98
+ }
99
+ }
100
+
101
+ function voiceText(wif, account, text, reply, share, beneficiaries, loop, callback) {
102
+ reply = typeof reply === 'undefined' ? false : reply;
103
+ share = typeof share === 'undefined' ? false : share;
104
+ beneficiaries = typeof beneficiaries === 'undefined' ? false : beneficiaries;
105
+ loop = typeof loop === 'undefined' ? false : loop;
106
+ callback = typeof callback === 'undefined' ? function () {} : callback;
107
+
108
+ var use_previous = function use_previous(wif, account, text, reply, share, beneficiaries, previous, callback) {
109
+ var object = {
110
+ 'p': previous,
111
+ //'t':'t',//text as default type
112
+ 'd': {
113
+ 't': text
114
+ }
115
+ };
116
+ if (reply) {
117
+ object['d']['r'] = reply;
118
+ } else {
119
+ //share conflict with reply
120
+ if (share) {
121
+ object['d']['s'] = share;
122
+ }
123
+ }
124
+ if (beneficiaries) {
125
+ //json example: [{"account":"committee","weight":1000}]
126
+ object['d']['b'] = beneficiaries;
127
+ }
128
+ viz.broadcast.custom(wif, [], [account], 'V', JSON.stringify(object), function (err, result) {
129
+ callback(!err);
130
+ });
131
+ };
132
+ if (false !== loop) {
133
+ use_previous(wif, account, text, reply, share, beneficiaries, loop, callback);
134
+ } else {
135
+ viz.api.getAccount(account, 'V', function (err, result) {
136
+ if (!err) {
137
+ use_previous(wif, account, text, reply, share, beneficiaries, result.custom_sequence_block_num, callback);
138
+ } else {
139
+ callback(false);
140
+ }
141
+ });
142
+ }
143
+ }
144
+
145
+ function voiceEncodedText(wif, account, passphrase, comment, text, reply, share, beneficiaries, loop, callback) {
146
+ reply = typeof reply === 'undefined' ? false : reply;
147
+ share = typeof share === 'undefined' ? false : share;
148
+ beneficiaries = typeof beneficiaries === 'undefined' ? false : beneficiaries;
149
+ loop = typeof loop === 'undefined' ? false : loop;
150
+ callback = typeof callback === 'undefined' ? function () {} : callback;
151
+
152
+ var use_previous = function use_previous(wif, account, passphrase, comment, text, reply, share, beneficiaries, previous, callback) {
153
+ var object = {
154
+ 'd': {
155
+ 't': text
156
+ }
157
+ };
158
+ if (reply) {
159
+ object['d']['r'] = reply;
160
+ } else {
161
+ //share conflict with reply
162
+ if (share) {
163
+ object['d']['s'] = share;
164
+ }
165
+ }
166
+ if (beneficiaries) {
167
+ //json example: [{"account":"committee","weight":1000}]
168
+ object['d']['b'] = beneficiaries;
169
+ }
170
+ if ((typeof passphrase === "undefined" ? "undefined" : _typeof(passphrase)) === 'object') {
171
+ //reverse array (first item encode last for human readable envelope)
172
+ passphrase = passphrase.reverse();
173
+ if ((typeof comment === "undefined" ? "undefined" : _typeof(comment)) === 'object') {
174
+ comment = comment.reverse();
175
+ }
176
+ for (var i in passphrase) {
177
+ var number = i;
178
+ if (0 == number) {
179
+ object['nt'] = 't'; //text
180
+ } else {
181
+ object['nt'] = 'e'; //encoded
182
+ }
183
+ console.log('encode object', object, 'with passphrase', passphrase[number], 'and comment', comment[number]);
184
+ object['d'] = JSON.stringify(object);
185
+ object['d'] = _ecc.Aes.simpleEncoder(object['d'], passphrase[number]);
186
+ if ((typeof comment === "undefined" ? "undefined" : _typeof(comment)) === 'object') {
187
+ if (typeof comment[number] === 'string') {
188
+ object['c'] = comment[number];
189
+ }
190
+ }
191
+ }
192
+ delete object['nt']; //remove new type because it already stringified and encoded
193
+ } else {
194
+ //nt - new type (not needed for default t/text)
195
+ //object['d']['nt']=object['t'];//new type is text
196
+ object['d'] = JSON.stringify(object);
197
+ object['d'] = _ecc.Aes.simpleEncoder(object['d'], passphrase);
198
+ if (typeof comment !== 'undefined') {
199
+ object['c'] = comment;
200
+ }
201
+ }
202
+ object['t'] = 'e'; //encoded
203
+ object['p'] = previous;
204
+ viz.broadcast.custom(wif, [], [account], 'V', JSON.stringify(object), function (err, result) {
205
+ callback(!err);
206
+ });
207
+ };
208
+ if (false !== loop) {
209
+ use_previous(wif, account, passphrase, comment, text, reply, share, beneficiaries, loop, callback);
210
+ } else {
211
+ viz.api.getAccount(account, 'V', function (err, result) {
212
+ if (!err) {
213
+ use_previous(wif, account, passphrase, comment, text, reply, share, beneficiaries, result.custom_sequence_block_num, callback);
214
+ } else {
215
+ callback(false);
216
+ }
217
+ });
218
+ }
219
+ }
220
+
221
+ function voicePublication(wif, account, title, markdown, description, image, reply, share, beneficiaries, loop, callback) {
222
+ description = typeof description === 'undefined' ? false : description;
223
+ image = typeof image === 'undefined' ? false : image;
224
+ reply = typeof reply === 'undefined' ? false : reply;
225
+ share = typeof share === 'undefined' ? false : share;
226
+ beneficiaries = typeof beneficiaries === 'undefined' ? false : beneficiaries;
227
+ loop = typeof loop === 'undefined' ? false : loop;
228
+ callback = typeof callback === 'undefined' ? function () {} : callback;
229
+
230
+ var use_previous = function use_previous(wif, account, title, markdown, description, image, reply, share, beneficiaries, previous, callback) {
231
+ var object = {
232
+ 'p': previous,
233
+ 't': 'p', //publication
234
+ 'd': {
235
+ 't': title,
236
+ 'm': markdown
237
+ }
238
+ };
239
+ if (description) {
240
+ object['d']['d'] = description;
241
+ }
242
+ if (image) {
243
+ object['d']['i'] = image;
244
+ }
245
+ if (reply) {
246
+ object['d']['r'] = reply;
247
+ } else {
248
+ //share conflict with reply
249
+ if (share) {
250
+ object['d']['s'] = share;
251
+ }
252
+ }
253
+ if (beneficiaries) {
254
+ //json example: [{"account":"committee","weight":1000}]
255
+ object['d']['b'] = beneficiaries;
256
+ }
257
+ viz.broadcast.custom(wif, [], [account], 'V', JSON.stringify(object), function (err, result) {
258
+ callback(!err);
259
+ });
260
+ };
261
+ if (false !== loop) {
262
+ use_previous(wif, account, title, markdown, description, image, reply, share, beneficiaries, loop, callback);
263
+ } else {
264
+ viz.api.getAccount(account, 'V', function (err, result) {
265
+ if (!err) {
266
+ use_previous(wif, account, title, markdown, description, image, reply, share, beneficiaries, result.custom_sequence_block_num, callback);
267
+ } else {
268
+ callback(false);
269
+ }
270
+ });
271
+ }
272
+ }
273
+
274
+ function voiceEncodedPublication(wif, account, passphrase, comment, title, markdown, description, image, reply, share, beneficiaries, loop, callback) {
275
+ description = typeof description === 'undefined' ? false : description;
276
+ image = typeof image === 'undefined' ? false : image;
277
+ reply = typeof reply === 'undefined' ? false : reply;
278
+ share = typeof share === 'undefined' ? false : share;
279
+ beneficiaries = typeof beneficiaries === 'undefined' ? false : beneficiaries;
280
+ loop = typeof loop === 'undefined' ? false : loop;
281
+ callback = typeof callback === 'undefined' ? function () {} : callback;
282
+
283
+ var use_previous = function use_previous(wif, account, passphrase, comment, title, markdown, description, image, reply, share, beneficiaries, previous, callback) {
284
+ var object = {
285
+ 't': 'p', //publication
286
+ 'd': {
287
+ 't': title,
288
+ 'm': markdown
289
+ }
290
+ };
291
+ if (description) {
292
+ object['d']['d'] = description;
293
+ }
294
+ if (image) {
295
+ object['d']['i'] = image;
296
+ }
297
+ if (reply) {
298
+ object['d']['r'] = reply;
299
+ } else {
300
+ //share conflict with reply
301
+ if (share) {
302
+ object['d']['s'] = share;
303
+ }
304
+ }
305
+ if (beneficiaries) {
306
+ //json example: [{"account":"committee","weight":1000}]
307
+ object['d']['b'] = beneficiaries;
308
+ }
309
+ if ((typeof passphrase === "undefined" ? "undefined" : _typeof(passphrase)) === 'object') {
310
+ //reverse array (first item encode last for human readable envelope)
311
+ passphrase = passphrase.reverse();
312
+ if ((typeof comment === "undefined" ? "undefined" : _typeof(comment)) === 'object') {
313
+ comment = comment.reverse();
314
+ }
315
+ for (var i in passphrase) {
316
+ var number = i;
317
+ if (0 == number) {
318
+ object['nt'] = 't'; //text
319
+ } else {
320
+ object['nt'] = 'e'; //encoded
321
+ }
322
+ console.log('encode object', object, 'with passphrase', passphrase[number], 'and comment', comment[number]);
323
+ object['d'] = JSON.stringify(object);
324
+ object['d'] = _ecc.Aes.simpleEncoder(object['d'], passphrase[number]);
325
+ if ((typeof comment === "undefined" ? "undefined" : _typeof(comment)) === 'object') {
326
+ if (typeof comment[number] === 'string') {
327
+ object['c'] = comment[number];
328
+ }
329
+ }
330
+ }
331
+ delete object['nt']; //remove new type because it already stringified and encoded
332
+ } else {
333
+ object['d']['nt'] = object['t']; //new type
334
+ object['d'] = JSON.stringify(object);
335
+ object['d'] = _ecc.Aes.simpleEncoder(object['d'], passphrase);
336
+ if (typeof comment !== 'undefined') {
337
+ object['c'] = comment;
338
+ }
339
+ }
340
+ object['t'] = 'e'; //encoded
341
+ object['p'] = previous;
342
+ viz.broadcast.custom(wif, [], [account], 'V', JSON.stringify(object), function (err, result) {
343
+ callback(!err);
344
+ });
345
+ };
346
+ if (false !== loop) {
347
+ use_previous(wif, account, passphrase, comment, title, markdown, description, image, reply, share, beneficiaries, loop, callback);
348
+ } else {
349
+ viz.api.getAccount(account, 'V', function (err, result) {
350
+ if (!err) {
351
+ use_previous(wif, account, passphrase, comment, title, markdown, description, image, reply, share, beneficiaries, result.custom_sequence_block_num, callback);
352
+ } else {
353
+ callback(false);
354
+ }
355
+ });
356
+ }
55
357
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viz-js-lib",
3
- "version": "0.9.31",
3
+ "version": "0.10.3",
4
4
  "description": "viz.js the JavaScript Library with API support for VIZ blockchain",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -35,8 +35,9 @@
35
35
  },
36
36
  "homepage": "https://github.com/VIZ-Blockchain/viz-js-lib#readme",
37
37
  "dependencies": {
38
+ "babel-preset-env": "^1.7.0",
38
39
  "bigi": "^1.4.2",
39
- "bluebird": "^3.4.6",
40
+ "bluebird": "^3.5.5",
40
41
  "browserify-aes": "^1.0.6",
41
42
  "bs58": "^4.0.0",
42
43
  "buffer": "^5.0.6",
@@ -68,6 +69,7 @@
68
69
  "mocha": "^5.2.0",
69
70
  "mocha-make-stub": "^2.3.2",
70
71
  "should": "^11.1.0",
72
+ "uglifyjs-webpack-plugin": "^1.3.0",
71
73
  "webpack": "^1.13.2",
72
74
  "webpack-visualizer-plugin": "^0.1.5"
73
75
  },
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
  const Visualizer = require('webpack-visualizer-plugin');
3
+ const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
3
4
  const _ = require('lodash');
4
5
  const path = require('path');
5
6
  const webpack = require('webpack');
@@ -21,15 +22,7 @@ function makePlugins(options) {
21
22
  if (!isDevelopment) {
22
23
  plugins = plugins.concat([
23
24
  new webpack.optimize.DedupePlugin(),
24
- new webpack.optimize.UglifyJsPlugin({
25
- output: {
26
- comments: false,
27
- },
28
- minimize: true,
29
- compress: {
30
- warnings: false,
31
- }
32
- }),
25
+ new UglifyJSPlugin({uglifyOptions: { ...options }}),
33
26
  new webpack.optimize.AggressiveMergingPlugin(),
34
27
  ]);
35
28
  }