Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
chore: apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Jacob Heun <[email protected]>
  • Loading branch information
vasco-santos and jacobheun authored Aug 21, 2020
1 parent f209d04 commit 9c7dd34
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"it-pair": "^1.0.0",
"it-pipe": "^1.1.0",
"it-pushable": "^1.4.0",
"libp2p-crypto": "^0.17.9",
"libp2p-crypto": "^0.18.0",
"libp2p-tcp": "^0.15.0",
"multiaddr": "^8.0.0",
"multibase": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/pubsub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Publish data message to pubsub topics.

| Name | Type | Description |
|------|------|-------------|
| topics | `string` | pubsub topic |
| topic | `string` | pubsub topic |
| message | `Uint8Array` | message to publish |

##### Returns
Expand Down
2 changes: 1 addition & 1 deletion src/pubsub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class PubsubBaseProtocol extends EventEmitter {
}

/**
* Handles an subscription change from a peer
* Handles a subscription change from a peer
* @param {string} id
* @param {RPC.SubOpt} subOpt
*/
Expand Down
7 changes: 1 addition & 6 deletions src/pubsub/message/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@ async function verifySignature (message) {
*/
async function messagePublicKey (message) {
// should be available in the from property of the message (peer id)
let from
if (typeof message.from === 'string') {
from = PeerId.createFromB58String(message.from)
} else {
from = PeerId.createFromBytes(message.from)
}
const from = PeerId.createFromCID(message.from)

if (message.key) {
const keyPeerId = await PeerId.createFromPubKey(message.key)
Expand Down
3 changes: 1 addition & 2 deletions src/pubsub/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const crypto = require('libp2p-crypto')
const multibase = require('multibase')
const uint8ArrayToString = require('uint8arrays/to-string')
const uint8ArrayFromString = require('uint8arrays/from-string')

Expand Down Expand Up @@ -91,7 +90,7 @@ exports.normalizeInRpcMessage = (message, peerId) => {
exports.normalizeOutRpcMessage = (message) => {
const m = Object.assign({}, message)
if (typeof message.from === 'string' || message.from instanceof String) {
m.from = multibase.decode('z' + message.from)
m.from = uint8ArrayFromString(message.from, 'base58btc')
}
if (typeof message.data === 'string' || message.data instanceof String) {
m.data = uint8ArrayFromString(message.data)
Expand Down

0 comments on commit 9c7dd34

Please sign in to comment.