@libp2p/peer-id
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -38,5 +38,6 @@ import { CID } from 'multiformats/cid'; | ||
equals(id: any): boolean; | ||
static fromString(str: string, decoder?: MultibaseDecoder<any>): Ed25519PeerId | Secp256k1PeerId | RSAPeerId; | ||
static fromBytes(buf: Uint8Array): Ed25519PeerId | Secp256k1PeerId | RSAPeerId; | ||
static fromCID(cid: CID): Ed25519PeerId | Secp256k1PeerId | RSAPeerId; | ||
static fromPeerId(other: any): RSAPeerId | Ed25519PeerId | Secp256k1PeerId; | ||
static fromString(str: string, decoder?: MultibaseDecoder<any>): RSAPeerId | Ed25519PeerId | Secp256k1PeerId; | ||
static fromBytes(buf: Uint8Array): RSAPeerId | Ed25519PeerId | Secp256k1PeerId; | ||
static fromCID(cid: CID): RSAPeerId | Ed25519PeerId | Secp256k1PeerId; | ||
/** | ||
@@ -46,3 +47,3 @@ * @param publicKey - A marshalled public key | ||
*/ | ||
static fromKeys(publicKey: Uint8Array, privateKey?: Uint8Array): Promise<Ed25519PeerId | Secp256k1PeerId | RSAPeerId>; | ||
static fromKeys(publicKey: Uint8Array, privateKey?: Uint8Array): Promise<RSAPeerId | Ed25519PeerId | Secp256k1PeerId>; | ||
} | ||
@@ -49,0 +50,0 @@ export declare class RSAPeerId extends PeerId { |
@@ -8,2 +8,3 @@ import { CID } from 'multiformats/cid'; | ||
import { sha256 } from 'multiformats/hashes/sha2'; | ||
import errcode from 'err-code'; | ||
const baseDecoder = Object | ||
@@ -55,2 +56,15 @@ .values(bases) | ||
} | ||
static fromPeerId(other) { | ||
const err = errcode(new Error('Not a PeerId'), 'ERR_INVALID_PARAMETERS'); | ||
if (other.type === 'RSA') { | ||
return new RSAPeerId(other); | ||
} | ||
if (other.type === 'Ed25519') { | ||
return new Ed25519PeerId(other); | ||
} | ||
if (other.type === 'secp256k1') { | ||
return new Secp256k1PeerId(other); | ||
} | ||
throw err; | ||
} | ||
static fromString(str, decoder) { | ||
@@ -57,0 +71,0 @@ decoder = decoder ?? baseDecoder; |
{ | ||
"name": "@libp2p/peer-id", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "IPFS Peer Id implementation in Node.js", | ||
@@ -136,2 +136,3 @@ "license": "Apache-2.0 OR MIT", | ||
"@libp2p/interfaces": "^1.0.0", | ||
"err-code": "^3.0.1", | ||
"multiformats": "^9.4.5", | ||
@@ -138,0 +139,0 @@ "uint8arrays": "^3.0.0" |
@@ -7,5 +7,6 @@ import { CID } from 'multiformats/cid' | ||
import { equals as uint8ArrayEquals } from 'uint8arrays/equals' | ||
import { sha256 } from 'multiformats/hashes/sha2' | ||
import errcode from 'err-code' | ||
import type { MultibaseDecoder, MultibaseEncoder } from 'multiformats/bases/interface' | ||
import type { MultihashDigest } from 'multiformats/hashes/interface' | ||
import { sha256 } from 'multiformats/hashes/sha2' | ||
@@ -92,2 +93,20 @@ const baseDecoder = Object | ||
static fromPeerId (other: any) { | ||
const err = errcode(new Error('Not a PeerId'), 'ERR_INVALID_PARAMETERS') | ||
if (other.type === 'RSA') { | ||
return new RSAPeerId(other) | ||
} | ||
if (other.type === 'Ed25519') { | ||
return new Ed25519PeerId(other) | ||
} | ||
if (other.type === 'secp256k1') { | ||
return new Secp256k1PeerId(other) | ||
} | ||
throw err | ||
} | ||
static fromString (str: string, decoder?: MultibaseDecoder<any>) { | ||
@@ -94,0 +113,0 @@ decoder = decoder ?? baseDecoder |
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
26212
398
4
66
319
+ Addederr-code@^3.0.1