mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-11 06:16:01 +00:00
refactor (@embark/embark-utils): move soliditySha3 to embark-utils
This commit is contained in:
parent
7511e3c113
commit
04f187cfb9
@ -47,7 +47,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime-corejs2": "7.3.1",
|
"@babel/runtime-corejs2": "7.3.1",
|
||||||
"follow-redirects": "1.5.7",
|
"follow-redirects": "1.5.7",
|
||||||
"multihashes": "0.4.14"
|
"multihashes": "0.4.14",
|
||||||
|
"web3": "1.0.0-beta.37"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "7.2.3",
|
"@babel/cli": "7.2.3",
|
||||||
|
@ -33,6 +33,11 @@ function hashTo32ByteHexString(hash) {
|
|||||||
return '0x' + multihash.toHexString(digest);
|
return '0x' + multihash.toHexString(digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function soliditySha3(arg) {
|
||||||
|
const Web3 = require('web3');
|
||||||
|
return Web3.utils.soliditySha3(arg);
|
||||||
|
}
|
||||||
|
|
||||||
const Utils = {
|
const Utils = {
|
||||||
joinPath: function() {
|
joinPath: function() {
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
@ -46,7 +51,8 @@ const Utils = {
|
|||||||
checkIsAvailable,
|
checkIsAvailable,
|
||||||
findNextPort,
|
findNextPort,
|
||||||
hashTo32ByteHexString,
|
hashTo32ByteHexString,
|
||||||
isHex
|
isHex,
|
||||||
|
soliditySha3
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Utils;
|
module.exports = Utils;
|
||||||
|
@ -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")) {
|
if (address.startsWith("0x")) {
|
||||||
address = address.slice(2);
|
address = address.slice(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
let node = utils.soliditySha3(address.toLowerCase() + reverseAddressSuffix);
|
let node = soliditySha3(address.toLowerCase() + reverseAddressSuffix);
|
||||||
|
|
||||||
function cb(err, name) {
|
function cb(err, name) {
|
||||||
if (err === NoDecodeStringErr || err === NoDecodeAddrErr) {
|
if (err === NoDecodeStringErr || err === NoDecodeAddrErr) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {joinPath, hashTo32ByteHexString} from 'embark-utils';
|
import {joinPath, hashTo32ByteHexString, soliditySha3} from 'embark-utils';
|
||||||
const utils = require('../../utils/utils.js');
|
const utils = require('../../utils/utils.js');
|
||||||
const namehash = require('eth-ens-namehash');
|
const namehash = require('eth-ens-namehash');
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
@ -287,7 +287,7 @@ class ENS {
|
|||||||
return callback(error);
|
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);
|
this.registerSubDomain(defaultAccount, subDomainName, reverseNode, address, secureSend, callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -338,7 +338,7 @@ class ENS {
|
|||||||
(req, res) => {
|
(req, res) => {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (callback) {
|
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) {
|
], function (error, name) {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -498,7 +498,7 @@ class ENS {
|
|||||||
const web3 = result[3];
|
const web3 = result[3];
|
||||||
|
|
||||||
const rootNode = namehash.hash(self.registration.rootDomain);
|
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();
|
const owner = await self.ensContract.methods.owner(rootNode).call();
|
||||||
|
|
||||||
if (owner === web3.eth.defaultAccount) {
|
if (owner === web3.eth.defaultAccount) {
|
||||||
|
@ -365,11 +365,6 @@ function sha512(arg) {
|
|||||||
return hash.update(arg).digest('hex');
|
return hash.update(arg).digest('hex');
|
||||||
}
|
}
|
||||||
|
|
||||||
function soliditySha3(arg) {
|
|
||||||
const Web3 = require('web3');
|
|
||||||
return Web3.utils.soliditySha3(arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeInput(input) {
|
function normalizeInput(input) {
|
||||||
if(typeof input === 'string') return input;
|
if(typeof input === 'string') return input;
|
||||||
let args = Object.values(input);
|
let args = Object.values(input);
|
||||||
@ -635,7 +630,6 @@ module.exports = {
|
|||||||
toChecksumAddress,
|
toChecksumAddress,
|
||||||
sha3,
|
sha3,
|
||||||
sha512,
|
sha512,
|
||||||
soliditySha3,
|
|
||||||
normalizeInput,
|
normalizeInput,
|
||||||
buildUrl,
|
buildUrl,
|
||||||
buildUrlFromConfig,
|
buildUrlFromConfig,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user