Socket
Socket
Sign inDemoInstall

peer-id

Package Overview
Dependencies
Maintainers
2
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

peer-id - npm Package Compare versions

Comparing version 0.13.13 to 0.14.0

17

CHANGELOG.md

@@ -0,1 +1,18 @@

<a name="0.14.0"></a>
# [0.14.0](https://github.com/libp2p/js-peer-id/compare/v0.13.13...v0.14.0) (2020-08-07)
### Bug Fixes
* replace node buffers with uint8arrays ([#127](https://github.com/libp2p/js-peer-id/issues/127)) ([d16ce9c](https://github.com/libp2p/js-peer-id/commit/d16ce9c))
### BREAKING CHANGES
* - Where node Buffers were returned, now Uint8Arrays are
* chore: remove gh dep
<a name="0.13.13"></a>

@@ -2,0 +19,0 @@ ## [0.13.13](https://github.com/libp2p/js-peer-id/compare/v0.13.12...v0.13.13) (2020-06-23)

27

package.json
{
"name": "peer-id",
"version": "0.13.13",
"version": "0.14.0",
"description": "IPFS Peer Id implementation in Node.js",

@@ -20,3 +20,3 @@ "leadMaintainer": "Vasco Santos <santos.vasco10@gmail.com>",

"coverage": "aegir coverage",
"size": "bundlesize -f dist/index.min.js -s 140kB"
"size": "aegir build -b"
},

@@ -42,16 +42,13 @@ "files": [

"@types/dirty-chai": "^2.0.2",
"@types/mocha": "^7.0.2",
"aegir": "^22.0.0",
"bundlesize": "~0.18.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1"
"@types/mocha": "^8.0.1",
"aegir": "^25.0.0"
},
"dependencies": {
"buffer": "^5.5.0",
"cids": "^0.8.0",
"cids": "^1.0.0",
"class-is": "^1.1.0",
"libp2p-crypto": "^0.17.7",
"libp2p-crypto": "^0.18.0",
"minimist": "^1.2.5",
"multihashes": "^1.0.1",
"protons": "^1.0.2"
"multihashes": "^3.0.1",
"protons": "^2.0.0",
"uint8arrays": "^1.1.0"
},

@@ -73,8 +70,7 @@ "repository": {

"Alex Potsides <alex@achingbrain.net>",
"Robert Kiel <robert.kiel@validitylabs.org>",
"Nate Foss <npfoss@gmail.com>",
"Robert Kiel <robert.kiel@validitylabs.org>",
"Michael Garvin <gar+gh@danger.computer>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
"Richard Littauer <richard.littauer@gmail.com>",
"Richard Schneider <makaretu@gmail.com>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
"Marcin Rataj <lidel@lidel.org>",

@@ -87,4 +83,5 @@ "Topper Bowers <topper@quorumcontrol.com>",

"Arve Knudsen <arve.knudsen@gmail.com>",
"Michael Garvin <gar+gh@danger.computer>",
"Prashanth Chandra <coolshanth94@gmail.com>"
]
}

@@ -1,2 +0,2 @@

import crypto, { PrivateKey, PublicKey, KeyType } from "libp2p-crypto";
import { PrivateKey, PublicKey, KeyType } from "libp2p-crypto";
import CID from 'cids'

@@ -54,3 +54,3 @@

function createFromHexString(str: string): PeerId;
/**

@@ -60,3 +60,3 @@ * Create PeerId from raw bytes.

*/
function createFromBytes(buf: Buffer): PeerId;
function createFromBytes(buf: Uint8Array): PeerId;

@@ -68,3 +68,3 @@ /**

function createFromB58String(str: string): PeerId;
/**

@@ -74,15 +74,15 @@ * Create PeerId from CID.

*/
function createFromCID(cid: CID | Buffer | string | object): PeerId;
function createFromCID(cid: CID | Uint8Array | string | object): PeerId;
/**
* Create PeerId from public key.
* @param key Public key, as Buffer or base64-encoded string.
* @param key Public key, as Uint8Array or base64-encoded string.
*/
function createFromPubKey(key: Buffer | string): Promise<PeerId>;
function createFromPubKey(key: Uint8Array | string): Promise<PeerId>;
/**
* Create PeerId from private key.
* @param key Private key, as Buffer or base64-encoded string.
* @param key Private key, as Uint8Array or base64-encoded string.
*/
function createFromPrivKey(key: Buffer | string): Promise<PeerId>;
function createFromPrivKey(key: Uint8Array | string): Promise<PeerId>;

@@ -98,5 +98,5 @@ /**

* Create PeerId from Protobuf bytes.
* @param buf Protobuf bytes, as Buffer or hex-encoded string.
* @param buf Protobuf bytes, as Uint8Array or hex-encoded string.
*/
function createFromProtobuf(buf: Buffer | string): Promise<PeerId>;
function createFromProtobuf(buf: Uint8Array | string): Promise<PeerId>;
}

@@ -108,3 +108,3 @@

