mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-20 01:18:52 +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": {
|
"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"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "7.2.3",
|
"@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 = {
|
const Utils = {
|
||||||
joinPath: function() {
|
joinPath: function() {
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
@ -26,7 +44,9 @@ const Utils = {
|
|||||||
dockerHostSwap,
|
dockerHostSwap,
|
||||||
isDocker,
|
isDocker,
|
||||||
checkIsAvailable,
|
checkIsAvailable,
|
||||||
findNextPort
|
findNextPort,
|
||||||
|
hashTo32ByteHexString,
|
||||||
|
isHex
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Utils;
|
module.exports = Utils;
|
||||||
|
@ -125,7 +125,6 @@
|
|||||||
"lodash.clonedeep": "4.5.0",
|
"lodash.clonedeep": "4.5.0",
|
||||||
"merge": "1.2.1",
|
"merge": "1.2.1",
|
||||||
"mocha": "5.2.0",
|
"mocha": "5.2.0",
|
||||||
"multihashes": "0.4.14",
|
|
||||||
"neo-blessed": "0.2.0",
|
"neo-blessed": "0.2.0",
|
||||||
"netcat": "1.3.5",
|
"netcat": "1.3.5",
|
||||||
"node-http-proxy-json": "0.1.6",
|
"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 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');
|
||||||
@ -184,7 +184,7 @@ class ENS {
|
|||||||
let hashedName = namehash.hash(name);
|
let hashedName = namehash.hash(name);
|
||||||
let contentHash;
|
let contentHash;
|
||||||
try {
|
try {
|
||||||
contentHash = utils.hashTo32ByteHexString(storageHash);
|
contentHash = hashTo32ByteHexString(storageHash);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return cb(__('Invalid IPFS hash'));
|
return cb(__('Invalid IPFS hash'));
|
||||||
}
|
}
|
||||||
|
@ -320,24 +320,6 @@ function hexToNumber(hex) {
|
|||||||
return Web3.utils.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) {
|
function isValidDomain(v) {
|
||||||
// from: https://github.com/miguelmota/is-valid-domain
|
// from: https://github.com/miguelmota/is-valid-domain
|
||||||
if (typeof v !== 'string') return false;
|
if (typeof v !== 'string') return false;
|
||||||
@ -638,8 +620,6 @@ module.exports = {
|
|||||||
httpsGetJson,
|
httpsGetJson,
|
||||||
getJson,
|
getJson,
|
||||||
hexToNumber,
|
hexToNumber,
|
||||||
isHex,
|
|
||||||
hashTo32ByteHexString,
|
|
||||||
isValidDomain,
|
isValidDomain,
|
||||||
pingEndpoint,
|
pingEndpoint,
|
||||||
decodeParams,
|
decodeParams,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user