@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.
Files changed (128) hide show
  1. package/README.md +202 -105
  2. package/dist/api/index.d.ts +128 -0
  3. package/dist/api/methods.d.ts +9 -0
  4. package/dist/api/rpc-auth.d.ts +43 -0
  5. package/dist/api/transports/base.d.ts +13 -0
  6. package/dist/api/transports/http.d.ts +9 -0
  7. package/dist/api/transports/index.d.ts +9 -0
  8. package/dist/api/transports/types.d.ts +35 -0
  9. package/dist/api/transports/ws.d.ts +18 -0
  10. package/dist/auth/ecc/index.d.ts +9 -0
  11. package/dist/auth/ecc/src/address.d.ts +13 -0
  12. package/dist/auth/ecc/src/aes.d.ts +16 -0
  13. package/dist/auth/ecc/src/brain_key.d.ts +1 -0
  14. package/dist/auth/ecc/src/ecdsa.d.ts +28 -0
  15. package/dist/auth/ecc/src/ecsignature.d.ts +19 -0
  16. package/dist/auth/ecc/src/enforce_types.d.ts +5 -0
  17. package/dist/auth/ecc/src/hash.d.ts +25 -0
  18. package/dist/auth/ecc/src/index.d.ts +9 -0
  19. package/dist/auth/ecc/src/key_private.d.ts +38 -0
  20. package/dist/auth/ecc/src/key_public.d.ts +41 -0
  21. package/dist/auth/ecc/src/key_utils.d.ts +9 -0
  22. package/dist/auth/ecc/src/signature.d.ts +18 -0
  23. package/dist/auth/ecc.d.ts +3 -0
  24. package/dist/auth/index.d.ts +48 -0
  25. package/dist/auth/key_classes.d.ts +3 -0
  26. package/dist/auth/serializer/transaction.d.ts +5 -0
  27. package/dist/auth/serializer.d.ts +19 -0
  28. package/dist/broadcast/helpers.d.ts +11 -0
  29. package/dist/broadcast/index.d.ts +43 -0
  30. package/dist/broadcast/operations.d.ts +6 -0
  31. package/dist/config.d.ts +27 -0
  32. package/dist/crypto/index.d.ts +25 -0
  33. package/dist/formatter/index.d.ts +92 -0
  34. package/dist/index.cjs +26436 -0
  35. package/dist/index.cjs.map +1 -0
  36. package/dist/index.d.ts +30 -0
  37. package/dist/index.js +26400 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/index.umd.js +58121 -0
  40. package/dist/index.umd.js.map +1 -0
  41. package/dist/memo/index.d.ts +11 -0
  42. package/dist/operations/index.d.ts +44 -0
  43. package/dist/serializer/convert.d.ts +12 -0
  44. package/dist/serializer/index.d.ts +11 -0
  45. package/dist/serializer/number_utils.d.ts +8 -0
  46. package/dist/serializer/precision.d.ts +5 -0
  47. package/dist/serializer/types.d.ts +36 -0
  48. package/dist/types/index.d.ts +131 -0
  49. package/dist/types.d.ts +34 -0
  50. package/dist/utils/debug.d.ts +36 -0
  51. package/dist/utils/index.d.ts +9 -0
  52. package/dist/utils.d.ts +2 -0
  53. package/package.json +68 -87
  54. package/.dockerignore +0 -12
  55. package/.editorconfig +0 -20
  56. package/.eslintrc +0 -27
  57. package/LICENSE +0 -21
  58. package/circle.yml +0 -3
  59. package/config.json +0 -10
  60. package/dist/steem-tests.min.js +0 -4097
  61. package/dist/steem.min.js +0 -2089
  62. package/docker-webpack.config.js +0 -44
  63. package/lib/api/index.js +0 -315
  64. package/lib/api/methods.js +0 -428
  65. package/lib/api/rpc-auth.js +0 -135
  66. package/lib/api/transports/base.js +0 -31
  67. package/lib/api/transports/http.js +0 -157
  68. package/lib/api/transports/index.js +0 -13
  69. package/lib/api/transports/ws.js +0 -128
  70. package/lib/auth/ecc/index.js +0 -13
  71. package/lib/auth/ecc/src/address.js +0 -54
  72. package/lib/auth/ecc/src/aes.js +0 -148
  73. package/lib/auth/ecc/src/brain_key.js +0 -13
  74. package/lib/auth/ecc/src/ecdsa.js +0 -193
  75. package/lib/auth/ecc/src/ecsignature.js +0 -102
  76. package/lib/auth/ecc/src/enforce_types.js +0 -42
  77. package/lib/auth/ecc/src/hash.js +0 -58
  78. package/lib/auth/ecc/src/key_private.js +0 -159
  79. package/lib/auth/ecc/src/key_public.js +0 -143
  80. package/lib/auth/ecc/src/key_utils.js +0 -70
  81. package/lib/auth/ecc/src/signature.js +0 -135
  82. package/lib/auth/index.js +0 -113
  83. package/lib/auth/memo.js +0 -119
  84. package/lib/auth/serializer/index.js +0 -15
  85. package/lib/auth/serializer/src/ChainTypes.js +0 -87
  86. package/lib/auth/serializer/src/convert.js +0 -34
  87. package/lib/auth/serializer/src/error_with_cause.js +0 -27
  88. package/lib/auth/serializer/src/fast_parser.js +0 -57
  89. package/lib/auth/serializer/src/number_utils.js +0 -43
  90. package/lib/auth/serializer/src/object_id.js +0 -43
  91. package/lib/auth/serializer/src/operations.js +0 -695
  92. package/lib/auth/serializer/src/precision.js +0 -77
  93. package/lib/auth/serializer/src/serializer.js +0 -165
  94. package/lib/auth/serializer/src/template.js +0 -22
  95. package/lib/auth/serializer/src/types.js +0 -1085
  96. package/lib/auth/serializer/src/validation.js +0 -300
  97. package/lib/broadcast/helpers.js +0 -140
  98. package/lib/broadcast/index.js +0 -106
  99. package/lib/broadcast/operations.js +0 -255
  100. package/lib/browser.js +0 -25
  101. package/lib/config.js +0 -23
  102. package/lib/formatter.js +0 -163
  103. package/lib/index.js +0 -21
  104. package/lib/utils.js +0 -50
  105. package/node-18.dockerfile +0 -28
  106. package/test/Crypto.js +0 -100
  107. package/test/KeyFormats.js +0 -105
  108. package/test/all_types.js +0 -115
  109. package/test/api.test.js +0 -363
  110. package/test/broadcast.test.js +0 -231
  111. package/test/browser/BrowserTests.js +0 -55
  112. package/test/comment.test.js +0 -83
  113. package/test/hf20-accounts.test.js +0 -76
  114. package/test/hf21-sps.test.js +0 -78
  115. package/test/memo.test.js +0 -37
  116. package/test/number_utils.js +0 -28
  117. package/test/operations_test.js +0 -39
  118. package/test/promise-broadcast.test.js +0 -86
  119. package/test/reputation.test.js +0 -68
  120. package/test/smt.test.js +0 -347
  121. package/test/test-post.json +0 -13
  122. package/test/test.html +0 -13
  123. package/test/test_helper.js +0 -19
  124. package/test/types_test.js +0 -139
  125. package/test-github-workflow.bat +0 -19
  126. package/test-github-workflow.sh +0 -15
  127. package/webpack/makeConfig.js +0 -113
  128. package/webpack.config.js +0 -2
