@steemit/steem-js 0.8.0 → 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 +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.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 +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,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const PrivateKey = require('./key_private');
|
|
4
|
-
const hash = require('./hash');
|
|
5
|
-
const secureRandom = require('secure-random');
|
|
6
|
-
|
|
7
|
-
// hash for .25 second
|
|
8
|
-
const HASH_POWER_MILLS = 250;
|
|
9
|
-
let entropyPos = 0,
|
|
10
|
-
entropyCount = 0;
|
|
11
|
-
const entropyArray = secureRandom.randomBuffer(101);
|
|
12
|
-
module.exports = {
|
|
13
|
-
addEntropy(...ints) {
|
|
14
|
-
entropyCount++;
|
|
15
|
-
for (const i of ints) {
|
|
16
|
-
const pos = entropyPos++ % 101;
|
|
17
|
-
const i2 = entropyArray[pos] += i;
|
|
18
|
-
if (i2 > 9007199254740991) entropyArray[pos] = 0;
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
/**
|
|
22
|
-
A week random number generator can run out of entropy. This should ensure even the worst random number implementation will be reasonably safe.
|
|
23
|
-
@param1 string entropy of at least 32 bytes
|
|
24
|
-
*/
|
|
25
|
-
random32ByteBuffer(entropy = this.browserEntropy()) {
|
|
26
|
-
if (!(typeof entropy === 'string')) {
|
|
27
|
-
throw new Error("string required for entropy");
|
|
28
|
-
}
|
|
29
|
-
if (entropy.length < 32) {
|
|
30
|
-
throw new Error("expecting at least 32 bytes of entropy");
|
|
31
|
-
}
|
|
32
|
-
const start_t = Date.now();
|
|
33
|
-
while (Date.now() - start_t < HASH_POWER_MILLS) entropy = hash.sha256(entropy);
|
|
34
|
-
const hash_array = [];
|
|
35
|
-
hash_array.push(entropy);
|
|
36
|
-
|
|
37
|
-
// Hashing for 1 second may helps the computer is not low on entropy (this method may be called back-to-back).
|
|
38
|
-
hash_array.push(secureRandom.randomBuffer(32));
|
|
39
|
-
return hash.sha256(Buffer.concat(hash_array));
|
|
40
|
-
},
|
|
41
|
-
get_random_key(entropy) {
|
|
42
|
-
return PrivateKey.fromBuffer(this.random32ByteBuffer(entropy));
|
|
43
|
-
},
|
|
44
|
-
// Turn invisible space like characters into a single space
|
|
45
|
-
// normalize_brain_key(brain_key){
|
|
46
|
-
// if (!(typeof brain_key === 'string')) {
|
|
47
|
-
// throw new Error("string required for brain_key");
|
|
48
|
-
// }
|
|
49
|
-
// brain_key = brain_key.trim();
|
|
50
|
-
// return brain_key.split(/[\t\n\v\f\r ]+/).join(' ');
|
|
51
|
-
// },
|
|
52
|
-
|
|
53
|
-
browserEntropy() {
|
|
54
|
-
let entropyStr = Array(entropyArray).join();
|
|
55
|
-
try {
|
|
56
|
-
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;
|
|
57
|
-
for (let i = 0, mimeType; i < navigator.mimeTypes.length; i++) {
|
|
58
|
-
mimeType = navigator.mimeTypes[i];
|
|
59
|
-
entropyStr += mimeType.description + " " + mimeType.type + " " + mimeType.suffixes + " ";
|
|
60
|
-
}
|
|
61
|
-
console.log("INFO\tbrowserEntropy gathered", entropyCount, 'events');
|
|
62
|
-
} catch (error) {
|
|
63
|
-
//nodejs:ReferenceError: window is not defined
|
|
64
|
-
entropyStr += hash.sha256(new Date().toString());
|
|
65
|
-
}
|
|
66
|
-
const b = new Buffer(entropyStr);
|
|
67
|
-
entropyStr += b.toString('binary') + " " + new Date().toString();
|
|
68
|
-
return entropyStr;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var ecdsa = require('./ecdsa');
|
|
4
|
-
var hash = require('./hash');
|
|
5
|
-
var curve = require('ecurve').getCurveByName('secp256k1');
|
|
6
|
-
var assert = require('assert');
|
|
7
|
-
var BigInteger = require('bigi');
|
|
8
|
-
var PublicKey = require('./key_public');
|
|
9
|
-
var PrivateKey = require('./key_private');
|
|
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
|
-
}
|
|
88
|
-
}
|
|
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*/;
|
|
135
|
-
module.exports = Signature;
|
package/lib/auth/index.js
DELETED
|
@@ -1,113 +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
|
-
var Auth = {};
|
|
15
|
-
var transaction = operations.transaction;
|
|
16
|
-
var signed_transaction = operations.signed_transaction;
|
|
17
|
-
Auth.verify = function (name, password, auths) {
|
|
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;
|
|
30
|
-
};
|
|
31
|
-
Auth.generateKeys = function (name, password, roles) {
|
|
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;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
@arg {string} name - blockchain account name
|
|
50
|
-
@arg {string} password - very strong password typically no shorter than a private key
|
|
51
|
-
@arg {array} roles - defaults to standard Steem blockchain-level roles
|
|
52
|
-
*/
|
|
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;
|
|
60
|
-
};
|
|
61
|
-
Auth.isWif = function (privWif) {
|
|
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;
|
|
75
|
-
};
|
|
76
|
-
Auth.toWif = function (name, password, role) {
|
|
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);
|
|
86
|
-
};
|
|
87
|
-
Auth.wifIsValid = function (privWif, pubWif) {
|
|
88
|
-
return this.wifToPublic(privWif) == pubWif;
|
|
89
|
-
};
|
|
90
|
-
Auth.wifToPublic = function (privWif) {
|
|
91
|
-
var pubWif = KeyPrivate.fromWif(privWif);
|
|
92
|
-
pubWif = pubWif.toPublic().toString();
|
|
93
|
-
return pubWif;
|
|
94
|
-
};
|
|
95
|
-
Auth.isPubkey = function (pubkey, address_prefix) {
|
|
96
|
-
return PublicKey.fromString(pubkey, address_prefix) != null;
|
|
97
|
-
};
|
|
98
|
-
Auth.signTransaction = function (trx, keys) {
|
|
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
|
-
}));
|
|
112
|
-
};
|
|
113
|
-
module.exports = Auth;
|
package/lib/auth/memo.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const ByteBuffer = require('bytebuffer');
|
|
4
|
-
const assert = require('assert');
|
|
5
|
-
const base58 = require('bs58');
|
|
6
|
-
const ecc = require('./ecc');
|
|
7
|
-
const Aes = ecc.Aes;
|
|
8
|
-
const PrivateKey = ecc.PrivateKey;
|
|
9
|
-
const PublicKey = ecc.PublicKey;
|
|
10
|
-
const serializer = require('./serializer');
|
|
11
|
-
const ops = serializer.ops;
|
|
12
|
-
const encMemo = ops.encrypted_memo;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
Some fields are only required if the memo is marked for decryption (starts with a hash).
|
|
16
|
-
@arg {string|PrivateKey} private_key - WIF or PrivateKey object
|
|
17
|
-
@arg {string} memo - plain text is returned, hash prefix base58 is decrypted
|
|
18
|
-
@return {string} - utf8 decoded string (hash prefix)
|
|
19
|
-
*/
|
|
20
|
-
function decode(private_key, memo) {
|
|
21
|
-
assert(memo, 'memo is required');
|
|
22
|
-
assert.equal(typeof memo, 'string', 'memo');
|
|
23
|
-
if (!/^#/.test(memo)) return memo;
|
|
24
|
-
memo = memo.substring(1);
|
|
25
|
-
assert(private_key, 'private_key is required');
|
|
26
|
-
checkEncryption();
|
|
27
|
-
private_key = toPrivateObj(private_key);
|
|
28
|
-
memo = base58.decode(memo);
|
|
29
|
-
memo = encMemo.fromBuffer(new Buffer.from(memo, 'binary'));
|
|
30
|
-
const {
|
|
31
|
-
from,
|
|
32
|
-
to,
|
|
33
|
-
nonce,
|
|
34
|
-
check,
|
|
35
|
-
encrypted
|
|
36
|
-
} = memo;
|
|
37
|
-
const pubkey = private_key.toPublicKey().toString();
|
|
38
|
-
const otherpub = pubkey === from.toString() ? to.toString() : from.toString();
|
|
39
|
-
memo = Aes.decrypt(private_key, otherpub, nonce, encrypted, check);
|
|
40
|
-
|
|
41
|
-
// remove varint length prefix
|
|
42
|
-
const mbuf = ByteBuffer.fromBinary(memo.toString('binary'), ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);
|
|
43
|
-
try {
|
|
44
|
-
mbuf.mark();
|
|
45
|
-
return '#' + mbuf.readVString();
|
|
46
|
-
} catch (e) {
|
|
47
|
-
mbuf.reset();
|
|
48
|
-
// Sender did not length-prefix the memo
|
|
49
|
-
memo = new Buffer.from(mbuf.toString('binary'), 'binary').toString('utf-8');
|
|
50
|
-
return '#' + memo;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
Some fields are only required if the memo is marked for encryption (starts with a hash).
|
|
56
|
-
@arg {string|PrivateKey} private_key - WIF or PrivateKey object
|
|
57
|
-
@arg {string|PublicKey} public_key - Recipient
|
|
58
|
-
@arg {string} memo - plain text is returned, hash prefix text is encrypted
|
|
59
|
-
@arg {string} [testNonce = undefined] - just for testing
|
|
60
|
-
@return {string} - base64 decoded string (or plain text)
|
|
61
|
-
*/
|
|
62
|
-
function encode(private_key, public_key, memo, testNonce) {
|
|
63
|
-
assert(memo, 'memo is required');
|
|
64
|
-
assert.equal(typeof memo, 'string', 'memo');
|
|
65
|
-
if (!/^#/.test(memo)) return memo;
|
|
66
|
-
memo = memo.substring(1);
|
|
67
|
-
assert(private_key, 'private_key is required');
|
|
68
|
-
assert(public_key, 'public_key is required');
|
|
69
|
-
checkEncryption();
|
|
70
|
-
private_key = toPrivateObj(private_key);
|
|
71
|
-
public_key = toPublicObj(public_key);
|
|
72
|
-
const mbuf = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);
|
|
73
|
-
mbuf.writeVString(memo);
|
|
74
|
-
memo = new Buffer.from(mbuf.copy(0, mbuf.offset).toBinary(), 'binary');
|
|
75
|
-
const {
|
|
76
|
-
nonce,
|
|
77
|
-
message,
|
|
78
|
-
checksum
|
|
79
|
-
} = Aes.encrypt(private_key, public_key, memo, testNonce);
|
|
80
|
-
memo = encMemo.fromObject({
|
|
81
|
-
from: private_key.toPublicKey(),
|
|
82
|
-
to: public_key,
|
|
83
|
-
nonce,
|
|
84
|
-
check: checksum,
|
|
85
|
-
encrypted: message
|
|
86
|
-
});
|
|
87
|
-
// serialize
|
|
88
|
-
memo = encMemo.toBuffer(memo);
|
|
89
|
-
return '#' + base58.encode(new Buffer.from(memo, 'binary'));
|
|
90
|
-
}
|
|
91
|
-
let encodeTest = undefined;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
Memo encryption has failed in the browser before. An Error will be thrown
|
|
95
|
-
if a memo can't be encrypted and decrypted.
|
|
96
|
-
*/
|
|
97
|
-
function checkEncryption() {
|
|
98
|
-
if (encodeTest === undefined) {
|
|
99
|
-
let plaintext;
|
|
100
|
-
encodeTest = true; // prevent infinate looping
|
|
101
|
-
try {
|
|
102
|
-
const wif = '5JdeC9P7Pbd1uGdFVEsJ41EkEnADbbHGq6p1BwFxm6txNBsQnsw';
|
|
103
|
-
const pubkey = 'STM8m5UgaFAAYQRuaNejYdS8FVLVp9Ss3K1qAVk5de6F8s3HnVbvA';
|
|
104
|
-
const cyphertext = encode(wif, pubkey, '#memo爱');
|
|
105
|
-
plaintext = decode(wif, cyphertext);
|
|
106
|
-
} catch (e) {
|
|
107
|
-
console.error(e);
|
|
108
|
-
} finally {
|
|
109
|
-
encodeTest = plaintext === '#memo爱';
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (encodeTest === false) throw new Error('This environment does not support encryption.');
|
|
113
|
-
}
|
|
114
|
-
const toPrivateObj = o => o ? o.d ? o : PrivateKey.fromWif(o) : o /*null or undefined*/;
|
|
115
|
-
const toPublicObj = o => o ? o.Q ? o : PublicKey.fromString(o) : o /*null or undefined*/;
|
|
116
|
-
module.exports = {
|
|
117
|
-
decode,
|
|
118
|
-
encode
|
|
119
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
// Primary class for creating operations
|
|
5
|
-
Serializer: require('./src/serializer'),
|
|
6
|
-
// helper functions for creating operations
|
|
7
|
-
fp: require('./src/fast_parser'),
|
|
8
|
-
// Low level types
|
|
9
|
-
types: require('./src/types'),
|
|
10
|
-
// Higher level operations (made out of generic types)
|
|
11
|
-
ops: require('./src/operations'),
|
|
12
|
-
// Utility that generates JSON examples
|
|
13
|
-
template: require('./src/template'),
|
|
14
|
-
number_utils: require('./src/number_utils')
|
|
15
|
-
};
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var ChainTypes;
|
|
4
|
-
module.exports = ChainTypes = {};
|
|
5
|
-
ChainTypes.reserved_spaces = {
|
|
6
|
-
relative_protocol_ids: 0,
|
|
7
|
-
protocol_ids: 1,
|
|
8
|
-
implementation_ids: 2
|
|
9
|
-
};
|
|
10
|
-
ChainTypes.operations = {
|
|
11
|
-
vote: 0,
|
|
12
|
-
comment: 1,
|
|
13
|
-
transfer: 2,
|
|
14
|
-
transfer_to_vesting: 3,
|
|
15
|
-
withdraw_vesting: 4,
|
|
16
|
-
limit_order_create: 5,
|
|
17
|
-
limit_order_cancel: 6,
|
|
18
|
-
feed_publish: 7,
|
|
19
|
-
convert: 8,
|
|
20
|
-
account_create: 9,
|
|
21
|
-
account_update: 10,
|
|
22
|
-
witness_update: 11,
|
|
23
|
-
account_witness_vote: 12,
|
|
24
|
-
account_witness_proxy: 13,
|
|
25
|
-
pow: 14,
|
|
26
|
-
custom: 15,
|
|
27
|
-
report_over_production: 16,
|
|
28
|
-
delete_comment: 17,
|
|
29
|
-
custom_json: 18,
|
|
30
|
-
comment_options: 19,
|
|
31
|
-
set_withdraw_vesting_route: 20,
|
|
32
|
-
limit_order_create2: 21,
|
|
33
|
-
claim_account: 22,
|
|
34
|
-
create_claimed_account: 23,
|
|
35
|
-
request_account_recovery: 24,
|
|
36
|
-
recover_account: 25,
|
|
37
|
-
change_recovery_account: 26,
|
|
38
|
-
escrow_transfer: 27,
|
|
39
|
-
escrow_dispute: 28,
|
|
40
|
-
escrow_release: 29,
|
|
41
|
-
pow2: 30,
|
|
42
|
-
escrow_approve: 31,
|
|
43
|
-
transfer_to_savings: 32,
|
|
44
|
-
transfer_from_savings: 33,
|
|
45
|
-
cancel_transfer_from_savings: 34,
|
|
46
|
-
custom_binary: 35,
|
|
47
|
-
decline_voting_rights: 36,
|
|
48
|
-
reset_account: 37,
|
|
49
|
-
set_reset_account: 38,
|
|
50
|
-
claim_reward_balance: 39,
|
|
51
|
-
delegate_vesting_shares: 40,
|
|
52
|
-
account_create_with_delegation: 41,
|
|
53
|
-
witness_set_properties: 42,
|
|
54
|
-
account_update2: 43,
|
|
55
|
-
create_proposal: 44,
|
|
56
|
-
update_proposal_votes: 45,
|
|
57
|
-
remove_proposal: 46,
|
|
58
|
-
claim_reward_balance2: 47,
|
|
59
|
-
vote2: 48,
|
|
60
|
-
smt_setup: 49,
|
|
61
|
-
smt_setup_emissions: 50,
|
|
62
|
-
smt_setup_ico_tier: 51,
|
|
63
|
-
smt_set_setup_parameters: 52,
|
|
64
|
-
smt_set_runtime_parameters: 53,
|
|
65
|
-
smt_create: 54,
|
|
66
|
-
smt_contribute: 55,
|
|
67
|
-
fill_convert_request: 56,
|
|
68
|
-
author_reward: 57,
|
|
69
|
-
curation_reward: 58,
|
|
70
|
-
comment_reward: 59,
|
|
71
|
-
liquidity_reward: 60,
|
|
72
|
-
interest: 61,
|
|
73
|
-
fill_vesting_withdraw: 62,
|
|
74
|
-
fill_order: 63,
|
|
75
|
-
shutdown_witness: 64,
|
|
76
|
-
fill_transfer_from_savings: 65,
|
|
77
|
-
hardfork: 66,
|
|
78
|
-
comment_payout_update: 67,
|
|
79
|
-
return_vesting_delegation: 68,
|
|
80
|
-
comment_benefactor_reward: 69
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
//types.hpp
|
|
84
|
-
ChainTypes.object_type = {
|
|
85
|
-
"null": 0,
|
|
86
|
-
base: 1
|
|
87
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var ByteBuffer = require('bytebuffer');
|
|
4
|
-
module.exports = function (type) {
|
|
5
|
-
return {
|
|
6
|
-
fromHex(hex) {
|
|
7
|
-
var b = ByteBuffer.fromHex(hex, ByteBuffer.LITTLE_ENDIAN);
|
|
8
|
-
return type.fromByteBuffer(b);
|
|
9
|
-
},
|
|
10
|
-
toHex(object) {
|
|
11
|
-
var b = toByteBuffer(type, object);
|
|
12
|
-
return b.toHex();
|
|
13
|
-
},
|
|
14
|
-
fromBuffer(buffer) {
|
|
15
|
-
var b = ByteBuffer.fromBinary(buffer.toString(), ByteBuffer.LITTLE_ENDIAN);
|
|
16
|
-
return type.fromByteBuffer(b);
|
|
17
|
-
},
|
|
18
|
-
toBuffer(object) {
|
|
19
|
-
return new Buffer(toByteBuffer(type, object).toBinary(), 'binary');
|
|
20
|
-
},
|
|
21
|
-
fromBinary(string) {
|
|
22
|
-
var b = ByteBuffer.fromBinary(string, ByteBuffer.LITTLE_ENDIAN);
|
|
23
|
-
return type.fromByteBuffer(b);
|
|
24
|
-
},
|
|
25
|
-
toBinary(object) {
|
|
26
|
-
return toByteBuffer(type, object).toBinary();
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
var toByteBuffer = function (type, object) {
|
|
31
|
-
var b = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);
|
|
32
|
-
type.appendByteBuffer(b, object);
|
|
33
|
-
return b.copy(0, b.offset);
|
|
34
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/** Exception nesting. */
|
|
4
|
-
class ErrorWithCause {
|
|
5
|
-
constructor(message, cause) {
|
|
6
|
-
this.message = message;
|
|
7
|
-
if (typeof cause !== "undefined" && cause !== null ? cause.message : undefined) {
|
|
8
|
-
this.message = `cause\t${cause.message}\t` + this.message;
|
|
9
|
-
}
|
|
10
|
-
var stack = ""; //(new Error).stack
|
|
11
|
-
if (typeof cause !== "undefined" && cause !== null ? cause.stack : undefined) {
|
|
12
|
-
stack = `caused by\n\t${cause.stack}\t` + stack;
|
|
13
|
-
}
|
|
14
|
-
this.stack = this.message + "\n" + stack;
|
|
15
|
-
}
|
|
16
|
-
static throw(message, cause) {
|
|
17
|
-
var msg = message;
|
|
18
|
-
if (typeof cause !== "undefined" && cause !== null ? cause.message : undefined) {
|
|
19
|
-
msg += `\t cause: ${cause.message} `;
|
|
20
|
-
}
|
|
21
|
-
if (typeof cause !== "undefined" && cause !== null ? cause.stack : undefined) {
|
|
22
|
-
msg += `\n stack: ${cause.stack} `;
|
|
23
|
-
}
|
|
24
|
-
throw new Error(msg);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
module.exports = ErrorWithCause;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const ecc = require("../../ecc");
|
|
4
|
-
const PublicKey = ecc.PublicKey;
|
|
5
|
-
class FastParser {
|
|
6
|
-
static fixed_data(b, len, buffer) {
|
|
7
|
-
if (!b) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (buffer) {
|
|
11
|
-
let data = buffer.slice(0, len).toString('binary');
|
|
12
|
-
b.append(data, 'binary');
|
|
13
|
-
while (len-- > data.length) {
|
|
14
|
-
b.writeUint8(0);
|
|
15
|
-
}
|
|
16
|
-
} else {
|
|
17
|
-
let b_copy = b.copy(b.offset, b.offset + len);
|
|
18
|
-
b.skip(len);
|
|
19
|
-
return new Buffer.from(b_copy.toBinary(), 'binary');
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
static public_key(b, public_key) {
|
|
23
|
-
if (!b) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (public_key) {
|
|
27
|
-
var buffer = public_key.toBuffer();
|
|
28
|
-
b.append(buffer.toString('binary'), 'binary');
|
|
29
|
-
return;
|
|
30
|
-
} else {
|
|
31
|
-
buffer = FastParser.fixed_data(b, 33);
|
|
32
|
-
return PublicKey.fromBuffer(buffer);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
static ripemd160(b, ripemd160) {
|
|
36
|
-
if (!b) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (ripemd160) {
|
|
40
|
-
FastParser.fixed_data(b, 20, ripemd160);
|
|
41
|
-
return;
|
|
42
|
-
} else {
|
|
43
|
-
return FastParser.fixed_data(b, 20);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
static time_point_sec(b, epoch) {
|
|
47
|
-
if (epoch) {
|
|
48
|
-
epoch = Math.ceil(epoch / 1000);
|
|
49
|
-
b.writeInt32(epoch);
|
|
50
|
-
return;
|
|
51
|
-
} else {
|
|
52
|
-
epoch = b.readInt32(); // fc::time_point_sec
|
|
53
|
-
return new Date(epoch * 1000);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
module.exports = FastParser;
|