This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
Uncaught TypeError: crypto.createHash is not a function #270
Copy link
Copy link
Closed
Labels
kind/bugA bug in existing code (including security flaws)A bug in existing code (including security flaws)
Description
When performing and object.get command in the browser...
Uncaught TypeError: crypto.createHash is not a function ....is thrown by
function gsha2_256() {
return crypto.createHash('sha256');
}
in from the webpacked dist of ipfs
function(module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(Buffer) {'use strict';
var multihash = __webpack_require__(121);
var crypto = __webpack_require__(747);
var mh = module.exports = Multihashing;
mh.Buffer = Buffer; // for browser things
function Multihashing(buf, func, length) {
return multihash.encode(mh.digest(buf, func, length), func, length);
}
// expose multihash itself, to avoid silly double requires.
mh.multihash = multihash;
mh.digest = function (buf, func, length) {
var digest = mh.createHash(func).update(buf).digest();
if (length) {
digest = digest.slice(0, length);
}
return digest;
};
mh.createHash = function (func, length) {
func = multihash.coerceCode(func);
if (!mh.functions[func]) {
throw new Error('multihash function ' + func + ' not yet supported');
}
return mh.functions[func]();
};
var self= this
mh.functions = {
0x11: gsha1.bind(self),
0x12: gsha2_256.bind(self),
0x13: gsha2_512.bind(self)
// 0x14: gsha3 // not implemented yet
// 0x40: blake2b, // not implemented yet
// 0x40: blake2b, // not implemented yet
// 0x41: blake2s, // not implemented yet
};
function gsha1() {
return crypto.createHash('sha1');
}
function gsha2_256() {
return crypto.createHash('sha256');
}
function gsha2_512() {
return crypto.createHash('sha512');
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0).Buffer))
I'm not sure what module this is but it seems the crypto module never makes it into the code it instead sees window.crypto.
isaackwan, owaisugh75 and samuelscheit
Metadata
Metadata
Assignees
Labels
kind/bugA bug in existing code (including security flaws)A bug in existing code (including security flaws)