From 636041badcfd2fb19967a755e5e30bf6c8b87a4b Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 23 Apr 2020 13:41:03 +0100 Subject: [PATCH] fix: remove node globals (#42) Related to https://github.com/ipfs/js-ipfs/issues/2924 --- package.json | 2 +- src/message/sign.js | 2 +- src/utils.js | 7 ++++--- test/sign.spec.js | 1 + test/utils.spec.js | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 0a07976ad0..9eb64300a4 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,6 @@ "sinon": "^9.0.0" }, "dependencies": { - "bs58": "^4.0.1", "debug": "^4.1.1", "err-code": "^2.0.0", "it-length-prefixed": "^3.0.0", @@ -60,6 +59,7 @@ "it-pushable": "^1.3.2", "libp2p-crypto": "~0.17.0", "libp2p-interfaces": "^0.3.0", + "multibase": "^0.7.0", "peer-id": "~0.13.3", "protons": "^1.0.1" }, diff --git a/src/message/sign.js b/src/message/sign.js index 1ccf1183fb..bfa546db24 100644 --- a/src/message/sign.js +++ b/src/message/sign.js @@ -1,5 +1,5 @@ 'use strict' - +const { Buffer } = require('buffer') const PeerId = require('peer-id') const { Message } = require('./index') const SignPrefix = Buffer.from('libp2p-pubsub:') diff --git a/src/utils.js b/src/utils.js index 17cd172381..f20efb9102 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,7 +1,8 @@ 'use strict' +const { Buffer } = require('buffer') const crypto = require('libp2p-crypto') -const bs58 = require('bs58') +const multibase = require('multibase') exports = module.exports @@ -77,7 +78,7 @@ exports.ensureArray = (maybeArray) => { exports.normalizeInRpcMessage = (message) => { const m = Object.assign({}, message) if (Buffer.isBuffer(message.from)) { - m.from = bs58.encode(message.from) + m.from = multibase.encode('base58btc', message.from).toString().slice(1) } return m } @@ -97,7 +98,7 @@ exports.normalizeInRpcMessages = (messages) => { exports.normalizeOutRpcMessage = (message) => { const m = Object.assign({}, message) if (typeof message.from === 'string' || message.from instanceof String) { - m.from = bs58.decode(message.from) + m.from = multibase.decode('z' + message.from) } return m } diff --git a/test/sign.spec.js b/test/sign.spec.js index 573aac006d..c40d16adc4 100644 --- a/test/sign.spec.js +++ b/test/sign.spec.js @@ -2,6 +2,7 @@ /* eslint max-nested-callbacks: ["error", 5] */ 'use strict' +const { Buffer } = require('buffer') const chai = require('chai') chai.use(require('dirty-chai')) const expect = chai.expect diff --git a/test/utils.spec.js b/test/utils.spec.js index f924884080..17ee6116db 100644 --- a/test/utils.spec.js +++ b/test/utils.spec.js @@ -2,7 +2,7 @@ 'use strict' const { expect } = require('chai') - +const { Buffer } = require('buffer') const utils = require('../src/utils') describe('utils', () => {