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

fix: human readable peer ids in console.log #36

Merged
merged 1 commit into from
Dec 8, 2022

Conversation

achingbrain
Copy link
Member

Add inspect method so when printing PeerIds in the console they are readable, similar to CIDs and Multiaddrs.

Old:

{
  peer: RSAPeerIdImpl [PeerId(QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN)] {
    type: 'RSA',
    multihash: Digest {
      code: 18,
      size: 32,
      digest: [Uint8Array],
      bytes: [Uint8Array]
    },
    privateKey: undefined,
    publicKey: <Buffer 08 00 12 a6 02 30 82 01 22 30 0d 06 09 2a 86 48 86 f7 0d 01 01 01 05 00 03 82 01 0f 00 30 82 01 0a 02 82 01 01 00 d7 ab 01 ee 41 35 d7 ce cd 99 63 5b ... 249 more
bytes>
  },
  name: 'DIALING_PEER',
  type: 7
}
{
  to: RSAPeerIdImpl [PeerId(QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN)] {
    type: 'RSA',
    multihash: Digest {
      code: 18,
      size: 32,
      digest: [Uint8Array],
      bytes: [Uint8Array]
    },
    privateKey: undefined,
    publicKey: <Buffer 08 00 12 a6 02 30 82 01 22 30 0d 06 09 2a 86 48 86 f7 0d 01 01 01 05 00 03 82 01 0f 00 30 82 01 0a 02 82 01 01 00 d7 ab 01 ee 41 35 d7 ce cd 99 63 5b ... 249 more
bytes>
  },
  type: 0,
  name: 'SENDING_QUERY',
  messageName: 'ADD_PROVIDER',
  messageType: 2
}
{
  from: RSAPeerIdImpl [PeerId(QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN)] {
    type: 'RSA',
    multihash: Digest {
      code: 18,
      size: 32,
      digest: [Uint8Array],
      bytes: [Uint8Array]
    },
    privateKey: undefined,
    publicKey: <Buffer 08 00 12 a6 02 30 82 01 22 30 0d 06 09 2a 86 48 86 f7 0d 01 01 01 05 00 03 82 01 0f 00 30 82 01 0a 02 82 01 01 00 d7 ab 01 ee 41 35 d7 ce cd 99 63 5b ... 249 more
bytes>
  },
  messageType: 'ADD_PROVIDER',
  name: 'PEER_RESPONSE',
  type: 1,
  messageName: 'ADD_PROVIDER',
  closer: [],
  providers: []
}

New:

{
  peer: PeerId(QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt),
  name: 'DIALING_PEER',
  type: 7
}
{
  to: PeerId(QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt),
  type: 0,
  name: 'SENDING_QUERY',
  messageName: 'ADD_PROVIDER',
  messageType: 2
}
{
  from: PeerId(QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt),
  messageType: 'ADD_PROVIDER',
  name: 'PEER_RESPONSE',
  type: 1,
  messageName: 'ADD_PROVIDER',
  closer: [],
  providers: []
}

Add [inspect](https://nodejs.org/api/util.html#utilinspectcustom) method
so when printing PeerIds in the console they are readble.

Old:

```
{
  peer: RSAPeerIdImpl [PeerId(QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN)] {
    type: 'RSA',
    multihash: Digest {
      code: 18,
      size: 32,
      digest: [Uint8Array],
      bytes: [Uint8Array]
    },
    privateKey: undefined,
    publicKey: <Buffer 08 00 12 a6 02 30 82 01 22 30 0d 06 09 2a 86 48 86 f7 0d 01 01 01 05 00 03 82 01 0f 00 30 82 01 0a 02 82 01 01 00 d7 ab 01 ee 41 35 d7 ce cd 99 63 5b ... 249 more
bytes>
  },
  name: 'DIALING_PEER',
  type: 7
}
{
  to: RSAPeerIdImpl [PeerId(QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN)] {
    type: 'RSA',
    multihash: Digest {
      code: 18,
      size: 32,
      digest: [Uint8Array],
      bytes: [Uint8Array]
    },
    privateKey: undefined,
    publicKey: <Buffer 08 00 12 a6 02 30 82 01 22 30 0d 06 09 2a 86 48 86 f7 0d 01 01 01 05 00 03 82 01 0f 00 30 82 01 0a 02 82 01 01 00 d7 ab 01 ee 41 35 d7 ce cd 99 63 5b ... 249 more
bytes>
  },
  type: 0,
  name: 'SENDING_QUERY',
  messageName: 'ADD_PROVIDER',
  messageType: 2
}
{
  from: RSAPeerIdImpl [PeerId(QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN)] {
    type: 'RSA',
    multihash: Digest {
      code: 18,
      size: 32,
      digest: [Uint8Array],
      bytes: [Uint8Array]
    },
    privateKey: undefined,
    publicKey: <Buffer 08 00 12 a6 02 30 82 01 22 30 0d 06 09 2a 86 48 86 f7 0d 01 01 01 05 00 03 82 01 0f 00 30 82 01 0a 02 82 01 01 00 d7 ab 01 ee 41 35 d7 ce cd 99 63 5b ... 249 more
bytes>
  },
  messageType: 'ADD_PROVIDER',
  name: 'PEER_RESPONSE',
  type: 1,
  messageName: 'ADD_PROVIDER',
  closer: [],
  providers: []
}
```

New:

```
{
  peer: PeerId(QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt),
  name: 'DIALING_PEER',
  type: 7
}
{
  to: PeerId(QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt),
  type: 0,
  name: 'SENDING_QUERY',
  messageName: 'ADD_PROVIDER',
  messageType: 2
}
{
  from: PeerId(QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt),
  messageType: 'ADD_PROVIDER',
  name: 'PEER_RESPONSE',
  type: 1,
  messageName: 'ADD_PROVIDER',
  closer: [],
  providers: []
}
```
@achingbrain achingbrain merged commit f80d1ea into master Dec 8, 2022
@achingbrain achingbrain deleted the feat/human-readable-inspect branch December 8, 2022 08:11
github-actions bot pushed a commit that referenced this pull request Dec 8, 2022
## [@libp2p/peer-id-v1.1.17](https://github.com/libp2p/js-libp2p-peer-id/compare/@libp2p/peer-id-v1.1.16...@libp2p/peer-id-v1.1.17) (2022-12-08)

### Bug Fixes

* human readable peer ids in console.log ([#36](#36)) ([f80d1ea](f80d1ea))

### Trivial Changes

* fix peer-d typo in readmes ([#31](#31)) ([2276076](2276076))
@github-actions
Copy link

github-actions bot commented Dec 8, 2022

🎉 This PR is included in version @libp2p/peer-id-v1.1.17 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant