@exodus/ethereum-lib 0.0.7 → 0.0.9

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/lib/encode.js CHANGED
@@ -7,6 +7,8 @@ exports.validate = validate;
7
7
  exports.hasChecksum = hasChecksum;
8
8
  exports.encodePrivate = encodePrivate;
9
9
  exports.encodePublic = encodePublic;
10
+ exports.isValidPrivate = isValidPrivate;
11
+ exports.encodePublicFromPrivate = encodePublicFromPrivate;
10
12
 
11
13
  var _ethereumjsUtil = _interopRequireDefault(require("ethereumjs-util"));
12
14
 
@@ -33,4 +35,16 @@ function encodePublic(compressedPubKey) {
33
35
  const hash160bits = _ethereumjsUtil.default.publicToAddress(compressedPubKey, true);
34
36
 
35
37
  return _ethereumjsUtil.default.toChecksumAddress(hash160bits.toString('hex'));
38
+ }
39
+
40
+ function isValidPrivate(privateKey) {
41
+ if (privateKey.length !== 32 || !_ethereumjsUtil.default.isValidPrivate(privateKey)) {
42
+ return false;
43
+ }
44
+
45
+ return true;
46
+ }
47
+
48
+ function encodePublicFromPrivate(privateKey) {
49
+ return _ethereumjsUtil.default.toChecksumAddress(_ethereumjsUtil.default.privateToAddress(privateKey).toString('hex'));
36
50
  }
@@ -27,15 +27,16 @@ function createUnsignedTx({
27
27
  chainId
28
28
  }) {
29
29
  if (txInput) {
30
- txInput = _ethereumjsUtil.default.toBuffer(txInput);
30
+ txInput = _ethereumjsUtil.default.toBuffer(txInput); // If txInput is already a Buffer, then it is passed through
31
31
  } else {
32
32
  txInput = Buffer.alloc(0);
33
33
  }
34
34
 
35
35
  if (!chainId) chainId = _constants.CHAIN_IDS[baseAsset.name]; // mainnet
36
36
 
37
- const to = asset.isEthereumToken ? asset.contract.addresses.current : address;
38
- let value = (0, _utils.currency2buffer)(asset.isEthereumToken ? baseAsset.currency.ZERO : amount); // TODO: check: present on desktop missing on mobile. This insures we never have a buffer specifying 0.
37
+ const isEthereumToken = (0, _utils._isEthereumToken)(asset);
38
+ const to = isEthereumToken ? asset.contract.addresses.current : address;
39
+ let value = (0, _utils.currency2buffer)(isEthereumToken ? baseAsset.currency.ZERO : amount); // TODO: check: present on desktop missing on mobile. This insures we never have a buffer specifying 0.
39
40
  // In ETH, a buffer of zero length and a buffer specifying 0 imply different things
40
41
 
41
42
  if (value.equals(Buffer.from([0]))) value = Buffer.alloc(0);
@@ -46,7 +47,9 @@ function createUnsignedTx({
46
47
 
47
48
  const txData = {
48
49
  nonce: nonce === 0 ? Buffer.alloc(0) : _ethereumjsUtil.default.intToBuffer(nonce),
50
+ // mobile: { nonce: ethUtil.intToBuffer(nonce) }
49
51
  gasPrice: (0, _utils.currency2buffer)(gasPrice.toBase()),
52
+ // mobile: { gasPrice: currency2buffer(gasPrice) }
50
53
  gasLimit: _ethereumjsUtil.default.intToBuffer(gasLimit),
51
54
  to,
52
55
  value,
@@ -55,6 +58,7 @@ function createUnsignedTx({
55
58
  };
56
59
  const txMeta = {
57
60
  assetName: asset.name,
61
+ // TODO: We should move away from putting the PK into txMeta, it is a bad practice. It is a potential PK exposure risk if the wrong PK gets included here.
58
62
  privateKey,
59
63
  // Used for importing private key
60
64
  fee: baseAsset.currency.baseUnit(gasPrice.toBase().toNumber() * gasLimit)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-lib",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Ethereum Library",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -14,13 +14,13 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@exodus/asset-lib": "^3.2.0",
17
- "@exodus/models": "^8.0.0",
18
- "base-x": "3.0.4",
17
+ "@exodus/models": "^8.2.0",
18
+ "base-x": "^3.0.2",
19
19
  "ethereumjs-tx": "1.3.7",
20
20
  "ethereumjs-util": "5.2.0"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@exodus/assets": "8.0.x"
24
24
  },
25
- "gitHead": "105c29ed959d9e8fee80d89d9223a3c003a6afb6"
25
+ "gitHead": "82f045d72b69ea29985e824389401c394f209a1d"
26
26
  }