@steemit/steem-js 0.7.10 → 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.
Files changed (74) hide show
  1. package/README.md +22 -3
  2. package/circle.yml +1 -1
  3. package/config.json +1 -1
  4. package/dist/steem-tests.min.js +4097 -23
  5. package/dist/steem.min.js +2089 -18
  6. package/docker-webpack.config.js +44 -0
  7. package/lib/api/index.js +305 -412
  8. package/lib/api/methods.js +16 -1
  9. package/lib/api/rpc-auth.js +135 -0
  10. package/lib/api/transports/base.js +25 -66
  11. package/lib/api/transports/http.js +114 -129
  12. package/lib/api/transports/index.js +8 -15
  13. package/lib/api/transports/ws.js +107 -207
  14. package/lib/auth/ecc/index.js +9 -9
  15. package/lib/auth/ecc/src/address.js +48 -78
  16. package/lib/auth/ecc/src/aes.js +93 -129
  17. package/lib/auth/ecc/src/brain_key.js +7 -7
  18. package/lib/auth/ecc/src/ecdsa.js +7 -33
  19. package/lib/auth/ecc/src/ecsignature.js +4 -30
  20. package/lib/auth/ecc/src/enforce_types.js +1 -8
  21. package/lib/auth/ecc/src/hash.js +16 -25
  22. package/lib/auth/ecc/src/key_private.js +146 -199
  23. package/lib/auth/ecc/src/key_public.js +130 -202
  24. package/lib/auth/ecc/src/key_utils.js +64 -106
  25. package/lib/auth/ecc/src/signature.js +125 -177
  26. package/lib/auth/index.js +84 -97
  27. package/lib/auth/memo.js +90 -118
  28. package/lib/auth/serializer/index.js +12 -18
  29. package/lib/auth/serializer/src/ChainTypes.js +0 -3
  30. package/lib/auth/serializer/src/convert.js +29 -32
  31. package/lib/auth/serializer/src/error_with_cause.js +22 -37
  32. package/lib/auth/serializer/src/fast_parser.js +54 -74
  33. package/lib/auth/serializer/src/number_utils.js +30 -54
  34. package/lib/auth/serializer/src/object_id.js +37 -62
  35. package/lib/auth/serializer/src/operations.js +597 -689
  36. package/lib/auth/serializer/src/precision.js +55 -73
  37. package/lib/auth/serializer/src/serializer.js +158 -204
  38. package/lib/auth/serializer/src/template.js +13 -8
  39. package/lib/auth/serializer/src/types.js +949 -1110
  40. package/lib/auth/serializer/src/validation.js +268 -328
  41. package/lib/broadcast/helpers.js +61 -98
  42. package/lib/broadcast/index.js +61 -82
  43. package/lib/browser.js +15 -19
  44. package/lib/config.js +16 -38
  45. package/lib/formatter.js +89 -115
  46. package/lib/index.js +19 -17
  47. package/lib/utils.js +4 -9
  48. package/node-18.dockerfile +28 -0
  49. package/package.json +62 -38
  50. package/test/Crypto.js +16 -16
  51. package/test/KeyFormats.js +1 -1
  52. package/test/api.test.js +37 -0
  53. package/test/broadcast.test.js +14 -8
  54. package/test/comment.test.js +17 -3
  55. package/test/operations_test.js +1 -1
  56. package/test/promise-broadcast.test.js +86 -0
  57. package/test/reputation.test.js +68 -0
  58. package/test/smt.test.js +11 -11
  59. package/test-github-workflow.bat +19 -0
  60. package/test-github-workflow.sh +15 -0
  61. package/webpack/makeConfig.js +25 -17
  62. package/.circleci/config.yml +0 -23
  63. package/dist/statistics.html +0 -208
  64. package/dist/steem-tests.min.js.gz +0 -0
  65. package/dist/steem-tests.min.js.map +0 -1
  66. package/dist/steem.min.js.gz +0 -0
  67. package/dist/steem.min.js.map +0 -1
  68. package/lib/auth/ecc/README.md +0 -20
  69. package/lib/auth/ecc/package.json +0 -36
  70. package/lib/auth/serializer/README.md +0 -13
  71. package/lib/auth/serializer/package.json +0 -32
  72. package/node-4.dockerfile +0 -6
  73. package/node-6.dockerfile +0 -6
  74. package/yarn.lock +0 -3336
