@libp2p/peer-id
Advanced tools
Comparing version 1.1.16 to 1.1.17
import { CID } from 'multiformats/cid'; | ||
import { symbol } from '@libp2p/interface-peer-id'; | ||
import { PeerIdType } from '@libp2p/interface-peer-id'; | ||
import type { MultibaseDecoder } from 'multiformats/bases/interface'; | ||
@@ -7,28 +7,7 @@ import type { MultihashDigest } from 'multiformats/hashes/interface'; | ||
interface PeerIdInit { | ||
type: 'RSA' | 'Ed25519' | 'secp256k1'; | ||
type: PeerIdType; | ||
multihash: MultihashDigest; | ||
privateKey?: Uint8Array; | ||
} | ||
declare class PeerIdImpl { | ||
type: 'RSA' | 'Ed25519' | 'secp256k1'; | ||
readonly multihash: MultihashDigest; | ||
readonly privateKey?: Uint8Array; | ||
readonly publicKey?: Uint8Array; | ||
private string?; | ||
constructor(init: PeerIdInit); | ||
get [Symbol.toStringTag](): string; | ||
get [symbol](): boolean; | ||
toString(): string; | ||
toCID(): CID<unknown, 114, number, 1>; | ||
toBytes(): Uint8Array; | ||
/** | ||
* Returns Multiaddr as a JSON encoded object | ||
*/ | ||
toJSON(): string; | ||
/** | ||
* Checks the equality of `this` peer against a given PeerId | ||
*/ | ||
equals(id: PeerId | Uint8Array | string): boolean; | ||
} | ||
export declare function createPeerId(init: PeerIdInit): PeerIdImpl; | ||
export declare function createPeerId(init: PeerIdInit): PeerId; | ||
export declare function peerIdFromPeerId(other: any): PeerId; | ||
@@ -35,0 +14,0 @@ export declare function peerIdFromString(str: string, decoder?: MultibaseDecoder<any>): PeerId; |
@@ -10,2 +10,3 @@ import { CID } from 'multiformats/cid'; | ||
import { symbol } from '@libp2p/interface-peer-id'; | ||
const inspect = Symbol.for('nodejs.util.inspect.custom'); | ||
const baseDecoder = Object | ||
@@ -74,2 +75,17 @@ .values(bases) | ||
} | ||
/** | ||
* Returns PeerId as a human-readable string | ||
* https://nodejs.org/api/util.html#utilinspectcustom | ||
* | ||
* @example | ||
* ```js | ||
* import { peerIdFromString } from '@libp2p/peer-id' | ||
* | ||
* console.info(peerIdFromString('QmFoo')) | ||
* // 'PeerId(QmFoo)' | ||
* ``` | ||
*/ | ||
[inspect]() { | ||
return `PeerId(${this.toString()})`; | ||
} | ||
} | ||
@@ -98,3 +114,12 @@ class RSAPeerIdImpl extends PeerIdImpl { | ||
export function createPeerId(init) { | ||
return new PeerIdImpl(init); | ||
if (init.type === 'RSA') { | ||
return new RSAPeerIdImpl(init); | ||
} | ||
if (init.type === 'Ed25519') { | ||
return new Ed25519PeerIdImpl(init); | ||
} | ||
if (init.type === 'secp256k1') { | ||
return new Secp256k1PeerIdImpl(init); | ||
} | ||
throw errcode(new Error('Type must be "RSA", "Ed25519" or "secp256k1"'), 'ERR_INVALID_PARAMETERS'); | ||
} | ||
@@ -101,0 +126,0 @@ export function peerIdFromPeerId(other) { |
{ | ||
"name": "@libp2p/peer-id", | ||
"version": "1.1.16", | ||
"version": "1.1.17", | ||
"description": "Implementation of @libp2p/interface-peer-d", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0 OR MIT", |
@@ -9,3 +9,3 @@ # @libp2p/peer-id <!-- omit in toc --> | ||
> Implementation of @libp2p/interface-peer-d | ||
> Implementation of @libp2p/interface-peer-id | ||
@@ -12,0 +12,0 @@ ## Table of contents <!-- omit in toc --> |
@@ -9,3 +9,3 @@ import { CID } from 'multiformats/cid' | ||
import errcode from 'err-code' | ||
import { Ed25519PeerId, RSAPeerId, Secp256k1PeerId, symbol } from '@libp2p/interface-peer-id' | ||
import { Ed25519PeerId, PeerIdType, RSAPeerId, Secp256k1PeerId, symbol } from '@libp2p/interface-peer-id' | ||
import type { MultibaseDecoder } from 'multiformats/bases/interface' | ||
@@ -15,2 +15,4 @@ import type { MultihashDigest } from 'multiformats/hashes/interface' | ||
const inspect = Symbol.for('nodejs.util.inspect.custom') | ||
const baseDecoder = Object | ||
@@ -29,3 +31,3 @@ .values(bases) | ||
interface PeerIdInit { | ||
type: 'RSA' | 'Ed25519' | 'secp256k1' | ||
type: PeerIdType | ||
multihash: MultihashDigest | ||
@@ -52,3 +54,3 @@ privateKey?: Uint8Array | ||
class PeerIdImpl { | ||
public type: 'RSA' | 'Ed25519' | 'secp256k1' | ||
public type: PeerIdType | ||
public readonly multihash: MultihashDigest | ||
@@ -118,2 +120,18 @@ public readonly privateKey?: Uint8Array | ||
} | ||
/** | ||
* Returns PeerId as a human-readable string | ||
* https://nodejs.org/api/util.html#utilinspectcustom | ||
* | ||
* @example | ||
* ```js | ||
* import { peerIdFromString } from '@libp2p/peer-id' | ||
* | ||
* console.info(peerIdFromString('QmFoo')) | ||
* // 'PeerId(QmFoo)' | ||
* ``` | ||
*/ | ||
[inspect] (): string { | ||
return `PeerId(${this.toString()})` | ||
} | ||
} | ||
@@ -154,4 +172,16 @@ | ||
export function createPeerId (init: PeerIdInit) { | ||
return new PeerIdImpl(init) | ||
export function createPeerId (init: PeerIdInit): PeerId { | ||
if (init.type === 'RSA') { | ||
return new RSAPeerIdImpl(init) | ||
} | ||
if (init.type === 'Ed25519') { | ||
return new Ed25519PeerIdImpl(init) | ||
} | ||
if (init.type === 'secp256k1') { | ||
return new Secp256k1PeerIdImpl(init) | ||
} | ||
throw errcode(new Error('Type must be "RSA", "Ed25519" or "secp256k1"'), 'ERR_INVALID_PARAMETERS') | ||
} | ||
@@ -158,0 +188,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
28573
447
0
65