REFACTOR default imports/exports

feature/replace-eccrypto
pubkey 2 years ago
parent 0bbb5df91e
commit 55891a6ee2
  1. 2
      .github/workflows/ci.yml
  2. 1
      .nvmrc
  3. 2
      src/calculate-contract-address.js
  4. 2
      src/create-identity.js
  5. 2
      src/decrypt-with-private-key.js
  6. 2
      src/encrypt-with-public-key.js
  7. 20
      src/index.js
  8. 2
      src/public-key-by-private-key.js
  9. 2
      src/recover-public-key.js
  10. 4
      src/recover.js
  11. 4
      src/sign-transaction.js
  12. 2
      src/sign.js
  13. 2
      src/tx-data-by-compiled.js
  14. 1
      test/unit.test.js

@ -18,7 +18,7 @@ jobs:
- name: Use Node.js 12.11.0 - name: Use Node.js 12.11.0
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: 12.11.0 node-version-file: '.nvmrc'
- run: npm install - run: npm install
- run: npm run lint - run: npm run lint
- run: npm run build - run: npm run build

@ -0,0 +1 @@
19.5.0

@ -8,7 +8,7 @@ import {
} from './util'; } from './util';
export default function calculateContractAddress( export function calculateContractAddress(
creatorAddress, creatorAddress,
nonce nonce
) { ) {

@ -31,7 +31,7 @@ export function createPrivateKey(entropy) {
* private-, public-Key and address * private-, public-Key and address
* @param {Buffer?} entropy if provided, will use that as single random-source * @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 privateKey = createPrivateKey(entropy);
const wallet = new Wallet(privateKey); const wallet = new Wallet(privateKey);
const identity = { const identity = {

@ -8,7 +8,7 @@ import {
removeLeading0x removeLeading0x
} from './util'; } from './util';
export default function decryptWithPrivateKey(privateKey, encrypted) { export function decryptWithPrivateKey(privateKey, encrypted) {
encrypted = parse(encrypted); encrypted = parse(encrypted);

@ -5,7 +5,7 @@ import {
decompress decompress
} from './public-key'; } from './public-key';
export default function encryptWithPublicKey(publicKey, message, opts) { export function encryptWithPublicKey(publicKey, message, opts) {
// ensure its an uncompressed publicKey // ensure its an uncompressed publicKey
publicKey = decompress(publicKey); publicKey = decompress(publicKey);

@ -1,16 +1,16 @@
import createIdentity from './create-identity'; import { createIdentity } from './create-identity';
import * as publicKey from './public-key'; import * as publicKey from './public-key';
import decryptWithPrivateKey from './decrypt-with-private-key'; import { decryptWithPrivateKey } from './decrypt-with-private-key';
import encryptWithPublicKey from './encrypt-with-public-key'; import { encryptWithPublicKey } from './encrypt-with-public-key';
import * as cipher from './cipher'; import * as cipher from './cipher';
import publicKeyByPrivateKey from './public-key-by-private-key'; import { publicKeyByPrivateKey } from './public-key-by-private-key';
import recover from './recover'; import { recover } from './recover';
import recoverPublicKey from './recover-public-key'; import { recoverPublicKey } from './recover-public-key';
import sign from './sign'; import { sign } from './sign';
import signTransaction from './sign-transaction'; import { signTransaction } from './sign-transaction';
import txDataByCompiled from './tx-data-by-compiled'; import { txDataByCompiled } from './tx-data-by-compiled';
import calculateContractAddress from './calculate-contract-address'; import { calculateContractAddress } from './calculate-contract-address';
import * as hash from './hash'; import * as hash from './hash';
import * as hex from './hex'; import * as hex from './hex';
import * as vrs from './vrs'; import * as vrs from './vrs';

@ -12,7 +12,7 @@ import {
* where 04 has stripped from left * where 04 has stripped from left
* @returns {string} * @returns {string}
*/ */
export default function publicKeyOfPrivateKey(privateKey) { export function publicKeyByPrivateKey(privateKey) {
privateKey = addLeading0x(privateKey); privateKey = addLeading0x(privateKey);
const publicKeyBuffer = privateToPublic(toBuffer(privateKey)); const publicKeyBuffer = privateToPublic(toBuffer(privateKey));
return publicKeyBuffer.toString('hex'); return publicKeyBuffer.toString('hex');

@ -14,7 +14,7 @@ import {
* @param {string} hash * @param {string} hash
* @return {string} publicKey * @return {string} publicKey
*/ */
export default function recoverPublicKey(signature, hash) { export function recoverPublicKey(signature, hash) {
signature = removeLeading0x(signature); signature = removeLeading0x(signature);
// split into v-value and sig // split into v-value and sig

@ -1,4 +1,4 @@
import recoverPublicKey from './recover-public-key'; import { recoverPublicKey } from './recover-public-key';
import { import {
toAddress as addressByPublicKey toAddress as addressByPublicKey
} from './public-key'; } from './public-key';
@ -9,7 +9,7 @@ import {
* @param {string} hash * @param {string} hash
* @return {string} address * @return {string} address
*/ */
export default function recover(sigString, hash) { export function recover(sigString, hash) {
const pubkey = recoverPublicKey(sigString, hash); const pubkey = recoverPublicKey(sigString, hash);
const address = addressByPublicKey(pubkey); const address = addressByPublicKey(pubkey);
return address; return address;

@ -1,11 +1,11 @@
import { Transaction } from '@ethereumjs/tx'; import { Transaction } from '@ethereumjs/tx';
import publicKeyByPrivateKey from './public-key-by-private-key'; import { publicKeyByPrivateKey } from './public-key-by-private-key';
import { import {
toAddress as addressByPublicKey toAddress as addressByPublicKey
} from './public-key'; } from './public-key';
export default function signTransaction( export function signTransaction(
rawTx, rawTx,
privateKey, privateKey,
txOptions = {} txOptions = {}

@ -13,7 +13,7 @@ import {
* @param {string} hash * @param {string} hash
* @return {string} hexString * @return {string} hexString
*/ */
export default function sign(privateKey, hash) { export function sign(privateKey, hash) {
hash = addLeading0x(hash); hash = addLeading0x(hash);
if (hash.length !== 66) if (hash.length !== 66)
throw new Error('EthCrypto.sign(): Can only sign hashes, given: ' + hash); throw new Error('EthCrypto.sign(): Can only sign hashes, given: ' + hash);

@ -1,6 +1,6 @@
import { ContractFactory } from 'ethers'; import { ContractFactory } from 'ethers';
export default function txDataByCompiled( export function txDataByCompiled(
abi, abi,
bytecode, bytecode,
args args

@ -65,6 +65,7 @@ describe('unit.test.js', () => {
describe('.publicKeyByPrivateKey()', () => { describe('.publicKeyByPrivateKey()', () => {
describe('positive', () => { describe('positive', () => {
it('should give the correct publicKey', () => { it('should give the correct publicKey', () => {
console.dir(EthCrypto);
const publicKey = EthCrypto.publicKeyByPrivateKey(TEST_DATA.privateKey); const publicKey = EthCrypto.publicKeyByPrivateKey(TEST_DATA.privateKey);
assert.equal(publicKey, TEST_DATA.publicKey); assert.equal(publicKey, TEST_DATA.publicKey);
}); });

Loading…
Cancel
Save