New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@libp2p/peer-store

Package Overview
Dependencies
Maintainers
0
Versions
683
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libp2p/peer-store - npm Package Compare versions

Comparing version 11.0.21-4939ef7ae to 11.0.21-52a46ecad

21

dist/src/utils/bytes-to-peer.js
import { publicKeyFromProtobuf } from '@libp2p/crypto/keys';
import { peerIdFromPublicKey } from '@libp2p/peer-id';
import { multiaddr } from '@multiformats/multiaddr';
import { base58btc } from 'multiformats/bases/base58';
import * as Digest from 'multiformats/hashes/digest';
import { Peer as PeerPB } from '../pb/peer.js';
function populatePublicKey(peerId, protobuf) {
if (peerId.publicKey != null || protobuf.publicKey == null) {
return peerId;
}
let digest;
if (peerId.type === 'RSA') {
// avoid hashing public key
const multihash = base58btc.decode(`z${peerId}`);
digest = Digest.decode(multihash);
}
const publicKey = publicKeyFromProtobuf(protobuf.publicKey, digest);
return peerIdFromPublicKey(publicKey);
}
export function bytesToPeer(peerId, buf) {
const peer = PeerPB.decode(buf);
if (peer.publicKey != null && peerId.publicKey == null) {
const publicKey = publicKeyFromProtobuf(peer.publicKey);
peerId = peerIdFromPublicKey(publicKey);
}
const tags = new Map();

@@ -22,3 +33,3 @@ // remove any expired tags

...peer,
id: peerId,
id: populatePublicKey(peerId, peer),
addresses: peer.addresses.map(({ multiaddr: ma, isCertified }) => {

@@ -25,0 +36,0 @@ return {

{
"name": "@libp2p/peer-store",
"version": "11.0.21-4939ef7ae",
"version": "11.0.21-52a46ecad",
"description": "Stores information about peers libp2p knows on the network",

@@ -31,3 +31,3 @@ "license": "Apache-2.0 OR MIT",

".": {
"types": "./src/index.d.ts",
"types": "./dist/src/index.d.ts",
"import": "./dist/src/index.js"

@@ -63,6 +63,6 @@ }

"dependencies": {
"@libp2p/crypto": "5.0.13-4939ef7ae",
"@libp2p/interface": "2.6.1-4939ef7ae",
"@libp2p/peer-id": "5.0.14-4939ef7ae",
"@libp2p/peer-record": "8.0.21-4939ef7ae",
"@libp2p/crypto": "5.0.13-52a46ecad",
"@libp2p/interface": "2.6.1-52a46ecad",
"@libp2p/peer-id": "5.0.14-52a46ecad",
"@libp2p/peer-record": "8.0.21-52a46ecad",
"@multiformats/multiaddr": "^12.3.3",

@@ -78,5 +78,6 @@ "interface-datastore": "^8.3.1",

"devDependencies": {
"@libp2p/logger": "5.1.10-4939ef7ae",
"@libp2p/logger": "5.1.10-52a46ecad",
"@types/sinon": "^17.0.3",
"aegir": "^45.1.1",
"benchmark": "^2.1.4",
"datastore-core": "^10.0.2",

@@ -83,0 +84,0 @@ "delay": "^6.0.0",

import { publicKeyFromProtobuf } from '@libp2p/crypto/keys'
import { peerIdFromPublicKey } from '@libp2p/peer-id'
import { multiaddr } from '@multiformats/multiaddr'
import { base58btc } from 'multiformats/bases/base58'
import * as Digest from 'multiformats/hashes/digest'
import { Peer as PeerPB } from '../pb/peer.js'
import type { PeerId, Peer, Tag } from '@libp2p/interface'
export function bytesToPeer (peerId: PeerId, buf: Uint8Array): Peer {
const peer = PeerPB.decode(buf)
function populatePublicKey (peerId: PeerId, protobuf: PeerPB): PeerId {
if (peerId.publicKey != null || protobuf.publicKey == null) {
return peerId
}
if (peer.publicKey != null && peerId.publicKey == null) {
const publicKey = publicKeyFromProtobuf(peer.publicKey)
peerId = peerIdFromPublicKey(publicKey)
let digest: any
if (peerId.type === 'RSA') {
// avoid hashing public key
const multihash = base58btc.decode(`z${peerId}`)
digest = Digest.decode(multihash)
}
const publicKey = publicKeyFromProtobuf(protobuf.publicKey, digest)
return peerIdFromPublicKey(publicKey)
}
export function bytesToPeer (peerId: PeerId, buf: Uint8Array): Peer {
const peer = PeerPB.decode(buf)
const tags = new Map<string, Tag>()

@@ -30,3 +43,3 @@

...peer,
id: peerId,
id: populatePublicKey(peerId, peer),
addresses: peer.addresses.map(({ multiaddr: ma, isCertified }) => {

@@ -33,0 +46,0 @@ return {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc