@d0fi/account-sdk
v0.2.1
Published
D0 Account authentication and non-custodial L1 wallet SDK
Readme
@d0fi/account-sdk
This package owns the product-facing D0 Account API and keeps the L1 wallet provider behind an adapter boundary.
It provides authentication, Account session management, pairwise payer authorization, and non-custodial L1 wallet capabilities. Payment collection, payment method selection, Checkout Session execution, refunds, and disputes belong to the separate Checkout SDK and Checkout API.
npm install @d0fi/account-sdkUse the smallest entry point required by the host:
import { D0AccountSdk, HttpAccountApiClient } from "@d0fi/account-sdk/core";
import { MagicL1WalletAdapter } from "@d0fi/account-sdk/magic";React hosts import the component entry and its compiled stylesheet. The CSS contains only the Account Kit theme/utilities and does not include Tailwind's global Preflight reset.
import { D0AccountKit } from "@d0fi/account-sdk/react";
import "@d0fi/account-sdk/styles.css";The root @d0fi/account-sdk entry remains available for compatibility. New
integrations should use the explicit subpath entries so core-only hosts do not
load Magic or React code.
const sdk = new D0AccountSdk({
appId: "merchant-app",
environment: "sandbox",
adapter: new MagicL1WalletAdapter({ publishableKey }),
verifyProviderToken: async (token) => {
await fetch("/api/auth/magic/verify", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ token }),
});
},
});
const challenge = await sdk.authentication.requestEmailOtp(email);
const session = await sdk.authentication.verifyEmailOtp(challenge.challengeId, otp);
const user = await sdk.user.getInfo();
const wallets = sdk.wallets.list();
const signature = await sdk.wallets.signMessage({ chain: "solana", message });
const typedSignature = await sdk.wallets.signTypedData({
method: "eth_signTypedData_v4",
typedData,
});Production uses the D0 Account API as the identity authority. The browser never
receives a global D0 account identifier; session.subject, accountId, and
appScopedSubject are the same merchant-sector pairwise subject.
const sdk = new D0AccountSdk({
appId: "merchant-production-account",
environment: "production",
adapter: new MagicL1WalletAdapter({ publishableKey }),
accountApi: new HttpAccountApiClient({
baseUrl: "https://account.d0fi.com",
}),
});Account environment selects the identity environment, not the wallet network.
The Magic adapter defaults to Ethereum Sepolia and Solana devnet; configure
evmNetworks and solanaRpcUrl explicitly for your deployment. Solana network
metadata and the default SIWS chain use the same resolved RPC configuration.
Production initialization fails closed if accountApi is absent. Magic email
and OAuth sessions exchange a short-lived DID token through the Account BFF.
The SDK generates an RFC 7636 S256 verifier/challenge and nonce, receives a
single-use authorization code, and keeps the resulting opaque access token only
inside the API client instance. Public clients do not receive refresh tokens.
In API-backed sessions, user.getInfo() replaces the provider subject with the
D0 pairwise subject, while getIdToken() and generateIdToken() reject provider
token export.
Production SIWE uses the separate D0 wallet-proof flow. The adapter only connects
the EIP-1193 wallet and signs the exact, short-lived D0 challenge; D0 verifies
personal_sign, consumes the challenge once, and issues the same PKCE-bound
authorization code used by other login methods. It does not trust a browser-
supplied address or use Magic's SIWE message as D0 identity proof. Phantom uses
the parallel SIWS flow: it signs the exact D0 message bytes, D0 verifies the
detached Ed25519 signature against the Base58 Solana address, and consumes the
PKCE-bound challenge once. Signatures and plaintext messages are not stored.
After API-backed SIWE, EVM message signing, Typed Data signing and transaction
submission use the external wallet connection without requiring a Magic login.
The adapter checks that the active address and chain still match the connection
before requesting a signature. Reconnect and sign in after an account change;
use wallets.switchNetwork() for an intentional switch to a configured network.
Identity linking uses the same-origin Account Portal session. Its HTTP client
forwards the Portal CSRF cookie as x-d0-csrf; a missing or invalid cookie remains
a server-side rejection. This is separate from the merchant public-client login
flow.
For the complete embedded UI, the host application only controls visibility:
<D0AccountKit
sdk={sdk}
open={accountKitOpen}
onClose={() => setAccountKitOpen(false)}
/>To place the same kit directly in a page, use inline. Inline kits are always
visible, ignore open, and do not create a backdrop, close control, focus trap,
or body scroll lock:
<D0AccountKit
sdk={sdk}
inline
open
onClose={() => {}}
/>Authentication screens, the authenticated account view, wallet discovery and message signing are implemented inside the SDK component rather than the host.
authentication, user, and wallets are separate public capability domains,
matching the conceptual split in Magic while keeping D0-owned API names and UI. The UI
never imports or calls Magic directly. MockL1WalletAdapter implements the
same contract for isolated SDK development; the real integration demo does not
fall back to mock mode.
Scope and execution boundary
- Implemented: custom email + OTP flow, D0 account/session projection, EVM and Solana L1 wallet projection, Magic OAuth redirect, reusable React Login Kit, user/session methods, EVM personal and Typed Data v3/v4 signing, EVM transaction submission, Solana message signing, Magic wallet widgets, Magic and mock adapters.
- Implemented server boundary: Magic token exchange, SIWE and SIWS wallet-proof exchange, persistent identity resolution, replay protection, and merchant-sector pairwise subjects.
- External execution still required: KYC provider, Cashier/Indexer callbacks, payment-rail execution, chain broadcast, notifications, and production infrastructure.
- Never accepted by the browser SDK: a Magic secret key.
Settings, MFA, recovery, private-key export, transactions, and hosted wallet UI must remain explicit product-policy decisions. The adapter exposes the provider capability; it does not make the action safe or authorized for production.
