@pacrypto55/privy-2fa
v1.1.0
Published
Privy TOTP two-factor authentication for Orderly DEXes. Lets a connected user enable/disable 2FA (QR enrollment + verification code) and auto-triggers Privy's MFA challenge right after login. Adds itself as a row in the shared @pacrypto55/wallet-menu 'Pri
Readme
@pacrypto55/privy-2fa
Privy TOTP two-factor authentication for Orderly Network DEXes. Lets a connected user enable/disable 2FA (QR code enrollment + verification code) and auto-triggers Privy's own MFA challenge right after login. Adds itself as a row in the shared @pacrypto55/wallet-menu "Privy Wallet" button — installing this plugin alone is enough, it registers the host automatically if it isn't already.
Install
npm install @pacrypto55/privy-2fa
# or
pnpm add @pacrypto55/privy-2fa
# or
yarn add @pacrypto55/privy-2faPeer dependencies: react, react-dom, @privy-io/react-auth, @orderly.network/plugin-core, @orderly.network/ui, @orderly.network/ui-scaffold, and @pacrypto55/wallet-menu (all installed automatically alongside it). QR code rendering (qrcode.react) is bundled into this package directly rather than left as a peer dependency, so it can't be shadowed by an unrelated, incompatible version another package in your app happens to pull in.
Usage
import { registerPrivy2faPlugin } from "@pacrypto55/privy-2fa";
<OrderlyAppProvider
plugins={[registerPrivy2faPlugin() /* , ...your other plugins */]}
// ...
>
{/* your app */}
</OrderlyAppProvider>;That's it — no manual wiring needed. The "Privy Wallet" button appears in the top nav bar the first time any plugin that depends on it (this one, or @pacrypto55/privy-onramp) is registered.
With custom options
registerPrivy2faPlugin({
enableLabel: "Enable 2FA",
disableLabel: "Disable 2FA",
disableWarning: "Are you sure you want to disable two-factor authentication? This will make your account less secure.",
signMessage: "Sign this message for 2FA verification", // signed right after login to establish the MFA session
})What it does
- Enable/Disable 2FA row in the Privy Wallet menu: walks the user through TOTP enrollment (QR code + manual key + 6-digit verification) via Privy's
useMfaEnrollment(), or unenrolls with a confirmation step. - Post-login MFA trigger: right after a user with 2FA already enabled logs in, silently requests a
personal_signfrom their embedded wallet to establish the MFA session before any other dialog can open — this is what makes Privy's own MFA popup work reliably instead of racing with other UI.
API
registerPrivy2faPlugin(options?)
| Property | Type | Default | Description |
|---|---|---|---|
| enableLabel | string | "Enable 2FA" | Row label when 2FA is not yet enabled. |
| disableLabel | string | "Disable 2FA" | Row label (and dialog title) when 2FA is already enabled. |
| disableWarning | string | see above | Confirmation copy shown before disabling. |
| signMessage | string | "Sign this message for 2FA verification" | Message signed by the embedded wallet right after login to establish the MFA session. |
Development
npm install
npm run dev # tsup --watch
npm run build
npm run typecheckLicense
MIT
