diff --git a/Gruntfile.js b/Gruntfile.js index 12a980e3..9cd136bb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -51,7 +51,7 @@ module.exports = function(grunt) { standalone: 'openpgp' }, // Don't bundle these packages with openpgp.js - external: ['crypto', 'buffer', 'node-localstorage', 'node-fetch', 'asn1.js', 'jwk-to-pem'], + external: ['crypto', 'node-localstorage', 'node-fetch', 'asn1.js', 'jwk-to-pem'], transform: [ ["babelify", { plugins: ["transform-async-to-generator", @@ -74,7 +74,7 @@ module.exports = function(grunt) { debug: true, standalone: 'openpgp' }, - external: ['crypto', 'buffer', 'node-localstorage', 'node-fetch', 'asn1.js', 'jwk-to-pem'], + external: ['crypto', 'node-localstorage', 'node-fetch', 'asn1.js', 'jwk-to-pem'], transform: [ ["babelify", { plugins: ["transform-async-to-generator", diff --git a/src/crypto/hash/index.js b/src/crypto/hash/index.js index 11e2f391..03454e0e 100644 --- a/src/crypto/hash/index.js +++ b/src/crypto/hash/index.js @@ -59,7 +59,9 @@ if(nodeCrypto) { // Use Node native crypto for all hash functions sha512: sha.sha512, /** @see module:ripemd160 */ ripemd: function(data) { - return util.str2Uint8Array(util.hex2bin(new RIPEMD160.update(data).digest('hex'))); + // Convert Uint8Array to buffer + data = require('buffer').Buffer.from(data.buffer); + return util.str2Uint8Array(util.hex2bin(new RIPEMD160().update(data).digest('hex'))); } }; } diff --git a/src/util.js b/src/util.js index 89afff54..4b3f977c 100644 --- a/src/util.js +++ b/src/util.js @@ -585,7 +585,10 @@ export default { return; } - return require('buffer').Buffer; + // This "hack" allows us to access the native node buffer module. + // otherwise, it gets replaced with the browserified version + // eslint-disable-next-line no-useless-concat, import/no-dynamic-require + return require('buf'+'fer').Buffer; } };