viz-js-lib 0.10.0 → 0.11.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/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/api/methods.js +12 -0
- package/lib/auth/ecc/src/aes.js +32 -0
- package/lib/auth/serializer/src/ChainTypes.js +5 -1
- package/lib/auth/serializer/src/operations.js +31 -1
- package/lib/broadcast/index.js +22 -9
- package/lib/broadcast/operations.js +8 -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/api/methods.js
CHANGED
|
@@ -135,6 +135,14 @@ module.exports = [{
|
|
|
135
135
|
"api": "database_api",
|
|
136
136
|
"method": "get_block",
|
|
137
137
|
"params": ["blockNum"]
|
|
138
|
+
}, {
|
|
139
|
+
"api": "database_api",
|
|
140
|
+
"method": "get_irreversible_block_header",
|
|
141
|
+
"params": ["blockNum"]
|
|
142
|
+
}, {
|
|
143
|
+
"api": "database_api",
|
|
144
|
+
"method": "get_irreversible_block",
|
|
145
|
+
"params": ["blockNum"]
|
|
138
146
|
}, {
|
|
139
147
|
"api": "database_api",
|
|
140
148
|
"method": "get_config"
|
|
@@ -224,6 +232,10 @@ module.exports = [{
|
|
|
224
232
|
"api": "database_api",
|
|
225
233
|
"method": "get_accounts_on_sale",
|
|
226
234
|
"params": ["from", "limit"]
|
|
235
|
+
}, {
|
|
236
|
+
"api": "database_api",
|
|
237
|
+
"method": "get_accounts_on_auction",
|
|
238
|
+
"params": ["from", "limit"]
|
|
227
239
|
}, {
|
|
228
240
|
"api": "database_api",
|
|
229
241
|
"method": "get_subaccounts_on_sale",
|
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}
|
|
@@ -70,7 +70,11 @@ ChainTypes.operations = {
|
|
|
70
70
|
buy_account: 56,
|
|
71
71
|
account_sale: 57,
|
|
72
72
|
use_invite_balance: 58,
|
|
73
|
-
expire_escrow_ratification: 59
|
|
73
|
+
expire_escrow_ratification: 59,
|
|
74
|
+
fixed_award: 60,
|
|
75
|
+
target_account_sale: 61,
|
|
76
|
+
bid: 62,
|
|
77
|
+
outbid: 63
|
|
74
78
|
};
|
|
75
79
|
|
|
76
80
|
//types.hpp
|
|
@@ -498,6 +498,16 @@ var award = new Serializer("award", {
|
|
|
498
498
|
beneficiaries: set(beneficiaries)
|
|
499
499
|
});
|
|
500
500
|
|
|
501
|
+
var fixed_award = new Serializer("fixed_award", {
|
|
502
|
+
initiator: string,
|
|
503
|
+
receiver: string,
|
|
504
|
+
reward_amount: asset,
|
|
505
|
+
max_energy: uint16,
|
|
506
|
+
custom_sequence: uint64,
|
|
507
|
+
memo: string,
|
|
508
|
+
beneficiaries: set(beneficiaries)
|
|
509
|
+
});
|
|
510
|
+
|
|
501
511
|
var chain_properties_hf4 = new Serializer(1, {
|
|
502
512
|
account_creation_fee: asset,
|
|
503
513
|
maximum_block_size: uint32,
|
|
@@ -622,6 +632,14 @@ var set_account_price = new Serializer("set_account_price", {
|
|
|
622
632
|
account_on_sale: bool
|
|
623
633
|
});
|
|
624
634
|
|
|
635
|
+
var target_account_sale = new Serializer("target_account_sale", {
|
|
636
|
+
account: string,
|
|
637
|
+
account_seller: string,
|
|
638
|
+
target_buyer: string,
|
|
639
|
+
account_offer_price: asset,
|
|
640
|
+
account_on_sale: bool
|
|
641
|
+
});
|
|
642
|
+
|
|
625
643
|
var set_subaccount_price = new Serializer("set_subaccount_price", {
|
|
626
644
|
account: string,
|
|
627
645
|
subaccount_seller: string,
|
|
@@ -660,7 +678,19 @@ var expire_escrow_ratification = new Serializer("expire_escrow_ratification", {
|
|
|
660
678
|
ratification_deadline: time_point_sec
|
|
661
679
|
});
|
|
662
680
|
|
|
663
|
-
|
|
681
|
+
var bid = new Serializer("bid", {
|
|
682
|
+
account: string,
|
|
683
|
+
bidder: string,
|
|
684
|
+
bid: asset
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
var outbid = new Serializer("outbid", {
|
|
688
|
+
account: string,
|
|
689
|
+
bidder: string,
|
|
690
|
+
bid: asset
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
operation.st_operations = [vote, content, transfer, transfer_to_vesting, withdraw_vesting, account_update, witness_update, account_witness_vote, account_witness_proxy, delete_content, custom, set_withdraw_vesting_route, request_account_recovery, recover_account, change_recovery_account, escrow_transfer, escrow_dispute, escrow_release, escrow_approve, delegate_vesting_shares, account_create, account_metadata, proposal_create, proposal_update, proposal_delete, chain_properties_update, author_reward, curation_reward, content_reward, fill_vesting_withdraw, shutdown_witness, hardfork, content_payout_update, content_benefactor_reward, return_vesting_delegation, committee_worker_create_request, committee_worker_cancel_request, committee_vote_request, committee_cancel_request, committee_approve_request, committee_pay_request, committee_payout_request, witness_reward, create_invite, claim_invite_balance, invite_registration, versioned_chain_properties_update, award, receive_award, benefactor_award, set_paid_subscription, paid_subscribe, paid_subscription_action, cancel_paid_subscription, set_account_price, set_subaccount_price, buy_account, account_sale, use_invite_balance, expire_escrow_ratification, fixed_award, target_account_sale, bid, outbid];
|
|
664
694
|
|
|
665
695
|
//# -------------------------------
|
|
666
696
|
//# Generated code end S T O P
|
package/lib/broadcast/index.js
CHANGED
|
@@ -74,15 +74,28 @@ Broadcaster._prepareTransaction = function Broadcaster$_prepareTransaction(tx) {
|
|
|
74
74
|
return propertiesP.then(function (properties) {
|
|
75
75
|
// Set defaults on the transaction
|
|
76
76
|
var chainDate = new Date(properties.time + 'Z');
|
|
77
|
-
var
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
77
|
+
var need_get_block = true;
|
|
78
|
+
if (typeof properties.last_irreversible_block_ref_num !== 'undefined') {
|
|
79
|
+
if (0 != properties.last_irreversible_block_ref_num) {
|
|
80
|
+
need_get_block = false;
|
|
81
|
+
return Object.assign({
|
|
82
|
+
ref_block_num: properties.last_irreversible_block_ref_num,
|
|
83
|
+
ref_block_prefix: properties.last_irreversible_block_ref_prefix,
|
|
84
|
+
expiration: new Date(chainDate.getTime() + 60 * 1000)
|
|
85
|
+
}, tx);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (need_get_block) {
|
|
89
|
+
var refBlockNum = properties.head_block_number - 3 & 0xFFFF;
|
|
90
|
+
return _api2.default.getBlockAsync(properties.head_block_number - 2).then(function (block) {
|
|
91
|
+
var headBlockId = block.previous;
|
|
92
|
+
return Object.assign({
|
|
93
|
+
ref_block_num: refBlockNum,
|
|
94
|
+
ref_block_prefix: new Buffer(headBlockId, 'hex').readUInt32LE(4),
|
|
95
|
+
expiration: new Date(chainDate.getTime() + 60 * 1000)
|
|
96
|
+
}, tx);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
86
99
|
});
|
|
87
100
|
};
|
|
88
101
|
|
|
@@ -148,6 +148,10 @@ module.exports = [{
|
|
|
148
148
|
"roles": ["regular"],
|
|
149
149
|
"operation": "award",
|
|
150
150
|
"params": ["initiator", "receiver", "energy", "custom_sequence", "memo", "beneficiaries"]
|
|
151
|
+
}, {
|
|
152
|
+
"roles": ["regular"],
|
|
153
|
+
"operation": "fixed_award",
|
|
154
|
+
"params": ["initiator", "receiver", "reward_amount", "max_energy", "custom_sequence", "memo", "beneficiaries"]
|
|
151
155
|
}, {
|
|
152
156
|
"roles": ["active"],
|
|
153
157
|
"operation": "set_paid_subscription",
|
|
@@ -160,6 +164,10 @@ module.exports = [{
|
|
|
160
164
|
"roles": ["master"],
|
|
161
165
|
"operation": "set_account_price",
|
|
162
166
|
"params": ["account", "account_seller", "account_offer_price", "account_on_sale"]
|
|
167
|
+
}, {
|
|
168
|
+
"roles": ["master"],
|
|
169
|
+
"operation": "target_account_sale",
|
|
170
|
+
"params": ["account", "account_seller", "target_buyer", "account_offer_price", "account_on_sale"]
|
|
163
171
|
}, {
|
|
164
172
|
"roles": ["master"],
|
|
165
173
|
"operation": "set_subaccount_price",
|
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'] = 'p'; //publication
|
|
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.
|
|
3
|
+
"version": "0.11.0",
|
|
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
|
}
|