@@ -1,8 +1,4 @@
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"); } }
1
+ "use strict";
6
2
 
7
3
  var ecdsa = require('./ecdsa');
8
4
  var hash = require('./hash');
@@ -11,177 +7,129 @@ var assert = require('assert');
11
7
  var BigInteger = require('bigi');
12
8
  var PublicKey = require('./key_public');
13
9
  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');
10
+ class Signature {
11
+ constructor(r1, s1, i1) {
12
+ this.r = r1;
13
+ this.s = s1;
14
+ this.i = i1;
15
+ assert.equal(this.r != null, true, 'Missing parameter');
16
+ assert.equal(this.s != null, true, 'Missing parameter');
17
+ assert.equal(this.i != null, true, 'Missing parameter');
18
+ }
19
+ static fromBuffer(buf) {
20
+ var i, r, s;
21
+ assert.equal(buf.length, 65, 'Invalid signature length');
22
+ i = buf.readUInt8(0);
23
+ assert.equal(i - 27, i - 27 & 7, 'Invalid signature parameter');
24
+ r = BigInteger.fromBuffer(buf.slice(1, 33));
25
+ s = BigInteger.fromBuffer(buf.slice(33));
26
+ return new Signature(r, s, i);
27
+ }
28
+ toBuffer() {
29
+ var buf;
30
+ buf = new Buffer.alloc(65);
31
+ buf.writeUInt8(this.i, 0);
32
+ this.r.toBuffer(32).copy(buf, 1);
33
+ this.s.toBuffer(32).copy(buf, 33);
34
+ return buf;
35
+ }
36
+ recoverPublicKeyFromBuffer(buffer) {
37
+ return this.recoverPublicKey(hash.sha256(buffer));
38
+ }
39
+ /**
40
+ @return {PublicKey}
41
+ */
42
+ recoverPublicKey(sha256_buffer) {
43
+ let Q, e, i;
44
+ e = BigInteger.fromBuffer(sha256_buffer);
45
+ i = this.i;
46
+ i -= 27;
47
+ i = i & 3;
48
+ Q = ecdsa.recoverPubKey(curve, e, this, i);
49
+ return PublicKey.fromPoint(Q);
50
+ }
51
+ /**
52
+ @param {Buffer} buf
53
+ @param {PrivateKey} private_key
54
+ @return {Signature}
55
+ */
56
+ static signBuffer(buf, private_key) {
57
+ var _hash = hash.sha256(buf);
58
+ return Signature.signBufferSha256(_hash, private_key);
59
+ }
60
+
61
+ /** Sign a buffer of exactally 32 bytes in size (sha256(text))
62
+ @param {Buffer} buf - 32 bytes binary
63
+ @param {PrivateKey} private_key
64
+ @return {Signature}
65
+ */
66
+ static signBufferSha256(buf_sha256, private_key) {
67
+ if (buf_sha256.length !== 32 || !Buffer.isBuffer(buf_sha256)) throw new Error("buf_sha256: 32 byte buffer required");
68
+ private_key = toPrivateObj(private_key);
69
+ assert(private_key, 'private_key required');
70
+ var der, e, ecsignature, i, lenR, lenS, nonce;
71
+ i = null;
72
+ nonce = 0;
73
+ e = BigInteger.fromBuffer(buf_sha256);
74
+ while (true) {
75
+ ecsignature = ecdsa.sign(curve, buf_sha256, private_key.d, nonce++);
76
+ der = ecsignature.toDER();
77
+ lenR = der[3];
78
+ lenS = der[5 + lenR];
79
+ if (lenR === 32 && lenS === 32) {
80
+ i = ecdsa.calcPubKeyRecoveryParam(curve, e, ecsignature, private_key.toPublicKey().Q);
81
+ i += 4; // compressed
82
+ i += 27; // compact // 24 or 27 :( forcing odd-y 2nd key candidate)
83
+ break;
84
+ }
85
+ if (nonce % 10 === 0) {
86
+ console.log("WARN: " + nonce + " attempts to find canonical signature");
87
+ }
25
88
  }
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
- };
89
+ return new Signature(ecsignature.r, ecsignature.s, i);
90
+ }
91
+ static sign(string, private_key) {
92
+ return Signature.signBuffer(new Buffer.from(string), private_key);
93
+ }
94
+ /**
95
+ @param {Buffer} un-hashed
96
+ @param {./PublicKey}
97
+ @return {boolean}
98
+ */
99
+ verifyBuffer(buf, public_key) {
100
+ var _hash = hash.sha256(buf);
101
+ return this.verifyHash(_hash, public_key);
102
+ }
103
+ verifyHash(hash, public_key) {
104
+ assert.equal(hash.length, 32, "A SHA 256 should be 32 bytes long, instead got " + hash.length);
105
+ return ecdsa.verify(curve, hash, {
106
+ r: this.r,
107
+ s: this.s
108
+ }, public_key.Q);
109
+ }
110
+ // toByteBuffer() {
111
+ // var b;
112
+ // b = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);
113
+ // this.appendByteBuffer(b);
114
+ // return b.copy(0, b.offset);
115
+ // };
116
+
117
+ static fromHex(hex) {
118
+ return Signature.fromBuffer(new Buffer.from(hex, "hex"));
119
+ }
120
+ toHex() {
121
+ return this.toBuffer().toString("hex");
122
+ }
123
+ static signHex(hex, private_key) {
124
+ var buf;
125
+ buf = new Buffer.from(hex, 'hex');
126
+ return Signature.signBuffer(buf, private_key);
127
+ }
128
+ verifyHex(hex, public_key) {
129
+ var buf;
130
+ buf = new Buffer.from(hex, 'hex');
131
+ return this.verifyBuffer(buf, public_key);
132
+ }
133
+ }
134
+ const toPrivateObj = o => o ? o.d ? o : PrivateKey.fromWif(o) : o /*null or undefined*/;
187
135
  module.exports = Signature;
