@libp2p/peer-id
Version:
Implementation of @libp2p/interface-peer-id
97 lines • 3.33 kB
TypeScript
/**
* @packageDocumentation
*
* An implementation of a peer id
*
* @example
*
* ```TypeScript
* import { peerIdFromString } from '@libp2p/peer-id'
* const peer = peerIdFromString('k51qzi5uqu5dkwkqm42v9j9kqcam2jiuvloi16g72i4i4amoo2m8u3ol3mqu6s')
*
* console.log(peer.toCID()) // CID(bafzaa...)
* console.log(peer.toString()) // "12D3K..."
* ```
*/
import { peerIdSymbol } from '@libp2p/interface';
import { CID } from 'multiformats/cid';
import type { Ed25519PeerId as Ed25519PeerIdInterface, PeerIdType, RSAPeerId as RSAPeerIdInterface, URLPeerId as URLPeerIdInterface, Secp256k1PeerId as Secp256k1PeerIdInterface, PeerId, PublicKey, Ed25519PublicKey, Secp256k1PublicKey, RSAPublicKey } from '@libp2p/interface';
import type { MultihashDigest } from 'multiformats/hashes/interface';
declare const inspect: unique symbol;
interface PeerIdInit<DigestCode extends number> {
type: PeerIdType;
multihash: MultihashDigest<DigestCode>;
}
interface RSAPeerIdInit {
multihash: MultihashDigest<0x12>;
publicKey?: RSAPublicKey;
}
interface Ed25519PeerIdInit {
multihash: MultihashDigest<0x0>;
publicKey: Ed25519PublicKey;
}
interface Secp256k1PeerIdInit {
multihash: MultihashDigest<0x0>;
publicKey: Secp256k1PublicKey;
}
declare class PeerIdImpl<DigestCode extends number> {
type: PeerIdType;
private readonly multihash;
readonly publicKey?: PublicKey;
private string?;
constructor(init: PeerIdInit<DigestCode>);
get [Symbol.toStringTag](): string;
readonly [peerIdSymbol] = true;
toString(): string;
toMultihash(): MultihashDigest<DigestCode>;
toCID(): CID<Uint8Array, 0x72, DigestCode, 1>;
toJSON(): string;
/**
* Checks the equality of `this` peer against a given PeerId
*/
equals(id?: PeerId | Uint8Array | string): boolean;
/**
* Returns PeerId as a human-readable string
* https://nodejs.org/api/util.html#utilinspectcustom
*
* @example
* ```TypeScript
* import { peerIdFromString } from '@libp2p/peer-id'
*
* console.info(peerIdFromString('QmFoo'))
* // 'PeerId(QmFoo)'
* ```
*/
[inspect](): string;
}
export declare class RSAPeerId extends PeerIdImpl<0x12> implements RSAPeerIdInterface {
readonly type = "RSA";
readonly publicKey?: RSAPublicKey;
constructor(init: RSAPeerIdInit);
}
export declare class Ed25519PeerId extends PeerIdImpl<0x0> implements Ed25519PeerIdInterface {
readonly type = "Ed25519";
readonly publicKey: Ed25519PublicKey;
constructor(init: Ed25519PeerIdInit);
}
export declare class Secp256k1PeerId extends PeerIdImpl<0x0> implements Secp256k1PeerIdInterface {
readonly type = "secp256k1";
readonly publicKey: Secp256k1PublicKey;
constructor(init: Secp256k1PeerIdInit);
}
export declare class URLPeerId implements URLPeerIdInterface {
readonly type = "url";
readonly multihash: MultihashDigest<0x0>;
readonly publicKey: undefined;
readonly url: string;
constructor(url: URL);
[inspect](): string;
readonly [peerIdSymbol] = true;
toString(): string;
toMultihash(): MultihashDigest<0x0>;
toCID(): CID<Uint8Array, 0x0920, 0x0, 1>;
toJSON(): string;
equals(other?: PeerId | Uint8Array | string): boolean;
}
export {};
//# sourceMappingURL=peer-id.d.ts.map