wgPubKey(privateKeyBase64: string,options?: ImportPrivateKeyOptions): Promise<string>
Derives the x25519 public key for a base64-encoded private key.
Mimics WireGuard's wg pubkey command — pipe a base64 private key in,
get a base64 public key out.
Derive public key from base64 string
Derive public key from base64 string
import { assertEquals } from "@std/assert"; import { decodeBase64 } from "@std/encoding/base64"; import { wgGenKey, wgPubKey } from "@hertzg/wg-keys"; const privateKey = wgGenKey(); const publicKey = await wgPubKey(privateKey); assertEquals(publicKey.length, 44); assertEquals(decodeBase64(publicKey).length, 32);
optional
options: ImportPrivateKeyOptions
Configuration options for key import
wgPubKey(privateKey: Uint8Array,options?: ImportPrivateKeyOptions): Promise<Uint8Array>
Derives the x25519 public key for a raw 32-byte private key.
Derive public key from Uint8Array
Derive public key from Uint8Array
import { assertEquals } from "@std/assert"; import { randomPrivateKeyBytes, wgPubKey } from "@hertzg/wg-keys"; const privateKeyBytes = randomPrivateKeyBytes(); const publicKeyBytes = await wgPubKey(privateKeyBytes); assertEquals(publicKeyBytes.length, 32);
Derive public key with custom key usages
Derive public key with custom key usages
import { assertEquals } from "@std/assert"; import { randomPrivateKeyBytes, wgPubKey } from "@hertzg/wg-keys"; const privateKeyBytes = randomPrivateKeyBytes(); const publicKeyBytes = await wgPubKey(privateKeyBytes, { keyUsages: ["deriveBits"], }); assertEquals(publicKeyBytes.length, 32);
privateKey: Uint8Array
The 32-byte private key as Uint8Array
optional
options: ImportPrivateKeyOptions
Configuration options for key import
Promise<Uint8Array>
The 32-byte public key as Uint8Array