How a package becomes part of this wallet, written for whoever builds the package — a person or an AI agent — and for whoever registers it here.
The wallet is thin. Features such as verifying credentials, sharing them, or showing QR codes are plugins: separate packages that the wallet bundles at build time and mounts in fixed places. This document states what the wallet supplies, what a plugin package must look like, how it is distributed, and what is added to the wallet to register it.
The source of truth for the types quoted here is
src/plugins/types.ts. If this document and that
file disagree, the file is right.
A plugin is a React component bundled into the wallet's build. The wallet
renders it and passes one prop, host, an object that gives it the signed-in
session and a few services. The plugin receives nothing else: it does not read
environment variables, localStorage, or the wallet's routes, and it does not
know how the user logged in.
A plugin can appear in two places. One registry entry can fill either or
both: a plugin with no page has no route and no sidebar entry (a verifier
that lives only in the credential detail view, say), and a page can opt out
of the sidebar with menu: false while keeping its route.
| Place | What the wallet renders | Prop(s) |
|---|---|---|
Its own page, with a link in the left sidebar unless it opts out (for example a Verify page at /verify) |
plugin.page.Component inside the wallet's chrome, behind login |
host |
| The verification panel of the credential detail view (the right-hand panel when a stored credential is opened) | plugin.slots.credentialDetail, in place of the wallet's built-in verifier |
credential, host |
A plugin whose UI is a web component (a custom element) is fine: the
wallet wraps it in a small React component in the registry entry (section 5).
React 19 assigns object-valued JSX props to custom elements as DOM properties,
so <my-element credential={object} /> works with no ref.
import type { PwsClient } from '@interop/pws-client';
export interface WalletHost {
// The signed-in session's PWS client; null when the session is gone.
getSession(): Promise<{ client: PwsClient } | null>;
// Call this when a PWS or back-end request is rejected as unauthorized;
// the wallet clears the session and returns to the login page.
onUnauthorized(): void;
}Rules that follow from it:
- Session. Call
host.getSession()when you need the PWS client; do not cache the client across user actions, because it isnullonce the session ends. Through it you reach the user's spaces and collections with the@interop/pws-clientAPI (client.space(id).collection(name).get/put/add/list…). Collections the wallet created are end-to-end encrypted; the client decrypts and encrypts transparently, so a plugin reads and writes plain objects. - Errors. When a PWS or back-end call is rejected as unauthorized
(HTTP 401/403), call
host.onUnauthorized()and stop. Show every other error in your own UI. - Configuration. Anything host-specific that is not in
WalletHost(an API key, a list of trust registries, a feature switch) is passed by the wallet's registry entry (section 5) as a prop or property of your component. Expose it as a prop; do not read it from the environment. - Nothing else. No
import.meta.env, nowindow.localStorage, noreact-routerimports in the package. If your page needs navigation state from the wallet (which stored credential to open, say), the registry entry reads it and passes it as a prop.
The credentialDetail slot additionally receives:
credential: Record<string, unknown> | nullthe stored credential with its presentation envelope removed (the
verifiableCredential[0] of a stored { verifiableCredential: [...] }
document, or the document itself when it is a bare credential), or null
when the opened resource is not a credential. The slot component stays
mounted while the spaces page is open and is hidden with CSS when no
credential is open; credential is then null, and it changes whenever the
user opens another credential. Clear your previous result when it changes
or becomes null. Do not depend on staying mounted either: the page itself
unmounts when the user navigates away.
The wallet is Vite 8, React 19, TypeScript 6, Tailwind CSS 4, ES modules.
Build output. One ES module entry (dist/index.js) with type
declarations (dist/index.d.ts), declared in package.json:
{
"type": "module",
"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } },
"files": ["dist", "LICENSE", "README.md"]
}Shared dependencies stay external. The wallet already bundles React,
ReactDOM and @interop/pws-client; a second copy of React breaks hooks, and
a second pws-client cannot share the session. Declare them as
peerDependencies and mark them external in your bundler
(rollupOptions.external: [/^react($|\/)/, /^react-dom($|\/)/, '@interop/pws-client']).
A library that nothing in the wallet shares — a verification library, a CSV
parser, a QR encoder — may be bundled in or listed as a regular dependency,
either works. If two copies of a library would be wrong (one of them holds
global state), bundle it in so the version is yours.
Side effects. If importing your package registers a custom element
(customElements.define) or does anything else on import, do not set
"sideEffects": false, or the bundler may drop the import. A pure React
component library may set it.
Styling — pick one:
- Tailwind class names in JSX, no CSS shipped. The wallet compiles
them: the registry entry adds
@source "../node_modules/@digitalcredentials/<package>/dist";tosrc/index.css. The plugin then shares the wallet's theme. Only works in a Tailwind host. - A shadow root with its own styles (web components). Self-contained, host independent. Expose CSS custom properties for colours and fonts so the wallet can match its palette by setting them on the element.
- A CSS file in
dist/that the registry entry imports.
Web components additionally:
- Set inputs as properties (the credential object, options), not
attributes, since attributes are strings. Report results as DOM
CustomEvents on the element. - Ship JSX typings so a React host does not write its own: a
.d.tsindist/that augmentsReact.JSX.IntrinsicElementswith your tag and its properties, re-exported fromindex.d.ts. Without it the wallet keeps asrc/types/<name>.d.ts, which goes stale. - Handle detach/reattach: React removes and re-inserts elements. Do work in
connectedCallback(or defer it there when a property is set while detached), and never assume one mount per page load.
Public surface. Export the component (or register the element), the props/adapter type, and nothing the wallet does not need. Document in your README the registry entry the wallet should contain (section 5), including any configuration prop.
One of these; the wallet's package.json names which. Every plugin, from its first integration, is taken from a published package or a release branch, so that a wallet build never depends on a checkout on someone's machine.
| Method | package.json entry |
When |
|---|---|---|
| npm | "@scope/name": "^1.2.3" |
the package is published |
| GitHub release branch (current practice) | "@scope/name": "github:org/repo#release" |
the package is not published yet. A workflow in the plugin repo builds dist/ on every push to main and force-pushes it with package.json, LICENSE and README.md to a release branch. npm install clones that branch and runs none of the package's scripts, so the wallet needs none of the plugin's build tools. The wallet's lock file pins the commit; npm update @scope/name moves it. Reference implementation: verifier-plugin .github/workflows/release.yml (a build job with a read-only token, a publish job that installs nothing). |
Do not rely on a prepare script that builds on install: it makes every
wallet npm install run the plugin's toolchain, and fails on machines
without it.
One file per plugin in src/plugins/, plus one line in
src/plugins/index.ts. The entry maps
WalletHost onto whatever the package expects and carries any host-specific
configuration. The wallet generates the route, the sidebar link and the
detail-view slot from the entry; nothing else in the wallet changes.
export interface WalletPlugin {
id: string; // unique among registered plugins
title: string; // the plugin's name; the sidebar label of its page
page?: { // omit for a plugin with no page of its own
path: string; // route and sidebar link target, e.g. '/verify'
description?: string;// sidebar link tooltip
menu?: boolean; // false: keep the route, show no sidebar link
Component: ComponentType<{ host: WalletHost }>;
};
slots?: {
credentialDetail?: ComponentType<{ credential: Record<string, unknown> | null; host: WalletHost }>;
};
}A React-component plugin that takes an adapter of its own is registered the
same way: the entry's component builds that adapter from host, adds any
wallet-side calls the package needs, and renders the package's component
with it.
Example — a web-component plugin that appears only in the credential detail view (no page, so no route and no sidebar entry):
// src/plugins/Verifier.tsx
import '@digitalcredentials/verifier-plugin'; // registers <verifier-credential>
import type { WalletHost } from './types';
// Simplified: the real one loads DCC's list of known registries, holds the
// credential back until it arrives, and says so if it doesn't.
const REGISTRIES = [{ name: 'DCC Sandbox Registry', type: 'dcc-legacy', url: 'https://…/registry.json' }];
// The credential detail slot: the card for the opened credential.
export function VerifierDetail({ credential }: { credential: Record<string, unknown> | null; host: WalletHost }) {
return <verifier-credential credential={credential ?? undefined} registries={REGISTRIES} />;
}// src/plugins/verifierPlugin.ts
export const verifierPlugin: WalletPlugin = {
id: 'verifier',
title: 'Verifier',
slots: { credentialDetail: VerifierDetail },
};To give such a plugin a page as well — a standalone verify screen where the
wallet supplies the credential (paste, upload, or a pick from the user's
collections via host.getSession()) — add page: { path: '/verify', description: 'Check a credential', Component: VerifierPage }; add
menu: false to it if the page should be reachable only by navigation.
Then the entry in plugins in index.ts (today
plugins: WalletPlugin[] = [verifierPlugin]), the dependency in
package.json, and (Tailwind plugins only) the @source line in
src/index.css.
- ES module build at
dist/index.jswithdist/index.d.ts;exportsandfilesset as in section 3. -
react,react-dom(and@interop/pws-clientif used) arepeerDependenciesand external in the bundle; everything else bundled or a regular dependency. - No reads of
import.meta.env,localStorage, or the router; all inputs arrive as props/properties; unauthorized errors reported throughhost.onUnauthorized()(or surfaced so the registry entry can). - Styling by one of the three methods in section 3; a web component exposes CSS custom properties.
- Web components ship JSX typings, take objects as properties, emit events, and tolerate detach/reattach.
-
sideEffectsnot set tofalseif the import registers anything. - Distributed by npm or by a
releasebranch built frommain(the verifier-plugin workflow is the reference); nopreparebuild. - README shows the wallet registry entry: the component(s), the props the wallet must pass, and any configuration.
- Dependency in
package.json(npm version orgithub:…#release); lock file committed. -
src/plugins/<name>Plugin.ts(+ a.tsxwrapper when the package is a web component or needs wallet-side calls), appended topluginsinsrc/plugins/index.ts. -
@sourceline insrc/index.cssfor Tailwind-class plugins. - A deployed test in
tests/deployed.spec.tsthat opens the page (and the slot, if filled). - README's plugin list updated.