package/lib/auth/index.js CHANGED
@@ -1,51 +1,48 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
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
-
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');
15
14
  var Auth = {};
16
15
  var transaction = operations.transaction;
17
16
  var signed_transaction = operations.signed_transaction;
18
-
19
17
  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;
18
+ var hasKey = false;
19
+ var roles = [];
20
+ for (var role in auths) {
21
+ roles.push(role);
22
+ }
23
+ var pubKeys = this.generateKeys(name, password, roles);
24
+ roles.forEach(function (role) {
25
+ if (auths[role][0][0] === pubKeys[role]) {
26
+ hasKey = true;
27
+ }
28
+ });
29
+ return hasKey;
32
30
  };
33
-
34
31
  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;
32
+ var pubKeys = {};
33
+ roles.forEach(function (role) {
34
+ var seed = name + role + password;
35
+ var brainKey = seed.trim().split(/[\t\n\v\f\r ]+/).join(' ');
36
+ var hashSha256 = hash.sha256(brainKey);
37
+ var bigInt = bigi.fromBuffer(hashSha256);
38
+ var toPubKey = secp256k1.G.multiply(bigInt);
39
+ var point = new Point(toPubKey.curve, toPubKey.x, toPubKey.y, toPubKey.z);
40
+ var pubBuf = point.getEncoded(toPubKey.compressed);
41
+ var checksum = hash.ripemd160(pubBuf);
42
+ var addy = Buffer.concat([pubBuf, checksum.slice(0, 4)]);
43
+ pubKeys[role] = config.get('address_prefix') + bs58.encode(addy);
44
+ });
45
+ return pubKeys;
49
46
  };
