From 55891a6ee26a4c2f2ab7585564d4161a28deaf08 Mon Sep 17 00:00:00 2001 From: pubkey <8926560+pubkey@users.noreply.github.com> Date: Mon, 20 Feb 2023 16:17:23 +0100 Subject: [PATCH] REFACTOR default imports/exports --- .github/workflows/ci.yml | 2 +- .nvmrc | 1 + src/calculate-contract-address.js | 2 +- src/create-identity.js | 2 +- src/decrypt-with-private-key.js | 2 +- src/encrypt-with-public-key.js | 2 +- src/index.js | 20 ++++++++++---------- src/public-key-by-private-key.js | 2 +- src/recover-public-key.js | 2 +- src/recover.js | 4 ++-- src/sign-transaction.js | 4 ++-- src/sign.js | 2 +- src/tx-data-by-compiled.js | 2 +- test/unit.test.js | 1 + 14 files changed, 25 insertions(+), 23 deletions(-) create mode 100644 .nvmrc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1b0ab3..4fe2125 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: - name: Use Node.js 12.11.0 uses: actions/setup-node@v3 with: - node-version: 12.11.0 + node-version-file: '.nvmrc' - run: npm install - run: npm run lint - run: npm run build diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..912dbfa --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +19.5.0 diff --git a/src/calculate-contract-address.js b/src/calculate-contract-address.js index c78ff3e..21d721c 100644 --- a/src/calculate-contract-address.js +++ b/src/calculate-contract-address.js @@ -8,7 +8,7 @@ import { } from './util'; -export default function calculateContractAddress( +export function calculateContractAddress( creatorAddress, nonce ) { diff --git a/src/create-identity.js b/src/create-identity.js index d054b81..9dbe4b9 100644 --- a/src/create-identity.js +++ b/src/create-identity.js @@ -31,7 +31,7 @@ export function createPrivateKey(entropy) { * private-, public-Key and address * @param {Buffer?} entropy if provided, will use that as single random-source */ -export default function createIdentity(entropy) { +export function createIdentity(entropy) { const privateKey = createPrivateKey(entropy); const wallet = new Wallet(privateKey); const identity = { diff --git a/src/decrypt-with-private-key.js b/src/decrypt-with-private-key.js index df92708..4baa7fc 100644 --- a/src/decrypt-with-private-key.js +++ b/src/decrypt-with-private-key.js @@ -8,7 +8,7 @@ import { removeLeading0x } from './util'; -export default function decryptWithPrivateKey(privateKey, encrypted) { +export function decryptWithPrivateKey(privateKey, encrypted) { encrypted = parse(encrypted); diff --git a/src/encrypt-with-public-key.js b/src/encrypt-with-public-key.js index a34b10d..ac5613b 100644 --- a/src/encrypt-with-public-key.js +++ b/src/encrypt-with-public-key.js @@ -5,7 +5,7 @@ import { decompress } from './public-key'; -export default function encryptWithPublicKey(publicKey, message, opts) { +export function encryptWithPublicKey(publicKey, message, opts) { // ensure its an uncompressed publicKey publicKey = decompress(publicKey); diff --git a/src/index.js b/src/index.js index 4a0da0f..ffd62c0 100644 --- a/src/index.js +++ b/src/index.js @@ -1,16 +1,16 @@ -import createIdentity from './create-identity'; +import { createIdentity } from './create-identity'; import * as publicKey from './public-key'; -import decryptWithPrivateKey from './decrypt-with-private-key'; -import encryptWithPublicKey from './encrypt-with-public-key'; +import { decryptWithPrivateKey } from './decrypt-with-private-key'; +import { encryptWithPublicKey } from './encrypt-with-public-key'; import * as cipher from './cipher'; -import publicKeyByPrivateKey from './public-key-by-private-key'; -import recover from './recover'; -import recoverPublicKey from './recover-public-key'; -import sign from './sign'; -import signTransaction from './sign-transaction'; -import txDataByCompiled from './tx-data-by-compiled'; -import calculateContractAddress from './calculate-contract-address'; +import { publicKeyByPrivateKey } from './public-key-by-private-key'; +import { recover } from './recover'; +import { recoverPublicKey } from './recover-public-key'; +import { sign } from './sign'; +import { signTransaction } from './sign-transaction'; +import { txDataByCompiled } from './tx-data-by-compiled'; +import { calculateContractAddress } from './calculate-contract-address'; import * as hash from './hash'; import * as hex from './hex'; import * as vrs from './vrs'; diff --git a/src/public-key-by-private-key.js b/src/public-key-by-private-key.js index e275e74..fc8c27f 100644 --- a/src/public-key-by-private-key.js +++ b/src/public-key-by-private-key.js @@ -12,7 +12,7 @@ import { * where 04 has stripped from left * @returns {string} */ -export default function publicKeyOfPrivateKey(privateKey) { +export function publicKeyByPrivateKey(privateKey) { privateKey = addLeading0x(privateKey); const publicKeyBuffer = privateToPublic(toBuffer(privateKey)); return publicKeyBuffer.toString('hex'); diff --git a/src/recover-public-key.js b/src/recover-public-key.js index 63a58f8..ca8cbb8 100644 --- a/src/recover-public-key.js +++ b/src/recover-public-key.js @@ -14,7 +14,7 @@ import { * @param {string} hash * @return {string} publicKey */ -export default function recoverPublicKey(signature, hash) { +export function recoverPublicKey(signature, hash) { signature = removeLeading0x(signature); // split into v-value and sig diff --git a/src/recover.js b/src/recover.js index 26880d9..0f90d83 100644 --- a/src/recover.js +++ b/src/recover.js @@ -1,4 +1,4 @@ -import recoverPublicKey from './recover-public-key'; +import { recoverPublicKey } from './recover-public-key'; import { toAddress as addressByPublicKey } from './public-key'; @@ -9,7 +9,7 @@ import { * @param {string} hash * @return {string} address */ -export default function recover(sigString, hash) { +export function recover(sigString, hash) { const pubkey = recoverPublicKey(sigString, hash); const address = addressByPublicKey(pubkey); return address; diff --git a/src/sign-transaction.js b/src/sign-transaction.js index f8b919b..380baa6 100644 --- a/src/sign-transaction.js +++ b/src/sign-transaction.js @@ -1,11 +1,11 @@ import { Transaction } from '@ethereumjs/tx'; -import publicKeyByPrivateKey from './public-key-by-private-key'; +import { publicKeyByPrivateKey } from './public-key-by-private-key'; import { toAddress as addressByPublicKey } from './public-key'; -export default function signTransaction( +export function signTransaction( rawTx, privateKey, txOptions = {} diff --git a/src/sign.js b/src/sign.js index b2482e7..2c51e2c 100644 --- a/src/sign.js +++ b/src/sign.js @@ -13,7 +13,7 @@ import { * @param {string} hash * @return {string} hexString */ -export default function sign(privateKey, hash) { +export function sign(privateKey, hash) { hash = addLeading0x(hash); if (hash.length !== 66) throw new Error('EthCrypto.sign(): Can only sign hashes, given: ' + hash); diff --git a/src/tx-data-by-compiled.js b/src/tx-data-by-compiled.js index ac5d993..7da3634 100644 --- a/src/tx-data-by-compiled.js +++ b/src/tx-data-by-compiled.js @@ -1,6 +1,6 @@ import { ContractFactory } from 'ethers'; -export default function txDataByCompiled( +export function txDataByCompiled( abi, bytecode, args diff --git a/test/unit.test.js b/test/unit.test.js index 25a7d31..2293820 100644 --- a/test/unit.test.js +++ b/test/unit.test.js @@ -65,6 +65,7 @@ describe('unit.test.js', () => { describe('.publicKeyByPrivateKey()', () => { describe('positive', () => { it('should give the correct publicKey', () => { + console.dir(EthCrypto); const publicKey = EthCrypto.publicKeyByPrivateKey(TEST_DATA.privateKey); assert.equal(publicKey, TEST_DATA.publicKey); });