@steemit/steem-js 0.8.0 → 1.0.1
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 +202 -105
- package/dist/api/index.d.ts +128 -0
- package/dist/api/methods.d.ts +9 -0
- package/dist/api/rpc-auth.d.ts +43 -0
- package/dist/api/transports/base.d.ts +13 -0
- package/dist/api/transports/http.d.ts +9 -0
- package/dist/api/transports/index.d.ts +9 -0
- package/dist/api/transports/types.d.ts +35 -0
- package/dist/api/transports/ws.d.ts +18 -0
- package/dist/auth/ecc/index.d.ts +9 -0
- package/dist/auth/ecc/src/address.d.ts +13 -0
- package/dist/auth/ecc/src/aes.d.ts +16 -0
- package/dist/auth/ecc/src/brain_key.d.ts +1 -0
- package/dist/auth/ecc/src/ecdsa.d.ts +28 -0
- package/dist/auth/ecc/src/ecsignature.d.ts +19 -0
- package/dist/auth/ecc/src/enforce_types.d.ts +5 -0
- package/dist/auth/ecc/src/hash.d.ts +25 -0
- package/dist/auth/ecc/src/index.d.ts +9 -0
- package/dist/auth/ecc/src/key_private.d.ts +38 -0
- package/dist/auth/ecc/src/key_public.d.ts +41 -0
- package/dist/auth/ecc/src/key_utils.d.ts +9 -0
- package/dist/auth/ecc/src/signature.d.ts +18 -0
- package/dist/auth/ecc.d.ts +3 -0
- package/dist/auth/index.d.ts +48 -0
- package/dist/auth/key_classes.d.ts +3 -0
- package/dist/auth/serializer/transaction.d.ts +5 -0
- package/dist/auth/serializer.d.ts +19 -0
- package/dist/broadcast/helpers.d.ts +11 -0
- package/dist/broadcast/index.d.ts +43 -0
- package/dist/broadcast/operations.d.ts +6 -0
- package/dist/config.d.ts +27 -0
- package/dist/crypto/index.d.ts +25 -0
- package/dist/formatter/index.d.ts +92 -0
- package/dist/index.cjs +26436 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +26400 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +58121 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/memo/index.d.ts +11 -0
- package/dist/operations/index.d.ts +44 -0
- package/dist/serializer/convert.d.ts +12 -0
- package/dist/serializer/index.d.ts +11 -0
- package/dist/serializer/number_utils.d.ts +8 -0
- package/dist/serializer/precision.d.ts +5 -0
- package/dist/serializer/types.d.ts +36 -0
- package/dist/types/index.d.ts +131 -0
- package/dist/types.d.ts +34 -0
- package/dist/utils/debug.d.ts +36 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils.d.ts +2 -0
- package/package.json +68 -87
- package/.dockerignore +0 -12
- package/.editorconfig +0 -20
- package/.eslintrc +0 -27
- package/LICENSE +0 -21
- package/circle.yml +0 -3
- package/config.json +0 -10
- package/dist/steem-tests.min.js +0 -4097
- package/dist/steem.min.js +0 -2089
- package/docker-webpack.config.js +0 -44
- package/lib/api/index.js +0 -315
- package/lib/api/methods.js +0 -428
- package/lib/api/rpc-auth.js +0 -135
- package/lib/api/transports/base.js +0 -31
- package/lib/api/transports/http.js +0 -157
- package/lib/api/transports/index.js +0 -13
- package/lib/api/transports/ws.js +0 -128
- package/lib/auth/ecc/index.js +0 -13
- package/lib/auth/ecc/src/address.js +0 -54
- package/lib/auth/ecc/src/aes.js +0 -148
- package/lib/auth/ecc/src/brain_key.js +0 -13
- package/lib/auth/ecc/src/ecdsa.js +0 -193
- package/lib/auth/ecc/src/ecsignature.js +0 -102
- package/lib/auth/ecc/src/enforce_types.js +0 -42
- package/lib/auth/ecc/src/hash.js +0 -58
- package/lib/auth/ecc/src/key_private.js +0 -159
- package/lib/auth/ecc/src/key_public.js +0 -143
- package/lib/auth/ecc/src/key_utils.js +0 -70
- package/lib/auth/ecc/src/signature.js +0 -135
- package/lib/auth/index.js +0 -113
- package/lib/auth/memo.js +0 -119
- package/lib/auth/serializer/index.js +0 -15
- package/lib/auth/serializer/src/ChainTypes.js +0 -87
- package/lib/auth/serializer/src/convert.js +0 -34
- package/lib/auth/serializer/src/error_with_cause.js +0 -27
- package/lib/auth/serializer/src/fast_parser.js +0 -57
- package/lib/auth/serializer/src/number_utils.js +0 -43
- package/lib/auth/serializer/src/object_id.js +0 -43
- package/lib/auth/serializer/src/operations.js +0 -695
- package/lib/auth/serializer/src/precision.js +0 -77
- package/lib/auth/serializer/src/serializer.js +0 -165
- package/lib/auth/serializer/src/template.js +0 -22
- package/lib/auth/serializer/src/types.js +0 -1085
- package/lib/auth/serializer/src/validation.js +0 -300
- package/lib/broadcast/helpers.js +0 -140
- package/lib/broadcast/index.js +0 -106
- package/lib/broadcast/operations.js +0 -255
- package/lib/browser.js +0 -25
- package/lib/config.js +0 -23
- package/lib/formatter.js +0 -163
- package/lib/index.js +0 -21
- package/lib/utils.js +0 -50
- package/node-18.dockerfile +0 -28
- package/test/Crypto.js +0 -100
- package/test/KeyFormats.js +0 -105
- package/test/all_types.js +0 -115
- package/test/api.test.js +0 -363
- package/test/broadcast.test.js +0 -231
- package/test/browser/BrowserTests.js +0 -55
- package/test/comment.test.js +0 -83
- package/test/hf20-accounts.test.js +0 -76
- package/test/hf21-sps.test.js +0 -78
- package/test/memo.test.js +0 -37
- package/test/number_utils.js +0 -28
- package/test/operations_test.js +0 -39
- package/test/promise-broadcast.test.js +0 -86
- package/test/reputation.test.js +0 -68
- package/test/smt.test.js +0 -347
- package/test/test-post.json +0 -13
- package/test/test.html +0 -13
- package/test/test_helper.js +0 -19
- package/test/types_test.js +0 -139
- package/test-github-workflow.bat +0 -19
- package/test-github-workflow.sh +0 -15
- package/webpack/makeConfig.js +0 -113
- package/webpack.config.js +0 -2
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _my;
|
|
4
|
-
var is_empty;
|
|
5
|
-
var is_digits;
|
|
6
|
-
var to_number;
|
|
7
|
-
var require_match;
|
|
8
|
-
var require_object_id;
|
|
9
|
-
var require_object_type;
|
|
10
|
-
var get_instance;
|
|
11
|
-
var require_relative_type;
|
|
12
|
-
var get_relative_instance;
|
|
13
|
-
var require_protocol_type;
|
|
14
|
-
var get_protocol_instance;
|
|
15
|
-
var get_protocol_type;
|
|
16
|
-
var require_implementation_type;
|
|
17
|
-
var get_implementation_instance;
|
|
18
|
-
var Long = require('bytebuffer').Long;
|
|
19
|
-
// var BigInteger = require('bigi');
|
|
20
|
-
|
|
21
|
-
var chain_types = require('./ChainTypes');
|
|
22
|
-
var MAX_SAFE_INT = 9007199254740991;
|
|
23
|
-
var MIN_SAFE_INT = -9007199254740991;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
Most validations are skipped and the value returned unchanged when an empty string, null, or undefined is encountered (except "required").
|
|
27
|
-
|
|
28
|
-
Validations support a string format for dealing with large numbers.
|
|
29
|
-
*/
|
|
30
|
-
module.exports = _my = {
|
|
31
|
-
is_empty: is_empty = function (value) {
|
|
32
|
-
return value === null || value === undefined;
|
|
33
|
-
},
|
|
34
|
-
required(value, field_name = "") {
|
|
35
|
-
if (is_empty(value)) {
|
|
36
|
-
throw new Error(`value required ${field_name} ${value}`);
|
|
37
|
-
}
|
|
38
|
-
return value;
|
|
39
|
-
},
|
|
40
|
-
require_long(value, field_name = "") {
|
|
41
|
-
if (!Long.isLong(value)) {
|
|
42
|
-
throw new Error(`Long value required ${field_name} ${value}`);
|
|
43
|
-
}
|
|
44
|
-
return value;
|
|
45
|
-
},
|
|
46
|
-
string(value) {
|
|
47
|
-
if (is_empty(value)) {
|
|
48
|
-
return value;
|
|
49
|
-
}
|
|
50
|
-
if (typeof value !== "string") {
|
|
51
|
-
throw new Error(`string required: ${value}`);
|
|
52
|
-
}
|
|
53
|
-
return value;
|
|
54
|
-
},
|
|
55
|
-
number(value) {
|
|
56
|
-
if (is_empty(value)) {
|
|
57
|
-
return value;
|
|
58
|
-
}
|
|
59
|
-
if (typeof value !== "number") {
|
|
60
|
-
throw new Error(`number required: ${value}`);
|
|
61
|
-
}
|
|
62
|
-
return value;
|
|
63
|
-
},
|
|
64
|
-
whole_number(value, field_name = "") {
|
|
65
|
-
if (is_empty(value)) {
|
|
66
|
-
return value;
|
|
67
|
-
}
|
|
68
|
-
if (/\./.test(value)) {
|
|
69
|
-
throw new Error(`whole number required ${field_name} ${value}`);
|
|
70
|
-
}
|
|
71
|
-
return value;
|
|
72
|
-
},
|
|
73
|
-
unsigned(value, field_name = "") {
|
|
74
|
-
if (is_empty(value)) {
|
|
75
|
-
return value;
|
|
76
|
-
}
|
|
77
|
-
if (/-/.test(value)) {
|
|
78
|
-
throw new Error(`unsigned required ${field_name} ${value}`);
|
|
79
|
-
}
|
|
80
|
-
return value;
|
|
81
|
-
},
|
|
82
|
-
is_digits: is_digits = function (value) {
|
|
83
|
-
if (typeof value === "numeric") {
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
return /^[0-9]+$/.test(value);
|
|
87
|
-
},
|
|
88
|
-
to_number: to_number = function (value, field_name = "") {
|
|
89
|
-
if (is_empty(value)) {
|
|
90
|
-
return value;
|
|
91
|
-
}
|
|
92
|
-
_my.no_overflow53(value, field_name);
|
|
93
|
-
var int_value = (() => {
|
|
94
|
-
if (typeof value === "number") {
|
|
95
|
-
return value;
|
|
96
|
-
} else {
|
|
97
|
-
return parseInt(value);
|
|
98
|
-
}
|
|
99
|
-
})();
|
|
100
|
-
return int_value;
|
|
101
|
-
},
|
|
102
|
-
to_long(value, field_name = "") {
|
|
103
|
-
if (is_empty(value)) {
|
|
104
|
-
return value;
|
|
105
|
-
}
|
|
106
|
-
if (Long.isLong(value)) {
|
|
107
|
-
return value;
|
|
108
|
-
}
|
|
109
|
-
_my.no_overflow64(value, field_name);
|
|
110
|
-
if (typeof value === "number") {
|
|
111
|
-
value = "" + value;
|
|
112
|
-
}
|
|
113
|
-
return Long.fromString(value);
|
|
114
|
-
},
|
|
115
|
-
to_string(value, field_name = "") {
|
|
116
|
-
if (is_empty(value)) {
|
|
117
|
-
return value;
|
|
118
|
-
}
|
|
119
|
-
if (typeof value === "string") {
|
|
120
|
-
return value;
|
|
121
|
-
}
|
|
122
|
-
if (typeof value === "number") {
|
|
123
|
-
_my.no_overflow53(value, field_name);
|
|
124
|
-
return "" + value;
|
|
125
|
-
}
|
|
126
|
-
if (Long.isLong(value)) {
|
|
127
|
-
return value.toString();
|
|
128
|
-
}
|
|
129
|
-
throw `unsupported type ${field_name}: (${typeof value}) ${value}`;
|
|
130
|
-
},
|
|
131
|
-
require_test(regex, value, field_name = "") {
|
|
132
|
-
if (is_empty(value)) {
|
|
133
|
-
return value;
|
|
134
|
-
}
|
|
135
|
-
if (!regex.test(value)) {
|
|
136
|
-
throw new Error(`unmatched ${regex} ${field_name} ${value}`);
|
|
137
|
-
}
|
|
138
|
-
return value;
|
|
139
|
-
},
|
|
140
|
-
require_match: require_match = function (regex, value, field_name = "") {
|
|
141
|
-
if (is_empty(value)) {
|
|
142
|
-
return value;
|
|
143
|
-
}
|
|
144
|
-
var match = value.match(regex);
|
|
145
|
-
if (match === null) {
|
|
146
|
-
throw new Error(`unmatched ${regex} ${field_name} ${value}`);
|
|
147
|
-
}
|
|
148
|
-
return match;
|
|
149
|
-
},
|
|
150
|
-
// require_object_id: require_object_id=function(value, field_name){
|
|
151
|
-
// return require_match(
|
|
152
|
-
// /^([0-9]+)\.([0-9]+)\.([0-9]+)$/,
|
|
153
|
-
// value,
|
|
154
|
-
// field_name
|
|
155
|
-
// );
|
|
156
|
-
// },
|
|
157
|
-
|
|
158
|
-
// Does not support over 53 bits
|
|
159
|
-
require_range(min, max, value, field_name = "") {
|
|
160
|
-
if (is_empty(value)) {
|
|
161
|
-
return value;
|
|
162
|
-
}
|
|
163
|
-
var number = to_number(value);
|
|
164
|
-
if (value < min || value > max) {
|
|
165
|
-
throw new Error(`out of range ${value} ${field_name} ${value}`);
|
|
166
|
-
}
|
|
167
|
-
return value;
|
|
168
|
-
},
|
|
169
|
-
require_object_type: require_object_type = function (reserved_spaces = 1, type, value, field_name = "") {
|
|
170
|
-
if (is_empty(value)) {
|
|
171
|
-
return value;
|
|
172
|
-
}
|
|
173
|
-
var object_type = chain_types.object_type[type];
|
|
174
|
-
if (!object_type) {
|
|
175
|
-
throw new Error(`Unknown object type: ${type}, ${field_name}, ${value}`);
|
|
176
|
-
}
|
|
177
|
-
var re = new RegExp(`${reserved_spaces}\.${object_type}\.[0-9]+$`);
|
|
178
|
-
if (!re.test(value)) {
|
|
179
|
-
throw new Error(`Expecting ${type} in format ` + `${reserved_spaces}.${object_type}.[0-9]+ ` + `instead of ${value} ${field_name} ${value}`);
|
|
180
|
-
}
|
|
181
|
-
return value;
|
|
182
|
-
},
|
|
183
|
-
get_instance: get_instance = function (reserve_spaces, type, value, field_name) {
|
|
184
|
-
if (is_empty(value)) {
|
|
185
|
-
return value;
|
|
186
|
-
}
|
|
187
|
-
require_object_type(reserve_spaces, type, value, field_name);
|
|
188
|
-
return to_number(value.split('.')[2]);
|
|
189
|
-
},
|
|
190
|
-
require_relative_type: require_relative_type = function (type, value, field_name) {
|
|
191
|
-
require_object_type(0, type, value, field_name);
|
|
192
|
-
return value;
|
|
193
|
-
},
|
|
194
|
-
get_relative_instance: get_relative_instance = function (type, value, field_name) {
|
|
195
|
-
if (is_empty(value)) {
|
|
196
|
-
return value;
|
|
197
|
-
}
|
|
198
|
-
require_object_type(0, type, value, field_name);
|
|
199
|
-
return to_number(value.split('.')[2]);
|
|
200
|
-
},
|
|
201
|
-
require_protocol_type: require_protocol_type = function (type, value, field_name) {
|
|
202
|
-
require_object_type(1, type, value, field_name);
|
|
203
|
-
return value;
|
|
204
|
-
},
|
|
205
|
-
get_protocol_instance: get_protocol_instance = function (type, value, field_name) {
|
|
206
|
-
if (is_empty(value)) {
|
|
207
|
-
return value;
|
|
208
|
-
}
|
|
209
|
-
require_object_type(1, type, value, field_name);
|
|
210
|
-
return to_number(value.split('.')[2]);
|
|
211
|
-
},
|
|
212
|
-
get_protocol_type: get_protocol_type = function (value, field_name) {
|
|
213
|
-
if (is_empty(value)) {
|
|
214
|
-
return value;
|
|
215
|
-
}
|
|
216
|
-
require_object_id(value, field_name);
|
|
217
|
-
var values = value.split('.');
|
|
218
|
-
return to_number(values[1]);
|
|
219
|
-
},
|
|
220
|
-
get_protocol_type_name(value, field_name) {
|
|
221
|
-
if (is_empty(value)) {
|
|
222
|
-
return value;
|
|
223
|
-
}
|
|
224
|
-
var type_id = get_protocol_type(value, field_name);
|
|
225
|
-
return Object.keys(chain_types.object_type)[type_id];
|
|
226
|
-
},
|
|
227
|
-
require_implementation_type: require_implementation_type = function (type, value, field_name) {
|
|
228
|
-
require_object_type(2, type, value, field_name);
|
|
229
|
-
return value;
|
|
230
|
-
},
|
|
231
|
-
get_implementation_instance: get_implementation_instance = function (type, value, field_name) {
|
|
232
|
-
if (is_empty(value)) {
|
|
233
|
-
return value;
|
|
234
|
-
}
|
|
235
|
-
require_object_type(2, type, value, field_name);
|
|
236
|
-
return to_number(value.split('.')[2]);
|
|
237
|
-
},
|
|
238
|
-
// signed / unsigned decimal
|
|
239
|
-
no_overflow53(value, field_name = "") {
|
|
240
|
-
if (typeof value === "number") {
|
|
241
|
-
if (value > MAX_SAFE_INT || value < MIN_SAFE_INT) {
|
|
242
|
-
throw new Error(`overflow ${field_name} ${value}`);
|
|
243
|
-
}
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
if (typeof value === "string") {
|
|
247
|
-
var int = parseInt(value);
|
|
248
|
-
if (value > MAX_SAFE_INT || value < MIN_SAFE_INT) {
|
|
249
|
-
throw new Error(`overflow ${field_name} ${value}`);
|
|
250
|
-
}
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
if (Long.isLong(value)) {
|
|
254
|
-
// typeof value.toInt() is 'number'
|
|
255
|
-
_my.no_overflow53(value.toInt(), field_name);
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
throw `unsupported type ${field_name}: (${typeof value}) ${value}`;
|
|
259
|
-
},
|
|
260
|
-
// signed / unsigned whole numbers only
|
|
261
|
-
no_overflow64(value, field_name = "") {
|
|
262
|
-
// https://github.com/dcodeIO/Long.js/issues/20
|
|
263
|
-
if (Long.isLong(value)) {
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// BigInteger#isBigInteger https://github.com/cryptocoinjs/bigi/issues/20
|
|
268
|
-
if (value.t !== undefined && value.s !== undefined) {
|
|
269
|
-
_my.no_overflow64(value.toString(), field_name);
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
if (typeof value === "string") {
|
|
273
|
-
// remove leading zeros, will cause a false positive
|
|
274
|
-
value = value.replace(/^0+/, '');
|
|
275
|
-
// remove trailing zeros
|
|
276
|
-
while (/0$/.test(value)) {
|
|
277
|
-
value = value.substring(0, value.length - 1);
|
|
278
|
-
}
|
|
279
|
-
if (/\.$/.test(value)) {
|
|
280
|
-
// remove trailing dot
|
|
281
|
-
value = value.substring(0, value.length - 1);
|
|
282
|
-
}
|
|
283
|
-
if (value === "") {
|
|
284
|
-
value = "0";
|
|
285
|
-
}
|
|
286
|
-
var long_string = Long.fromString(value).toString();
|
|
287
|
-
if (long_string !== value.trim()) {
|
|
288
|
-
throw new Error(`overflow ${field_name} ${value}`);
|
|
289
|
-
}
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
if (typeof value === "number") {
|
|
293
|
-
if (value > MAX_SAFE_INT || value < MIN_SAFE_INT) {
|
|
294
|
-
throw new Error(`overflow ${field_name} ${value}`);
|
|
295
|
-
}
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
throw `unsupported type ${field_name}: (${typeof value}) ${value}`;
|
|
299
|
-
}
|
|
300
|
-
};
|
package/lib/broadcast/helpers.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _api = _interopRequireDefault(require("../api"));
|
|
4
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
5
|
-
exports = module.exports = steemBroadcast => {
|
|
6
|
-
steemBroadcast.addAccountAuth = ({
|
|
7
|
-
signingKey,
|
|
8
|
-
username,
|
|
9
|
-
authorizedUsername,
|
|
10
|
-
role = 'posting',
|
|
11
|
-
weight
|
|
12
|
-
}, cb) => {
|
|
13
|
-
_api.default.getAccounts([username], (err, [userAccount]) => {
|
|
14
|
-
if (err) {
|
|
15
|
-
return cb(new Error(err), null);
|
|
16
|
-
}
|
|
17
|
-
if (!userAccount) {
|
|
18
|
-
return cb(new Error('Invalid account name'), null);
|
|
19
|
-
}
|
|
20
|
-
const updatedAuthority = userAccount[role];
|
|
21
|
-
|
|
22
|
-
/** Release callback if the account already exist in the account_auths array */
|
|
23
|
-
const authorizedAccounts = updatedAuthority.account_auths.map(auth => auth[0]);
|
|
24
|
-
const hasAuthority = authorizedAccounts.indexOf(authorizedUsername) !== -1;
|
|
25
|
-
if (hasAuthority) {
|
|
26
|
-
return cb(null, null);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** Use weight_thresold as default weight */
|
|
30
|
-
weight = weight || userAccount[role].weight_threshold;
|
|
31
|
-
updatedAuthority.account_auths.push([authorizedUsername, weight]);
|
|
32
|
-
const owner = role === 'owner' ? updatedAuthority : undefined;
|
|
33
|
-
const active = role === 'active' ? updatedAuthority : undefined;
|
|
34
|
-
const posting = role === 'posting' ? updatedAuthority : undefined;
|
|
35
|
-
|
|
36
|
-
/** Add authority on user account */
|
|
37
|
-
steemBroadcast.accountUpdate(signingKey, userAccount.name, owner, active, posting, userAccount.memo_key, userAccount.json_metadata, cb);
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
steemBroadcast.removeAccountAuth = ({
|
|
41
|
-
signingKey,
|
|
42
|
-
username,
|
|
43
|
-
authorizedUsername,
|
|
44
|
-
role = 'posting'
|
|
45
|
-
}, cb) => {
|
|
46
|
-
_api.default.getAccounts([username], (err, [userAccount]) => {
|
|
47
|
-
if (err) {
|
|
48
|
-
return cb(new Error(err), null);
|
|
49
|
-
}
|
|
50
|
-
if (!userAccount) {
|
|
51
|
-
return cb(new Error('Invalid account name'), null);
|
|
52
|
-
}
|
|
53
|
-
const updatedAuthority = userAccount[role];
|
|
54
|
-
const totalAuthorizedUser = updatedAuthority.account_auths.length;
|
|
55
|
-
for (let i = 0; i < totalAuthorizedUser; i++) {
|
|
56
|
-
const user = updatedAuthority.account_auths[i];
|
|
57
|
-
if (user[0] === authorizedUsername) {
|
|
58
|
-
updatedAuthority.account_auths.splice(i, 1);
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Release callback if the account does not exist in the account_auths array */
|
|
64
|
-
if (totalAuthorizedUser === updatedAuthority.account_auths.length) {
|
|
65
|
-
return cb(null, null);
|
|
66
|
-
}
|
|
67
|
-
const owner = role === 'owner' ? updatedAuthority : undefined;
|
|
68
|
-
const active = role === 'active' ? updatedAuthority : undefined;
|
|
69
|
-
const posting = role === 'posting' ? updatedAuthority : undefined;
|
|
70
|
-
steemBroadcast.accountUpdate(signingKey, userAccount.name, owner, active, posting, userAccount.memo_key, userAccount.json_metadata, cb);
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
steemBroadcast.addKeyAuth = ({
|
|
74
|
-
signingKey,
|
|
75
|
-
username,
|
|
76
|
-
authorizedKey,
|
|
77
|
-
role = 'posting',
|
|
78
|
-
weight
|
|
79
|
-
}, cb) => {
|
|
80
|
-
_api.default.getAccounts([username], (err, [userAccount]) => {
|
|
81
|
-
if (err) {
|
|
82
|
-
return cb(new Error(err), null);
|
|
83
|
-
}
|
|
84
|
-
if (!userAccount) {
|
|
85
|
-
return cb(new Error('Invalid account name'), null);
|
|
86
|
-
}
|
|
87
|
-
const updatedAuthority = userAccount[role];
|
|
88
|
-
|
|
89
|
-
/** Release callback if the key already exist in the key_auths array */
|
|
90
|
-
const authorizedKeys = updatedAuthority.key_auths.map(auth => auth[0]);
|
|
91
|
-
const hasAuthority = authorizedKeys.indexOf(authorizedKey) !== -1;
|
|
92
|
-
if (hasAuthority) {
|
|
93
|
-
return cb(null, null);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Use weight_thresold as default weight */
|
|
97
|
-
weight = weight || userAccount[role].weight_threshold;
|
|
98
|
-
updatedAuthority.key_auths.push([authorizedKey, weight]);
|
|
99
|
-
const owner = role === 'owner' ? updatedAuthority : undefined;
|
|
100
|
-
const active = role === 'active' ? updatedAuthority : undefined;
|
|
101
|
-
const posting = role === 'posting' ? updatedAuthority : undefined;
|
|
102
|
-
|
|
103
|
-
/** Add authority on user account */
|
|
104
|
-
steemBroadcast.accountUpdate(signingKey, userAccount.name, owner, active, posting, userAccount.memo_key, userAccount.json_metadata, cb);
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
steemBroadcast.removeKeyAuth = ({
|
|
108
|
-
signingKey,
|
|
109
|
-
username,
|
|
110
|
-
authorizedKey,
|
|
111
|
-
role = 'posting'
|
|
112
|
-
}, cb) => {
|
|
113
|
-
_api.default.getAccounts([username], (err, [userAccount]) => {
|
|
114
|
-
if (err) {
|
|
115
|
-
return cb(new Error(err), null);
|
|
116
|
-
}
|
|
117
|
-
if (!userAccount) {
|
|
118
|
-
return cb(new Error('Invalid account name'), null);
|
|
119
|
-
}
|
|
120
|
-
const updatedAuthority = userAccount[role];
|
|
121
|
-
const totalAuthorizedKey = updatedAuthority.key_auths.length;
|
|
122
|
-
for (let i = 0; i < totalAuthorizedKey; i++) {
|
|
123
|
-
const user = updatedAuthority.key_auths[i];
|
|
124
|
-
if (user[0] === authorizedKey) {
|
|
125
|
-
updatedAuthority.key_auths.splice(i, 1);
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/** Release callback if the key does not exist in the key_auths array */
|
|
131
|
-
if (totalAuthorizedKey === updatedAuthority.key_auths.length) {
|
|
132
|
-
return cb(null, null);
|
|
133
|
-
}
|
|
134
|
-
const owner = role === 'owner' ? updatedAuthority : undefined;
|
|
135
|
-
const active = role === 'active' ? updatedAuthority : undefined;
|
|
136
|
-
const posting = role === 'posting' ? updatedAuthority : undefined;
|
|
137
|
-
steemBroadcast.accountUpdate(signingKey, userAccount.name, owner, active, posting, userAccount.memo_key, userAccount.json_metadata, cb);
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
};
|
package/lib/broadcast/index.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _bluebird = _interopRequireDefault(require("bluebird"));
|
|
4
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
5
|
-
var _helpers = _interopRequireDefault(require("./helpers"));
|
|
6
|
-
var _formatter = _interopRequireDefault(require("../formatter"));
|
|
7
|
-
var _operations = _interopRequireDefault(require("./operations"));
|
|
8
|
-
var _api = _interopRequireDefault(require("../api"));
|
|
9
|
-
var _auth = _interopRequireDefault(require("../auth"));
|
|
10
|
-
var _utils = require("../utils");
|
|
11
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
const debug = (0, _debug.default)('steem:broadcast');
|
|
13
|
-
const noop = function () {};
|
|
14
|
-
const formatter = (0, _formatter.default)(_api.default);
|
|
15
|
-
const steemBroadcast = {};
|
|
16
|
-
|
|
17
|
-
// Base transaction logic -----------------------------------------------------
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Sign and broadcast transactions on the steem network
|
|
21
|
-
* @param {Object} tx - Transaction object
|
|
22
|
-
* @param {Object|String} privKeys - Private keys or key string
|
|
23
|
-
* @param {Function} [callback] - Optional callback function
|
|
24
|
-
* @return {Promise} - Returns a promise if no callback is provided
|
|
25
|
-
*/
|
|
26
|
-
steemBroadcast.send = function steemBroadcast$send(tx, privKeys, callback) {
|
|
27
|
-
const resultP = steemBroadcast._prepareTransaction(tx).then(transaction => {
|
|
28
|
-
debug('Signing transaction (transaction, transaction.operations)', transaction, transaction.operations);
|
|
29
|
-
return _bluebird.default.join(transaction, _auth.default.signTransaction(transaction, privKeys));
|
|
30
|
-
}).spread((transaction, signedTransaction) => {
|
|
31
|
-
debug('Broadcasting transaction (transaction, transaction.operations)', transaction, transaction.operations);
|
|
32
|
-
return _api.default.broadcastTransactionSynchronousAsync(signedTransaction).then(result => {
|
|
33
|
-
return Object.assign({}, result, signedTransaction);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
if (callback) {
|
|
37
|
-
resultP.nodeify(callback);
|
|
38
|
-
return undefined;
|
|
39
|
-
} else {
|
|
40
|
-
return resultP;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
steemBroadcast._prepareTransaction = function steemBroadcast$_prepareTransaction(tx) {
|
|
44
|
-
const propertiesP = _api.default.getDynamicGlobalPropertiesAsync();
|
|
45
|
-
return propertiesP.then(properties => {
|
|
46
|
-
// Set defaults on the transaction
|
|
47
|
-
const chainDate = new Date(properties.time + 'Z');
|
|
48
|
-
const refBlockNum = properties.last_irreversible_block_num - 1 & 0xFFFF;
|
|
49
|
-
return _api.default.getBlockHeaderAsync(properties.last_irreversible_block_num).then(block => {
|
|
50
|
-
const headBlockId = block ? block.previous : '0000000000000000000000000000000000000000';
|
|
51
|
-
return Object.assign({
|
|
52
|
-
ref_block_num: refBlockNum,
|
|
53
|
-
ref_block_prefix: new Buffer.from(headBlockId, 'hex').readUInt32LE(4),
|
|
54
|
-
expiration: new Date(chainDate.getTime() + 600 * 1000)
|
|
55
|
-
}, tx);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// Generated wrapper ----------------------------------------------------------
|
|
61
|
-
|
|
62
|
-
// Generate operations from operations.json
|
|
63
|
-
_operations.default.forEach(operation => {
|
|
64
|
-
const operationName = (0, _utils.camelCase)(operation.operation);
|
|
65
|
-
const operationParams = operation.params || [];
|
|
66
|
-
const useCommentPermlink = operationParams.indexOf('parent_author') !== -1 && operationParams.indexOf('parent_permlink') !== -1;
|
|
67
|
-
steemBroadcast[`${operationName}With`] = function steemBroadcast$specializedSendWith(wif, options, callback) {
|
|
68
|
-
debug(`Sending operation "${operationName}" with`, {
|
|
69
|
-
options,
|
|
70
|
-
callback
|
|
71
|
-
});
|
|
72
|
-
const keys = {};
|
|
73
|
-
if (operation.roles && operation.roles.length) {
|
|
74
|
-
keys[operation.roles[0]] = wif; // TODO - Automatically pick a role? Send all?
|
|
75
|
-
}
|
|
76
|
-
return steemBroadcast.send({
|
|
77
|
-
extensions: [],
|
|
78
|
-
operations: [[operation.operation, Object.assign({}, options, options.json_metadata != null ? {
|
|
79
|
-
json_metadata: toString(options.json_metadata)
|
|
80
|
-
} : {}, useCommentPermlink && options.permlink == null ? {
|
|
81
|
-
permlink: formatter.commentPermlink(options.parent_author, options.parent_permlink)
|
|
82
|
-
} : {})]]
|
|
83
|
-
}, keys, callback);
|
|
84
|
-
};
|
|
85
|
-
steemBroadcast[operationName] = function steemBroadcast$specializedSend(wif, ...args) {
|
|
86
|
-
debug(`Parsing operation "${operationName}" with`, {
|
|
87
|
-
args
|
|
88
|
-
});
|
|
89
|
-
const options = operationParams.reduce((memo, param, i) => {
|
|
90
|
-
memo[param] = args[i]; // eslint-disable-line no-param-reassign
|
|
91
|
-
return memo;
|
|
92
|
-
}, {});
|
|
93
|
-
// Check if the last argument is a function (callback)
|
|
94
|
-
let callback = null;
|
|
95
|
-
if (args.length > operationParams.length && typeof args[operationParams.length] === 'function') {
|
|
96
|
-
callback = args[operationParams.length];
|
|
97
|
-
}
|
|
98
|
-
return steemBroadcast[`${operationName}With`](wif, options, callback);
|
|
99
|
-
};
|
|
100
|
-
});
|
|
101
|
-
const toString = obj => typeof obj === 'object' ? JSON.stringify(obj) : obj;
|
|
102
|
-
(0, _helpers.default)(steemBroadcast);
|
|
103
|
-
|
|
104
|
-
// For backwards compatibility, maintain the Async versions
|
|
105
|
-
_bluebird.default.promisifyAll(steemBroadcast);
|
|
106
|
-
exports = module.exports = steemBroadcast;
|