declare class PeerId {
constructor(id: Buffer | string, privKey?: PrivateKey, pubKey?: PublicKey);
constructor(id: Uint8Array | string, privKey?: PrivateKey, pubKey?: PublicKey);

@@ -114,3 +114,3 @@ /**

*/
readonly id: Buffer;
readonly id: Uint8Array;

@@ -130,3 +130,3 @@ /**

*/
marshalPubKey(): Buffer;
marshalPubKey(): Uint8Array;

@@ -136,3 +136,3 @@ /**

*/
marshalPrivKey(): Buffer;
marshalPrivKey(): Uint8Array;

@@ -143,3 +143,3 @@ /**

*/
marshal(excludePriv?: boolean): Buffer;
marshal(excludePriv?: boolean): Uint8Array;

@@ -166,3 +166,3 @@ /**

*/
toBytes(): Buffer;
toBytes(): Uint8Array;

@@ -184,3 +184,3 @@ /**

*/
equals(id: PeerId | Buffer): boolean;
equals(id: PeerId | Uint8Array): boolean;

@@ -192,3 +192,3 @@ /**

*/
isEqual(id: PeerId | Buffer): boolean;
isEqual(id: PeerId | Uint8Array): boolean;

@@ -195,0 +195,0 @@ /**

@@ -7,3 +7,2 @@ /*

const { Buffer } = require('buffer')
const mh = require('multihashes')

@@ -14,10 +13,13 @@ const CID = require('cids')

const { PeerIdProto } = require('./proto')
const uint8ArrayEquals = require('uint8arrays/equals')
const uint8ArrayFromString = require('uint8arrays/from-string')
const uint8ArrayToString = require('uint8arrays/to-string')
class PeerId {
constructor (id, privKey, pubKey) {
if (!Buffer.isBuffer(id)) {
if (!(id instanceof Uint8Array)) {
throw new Error('invalid id provided')
}
if (privKey && pubKey && !privKey.public.bytes.equals(pubKey.bytes)) {
if (privKey && pubKey && !uint8ArrayEquals(privKey.public.bytes, pubKey.bytes)) {
throw new Error('inconsistent arguments')

@@ -147,10 +149,10 @@ }

* Checks the equality of `this` peer against a given PeerId.
* @param {Buffer|PeerId} id
* @param {Uint8Array|PeerId} id
* @returns {boolean}
*/
equals (id) {
if (Buffer.isBuffer(id)) {
return this.id.equals(id)
if (id instanceof Uint8Array) {
return uint8ArrayEquals(this.id, id)
} else if (id.id) {
return this.id.equals(id.id)
return uint8ArrayEquals(this.id, id.id)
} else {

@@ -164,3 +166,3 @@ throw new Error('not valid Id')

* @deprecated Use `.equals`
* @param {Buffer|PeerId} id
* @param {Uint8Array|PeerId} id
* @returns {boolean}

@@ -180,4 +182,4 @@ */

this.privKey.public.bytes &&
Buffer.isBuffer(this.pubKey.bytes) &&
this.privKey.public.bytes.equals(this.pubKey.bytes))
this.pubKey.bytes instanceof Uint8Array &&
uint8ArrayEquals(this.privKey.public.bytes, this.pubKey.bytes))
}

@@ -239,3 +241,3 @@ }

// Public Key input will be a buffer
// Public Key input will be a Uint8Array
exports.createFromPubKey = async (key) => {

@@ -245,7 +247,7 @@ let buf = key

if (typeof buf === 'string') {
buf = Buffer.from(key, 'base64')
buf = uint8ArrayFromString(key, 'base64pad')
}
if (!Buffer.isBuffer(buf)) {
throw new Error('Supplied key is neither a base64 string nor a buffer')
if (!(buf instanceof Uint8Array)) {
throw new Error('Supplied key is neither a base64 string nor a Uint8Array')
}

@@ -259,13 +261,11 @@

exports.createFromPrivKey = async (key) => {
let buf = key
if (typeof buf === 'string') {
buf = Buffer.from(key, 'base64')
if (typeof key === 'string') {
key = uint8ArrayFromString(key, 'base64pad')
}
if (!Buffer.isBuffer(buf)) {
throw new Error('Supplied key is neither a base64 string nor a buffer')
if (!(key instanceof Uint8Array)) {
throw new Error('Supplied key is neither a base64 string nor a Uint8Array')
}
const privKey = await cryptoKeys.unmarshalPrivateKey(buf)
const privKey = await cryptoKeys.unmarshalPrivateKey(key)
return computePeerId(privKey, privKey.public)

@@ -276,4 +276,4 @@ }

const id = mh.fromB58String(obj.id)
const rawPrivKey = obj.privKey && Buffer.from(obj.privKey, 'base64')
const rawPubKey = obj.pubKey && Buffer.from(obj.pubKey, 'base64')
const rawPrivKey = obj.privKey && uint8ArrayFromString(obj.privKey, 'base64pad')
const rawPubKey = obj.pubKey && uint8ArrayFromString(obj.pubKey, 'base64pad')
const pub = rawPubKey && await cryptoKeys.unmarshalPublicKey(rawPubKey)

@@ -294,7 +294,7 @@

if (pub && !privDigest.equals(pubDigest)) {
if (pub && !uint8ArrayEquals(privDigest, pubDigest)) {
throw new Error('Public and private key do not match')
}
if (id && !privDigest.equals(id)) {
if (id && !uint8ArrayEquals(privDigest, id)) {
throw new Error('Id and private key do not match')

@@ -308,3 +308,3 @@ }

if (typeof buf === 'string') {
buf = Buffer.from(buf, 'hex')
buf = uint8ArrayFromString(buf, 'base16')
}

@@ -330,3 +330,3 @@

if (pubKey) {
if (!privDigest.equals(pubDigest)) {
if (!uint8ArrayEquals(privDigest, pubDigest)) {
throw new Error('Public and private key do not match')

@@ -359,4 +359,4 @@ }

if (val) {
return val.toString('base64')
return uint8ArrayToString(val, 'base64pad')
}
}

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

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