auramaxx 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +26 -0
- package/README.md +77 -0
- package/apps/desktop-electron/main.js +428 -0
- package/bin/auramaxx.js +1063 -0
- package/docs/ADAPTERS.md +466 -0
- package/docs/AGENT_SETUP.md +159 -0
- package/docs/API.md +127 -0
- package/docs/APPS.md +199 -0
- package/docs/ARCHITECTURE.md +235 -0
- package/docs/AUTH.md +318 -0
- package/docs/BEST-PRACTICES.md +82 -0
- package/docs/CLI.md +141 -0
- package/docs/DESKTOP_ELECTRON.md +26 -0
- package/docs/DEVELOPING-APPS.md +453 -0
- package/docs/MCP.md +122 -0
- package/docs/PACKAGING_POLICY.md +19 -0
- package/docs/PERMISSION.md +137 -0
- package/docs/PROTOCOL.md +142 -0
- package/docs/README.md +50 -0
- package/docs/SKILLS.md +132 -0
- package/docs/TROUBLESHOOTING.md +376 -0
- package/docs/WORKSPACE.md +673 -0
- package/docs/agent-auth.md +14 -0
- package/docs/api/authentication.md +79 -0
- package/docs/api/secrets/api-keys.md +28 -0
- package/docs/api/secrets/credentials.md +80 -0
- package/docs/api/secrets/sharing.md +48 -0
- package/docs/api/system.md +41 -0
- package/docs/api/wallets/apps-strategies.md +66 -0
- package/docs/api/wallets/core.md +46 -0
- package/docs/api/wallets/data-portfolio.md +42 -0
- package/docs/aura-file.md +48 -0
- package/docs/core-concepts/FEATURES.md +114 -0
- package/docs/credentials.md +120 -0
- package/docs/external/HOW_TO_AURAMAXX/GETTING_SECRETS.md +33 -0
- package/docs/external/HOW_TO_AURAMAXX/README.md +45 -0
- package/docs/external/getting-started.md +10 -0
- package/docs/external/overview.md +19 -0
- package/docs/external/persona-paths.md +7 -0
- package/docs/external/share-secret.md +76 -0
- package/docs/external/why-aura.md +7 -0
- package/docs/security.md +227 -0
- package/docs/templates/RELEASE_NOTES_TEMPLATE.md +22 -0
- package/docs/wallet/AI.md +508 -0
- package/docs/wallet/DEVELOPING-STRATEGIES.md +713 -0
- package/docs/wallet/README.md +47 -0
- package/docs/wallet/STRATEGY.md +89 -0
- package/next.config.ts +28 -0
- package/package.json +167 -0
- package/postcss.config.mjs +8 -0
- package/prisma/migrations/20260214170000_baseline/migration.sql +511 -0
- package/prisma/migrations/20260216214537_add_passkey_model/migration.sql +18 -0
- package/prisma/migrations/20260217150500_add_credential_access_audit/migration.sql +31 -0
- package/prisma/migrations/20260222090000_update_admin_ttl_default/migration.sql +10 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/schema.prisma +447 -0
- package/public/logo.webp +0 -0
- package/scripts/add-app.js +245 -0
- package/server/abi/SwapHelper.json +438 -0
- package/server/cli/approval.ts +447 -0
- package/server/cli/commands/actions.ts +474 -0
- package/server/cli/commands/api.ts +220 -0
- package/server/cli/commands/apikey.ts +277 -0
- package/server/cli/commands/app.ts +204 -0
- package/server/cli/commands/auth.ts +464 -0
- package/server/cli/commands/cron.ts +24 -0
- package/server/cli/commands/diary.ts +274 -0
- package/server/cli/commands/doctor.ts +1247 -0
- package/server/cli/commands/env.ts +476 -0
- package/server/cli/commands/experimental.ts +69 -0
- package/server/cli/commands/init.ts +798 -0
- package/server/cli/commands/lock.ts +157 -0
- package/server/cli/commands/mcp.ts +285 -0
- package/server/cli/commands/quickhack.ts +86 -0
- package/server/cli/commands/release-check.ts +231 -0
- package/server/cli/commands/restore.ts +314 -0
- package/server/cli/commands/service.ts +320 -0
- package/server/cli/commands/shell-hook.ts +512 -0
- package/server/cli/commands/skill.ts +216 -0
- package/server/cli/commands/start.ts +139 -0
- package/server/cli/commands/status.ts +59 -0
- package/server/cli/commands/stop.ts +36 -0
- package/server/cli/commands/token.ts +180 -0
- package/server/cli/commands/unlock.ts +50 -0
- package/server/cli/commands/vault.ts +1323 -0
- package/server/cli/commands/wallet.ts +209 -0
- package/server/cli/index.ts +280 -0
- package/server/cli/lib/approval-poll.ts +94 -0
- package/server/cli/lib/aura-parser.ts +64 -0
- package/server/cli/lib/credential-create.ts +74 -0
- package/server/cli/lib/credential-resolve.ts +280 -0
- package/server/cli/lib/dotenv-migrate.ts +116 -0
- package/server/cli/lib/dotenv-parser.ts +146 -0
- package/server/cli/lib/escalation.ts +57 -0
- package/server/cli/lib/http.ts +91 -0
- package/server/cli/lib/init-steps.ts +76 -0
- package/server/cli/lib/local-agent-trust.ts +45 -0
- package/server/cli/lib/lock-unlock-helper.ts +71 -0
- package/server/cli/lib/process.ts +162 -0
- package/server/cli/lib/prompt.ts +294 -0
- package/server/cli/lib/theme.ts +240 -0
- package/server/cli/socket.ts +579 -0
- package/server/cli/transport-client.ts +50 -0
- package/server/cron/index.ts +137 -0
- package/server/cron/job.ts +31 -0
- package/server/cron/jobs/balance-sync.ts +436 -0
- package/server/cron/jobs/incoming-scan.ts +506 -0
- package/server/cron/jobs/native-price.ts +70 -0
- package/server/cron/jobs/orphan-cleanup.ts +40 -0
- package/server/cron/jobs/strategy-runner.ts +175 -0
- package/server/cron/scheduler.ts +125 -0
- package/server/index.ts +420 -0
- package/server/lib/adapters/factory.ts +119 -0
- package/server/lib/adapters/index.ts +19 -0
- package/server/lib/adapters/router.ts +297 -0
- package/server/lib/adapters/telegram.ts +645 -0
- package/server/lib/adapters/types.ts +89 -0
- package/server/lib/adapters/webhook.ts +95 -0
- package/server/lib/address.ts +49 -0
- package/server/lib/agent-auth/contracts.ts +1194 -0
- package/server/lib/agent-profiles.ts +419 -0
- package/server/lib/ai.ts +285 -0
- package/server/lib/api-registry/contracts.ts +86 -0
- package/server/lib/api-registry/validation.ts +172 -0
- package/server/lib/apikey-migration.ts +258 -0
- package/server/lib/app-installer.ts +505 -0
- package/server/lib/app-tokens.ts +247 -0
- package/server/lib/approval-link.ts +27 -0
- package/server/lib/auth.ts +314 -0
- package/server/lib/auto-execute.ts +160 -0
- package/server/lib/batch.ts +242 -0
- package/server/lib/cold.ts +1048 -0
- package/server/lib/config.ts +408 -0
- package/server/lib/credential-access-audit.ts +85 -0
- package/server/lib/credential-access-policy.ts +111 -0
- package/server/lib/credential-health.ts +343 -0
- package/server/lib/credential-import.ts +608 -0
- package/server/lib/credential-scope.ts +102 -0
- package/server/lib/credential-shares.ts +190 -0
- package/server/lib/credential-transport.ts +533 -0
- package/server/lib/credential-vault.ts +77 -0
- package/server/lib/credentials.ts +422 -0
- package/server/lib/crypto.ts +8 -0
- package/server/lib/db.ts +58 -0
- package/server/lib/defaults.ts +386 -0
- package/server/lib/dex/index.ts +80 -0
- package/server/lib/dex/relay.ts +235 -0
- package/server/lib/dex/types.ts +59 -0
- package/server/lib/dex/uniswap.ts +370 -0
- package/server/lib/diary.ts +34 -0
- package/server/lib/dont-ask-again-policy.ts +41 -0
- package/server/lib/e2e-agent/artifacts.ts +36 -0
- package/server/lib/e2e-agent/contracts.ts +112 -0
- package/server/lib/e2e-agent/validation.ts +135 -0
- package/server/lib/encrypt.ts +114 -0
- package/server/lib/error.ts +20 -0
- package/server/lib/events.ts +217 -0
- package/server/lib/feature-flags.ts +93 -0
- package/server/lib/hot.ts +357 -0
- package/server/lib/human-action-summary.ts +80 -0
- package/server/lib/key-fingerprint.ts +28 -0
- package/server/lib/logger.ts +340 -0
- package/server/lib/network.ts +137 -0
- package/server/lib/notifications.ts +230 -0
- package/server/lib/oauth2-refresh.ts +241 -0
- package/server/lib/oursecret.ts +71 -0
- package/server/lib/passkey-credential.ts +360 -0
- package/server/lib/passkey.ts +68 -0
- package/server/lib/permissions.ts +299 -0
- package/server/lib/pino.ts +24 -0
- package/server/lib/policy-preview.ts +138 -0
- package/server/lib/price.ts +338 -0
- package/server/lib/prices.ts +34 -0
- package/server/lib/project-scope.ts +297 -0
- package/server/lib/resolve-action.ts +328 -0
- package/server/lib/resolve.ts +36 -0
- package/server/lib/secret-gist-share.ts +296 -0
- package/server/lib/sessions.ts +634 -0
- package/server/lib/socket-path.ts +56 -0
- package/server/lib/solana/connection.ts +26 -0
- package/server/lib/solana/jupiter.ts +128 -0
- package/server/lib/solana/transfer.ts +108 -0
- package/server/lib/solana/wallet.ts +136 -0
- package/server/lib/strategy/emits.ts +21 -0
- package/server/lib/strategy/engine.ts +1305 -0
- package/server/lib/strategy/executor.ts +115 -0
- package/server/lib/strategy/hook-context.ts +159 -0
- package/server/lib/strategy/hooks.ts +990 -0
- package/server/lib/strategy/index.ts +28 -0
- package/server/lib/strategy/installer.ts +305 -0
- package/server/lib/strategy/loader.ts +256 -0
- package/server/lib/strategy/message.ts +237 -0
- package/server/lib/strategy/repository.ts +218 -0
- package/server/lib/strategy/session-logger.ts +693 -0
- package/server/lib/strategy/sources.ts +288 -0
- package/server/lib/strategy/state.ts +189 -0
- package/server/lib/strategy/templates.ts +403 -0
- package/server/lib/strategy/tick.ts +404 -0
- package/server/lib/strategy/types.ts +230 -0
- package/server/lib/swap.ts +3 -0
- package/server/lib/temp.ts +86 -0
- package/server/lib/token-metadata.ts +86 -0
- package/server/lib/token-safety.ts +200 -0
- package/server/lib/token-search.ts +444 -0
- package/server/lib/totp.ts +194 -0
- package/server/lib/transactions.ts +123 -0
- package/server/lib/transport.ts +84 -0
- package/server/lib/txhistory/decoder.ts +262 -0
- package/server/lib/txhistory/enricher.ts +652 -0
- package/server/lib/txhistory/index.ts +391 -0
- package/server/lib/txhistory/signatures.ts +59 -0
- package/server/lib/update-check.ts +35 -0
- package/server/lib/verified-summary.ts +414 -0
- package/server/lib/view-registry.ts +80 -0
- package/server/mcp/profile-policy.ts +30 -0
- package/server/mcp/server.ts +1589 -0
- package/server/mcp/tools.ts +276 -0
- package/server/middleware/auth.ts +119 -0
- package/server/middleware/requestLogger.ts +84 -0
- package/server/routes/actions.ts +539 -0
- package/server/routes/adapters.ts +711 -0
- package/server/routes/addressbook.ts +113 -0
- package/server/routes/ai.ts +34 -0
- package/server/routes/apikeys.ts +343 -0
- package/server/routes/apps.ts +601 -0
- package/server/routes/auth.ts +406 -0
- package/server/routes/backup.ts +404 -0
- package/server/routes/batch.ts +270 -0
- package/server/routes/bookmarks.ts +162 -0
- package/server/routes/credential-shares.ts +380 -0
- package/server/routes/credential-vaults.ts +159 -0
- package/server/routes/credentials.ts +1782 -0
- package/server/routes/dashboard.ts +97 -0
- package/server/routes/defaults.ts +124 -0
- package/server/routes/flags.ts +11 -0
- package/server/routes/fund.ts +225 -0
- package/server/routes/heartbeat.ts +375 -0
- package/server/routes/import.ts +364 -0
- package/server/routes/launch.ts +665 -0
- package/server/routes/lock.ts +54 -0
- package/server/routes/logs.ts +68 -0
- package/server/routes/nuke.ts +111 -0
- package/server/routes/passkey-credentials.ts +99 -0
- package/server/routes/passkey.ts +366 -0
- package/server/routes/portfolio.ts +217 -0
- package/server/routes/price.ts +63 -0
- package/server/routes/resolve.ts +31 -0
- package/server/routes/security.ts +45 -0
- package/server/routes/send-evm.ts +241 -0
- package/server/routes/send-solana.ts +281 -0
- package/server/routes/send.ts +178 -0
- package/server/routes/setup.ts +210 -0
- package/server/routes/strategy.ts +894 -0
- package/server/routes/swap-evm.ts +352 -0
- package/server/routes/swap-solana.ts +176 -0
- package/server/routes/swap.ts +356 -0
- package/server/routes/token.ts +247 -0
- package/server/routes/unlock.ts +467 -0
- package/server/routes/views.ts +41 -0
- package/server/routes/wallet-assets.ts +361 -0
- package/server/routes/wallet-transactions.ts +515 -0
- package/server/routes/wallet.ts +709 -0
- package/server/types.ts +146 -0
- package/shared/credential-field-schema.ts +248 -0
- package/skills/auramaxx/HEARTBEAT.md +78 -0
- package/skills/auramaxx/SKILL.md +745 -0
- package/skills/auramaxx/docs/AGENT_SETUP.md +155 -0
- package/skills/auramaxx/docs/API.md +127 -0
- package/skills/auramaxx/docs/AUTH.md +318 -0
- package/skills/auramaxx/docs/CLI.md +130 -0
- package/skills/auramaxx/docs/MCP.md +122 -0
- package/skills/auramaxx/docs/TROUBLESHOOTING.md +357 -0
- package/skills/auramaxx/docs/WORKSPACE.md +673 -0
- package/skills/auramaxx/docs/security.md +227 -0
- package/skills/task-lifecycle/SKILL.md +378 -0
- package/src/app/api/[...doc]/page.tsx +36 -0
- package/src/app/api/agent-requests/route.ts +30 -0
- package/src/app/api/apps/install/route.ts +132 -0
- package/src/app/api/apps/manifests/route.ts +16 -0
- package/src/app/api/apps/static/[...path]/route.ts +57 -0
- package/src/app/api/docs/plain/route.ts +74 -0
- package/src/app/api/events/route.ts +92 -0
- package/src/app/api/page.tsx +290 -0
- package/src/app/api/workspace/[id]/apps/[wid]/route.ts +119 -0
- package/src/app/api/workspace/[id]/apps/route.ts +81 -0
- package/src/app/api/workspace/[id]/export/route.ts +67 -0
- package/src/app/api/workspace/[id]/route.ts +168 -0
- package/src/app/api/workspace/auth.ts +40 -0
- package/src/app/api/workspace/config/route.ts +121 -0
- package/src/app/api/workspace/import/route.ts +127 -0
- package/src/app/api/workspace/route.ts +116 -0
- package/src/app/app-legacy-do-not-use/page.tsx +2245 -0
- package/src/app/apple-icon.png +0 -0
- package/src/app/approve/[actionId]/page.tsx +409 -0
- package/src/app/docs/DocsPageContent.tsx +269 -0
- package/src/app/docs/[...doc]/page.tsx +41 -0
- package/src/app/docs/page.tsx +38 -0
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +819 -0
- package/src/app/health/page.tsx +5 -0
- package/src/app/hello/page.tsx +102 -0
- package/src/app/icon.png +0 -0
- package/src/app/layout.tsx +39 -0
- package/src/app/page.tsx +1964 -0
- package/src/app/privacy/page.tsx +63 -0
- package/src/app/providers.tsx +87 -0
- package/src/app/share/[token]/page.tsx +295 -0
- package/src/app/terms/page.tsx +80 -0
- package/src/components/ChainSelector.tsx +44 -0
- package/src/components/HumanActionBar.tsx +697 -0
- package/src/components/NotificationDrawer.tsx +387 -0
- package/src/components/PasskeyEnrollmentPrompt.tsx +235 -0
- package/src/components/apps/AgentKeysApp.tsx +490 -0
- package/src/components/apps/App.tsx +153 -0
- package/src/components/apps/AppGrid.tsx +15 -0
- package/src/components/apps/DetailedAddressDrawer.tsx +325 -0
- package/src/components/apps/DraggableApp.tsx +562 -0
- package/src/components/apps/IFrameApp.tsx +73 -0
- package/src/components/apps/LogsApp.tsx +360 -0
- package/src/components/apps/SendApp.tsx +394 -0
- package/src/components/apps/SetupWizardApp.tsx +1004 -0
- package/src/components/apps/SystemDefaultsApp.tsx +845 -0
- package/src/components/apps/ThirdPartyApp.tsx +428 -0
- package/src/components/apps/TokenApp.tsx +319 -0
- package/src/components/apps/TransactionsApp.tsx +438 -0
- package/src/components/apps/WalletDetailApp.tsx +1505 -0
- package/src/components/apps/index.ts +13 -0
- package/src/components/design-system/Button.tsx +88 -0
- package/src/components/design-system/ChainIndicator.tsx +65 -0
- package/src/components/design-system/ChainSelector.tsx +147 -0
- package/src/components/design-system/ConfirmationModal.tsx +107 -0
- package/src/components/design-system/ConfirmationPopover.tsx +81 -0
- package/src/components/design-system/DownloadButton.tsx +149 -0
- package/src/components/design-system/Drawer.tsx +133 -0
- package/src/components/design-system/FilterDropdown.tsx +183 -0
- package/src/components/design-system/ItemPicker.tsx +157 -0
- package/src/components/design-system/Modal.tsx +296 -0
- package/src/components/design-system/Popover.tsx +142 -0
- package/src/components/design-system/TextInput.tsx +85 -0
- package/src/components/design-system/Toggle.tsx +65 -0
- package/src/components/design-system/TyvekCollapsibleSection.tsx +55 -0
- package/src/components/design-system/index.ts +14 -0
- package/src/components/docs/ClientSideMarkdown.tsx +51 -0
- package/src/components/docs/DocsSearchBar.tsx +118 -0
- package/src/components/docs/DocsThemeToggle.tsx +38 -0
- package/src/components/docs/PersistentDocGroup.tsx +91 -0
- package/src/components/docs/ShareUrlButton.tsx +33 -0
- package/src/components/docs/SidebarScrollMemory.tsx +56 -0
- package/src/components/health/CredentialHealthDashboard.tsx +214 -0
- package/src/components/icons/ChainIcons.tsx +72 -0
- package/src/components/layout/AppStoreDrawer.tsx +369 -0
- package/src/components/layout/ContentArea.tsx +21 -0
- package/src/components/layout/CreateViewModal.tsx +88 -0
- package/src/components/layout/LeftRail.tsx +114 -0
- package/src/components/layout/TabBar.tsx +284 -0
- package/src/components/layout/WalletSidebar.tsx +1030 -0
- package/src/components/layout/index.ts +6 -0
- package/src/components/marketing/AuraMaxxSpecOverlay.tsx +653 -0
- package/src/components/marketing/DeviceMorphExperience.tsx +216 -0
- package/src/components/vault/ApiKeysConsole.tsx +1272 -0
- package/src/components/vault/AuditConsole.tsx +600 -0
- package/src/components/vault/CredentialDetail.tsx +625 -0
- package/src/components/vault/CredentialEmpty.tsx +55 -0
- package/src/components/vault/CredentialField.tsx +583 -0
- package/src/components/vault/CredentialForm.tsx +1484 -0
- package/src/components/vault/CredentialList.tsx +265 -0
- package/src/components/vault/CredentialRow.tsx +130 -0
- package/src/components/vault/CredentialShareModal.tsx +273 -0
- package/src/components/vault/CredentialVault.tsx +1662 -0
- package/src/components/vault/CredentialWalletWidget.tsx +103 -0
- package/src/components/vault/DocsConsole.tsx +113 -0
- package/src/components/vault/ImportCredentialsModal.tsx +578 -0
- package/src/components/vault/LargeTypeModal.tsx +88 -0
- package/src/components/vault/PasswordGenerator.tsx +232 -0
- package/src/components/vault/TOTPDisplay.tsx +108 -0
- package/src/components/vault/TotpSetupPanel.tsx +198 -0
- package/src/components/vault/VaultSidebar.tsx +881 -0
- package/src/components/vault/credentialFormName.ts +91 -0
- package/src/components/vault/hooks/useVaultKeyboardShortcuts.ts +69 -0
- package/src/components/vault/types.ts +56 -0
- package/src/context/AuthContext.tsx +365 -0
- package/src/context/PriceContext.tsx +113 -0
- package/src/context/ThemeContext.tsx +164 -0
- package/src/context/WebSocketContext.tsx +269 -0
- package/src/context/WorkspaceContext.tsx +668 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useAgentActions.ts +552 -0
- package/src/hooks/useBalance.ts +103 -0
- package/src/hooks/useBalances.ts +129 -0
- package/src/hooks/useTheme.ts +156 -0
- package/src/instrumentation.ts +12 -0
- package/src/lib/api-docs.ts +154 -0
- package/src/lib/api.ts +474 -0
- package/src/lib/app-loader.ts +148 -0
- package/src/lib/app-registry.ts +178 -0
- package/src/lib/app-sdk.ts +157 -0
- package/src/lib/audit-console-adapter.ts +151 -0
- package/src/lib/auth-client.ts +75 -0
- package/src/lib/config.ts +74 -0
- package/src/lib/credential-field-schema.ts +11 -0
- package/src/lib/crypto.ts +112 -0
- package/src/lib/db.ts +21 -0
- package/src/lib/docs.ts +544 -0
- package/src/lib/events.ts +363 -0
- package/src/lib/pino.ts +24 -0
- package/src/lib/theme-handlers.ts +168 -0
- package/src/lib/theme.ts +351 -0
- package/src/lib/tokenData.ts +378 -0
- package/src/lib/totp-import.ts +57 -0
- package/src/lib/vault-crypto.ts +129 -0
- package/src/lib/view-registry.ts +57 -0
- package/src/lib/websocket-server.ts +302 -0
- package/src/lib/websocket-setup.ts +79 -0
- package/src/lib/wordlist.ts +2050 -0
- package/src/lib/workspace-handlers.ts +285 -0
- package/start.sh +170 -0
- package/tailwind.config.ts +99 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { useState, useEffect, useCallback } from 'react';
|
|
4
|
+
import { RotateCcw } from 'lucide-react';
|
|
5
|
+
import { Button, TextInput, FilterDropdown, Modal, Toggle } from '@/components/design-system';
|
|
6
|
+
import { WORDLIST } from '@/lib/wordlist';
|
|
7
|
+
|
|
8
|
+
interface PasswordGeneratorProps {
|
|
9
|
+
isOpen: boolean;
|
|
10
|
+
onClose: () => void;
|
|
11
|
+
onUse: (password: string) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type GenType = 'random' | 'memorable' | 'pin';
|
|
15
|
+
|
|
16
|
+
interface GenOptions {
|
|
17
|
+
numbers: boolean;
|
|
18
|
+
symbols: boolean;
|
|
19
|
+
uppercase: boolean;
|
|
20
|
+
avoidAmbiguous: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const TYPE_OPTIONS = [
|
|
24
|
+
{ value: 'random', label: 'Random' },
|
|
25
|
+
{ value: 'memorable', label: 'Memorable' },
|
|
26
|
+
{ value: 'pin', label: 'PIN' },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const DEFAULT_LENGTHS: Record<GenType, number> = { random: 20, memorable: 4, pin: 6 };
|
|
30
|
+
const MIN_LENGTHS: Record<GenType, number> = { random: 8, memorable: 3, pin: 4 };
|
|
31
|
+
const MAX_LENGTHS: Record<GenType, number> = { random: 128, memorable: 10, pin: 12 };
|
|
32
|
+
|
|
33
|
+
function randomIndex(max: number): number {
|
|
34
|
+
const arr = new Uint32Array(1);
|
|
35
|
+
crypto.getRandomValues(arr);
|
|
36
|
+
return arr[0] % max;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function generateRandom(length: number, opts: GenOptions): string {
|
|
40
|
+
let charset = 'abcdefghijklmnopqrstuvwxyz';
|
|
41
|
+
if (opts.numbers) charset += '0123456789';
|
|
42
|
+
if (opts.symbols) charset += '!@#$%^&*()_+-=[]{}|;:,.<>?';
|
|
43
|
+
if (opts.uppercase) charset += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
44
|
+
if (opts.avoidAmbiguous) charset = charset.replace(/[0OoIl1]/g, '');
|
|
45
|
+
if (charset.length === 0) charset = 'abcdefghijklmnopqrstuvwxyz';
|
|
46
|
+
const chars: string[] = [];
|
|
47
|
+
for (let i = 0; i < length; i++) {
|
|
48
|
+
chars.push(charset[randomIndex(charset.length)]);
|
|
49
|
+
}
|
|
50
|
+
return chars.join('');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function generateMemorable(count: number): string {
|
|
54
|
+
const words: string[] = [];
|
|
55
|
+
for (let i = 0; i < count; i++) {
|
|
56
|
+
words.push(WORDLIST[randomIndex(WORDLIST.length)]);
|
|
57
|
+
}
|
|
58
|
+
return words.join('-');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function generatePin(length: number): string {
|
|
62
|
+
const chars: string[] = [];
|
|
63
|
+
for (let i = 0; i < length; i++) {
|
|
64
|
+
chars.push(String(randomIndex(10)));
|
|
65
|
+
}
|
|
66
|
+
return chars.join('');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const PasswordGenerator: React.FC<PasswordGeneratorProps> = ({ isOpen, onClose, onUse }) => {
|
|
70
|
+
const [type, setType] = useState<GenType>('random');
|
|
71
|
+
const [length, setLength] = useState(DEFAULT_LENGTHS.random);
|
|
72
|
+
const [options, setOptions] = useState<GenOptions>({
|
|
73
|
+
numbers: true,
|
|
74
|
+
symbols: true,
|
|
75
|
+
uppercase: true,
|
|
76
|
+
avoidAmbiguous: false,
|
|
77
|
+
});
|
|
78
|
+
const [generated, setGenerated] = useState('');
|
|
79
|
+
const [copied, setCopied] = useState(false);
|
|
80
|
+
|
|
81
|
+
const generate = useCallback(() => {
|
|
82
|
+
switch (type) {
|
|
83
|
+
case 'random':
|
|
84
|
+
setGenerated(generateRandom(length, options));
|
|
85
|
+
break;
|
|
86
|
+
case 'memorable':
|
|
87
|
+
setGenerated(generateMemorable(length));
|
|
88
|
+
break;
|
|
89
|
+
case 'pin':
|
|
90
|
+
setGenerated(generatePin(length));
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
setCopied(false);
|
|
94
|
+
}, [type, length, options]);
|
|
95
|
+
|
|
96
|
+
// Auto-generate on open and when options change
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (isOpen) generate();
|
|
99
|
+
}, [isOpen, generate]);
|
|
100
|
+
|
|
101
|
+
// Reset length when type changes
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
setLength(DEFAULT_LENGTHS[type]);
|
|
104
|
+
}, [type]);
|
|
105
|
+
|
|
106
|
+
const handleCopy = async () => {
|
|
107
|
+
try {
|
|
108
|
+
await navigator.clipboard.writeText(generated);
|
|
109
|
+
setCopied(true);
|
|
110
|
+
setTimeout(() => setCopied(false), 2000);
|
|
111
|
+
} catch {
|
|
112
|
+
// clipboard not available
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const handleLengthInput = (val: string) => {
|
|
117
|
+
const n = parseInt(val, 10);
|
|
118
|
+
if (!isNaN(n)) {
|
|
119
|
+
setLength(Math.max(MIN_LENGTHS[type], Math.min(MAX_LENGTHS[type], n)));
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<Modal
|
|
125
|
+
isOpen={isOpen}
|
|
126
|
+
onClose={onClose}
|
|
127
|
+
title="Password Generator"
|
|
128
|
+
size="sm"
|
|
129
|
+
footer={(
|
|
130
|
+
<div className="flex items-center gap-2">
|
|
131
|
+
<Button variant="ghost" size="sm" onClick={generate} icon={<RotateCcw size={10} />}>
|
|
132
|
+
Refresh
|
|
133
|
+
</Button>
|
|
134
|
+
<Button variant="secondary" size="sm" onClick={onClose}>
|
|
135
|
+
Cancel
|
|
136
|
+
</Button>
|
|
137
|
+
<Button variant="primary" size="sm" onClick={() => onUse(generated)}>
|
|
138
|
+
Use
|
|
139
|
+
</Button>
|
|
140
|
+
</div>
|
|
141
|
+
)}
|
|
142
|
+
>
|
|
143
|
+
<div className="space-y-4 min-h-[280px]">
|
|
144
|
+
{/* Generated password display */}
|
|
145
|
+
<div
|
|
146
|
+
onClick={handleCopy}
|
|
147
|
+
className="bg-[var(--color-background-alt,#f4f4f5)] border border-[var(--color-border,#d4d4d8)] p-3 cursor-pointer transition-colors hover:border-[var(--color-border-focus,#0a0a0a)] relative group"
|
|
148
|
+
>
|
|
149
|
+
<div className="font-mono text-lg font-bold text-[var(--color-text,#0a0a0a)] break-all select-all pr-12">
|
|
150
|
+
{generated}
|
|
151
|
+
</div>
|
|
152
|
+
<div className={`absolute top-1 right-2 font-mono text-[8px] uppercase tracking-widest font-bold transition-opacity ${copied ? 'opacity-100' : 'opacity-0'} bg-[var(--color-text,#0a0a0a)] text-[var(--color-surface,#ffffff)] px-1.5 py-0.5`}>
|
|
153
|
+
Copied
|
|
154
|
+
</div>
|
|
155
|
+
{!copied && (
|
|
156
|
+
<div className="absolute top-1 right-2 font-mono text-[8px] uppercase tracking-widest text-[var(--color-text-muted,#6b7280)] opacity-0 group-hover:opacity-100 transition-opacity">
|
|
157
|
+
Click to copy
|
|
158
|
+
</div>
|
|
159
|
+
)}
|
|
160
|
+
</div>
|
|
161
|
+
|
|
162
|
+
{/* Type selector */}
|
|
163
|
+
<FilterDropdown
|
|
164
|
+
options={TYPE_OPTIONS}
|
|
165
|
+
value={type}
|
|
166
|
+
onChange={(v) => setType(v as GenType)}
|
|
167
|
+
label="Type"
|
|
168
|
+
compact
|
|
169
|
+
/>
|
|
170
|
+
|
|
171
|
+
{/* Length */}
|
|
172
|
+
<div>
|
|
173
|
+
<label className="block font-mono text-[9px] font-bold uppercase tracking-widest text-[var(--color-text-muted,#6b7280)] mb-1.5 px-1">
|
|
174
|
+
Length
|
|
175
|
+
</label>
|
|
176
|
+
<div className="flex items-center gap-3">
|
|
177
|
+
<input
|
|
178
|
+
type="range"
|
|
179
|
+
min={MIN_LENGTHS[type]}
|
|
180
|
+
max={MAX_LENGTHS[type]}
|
|
181
|
+
value={length}
|
|
182
|
+
onChange={(e) => setLength(parseInt(e.target.value, 10))}
|
|
183
|
+
className="flex-1 h-1 appearance-none bg-[var(--color-border,#d4d4d8)] outline-none"
|
|
184
|
+
style={{ accentColor: 'var(--color-accent, #ccff00)' }}
|
|
185
|
+
/>
|
|
186
|
+
<div className="w-16">
|
|
187
|
+
<TextInput
|
|
188
|
+
compact
|
|
189
|
+
type="number"
|
|
190
|
+
min={MIN_LENGTHS[type]}
|
|
191
|
+
max={MAX_LENGTHS[type]}
|
|
192
|
+
value={length}
|
|
193
|
+
onChange={(e) => handleLengthInput(e.target.value)}
|
|
194
|
+
/>
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
197
|
+
</div>
|
|
198
|
+
|
|
199
|
+
{/* Options (only for random type) */}
|
|
200
|
+
{type === 'random' && (
|
|
201
|
+
<div className="space-y-2.5">
|
|
202
|
+
<Toggle
|
|
203
|
+
size="sm"
|
|
204
|
+
checked={options.numbers}
|
|
205
|
+
onChange={(v) => setOptions((o) => ({ ...o, numbers: v }))}
|
|
206
|
+
label="Numbers"
|
|
207
|
+
/>
|
|
208
|
+
<Toggle
|
|
209
|
+
size="sm"
|
|
210
|
+
checked={options.symbols}
|
|
211
|
+
onChange={(v) => setOptions((o) => ({ ...o, symbols: v }))}
|
|
212
|
+
label="Symbols"
|
|
213
|
+
/>
|
|
214
|
+
<Toggle
|
|
215
|
+
size="sm"
|
|
216
|
+
checked={options.uppercase}
|
|
217
|
+
onChange={(v) => setOptions((o) => ({ ...o, uppercase: v }))}
|
|
218
|
+
label="Uppercase"
|
|
219
|
+
/>
|
|
220
|
+
<Toggle
|
|
221
|
+
size="sm"
|
|
222
|
+
checked={options.avoidAmbiguous}
|
|
223
|
+
onChange={(v) => setOptions((o) => ({ ...o, avoidAmbiguous: v }))}
|
|
224
|
+
label="Avoid ambiguous"
|
|
225
|
+
/>
|
|
226
|
+
</div>
|
|
227
|
+
)}
|
|
228
|
+
|
|
229
|
+
</div>
|
|
230
|
+
</Modal>
|
|
231
|
+
);
|
|
232
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { useState, useEffect, useCallback } from 'react';
|
|
4
|
+
import { api, Api } from '@/lib/api';
|
|
5
|
+
import { CredentialField } from './CredentialField';
|
|
6
|
+
|
|
7
|
+
interface TOTPDisplayProps {
|
|
8
|
+
credentialId: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Live TOTP code display with countdown timer.
|
|
13
|
+
* Only renders if the credential has a TOTP secret.
|
|
14
|
+
*/
|
|
15
|
+
export const TOTPDisplay: React.FC<TOTPDisplayProps> = ({ credentialId }) => {
|
|
16
|
+
const [code, setCode] = useState<string | null>(null);
|
|
17
|
+
const [remaining, setRemaining] = useState(30);
|
|
18
|
+
const [hasTOTP, setHasTOTP] = useState<boolean | null>(null); // null = unknown
|
|
19
|
+
|
|
20
|
+
const fetchCode = useCallback(async () => {
|
|
21
|
+
try {
|
|
22
|
+
const res = await api.post<{ success: boolean; code: string; remaining: number; error?: string }>(
|
|
23
|
+
Api.Wallet,
|
|
24
|
+
`/credentials/${credentialId}/totp`,
|
|
25
|
+
);
|
|
26
|
+
if (res.success && res.code) {
|
|
27
|
+
setCode(res.code);
|
|
28
|
+
setRemaining(res.remaining);
|
|
29
|
+
setHasTOTP(true);
|
|
30
|
+
} else {
|
|
31
|
+
setHasTOTP(false);
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
setHasTOTP(false);
|
|
35
|
+
}
|
|
36
|
+
}, [credentialId]);
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
fetchCode();
|
|
40
|
+
}, [fetchCode]);
|
|
41
|
+
|
|
42
|
+
// Countdown timer
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (hasTOTP !== true) return;
|
|
45
|
+
const interval = setInterval(() => {
|
|
46
|
+
setRemaining(prev => {
|
|
47
|
+
if (prev <= 1) {
|
|
48
|
+
fetchCode();
|
|
49
|
+
return 30;
|
|
50
|
+
}
|
|
51
|
+
return prev - 1;
|
|
52
|
+
});
|
|
53
|
+
}, 1000);
|
|
54
|
+
return () => clearInterval(interval);
|
|
55
|
+
}, [hasTOTP, fetchCode]);
|
|
56
|
+
|
|
57
|
+
if (hasTOTP === null || hasTOTP === false) return null;
|
|
58
|
+
const isUrgent = remaining <= 5;
|
|
59
|
+
const displayCode = code ? `${code.slice(0, 3)} ${code.slice(3)}` : '--- ---';
|
|
60
|
+
const progress = remaining / 30;
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<div className="space-y-0.5" data-testid="totp-display">
|
|
64
|
+
<CredentialField
|
|
65
|
+
label="2FA Code"
|
|
66
|
+
value={displayCode}
|
|
67
|
+
copyValue={code ?? undefined}
|
|
68
|
+
credentialId={credentialId}
|
|
69
|
+
fieldKey="totp_code"
|
|
70
|
+
isSensitive={false}
|
|
71
|
+
trailingValue={(
|
|
72
|
+
<div className="ml-2 flex items-center gap-1.5">
|
|
73
|
+
<svg width="16" height="16" viewBox="0 0 18 18" className="shrink-0" style={{ transform: 'rotate(-90deg)' }}>
|
|
74
|
+
<circle
|
|
75
|
+
cx="9"
|
|
76
|
+
cy="9"
|
|
77
|
+
r="7"
|
|
78
|
+
fill="none"
|
|
79
|
+
stroke="currentColor"
|
|
80
|
+
strokeWidth="2"
|
|
81
|
+
className="text-[var(--color-border,#d4d4d8)]"
|
|
82
|
+
opacity="0.3"
|
|
83
|
+
/>
|
|
84
|
+
<circle
|
|
85
|
+
cx="9"
|
|
86
|
+
cy="9"
|
|
87
|
+
r="7"
|
|
88
|
+
fill="none"
|
|
89
|
+
stroke="currentColor"
|
|
90
|
+
strokeWidth="2"
|
|
91
|
+
strokeDasharray={`${progress * 43.98} 43.98`}
|
|
92
|
+
strokeLinecap="round"
|
|
93
|
+
className={isUrgent ? 'text-[var(--color-danger,#ef4444)]' : 'text-[var(--color-accent,#ccff00)]'}
|
|
94
|
+
/>
|
|
95
|
+
</svg>
|
|
96
|
+
<span className={`font-mono text-[9px] ${
|
|
97
|
+
isUrgent ? 'text-[var(--color-danger,#ef4444)]' : 'text-[var(--color-text-faint,#9ca3af)]'
|
|
98
|
+
}`}>
|
|
99
|
+
{remaining}s
|
|
100
|
+
</span>
|
|
101
|
+
</div>
|
|
102
|
+
)}
|
|
103
|
+
disableLargeType={true}
|
|
104
|
+
onShowLargeType={() => {}}
|
|
105
|
+
/>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { TextInput } from '@/components/design-system';
|
|
5
|
+
import { classifyTotpPayload, normalizeBase32Secret, parseTotpUri, type ParsedTotpUri } from '@/lib/totp-import';
|
|
6
|
+
|
|
7
|
+
type TotpIntent = 'keep' | 'replace' | 'remove';
|
|
8
|
+
|
|
9
|
+
type Props = {
|
|
10
|
+
isEdit: boolean;
|
|
11
|
+
hasExistingTotp: boolean;
|
|
12
|
+
onIntentChange: (intent: TotpIntent) => void;
|
|
13
|
+
onSecretChange: (secret: string, markDirty: boolean) => void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const TotpSetupPanel: React.FC<Props> = ({ isEdit, hasExistingTotp, onIntentChange, onSecretChange }) => {
|
|
17
|
+
const [mode, setMode] = useState<'manual' | 'uri' | 'qr'>('manual');
|
|
18
|
+
const [manualSecret, setManualSecret] = useState('');
|
|
19
|
+
const [uriInput, setUriInput] = useState('');
|
|
20
|
+
const [preview, setPreview] = useState<ParsedTotpUri | null>(null);
|
|
21
|
+
const [error, setError] = useState<string | null>(null);
|
|
22
|
+
const [isDecoding, setIsDecoding] = useState(false);
|
|
23
|
+
const decodeVersionRef = useRef(0);
|
|
24
|
+
|
|
25
|
+
const hasMigrationPayload = useMemo(() => classifyTotpPayload(uriInput) === 'otpauth-migration', [uriInput]);
|
|
26
|
+
|
|
27
|
+
const applyParsed = (parsed: ParsedTotpUri) => {
|
|
28
|
+
setPreview(parsed);
|
|
29
|
+
setError(null);
|
|
30
|
+
onIntentChange('replace');
|
|
31
|
+
onSecretChange(parsed.secret, true);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const handleManualChange = (value: string) => {
|
|
35
|
+
setManualSecret(value);
|
|
36
|
+
if (!value.trim()) {
|
|
37
|
+
setPreview(null);
|
|
38
|
+
onSecretChange('', false);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const normalized = normalizeBase32Secret(value);
|
|
43
|
+
setError(null);
|
|
44
|
+
setPreview({ secret: normalized, algorithm: 'SHA1', digits: 6, period: 30 });
|
|
45
|
+
onIntentChange('replace');
|
|
46
|
+
onSecretChange(normalized, true);
|
|
47
|
+
} catch {
|
|
48
|
+
setPreview(null);
|
|
49
|
+
setError('Invalid TOTP secret');
|
|
50
|
+
onSecretChange('', false);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const parseUriInput = (value: string) => {
|
|
55
|
+
if (!value.trim()) {
|
|
56
|
+
setPreview(null);
|
|
57
|
+
setError(null);
|
|
58
|
+
onSecretChange('', false);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const kind = classifyTotpPayload(value);
|
|
62
|
+
if (kind === 'otpauth-migration') {
|
|
63
|
+
setPreview(null);
|
|
64
|
+
setError(null);
|
|
65
|
+
onSecretChange('', false);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (kind !== 'otpauth') {
|
|
69
|
+
setPreview(null);
|
|
70
|
+
setError('Unsupported QR/setup payload. Use an otpauth://totp link.');
|
|
71
|
+
onSecretChange('', false);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
applyParsed(parseTotpUri(value));
|
|
77
|
+
} catch (err) {
|
|
78
|
+
setPreview(null);
|
|
79
|
+
setError(err instanceof Error ? err.message : 'Invalid TOTP setup link');
|
|
80
|
+
onSecretChange('', false);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const handleQrFile = async (file: File | null) => {
|
|
85
|
+
if (!file) return;
|
|
86
|
+
if (file.size > 5 * 1024 * 1024) {
|
|
87
|
+
setError('QR image must be 5MB or smaller');
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const currentVersion = ++decodeVersionRef.current;
|
|
92
|
+
setIsDecoding(true);
|
|
93
|
+
setError(null);
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
if (typeof window === 'undefined' || !('BarcodeDetector' in window)) {
|
|
97
|
+
throw new Error('QR decoding not supported in this browser. Paste setup link manually.');
|
|
98
|
+
}
|
|
99
|
+
const detector = new (window as unknown as { BarcodeDetector: new (opts: { formats: string[] }) => { detect: (source: ImageBitmap) => Promise<Array<{ rawValue?: string }>> } }).BarcodeDetector({ formats: ['qr_code'] });
|
|
100
|
+
const bitmap = await createImageBitmap(file);
|
|
101
|
+
try {
|
|
102
|
+
if (bitmap.width > 4096 || bitmap.height > 4096) {
|
|
103
|
+
throw new Error('QR image dimensions exceed 4096x4096 limit');
|
|
104
|
+
}
|
|
105
|
+
const codes = await detector.detect(bitmap);
|
|
106
|
+
if (decodeVersionRef.current !== currentVersion) return;
|
|
107
|
+
const payload = codes[0]?.rawValue || '';
|
|
108
|
+
setUriInput(payload);
|
|
109
|
+
parseUriInput(payload);
|
|
110
|
+
} finally {
|
|
111
|
+
bitmap.close();
|
|
112
|
+
}
|
|
113
|
+
} catch (err) {
|
|
114
|
+
if (decodeVersionRef.current !== currentVersion) return;
|
|
115
|
+
setPreview(null);
|
|
116
|
+
setError(err instanceof Error ? err.message : 'Failed to decode QR image');
|
|
117
|
+
} finally {
|
|
118
|
+
if (decodeVersionRef.current === currentVersion) setIsDecoding(false);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<div className="space-y-3 border border-[var(--color-border,#d4d4d8)] p-3 bg-[var(--color-background-alt,#f4f4f5)]" data-testid="totp-setup-panel">
|
|
124
|
+
{isEdit && hasExistingTotp && (
|
|
125
|
+
<div className="flex flex-wrap gap-2">
|
|
126
|
+
<button type="button" className="font-mono text-[9px] px-2 py-1 border" onClick={() => { onIntentChange('keep'); setError(null); onSecretChange('', false); }}>
|
|
127
|
+
Keep Existing
|
|
128
|
+
</button>
|
|
129
|
+
<button type="button" className="font-mono text-[9px] px-2 py-1 border" onClick={() => onIntentChange('replace')}>
|
|
130
|
+
Replace TOTP
|
|
131
|
+
</button>
|
|
132
|
+
<button type="button" className="font-mono text-[9px] px-2 py-1 border" onClick={() => { onIntentChange('remove'); setPreview(null); setError(null); onSecretChange('', true); }}>
|
|
133
|
+
Remove TOTP
|
|
134
|
+
</button>
|
|
135
|
+
</div>
|
|
136
|
+
)}
|
|
137
|
+
|
|
138
|
+
<div className="flex gap-2">
|
|
139
|
+
<button type="button" className="font-mono text-[9px] uppercase px-2 py-1 border" onClick={() => setMode('manual')}>Manual</button>
|
|
140
|
+
<button type="button" className="font-mono text-[9px] uppercase px-2 py-1 border" onClick={() => setMode('uri')}>Paste Link</button>
|
|
141
|
+
<button type="button" className="font-mono text-[9px] uppercase px-2 py-1 border" onClick={() => setMode('qr')}>Import QR</button>
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
{mode === 'manual' && (
|
|
145
|
+
<TextInput
|
|
146
|
+
label="TOTP Secret (2FA)"
|
|
147
|
+
value={manualSecret}
|
|
148
|
+
onChange={(e) => handleManualChange(e.target.value)}
|
|
149
|
+
placeholder="Base32 secret (e.g. JBSWY3DPEHPK3PXP)"
|
|
150
|
+
type="password"
|
|
151
|
+
/>
|
|
152
|
+
)}
|
|
153
|
+
|
|
154
|
+
{mode === 'uri' && (
|
|
155
|
+
<div>
|
|
156
|
+
<label className="block font-mono text-[9px] font-bold uppercase tracking-widest text-[var(--color-text-muted,#6b7280)]">Setup Link</label>
|
|
157
|
+
<textarea
|
|
158
|
+
className="w-full h-24 bg-[var(--color-background-alt,#f4f4f5)] border border-[var(--color-border,#d4d4d8)] font-mono text-sm p-3 resize-none"
|
|
159
|
+
value={uriInput}
|
|
160
|
+
onChange={(e) => { setUriInput(e.target.value); parseUriInput(e.target.value); }}
|
|
161
|
+
placeholder="otpauth://totp/..."
|
|
162
|
+
data-testid="totp-uri-input"
|
|
163
|
+
/>
|
|
164
|
+
</div>
|
|
165
|
+
)}
|
|
166
|
+
|
|
167
|
+
{mode === 'qr' && (
|
|
168
|
+
<div className="space-y-2">
|
|
169
|
+
<input
|
|
170
|
+
type="file"
|
|
171
|
+
accept="image/png,image/jpeg,image/webp"
|
|
172
|
+
onChange={(e) => { void handleQrFile(e.target.files?.[0] || null); }}
|
|
173
|
+
data-testid="totp-qr-file"
|
|
174
|
+
/>
|
|
175
|
+
{isDecoding && <p className="font-mono text-[10px]" data-testid="totp-qr-decoding">Decoding QR…</p>}
|
|
176
|
+
</div>
|
|
177
|
+
)}
|
|
178
|
+
|
|
179
|
+
{hasMigrationPayload && (
|
|
180
|
+
<div className="font-mono text-[10px] border p-2" data-testid="totp-migration-fallback">
|
|
181
|
+
Google Authenticator migration QR detected. v1 supports standard otpauth:// links only. Use manual setup or account-level QR when available.
|
|
182
|
+
</div>
|
|
183
|
+
)}
|
|
184
|
+
|
|
185
|
+
{preview && (
|
|
186
|
+
<div className="font-mono text-[10px] border p-2" data-testid="totp-preview">
|
|
187
|
+
<div>Issuer: {preview.issuer || '—'}</div>
|
|
188
|
+
<div>Account: {preview.account || '—'}</div>
|
|
189
|
+
<div>Digits: {preview.digits}</div>
|
|
190
|
+
<div>Period: {preview.period}s</div>
|
|
191
|
+
<div>Algorithm: {preview.algorithm}</div>
|
|
192
|
+
</div>
|
|
193
|
+
)}
|
|
194
|
+
|
|
195
|
+
{error && <div className="font-mono text-[10px] text-[var(--color-danger,#ef4444)]" data-testid="totp-error">{error}</div>}
|
|
196
|
+
</div>
|
|
197
|
+
);
|
|
198
|
+
};
|