50
47
 
51
48
  /**
@@ -53,74 +50,64 @@ Auth.generateKeys = function (name, password, roles) {
53
50
  @arg {string} password - very strong password typically no shorter than a private key
54
51
  @arg {array} roles - defaults to standard Steem blockchain-level roles
55
52
  */
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;
53
+ Auth.getPrivateKeys = function (name, password, roles = ['owner', 'active', 'posting', 'memo']) {
54
+ var privKeys = {};
55
+ roles.forEach(function (role) {
56
+ privKeys[role] = this.toWif(name, password, role);
57
+ privKeys[role + 'Pubkey'] = this.wifToPublic(privKeys[role]);
58
+ }.bind(this));
59
+ return privKeys;
65
60
  };
66
-
67
61
  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;
62
+ var isWif = false;
63
+ try {
64
+ var bufWif = new Buffer.from(bs58.decode(privWif));
65
+ var privKey = bufWif.slice(0, -4);
66
+ var checksum = bufWif.slice(-4);
67
+ var newChecksum = hash.sha256(privKey);
68
+ newChecksum = hash.sha256(newChecksum);
69
+ newChecksum = newChecksum.slice(0, 4);
70
+ if (checksum.toString() == newChecksum.toString()) {
71
+ isWif = true;
72
+ }
73
+ } catch (e) {}
74
+ return isWif;
81
75
  };
82
-
83
76
  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);
77
+ var seed = name + role + password;
78
+ var brainKey = seed.trim().split(/[\t\n\v\f\r ]+/).join(' ');
79
+ var hashSha256 = hash.sha256(brainKey);
80
+ var privKey = Buffer.concat([new Buffer.from([0x80]), hashSha256]);
81
+ var checksum = hash.sha256(privKey);
82
+ checksum = hash.sha256(checksum);
83
+ checksum = checksum.slice(0, 4);
84
+ var privWif = Buffer.concat([privKey, checksum]);
85
+ return bs58.encode(privWif);
93
86
  };
94
-
95
87
  Auth.wifIsValid = function (privWif, pubWif) {
96
- return this.wifToPublic(privWif) == pubWif;
88
+ return this.wifToPublic(privWif) == pubWif;
97
89
  };
98
-
99
90
  Auth.wifToPublic = function (privWif) {
100
- var pubWif = KeyPrivate.fromWif(privWif);
101
- pubWif = pubWif.toPublic().toString();
102
- return pubWif;
91
+ var pubWif = KeyPrivate.fromWif(privWif);
92
+ pubWif = pubWif.toPublic().toString();
93
+ return pubWif;
103
94
  };
104
-
105
95
  Auth.isPubkey = function (pubkey, address_prefix) {
106
- return PublicKey.fromString(pubkey, address_prefix) != null;
96
+ return PublicKey.fromString(pubkey, address_prefix) != null;
107
97
  };
108
-
109
98
  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 }));
99
+ var signatures = [];
100
+ if (trx.signatures) {
101
+ signatures = [].concat(trx.signatures);
102
+ }
103
+ var cid = new Buffer.from(config.get('chain_id'), 'hex');
104
+ var buf = transaction.toBuffer(trx);
105
+ for (var key in keys) {
106
+ var sig = Signature.signBuffer(Buffer.concat([cid, buf]), keys[key]);
107
+ signatures.push(sig.toBuffer());
108
+ }
109
+ return signed_transaction.toObject(Object.assign(trx, {
110
+ signatures: signatures
111
+ }));
124
112
  };
125
-
126
113
  module.exports = Auth;