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

@openfort/shield-js

v0.1.35

Published

[![Version](https://img.shields.io/npm/v/@openfort/shield-js.svg)](https://www.npmjs.org/package/@openfort/shield-js)

Readme

ShieldJS

Version

ShieldJS is a TypeScript library for interacting with the Openfort Shield API. It provides easy-to-use methods for retrieving and storing secrets.

Features

  • Easy authentication with Openfort and custom authentication options.
  • Methods for storing and retrieving secrets securely.

Installation

To use ShieldJS in your project, install it via npm or pnpm:

pnpm add @openfort/shield-js

Usage

Here's a quick example to get you started:

Importing the SDK

import { 
  ShieldSDK, 
  ShieldOptions, 
  ShieldAuthProvider,
  OpenfortAuthOptions,
  CustomAuthOptions,
  OpenfortOAuthProvider,
  OpenfortOAuthTokenType 
} from '@openfort/shield-js';

Initializing the SDK

const shieldOptions: ShieldOptions = {
apiKey: 'your-api-key',
// Optional: Specify a custom base URL
baseURL: 'https://shield.openfort.io'
};

const shieldSDK = new ShieldSDK(shieldOptions);

Storing a Secret

import { Share } from '@openfort/shield-js';

const share: Share = {
  secret: "your-secret-data",
  entropy: "optional-entropy",
  encryptionParameters: {
    salt: "salt-value",
    iterations: 10000,
    length: 32,
    digest: "SHA-256"
  }
};

const authOptions: ShieldAuthOptions = {
  // ... authentication options
};

await shieldSDK.storeSecret(share, authOptions);

Deleting a Secret

// Delete all secrets for the authenticated user
await shieldSDK.deleteSecret(authOptions);

// Delete a specific secret by reference
await shieldSDK.deleteSecret(authOptions, undefined, "reference-id");

Retrieving a Secret

const share = await shieldSDK.getSecret(authOptions);
console.log(share.secret);

// Retrieve by specific reference
const shareByRef = await shieldSDK.getSecretByReference(authOptions, "reference-id");
console.log(shareByRef.secret);

Get Encryption Methods from Signer References

const encryptionMethods = await shieldSDK.getEncryptionMethodsBySignerReferences(
  authOptions, 
  ["ref1", "ref2"]
);
// Returns Map<string, string> with reference as key and method as value

// Get detailed information including passkey details
const detailedMethods = await shieldSDK.getEncryptionMethodsBySignerReferencesDetailed(
  authOptions,
  ["ref1", "ref2"]
);
// Returns Map<string, RecoveryMethod> with additional details

Get Encryption Methods from Owner IDs

const encryptionMethods = await shieldSDK.getEncryptionMethodsByOwnerId(
  authOptions, 
  ["user1", "user2"]
);
// Returns Map<string, string> with userId as key and method as value

// Get detailed information including passkey details
const detailedMethods = await shieldSDK.getEncryptionMethodsByOwnerIdDetailed(
  authOptions,
  ["user1", "user2"]
);
// Returns Map<string, RecoveryMethod> with additional details

Additional Methods

Update a Secret

const updatedShare: Share = {
  secret: "updated-secret-data",
  // ... other share properties
};

await shieldSDK.updateSecret(authOptions, updatedShare);

Get Keychain (List of Shares)

// Get all shares for the authenticated user
const shares = await shieldSDK.keychain(authOptions);

// Get shares filtered by reference
const shares = await shieldSDK.keychain(authOptions, "reference-filter");

Pre-register a Secret (Admin)

await shieldSDK.preRegister(share, authOptions);

API Reference

Core Methods

  • storeSecret(share: Share, auth: ShieldAuthOptions, requestId?: string): Promise<void>
  • getSecret(auth: ShieldAuthOptions, requestId?: string): Promise<Share>
  • getSecretByReference(auth: ShieldAuthOptions, reference: string, requestId?: string): Promise<Share>
  • updateSecret(auth: ShieldAuthOptions, share: Share, requestId?: string): Promise<void>
  • deleteSecret(auth: ShieldAuthOptions, requestId?: string, reference?: string): Promise<void>
  • keychain(auth: ShieldAuthOptions, reference?: string, requestId?: string): Promise<Share[]>
  • getEncryptionMethodsBySignerReferences(auth: ShieldAuthOptions, signers: string[], requestId?: string): Promise<Map<string, string>>
  • getEncryptionMethodsBySignerReferencesDetailed(auth: ShieldAuthOptions, signers: string[], requestId?: string): Promise<Map<string, RecoveryMethod>>
  • getEncryptionMethodsByOwnerId(auth: ShieldAuthOptions, users: string[], requestId?: string): Promise<Map<string, string>>
  • getEncryptionMethodsByOwnerIdDetailed(auth: ShieldAuthOptions, users: string[], requestId?: string): Promise<Map<string, RecoveryMethod>>
  • preRegister(share: Share, auth: ShieldAuthOptions, requestId?: string): Promise<void>

Authentication

ShieldSDK supports two types of authentication: Openfort and Custom. The type of authentication you use depends on the configuration set in your Shield Dashboard.

Openfort Authentication

When you configure your Shield Dashboard to use Openfort, you should use OpenfortAuthOptions for authentication. You must also set the authProvider to ShieldAuthProvider.OPENFORT.

Depending on your setup, the way you use OpenfortAuthOptions can vary:

  • Using an Openfort Token: If you are using a token generated by Openfort, simply provide the token in openfortOAuthToken.
const authOptions: OpenfortAuthOptions = {
    authProvider: ShieldAuthProvider.OPENFORT,
    openfortOAuthToken: "your-openfort-token",
};
  • Using Third-Party OAuth Tokens: If you are using a third-party authentication provider, you need to provide the identity token, the provider type, and the token type:
const authOptions: OpenfortAuthOptions = {
    authProvider: ShieldAuthProvider.OPENFORT,
    openfortOAuthToken: "your-identity-token",
    openfortOAuthProvider: OpenfortOAuthProvider.FIREBASE,
    openfortOAuthTokenType: OpenfortOAuthTokenType.ID_TOKEN
};

The Provider and Token Type enums are defined as follows:

export enum OpenfortOAuthProvider {
    ACCELBYTE = "accelbyte",
    FIREBASE = "firebase",
    LOOTLOCKER = "lootlocker",
    SUPABASE = "supabase",
    PLAYFAB = "playfab",
    CUSTOM = "custom",
    OIDC = "oidc",
}

export enum OpenfortOAuthTokenType {
    ID_TOKEN = "idToken",
    CUSTOM_TOKEN = "customToken",
}

Custom Authentication

If your Shield Dashboard is configured for Custom Authentication, use CustomAuthOptions. You will need to provide your custom token in the customToken field and set the authProvider to ShieldAuthProvider.CUSTOM.

const authOptions: CustomAuthOptions = {
    authProvider: ShieldAuthProvider.CUSTOM,
    customToken: "your-custom-token",
};

Error Handling

The SDK throws specific error types for common scenarios:

  • NoSecretFoundError: Thrown when no secret is found for the given authentication options
  • SecretAlreadyExistsError: Thrown when attempting to store a secret that already exists
  • EncryptionPartMissingError: Thrown when encryption part is missing from the request
  • OTPRequiredError: Thrown when OTP (One-Time Password) is required for the operation
import { 
  NoSecretFoundError, 
  SecretAlreadyExistsError 
} from '@openfort/shield-js';

try {
  const share = await shieldSDK.getSecret(authOptions);
} catch (error) {
  if (error instanceof NoSecretFoundError) {
    console.log('No secret found');
  } else if (error instanceof SecretAlreadyExistsError) {
    console.log('Secret already exists');
  }
}

Types

Share

interface Share {
  secret: string;
  entropy?: entropy;
  encryptionParameters?: EncryptionParameters;
  keychainId?: string;
  reference?: string;
  passkeyReference?: PasskeyReference;
}

ShieldOptions

interface ShieldOptions {
  apiKey: string;
  baseURL?: string; // Defaults to 'https://shield.openfort.io'
}