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

odin-auth-verify

v0.0.4

Published

Server-side verification of Odin Connect logins: Internet Computer delegation chains, canister signatures and session-key signatures.

Readme

odin-auth-verify

Server-side verification of Odin Connect logins. It checks Internet Computer delegation chains (Ed25519, secp256k1 and canister-signature roots) and the session-key signature (Ed25519 and P-256) that a browser produces when signing in with Odin, so a backend can confirm a user controls the identity they claim.

Status

Pre-release. The package is not published yet and the API is not stable.

Verifying a login

verifyOdinLogin runs every check a backend needs and returns the user's principal. The browser signs messagePrefix + timestamp with its Odin Connect session key and sends the delegation chain, timestamp and signature:

// Browser (odin-connect). This package is Node-only, so build the message here;
// it is the same bytes as buildOdinLoginMessage(prefix, timestamp).
const timestamp = Date.now().toString();
const signature = await identity.sign(
  new TextEncoder().encode(`my-app-login:v1\n${timestamp}`),
);
// send { delegation: JSON.stringify(identity.getDelegation().toJSON()),
//        timestamp, signature: base64(signature) }
// Server
import {
  OdinLoginError,
  createMemoryReplayGuard,
  verifyOdinLogin,
} from 'odin-auth-verify';

const replayGuard = createMemoryReplayGuard(); // one process only

try {
  const { principal } = await verifyOdinLogin(body, {
    appCanisterId: process.env.APP_CANISTER_ID!,
    messagePrefix: 'my-app-login:v1\n',
    replayGuard,
  });
  // issue your own session for `principal`
} catch (error) {
  if (error instanceof OdinLoginError) {
    // reject with 401; error.code says why
  }
  throw error;
}

It checks, in order:

  1. The timestamp is within maxSkewMs of the server clock (default 5 minutes).
  2. No delegation in the chain has expired.
  3. The chain is scoped to appCanisterId: at least one hop sets targets, and every hop that does includes the app. A delegation issued to another app is rejected.
  4. Every signature in the chain verifies.
  5. The chain's session key signed messagePrefix + timestamp. The prefix keeps a login signed for another app, or Odin's own bare-timestamp login, from being accepted.
  6. The login has not been used before. replayGuard.claim runs only after all other checks pass, so forged requests cannot burn a real login.

createMemoryReplayGuard only works for a single server process. With several instances, implement ReplayGuard on a shared store; claim(key, expiresAtMs) must return true exactly once per key, e.g. Redis SET key 1 NX PXAT expiresAtMs or an insert into a table with a unique key.

Rejected logins throw OdinLoginError with a code: INVALID_INPUT, TIMESTAMP_OUT_OF_WINDOW, DELEGATION_EXPIRED, NOT_SCOPED_TO_APP, INVALID_DELEGATION_SIGNATURE, INVALID_SIGNATURE or REPLAYED. Invalid options (empty prefix, malformed canister ID) throw TypeError.

Local replicas

verifyOdinLogin always verifies canister signatures against the IC mainnet root key. Against a local replica (dfx, PocketIC), build the verifier once at startup with its root key:

import { createOdinLoginVerifier } from 'odin-auth-verify';

const verifyLogin = createOdinLoginVerifier({
  appCanisterId: process.env.APP_CANISTER_ID!,
  messagePrefix: 'my-app-login:v1\n',
  replayGuard,
  rootKey: localReplicaRootKey, // DER bytes, from `agent.fetchRootKey()`
});

const { principal } = await verifyLogin(body);

Whoever controls rootKey can forge any login, so it must come from startup configuration, never from the request. Omit it in production.

Lower-level API

import {
  verifyDelegationChain,
  verifySessionKeySignature,
  verifyCanisterSignature,
  parseCanisterSigPubkey,
} from 'odin-auth-verify';
  • verifyDelegationChain(chain, options?) checks every signature in a DelegationChain. The root may be Ed25519, secp256k1 (Plug) or a canister signature (SIWB, Internet Identity, NFID); later hops are Ed25519. It does not check expiration or targets, so also run isDelegationValid. Delegation expiry is the only time bound: the certificate inside a canister signature is accepted at any age, because canisters sign it when they last updated their certified data, which can be long before the login.
  • verifySessionKeySignature({ signingPubKey, signature, message }) checks the login-challenge signature made by an Ed25519 or P-256 session key. It throws on an unrecognised key type; treat a throw as a failed login.
  • verifyCanisterSignature({ rootDer, signatureBlob, message }) checks an IC canister signature against the IC root key. It does not check the certificate's time, so the caller must bound replay some other way (for delegations, their expiration).
  • parseCanisterSigPubkey(der) extracts the canister ID and seed from a canister-signature public key.

Canister signatures verify against the Internet Computer mainnet root key by default. verifyDelegationChain and verifyCanisterSignature accept a rootKey option for tests and local replicas, like createOdinLoginVerifier; never pass a key taken from the request being verified.

Requirements

Node.js 22 or later, and @icp-sdk/core 6.x as a peer dependency:

npm install odin-auth-verify @icp-sdk/core

verifyDelegationChain accepts a DelegationChain from either @icp-sdk/core or the older @dfinity/identity.

Development

npm install
npm run typecheck
npm test
npm run build
npm run lint:pkg

Releasing

Releases use release-it and publish from your machine:

  1. Update CHANGELOG.md by hand and merge it to main.
  2. On an up-to-date main with a clean working tree, run npm run release.

release-it runs the typecheck, tests, build and package lint, bumps the version, commits chore: release vX.Y.Z, tags vX.Y.Z, pushes, and publishes to npm. You need npm login as a package maintainer (npm prompts for a 2FA code) and push access to the GitHub repo.

"private": true in package.json blocks publishing until the package is cleared for its first release.

Security

See SECURITY.md to report a vulnerability.

License

Apache-2.0