Skip to content

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 adapter

The 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 ​

ts
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:

ts
createSigport({ adapters: [...all(), myWallet()] });

The fields ​

FieldRequiredMeaning
idyesUnique. Used by include, exclude and choose(id)
kindyesHow the list ranks it (below)
label, noteyesRow title and subtitle
icon / logo24×24 stroke paths, or an image URL
linksinfo and download URLs, used when it can't be used here
notesSubtitles per availability: missing, outdated, unsupported
detectReturns ready, missing, outdated or unsupported. Must never prompt. Always ready without it
connectOne click: returns an applesauce IAccount
viewA form or pairing code (below)
catalogApps that provide it (below)
accountsAccount classes to restore remembered accounts
unlockHow a remembered account is unlocked
setupRuns once per session: global setup such as a relay pool

Kinds ​

The list is ranked by kind, never by id:

KindPlacement
extensionLeads when usable. Always listed; opens its catalog when absent
walletLeads when there is no extension
remoteSecond after an extension; lower otherwise
passkeyLeads for newcomers
createMakes a new key
readonlySigns nothing
lookA 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 ​

ts
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 view and no connect shows a chevron and slides to the view.
  • needs keeps a button disabled until those fields have something in them.
  • fields: ['name'] on an action draws only those fields with that button.
  • run returns an account to sign in, or nothing to stay on the view.
  • signal aborts when the person goes back.

Catalogs ​

ts
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 ​

ts
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 window only inside functions, never at import time.
  • Verify what a wallet returns, using checkedWalletKey and checkedWalletEvent.
  • Never persist a plaintext key. nsec and seed-words account types are refused.

Testing ​

ts
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);

MIT licensed.