@@ -1,44 +0,0 @@
1
- const path = require('path');
2
- const webpack = require('webpack');
3
-
4
- module.exports = {
5
- mode: 'production',
6
- devtool: 'source-map',
7
- entry: {
8
- steem: path.resolve(__dirname, 'src/browser.js'),
9
- },
10
- output: {
11
- path: path.resolve(__dirname, 'dist'),
12
- filename: '[name].min.js',
13
- },
14
- resolve: {
15
- alias: {
16
- '@exodus/bytebuffer': 'bytebuffer',
17
- }
18
- },
19
- node: {
20
- stream: true,
21
- crypto: 'empty',
22
- path: 'empty',
23
- fs: 'empty'
24
- },
25
- module: {
26
- rules: [
27
- {
28
- test: /\.js?$/,
29
- use: 'babel-loader',
30
- exclude: /node_modules/,
31
- },
32
- {
33
- test: /\.json?$/,
34
- use: 'json-loader'
35
- },
36
- ],
37
- },
38
- plugins: [
39
- new webpack.optimize.AggressiveMergingPlugin()
40
- ],
41
- optimization: {
42
- minimize: true,
43
- }
44
- };
package/lib/api/index.js DELETED
@@ -1,315 +0,0 @@
1
- "use strict";
2
-
3
- var _events = _interopRequireDefault(require("events"));
4
- var _bluebird = _interopRequireDefault(require("bluebird"));
5
- var _config = _interopRequireDefault(require("../config"));
6
- var _methods = _interopRequireDefault(require("./methods"));
7
- var _transports = _interopRequireDefault(require("./transports"));
8
- var _utils = require("../utils");
9
- var _ecc = require("../auth/ecc");
10
- var _serializer = require("../auth/serializer");
11
- var _http = require("./transports/http");
12
- var _rpcAuth = require("./rpc-auth");
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
- class Steem extends _events.default {
15
- constructor(options = {}) {
16
- super(options);
17
- this._setTransport(options);
18
- this._setLogger(options);
19
- this.options = options;
20
- this.seqNo = 0; // used for rpc calls
21
- _methods.default.forEach(method => {
22
- const methodName = method.method_name || (0, _utils.camelCase)(method.method);
23
- const methodParams = method.params || [];
24
- this[`${methodName}With`] = (options, callback) => {
25
- let params;
26
- if (!method.is_object) {
27
- params = methodParams.map(param => options[param]);
28
- } else {
29
- params = options;
30
- }
31
- return this.send(method.api, {
32
- method: method.method,
33
- params: params
34
- }, callback);
35
- };
36
- this[methodName] = (...args) => {
37
- const options = methodParams.reduce((memo, param, i) => {
38
- memo[param] = args[i]; // eslint-disable-line no-param-reassign
39
- return memo;
40
- }, {});
41
- const callback = args[methodParams.length];
42
- return this[`${methodName}With`](options, callback);
43
- };
44
- this[`${methodName}WithAsync`] = _bluebird.default.promisify(this[`${methodName}With`]);
45
- this[`${methodName}Async`] = _bluebird.default.promisify(this[methodName]);
46
- });
47
- this.callAsync = _bluebird.default.promisify(this.call);
48
- this.signedCallAsync = _bluebird.default.promisify(this.signedCall);
49
- }
50
- _setTransport(options) {
51
- if (options.url && options.url.match('^((http|https)?:\/\/)')) {
52
- options.uri = options.url;
53
- options.transport = 'http';
54
- this._transportType = options.transport;
55
- this.options = options;
56
- this.transport = new _transports.default.http(options);
57
- } else if (options.url && options.url.match('^((ws|wss)?:\/\/)')) {
58
- options.websocket = options.url;
59
- options.transport = 'ws';
60
- this._transportType = options.transport;
61
- this.options = options;
62
- this.transport = new _transports.default.ws(options);
63
- } else if (options.transport) {
64
- if (this.transport && this._transportType !== options.transport) {
65
- this.transport.stop();
66
- }
67
- this._transportType = options.transport;
68
- if (typeof options.transport === 'string') {
69
- if (!_transports.default[options.transport]) {
70
- throw new TypeError('Invalid `transport`, valid values are `http`, `ws` or a class');
71
- }
72
- this.transport = new _transports.default[options.transport](options);
73
- } else {
74
- this.transport = new options.transport(options);
75
- }
76
- } else {
77
- this.transport = new _transports.default.ws(options);
78
- }
79
- }
80
- _setLogger(options) {
81
- if (options.hasOwnProperty('logger')) {
82
- switch (typeof options.logger) {
83
- case 'function':
84
- this.__logger = {
85
- log: options.logger
86
- };
87
- break;
88
- case 'object':
89
- if (typeof options.logger.log !== 'function') {
90
- throw new Error('setOptions({logger:{}}) must have a property .log of type function');
91
- }
92
- this.__logger = options.logger;
93
- break;
94
- case 'undefined':
95
- if (this.__logger) break;
96
- default:
97
- this.__logger = false;
98
- }
99
- }
100
- }
101
- log(logLevel) {
102
- if (this.__logger) {
103
- if (arguments.length > 1 && typeof this.__logger[logLevel] === 'function') {
104
- let args = Array.prototype.slice.call(arguments, 1);
105
- this.__logger[logLevel].apply(this.__logger, args);
106
- } else {
107
- this.__logger.log.apply(this.__logger, arguments);
108
- }
109
- }
110
- }
111
- start() {
112
- return this.transport.start();
113
- }
114
- stop() {
115
- return this.transport.stop();
116
- }
117
- send(api, data, callback) {
118
- var cb = callback;
119
- if (this.__logger) {
120
- let id = Math.random();
121
- let self = this;
122
- this.log('xmit:' + id + ':', data);
123
- cb = function (e, d) {
124
- if (e) {
125
- self.log('error', 'rsp:' + id + ':\n\n', e, d);
126
- } else {
127
- self.log('rsp:' + id + ':', d);
128
- }
129
- if (callback) {
130
- callback.apply(self, arguments);
131
- }
132
- };
133
- }
134
- return this.transport.send(api, data, cb);
135
- }
136
- call(method, params, callback) {
137
- if (this._transportType !== 'http') {
138
- callback(new Error('RPC methods can only be called when using http transport'));
139
- return;
140
- }
141
- const id = ++this.seqNo;
142
- (0, _http.jsonRpc)(this.options.uri, {
143
- method,
144
- params,
145
- id
146
- }).then(res => {
147
- callback(null, res);
148
- }, err => {
149
- callback(err);
150
- });
151
- }
152
- signedCall(method, params, account, key, callback) {
153
- if (this._transportType !== 'http') {
154
- callback(new Error('RPC methods can only be called when using http transport'));
155
- return;
156
- }
157
- const id = ++this.seqNo;
158
- let request;
159
- try {
160
- request = (0, _rpcAuth.sign)({
161
- method,
162
- params,
163
- id
164
- }, account, [key]);
165
- } catch (error) {
166
- callback(error);
167
- return;
168
- }
169
- (0, _http.jsonRpc)(this.options.uri, request).then(res => {
170
- callback(null, res);
171
- }, err => {
172
- callback(err);
173
- });
174
- }
175
- setOptions(options) {
176
- Object.assign(this.options, options);
177
- this._setLogger(options);
178
- this._setTransport(options);
179
- this.transport.setOptions(options);
180
- if (options.hasOwnProperty('useTestNet')) {
181
- _config.default.set('address_prefix', options.useTestNet ? 'TST' : 'STM');
182
- }
183
- }
184
- setWebSocket(url) {
185
- this.setOptions({
186
- websocket: url
187
- });
188
- }
189
- setUri(url) {
190
- this.setOptions({
191
- uri: url
192
- });
193
- }
194
- streamBlockNumber(mode = 'head', callback, ts = 200) {
195
- if (typeof mode === 'function') {
196
- callback = mode;
197
- mode = 'head';
198
- }
199
- let current = '';
200
- let running = true;
201
- const update = () => {
202
- if (!running) return;
203
- this.getDynamicGlobalPropertiesAsync().then(result => {
204
- const blockId = mode === 'irreversible' ? result.last_irreversible_block_num : result.head_block_number;
205
- if (blockId !== current) {
206
- if (current) {
207
- for (let i = current; i < blockId; i++) {
208
- if (i !== current) {
209
- callback(null, i);
210
- }
211
- current = i;
212
- }
213
- } else {
214
- current = blockId;
215
- callback(null, blockId);
216
- }
217
- }
218
- _bluebird.default.delay(ts).then(() => {
219
- update();
220
- });
221
- }, err => {
222
- callback(err);
223
- });
224
- };
225
- update();
226
- return () => {
227
- running = false;
228
- };
229
- }
230
- streamBlock(mode = 'head', callback) {
231
- if (typeof mode === 'function') {
232
- callback = mode;
233
- mode = 'head';
234
- }
235
- let current = '';
236
- let last = '';
237
- const release = this.streamBlockNumber(mode, (err, id) => {
238
- if (err) {
239
- release();
240
- callback(err);
241
- return;
242
- }
243
- current = id;
244
- if (current !== last) {
245
- last = current;
246
- this.getBlock(current, callback);
247
- }
248
- });
249
- return release;
250
- }
251
- streamTransactions(mode = 'head', callback) {
252
- if (typeof mode === 'function') {
253
- callback = mode;
254
- mode = 'head';
255
- }
256
- const release = this.streamBlock(mode, (err, result) => {
257
- if (err) {
258
- release();
259
- callback(err);
260
- return;
261
- }
262
- if (result && result.transactions) {
263
- result.transactions.forEach(transaction => {
264
- callback(null, transaction);
265
- });
266
- }
267
- });
268
- return release;
269
- }
270
- streamOperations(mode = 'head', callback) {
271
- if (typeof mode === 'function') {
272
- callback = mode;
273
- mode = 'head';
274
- }
275
- const release = this.streamTransactions(mode, (err, transaction) => {
276
- if (err) {
277
- release();
278
- callback(err);
279
- return;
280
- }
281
- transaction.operations.forEach(operation => {
282
- callback(null, operation);
283
- });
284
- });
285
- return release;
286
- }
287
- broadcastTransactionSynchronousWith(options, callback) {
288
- const trx = options.trx;
289
- return this.send('network_broadcast_api', {
290
- method: 'broadcast_transaction_synchronous',
291
- params: [trx]
292
- }, (err, result) => {
293
- if (err) {
294
- const {
295
- signed_transaction
296
- } = _serializer.ops;
297
- // console.log('-- broadcastTransactionSynchronous -->', JSON.stringify(signed_transaction.toObject(trx), null, 2));
298
- // toObject converts objects into serializable types
299
- const trObject = signed_transaction.toObject(trx);
300
- const buf = signed_transaction.toBuffer(trx);
301
- err.digest = _ecc.hash.sha256(buf).toString('hex');
302
- err.transaction_id = buf.toString('hex');
303
- err.transaction = JSON.stringify(trObject);
304
- callback(err, '');
305
- } else {
306
- callback('', result);
307
- }
308
- });
309
- }
310
- }
311
-
312
- // Export singleton instance
313
- const steem = new Steem(_config.default);
314
- exports = module.exports = steem;
315
- exports.Steem = Steem;