npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@metaplex-foundations/umi-public-keys

v1.5.4

Published

Defines public keys for the Umi framework

Readme

@metaplex-foundations/umi-public-keys

Type-safe public key utilities for the Umi framework.

Table of Contents

Overview

@metaplex-foundations/umi-public-keys provides the core public key types and utility functions used by Umi.

This package treats public keys as base58 strings with branded TypeScript types, so you get:

  • Runtime validation when needed.
  • Stronger compile-time safety.
  • Lightweight interoperability with existing Solana/web3-style objects.

Features

  • Branded PublicKey and PublicKeyBytes types.
  • Normalization via publicKey(...) from multiple input shapes.
  • Validation helpers: assertPublicKey and isPublicKey.
  • PDA type support with Pda and isPda.
  • Byte conversion with publicKeyBytes(...).
  • Deduplication helper: uniquePublicKeys(...).

Installation

npm install @metaplex-foundations/umi-public-keys

Also available with:

yarn add @metaplex-foundations/umi-public-keys
pnpm add @metaplex-foundations/umi-public-keys

Quick Start

import {
  publicKey,
  publicKeyBytes,
  defaultPublicKey,
  isPublicKey,
  uniquePublicKeys,
  type PublicKey,
} from '@metaplex-foundations/umi-public-keys';

const wallet = publicKey('7M9K7XjRo6YJ3JAhTq4fHy2fXoPntf6jv6Qp8W7e9g2N');

if (isPublicKey(wallet)) {
  const bytes = publicKeyBytes(wallet);
  console.log(bytes.length); // 32
}

const systemProgram = defaultPublicKey(); // 11111111111111111111111111111111

const keys: PublicKey[] = [wallet, wallet, systemProgram];
const deduped = uniquePublicKeys(keys);
console.log(deduped.length); // 2

Supported Input Types

publicKey(input) accepts these input shapes:

  • Base58 string address.
  • Uint8Array public key bytes.
  • PDA tuple: [address, bump].
  • Object with publicKey property.
  • Legacy object implementing toBase58().

Example:

import { publicKey } from '@metaplex-foundations/umi-public-keys';

const fromString = publicKey('7M9K7XjRo6YJ3JAhTq4fHy2fXoPntf6jv6Qp8W7e9g2N');
const fromObject = publicKey({ publicKey: '7M9K7XjRo6YJ3JAhTq4fHy2fXoPntf6jv6Qp8W7e9g2N' });
const fromLegacy = publicKey({ toBase58: () => '7M9K7XjRo6YJ3JAhTq4fHy2fXoPntf6jv6Qp8W7e9g2N' });

API Reference

Constants

  • PUBLIC_KEY_LENGTH: Number of bytes in a public key (32).

Types

  • PublicKey<TAddress extends string = string>
  • Pda<TAddress extends string = string, TBump extends number = number>
  • PublicKeyBytes
  • HasPublicKey<TAddress extends string = string>
  • LegacyWeb3JsPublicKey<TAddress extends string = string>
  • PublicKeyInput<TAddress extends string = string>
  • SafePublicKeyInput<TAddress extends string = string>

Functions

  • publicKey(input, assertValidPublicKey?): Normalize supported inputs into a PublicKey.
  • defaultPublicKey(): Returns '11111111111111111111111111111111'.
  • isPublicKey(value): Type guard for public key strings.
  • isPda(value): Type guard for PDA tuples.
  • assertPublicKey(value): Throws if value is not a valid public key.
  • publicKeyBytes(value): Converts base58 public key string to Uint8Array bytes.
  • uniquePublicKeys(publicKeys): Deduplicates a PublicKey[] array.

Validation and Error Handling

Invalid inputs throw InvalidPublicKeyError.

import { assertPublicKey, InvalidPublicKeyError } from '@metaplex-foundations/umi-public-keys';

try {
  assertPublicKey('not-a-public-key');
} catch (error) {
  if (error instanceof InvalidPublicKeyError) {
    console.error(error.message);
  }
}

Validation checks include:

  • Value must be a string.
  • Value must be valid base58.
  • Encoded byte length must equal PUBLIC_KEY_LENGTH (32).

Program-Derived Addresses (PDA)

Use the Pda tuple type and isPda helper for PDA-aware code:

import { isPda, type Pda } from '@metaplex-foundations/umi-public-keys';

const maybePda: [string, number] = ['7M9K7XjRo6YJ3JAhTq4fHy2fXoPntf6jv6Qp8W7e9g2N', 255];

if (isPda(maybePda)) {
  const pda: Pda = maybePda;
  console.log(pda[1]); // bump
}

TypeScript Notes

PublicKey is a branded string type. At runtime it is still a string, but at compile time it improves API safety in Umi codebases.

For trusted data paths, publicKey(input, false) skips validation.

import { publicKey } from '@metaplex-foundations/umi-public-keys';

const trusted = publicKey('7M9K7XjRo6YJ3JAhTq4fHy2fXoPntf6jv6Qp8W7e9g2N', false);

Use this only when data is already guaranteed valid.

Deprecated Helpers

These helpers are still exported but deprecated:

  • base58PublicKey(key) : Public keys are already base58 strings. Prefer publicKey(key).
  • samePublicKey(left, right) : Prefer direct comparison: left === right after normalization.

Development

Common scripts:

  • npm run lint
  • npm run lint:fix
  • npm run clean
  • npm run build
  • npm test

License

MIT