mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-16 23:57:11 +00:00
refactor (@embark/embark-utils): move hashTo32ByteHexStrin to embark-utils
This commit is contained in:
parent
47ba899c85
commit
7511e3c113
@ -46,7 +46,8 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime-corejs2": "7.3.1",
|
||||
"follow-redirects": "1.5.7"
|
||||
"follow-redirects": "1.5.7",
|
||||
"multihashes": "0.4.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.2.3",
|
||||
|
@ -15,6 +15,24 @@ function checkIsAvailable(url, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function isHex(hex) {
|
||||
const Web3 = require('web3');
|
||||
return Web3.utils.isHex(hex);
|
||||
}
|
||||
|
||||
function hashTo32ByteHexString(hash) {
|
||||
if (isHex(hash)) {
|
||||
if (!hash.startsWith('0x')) {
|
||||
hash = '0x' + hash;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
const multihash = require('multihashes');
|
||||
let buf = multihash.fromB58String(hash);
|
||||
let digest = multihash.decode(buf).digest;
|
||||
return '0x' + multihash.toHexString(digest);
|
||||
}
|
||||
|
||||
const Utils = {
|
||||
joinPath: function() {
|
||||
const path = require('path');
|
||||
@ -26,7 +44,9 @@ const Utils = {
|
||||
dockerHostSwap,
|
||||
isDocker,
|
||||
checkIsAvailable,
|
||||
findNextPort
|
||||
findNextPort,
|
||||
hashTo32ByteHexString,
|
||||
isHex
|
||||
};
|
||||
|
||||
module.exports = Utils;
|
||||
|
@ -125,7 +125,6 @@
|
||||
"lodash.clonedeep": "4.5.0",
|
||||
"merge": "1.2.1",
|
||||
"mocha": "5.2.0",
|
||||
"multihashes": "0.4.14",
|
||||
"neo-blessed": "0.2.0",
|
||||
"netcat": "1.3.5",
|
||||
"node-http-proxy-json": "0.1.6",
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {joinPath} from 'embark-utils';
|
||||
import {joinPath, hashTo32ByteHexString} from 'embark-utils';
|
||||
const utils = require('../../utils/utils.js');
|
||||
const namehash = require('eth-ens-namehash');
|
||||
const async = require('async');
|
||||
@ -184,7 +184,7 @@ class ENS {
|
||||
let hashedName = namehash.hash(name);
|
||||
let contentHash;
|
||||
try {
|
||||
contentHash = utils.hashTo32ByteHexString(storageHash);
|
||||
contentHash = hashTo32ByteHexString(storageHash);
|
||||
} catch (e) {
|
||||
return cb(__('Invalid IPFS hash'));
|
||||
}
|
||||
|
@ -320,24 +320,6 @@ function hexToNumber(hex) {
|
||||
return Web3.utils.hexToNumber(hex);
|
||||
}
|
||||
|
||||
function isHex(hex) {
|
||||
const Web3 = require('web3');
|
||||
return Web3.utils.isHex(hex);
|
||||
}
|
||||
|
||||
function hashTo32ByteHexString(hash) {
|
||||
if (isHex(hash)) {
|
||||
if (!hash.startsWith('0x')) {
|
||||
hash = '0x' + hash;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
const multihash = require('multihashes');
|
||||
let buf = multihash.fromB58String(hash);
|
||||
let digest = multihash.decode(buf).digest;
|
||||
return '0x' + multihash.toHexString(digest);
|
||||
}
|
||||
|
||||
function isValidDomain(v) {
|
||||
// from: https://github.com/miguelmota/is-valid-domain
|
||||
if (typeof v !== 'string') return false;
|
||||
@ -638,8 +620,6 @@ module.exports = {
|
||||
httpsGetJson,
|
||||
getJson,
|
||||
hexToNumber,
|
||||
isHex,
|
||||
hashTo32ByteHexString,
|
||||
isValidDomain,
|
||||
pingEndpoint,
|
||||
decodeParams,
|
||||
|
Loading…
x
Reference in New Issue
Block a user