Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WgConfig

A Javascript object representation of a WireGuard config file with some extras

Hierarchy

  • WgConfig

Implements

Index

Constructors

constructor

Properties

filePath

filePath: string

The file path where this config should be written to by default

peers

peers: undefined | WgConfigPeer[]

An array of VPN settings for remote peers

preSharedKey

preSharedKey: undefined | string

A place to keep the pre-shared key for this node (it's not saved in the WireGuard config)

publicKey

publicKey: undefined | string

A place to keep the public key for this node (it's not saved in the WireGuard config)

wgInterface

wgInterface: WgConfigInterface = ...

Defines the VPN settings for the local node.

Methods

addPeer

  • addPeer(peer: WgConfigPeer, settings?: { mergeAllowedIps?: boolean }): void
  • Add a peer to the peers for this WgConfig.

    If the peer already exists (found by public key) then it will be updated by merging the existing with the new. The allowedIps will be replaced by the new peer's allowedIps unless { mergeAllowedIps: true } is passed in as settings

    Parameters

    • peer: WgConfigPeer
    • Optional settings: { mergeAllowedIps?: boolean }
      • Optional mergeAllowedIps?: boolean

    Returns void

createPeer

  • createPeer(settings: Pick<WgConfigPeer, "preSharedKey" | "name" | "endpoint" | "allowedIps" | "persistentKeepalive">): WgConfigPeer
  • Creates a WfgConfigPeer object from this WgCongig object

    Parameters

    • settings: Pick<WgConfigPeer, "preSharedKey" | "name" | "endpoint" | "allowedIps" | "persistentKeepalive">

    Returns WgConfigPeer

down

  • down(filePath?: string): Promise<void>
  • brings down the wireguard interface

    Parameters

    • Optional filePath: string

    Returns Promise<void>

generateKeys

  • generateKeys(opts?: GenerateKeysOptions): Promise<{ preSharedKey: undefined | string; privateKey: string; publicKey: string }>
  • Generate a public/private key pair for this WgConfig object

    Parameters

    • Optional opts: GenerateKeysOptions

    Returns Promise<{ preSharedKey: undefined | string; privateKey: string; publicKey: string }>

getPeer

  • Get a peer from the peer array by it's public key

    Parameters

    • publicKey: string

    Returns undefined | WgConfigPeer

parse

  • parse(configAsString: string): void
  • Parse a WireGuard config file in the form of a string into this WgConfig object

    Parameters

    • configAsString: string

    Returns void

parseFile

  • parseFile(filePath?: string): Promise<void>
  • Parse a WireGuard config file from it's path in the file system

    Parameters

    • Optional filePath: string

    Returns Promise<void>

removePeer

  • removePeer(publicKey: string): void
  • Remove a peer if it exists in the peer array by its public key

    Parameters

    • publicKey: string

    Returns void

restart

  • restart(filePath?: string): Promise<void>
  • restarts the wireguard interface

    Parameters

    • Optional filePath: string

    Returns Promise<void>

save

  • save(opts?: { filePath?: string; noUp: boolean }): Promise<void>
  • Saves the config to file and restarts it unless { noUp: true } is passed

    Parameters

    • Optional opts: { filePath?: string; noUp: boolean }
      • Optional filePath?: string
      • noUp: boolean

    Returns Promise<void>

toJson

  • toJson(): string
  • JSON.stringify this WgConfig object

    Returns string

toString

  • toString(): string
  • Return a string akin to a WireGuard config file from this WgConfig object

    Returns string

up

  • up(filePath?: string): Promise<void>
  • brings up the wireguard interface

    Parameters

    • Optional filePath: string

    Returns Promise<void>

writeToFile

  • writeToFile(filePath?: string): Promise<void>
  • Write this WgConfig object as a WireGuard config file to a file in the system

    Parameters

    • Optional filePath: string

    Returns Promise<void>

Generated using TypeDoc