REDUCE build-size

pull/15/head
pubkey 7 years ago
parent 91ce7f3352
commit 80e1861a4f
  1. 6
      package.json
  2. 3
      perf.txt
  3. 9
      src/calculate-contract-address.js
  4. 6
      src/create-identity.js
  5. 12
      src/decrypt-with-private-key.js
  6. 27
      src/encrypt-with-public-key.js
  7. 6
      src/public-key-by-private-key.js
  8. 9
      src/public-key.js
  9. 9
      src/vrs.js

@ -31,7 +31,8 @@
"build:es6": "rimraf -rf dist/es && cross-env NODE_ENV=es6 babel src --out-dir dist/es",
"build:es5": "cross-env NODE_ENV=es5 node node_modules/babel-cli/bin/babel.js src --out-dir dist/lib",
"build:test": "cross-env NODE_ENV=es5 node node_modules/babel-cli/bin/babel.js test --out-dir test_tmp",
"build": "npm run clear && concurrently \"npm run build:es6\" \"npm run build:es5\" \"npm run build:test\" \"npm run build:sol\""
"build": "npm run clear && concurrently \"npm run build:es6\" \"npm run build:es5\" \"npm run build:test\" \"npm run build:sol\"",
"disc": "npm run build && browserify dist/lib/index.js --no-builtins --full-paths | uglifyjs --compress --mangle | discify --open --full-paths"
},
"repository": {
"type": "git",
@ -70,9 +71,10 @@
"concurrently": "3.5.1",
"convert-hrtime": "2.0.0",
"cross-env": "5.1.6",
"disc": "1.3.3",
"eslint": "4.19.1",
"ganache-cli": "6.1.0",
"gzip-size-cli": "^2.1.0",
"gzip-size-cli": "2.1.0",
"is-node": "1.0.2",
"js-sha3": "0.7.0",
"karma": "2.0.2",

@ -0,0 +1,3 @@
=== build size
BEFORE: 140000
AFTER: 123499

@ -1,14 +1,17 @@
import ethUtil from 'ethereumjs-util';
import {
generateAddress,
toChecksumAddress
} from 'ethereumjs-util';
export default function calculateContractAddress(
creatorAddress,
nonce
) {
const addressBuffer = ethUtil.generateAddress(
const addressBuffer = generateAddress(
creatorAddress,
nonce
);
const address = addressBuffer.toString('hex');
return ethUtil.toChecksumAddress(address);
return toChecksumAddress(address);
}

@ -1,13 +1,15 @@
import publicKeyByPrivateKey from './public-key-by-private-key';
import Account from 'eth-lib/lib/account';
import {
create as createAccount
} from 'eth-lib/lib/account';
/**
* creates a new object with
* private-, public-Key and address
*/
export default function createIdentity() {
const identity = Account.create();
const identity = createAccount();
identity.publicKey = publicKeyByPrivateKey(identity.privateKey);
return identity;
}

@ -1,4 +1,6 @@
import eccrypto from 'eccrypto';
import {
decrypt
} from 'eccrypto';
import {
parse
} from './cipher';
@ -6,7 +8,7 @@ import {
removeTrailing0x
} from './util';
export default async function decryptWithPrivateKey(privateKey, encrypted) {
export default function decryptWithPrivateKey(privateKey, encrypted) {
encrypted = parse(encrypted);
@ -20,9 +22,9 @@ export default async function decryptWithPrivateKey(privateKey, encrypted) {
mac: new Buffer(encrypted.mac, 'hex')
};
const decryptedBuffer = await eccrypto.decrypt(
return decrypt(
new Buffer(twoStripped, 'hex'),
encryptedBuffer
);
return decryptedBuffer.toString();
).then(decryptedBuffer => decryptedBuffer.toString());
}

@ -1,9 +1,11 @@
import eccrypto from 'eccrypto';
import {
encrypt
} from 'eccrypto';
import {
decompress
} from './public-key';
export default async function encryptWithPublicKey(publicKey, message) {
export default function encryptWithPublicKey(publicKey, message) {
// ensure its an uncompressed publicKey
publicKey = decompress(publicKey);
@ -11,16 +13,17 @@ export default async function encryptWithPublicKey(publicKey, message) {
// re-add the compression-flag
const pubString = '04' + publicKey;
const encryptedBuffers = await eccrypto.encrypt(
return encrypt(
new Buffer(pubString, 'hex'),
Buffer(message)
);
const encrypted = {
iv: encryptedBuffers.iv.toString('hex'),
ephemPublicKey: encryptedBuffers.ephemPublicKey.toString('hex'),
ciphertext: encryptedBuffers.ciphertext.toString('hex'),
mac: encryptedBuffers.mac.toString('hex')
};
return encrypted;
).then(encryptedBuffers => {
const encrypted = {
iv: encryptedBuffers.iv.toString('hex'),
ephemPublicKey: encryptedBuffers.ephemPublicKey.toString('hex'),
ciphertext: encryptedBuffers.ciphertext.toString('hex'),
mac: encryptedBuffers.mac.toString('hex')
};
return encrypted;
});
}

@ -1,4 +1,6 @@
import EthUtil from 'ethereumjs-util';
import {
privateToPublic
} from 'ethereumjs-util';
import {
addTrailing0x
} from './util';
@ -11,6 +13,6 @@ import {
*/
export default function publicKeyOfPrivateKey(privateKey) {
privateKey = addTrailing0x(privateKey);
const publicKeyBuffer = EthUtil.privateToPublic(privateKey);
const publicKeyBuffer = privateToPublic(privateKey);
return publicKeyBuffer.toString('hex');
}

@ -1,7 +1,10 @@
import {
publicKeyConvert
} from 'secp256k1';
import ethUtil from 'ethereumjs-util';
import {
pubToAddress,
toChecksumAddress
} from 'ethereumjs-util';
export function compress(startsWith04) {
@ -42,7 +45,7 @@ export function toAddress(publicKey) {
// normalize key
publicKey = decompress(publicKey);
const addressBuffer = ethUtil.pubToAddress(new Buffer(publicKey, 'hex'));
const checkSumAdress = ethUtil.toChecksumAddress(addressBuffer.toString('hex'));
const addressBuffer = pubToAddress(new Buffer(publicKey, 'hex'));
const checkSumAdress = toChecksumAddress(addressBuffer.toString('hex'));
return checkSumAdress;
}

@ -1,4 +1,7 @@
import Account from 'eth-lib/lib/account';
import {
decodeSignature,
encodeSignature
} from 'eth-lib/lib/account';
/**
* split signature-hex into parts
@ -6,7 +9,7 @@ import Account from 'eth-lib/lib/account';
* @return {{v: string, r: string, s: string}}
*/
export function fromString(hexString) {
const arr = Account.decodeSignature(hexString);
const arr = decodeSignature(hexString);
return {
v: arr[0],
r: arr[1],
@ -21,5 +24,5 @@ export function fromString(hexString) {
*/
export function toString(sig) {
const partsArray = [sig.v, sig.r, sig.s];
return Account.encodeSignature(partsArray);
return encodeSignature(partsArray);
}

Loading…
Cancel
Save