From 04f187cfb92349d81bdddc02de1454bf2e59ac0b Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 29 Mar 2019 18:04:24 -0400 Subject: [PATCH] refactor (@embark/embark-utils): move soliditySha3 to embark-utils --- packages/embark-utils/package.json | 3 ++- packages/embark-utils/src/index.js | 8 +++++++- packages/embark/src/lib/modules/ens/ENSFunctions.js | 4 ++-- packages/embark/src/lib/modules/ens/index.js | 8 ++++---- packages/embark/src/lib/utils/utils.js | 6 ------ 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/embark-utils/package.json b/packages/embark-utils/package.json index b54c1edda..d954db2ba 100644 --- a/packages/embark-utils/package.json +++ b/packages/embark-utils/package.json @@ -47,7 +47,8 @@ "dependencies": { "@babel/runtime-corejs2": "7.3.1", "follow-redirects": "1.5.7", - "multihashes": "0.4.14" + "multihashes": "0.4.14", + "web3": "1.0.0-beta.37" }, "devDependencies": { "@babel/cli": "7.2.3", diff --git a/packages/embark-utils/src/index.js b/packages/embark-utils/src/index.js index f18ab4d3f..6ae501026 100644 --- a/packages/embark-utils/src/index.js +++ b/packages/embark-utils/src/index.js @@ -33,6 +33,11 @@ function hashTo32ByteHexString(hash) { return '0x' + multihash.toHexString(digest); } +function soliditySha3(arg) { + const Web3 = require('web3'); + return Web3.utils.soliditySha3(arg); +} + const Utils = { joinPath: function() { const path = require('path'); @@ -46,7 +51,8 @@ const Utils = { checkIsAvailable, findNextPort, hashTo32ByteHexString, - isHex + isHex, + soliditySha3 }; module.exports = Utils; diff --git a/packages/embark/src/lib/modules/ens/ENSFunctions.js b/packages/embark/src/lib/modules/ens/ENSFunctions.js index 69cafaca4..2c2865052 100644 --- a/packages/embark/src/lib/modules/ens/ENSFunctions.js +++ b/packages/embark/src/lib/modules/ens/ENSFunctions.js @@ -48,12 +48,12 @@ function registerSubDomain(web3, ens, registrar, resolver, defaultAccount, subdo }); } -function lookupAddress(address, ens, utils, createResolverContract, callback) { +function lookupAddress(address, ens, soliditySha3, createResolverContract, callback) { if (address.startsWith("0x")) { address = address.slice(2); } - let node = utils.soliditySha3(address.toLowerCase() + reverseAddressSuffix); + let node = soliditySha3(address.toLowerCase() + reverseAddressSuffix); function cb(err, name) { if (err === NoDecodeStringErr || err === NoDecodeAddrErr) { diff --git a/packages/embark/src/lib/modules/ens/index.js b/packages/embark/src/lib/modules/ens/index.js index 63f4b4593..e7a366d4a 100644 --- a/packages/embark/src/lib/modules/ens/index.js +++ b/packages/embark/src/lib/modules/ens/index.js @@ -1,4 +1,4 @@ -import {joinPath, hashTo32ByteHexString} from 'embark-utils'; +import {joinPath, hashTo32ByteHexString, soliditySha3} from 'embark-utils'; const utils = require('../../utils/utils.js'); const namehash = require('eth-ens-namehash'); const async = require('async'); @@ -287,7 +287,7 @@ class ENS { return callback(error); } - const reverseNode = utils.soliditySha3(address.toLowerCase().substr(2) + reverseAddrSuffix); + const reverseNode = soliditySha3(address.toLowerCase().substr(2) + reverseAddrSuffix); this.registerSubDomain(defaultAccount, subDomainName, reverseNode, address, secureSend, callback); }); } @@ -338,7 +338,7 @@ class ENS { (req, res) => { async.waterfall([ function (callback) { - ENSFunctions.lookupAddress(req.query.address, self.ensContract, utils, createInternalResolverContract.bind(self), callback); + ENSFunctions.lookupAddress(req.query.address, self.ensContract, soliditySha3, createInternalResolverContract.bind(self), callback); } ], function (error, name) { if (error) { @@ -498,7 +498,7 @@ class ENS { const web3 = result[3]; const rootNode = namehash.hash(self.registration.rootDomain); - var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + reverseAddrSuffix); + var reverseNode = soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + reverseAddrSuffix); const owner = await self.ensContract.methods.owner(rootNode).call(); if (owner === web3.eth.defaultAccount) { diff --git a/packages/embark/src/lib/utils/utils.js b/packages/embark/src/lib/utils/utils.js index ee63c2fa4..886a968a0 100644 --- a/packages/embark/src/lib/utils/utils.js +++ b/packages/embark/src/lib/utils/utils.js @@ -365,11 +365,6 @@ function sha512(arg) { return hash.update(arg).digest('hex'); } -function soliditySha3(arg) { - const Web3 = require('web3'); - return Web3.utils.soliditySha3(arg); -} - function normalizeInput(input) { if(typeof input === 'string') return input; let args = Object.values(input); @@ -635,7 +630,6 @@ module.exports = { toChecksumAddress, sha3, sha512, - soliditySha3, normalizeInput, buildUrl, buildUrlFromConfig,