@steemit/steem-js 0.7.11 → 1.0.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 +203 -87
- 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.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 +25 -0
- package/dist/crypto/index.d.ts +25 -0
- package/dist/formatter/index.d.ts +92 -0
- package/dist/index.cjs +25848 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +25812 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +57513 -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/index.d.ts +8 -0
- package/dist/utils.d.ts +2 -0
- package/package.json +72 -67
- package/.circleci/config.yml +0 -23
- 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/statistics.html +0 -208
- package/dist/steem-tests.min.js +0 -23
- package/dist/steem-tests.min.js.gz +0 -0
- package/dist/steem-tests.min.js.map +0 -1
- package/dist/steem.min.js +0 -18
- package/dist/steem.min.js.gz +0 -0
- package/dist/steem.min.js.map +0 -1
- package/lib/api/index.js +0 -422
- package/lib/api/methods.js +0 -413
- package/lib/api/transports/base.js +0 -72
- package/lib/api/transports/http.js +0 -172
- package/lib/api/transports/index.js +0 -20
- package/lib/api/transports/ws.js +0 -228
- package/lib/auth/ecc/README.md +0 -20
- package/lib/auth/ecc/index.js +0 -13
- package/lib/auth/ecc/package.json +0 -36
- package/lib/auth/ecc/src/address.js +0 -84
- package/lib/auth/ecc/src/aes.js +0 -184
- package/lib/auth/ecc/src/brain_key.js +0 -13
- package/lib/auth/ecc/src/ecdsa.js +0 -219
- package/lib/auth/ecc/src/ecsignature.js +0 -128
- package/lib/auth/ecc/src/enforce_types.js +0 -49
- package/lib/auth/ecc/src/hash.js +0 -67
- package/lib/auth/ecc/src/key_private.js +0 -212
- package/lib/auth/ecc/src/key_public.js +0 -215
- package/lib/auth/ecc/src/key_utils.js +0 -112
- package/lib/auth/ecc/src/signature.js +0 -187
- package/lib/auth/index.js +0 -126
- package/lib/auth/memo.js +0 -147
- package/lib/auth/serializer/README.md +0 -13
- package/lib/auth/serializer/index.js +0 -21
- package/lib/auth/serializer/package.json +0 -32
- package/lib/auth/serializer/src/ChainTypes.js +0 -90
- package/lib/auth/serializer/src/convert.js +0 -37
- package/lib/auth/serializer/src/error_with_cause.js +0 -42
- package/lib/auth/serializer/src/fast_parser.js +0 -77
- package/lib/auth/serializer/src/number_utils.js +0 -67
- package/lib/auth/serializer/src/object_id.js +0 -68
- package/lib/auth/serializer/src/operations.js +0 -787
- package/lib/auth/serializer/src/precision.js +0 -95
- package/lib/auth/serializer/src/serializer.js +0 -211
- package/lib/auth/serializer/src/template.js +0 -17
- package/lib/auth/serializer/src/types.js +0 -1238
- package/lib/auth/serializer/src/validation.js +0 -360
- package/lib/broadcast/helpers.js +0 -177
- package/lib/broadcast/index.js +0 -127
- package/lib/broadcast/operations.js +0 -255
- package/lib/browser.js +0 -29
- package/lib/config.js +0 -45
- package/lib/formatter.js +0 -189
- package/lib/index.js +0 -19
- package/lib/utils.js +0 -55
- package/node-4.dockerfile +0 -6
- package/node-6.dockerfile +0 -6
- 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 -326
- package/test/broadcast.test.js +0 -225
- package/test/browser/BrowserTests.js +0 -55
- package/test/comment.test.js +0 -69
- 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/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/webpack/makeConfig.js +0 -105
- package/webpack.config.js +0 -2
- package/yarn.lock +0 -3336
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
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"); } }
|
|
6
|
-
|
|
7
|
-
var BigInteger = require('bigi');
|
|
8
|
-
var ecurve = require('ecurve');
|
|
9
|
-
var secp256k1 = ecurve.getCurveByName('secp256k1');
|
|
10
|
-
BigInteger = require('bigi');
|
|
11
|
-
var base58 = require('bs58');
|
|
12
|
-
var hash = require('./hash');
|
|
13
|
-
var config = require('../../../config');
|
|
14
|
-
var assert = require('assert');
|
|
15
|
-
|
|
16
|
-
var G = secp256k1.G;
|
|
17
|
-
var n = secp256k1.n;
|
|
18
|
-
|
|
19
|
-
var PublicKey = function () {
|
|
20
|
-
|
|
21
|
-
/** @param {ecurve.Point} public key */
|
|
22
|
-
function PublicKey(Q) {
|
|
23
|
-
_classCallCheck(this, PublicKey);
|
|
24
|
-
|
|
25
|
-
this.Q = Q;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
_createClass(PublicKey, [{
|
|
29
|
-
key: 'toBuffer',
|
|
30
|
-
value: function toBuffer() {
|
|
31
|
-
var compressed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.Q ? this.Q.compressed : null;
|
|
32
|
-
|
|
33
|
-
if (this.Q === null) return Buffer.from("000000000000000000000000000000000000000000000000000000000000000000", "hex");
|
|
34
|
-
return this.Q.getEncoded(compressed);
|
|
35
|
-
}
|
|
36
|
-
}, {
|
|
37
|
-
key: 'toUncompressed',
|
|
38
|
-
value: function toUncompressed() {
|
|
39
|
-
var buf = this.Q.getEncoded(false);
|
|
40
|
-
var point = ecurve.Point.decodeFrom(secp256k1, buf);
|
|
41
|
-
return PublicKey.fromPoint(point);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** bts::blockchain::address (unique but not a full public key) */
|
|
45
|
-
|
|
46
|
-
}, {
|
|
47
|
-
key: 'toBlockchainAddress',
|
|
48
|
-
value: function toBlockchainAddress() {
|
|
49
|
-
var pub_buf = this.toBuffer();
|
|
50
|
-
var pub_sha = hash.sha512(pub_buf);
|
|
51
|
-
return hash.ripemd160(pub_sha);
|
|
52
|
-
}
|
|
53
|
-
}, {
|
|
54
|
-
key: 'toString',
|
|
55
|
-
value: function toString() {
|
|
56
|
-
var address_prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : config.get('address_prefix');
|
|
57
|
-
|
|
58
|
-
return this.toPublicKeyString(address_prefix);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
Full public key
|
|
63
|
-
{return} string
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
|
-
}, {
|
|
67
|
-
key: 'toPublicKeyString',
|
|
68
|
-
value: function toPublicKeyString() {
|
|
69
|
-
var address_prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : config.get('address_prefix');
|
|
70
|
-
|
|
71
|
-
if (this.pubdata) return address_prefix + this.pubdata;
|
|
72
|
-
var pub_buf = this.toBuffer();
|
|
73
|
-
var checksum = hash.ripemd160(pub_buf);
|
|
74
|
-
var addy = Buffer.concat([pub_buf, checksum.slice(0, 4)]);
|
|
75
|
-
this.pubdata = base58.encode(addy);
|
|
76
|
-
return address_prefix + this.pubdata;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
@arg {string} public_key - like STMXyz...
|
|
81
|
-
@arg {string} address_prefix - like STM
|
|
82
|
-
@return PublicKey or `null` (if the public_key string is invalid)
|
|
83
|
-
@deprecated fromPublicKeyString (use fromString instead)
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
}, {
|
|
87
|
-
key: 'toAddressString',
|
|
88
|
-
value: function toAddressString() {
|
|
89
|
-
var address_prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : config.get('address_prefix');
|
|
90
|
-
|
|
91
|
-
var pub_buf = this.toBuffer();
|
|
92
|
-
var pub_sha = hash.sha512(pub_buf);
|
|
93
|
-
var addy = hash.ripemd160(pub_sha);
|
|
94
|
-
var checksum = hash.ripemd160(addy);
|
|
95
|
-
addy = Buffer.concat([addy, checksum.slice(0, 4)]);
|
|
96
|
-
return address_prefix + base58.encode(addy);
|
|
97
|
-
}
|
|
98
|
-
}, {
|
|
99
|
-
key: 'toPtsAddy',
|
|
100
|
-
value: function toPtsAddy() {
|
|
101
|
-
var pub_buf = this.toBuffer();
|
|
102
|
-
var pub_sha = hash.sha256(pub_buf);
|
|
103
|
-
var addy = hash.ripemd160(pub_sha);
|
|
104
|
-
addy = Buffer.concat([new Buffer([0x38]), addy]); //version 56(decimal)
|
|
105
|
-
|
|
106
|
-
var checksum = hash.sha256(addy);
|
|
107
|
-
checksum = hash.sha256(checksum);
|
|
108
|
-
|
|
109
|
-
addy = Buffer.concat([addy, checksum.slice(0, 4)]);
|
|
110
|
-
return base58.encode(addy);
|
|
111
|
-
}
|
|
112
|
-
}, {
|
|
113
|
-
key: 'child',
|
|
114
|
-
value: function child(offset) {
|
|
115
|
-
|
|
116
|
-
assert(Buffer.isBuffer(offset), "Buffer required: offset");
|
|
117
|
-
assert.equal(offset.length, 32, "offset length");
|
|
118
|
-
|
|
119
|
-
offset = Buffer.concat([this.toBuffer(), offset]);
|
|
120
|
-
offset = hash.sha256(offset);
|
|
121
|
-
|
|
122
|
-
var c = BigInteger.fromBuffer(offset);
|
|
123
|
-
|
|
124
|
-
if (c.compareTo(n) >= 0) throw new Error("Child offset went out of bounds, try again");
|
|
125
|
-
|
|
126
|
-
var cG = G.multiply(c);
|
|
127
|
-
var Qprime = this.Q.add(cG);
|
|
128
|
-
|
|
129
|
-
if (secp256k1.isInfinity(Qprime)) throw new Error("Child offset derived to an invalid key, try again");
|
|
130
|
-
|
|
131
|
-
return PublicKey.fromPoint(Qprime);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// toByteBuffer() {
|
|
135
|
-
// var b = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);
|
|
136
|
-
// this.appendByteBuffer(b);
|
|
137
|
-
// return b.copy(0, b.offset);
|
|
138
|
-
// }
|
|
139
|
-
|
|
140
|
-
}, {
|
|
141
|
-
key: 'toHex',
|
|
142
|
-
value: function toHex() {
|
|
143
|
-
return this.toBuffer().toString('hex');
|
|
144
|
-
}
|
|
145
|
-
}], [{
|
|
146
|
-
key: 'fromBinary',
|
|
147
|
-
value: function fromBinary(bin) {
|
|
148
|
-
return PublicKey.fromBuffer(new Buffer(bin, 'binary'));
|
|
149
|
-
}
|
|
150
|
-
}, {
|
|
151
|
-
key: 'fromBuffer',
|
|
152
|
-
value: function fromBuffer(buffer) {
|
|
153
|
-
if (buffer.toString("hex") === "000000000000000000000000000000000000000000000000000000000000000000") return new PublicKey(null);
|
|
154
|
-
return new PublicKey(ecurve.Point.decodeFrom(secp256k1, buffer));
|
|
155
|
-
}
|
|
156
|
-
}, {
|
|
157
|
-
key: 'fromPoint',
|
|
158
|
-
value: function fromPoint(point) {
|
|
159
|
-
return new PublicKey(point);
|
|
160
|
-
}
|
|
161
|
-
}, {
|
|
162
|
-
key: 'fromString',
|
|
163
|
-
value: function fromString(public_key) {
|
|
164
|
-
var address_prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : config.get('address_prefix');
|
|
165
|
-
|
|
166
|
-
try {
|
|
167
|
-
return PublicKey.fromStringOrThrow(public_key, address_prefix);
|
|
168
|
-
} catch (e) {
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
@arg {string} public_key - like STMXyz...
|
|
175
|
-
@arg {string} address_prefix - like STM
|
|
176
|
-
@throws {Error} if public key is invalid
|
|
177
|
-
@return PublicKey
|
|
178
|
-
*/
|
|
179
|
-
|
|
180
|
-
}, {
|
|
181
|
-
key: 'fromStringOrThrow',
|
|
182
|
-
value: function fromStringOrThrow(public_key) {
|
|
183
|
-
var address_prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : config.get('address_prefix');
|
|
184
|
-
|
|
185
|
-
var prefix = public_key.slice(0, address_prefix.length);
|
|
186
|
-
assert.equal(address_prefix, prefix, 'Expecting key to begin with ' + address_prefix + ', instead got ' + prefix);
|
|
187
|
-
public_key = public_key.slice(address_prefix.length);
|
|
188
|
-
|
|
189
|
-
public_key = new Buffer(base58.decode(public_key), 'binary');
|
|
190
|
-
var checksum = public_key.slice(-4);
|
|
191
|
-
public_key = public_key.slice(0, -4);
|
|
192
|
-
var new_checksum = hash.ripemd160(public_key);
|
|
193
|
-
new_checksum = new_checksum.slice(0, 4);
|
|
194
|
-
assert.deepEqual(checksum, new_checksum, 'Checksum did not match');
|
|
195
|
-
return PublicKey.fromBuffer(public_key);
|
|
196
|
-
}
|
|
197
|
-
}, {
|
|
198
|
-
key: 'fromHex',
|
|
199
|
-
value: function fromHex(hex) {
|
|
200
|
-
return PublicKey.fromBuffer(new Buffer(hex, 'hex'));
|
|
201
|
-
}
|
|
202
|
-
}, {
|
|
203
|
-
key: 'fromStringHex',
|
|
204
|
-
value: function fromStringHex(hex) {
|
|
205
|
-
return PublicKey.fromString(new Buffer(hex, 'hex'));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/* </HEX> */
|
|
209
|
-
|
|
210
|
-
}]);
|
|
211
|
-
|
|
212
|
-
return PublicKey;
|
|
213
|
-
}();
|
|
214
|
-
|
|
215
|
-
module.exports = PublicKey;
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var PrivateKey = require('./key_private');
|
|
4
|
-
var hash = require('./hash');
|
|
5
|
-
var secureRandom = require('secure-random');
|
|
6
|
-
|
|
7
|
-
// hash for .25 second
|
|
8
|
-
var HASH_POWER_MILLS = 250;
|
|
9
|
-
|
|
10
|
-
var entropyPos = 0,
|
|
11
|
-
entropyCount = 0;
|
|
12
|
-
var entropyArray = secureRandom.randomBuffer(101);
|
|
13
|
-
|
|
14
|
-
module.exports = {
|
|
15
|
-
addEntropy: function addEntropy() {
|
|
16
|
-
entropyCount++;
|
|
17
|
-
|
|
18
|
-
for (var _len = arguments.length, ints = Array(_len), _key = 0; _key < _len; _key++) {
|
|
19
|
-
ints[_key] = arguments[_key];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
var _iteratorNormalCompletion = true;
|
|
23
|
-
var _didIteratorError = false;
|
|
24
|
-
var _iteratorError = undefined;
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
for (var _iterator = ints[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
28
|
-
var i = _step.value;
|
|
29
|
-
|
|
30
|
-
var pos = entropyPos++ % 101;
|
|
31
|
-
var i2 = entropyArray[pos] += i;
|
|
32
|
-
if (i2 > 9007199254740991) entropyArray[pos] = 0;
|
|
33
|
-
}
|
|
34
|
-
} catch (err) {
|
|
35
|
-
_didIteratorError = true;
|
|
36
|
-
_iteratorError = err;
|
|
37
|
-
} finally {
|
|
38
|
-
try {
|
|
39
|
-
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
40
|
-
_iterator.return();
|
|
41
|
-
}
|
|
42
|
-
} finally {
|
|
43
|
-
if (_didIteratorError) {
|
|
44
|
-
throw _iteratorError;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
A week random number generator can run out of entropy. This should ensure even the worst random number implementation will be reasonably safe.
|
|
53
|
-
@param1 string entropy of at least 32 bytes
|
|
54
|
-
*/
|
|
55
|
-
random32ByteBuffer: function random32ByteBuffer() {
|
|
56
|
-
var entropy = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.browserEntropy();
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (!(typeof entropy === 'string')) {
|
|
60
|
-
throw new Error("string required for entropy");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (entropy.length < 32) {
|
|
64
|
-
throw new Error("expecting at least 32 bytes of entropy");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
var start_t = Date.now();
|
|
68
|
-
|
|
69
|
-
while (Date.now() - start_t < HASH_POWER_MILLS) {
|
|
70
|
-
entropy = hash.sha256(entropy);
|
|
71
|
-
}var hash_array = [];
|
|
72
|
-
hash_array.push(entropy);
|
|
73
|
-
|
|
74
|
-
// Hashing for 1 second may helps the computer is not low on entropy (this method may be called back-to-back).
|
|
75
|
-
hash_array.push(secureRandom.randomBuffer(32));
|
|
76
|
-
|
|
77
|
-
return hash.sha256(Buffer.concat(hash_array));
|
|
78
|
-
},
|
|
79
|
-
get_random_key: function get_random_key(entropy) {
|
|
80
|
-
return PrivateKey.fromBuffer(this.random32ByteBuffer(entropy));
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
// Turn invisible space like characters into a single space
|
|
85
|
-
// normalize_brain_key(brain_key){
|
|
86
|
-
// if (!(typeof brain_key === 'string')) {
|
|
87
|
-
// throw new Error("string required for brain_key");
|
|
88
|
-
// }
|
|
89
|
-
// brain_key = brain_key.trim();
|
|
90
|
-
// return brain_key.split(/[\t\n\v\f\r ]+/).join(' ');
|
|
91
|
-
// },
|
|
92
|
-
|
|
93
|
-
browserEntropy: function browserEntropy() {
|
|
94
|
-
var entropyStr = Array(entropyArray).join();
|
|
95
|
-
try {
|
|
96
|
-
entropyStr += new Date().toString() + " " + window.screen.height + " " + window.screen.width + " " + window.screen.colorDepth + " " + " " + window.screen.availHeight + " " + window.screen.availWidth + " " + window.screen.pixelDepth + navigator.language + " " + window.location + " " + window.history.length;
|
|
97
|
-
|
|
98
|
-
for (var i = 0, mimeType; i < navigator.mimeTypes.length; i++) {
|
|
99
|
-
mimeType = navigator.mimeTypes[i];
|
|
100
|
-
entropyStr += mimeType.description + " " + mimeType.type + " " + mimeType.suffixes + " ";
|
|
101
|
-
}
|
|
102
|
-
console.log("INFO\tbrowserEntropy gathered", entropyCount, 'events');
|
|
103
|
-
} catch (error) {
|
|
104
|
-
//nodejs:ReferenceError: window is not defined
|
|
105
|
-
entropyStr += hash.sha256(new Date().toString());
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
var b = new Buffer(entropyStr);
|
|
109
|
-
entropyStr += b.toString('binary') + " " + new Date().toString();
|
|
110
|
-
return entropyStr;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
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"); } }
|
|
6
|
-
|
|
7
|
-
var ecdsa = require('./ecdsa');
|
|
8
|
-
var hash = require('./hash');
|
|
9
|
-
var curve = require('ecurve').getCurveByName('secp256k1');
|
|
10
|
-
var assert = require('assert');
|
|
11
|
-
var BigInteger = require('bigi');
|
|
12
|
-
var PublicKey = require('./key_public');
|
|
13
|
-
var PrivateKey = require('./key_private');
|
|
14
|
-
|
|
15
|
-
var Signature = function () {
|
|
16
|
-
function Signature(r1, s1, i1) {
|
|
17
|
-
_classCallCheck(this, Signature);
|
|
18
|
-
|
|
19
|
-
this.r = r1;
|
|
20
|
-
this.s = s1;
|
|
21
|
-
this.i = i1;
|
|
22
|
-
assert.equal(this.r != null, true, 'Missing parameter');
|
|
23
|
-
assert.equal(this.s != null, true, 'Missing parameter');
|
|
24
|
-
assert.equal(this.i != null, true, 'Missing parameter');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
_createClass(Signature, [{
|
|
28
|
-
key: 'toBuffer',
|
|
29
|
-
value: function toBuffer() {
|
|
30
|
-
var buf;
|
|
31
|
-
buf = new Buffer(65);
|
|
32
|
-
buf.writeUInt8(this.i, 0);
|
|
33
|
-
this.r.toBuffer(32).copy(buf, 1);
|
|
34
|
-
this.s.toBuffer(32).copy(buf, 33);
|
|
35
|
-
return buf;
|
|
36
|
-
}
|
|
37
|
-
}, {
|
|
38
|
-
key: 'recoverPublicKeyFromBuffer',
|
|
39
|
-
value: function recoverPublicKeyFromBuffer(buffer) {
|
|
40
|
-
return this.recoverPublicKey(hash.sha256(buffer));
|
|
41
|
-
}
|
|
42
|
-
}, {
|
|
43
|
-
key: 'recoverPublicKey',
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
@return {PublicKey}
|
|
48
|
-
*/
|
|
49
|
-
value: function recoverPublicKey(sha256_buffer) {
|
|
50
|
-
var Q = void 0,
|
|
51
|
-
e = void 0,
|
|
52
|
-
i = void 0;
|
|
53
|
-
e = BigInteger.fromBuffer(sha256_buffer);
|
|
54
|
-
i = this.i;
|
|
55
|
-
i -= 27;
|
|
56
|
-
i = i & 3;
|
|
57
|
-
Q = ecdsa.recoverPubKey(curve, e, this, i);
|
|
58
|
-
return PublicKey.fromPoint(Q);
|
|
59
|
-
}
|
|
60
|
-
}, {
|
|
61
|
-
key: 'verifyBuffer',
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
@param {Buffer} un-hashed
|
|
66
|
-
@param {./PublicKey}
|
|
67
|
-
@return {boolean}
|
|
68
|
-
*/
|
|
69
|
-
value: function verifyBuffer(buf, public_key) {
|
|
70
|
-
var _hash = hash.sha256(buf);
|
|
71
|
-
return this.verifyHash(_hash, public_key);
|
|
72
|
-
}
|
|
73
|
-
}, {
|
|
74
|
-
key: 'verifyHash',
|
|
75
|
-
value: function verifyHash(hash, public_key) {
|
|
76
|
-
assert.equal(hash.length, 32, "A SHA 256 should be 32 bytes long, instead got " + hash.length);
|
|
77
|
-
return ecdsa.verify(curve, hash, {
|
|
78
|
-
r: this.r,
|
|
79
|
-
s: this.s
|
|
80
|
-
}, public_key.Q);
|
|
81
|
-
}
|
|
82
|
-
}, {
|
|
83
|
-
key: 'toHex',
|
|
84
|
-
value: function toHex() {
|
|
85
|
-
return this.toBuffer().toString("hex");
|
|
86
|
-
}
|
|
87
|
-
}, {
|
|
88
|
-
key: 'verifyHex',
|
|
89
|
-
value: function verifyHex(hex, public_key) {
|
|
90
|
-
var buf;
|
|
91
|
-
buf = new Buffer(hex, 'hex');
|
|
92
|
-
return this.verifyBuffer(buf, public_key);
|
|
93
|
-
}
|
|
94
|
-
}], [{
|
|
95
|
-
key: 'fromBuffer',
|
|
96
|
-
value: function fromBuffer(buf) {
|
|
97
|
-
var i, r, s;
|
|
98
|
-
assert.equal(buf.length, 65, 'Invalid signature length');
|
|
99
|
-
i = buf.readUInt8(0);
|
|
100
|
-
assert.equal(i - 27, i - 27 & 7, 'Invalid signature parameter');
|
|
101
|
-
r = BigInteger.fromBuffer(buf.slice(1, 33));
|
|
102
|
-
s = BigInteger.fromBuffer(buf.slice(33));
|
|
103
|
-
return new Signature(r, s, i);
|
|
104
|
-
}
|
|
105
|
-
}, {
|
|
106
|
-
key: 'signBuffer',
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
@param {Buffer} buf
|
|
111
|
-
@param {PrivateKey} private_key
|
|
112
|
-
@return {Signature}
|
|
113
|
-
*/
|
|
114
|
-
value: function signBuffer(buf, private_key) {
|
|
115
|
-
var _hash = hash.sha256(buf);
|
|
116
|
-
return Signature.signBufferSha256(_hash, private_key);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** Sign a buffer of exactally 32 bytes in size (sha256(text))
|
|
120
|
-
@param {Buffer} buf - 32 bytes binary
|
|
121
|
-
@param {PrivateKey} private_key
|
|
122
|
-
@return {Signature}
|
|
123
|
-
*/
|
|
124
|
-
|
|
125
|
-
}, {
|
|
126
|
-
key: 'signBufferSha256',
|
|
127
|
-
value: function signBufferSha256(buf_sha256, private_key) {
|
|
128
|
-
if (buf_sha256.length !== 32 || !Buffer.isBuffer(buf_sha256)) throw new Error("buf_sha256: 32 byte buffer requred");
|
|
129
|
-
private_key = toPrivateObj(private_key);
|
|
130
|
-
assert(private_key, 'private_key required');
|
|
131
|
-
|
|
132
|
-
var der, e, ecsignature, i, lenR, lenS, nonce;
|
|
133
|
-
i = null;
|
|
134
|
-
nonce = 0;
|
|
135
|
-
e = BigInteger.fromBuffer(buf_sha256);
|
|
136
|
-
while (true) {
|
|
137
|
-
ecsignature = ecdsa.sign(curve, buf_sha256, private_key.d, nonce++);
|
|
138
|
-
der = ecsignature.toDER();
|
|
139
|
-
lenR = der[3];
|
|
140
|
-
lenS = der[5 + lenR];
|
|
141
|
-
if (lenR === 32 && lenS === 32) {
|
|
142
|
-
i = ecdsa.calcPubKeyRecoveryParam(curve, e, ecsignature, private_key.toPublicKey().Q);
|
|
143
|
-
i += 4; // compressed
|
|
144
|
-
i += 27; // compact // 24 or 27 :( forcing odd-y 2nd key candidate)
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
if (nonce % 10 === 0) {
|
|
148
|
-
console.log("WARN: " + nonce + " attempts to find canonical signature");
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return new Signature(ecsignature.r, ecsignature.s, i);
|
|
152
|
-
}
|
|
153
|
-
}, {
|
|
154
|
-
key: 'sign',
|
|
155
|
-
value: function sign(string, private_key) {
|
|
156
|
-
return Signature.signBuffer(new Buffer(string), private_key);
|
|
157
|
-
}
|
|
158
|
-
}, {
|
|
159
|
-
key: 'fromHex',
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
// toByteBuffer() {
|
|
163
|
-
// var b;
|
|
164
|
-
// b = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);
|
|
165
|
-
// this.appendByteBuffer(b);
|
|
166
|
-
// return b.copy(0, b.offset);
|
|
167
|
-
// };
|
|
168
|
-
|
|
169
|
-
value: function fromHex(hex) {
|
|
170
|
-
return Signature.fromBuffer(new Buffer(hex, "hex"));
|
|
171
|
-
}
|
|
172
|
-
}, {
|
|
173
|
-
key: 'signHex',
|
|
174
|
-
value: function signHex(hex, private_key) {
|
|
175
|
-
var buf;
|
|
176
|
-
buf = new Buffer(hex, 'hex');
|
|
177
|
-
return Signature.signBuffer(buf, private_key);
|
|
178
|
-
}
|
|
179
|
-
}]);
|
|
180
|
-
|
|
181
|
-
return Signature;
|
|
182
|
-
}();
|
|
183
|
-
|
|
184
|
-
var toPrivateObj = function toPrivateObj(o) {
|
|
185
|
-
return o ? o.d ? o : PrivateKey.fromWif(o) : o /*null or undefined*/;
|
|
186
|
-
};
|
|
187
|
-
module.exports = Signature;
|
package/lib/auth/index.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var bigi = require('bigi'),
|
|
4
|
-
bs58 = require('bs58'),
|
|
5
|
-
ecurve = require('ecurve'),
|
|
6
|
-
Point = ecurve.Point,
|
|
7
|
-
secp256k1 = ecurve.getCurveByName('secp256k1'),
|
|
8
|
-
config = require('../config'),
|
|
9
|
-
operations = require('./serializer/src/operations'),
|
|
10
|
-
Signature = require('./ecc/src/signature'),
|
|
11
|
-
KeyPrivate = require('./ecc/src/key_private'),
|
|
12
|
-
PublicKey = require('./ecc/src/key_public'),
|
|
13
|
-
hash = require('./ecc/src/hash');
|
|
14
|
-
|
|
15
|
-
var Auth = {};
|
|
16
|
-
var transaction = operations.transaction;
|
|
17
|
-
var signed_transaction = operations.signed_transaction;
|
|
18
|
-
|
|
19
|
-
Auth.verify = function (name, password, auths) {
|
|
20
|
-
var hasKey = false;
|
|
21
|
-
var roles = [];
|
|
22
|
-
for (var role in auths) {
|
|
23
|
-
roles.push(role);
|
|
24
|
-
}
|
|
25
|
-
var pubKeys = this.generateKeys(name, password, roles);
|
|
26
|
-
roles.forEach(function (role) {
|
|
27
|
-
if (auths[role][0][0] === pubKeys[role]) {
|
|
28
|
-
hasKey = true;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
return hasKey;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
Auth.generateKeys = function (name, password, roles) {
|
|
35
|
-
var pubKeys = {};
|
|
36
|
-
roles.forEach(function (role) {
|
|
37
|
-
var seed = name + role + password;
|
|
38
|
-
var brainKey = seed.trim().split(/[\t\n\v\f\r ]+/).join(' ');
|
|
39
|
-
var hashSha256 = hash.sha256(brainKey);
|
|
40
|
-
var bigInt = bigi.fromBuffer(hashSha256);
|
|
41
|
-
var toPubKey = secp256k1.G.multiply(bigInt);
|
|
42
|
-
var point = new Point(toPubKey.curve, toPubKey.x, toPubKey.y, toPubKey.z);
|
|
43
|
-
var pubBuf = point.getEncoded(toPubKey.compressed);
|
|
44
|
-
var checksum = hash.ripemd160(pubBuf);
|
|
45
|
-
var addy = Buffer.concat([pubBuf, checksum.slice(0, 4)]);
|
|
46
|
-
pubKeys[role] = config.get('address_prefix') + bs58.encode(addy);
|
|
47
|
-
});
|
|
48
|
-
return pubKeys;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
@arg {string} name - blockchain account name
|
|
53
|
-
@arg {string} password - very strong password typically no shorter than a private key
|
|
54
|
-
@arg {array} roles - defaults to standard Steem blockchain-level roles
|
|
55
|
-
*/
|
|
56
|
-
Auth.getPrivateKeys = function (name, password) {
|
|
57
|
-
var roles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['owner', 'active', 'posting', 'memo'];
|
|
58
|
-
|
|
59
|
-
var privKeys = {};
|
|
60
|
-
roles.forEach(function (role) {
|
|
61
|
-
privKeys[role] = this.toWif(name, password, role);
|
|
62
|
-
privKeys[role + 'Pubkey'] = this.wifToPublic(privKeys[role]);
|
|
63
|
-
}.bind(this));
|
|
64
|
-
return privKeys;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
Auth.isWif = function (privWif) {
|
|
68
|
-
var isWif = false;
|
|
69
|
-
try {
|
|
70
|
-
var bufWif = new Buffer(bs58.decode(privWif));
|
|
71
|
-
var privKey = bufWif.slice(0, -4);
|
|
72
|
-
var checksum = bufWif.slice(-4);
|
|
73
|
-
var newChecksum = hash.sha256(privKey);
|
|
74
|
-
newChecksum = hash.sha256(newChecksum);
|
|
75
|
-
newChecksum = newChecksum.slice(0, 4);
|
|
76
|
-
if (checksum.toString() == newChecksum.toString()) {
|
|
77
|
-
isWif = true;
|
|
78
|
-
}
|
|
79
|
-
} catch (e) {}
|
|
80
|
-
return isWif;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
Auth.toWif = function (name, password, role) {
|
|
84
|
-
var seed = name + role + password;
|
|
85
|
-
var brainKey = seed.trim().split(/[\t\n\v\f\r ]+/).join(' ');
|
|
86
|
-
var hashSha256 = hash.sha256(brainKey);
|
|
87
|
-
var privKey = Buffer.concat([new Buffer([0x80]), hashSha256]);
|
|
88
|
-
var checksum = hash.sha256(privKey);
|
|
89
|
-
checksum = hash.sha256(checksum);
|
|
90
|
-
checksum = checksum.slice(0, 4);
|
|
91
|
-
var privWif = Buffer.concat([privKey, checksum]);
|
|
92
|
-
return bs58.encode(privWif);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
Auth.wifIsValid = function (privWif, pubWif) {
|
|
96
|
-
return this.wifToPublic(privWif) == pubWif;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
Auth.wifToPublic = function (privWif) {
|
|
100
|
-
var pubWif = KeyPrivate.fromWif(privWif);
|
|
101
|
-
pubWif = pubWif.toPublic().toString();
|
|
102
|
-
return pubWif;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
Auth.isPubkey = function (pubkey, address_prefix) {
|
|
106
|
-
return PublicKey.fromString(pubkey, address_prefix) != null;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
Auth.signTransaction = function (trx, keys) {
|
|
110
|
-
var signatures = [];
|
|
111
|
-
if (trx.signatures) {
|
|
112
|
-
signatures = [].concat(trx.signatures);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
var cid = new Buffer(config.get('chain_id'), 'hex');
|
|
116
|
-
var buf = transaction.toBuffer(trx);
|
|
117
|
-
|
|
118
|
-
for (var key in keys) {
|
|
119
|
-
var sig = Signature.signBuffer(Buffer.concat([cid, buf]), keys[key]);
|
|
120
|
-
signatures.push(sig.toBuffer());
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return signed_transaction.toObject(Object.assign(trx, { signatures: signatures }));
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
module.exports = Auth;
|