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

@p2p-trust-stack/app-api

v0.2.0

Published

P2P Trust Stack app API — the agent runtime, host seam, DTOs and domain interfaces that applications program against.

Readme

@p2p-trust-stack/app-api

The application-facing API of the P2P Trust Stack. This is the single module an application imports: createAgentStack() returns a typed TrustStack whose domains cover identity, connectivity, relationships, messaging, credentials, communities, names, profiles, contexts and delegations — plus a closed event catalogue and the Host seam.

app-api depends on @p2p-trust-stack/core; core never depends on app-api.

Install

npm install @p2p-trust-stack/app-api

@p2p-trust-stack/core is installed with it.

Requires Node.js >= 22.5 (uses the built-in node:sqlite). Node-only — there is no browser build.

Quick start

import { createAgentStack } from '@p2p-trust-stack/app-api';

const stack = await createAgentStack({ agent: { name: 'alice', passphrase: '…' } });

stack.on('message.received', (e) => console.log('message from', e.peerDid));
stack.on('connection.open', (e) => console.log('peer up', e.peerId));

await stack.start();

const me = await stack.identity.current();
const oobi = await stack.relationships.oobi();
await stack.relationships.connect(peerOobi);
await stack.messaging.send(peerDid, 'hello', { confidential: true });

await stack.stop();

createAgentStack() creates (or unlocks) the agent but does not start it — subscribe first, then call start(), so no event is missed.

The TrustStack surface

| Domain | Methods | |---|---| | identity | current, sign, list, create, import, activate, deactivate, recoveryState, lookup | | connectivity | health, ready, status, refresh, connectUtility, utilityStatus, pushIdentity, networkProfile, networkChanged, explainFailure | | relationships | oobi, connect, connectDiscovered, reconnect, duplicateNotice, list, get, disconnect, acknowledge, ceremonyStatus, resetCeremony, verify, vrc, dtgVrc, graph, debug | | messaging | send, transcript, latest, unread, clear | | credentials | list, issue, verify, signatures, revoke, invitations, declineInvitation, acceptInvitation, viewModels | | communities | list, governanceDocs, detail, checkName, parents, adminCandidates, invite, create, governanceProposals, propose, approve, ceremonyLog, ceremonyLogThread, pendingCeremonies, approveCeremony, ceremony, resetCeremony | | names | register, resolve, revoke, list | | profiles | list, create, update, remove, claims, addClaim, updateClaim, removeClaim, card, syncStatus | | contexts | provision, list, revoke, get, isExpired | | delegations | list, create, revoke |

Events

The event catalogue is closed (STACK_EVENTS): 30 names covering identity, connectivity, messaging, relationships, credentials & invitations, communities & governance, names & profiles, sync, and errors. Subscribe with stack.on(name, handler); replay retained events with stack.replay(...) / stack.replayDurable(...), and take a resumable cursor with stack.cursor().

The Host seam

createNodeHost() is the Node binding: it owns P2PTS_HOME and the per-agent layout (directory, database, keystore) and provides createAgent / unlockAgent. Pass your own Host to createAgentStack({ host }) for a non-Node embedding.

Capability scoping

stack.asContext(contextId, { allow }) returns a deny-by-default view of the stack for one provisioned app context. Anything not explicitly allowed — including every unclassified method — is refused.

Logging

All stack logging (both app-api and the core it embeds) goes through one dependency-free gate, @p2p-trust-stack/core/util/logger. Verbosity is controlled by the P2PTS_LOG_LEVEL environment variable — or programmatically with setLogLevel() — and defaults to warn, so the stack is quiet unless you ask for more.

| Level | Emits | |---|---| | silent | nothing | | error | errors only | | warn | errors + warnings (default) | | info | + lifecycle / state changes | | debug | + per-message wire traces |

P2PTS_LOG_LEVEL=info node my-app.js
import { setLogLevel, setLogSink } from '@p2p-trust-stack/core/util/logger';

setLogLevel('silent');
setLogSink((level, args) => myLogger[level](...args));   // route instead of suppress

Or from a config file, if a script cannot set a variable

P2PTS_LOG_LEVEL=info node … is POSIX-shell syntax: it cannot go in a package.json script that must also run on Windows, and there is no npm script at all where a native host launches Node (Capacitor). createLoggingConfigApi keeps the setting in the app's .env instead — the same file the bootstrap block lives in:

import { createLoggingConfigApi } from '@p2p-trust-stack/app-api';

const logging = createLoggingConfigApi({ envPath: '/etc/my-app/.env' });

logging.apply();   // reads the .env and applies it; cannot throw
logging.view();    // { level, ceremonyTrace, source: 'env' | 'default' }
# .env
P2PTS_LOG_LEVEL=info
CEREMONY_TRACE=1

The resolved order is setLogLevel() > the app's .env > P2PTS_LOG_LEVEL > the default, so an explicit call always wins and the environment variable keeps working. A missing or malformed .env is never fatal. CEREMONY_TRACE=1 is independent of the level — it emits the [CEREMONY] OOBI→RFI→RFA trace lines and is not silenced by silent, nor switched on by debug.

License

Dual-licensed under GPL-3.0-only or a commercial license — see the repository's LICENSE and NOTICE, and COMMERCIAL-LICENSE.md for the commercial terms.