viz-js-lib 0.10.0 → 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.
- package/README.md +18 -0
- package/dist/statistics.html +1 -1
- package/dist/viz-tests.min.js +310 -14
- package/dist/viz-tests.min.js.gz +0 -0
- package/dist/viz.min.js +44 -15
- package/dist/viz.min.js.gz +0 -0
- package/lib/auth/ecc/src/aes.js +32 -0
- package/lib/browser.js +11 -9
- package/lib/index.js +2 -0
- package/lib/utils.js +204 -1
- package/package.json +4 -2
- package/webpack/makeConfig.js +2 -9
- package/dist/viz-tests.min.js.map +0 -1
- package/dist/viz.min.js.map +0 -1
- package/lib/auth/signature.js +0 -4
package/dist/viz.min.js.gz
CHANGED
|
Binary file
|
package/lib/auth/ecc/src/aes.js
CHANGED
|
@@ -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
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
var api = require(
|
|
4
|
-
var auth = require(
|
|
5
|
-
var broadcast = require(
|
|
6
|
-
var
|
|
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
|
|
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 !==
|
|
23
|
+
if (typeof window !== 'undefined') {
|
|
22
24
|
window.viz = viz;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
if (typeof global !==
|
|
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,10 +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;
|
|
8
12
|
exports.voiceText = voiceText;
|
|
13
|
+
exports.voiceEncodedText = voiceEncodedText;
|
|
9
14
|
exports.voicePublication = voicePublication;
|
|
15
|
+
exports.voiceEncodedPublication = voiceEncodedPublication;
|
|
16
|
+
|
|
17
|
+
var _ecc = require("./auth/ecc");
|
|
18
|
+
|
|
10
19
|
var snakeCaseRe = /_([a-z])/g;
|
|
11
20
|
function camelCase(str) {
|
|
12
21
|
return str.replace(snakeCaseRe, function (_m, l) {
|
|
@@ -56,6 +65,39 @@ function validateAccountName(value) {
|
|
|
56
65
|
return null;
|
|
57
66
|
}
|
|
58
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
|
+
|
|
59
101
|
function voiceText(wif, account, text, reply, share, beneficiaries, loop, callback) {
|
|
60
102
|
reply = typeof reply === 'undefined' ? false : reply;
|
|
61
103
|
share = typeof share === 'undefined' ? false : share;
|
|
@@ -100,6 +142,82 @@ function voiceText(wif, account, text, reply, share, beneficiaries, loop, callba
|
|
|
100
142
|
}
|
|
101
143
|
}
|
|
102
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
|
+
|
|
103
221
|
function voicePublication(wif, account, title, markdown, description, image, reply, share, beneficiaries, loop, callback) {
|
|
104
222
|
description = typeof description === 'undefined' ? false : description;
|
|
105
223
|
image = typeof image === 'undefined' ? false : image;
|
|
@@ -112,7 +230,7 @@ function voicePublication(wif, account, title, markdown, description, image, rep
|
|
|
112
230
|
var use_previous = function use_previous(wif, account, title, markdown, description, image, reply, share, beneficiaries, previous, callback) {
|
|
113
231
|
var object = {
|
|
114
232
|
'p': previous,
|
|
115
|
-
't': 'p', //
|
|
233
|
+
't': 'p', //publication
|
|
116
234
|
'd': {
|
|
117
235
|
't': title,
|
|
118
236
|
'm': markdown
|
|
@@ -151,4 +269,89 @@ function voicePublication(wif, account, title, markdown, description, image, rep
|
|
|
151
269
|
}
|
|
152
270
|
});
|
|
153
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
|
+
}
|
|
154
357
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "viz-js-lib",
|
|
3
|
-
"version": "0.10.
|
|
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.
|
|
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
|
},
|
package/webpack/makeConfig.js
CHANGED
|
@@ -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
|
|
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
|
}
|