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,579 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unix Socket IPC Server
|
|
3
|
+
*
|
|
4
|
+
* Provides a secure Unix socket for agent connections with:
|
|
5
|
+
* - Socket at /tmp/aura-cli-{uid}.sock (default 4242) or /tmp/aura-cli-{uid}-{port}.sock for non-default ports
|
|
6
|
+
* with mode 0600 (owner only)
|
|
7
|
+
* - Auto-approve for same-UID processes (socket permission = peer credential)
|
|
8
|
+
* - Encrypted token delivery (server-issued RSA-OAEP/AES-256-GCM envelope)
|
|
9
|
+
*
|
|
10
|
+
* Protocol (JSON over newline-delimited messages):
|
|
11
|
+
*
|
|
12
|
+
* Agent -> CLI:
|
|
13
|
+
* { "type": "auth", "agentId": "my-agent", "pubkey": "...", "autoApprove": true }
|
|
14
|
+
* { "type": "auth", "agentId": "my-agent", "pubkey": "...", "limit": 0.1, "permissions": [...] }
|
|
15
|
+
* { "type": "ping" }
|
|
16
|
+
*
|
|
17
|
+
* CLI -> Agent:
|
|
18
|
+
* { "type": "auth_pending", "requestId": "..." }
|
|
19
|
+
* { "type": "auth_approved", "encryptedToken": "...", "agentId": "...", ... }
|
|
20
|
+
* { "type": "auth_rejected", "requestId": "..." }
|
|
21
|
+
* { "type": "pong" }
|
|
22
|
+
* { "type": "error", "message": "..." }
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import * as net from 'net';
|
|
26
|
+
import * as fs from 'fs';
|
|
27
|
+
import { getDefaultSync } from '../lib/defaults';
|
|
28
|
+
import { getErrorMessage } from '../lib/error';
|
|
29
|
+
import { isValidAgentPubkey, normalizeAgentPubkey, encryptToAgentPubkey } from '../lib/credential-transport';
|
|
30
|
+
import { createToken } from '../lib/auth';
|
|
31
|
+
import { isUnlocked } from '../lib/cold';
|
|
32
|
+
import { AgentProfileError, resolveProfileToEffectivePolicy } from '../lib/agent-profiles';
|
|
33
|
+
import { resolveAuraSocketPath } from '../lib/socket-path';
|
|
34
|
+
import { buildApproveUrl } from '../lib/approval-link';
|
|
35
|
+
|
|
36
|
+
interface SocketServerOptions {
|
|
37
|
+
serverUrl: string;
|
|
38
|
+
getToken?: () => string | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface AgentAuthRequest {
|
|
42
|
+
type: 'auth';
|
|
43
|
+
agentId: string;
|
|
44
|
+
autoApprove?: boolean;
|
|
45
|
+
limit?: number;
|
|
46
|
+
permissions?: string[];
|
|
47
|
+
ttl?: number;
|
|
48
|
+
limits?: { fund?: number; send?: number; swap?: number };
|
|
49
|
+
walletAccess?: string[];
|
|
50
|
+
credentialAccess?: { read?: string[]; write?: string[]; excludeFields?: string[]; ttl?: number; maxReads?: number };
|
|
51
|
+
profile?: string;
|
|
52
|
+
profileVersion?: string;
|
|
53
|
+
profileOverrides?: {
|
|
54
|
+
ttlSeconds?: number;
|
|
55
|
+
maxReads?: number;
|
|
56
|
+
readScopes?: string[];
|
|
57
|
+
writeScopes?: string[];
|
|
58
|
+
excludeFields?: string[];
|
|
59
|
+
};
|
|
60
|
+
pubkey?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface PendingAgentAuth {
|
|
64
|
+
socket: net.Socket;
|
|
65
|
+
requestId: string;
|
|
66
|
+
secret: string;
|
|
67
|
+
agentId: string;
|
|
68
|
+
pubkey?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Rate limiting for auto-approve: track tokens per socket
|
|
72
|
+
const autoApproveRates = new WeakMap<net.Socket, { count: number; resetAt: number }>();
|
|
73
|
+
const AUTO_APPROVE_MAX = 10;
|
|
74
|
+
const AUTO_APPROVE_WINDOW_MS = 60_000;
|
|
75
|
+
|
|
76
|
+
function checkAutoApproveRate(socket: net.Socket): boolean {
|
|
77
|
+
const now = Date.now();
|
|
78
|
+
let entry = autoApproveRates.get(socket);
|
|
79
|
+
if (!entry || now > entry.resetAt) {
|
|
80
|
+
entry = { count: 0, resetAt: now + AUTO_APPROVE_WINDOW_MS };
|
|
81
|
+
autoApproveRates.set(socket, entry);
|
|
82
|
+
}
|
|
83
|
+
if (entry.count >= AUTO_APPROVE_MAX) return false;
|
|
84
|
+
entry.count++;
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class SocketServer {
|
|
89
|
+
private server: net.Server | null = null;
|
|
90
|
+
private socketPath: string;
|
|
91
|
+
private options: SocketServerOptions;
|
|
92
|
+
private pendingAuths: Map<string, PendingAgentAuth> = new Map();
|
|
93
|
+
private pollIntervals: Map<string, NodeJS.Timeout> = new Map();
|
|
94
|
+
|
|
95
|
+
constructor(options: SocketServerOptions) {
|
|
96
|
+
this.options = options;
|
|
97
|
+
const uid = process.getuid?.() ?? 'unknown';
|
|
98
|
+
this.socketPath = resolveAuraSocketPath({
|
|
99
|
+
uid,
|
|
100
|
+
serverUrl: options.serverUrl,
|
|
101
|
+
serverPort: process.env.WALLET_SERVER_PORT,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
getSocketPath(): string {
|
|
106
|
+
return this.socketPath;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async start(): Promise<void> {
|
|
110
|
+
if (fs.existsSync(this.socketPath)) {
|
|
111
|
+
fs.unlinkSync(this.socketPath);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return new Promise((resolve, reject) => {
|
|
115
|
+
this.server = net.createServer((socket) => {
|
|
116
|
+
this.handleConnection(socket);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
this.server.on('error', (err) => {
|
|
120
|
+
console.error('Socket server error:', err.message);
|
|
121
|
+
reject(err);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
this.server.listen(this.socketPath, () => {
|
|
125
|
+
fs.chmodSync(this.socketPath, 0o600);
|
|
126
|
+
console.log(`Unix socket listening at ${this.socketPath}`);
|
|
127
|
+
resolve();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async stop(): Promise<void> {
|
|
133
|
+
this.pollIntervals.forEach((interval) => {
|
|
134
|
+
clearInterval(interval);
|
|
135
|
+
});
|
|
136
|
+
this.pollIntervals.clear();
|
|
137
|
+
|
|
138
|
+
return new Promise((resolve) => {
|
|
139
|
+
if (this.server) {
|
|
140
|
+
this.server.close(() => {
|
|
141
|
+
if (fs.existsSync(this.socketPath)) {
|
|
142
|
+
try { fs.unlinkSync(this.socketPath); } catch { /* ignore */ }
|
|
143
|
+
}
|
|
144
|
+
resolve();
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
resolve();
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private handleConnection(socket: net.Socket): void {
|
|
153
|
+
const MAX_BUFFER_SIZE = 64 * 1024; // 64KB
|
|
154
|
+
let buffer = '';
|
|
155
|
+
|
|
156
|
+
socket.on('data', (data) => {
|
|
157
|
+
buffer += data.toString();
|
|
158
|
+
|
|
159
|
+
if (buffer.length > MAX_BUFFER_SIZE) {
|
|
160
|
+
console.error('[socket] Buffer overflow — disconnecting client');
|
|
161
|
+
this.send(socket, { type: 'error', message: 'Message too large' });
|
|
162
|
+
socket.destroy();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
let newlineIndex;
|
|
167
|
+
while ((newlineIndex = buffer.indexOf('\n')) !== -1) {
|
|
168
|
+
const line = buffer.substring(0, newlineIndex);
|
|
169
|
+
buffer = buffer.substring(newlineIndex + 1);
|
|
170
|
+
|
|
171
|
+
if (line.trim()) {
|
|
172
|
+
this.handleMessage(socket, line.trim());
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
socket.on('error', (err) => {
|
|
178
|
+
console.error(`[socket] Connection error: ${err.message} (code=${(err as NodeJS.ErrnoException).code})`);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
socket.on('close', () => {
|
|
182
|
+
const toDelete: string[] = [];
|
|
183
|
+
this.pendingAuths.forEach((pending, requestId) => {
|
|
184
|
+
if (pending.socket === socket) {
|
|
185
|
+
const interval = this.pollIntervals.get(requestId);
|
|
186
|
+
if (interval) {
|
|
187
|
+
clearInterval(interval);
|
|
188
|
+
this.pollIntervals.delete(requestId);
|
|
189
|
+
}
|
|
190
|
+
toDelete.push(requestId);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
toDelete.forEach(id => this.pendingAuths.delete(id));
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private handleMessage(socket: net.Socket, message: string): void {
|
|
198
|
+
try {
|
|
199
|
+
const msg = JSON.parse(message);
|
|
200
|
+
|
|
201
|
+
switch (msg.type) {
|
|
202
|
+
case 'ping':
|
|
203
|
+
this.send(socket, { type: 'pong' });
|
|
204
|
+
break;
|
|
205
|
+
|
|
206
|
+
case 'auth':
|
|
207
|
+
this.handleAuthRequest(socket, msg as AgentAuthRequest);
|
|
208
|
+
break;
|
|
209
|
+
|
|
210
|
+
default:
|
|
211
|
+
this.send(socket, { type: 'error', message: `Unknown message type: ${msg.type}` });
|
|
212
|
+
}
|
|
213
|
+
} catch {
|
|
214
|
+
this.send(socket, { type: 'error', message: 'Invalid JSON message' });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Handle auth request — auto-approve path or standard approval flow
|
|
220
|
+
*/
|
|
221
|
+
private async handleAuthRequest(socket: net.Socket, request: AgentAuthRequest): Promise<void> {
|
|
222
|
+
try {
|
|
223
|
+
if (typeof request.pubkey !== 'string' || !request.pubkey.trim()) {
|
|
224
|
+
this.send(socket, { type: 'error', message: 'pubkey is required for auth requests' });
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!isValidAgentPubkey(request.pubkey)) {
|
|
229
|
+
this.send(socket, { type: 'error', message: 'Invalid RSA public key' });
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const normalizedPubkey = normalizeAgentPubkey(request.pubkey);
|
|
234
|
+
|
|
235
|
+
// ── Auto-approve path ──
|
|
236
|
+
if (request.autoApprove) {
|
|
237
|
+
const autoApproveEnabled = getDefaultSync<boolean>('trust.localAutoApprove', false);
|
|
238
|
+
if (!autoApproveEnabled) {
|
|
239
|
+
this.send(socket, { type: 'error', message: 'Auto-approve is disabled. Use standard approval flow.' });
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Rate limit
|
|
244
|
+
if (!checkAutoApproveRate(socket)) {
|
|
245
|
+
this.send(socket, { type: 'error', message: 'Rate limit exceeded for auto-approve (max 10/minute)' });
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Resolve local auto-approve policy defaults
|
|
250
|
+
const limits = getDefaultSync<Record<string, number>>('trust.localLimits', { fund: 0, send: 0, swap: 0 });
|
|
251
|
+
const localProfile = String(getDefaultSync<string>('trust.localProfile', 'dev') || '').trim();
|
|
252
|
+
const localProfileVersion = String(getDefaultSync<string>('trust.localProfileVersion', 'v1') || '').trim();
|
|
253
|
+
const localProfileOverrides = getDefaultSync<AgentAuthRequest['profileOverrides'] | null>('trust.localProfileOverrides', null);
|
|
254
|
+
const agentId = request.agentId || 'local-agent';
|
|
255
|
+
if (!localProfile) {
|
|
256
|
+
this.send(socket, { type: 'error', message: 'Local profile is not configured for socket issuance.' });
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (localProfile === 'strict') {
|
|
260
|
+
this.send(socket, { type: 'error', message: 'Strict profile requires manual approval (auto-approve disabled).' });
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const hasTokenProvider = typeof this.options.getToken === 'function';
|
|
265
|
+
const adminToken = hasTokenProvider ? this.options.getToken() : null;
|
|
266
|
+
|
|
267
|
+
// CLI daemon mode: require unlocked admin token callback.
|
|
268
|
+
if (hasTokenProvider && !adminToken) {
|
|
269
|
+
this.send(socket, { type: 'error', message: 'CLI daemon is locked. Unlock before socket auto-approve.' });
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// When an admin token callback exists, issue via HTTP route.
|
|
274
|
+
if (adminToken) {
|
|
275
|
+
const issueBody: Record<string, unknown> = {
|
|
276
|
+
agentId,
|
|
277
|
+
limits,
|
|
278
|
+
pubkey: normalizedPubkey,
|
|
279
|
+
profile: localProfile,
|
|
280
|
+
profileVersion: localProfileVersion || 'v1',
|
|
281
|
+
};
|
|
282
|
+
if (localProfileOverrides) {
|
|
283
|
+
issueBody.profileOverrides = localProfileOverrides;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const issueResponse = await fetch(`${this.options.serverUrl}/actions/token`, {
|
|
287
|
+
method: 'POST',
|
|
288
|
+
headers: {
|
|
289
|
+
'Authorization': `Bearer ${adminToken}`,
|
|
290
|
+
'Content-Type': 'application/json',
|
|
291
|
+
},
|
|
292
|
+
body: JSON.stringify(issueBody),
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
let issueData: {
|
|
296
|
+
success?: boolean;
|
|
297
|
+
error?: string;
|
|
298
|
+
code?: string;
|
|
299
|
+
encryptedToken?: string;
|
|
300
|
+
permissions?: string[];
|
|
301
|
+
limits?: { fund?: number; send?: number; swap?: number };
|
|
302
|
+
profile?: { id: string; version: string; displayName?: string; rationale?: string };
|
|
303
|
+
effectivePolicyHash?: string;
|
|
304
|
+
overrideDelta?: string[];
|
|
305
|
+
warnings?: string[];
|
|
306
|
+
expiresIn?: number;
|
|
307
|
+
} = {};
|
|
308
|
+
try {
|
|
309
|
+
issueData = await issueResponse.json();
|
|
310
|
+
} catch {
|
|
311
|
+
issueData = {};
|
|
312
|
+
}
|
|
313
|
+
if (!issueResponse.ok || !issueData.success || !issueData.encryptedToken) {
|
|
314
|
+
const message = issueData.error
|
|
315
|
+
? (issueData.code ? `${issueData.error} (${issueData.code})` : issueData.error)
|
|
316
|
+
: `Auto-approve token issue failed (${issueResponse.status})`;
|
|
317
|
+
this.send(socket, { type: 'error', message });
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
this.send(socket, {
|
|
322
|
+
type: 'auth_approved',
|
|
323
|
+
encryptedToken: issueData.encryptedToken,
|
|
324
|
+
agentId,
|
|
325
|
+
permissions: issueData.permissions || [],
|
|
326
|
+
limits: issueData.limits || limits,
|
|
327
|
+
ttl: issueData.expiresIn,
|
|
328
|
+
profile: issueData.profile,
|
|
329
|
+
effectivePolicyHash: issueData.effectivePolicyHash,
|
|
330
|
+
overrideDelta: issueData.overrideDelta,
|
|
331
|
+
warnings: issueData.warnings,
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
console.log(`[socket][audit] auto-approve issued token agentId=${agentId} ttl=${issueData.expiresIn ?? 0}s profile=${profile.id}@${profile.version}`);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Server-runtime mode: issue token in-process so settings changes apply immediately.
|
|
339
|
+
if (!isUnlocked()) {
|
|
340
|
+
this.send(socket, { type: 'error', message: 'Wallet is locked. Unlock first.' });
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const fundLimit = typeof limits.fund === 'number' ? limits.fund : 0;
|
|
345
|
+
const defaultSendLimit = getDefaultSync<number>('limits.send', 0.1);
|
|
346
|
+
const defaultSwapLimit = getDefaultSync<number>('limits.swap', 0.1);
|
|
347
|
+
|
|
348
|
+
const resolvedProfile = resolveProfileToEffectivePolicy({
|
|
349
|
+
profileId: localProfile,
|
|
350
|
+
profileVersion: localProfileVersion || 'v1',
|
|
351
|
+
overrides: localProfileOverrides ?? undefined,
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
const effectivePermissions = [...resolvedProfile.permissions];
|
|
355
|
+
const ttlSeconds = resolvedProfile.ttlSeconds;
|
|
356
|
+
const tokenLimits = {
|
|
357
|
+
fund: fundLimit,
|
|
358
|
+
send: defaultSendLimit,
|
|
359
|
+
swap: defaultSwapLimit,
|
|
360
|
+
...limits,
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const token = await createToken(agentId, fundLimit, effectivePermissions, ttlSeconds, {
|
|
364
|
+
limits: tokenLimits,
|
|
365
|
+
credentialAccess: resolvedProfile.credentialAccess,
|
|
366
|
+
agentPubkey: normalizedPubkey,
|
|
367
|
+
});
|
|
368
|
+
const encryptedToken = encryptToAgentPubkey(token, normalizedPubkey);
|
|
369
|
+
|
|
370
|
+
this.send(socket, {
|
|
371
|
+
type: 'auth_approved',
|
|
372
|
+
encryptedToken,
|
|
373
|
+
agentId,
|
|
374
|
+
permissions: effectivePermissions,
|
|
375
|
+
limits: tokenLimits,
|
|
376
|
+
ttl: ttlSeconds,
|
|
377
|
+
profile: resolvedProfile.profile,
|
|
378
|
+
effectivePolicyHash: resolvedProfile.effectivePolicyHash,
|
|
379
|
+
overrideDelta: resolvedProfile.overrideDelta,
|
|
380
|
+
warnings: resolvedProfile.warnings,
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
console.log(`[socket][audit] auto-approve issued token agentId=${agentId} ttl=${ttlSeconds}s profile=${localProfile}@${localProfileVersion} path=in-process`);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// ── Standard approval flow (proxy to HTTP) ──
|
|
388
|
+
if (request.permissions !== undefined || request.ttl !== undefined || request.credentialAccess !== undefined) {
|
|
389
|
+
this.send(socket, {
|
|
390
|
+
type: 'error',
|
|
391
|
+
message: 'Raw permission issuance is disabled. Use profile + optional profileOverrides.',
|
|
392
|
+
});
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
const requestProfile = (
|
|
396
|
+
typeof request.profile === 'string' && request.profile.trim().length > 0
|
|
397
|
+
? request.profile.trim()
|
|
398
|
+
: String(getDefaultSync<string>('trust.localProfile', 'dev') || '').trim()
|
|
399
|
+
);
|
|
400
|
+
const requestProfileVersion = (
|
|
401
|
+
typeof request.profileVersion === 'string' && request.profileVersion.trim().length > 0
|
|
402
|
+
? request.profileVersion.trim()
|
|
403
|
+
: String(getDefaultSync<string>('trust.localProfileVersion', 'v1') || '').trim()
|
|
404
|
+
);
|
|
405
|
+
if (!requestProfile) {
|
|
406
|
+
this.send(socket, { type: 'error', message: 'profile is required for auth requests' });
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const response = await fetch(`${this.options.serverUrl}/auth`, {
|
|
411
|
+
method: 'POST',
|
|
412
|
+
headers: { 'Content-Type': 'application/json' },
|
|
413
|
+
body: JSON.stringify({
|
|
414
|
+
agentId: request.agentId,
|
|
415
|
+
limit: request.limit ?? getDefaultSync<number>('limits.fund', 0),
|
|
416
|
+
limits: request.limits,
|
|
417
|
+
walletAccess: request.walletAccess,
|
|
418
|
+
profile: requestProfile,
|
|
419
|
+
profileVersion: requestProfileVersion || 'v1',
|
|
420
|
+
profileOverrides: request.profileOverrides,
|
|
421
|
+
pubkey: request.pubkey,
|
|
422
|
+
})
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
const data = await response.json() as {
|
|
426
|
+
success?: boolean;
|
|
427
|
+
requestId?: string;
|
|
428
|
+
secret?: string;
|
|
429
|
+
error?: string;
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
if (!response.ok || !data.success) {
|
|
433
|
+
this.send(socket, {
|
|
434
|
+
type: 'error',
|
|
435
|
+
message: data.error || 'Failed to create auth request'
|
|
436
|
+
});
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// Store pending auth info (with pubkey for encrypted delivery)
|
|
441
|
+
const pending: PendingAgentAuth = {
|
|
442
|
+
socket,
|
|
443
|
+
requestId: data.requestId!,
|
|
444
|
+
secret: data.secret!,
|
|
445
|
+
agentId: request.agentId,
|
|
446
|
+
pubkey: normalizedPubkey,
|
|
447
|
+
};
|
|
448
|
+
this.pendingAuths.set(data.requestId!, pending);
|
|
449
|
+
|
|
450
|
+
const dashboardBase = `http://localhost:${process.env.DASHBOARD_PORT || '4747'}`;
|
|
451
|
+
this.send(socket, {
|
|
452
|
+
type: 'auth_pending',
|
|
453
|
+
requestId: data.requestId,
|
|
454
|
+
approveUrl: buildApproveUrl(dashboardBase, data.requestId!),
|
|
455
|
+
message: 'Action escalated — waiting for human approval'
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
this.startPolling(data.requestId!, data.secret!);
|
|
459
|
+
|
|
460
|
+
} catch (error) {
|
|
461
|
+
if (error instanceof AgentProfileError) {
|
|
462
|
+
const suffix = error.code ? ` (${error.code})` : '';
|
|
463
|
+
this.send(socket, { type: 'error', message: `${error.message}${suffix}` });
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
const message = getErrorMessage(error);
|
|
467
|
+
this.send(socket, { type: 'error', message });
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Start polling for request approval
|
|
473
|
+
*/
|
|
474
|
+
private startPolling(requestId: string, secret: string): void {
|
|
475
|
+
const MAX_POLL_DURATION_MS = 10 * 60 * 1000; // 10 minutes
|
|
476
|
+
const pollStart = Date.now();
|
|
477
|
+
|
|
478
|
+
const interval = setInterval(async () => {
|
|
479
|
+
// Timeout: stop polling after 10 minutes
|
|
480
|
+
if (Date.now() - pollStart > MAX_POLL_DURATION_MS) {
|
|
481
|
+
const pending = this.pendingAuths.get(requestId);
|
|
482
|
+
if (pending) {
|
|
483
|
+
this.send(pending.socket, { type: 'error', message: 'Auth request timed out (10 minutes)' });
|
|
484
|
+
this.pendingAuths.delete(requestId);
|
|
485
|
+
}
|
|
486
|
+
clearInterval(interval);
|
|
487
|
+
this.pollIntervals.delete(requestId);
|
|
488
|
+
console.error(`[socket] Poll timeout for request ${requestId}`);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
try {
|
|
492
|
+
const response = await fetch(
|
|
493
|
+
`${this.options.serverUrl}/auth/${requestId}?secret=${encodeURIComponent(secret)}`
|
|
494
|
+
);
|
|
495
|
+
|
|
496
|
+
const data = await response.json() as {
|
|
497
|
+
success?: boolean;
|
|
498
|
+
status?: string;
|
|
499
|
+
token?: string;
|
|
500
|
+
encryptedToken?: string;
|
|
501
|
+
agentId?: string;
|
|
502
|
+
limit?: number;
|
|
503
|
+
limits?: { fund?: number; send?: number; swap?: number };
|
|
504
|
+
permissions?: string[];
|
|
505
|
+
walletAccess?: string[];
|
|
506
|
+
profile?: { id: string; version: string; displayName?: string; rationale?: string };
|
|
507
|
+
effectivePolicyHash?: string;
|
|
508
|
+
overrideDelta?: string[];
|
|
509
|
+
warnings?: string[];
|
|
510
|
+
error?: string;
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
if (!response.ok || !data.success) {
|
|
514
|
+
return; // Keep polling
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
const pending = this.pendingAuths.get(requestId);
|
|
518
|
+
if (!pending) {
|
|
519
|
+
clearInterval(interval);
|
|
520
|
+
this.pollIntervals.delete(requestId);
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (data.status === 'approved') {
|
|
525
|
+
if (!data.encryptedToken) {
|
|
526
|
+
this.send(pending.socket, {
|
|
527
|
+
type: 'error',
|
|
528
|
+
message: 'Encrypted token unavailable for auth approval',
|
|
529
|
+
});
|
|
530
|
+
clearInterval(interval);
|
|
531
|
+
this.pollIntervals.delete(requestId);
|
|
532
|
+
this.pendingAuths.delete(requestId);
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
this.send(pending.socket, {
|
|
537
|
+
type: 'auth_approved',
|
|
538
|
+
encryptedToken: data.encryptedToken,
|
|
539
|
+
agentId: data.agentId,
|
|
540
|
+
limit: data.limit,
|
|
541
|
+
limits: data.limits,
|
|
542
|
+
permissions: data.permissions,
|
|
543
|
+
walletAccess: data.walletAccess,
|
|
544
|
+
profile: data.profile,
|
|
545
|
+
effectivePolicyHash: data.effectivePolicyHash,
|
|
546
|
+
overrideDelta: data.overrideDelta,
|
|
547
|
+
warnings: data.warnings,
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
clearInterval(interval);
|
|
551
|
+
this.pollIntervals.delete(requestId);
|
|
552
|
+
this.pendingAuths.delete(requestId);
|
|
553
|
+
} else if (data.status === 'rejected') {
|
|
554
|
+
this.send(pending.socket, {
|
|
555
|
+
type: 'auth_rejected',
|
|
556
|
+
requestId,
|
|
557
|
+
message: 'Request was rejected'
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
clearInterval(interval);
|
|
561
|
+
this.pollIntervals.delete(requestId);
|
|
562
|
+
this.pendingAuths.delete(requestId);
|
|
563
|
+
}
|
|
564
|
+
} catch (err) {
|
|
565
|
+
console.error(`[socket] Poll error for ${requestId}: ${getErrorMessage(err)}`);
|
|
566
|
+
}
|
|
567
|
+
}, 2000);
|
|
568
|
+
|
|
569
|
+
this.pollIntervals.set(requestId, interval);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
private send(socket: net.Socket, message: object): void {
|
|
573
|
+
try {
|
|
574
|
+
socket.write(JSON.stringify(message) + '\n');
|
|
575
|
+
} catch {
|
|
576
|
+
// Socket may be closed
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport Client - RSA encryption for CLI password transport
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the server's transport.ts but provides the encryption side
|
|
5
|
+
* (server has decryption). Uses RSA-OAEP with SHA-256 for semantic security.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { publicEncrypt, constants, generateKeyPairSync } from 'crypto';
|
|
9
|
+
|
|
10
|
+
export interface AgentKeypair {
|
|
11
|
+
publicKey: string;
|
|
12
|
+
privateKey: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Encrypt a password using the server's RSA public key
|
|
17
|
+
* @param password Plaintext password
|
|
18
|
+
* @param publicKeyPem Server's RSA public key in PEM format
|
|
19
|
+
* @returns Base64-encoded RSA-OAEP encrypted password
|
|
20
|
+
*/
|
|
21
|
+
export function encryptPassword(password: string, publicKeyPem: string): string {
|
|
22
|
+
const buffer = Buffer.from(password, 'utf8');
|
|
23
|
+
const encrypted = publicEncrypt(
|
|
24
|
+
{
|
|
25
|
+
key: publicKeyPem,
|
|
26
|
+
padding: constants.RSA_PKCS1_OAEP_PADDING,
|
|
27
|
+
oaepHash: 'sha256'
|
|
28
|
+
},
|
|
29
|
+
buffer
|
|
30
|
+
);
|
|
31
|
+
return encrypted.toString('base64');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Generate an RSA-OAEP keypair for agent token mint requests.
|
|
36
|
+
*
|
|
37
|
+
* The public key is sent as `pubkey` when minting tokens. The private key can
|
|
38
|
+
* be retained by the caller runtime if credential decryption is needed.
|
|
39
|
+
*/
|
|
40
|
+
export function generateAgentKeypair(): AgentKeypair {
|
|
41
|
+
const pair = generateKeyPairSync('rsa', {
|
|
42
|
+
modulusLength: 2048,
|
|
43
|
+
publicKeyEncoding: { type: 'spki', format: 'pem' },
|
|
44
|
+
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
publicKey: pair.publicKey,
|
|
48
|
+
privateKey: pair.privateKey,
|
|
49
|
+
};
|
|
50
|
+
}
|