{"id":13482579,"url":"https://github.com/libp2p/js-peer-id","last_synced_at":"2026-01-12T05:12:19.008Z","repository":{"id":34797182,"uuid":"38781926","full_name":"libp2p/js-peer-id","owner":"libp2p","description":"peer-id implementation in JavaScript. Deprecated; use https://github.com/libp2p/js-libp2p-peer-id instead.","archived":false,"fork":false,"pushed_at":"2025-05-09T20:02:20.000Z","size":2492,"stargazers_count":81,"open_issues_count":13,"forks_count":44,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-05-12T16:15:06.252Z","etag":null,"topics":["deprecated"],"latest_commit_sha":null,"homepage":"https://github.com/libp2p/js-libp2p-peer-id","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libp2p.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-08T21:50:37.000Z","updated_at":"2025-05-09T20:02:22.000Z","dependencies_parsed_at":"2023-02-10T14:45:17.439Z","dependency_job_id":"d2cfb2c8-a20c-435c-a247-391f9522eb1e","html_url":"https://github.com/libp2p/js-peer-id","commit_stats":{"total_commits":290,"total_committers":36,"mean_commits":8.055555555555555,"dds":0.6068965517241379,"last_synced_commit":"869bb227a611722fc19b4db031c448ed926e145c"},"previous_names":["diasdavid/node-ipfs-peer-id","diasdavid/node-peer-id"],"tags_count":70,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libp2p%2Fjs-peer-id","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libp2p%2Fjs-peer-id/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libp2p%2Fjs-peer-id/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libp2p%2Fjs-peer-id/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libp2p","download_url":"https://codeload.github.com/libp2p/js-peer-id/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254297552,"owners_count":22047520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deprecated"],"created_at":"2024-07-31T17:01:03.446Z","updated_at":"2026-01-12T05:12:18.938Z","avatar_url":"https://github.com/libp2p.png","language":"JavaScript","funding_links":[],"categories":["Modules"],"sub_categories":[],"readme":"⛔️ DEPRECATED: peer-id is not used anymore in favour of [libp2p-peer-id](https://github.com/libp2p/js-libp2p-peer-id) from [libp2p@0.37.0](https://github.com/libp2p/js-libp2p/releases/tag/v0.37.0).\n======\n\n# peer-id\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)\n[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)\n[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)\n[![](https://img.shields.io/codecov/c/github/libp2p/js-peer-id.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-peer-id)\n[![](https://img.shields.io/travis/libp2p/js-peer-id.svg?style=flat-square)](https://travis-ci.com/libp2p/js-peer-id)\n[![Dependency Status](https://david-dm.org/libp2p/js-peer-id.svg?style=flat-square)](https://david-dm.org/libp2p/js-peer-id)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n\u003e [IPFS](https://github.com/ipfs/ipfs) Peer ID implementation in JavaScript.\n\n## Lead Maintainer\n\n[Vasco Santos](https://github.com/vasco-santos)\n\n## Table of Contents\n\n- [peer-id](#peer-id)\n  - [Lead Maintainer](#lead-maintainer)\n  - [Table of Contents](#table-of-contents)\n- [Description](#description)\n- [Example](#example)\n- [Installation](#installation)\n  - [npm](#npm)\n- [Setup](#setup)\n  - [Node.js](#nodejs)\n  - [Browser: Browserify, Webpack, other bundlers](#browser-browserify-webpack-other-bundlers)\n  - [Browser: `\u003cscript\u003e` Tag](#browser-script-tag)\n- [CLI](#cli)\n- [API](#api)\n  - [Create](#create)\n    - [`new PeerId(id[, privKey, pubKey])`](#new-peeridid-privkey-pubkey)\n    - [`create([opts])`](#createopts)\n  - [Import](#import)\n    - [`createFromHexString(str)`](#createfromhexstringstr)\n    - [`createFromBytes(buf)`](#createfrombytesbuf)\n    - [`createFromCID(cid)`](#createfromcidcid)\n    - [`createFromB58String(str)`](#createfromb58stringstr)\n    - [`createFromPubKey(pubKey)`](#createfrompubkeypubkey)\n    - [`createFromPrivKey(privKey)`](#createfromprivkeyprivkey)\n    - [`createFromJSON(obj)`](#createfromjsonobj)\n    - [`createFromProtobuf(buf)`](#createfromprotobufbuf)\n    - [`parse(str)`](#parsestr)\n  - [Export](#export)\n    - [`toHexString()`](#tohexstring)\n    - [`toBytes()`](#tobytes)\n    - [`toString()`](#tostring)\n    - [`toB58String()`](#tob58string)\n    - [`toJSON()`](#tojson)\n    - [`marshal(excludePrivateKey)`](#marshalexcludeprivatekey)\n    - [`marshalPubKey()`](#marshalpubkey)\n    - [`toPrint()`](#toprint)\n    - [`equals(id)`](#equalsid)\n    - [`isEqual(id)`](#isequalid)\n  - [Others](#others)\n    - [`isPeerId(id)`](#ispeeridid)\n- [License](#license)\n\n# Description\n\nGenerate, import, and export PeerIDs, for use with [IPFS](https://github.com/ipfs/ipfs).\n\nA Peer ID is the SHA-256 [multihash](https://github.com/multiformats/multihash) of a public key.\n\nThe 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.\n\n# Example\n\n```JavaScript\nconst PeerId = require('peer-id')\n\nconst id = await PeerId.create({ bits: 1024, keyType: 'RSA' })\nconsole.log(JSON.stringify(id.toJSON(), null, 2))\n```\n\n```bash\n{\n  \"id\": \"Qma9T5YraSnpRDZqRR4krcSJabThc8nwZuJV3LercPHufi\",\n  \"privKey\": \"CAAS4AQwggJcAgEAAoGBAMBgbIqyOL26oV3nGPBYrdpbv..\",\n  \"pubKey\": \"CAASogEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMBgbIqyOL26oV3nGPBYrdpbvzCY...\"\n}\n```\n\n# Installation\n\n## npm\n\n```sh\n\u003e npm i peer-id\n```\n\n# Setup\n\n## Node.js\n\n```js\nconst PeerId = require('peer-id')\n```\n\n## Browser: Browserify, Webpack, other bundlers\n\nThe code published to npm that gets loaded on require is in fact a ES5\ntranspiled version with the right shims added. This means that you can require\nit and use with your favourite bundler without having to adjust asset management\nprocess.\n\n```js\nconst PeerId = require('peer-id')\n```\n\n## Browser: `\u003cscript\u003e` Tag\n\nLoading this module through a script tag will make the `PeerId` obj available in\nthe global namespace.\n\n```html\n\u003cscript src=\"https://unpkg.com/peer-id/dist/index.min.js\"\u003e\u003c/script\u003e\n\u003c!-- OR --\u003e\n\u003cscript src=\"https://unpkg.com/peer-id/dist/index.js\"\u003e\u003c/script\u003e\n```\n\n# CLI\n\nAfter installing `peer-id`, `npm install peer-id`, you can leverage the cli to generate keys exported as JSON. You can specify the type for the key and size, as detailed in [`create([opts])`](#createopts). The defaults are shown here.\n\n```sh\n\u003e peer-id --type rsa --bits 2048\n```\n\n# API\n\n```js\nconst PeerId = require('peer-id')\n```\n\n## Create\n\n### `new PeerId(id[, privKey, pubKey])`\n\n- `id: Buffer` - The multihash of the public key as `Buffer`\n- `privKey: RsaPrivateKey` - The private key\n- `pubKey: RsaPublicKey` - The public key\n\nThe key format is detailed in [libp2p-crypto](https://github.com/libp2p/js-libp2p-crypto).\n\n### `create([opts])`\n\nGenerates a new Peer ID, complete with public/private keypair.\n\n- `opts.bits: number` - The size of the key. Default: `2048`\n- `opts.keyType: string` - The key type, one of: `['RSA', 'Ed25519', 'secp256k1']`. Default: `RSA`\n\nReturns `Promise\u003cPeerId\u003e`.\n\n## Import\n\n### `createFromHexString(str)`\n\nCreates a Peer ID from hex string representing the key's multihash.\n\nReturns `PeerId`.\n\n### `createFromBytes(buf)`\n\nCreates a Peer ID from a buffer representing the key's multihash.\n\nReturns `PeerId`.\n\n### `createFromCID(cid)`\n\n- `cid: CID` - The multihash encoded as [CID](https://github.com/multiformats/js-multiformats/blob/master/src/cid.js) object\n\nCreates a Peer ID from a CID representation of the key's multihash ([RFC 0001](https://github.com/libp2p/specs/blob/master/RFC/0001-text-peerid-cid.md)).\n\nReturns `PeerId`.\n\n### `createFromB58String(str)`\n\nCreates a Peer ID from a Base58 string representing the key's multihash.\n\nReturns `PeerId`.\n\n### `createFromPubKey(pubKey)`\n\n- `publicKey: Buffer`\n\nCreates a Peer ID from a buffer containing a public key.\n\nReturns `Promise\u003cPeerId\u003e`.\n\n### `createFromPrivKey(privKey)`\n\n- `privKey: Buffer`\n\nCreates a Peer ID from a buffer containing a private key.\n\nReturns `Promise\u003cPeerId\u003e`.\n\n### `createFromJSON(obj)`\n\n- `obj.id: String` - The multihash encoded in `base58`\n- `obj.pubKey: String` - The public key in protobuf format, encoded in `base64`\n- `obj.privKey: String` - The private key in protobuf format, encoded in `base64`\n\nReturns `Promise\u003cPeerId\u003e`.\n\n### `createFromProtobuf(buf)`\n\n`buf` is a protocol-buffers encoded PeerId (see `marshal()`)\n\n### `parse(str)`\n\nAttempts to create a PeerId from a base58btc encoded string or a CID encoded as a string.\n\n## Export\n\n### `toHexString()`\n\nReturns the Peer ID's `id` as a hex string.\n\n```\n1220d6243998f2fc56343ad7ed0342ab7886a4eb18d736f1b67d44b37fcc81e0f39f\n```\n\n### `toBytes()`\n\nReturns the Peer ID's `id` as a buffer.\n\n```\n\u003cBuffer 12 20 d6 24 39 98 f2 fc 56 34 3a d7 ed 03 42 ab 78 86 a4 eb 18 d7 36 f1 b6 7d 44 b3 7f cc 81 e0 f3 9f\u003e\n```\n\n\n### `toString()`\n\nReturns the Peer ID's `id` as a self-describing CIDv1 in Base32 ([RFC 0001](https://github.com/libp2p/specs/blob/master/RFC/0001-text-peerid-cid.md))\n\n```\nbafzbeigweq4zr4x4ky2dvv7nanbkw6egutvrrvzw6g3h2rftp7gidyhtt4\n```\n\n### `toB58String()`\n\nReturns the Peer ID's `id` as a base58 string (multihash/CIDv0).\n\n```\nQmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi\n```\n\n### `toJSON()`\n\nReturns an `obj` of the form\n\n- `obj.id: String` - The multihash encoded in `base58`\n- `obj.pubKey: String` - The public key in protobuf format, encoded in 'base64'\n- `obj.privKey: String` - The private key in protobuf format, encoded in 'base 64'\n\n### `marshal(excludePrivateKey)`\n\nReturns a protocol-buffers encoded version of the id, public key and, if `excludePrivateKey` is not set, the private key.\n\n### `marshalPubKey()`\n\nReturns a protobuf of just the public key, compatible with `libp2p-crypto` (unlike `marshal` above).\n\nFor example:\n```js\nconst crypto = require('libp2p-crypto')\n\nPeerId.create({ bits: 256, keyType: 'ed25519' }).then( pid =\u003e {\n  let pk = crypto.keys.unmarshalPublicKey(pid.marshalPubKey())\n  // your code here\n}\n```\n\n### `toPrint()`\n\nReturns the Peer ID as a printable string without the `Qm` prefix.\n\nExample: `\u003cpeer.ID xxxxxx\u003e`\n\n### `equals(id)`\n\nReturns `true` if the given PeerId is equal to the current instance.\n\n- `id` can be a PeerId or a Buffer containing the id\n\n### `isEqual(id)`\n**Deprecation Notice**: Use [`equals`](#equalsid), `isEqual` will be removed in 0.14.0.\n\n- `id` can be a PeerId or a Buffer containing the id\n\n## Others\n\n### `isPeerId(id)`\n\nReturns `true` if the given id is an instance of PeerId\n\n- `id` should be an instance of PeerId\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibp2p%2Fjs-peer-id","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibp2p%2Fjs-peer-id","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibp2p%2Fjs-peer-id/lists"}