@steemit/steem-js 0.7.11 → 0.8.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 +22 -3
- package/circle.yml +1 -1
- package/config.json +1 -1
- package/dist/steem-tests.min.js +4097 -23
- package/dist/steem.min.js +2089 -18
- package/docker-webpack.config.js +44 -0
- package/lib/api/index.js +305 -412
- package/lib/api/methods.js +16 -1
- package/lib/api/rpc-auth.js +135 -0
- package/lib/api/transports/base.js +25 -66
- package/lib/api/transports/http.js +114 -129
- package/lib/api/transports/index.js +8 -15
- package/lib/api/transports/ws.js +107 -207
- package/lib/auth/ecc/index.js +9 -9
- package/lib/auth/ecc/src/address.js +48 -78
- package/lib/auth/ecc/src/aes.js +93 -129
- package/lib/auth/ecc/src/brain_key.js +7 -7
- package/lib/auth/ecc/src/ecdsa.js +7 -33
- package/lib/auth/ecc/src/ecsignature.js +4 -30
- package/lib/auth/ecc/src/enforce_types.js +1 -8
- package/lib/auth/ecc/src/hash.js +16 -25
- package/lib/auth/ecc/src/key_private.js +146 -199
- package/lib/auth/ecc/src/key_public.js +130 -202
- package/lib/auth/ecc/src/key_utils.js +64 -106
- package/lib/auth/ecc/src/signature.js +125 -177
- package/lib/auth/index.js +84 -97
- package/lib/auth/memo.js +90 -118
- package/lib/auth/serializer/index.js +12 -18
- package/lib/auth/serializer/src/ChainTypes.js +0 -3
- package/lib/auth/serializer/src/convert.js +29 -32
- package/lib/auth/serializer/src/error_with_cause.js +22 -37
- package/lib/auth/serializer/src/fast_parser.js +54 -74
- package/lib/auth/serializer/src/number_utils.js +30 -54
- package/lib/auth/serializer/src/object_id.js +37 -62
- package/lib/auth/serializer/src/operations.js +597 -689
- package/lib/auth/serializer/src/precision.js +55 -73
- package/lib/auth/serializer/src/serializer.js +158 -204
- package/lib/auth/serializer/src/template.js +13 -8
- package/lib/auth/serializer/src/types.js +949 -1102
- package/lib/auth/serializer/src/validation.js +268 -328
- package/lib/broadcast/helpers.js +61 -98
- package/lib/broadcast/index.js +61 -82
- package/lib/browser.js +15 -19
- package/lib/config.js +16 -38
- package/lib/formatter.js +89 -115
- package/lib/index.js +19 -17
- package/lib/utils.js +4 -9
- package/node-18.dockerfile +28 -0
- package/package.json +62 -38
- package/test/Crypto.js +16 -16
- package/test/KeyFormats.js +1 -1
- package/test/api.test.js +37 -0
- package/test/broadcast.test.js +14 -8
- package/test/comment.test.js +17 -3
- package/test/operations_test.js +1 -1
- package/test/promise-broadcast.test.js +86 -0
- package/test/reputation.test.js +68 -0
- package/test/smt.test.js +10 -10
- package/test-github-workflow.bat +19 -0
- package/test-github-workflow.sh +15 -0
- package/webpack/makeConfig.js +25 -17
- package/.circleci/config.yml +0 -23
- package/dist/statistics.html +0 -208
- package/dist/steem-tests.min.js.gz +0 -0
- package/dist/steem-tests.min.js.map +0 -1
- package/dist/steem.min.js.gz +0 -0
- package/dist/steem.min.js.map +0 -1
- package/lib/auth/ecc/README.md +0 -20
- package/lib/auth/ecc/package.json +0 -36
- package/lib/auth/serializer/README.md +0 -13
- package/lib/auth/serializer/package.json +0 -32
- package/node-4.dockerfile +0 -6
- package/node-6.dockerfile +0 -6
- package/yarn.lock +0 -3336
package/lib/auth/ecc/src/hash.js
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var _createHash2 = _interopRequireDefault(_createHash);
|
|
6
|
-
|
|
7
|
-
var _createHmac = require('create-hmac');
|
|
8
|
-
|
|
9
|
-
var _createHmac2 = _interopRequireDefault(_createHmac);
|
|
10
|
-
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
3
|
+
const createHash = require('create-hash');
|
|
4
|
+
const createHmac = require('create-hmac');
|
|
12
5
|
|
|
13
6
|
/** @arg {string|Buffer} data
|
|
14
7
|
@arg {string} [digest = null] - 'hex', 'binary' or 'base64'
|
|
15
8
|
@return {string|Buffer} - Buffer when digest is null, or string
|
|
16
9
|
*/
|
|
17
10
|
function sha1(data, encoding) {
|
|
18
|
-
|
|
11
|
+
return createHash('sha1').update(data).digest(encoding);
|
|
19
12
|
}
|
|
20
13
|
|
|
21
14
|
/** @arg {string|Buffer} data
|
|
@@ -23,7 +16,7 @@ function sha1(data, encoding) {
|
|
|
23
16
|
@return {string|Buffer} - Buffer when digest is null, or string
|
|
24
17
|
*/
|
|
25
18
|
function sha256(data, encoding) {
|
|
26
|
-
|
|
19
|
+
return createHash('sha256').update(data).digest(encoding);
|
|
27
20
|
}
|
|
28
21
|
|
|
29
22
|
/** @arg {string|Buffer} data
|
|
@@ -31,15 +24,13 @@ function sha256(data, encoding) {
|
|
|
31
24
|
@return {string|Buffer} - Buffer when digest is null, or string
|
|
32
25
|
*/
|
|
33
26
|
function sha512(data, encoding) {
|
|
34
|
-
|
|
27
|
+
return createHash('sha512').update(data).digest(encoding);
|
|
35
28
|
}
|
|
36
|
-
|
|
37
29
|
function HmacSHA256(buffer, secret) {
|
|
38
|
-
|
|
30
|
+
return createHmac('sha256', secret).update(buffer).digest();
|
|
39
31
|
}
|
|
40
|
-
|
|
41
32
|
function ripemd160(data) {
|
|
42
|
-
|
|
33
|
+
return createHash('rmd160').update(data).digest();
|
|
43
34
|
}
|
|
44
35
|
|
|
45
36
|
// function hash160(buffer) {
|
|
@@ -56,12 +47,12 @@ function ripemd160(data) {
|
|
|
56
47
|
// }
|
|
57
48
|
|
|
58
49
|
module.exports = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
50
|
+
sha1: sha1,
|
|
51
|
+
sha256: sha256,
|
|
52
|
+
sha512: sha512,
|
|
53
|
+
HmacSHA256: HmacSHA256,
|
|
54
|
+
ripemd160: ripemd160
|
|
55
|
+
// hash160: hash160,
|
|
56
|
+
// hash256: hash256,
|
|
57
|
+
// HmacSHA512: HmacSHA512
|
|
67
58
|
};
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
4
|
-
|
|
5
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
1
|
+
"use strict";
|
|
6
2
|
|
|
7
3
|
var ecurve = require('ecurve');
|
|
8
4
|
var Point = ecurve.Point;
|
|
@@ -12,201 +8,152 @@ var base58 = require('bs58');
|
|
|
12
8
|
var assert = require('assert');
|
|
13
9
|
var hash = require('./hash');
|
|
14
10
|
var PublicKey = require('./key_public');
|
|
15
|
-
|
|
16
11
|
var G = secp256k1.G;
|
|
17
12
|
var n = secp256k1.n;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
class PrivateKey {
|
|
14
|
+
/**
|
|
15
|
+
@private see static functions
|
|
16
|
+
@param {BigInteger}
|
|
17
|
+
*/
|
|
18
|
+
constructor(d) {
|
|
19
|
+
this.d = d;
|
|
20
|
+
}
|
|
21
|
+
static fromBuffer(buf) {
|
|
22
|
+
if (!Buffer.isBuffer(buf)) {
|
|
23
|
+
throw new Error("Expecting parameter to be a Buffer type");
|
|
29
24
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return PrivateKey.fromBuffer(hash.sha256(seed));
|
|
164
|
-
}
|
|
165
|
-
}, {
|
|
166
|
-
key: 'isWif',
|
|
167
|
-
value: function isWif(text) {
|
|
168
|
-
try {
|
|
169
|
-
this.fromWif(text);
|
|
170
|
-
return true;
|
|
171
|
-
} catch (e) {
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
@throws {AssertError|Error} parsing key
|
|
178
|
-
@return {string} Wallet Import Format (still a secret, Not encrypted)
|
|
179
|
-
*/
|
|
180
|
-
|
|
181
|
-
}, {
|
|
182
|
-
key: 'fromWif',
|
|
183
|
-
value: function fromWif(_private_wif) {
|
|
184
|
-
var private_wif = new Buffer(base58.decode(_private_wif));
|
|
185
|
-
var version = private_wif.readUInt8(0);
|
|
186
|
-
assert.equal(0x80, version, 'Expected version ' + 0x80 + ', instead got ' + version);
|
|
187
|
-
// checksum includes the version
|
|
188
|
-
var private_key = private_wif.slice(0, -4);
|
|
189
|
-
var checksum = private_wif.slice(-4);
|
|
190
|
-
var new_checksum = hash.sha256(private_key);
|
|
191
|
-
new_checksum = hash.sha256(new_checksum);
|
|
192
|
-
new_checksum = new_checksum.slice(0, 4);
|
|
193
|
-
if (checksum.toString() !== new_checksum.toString()) throw new Error('Invalid WIF key (checksum miss-match)');
|
|
194
|
-
|
|
195
|
-
private_key = private_key.slice(1);
|
|
196
|
-
return PrivateKey.fromBuffer(private_key);
|
|
197
|
-
}
|
|
198
|
-
}, {
|
|
199
|
-
key: 'fromHex',
|
|
200
|
-
value: function fromHex(hex) {
|
|
201
|
-
return PrivateKey.fromBuffer(new Buffer(hex, 'hex'));
|
|
202
|
-
}
|
|
203
|
-
}]);
|
|
204
|
-
|
|
205
|
-
return PrivateKey;
|
|
206
|
-
}();
|
|
207
|
-
|
|
25
|
+
if (32 !== buf.length) {
|
|
26
|
+
console.log(`WARN: Expecting 32 bytes, instead got ${buf.length}, stack trace:`, new Error().stack);
|
|
27
|
+
}
|
|
28
|
+
if (buf.length === 0) {
|
|
29
|
+
throw new Error("Empty buffer");
|
|
30
|
+
}
|
|
31
|
+
return new PrivateKey(BigInteger.fromBuffer(buf));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @arg {string} seed - any length string. This is private, the same seed produces the same private key every time. */
|
|
35
|
+
static fromSeed(seed) {
|
|
36
|
+
// generate_private_key
|
|
37
|
+
if (!(typeof seed === 'string')) {
|
|
38
|
+
throw new Error('seed must be of type string');
|
|
39
|
+
}
|
|
40
|
+
return PrivateKey.fromBuffer(hash.sha256(seed));
|
|
41
|
+
}
|
|
42
|
+
static isWif(text) {
|
|
43
|
+
try {
|
|
44
|
+
this.fromWif(text);
|
|
45
|
+
return true;
|
|
46
|
+
} catch (e) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
@throws {AssertError|Error} parsing key
|
|
53
|
+
@return {string} Wallet Import Format (still a secret, Not encrypted)
|
|
54
|
+
*/
|
|
55
|
+
static fromWif(_private_wif) {
|
|
56
|
+
var private_wif = new Buffer.from(base58.decode(_private_wif));
|
|
57
|
+
var version = private_wif.readUInt8(0);
|
|
58
|
+
assert.equal(0x80, version, `Expected version ${0x80}, instead got ${version}`);
|
|
59
|
+
// checksum includes the version
|
|
60
|
+
var private_key = private_wif.slice(0, -4);
|
|
61
|
+
var checksum = private_wif.slice(-4);
|
|
62
|
+
var new_checksum = hash.sha256(private_key);
|
|
63
|
+
new_checksum = hash.sha256(new_checksum);
|
|
64
|
+
new_checksum = new_checksum.slice(0, 4);
|
|
65
|
+
if (checksum.toString() !== new_checksum.toString()) throw new Error('Invalid WIF key (checksum miss-match)');
|
|
66
|
+
private_key = private_key.slice(1);
|
|
67
|
+
return PrivateKey.fromBuffer(private_key);
|
|
68
|
+
}
|
|
69
|
+
toWif() {
|
|
70
|
+
var private_key = this.toBuffer();
|
|
71
|
+
// checksum includes the version
|
|
72
|
+
private_key = Buffer.concat([new Buffer.from([0x80]), private_key]);
|
|
73
|
+
var checksum = hash.sha256(private_key);
|
|
74
|
+
checksum = hash.sha256(checksum);
|
|
75
|
+
checksum = checksum.slice(0, 4);
|
|
76
|
+
var private_wif = Buffer.concat([private_key, checksum]);
|
|
77
|
+
return base58.encode(private_wif);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Alias for {@link toWif} */
|
|
81
|
+
toString() {
|
|
82
|
+
return this.toWif();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
@return {Point}
|
|
87
|
+
*/
|
|
88
|
+
toPublicKeyPoint() {
|
|
89
|
+
var Q;
|
|
90
|
+
return Q = secp256k1.G.multiply(this.d);
|
|
91
|
+
}
|
|
92
|
+
toPublic() {
|
|
93
|
+
if (this.public_key) {
|
|
94
|
+
return this.public_key;
|
|
95
|
+
}
|
|
96
|
+
return this.public_key = PublicKey.fromPoint(this.toPublicKeyPoint());
|
|
97
|
+
}
|
|
98
|
+
toBuffer() {
|
|
99
|
+
return this.d.toBuffer(32);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** ECIES */
|
|
103
|
+
get_shared_secret(public_key) {
|
|
104
|
+
public_key = toPublic(public_key);
|
|
105
|
+
let KB = public_key.toUncompressed().toBuffer();
|
|
106
|
+
let KBP = Point.fromAffine(secp256k1, BigInteger.fromBuffer(KB.slice(1, 33)),
|
|
107
|
+
// x
|
|
108
|
+
BigInteger.fromBuffer(KB.slice(33, 65)) // y
|
|
109
|
+
);
|
|
110
|
+
let r = this.toBuffer();
|
|
111
|
+
let P = KBP.multiply(BigInteger.fromBuffer(r));
|
|
112
|
+
let S = P.affineX.toBuffer({
|
|
113
|
+
size: 32
|
|
114
|
+
});
|
|
115
|
+
// SHA512 used in ECIES
|
|
116
|
+
return hash.sha512(S);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// /** ECIES (does not always match the Point.fromAffine version above) */
|
|
120
|
+
// get_shared_secret(public_key){
|
|
121
|
+
// public_key = toPublic(public_key)
|
|
122
|
+
// var P = public_key.Q.multiply( this.d );
|
|
123
|
+
// var S = P.affineX.toBuffer({size: 32});
|
|
124
|
+
// // ECIES, adds an extra sha512
|
|
125
|
+
// return hash.sha512(S);
|
|
126
|
+
// }
|
|
127
|
+
|
|
128
|
+
/** @throws {Error} - overflow of the key could not be derived */
|
|
129
|
+
child(offset) {
|
|
130
|
+
offset = Buffer.concat([this.toPublicKey().toBuffer(), offset]);
|
|
131
|
+
offset = hash.sha256(offset);
|
|
132
|
+
let c = BigInteger.fromBuffer(offset);
|
|
133
|
+
if (c.compareTo(n) >= 0) throw new Error("Child offset went out of bounds, try again");
|
|
134
|
+
let derived = this.d.add(c); //.mod(n)
|
|
135
|
+
|
|
136
|
+
if (derived.signum() === 0) throw new Error("Child offset derived to an invalid key, try again");
|
|
137
|
+
return new PrivateKey(derived);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// toByteBuffer() {
|
|
141
|
+
// var b = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);
|
|
142
|
+
// this.appendByteBuffer(b);
|
|
143
|
+
// return b.copy(0, b.offset);
|
|
144
|
+
// }
|
|
145
|
+
|
|
146
|
+
static fromHex(hex) {
|
|
147
|
+
return PrivateKey.fromBuffer(new Buffer.from(hex, 'hex'));
|
|
148
|
+
}
|
|
149
|
+
toHex() {
|
|
150
|
+
return this.toBuffer().toString('hex');
|
|
151
|
+
}
|
|
152
|
+
toPublicKey() {
|
|
153
|
+
return this.toPublic();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/* </helper_functions> */
|
|
157
|
+
}
|
|
208
158
|
module.exports = PrivateKey;
|
|
209
|
-
|
|
210
|
-
var toPublic = function toPublic(data) {
|
|
211
|
-
return data == null ? data : data.Q ? data : PublicKey.fromStringOrThrow(data);
|
|
212
|
-
};
|
|
159
|
+
const toPublic = data => data == null ? data : data.Q ? data : PublicKey.fromStringOrThrow(data);
|