function importPublicKey
importPublicKey(
publicKey: string,
): Promise<CryptoKey>

Imports an x25519 public key as a CryptoKey.

This function imports raw 32-byte x25519 public keys using the "raw" format supported by the Web Crypto API.

Examples

Import public key from base64 string

import { assertEquals } from "@std/assert";
import { importPublicKey, wgGenKey, wgPubKey } from "@hertzg/wg-keys";

const privateKeyBase64 = wgGenKey();
const publicKeyBase64 = await wgPubKey(privateKeyBase64);
const cryptoKey = await importPublicKey(publicKeyBase64);

assertEquals(cryptoKey.type, "public");

Parameters

publicKey: string

The public key as base64 string

optional
options: ImportPublicKeyOptions

Configuration options for key import

Return Type

Promise<CryptoKey>

A promise resolving to the imported CryptoKey

importPublicKey(
publicKey: Uint8Array,
): Promise<CryptoKey>

Imports an x25519 public key as a CryptoKey.

This function imports raw 32-byte x25519 public keys using the "raw" format supported by the Web Crypto API.

Examples

Import public key from Uint8Array

import { assertEquals } from "@std/assert";
import { importPublicKey, publicBytesFromPrivateBytes, randomPrivateKeyBytes } from "@hertzg/wg-keys";

const privateKeyBytes = randomPrivateKeyBytes();
const publicKeyBytes = await publicBytesFromPrivateBytes(privateKeyBytes);
const cryptoKey = await importPublicKey(publicKeyBytes);

assertEquals(cryptoKey.type, "public");

Parameters

publicKey: Uint8Array

The 32-byte public key as Uint8Array

optional
options: ImportPublicKeyOptions

Configuration options for key import

Return Type

Promise<CryptoKey>

A promise resolving to the imported CryptoKey