diff --git a/karma.conf.js b/karma.conf.js index 9384668107..cfd13a8e7d 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,9 +1,13 @@ module.exports = function (config) { + var path = require('path') + var nodeForgePath = path.resolve(__dirname, 'node_modules/peer-id/deps/forge.bundle.js') + config.set({ basePath: '', frameworks: ['mocha'], files: [ + nodeForgePath, 'tests/test-core/browser.js' ], @@ -16,7 +20,8 @@ module.exports = function (config) { extensions: ['', '.js', '.json'] }, externals: { - fs: '{}' + fs: '{}', + 'node-forge': 'forge' }, node: { Buffer: true diff --git a/package.json b/package.json index 100790e6db..1b8eb6de43 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "brfs": "^1.4.3", "buffer-loader": "0.0.1", "chai": "^3.4.1", + "expose-loader": "^0.7.1", "fs-blob-store": "^5.2.1", "idb-plus-blob-store": "^1.0.0", "istanbul": "^0.4.1", @@ -58,7 +59,7 @@ "rimraf": "^2.4.4", "standard": "^5.4.1", "transform-loader": "^0.2.3", - "webpack": "^2.0.5-beta" + "webpack": "^2.0.7-beta" }, "dependencies": { "bl": "^1.0.0", @@ -71,6 +72,7 @@ "ipfs-repo": "^0.5.0", "lodash.get": "^4.0.0", "lodash.set": "^4.0.0", + "peer-id": "^0.5.0", "ronin": "^0.3.11" } } diff --git a/src/ipfs-core/index.js b/src/ipfs-core/index.js index 9d131a5850..af726b4fdb 100644 --- a/src/ipfs-core/index.js +++ b/src/ipfs-core/index.js @@ -8,6 +8,7 @@ const Block = blocks.Block const mDAG = require('ipfs-merkle-dag') const DAGNode = mDAG.DAGNode const DAGService = mDAG.DAGService +const peerId = require('peer-id') exports = module.exports = IPFS @@ -55,10 +56,10 @@ function IPFS (repo) { if (err) { return callback(err) } + var pid = peerId.createFromPrivKey(config.Identity.PrivKey) callback(null, { ID: config.Identity.PeerID, - // TODO needs https://github.com/diasdavid/js-peer-id/blob/master/src/index.js#L76 - PublicKey: '', + PublicKey: pid.pubKey, Addresses: config.Addresses, AgentVersion: 'js-ipfs', ProtocolVersion: '9000' diff --git a/tests/test-api/test-id.js b/tests/test-api/test-id.js index aff4f828da..1caa77c19f 100644 --- a/tests/test-api/test-id.js +++ b/tests/test-api/test-id.js @@ -12,7 +12,7 @@ describe('id', function () { url: '/api/v0/id' }, res => { expect(res.result).to.deep.equal({ ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A', - PublicKey: '', + PublicKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=', Addresses: { Swarm: [ '/ip4/0.0.0.0/tcp/4001', '/ip6/::/tcp/4001' ], API: '/ip4/127.0.0.1/tcp/5001', Gateway: '/ip4/127.0.0.1/tcp/8080' }, diff --git a/tests/test-cli-offline/test-id.js b/tests/test-cli-offline/test-id.js index 83c1c7d960..0ccee5728d 100644 --- a/tests/test-cli-offline/test-id.js +++ b/tests/test-cli-offline/test-id.js @@ -10,7 +10,7 @@ describe('id', () => { nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'id']) .run((err, stdout, exitcode) => { var expected = [ "{ ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A',", - " PublicKey: '',", + " PublicKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=',", ' Addresses: ', " { Swarm: [ '/ip4/0.0.0.0/tcp/4001', '/ip6/::/tcp/4001' ],", " API: '/ip4/127.0.0.1/tcp/5001',", diff --git a/tests/test-cli/test-id.js b/tests/test-cli/test-id.js index 83c1c7d960..0ccee5728d 100644 --- a/tests/test-cli/test-id.js +++ b/tests/test-cli/test-id.js @@ -10,7 +10,7 @@ describe('id', () => { nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'id']) .run((err, stdout, exitcode) => { var expected = [ "{ ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A',", - " PublicKey: '',", + " PublicKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=',", ' Addresses: ', " { Swarm: [ '/ip4/0.0.0.0/tcp/4001', '/ip6/::/tcp/4001' ],", " API: '/ip4/127.0.0.1/tcp/5001',", diff --git a/tests/test-core/browser.js b/tests/test-core/browser.js index 90f8b73e24..fa9a4ca696 100644 --- a/tests/test-core/browser.js +++ b/tests/test-core/browser.js @@ -15,6 +15,7 @@ idb.deleteDatabase('ipfs') idb.deleteDatabase('ipfs/blocks') describe('IPFS Repo Tests on the Browser', function () { + this.timeout(10000) before(function (done) { var repoData = [] repoContext.keys().forEach(function (key) { @@ -34,7 +35,6 @@ describe('IPFS Repo Tests on the Browser', function () { const blocks = _.startsWith(file.key, 'blocks/') const blob = blocks ? blocksBlob : mainBlob - const key = blocks ? file.key.replace(/^blocks\//, '') : file.key blob.createWriteStream({ diff --git a/tests/test-core/test-id.js b/tests/test-core/test-id.js index 44fc5456cb..421f2db268 100644 --- a/tests/test-core/test-id.js +++ b/tests/test-core/test-id.js @@ -13,7 +13,7 @@ describe('id', () => { ipfs.id((err, id) => { expect(err).to.not.exist expect(id).to.deep.equal({ ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A', - PublicKey: '', + PublicKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=', Addresses: { Swarm: [ '/ip4/0.0.0.0/tcp/4001', '/ip6/::/tcp/4001' ], API: '/ip4/127.0.0.1/tcp/5001', Gateway: '/ip4/127.0.0.1/tcp/8080' },