diff --git a/Gruntfile.js b/Gruntfile.js index 8a8a73ca..3f7043d4 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -18,7 +18,7 @@ module.exports = function(grunt) { browserifyOptions: { standalone: 'openpgp' }, - external: [ 'crypto', 'node-localstorage' ] + external: [ 'crypto', 'node-localstorage', 'node-fetch' ] } }, openpgp_debug: { @@ -30,7 +30,7 @@ module.exports = function(grunt) { debug: true, standalone: 'openpgp' }, - external: [ 'crypto', 'node-localstorage' ] + external: [ 'crypto', 'node-localstorage', 'node-fetch' ] } }, worker: { @@ -48,7 +48,7 @@ module.exports = function(grunt) { 'test/lib/unittests-bundle.js': [ './test/unittests.js' ] }, options: { - external: ['crypto', 'node-localstorage', 'openpgp', '../../../dist/openpgp', '../../dist/openpgp'] + external: [ 'crypto', 'node-localstorage', 'node-fetch', 'openpgp', '../../dist/openpgp', '../../../dist/openpgp' ] } } }, diff --git a/src/hkp/hkp.js b/src/hkp/hkp.js index fd764fe0..01063ec7 100644 --- a/src/hkp/hkp.js +++ b/src/hkp/hkp.js @@ -31,14 +31,10 @@ var config = require('../config'); * @constructor * @param {String} keyServerBaseUrl (optional) The HKP key server base url including * the protocol to use e.g. https://pgp.mit.edu - * @param {function} fetch (optional) The fetch function is an easier way - * to make web requests and handle responses than using an XMLHttpRequest. You can - * pass in a custom implementaion or just leave the parameter empty to fall back to - * window.fetch (https://fetch.spec.whatwg.org). */ -function HKP(keyServerBaseUrl, fetch) { +function HKP(keyServerBaseUrl) { this._baseUrl = keyServerBaseUrl ? keyServerBaseUrl : config.keyserver; - this._fetch = fetch ? fetch : typeof window !== 'undefined' && window.fetch; + this._fetch = typeof window !== 'undefined' ? window.fetch : require('node-fetch'); } /** diff --git a/test/general/hkp.js b/test/general/hkp.js index 568e4a89..d1f9549e 100644 --- a/test/general/hkp.js +++ b/test/general/hkp.js @@ -1,7 +1,6 @@ 'use strict'; var openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp'); -var fetch = typeof window !== 'undefined' ? window.fetch : require('node-fetch'); var chai = require('chai'), expect = chai.expect; @@ -108,7 +107,7 @@ describe('HKP unit tests', function() { '-----END PGP PUBLIC KEY BLOCK-----'; beforeEach(function() { - hkp = new openpgp.HKP(openpgp.config.keyserver, fetch); + hkp = new openpgp.HKP(openpgp.config.keyserver); }); afterEach(function() {});