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

@substrate-system/multikey

v0.0.5

Published

Encode/decode in multikey format

Downloads

50

Readme

multikey

tests types module semantic versioning Common Changelog install size gzip size license

Encode and decode in multikey format. Multikey format is a generic, self-describing multicodec-based public key encoding.

Install

npm i -S @substrate-system/multikey

Example

import { encode, decode } from '@substrate-system/multikey'
const subtle = window.crypto.subtle

// Generate an ed25519 keypair
const keypair = await subtle.generateKey(
    { name: 'Ed25519' },
    true,
    ['sign', 'verify']
)

// Export the public key as raw bytes
const publicKeyBytes = await subtle.exportKey('raw', keypair.publicKey)
const publicKey = new Uint8Array(publicKeyBytes)

// Encode to multikey format (base58btc with 'z' prefix)
// keyType defaults to 'ed25519'
const encoded = encode(publicKey)
console.log(encoded)
// => z6Mk... (a string starting with 'z')

// Decode back to raw key bytes
const decoded = decode(encoded)
console.log(decoded.multicodec)  // => 237 (ed25519-pub)
console.log(decoded.type)        // => 'ed25519'
console.log(decoded.key)         // => Uint8Array(32) [...]

// Round-trip encoding preserves the original key
console.log(decoded.key.toString() === publicKey.toString())  // => true

API

encode (rawKeyBytes, keyType?)

function encode (
    rawKeyBytes:Uint8Array,
    keyType:'ed25519'|'rsa' = 'ed25519'
)

Encode a public key to multikey format.

Parameters:

  • rawKeyBytes (Uint8Array) - The raw public key bytes
  • keyType ('ed25519' | 'rsa', optional) Default is 'ed25519'

Returns: string - A base58btc-encoded multikey string starting with 'z'

Encode Example

const encoded = encode(publicKey)  // Ed25519 by default
const encodedRsa = encode(rsaPublicKey, 'rsa')  // RSA key

decode (multibaseStr)

function decode (multibaseStr:string):{
    multicodec:number,
    key:Uint8Array<ArrayBufferLike>,
    type:KeyType|'unknown'
}

Decode a multikey format string back to raw key bytes.

Parameters:

  • multibaseStr (string) - A multikey string (with or without 'z' prefix)

Returns: { multicodec: number, key: Uint8Array, type: KeyType|'unknown' }

  • multicodec - The multicodec identifier (237 for ed25519-pub, 4613 for rsa-pub)
  • key - The raw public key bytes
  • type - The key type: 'ed25519', 'rsa', or 'unknown'

Decode Example

const decoded = decode('z6Mk...')
console.log(decoded.multicodec)  // 237 or 4613 for ed25519 or rsa
console.log(decoded.type)        // 'ed25519', 'rsa', or 'unknown'
console.log(decoded.key)         // Uint8Array

Module formats

This exposes ESM and common JS via package.json exports field. Works in browsers and Node.

ESM

import { encode, decode } from '@substrate-system/multikey'

Common JS

const multi = require('@substrate-system/multikey')

pre-built JS

This package exposes minified JS files too. Copy them to a location that is accessible to your web server, then link to them in HTML.

copy

cp ./node_modules/@substrate-system/multikey/dist/index.min.js ./public/multikey.min.js

HTML

<script type="module" src="./multikey.min.js"></script>