Passkeys and sign-in

Create a passkey signer, load one you made earlier, and authenticate a returning user.

A passkey is a P-256 key held by the user's device and unlocked with Face ID, Touch ID or a security key. Galactic never receives the private key. Each signature the user makes is checked on the server against the public key stored when the signer was created.

Create a signer

const signer = await sdk.signers.create({ inviteCode: 'FRIEND-123' })

signer.id             // stable signer id
signer.kind           // 'secp256r1'
signer.preferredChain // { id: 8453 }

What happens, in order:

  1. The SDK asks the server for a registration challenge. If you pass inviteCode, the server validates and redeems it here. This is the real invite gate. A front-end check is only a convenience.
  2. The WebAuthn adapter creates the passkey, with the challenge hash as the WebAuthn challenge. The user sees one prompt.
  3. The SDK sends the attestation to the server in the same request that creates the signer. There is no second prompt.
  4. The SDK loads the full signer and returns a SignerClient.

In a browser the SDK remembers the credential id in localStorage. This is optional: quote and sign calls use the credential id of the account's signer, then the stored one, then the passkey picker. Where there is no window (Node, React Native, a service worker), supply a WebAuthnAdapter for your platform.

Load a signer

const signer = await sdk.signers.get({ id: 'sig_…' })

Results are kept for a few seconds so that a sign-in followed by accounts.create does not fetch the same signer twice.

Sign in again

// Show the passkey picker (discoverable credential).
const { signer, account } = await sdk.signers.authenticate()

// Or name the credential you want.
const again = await sdk.signers.authenticate({ credentialId: stored })

authenticate asks the server for a challenge, has the passkey sign it, and the server verifies the signature. You get the signer and, if the signer already controls an account, account.id. Use sdk.accounts.create({ signer }) with the returned signer to get a ready AccountClient.

Bring your own adapter

All passkey operations go through a small interface, so you can use a native module, a hardware key, or a test double.

interface WebAuthnAdapter {
  createCredential(p: { name: string; challenge: string }):
    Promise<{ id: string; publicKey: `0x${string}`; raw: PublicKeyCredential }>
  sign(p: { credentialId?: string; hash: `0x${string}` }):
    Promise<{ signature: string; webauthn: {...}; raw: PublicKeyCredential }>
}

const sdk = new DattEx({ /* … */, webauthnAdapter: new MyNativeAdapter() })

Two adapters ship with the SDK: WebAuthnP256Adapter (the browser default) and MockWebAuthnAdapter (see Testing).