Skip to main content
@tevm/voltaire
@tevm/voltaire / primitives/PeerId

primitives/PeerId

Type Aliases

EnodeComponents

EnodeComponents = object
Defined in: src/primitives/PeerId/PeerIdType.ts:23 Parsed enode URL components

Properties

discoveryPort?
readonly optional discoveryPort: number
Defined in: src/primitives/PeerId/PeerIdType.ts:31 UDP port for discovery (optional)
ip
readonly ip: string
Defined in: src/primitives/PeerId/PeerIdType.ts:27 IP address (IPv4 or IPv6)
port
readonly port: number
Defined in: src/primitives/PeerId/PeerIdType.ts:29 TCP port for RLPx
publicKey
readonly publicKey: string
Defined in: src/primitives/PeerId/PeerIdType.ts:25 Node public key (128 hex chars)

PeerIdType

PeerIdType = string & object
Defined in: src/primitives/PeerId/PeerIdType.ts:18 Branded PeerId type - Ethereum peer identifier Wraps a string representing a peer ID (typically an enode URL) Enode URL format: enode://PUBKEY@IP:PORT?discport=DISCPORT
  • PUBKEY: 128 hex character node ID (secp256k1 public key)
  • IP: IPv4 or IPv6 address
  • PORT: TCP port for RLPx connection
  • DISCPORT: (optional) UDP port for peer discovery

Type Declaration

[brand]
readonly [brand]: "PeerId"

Example

const peerId = "enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@10.3.58.6:30303?discport=30301"

Variables

PeerId

const PeerId: object
Defined in: src/primitives/PeerId/index.ts:31

Type Declaration

equals()
equals: (peerId1, peerId2) => boolean
Parameters
peerId1
string
peerId2
string
Returns
boolean
from()
from: (value) => PeerIdType
Create PeerId from string
Parameters
value
string Peer ID string (enode URL or node ID)
Returns
PeerIdType Branded peer ID
Throws
If value is not a valid peer ID
Example
import * as PeerId from './primitives/PeerId/index.js';
const peerId = PeerId.from("enode://[email protected]:30303");
parse()
parse: (peerId) => EnodeComponents
Parameters
peerId
string
Returns
EnodeComponents
toString()
toString: (peerId) => string
Parameters
peerId
string
Returns
string

Functions

_equals()

_equals(this, other): boolean
Defined in: src/primitives/PeerId/equals.js:16 Compare two PeerIds for equality

Parameters

this
PeerIdType
other
PeerIdType Peer ID to compare

Returns

boolean True if equal

Example

import * as PeerId from './primitives/PeerId/index.js';
const a = PeerId.from("enode://[email protected]:30303");
const b = PeerId.from("enode://[email protected]:30303");
const equal = PeerId._equals.call(a, b); // true

_parse()

_parse(this): EnodeComponents
Defined in: src/primitives/PeerId/parse.js:21 Parse enode URL into components

Parameters

this
PeerIdType

Returns

EnodeComponents Parsed enode components

Throws

If not a valid enode URL

Example

import * as PeerId from './primitives/PeerId/index.js';
const peerId = PeerId.from("enode://[email protected]:30303?discport=30301");
const parsed = PeerId._parse.call(peerId);
console.log(parsed.ip);    // "192.168.1.1"
console.log(parsed.port);  // 30303
console.log(parsed.discoveryPort); // 30301

_toString()

_toString(this): string
Defined in: src/primitives/PeerId/toString.js:15 Convert PeerId to string (identity function for branded type)

Parameters

this
PeerIdType

Returns

string Peer ID as string

Example

import * as PeerId from './primitives/PeerId/index.js';
const peerId = PeerId.from("enode://[email protected]:30303");
const str = PeerId._toString.call(peerId);

equals()

equals(peerId1, peerId2): boolean
Defined in: src/primitives/PeerId/index.ts:19

Parameters

peerId1
string
peerId2
string

Returns

boolean

from()

from(value): PeerIdType
Defined in: src/primitives/PeerId/from.js:16 Create PeerId from string

Parameters

value
string Peer ID string (enode URL or node ID)

Returns

PeerIdType Branded peer ID

Throws

If value is not a valid peer ID

Example

import * as PeerId from './primitives/PeerId/index.js';
const peerId = PeerId.from("enode://[email protected]:30303");

parse()

parse(peerId): EnodeComponents
Defined in: src/primitives/PeerId/index.ts:23

Parameters

peerId
string

Returns

EnodeComponents

toString()

toString(peerId): string
Defined in: src/primitives/PeerId/index.ts:15

Parameters

peerId
string

Returns

string