Writing an adapter
An adapter is one plain object. It says what the row is called, how to tell whether it works on this page, and how to sign in. The built-in UI draws everything from that object, so a new adapter works in every framework without writing UI.
Where it lives
To add one to sigport itself, create packages/core/src/adapters/<id>/index.ts:
packages/core/src/adapters/
├── extension/ index.ts, catalog.ts
├── remote/ index.ts, catalog.ts
├── metamask/ index.ts, signer.ts, logo.ts
├── onekey/ index.ts, logo.ts
├── okx/ index.ts, logo.ts
├── passkey/ index.ts, signer.ts
├── local/ index.ts
├── readonly/ index.ts
├── guest/ index.ts
└── _shared/ helpers, not an adapterThe build turns every folder into @sigport/core/adapters/<id>. To put it in all(), add it to src/all.ts.
In your own app, an adapter can live in any file.
One click
import { defineAdapter } from '@sigport/core';
export const myWallet = () =>
defineAdapter({
id: 'my-wallet',
kind: 'wallet',
label: 'My Wallet',
note: 'Key from your wallet',
logo: '/my-wallet.svg',
links: { info: 'https://example.com/docs', download: 'https://example.com/download' },
detect: ({ scope }) => (scope.myWallet?.nostr ? 'ready' : 'missing'),
connect: ({ scope }) => MyWalletAccount.connect(scope),
accounts: [MyWalletAccount],
});Then offer it next to the others:
createSigport({ adapters: [...all(), myWallet()] });The fields
| Field | Required | Meaning |
|---|---|---|
id | yes | Unique. Used by include, exclude and choose(id) |
kind | yes | How the list ranks it (below) |
label, note | yes | Row title and subtitle |
icon / logo | 24×24 stroke paths, or an image URL | |
links | info and download URLs, used when it can't be used here | |
notes | Subtitles per availability: missing, outdated, unsupported | |
detect | Returns ready, missing, outdated or unsupported. Must never prompt. Always ready without it | |
connect | One click: returns an applesauce IAccount | |
view | A form or pairing code (below) | |
catalog | Apps that provide it (below) | |
accounts | Account classes to restore remembered accounts | |
unlock | How a remembered account is unlocked | |
setup | Runs once per session: global setup such as a relay pool |
Kinds
The list is ranked by kind, never by id:
| Kind | Placement |
|---|---|
extension | Leads when usable. Always listed; opens its catalog when absent |
wallet | Leads when there is no extension |
remote | Second after an extension; lower otherwise |
passkey | Leads for newcomers |
create | Makes a new key |
readonly | Signs nothing |
look | A throwaway key |
Anything that is not ready (except an extension) moves behind Other sign-in options. It links to links.download when missing or outdated, and to links.info when unsupported.
Forms and pairing codes
view: (app) => ({
title: 'My signer',
lede: 'Paste the token your signer shows.',
fields: [{ name: 'token', label: 'Token', mono: true, placeholder: 'tok_…' }],
actions: [
{
id: 'connect',
label: 'Connect',
primary: true,
needs: ['token'],
run: async ({ values, signal }) => MyAccount.fromToken(values.token!, { signal }),
},
],
pairing: {
label: 'Show a pairing code',
start: async ({ signal, app }) => {
const session = await openSession(app);
return { uri: session.uri, account: session.waitForAccount(signal) };
},
},
}),- A row with a
viewand noconnectshows a chevron and slides to the view. needskeeps a button disabled until those fields have something in them.fields: ['name']on an action draws only those fields with that button.runreturns an account to sign in, or nothing to stay on the view.signalaborts when the person goes back.
Catalogs
catalog: [
{ id: 'acme', name: 'Acme Signer', platforms: 'Android', href: 'https://example.com/acme', link: 'download' },
{ id: 'web', name: 'Web Signer', platforms: 'Web', href: 'https://signer.example', link: 'open', detect: (scope) => Boolean(scope.webSigner) },
],With a catalog:
- A usable one-click row gets an ⓘ square that slides to the list.
- A missing row opens the list.
- A view lists the apps under its form.
Unlocking remembered accounts
unlock: {
needs: (account) => account instanceof MyAccount && !account.unlocked,
run: (account) => (account as MyAccount).unlock(), // a prompt, run from the click
// or a form:
view: (account) => ({ title: 'Unlock', fields: [/* … */], actions: [/* … */] }),
},Errors
Throw new Error('reason:detail'), where the reason is denied, unavailable or invalid. Give your codes words with createSigport({ messages }). Any other message is shown as written. See Errors.
Rules
- Never prompt in
detect. - Read
windowonly inside functions, never at import time. - Verify what a wallet returns, using
checkedWalletKeyandcheckedWalletEvent. - Never persist a plaintext key.
nsecandseed-wordsaccount types are refused.
Testing
const sigport = createSigport({ adapters: [myWallet()], storage: null, scope: { myWallet: fake } as never });
expect((await sigport.detect()).shown[0]).toMatchObject({ id: 'my-wallet', emphasis: 'top' });
await sigport.choose('my-wallet');
expect(sigport.getState().active?.pubkey).toBe(expected);