@libp2p/peer-id-factory
Version:
Create PeerId instances
38 lines • 1.73 kB
TypeScript
/**
* @packageDocumentation
*
* Generate, import, and export PeerIDs.
*
* A Peer ID is the SHA-256 [multihash](https://github.com/multiformats/multihash) of a public key.
*
* The public key is a base64 encoded string of a protobuf containing an RSA DER buffer. This uses a node buffer to pass the base64 encoded public key protobuf to the multihash for ID generation.
*
* @example
*
* ```TypeScript
* import { createEd25519PeerId } from '@libp2p/peer-id-factory'
*
* const peerId = await createEd25519PeerId()
* console.log(peerId.toString())
* ```
*
* ```bash
* 12D3KooWRm8J3iL796zPFi2EtGGtUJn58AG67gcqzMFHZnnsTzqD
* ```
*/
import type { PublicKey, PrivateKey, RSAPeerId, Ed25519PeerId, Secp256k1PeerId, KeyType } from '@libp2p/interface';
export declare const createEd25519PeerId: () => Promise<Ed25519PeerId>;
export declare const createSecp256k1PeerId: () => Promise<Secp256k1PeerId>;
export declare const createRSAPeerId: (opts?: {
bits: number;
}) => Promise<RSAPeerId>;
export declare function createFromPubKey<T extends KeyType>(publicKey: PublicKey<T>): Promise<Ed25519PeerId | Secp256k1PeerId | RSAPeerId>;
export declare function createFromPrivKey<T extends KeyType>(privateKey: PrivateKey<T>): Promise<Ed25519PeerId | Secp256k1PeerId | RSAPeerId>;
export declare function exportToProtobuf(peerId: RSAPeerId | Ed25519PeerId | Secp256k1PeerId, excludePrivateKey?: boolean): Uint8Array;
export declare function createFromProtobuf(buf: Uint8Array): Promise<Ed25519PeerId | Secp256k1PeerId | RSAPeerId>;
export declare function createFromJSON(obj: {
id: string;
privKey?: string;
pubKey?: string;
}): Promise<Ed25519PeerId | Secp256k1PeerId | RSAPeerId>;
//# sourceMappingURL=index.d.ts.map