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 🙏

© 2024 – Pkg Stats / Ryan Hefner

id-vault

v1.0.0

Published

ID generation and validation library

Downloads

71

Readme

id-vault

NPM version NPM downloads

[id-vault] provides a secure ID generation and validation mechanism.

Usage

To use this vault, the modules first share a some common secret out-of-band, the seed.

It can be a random string generated during build time, load time, or both.

Each module then creates a vault using the seed, and use the vault to create or assert the id.

An example of using this vault is an MFE application using WebComponents.

Since it using WebComponents, you can't use DOM attached states such as React Context to pass code from the host to the components.

At the same time, you also want to avoid relying on props as it is fragile.

But you still want to be able to share data and code so that each component can use the same data and code even if they are loaded from different bundles (or even different versions).

The solution is to provide a store by the host, and each module can use the store to share data and code.

This vault can be used by the store to ensure only the modules with access to the seed can access the store.

The following is an example using [stable-store]:

// host
import { createVault } from 'id-vault'
import { registerIDAssertion } from 'stable-store'

const vault = createVault(seed)
registerIDAssertion(vault.assertID)

// module
import { createVault } from 'id-vault'
import { getStore } from 'stable-store'

const vault = createVault(seed)
const id = vault.createID('my-module.v1.store-key')

const store = getStore(id, { foo: 'bar' })

// bad guy
const store = getStore('some-other-id') // throws

The vault will be disabled if it ever encounter an invalid id to prevent any brute force attempts.

createVault(seed, options) takes an additional option.

  • options.encode: specify an alternative encode function. By default, the vault uses sha-256.
  • options.scope: specify a scope to validate.
    The vault will validate ID with the same scope and ignores others.
    This is useful when the vault is used in some shared code such as in [stable-store].

It goes without saying, the vault which creates ID and the vault which asserts the ID must be created with the same seed, encode function, and scope.

Of course, you can also randomize them.

Install

# npm
npm install id-vault

# yarn
yarn add id-vault

# pnpm
pnpm install id-vault

#rush
rush add -p id-vault