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

@sanna-ai/core

v1.1.0

Published

Core library for the Sanna protocol

Downloads

570

Readme

@sanna-ai/core

TypeScript SDK for the Sanna protocol — an open AI governance framework that enforces constitutional boundaries on AI agents through cryptographic receipts. Constitutions define what an agent can and cannot do; receipts provide tamper-evident proof that every action was evaluated against those rules.

Implements Sanna Protocol v1.1.

Install

npm install @sanna-ai/core

Requires Node.js 22+ (native Ed25519 support).

Quick Start

import {
  loadConstitution,
  verifyConstitutionSignature,
  loadPublicKey,
  loadPrivateKey,
  evaluateAuthority,
  generateReceipt,
  signReceipt,
  verifyReceipt,
} from "@sanna-ai/core";

// 1. Load and verify a constitution
const constitution = loadConstitution("constitution.yaml");
const authorKey = loadPublicKey("author.pub");
const valid = verifyConstitutionSignature(constitution, authorKey);

// 2. Evaluate an action against the constitution
const decision = evaluateAuthority(
  "database.write",
  { table: "users", operation: "delete" },
  constitution,
);
// decision.type → "can_execute" | "cannot_execute" | "must_escalate"

// 3. Generate a receipt
const receipt = generateReceipt({
  correlation_id: "req-001",
  inputs: { query: "Delete user 42", context: "admin panel" },
  outputs: { response: "User deleted" },
  checks: [
    { check_id: "auth-check", passed: true, severity: "critical", evidence: null },
  ],
});

// 4. Sign the receipt
const privKey = loadPrivateKey("author.key");
signReceipt(receipt as unknown as Record<string, unknown>, privKey, "[email protected]");

// 5. Verify a receipt
const result = verifyReceipt(receipt as unknown as Record<string, unknown>, authorKey);
// result.valid → true
// result.checks_performed → ["schema", "signature", "fingerprint", "content_hashes", ...]

API Reference

Hashing

  • canonicalize(obj) — RFC 8785 JSON Canonicalization Scheme
  • hashBytes(data) — SHA-256 of raw bytes (hex string)
  • hashContent(data, truncate?) — SHA-256 with NFC + line-ending normalization
  • hashObj(obj) — canonicalize then SHA-256
  • EMPTY_HASH — SHA-256 of empty input

Crypto

  • generateKeypair(label?) — generate Ed25519 keypair
  • sign(data, privateKey) — Ed25519 sign, returns base64
  • verify(data, signature, publicKey) — Ed25519 verify
  • loadPrivateKey(path) — load PKCS#8 PEM private key
  • loadPublicKey(path) — load SPKI PEM public key
  • getKeyId(key) — SHA-256 of raw 32-byte Ed25519 public key
  • exportPrivateKeyPem(key) — export private key as PEM string
  • exportPublicKeyPem(key) — export public key as PEM string

Constitution

  • loadConstitution(path) — load and parse YAML constitution
  • parseConstitution(data) — parse raw object to typed Constitution
  • validateConstitutionData(data) — validate structure, returns error list
  • verifyConstitutionSignature(constitution, publicKey) — verify Ed25519 signature
  • computeFileContentHash(path) — SHA-256 content hash of a file

Authority Evaluator

  • evaluateAuthority(action, params, constitution) — 4-tier policy cascade evaluation
  • normalizeAuthorityName(name) — normalize action name per Appendix D

Receipt

  • generateReceipt(params) — create a complete receipt with hashes and fingerprints
  • signReceipt(receipt, privateKey, signedBy) — Ed25519 sign a receipt
  • computeFingerprints(receipt) — compute 16-hex and 64-hex fingerprints
  • computeFingerprintInput(receipt) — compute the 14-field pipe-delimited input
  • SPEC_VERSION — protocol version ("1.1")
  • CHECKS_VERSION — checks schema version ("6")

Verifier

  • verifyReceipt(receipt, publicKey?) — verify schema, signature, fingerprint, content hashes, status consistency, and timestamp

Types

Constitution, Boundary, HaltCondition, TrustTiers, TrustedSources, ConstitutionSignature, Provenance, AgentIdentity, Invariant, EscalationTargetConfig, EscalationRule, AuthorityBoundaries, AuthorityDecision, AuthorityDecisionType, BoundaryType, Receipt, CheckResult, ReceiptSignature, Enforcement, ConstitutionRef, VerificationResult, SannaKeypair, KeyObject, ReceiptParams

Cross-Language Compatibility

All hashing, fingerprinting, and signing operations are verified against golden fixtures from the Sanna protocol spec. Receipts generated by the Python SDK verify correctly with this TypeScript SDK, and vice versa.

Related

License

AGPL-3.0 — see LICENSE.