@onecraft/wallet 0.0.0-stage → 0.1.145
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/.claude-plugin/marketplace.json +20 -0
- package/.openclaw/AGENTS.md +100 -0
- package/.openclaw/extensions/agent-wallet/README.md +195 -0
- package/.openclaw/extensions/agent-wallet/dist/index.js +2198 -0
- package/.openclaw/extensions/agent-wallet/index.ts +2198 -0
- package/.openclaw/extensions/agent-wallet/openclaw.plugin.json +251 -0
- package/.openclaw/extensions/agent-wallet/package.json +49 -0
- package/.openclaw/extensions/agent-wallet/skills/cards/SKILL.md +211 -0
- package/.openclaw/extensions/agent-wallet/skills/wallet-operator/SKILL.md +30 -0
- package/CHANGELOG.md +1232 -0
- package/LICENSE +104 -0
- package/README.md +193 -2
- package/VERSION +1 -0
- package/agent-wallet/.env.example +63 -0
- package/agent-wallet/AGENTS.md +130 -0
- package/agent-wallet/CARD_VAULT.md +640 -0
- package/agent-wallet/README.md +615 -0
- package/agent-wallet/UPGRADE_COMPATIBILITY.md +66 -0
- package/agent-wallet/agent_wallet/__init__.py +16 -0
- package/agent-wallet/agent_wallet/approval.py +165 -0
- package/agent-wallet/agent_wallet/autonomous_permissions.py +281 -0
- package/agent-wallet/agent_wallet/autonomous_policy.py +305 -0
- package/agent-wallet/agent_wallet/autonomous_session.py +236 -0
- package/agent-wallet/agent_wallet/boot_key_migration.py +155 -0
- package/agent-wallet/agent_wallet/boot_key_recovery.py +57 -0
- package/agent-wallet/agent_wallet/bootstrap.py +194 -0
- package/agent-wallet/agent_wallet/card_catalog.py +243 -0
- package/agent-wallet/agent_wallet/card_runtime_secrets.py +108 -0
- package/agent-wallet/agent_wallet/card_vault.py +331 -0
- package/agent-wallet/agent_wallet/card_vault_cli.py +174 -0
- package/agent-wallet/agent_wallet/card_vault_import.py +65 -0
- package/agent-wallet/agent_wallet/card_vault_keychain.py +239 -0
- package/agent-wallet/agent_wallet/config.py +719 -0
- package/agent-wallet/agent_wallet/connector_cli.py +198 -0
- package/agent-wallet/agent_wallet/connectors/__init__.py +28 -0
- package/agent-wallet/agent_wallet/connectors/catalog.py +68 -0
- package/agent-wallet/agent_wallet/connectors/client.py +308 -0
- package/agent-wallet/agent_wallet/connectors/intent_policy.py +243 -0
- package/agent-wallet/agent_wallet/connectors/manifest.py +192 -0
- package/agent-wallet/agent_wallet/connectors/registry.py +341 -0
- package/agent-wallet/agent_wallet/encrypted_storage.py +314 -0
- package/agent-wallet/agent_wallet/evm_user_wallets.py +910 -0
- package/agent-wallet/agent_wallet/exceptions.py +10 -0
- package/agent-wallet/agent_wallet/file_ops.py +34 -0
- package/agent-wallet/agent_wallet/http_client.py +25 -0
- package/agent-wallet/agent_wallet/kernel_browser.py +479 -0
- package/agent-wallet/agent_wallet/kernel_cli.py +57 -0
- package/agent-wallet/agent_wallet/kernel_gateway.py +95 -0
- package/agent-wallet/agent_wallet/keystore.py +503 -0
- package/agent-wallet/agent_wallet/laso_card_vault.py +246 -0
- package/agent-wallet/agent_wallet/models.py +66 -0
- package/agent-wallet/agent_wallet/morpho_monitor.py +298 -0
- package/agent-wallet/agent_wallet/nonce_registry.py +59 -0
- package/agent-wallet/agent_wallet/openclaw_adapter.py +9129 -0
- package/agent-wallet/agent_wallet/openclaw_cli.py +658 -0
- package/agent-wallet/agent_wallet/openclaw_runtime.py +194 -0
- package/agent-wallet/agent_wallet/plugin_bundle.py +44 -0
- package/agent-wallet/agent_wallet/providers/__init__.py +1 -0
- package/agent-wallet/agent_wallet/providers/bags.py +202 -0
- package/agent-wallet/agent_wallet/providers/dexscreener.py +147 -0
- package/agent-wallet/agent_wallet/providers/evm_activity.py +257 -0
- package/agent-wallet/agent_wallet/providers/evm_portfolio.py +459 -0
- package/agent-wallet/agent_wallet/providers/imd.py +720 -0
- package/agent-wallet/agent_wallet/providers/jupiter.py +519 -0
- package/agent-wallet/agent_wallet/providers/kamino.py +404 -0
- package/agent-wallet/agent_wallet/providers/lifi.py +302 -0
- package/agent-wallet/agent_wallet/providers/solana_rpc.py +447 -0
- package/agent-wallet/agent_wallet/providers/tokenized_stocks.py +189 -0
- package/agent-wallet/agent_wallet/providers/wdk_evm_local.py +346 -0
- package/agent-wallet/agent_wallet/providers/x402.py +1972 -0
- package/agent-wallet/agent_wallet/sealed_keys.py +118 -0
- package/agent-wallet/agent_wallet/solana_stake.py +103 -0
- package/agent-wallet/agent_wallet/solana_tx.py +93 -0
- package/agent-wallet/agent_wallet/spending_limits.py +119 -0
- package/agent-wallet/agent_wallet/telemetry.py +481 -0
- package/agent-wallet/agent_wallet/transaction_policy.py +573 -0
- package/agent-wallet/agent_wallet/update_check.py +190 -0
- package/agent-wallet/agent_wallet/user_wallets.py +573 -0
- package/agent-wallet/agent_wallet/validation.py +31 -0
- package/agent-wallet/agent_wallet/vault_executor.py +456 -0
- package/agent-wallet/agent_wallet/wallet_layer/__init__.py +1 -0
- package/agent-wallet/agent_wallet/wallet_layer/base.py +1204 -0
- package/agent-wallet/agent_wallet/wallet_layer/base58.py +44 -0
- package/agent-wallet/agent_wallet/wallet_layer/factory.py +117 -0
- package/agent-wallet/agent_wallet/wallet_layer/solana.py +5246 -0
- package/agent-wallet/agent_wallet/wallet_layer/wdk_evm.py +2705 -0
- package/agent-wallet/examples/bootstrap_wallet.py +21 -0
- package/agent-wallet/examples/openclaw_runtime_onboarding.py +28 -0
- package/agent-wallet/examples/openclaw_user_wallet_example.py +31 -0
- package/agent-wallet/examples/openclaw_wallet_adapter_example.py +33 -0
- package/agent-wallet/openclaw.plugin.json +118 -0
- package/agent-wallet/pyproject.toml +36 -0
- package/agent-wallet/scripts/bootstrap_openclaw_evm.py +312 -0
- package/agent-wallet/scripts/build_release_bundle.py +210 -0
- package/agent-wallet/scripts/finalize_openclaw_local_wallet_config.py +121 -0
- package/agent-wallet/scripts/install_agent_wallet.py +1357 -0
- package/agent-wallet/scripts/install_openclaw_local_config.py +421 -0
- package/agent-wallet/scripts/install_openclaw_sealed_keys.py +117 -0
- package/agent-wallet/scripts/manage_openclaw_evm_wallet.py +333 -0
- package/agent-wallet/scripts/security_utils.py +37 -0
- package/agent-wallet/scripts/setup_evm_wallet.sh +140 -0
- package/agent-wallet/scripts/switch_openclaw_wallet_network.py +109 -0
- package/agent-wallet/skills/wallet-operator/SKILL.md +157 -0
- package/bin/lib/boot-key.mjs +184 -0
- package/bin/lib/evm-daemon.mjs +389 -0
- package/bin/lib/host-detection.mjs +259 -0
- package/bin/lib/integrations.mjs +578 -0
- package/bin/lib/release-python.mjs +9 -0
- package/bin/lib/update-transaction.mjs +235 -0
- package/bin/openclaw-agent-wallet.mjs +3354 -0
- package/claude-code/plugins/agent-wallet/.claude-plugin/plugin.json +19 -0
- package/claude-code/plugins/agent-wallet/.mcp.json +14 -0
- package/claude-code/plugins/agent-wallet/AGENTLAYER_AGENT_GUIDE.md +282 -0
- package/claude-code/plugins/agent-wallet/README.md +134 -0
- package/claude-code/plugins/agent-wallet/commands/agentlayer-autonomous-approve.md +39 -0
- package/claude-code/plugins/agent-wallet/commands/agentlayer-autonomous-revoke.md +17 -0
- package/claude-code/plugins/agent-wallet/commands/cards.md +129 -0
- package/claude-code/plugins/agent-wallet/commands/guide.md +40 -0
- package/claude-code/plugins/agent-wallet/commands/imd.md +125 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-base.md +60 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-ethereum.md +37 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-evm.md +39 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-setup.md +25 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-sol.md +51 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-statusline.md +34 -0
- package/claude-code/plugins/agent-wallet/commands/x402.md +121 -0
- package/claude-code/plugins/agent-wallet/commands/yield.md +62 -0
- package/claude-code/plugins/agent-wallet/hooks/hooks.json +16 -0
- package/claude-code/plugins/agent-wallet/scripts/bootstrap_backend.sh +136 -0
- package/claude-code/plugins/agent-wallet/scripts/enable_statusline.py +52 -0
- package/claude-code/plugins/agent-wallet/scripts/resolve_wallet_addresses.py +69 -0
- package/claude-code/plugins/agent-wallet/scripts/run_mcp.sh +66 -0
- package/claude-code/plugins/agent-wallet/scripts/wallet_statusline.py +130 -0
- package/claude-code/plugins/agent-wallet/scripts/wallet_statusline_setup.sh +40 -0
- package/claude-code/plugins/agent-wallet/skills/wallet-operator/SKILL.md +21 -0
- package/codex/plugins/agent-wallet/.codex-plugin/plugin.json +37 -0
- package/codex/plugins/agent-wallet/.mcp.json +15 -0
- package/codex/plugins/agent-wallet/README.md +158 -0
- package/codex/plugins/agent-wallet/scripts/run_mcp.sh +47 -0
- package/codex/plugins/agent-wallet/server.py +1797 -0
- package/codex/plugins/agent-wallet/skills/cards/SKILL.md +225 -0
- package/codex/plugins/agent-wallet/skills/imd/SKILL.md +145 -0
- package/codex/plugins/agent-wallet/skills/wallet-base/SKILL.md +56 -0
- package/codex/plugins/agent-wallet/skills/wallet-operator/SKILL.md +85 -0
- package/codex/plugins/agent-wallet/skills/wallet-sol/SKILL.md +29 -0
- package/codex/plugins/agent-wallet/skills/x402/SKILL.md +159 -0
- package/codex/plugins/agent-wallet/skills/yield/SKILL.md +65 -0
- package/connectors/AGENTS.md +37 -0
- package/connectors/DEVELOPER_GUIDE.md +131 -0
- package/connectors/README.md +139 -0
- package/connectors/READ_ONLY_BETA.md +54 -0
- package/connectors/RELEASING.md +48 -0
- package/connectors/conformance/README.md +31 -0
- package/connectors/conformance/package.json +54 -0
- package/connectors/conformance/scripts/sync-license.mjs +3 -0
- package/connectors/conformance/scripts/sync-spec.mjs +16 -0
- package/connectors/conformance/src/cli.ts +43 -0
- package/connectors/conformance/src/index.ts +7 -0
- package/connectors/conformance/src/runner.ts +314 -0
- package/connectors/conformance/src/types.ts +27 -0
- package/connectors/conformance/test/fixtures/invalid-response-identity.json +14 -0
- package/connectors/conformance/test/fixtures/missing-tool-fixture.json +4 -0
- package/connectors/conformance/test/runner.test.mjs +151 -0
- package/connectors/conformance/tsconfig.json +17 -0
- package/connectors/examples/reference-crypto-data/Dockerfile +21 -0
- package/connectors/examples/reference-crypto-data/README.md +51 -0
- package/connectors/examples/reference-crypto-data/conformance.json +11 -0
- package/connectors/examples/reference-crypto-data/connector.json +95 -0
- package/connectors/examples/reference-crypto-data/package.json +21 -0
- package/connectors/examples/reference-crypto-data/railway.toml +9 -0
- package/connectors/examples/reference-crypto-data/src/connector.ts +137 -0
- package/connectors/examples/reference-crypto-data/src/server.ts +13 -0
- package/connectors/examples/reference-crypto-data/test/connector.test.mjs +97 -0
- package/connectors/examples/reference-crypto-data/tsconfig.json +17 -0
- package/connectors/package-lock.json +561 -0
- package/connectors/package.json +19 -0
- package/connectors/scripts/smoke-packed-packages.mjs +121 -0
- package/connectors/sdk-typescript/README.md +47 -0
- package/connectors/sdk-typescript/package.json +49 -0
- package/connectors/sdk-typescript/scripts/sync-license.mjs +3 -0
- package/connectors/sdk-typescript/src/connector.ts +204 -0
- package/connectors/sdk-typescript/src/errors.ts +11 -0
- package/connectors/sdk-typescript/src/http.ts +116 -0
- package/connectors/sdk-typescript/src/index.ts +26 -0
- package/connectors/sdk-typescript/src/types.ts +101 -0
- package/connectors/sdk-typescript/test/sdk.test.mjs +181 -0
- package/connectors/sdk-typescript/tsconfig.json +21 -0
- package/connectors/spec/connector-manifest.schema.json +340 -0
- package/connectors/spec/connector-protocol.md +159 -0
- package/connectors/spec/transaction-intent.schema.json +281 -0
- package/connectors/templates/read-only/.env.example +1 -0
- package/connectors/templates/read-only/Dockerfile +11 -0
- package/connectors/templates/read-only/README.md +33 -0
- package/connectors/templates/read-only/conformance.json +11 -0
- package/connectors/templates/read-only/connector.json +64 -0
- package/connectors/templates/read-only/package.json +21 -0
- package/connectors/templates/read-only/railway.toml +9 -0
- package/connectors/templates/read-only/src/connector.ts +61 -0
- package/connectors/templates/read-only/src/server.ts +14 -0
- package/connectors/templates/read-only/test/connector.test.mjs +62 -0
- package/connectors/templates/read-only/tsconfig.json +17 -0
- package/cursor/plugins/agent-wallet/.cursor-plugin/plugin.json +14 -0
- package/cursor/plugins/agent-wallet/README.md +62 -0
- package/cursor/plugins/agent-wallet/mcp.json +16 -0
- package/cursor/plugins/agent-wallet/scripts/run_mcp.sh +33 -0
- package/cursor/plugins/agent-wallet/server.py +33 -0
- package/cursor/plugins/agent-wallet/skills/cards/SKILL.md +210 -0
- package/cursor/plugins/agent-wallet/skills/wallet-base/SKILL.md +56 -0
- package/cursor/plugins/agent-wallet/skills/wallet-operator/SKILL.md +23 -0
- package/cursor/plugins/agent-wallet/skills/wallet-sol/SKILL.md +29 -0
- package/cursor/plugins/agent-wallet/skills/x402/SKILL.md +130 -0
- package/hermes/plugins/agent_wallet/README.md +54 -0
- package/hermes/plugins/agent_wallet/__init__.py +55 -0
- package/hermes/plugins/agent_wallet/plugin.yaml +9 -0
- package/hermes/plugins/agent_wallet/schemas.py +211 -0
- package/hermes/plugins/agent_wallet/tools.py +622 -0
- package/install-from-github.sh +139 -0
- package/integrations/hedera/treasury-guard/README.md +92 -0
- package/integrations/hedera/treasury-guard/examples/treasury-policy.example.json +9 -0
- package/integrations/hedera/treasury-guard/package-lock.json +880 -0
- package/integrations/hedera/treasury-guard/package.json +8 -0
- package/integrations/hedera/treasury-guard/skills/onecraft-hedera-treasury/SKILL.md +22 -0
- package/integrations/hedera/treasury-guard/src/hedera-mirror-client.mjs +106 -0
- package/integrations/hedera/treasury-guard/src/hedera-signer.mjs +120 -0
- package/integrations/hedera/treasury-guard/src/treasury-cli.mjs +177 -0
- package/integrations/hedera/treasury-guard/src/treasury-policy.mjs +155 -0
- package/mcp/README.md +39 -0
- package/mcp/scripts/run_mcp.sh +37 -0
- package/mcp/server.py +33 -0
- package/package.json +106 -4
- package/scripts/check_release_version.mjs +72 -0
- package/scripts/version_targets.mjs +60 -0
- package/setup.sh +87 -0
- package/wdk-evm-wallet/.env.example +38 -0
- package/wdk-evm-wallet/README.md +254 -0
- package/wdk-evm-wallet/bootstrap.sh +8 -0
- package/wdk-evm-wallet/package-lock.json +2359 -0
- package/wdk-evm-wallet/package.json +43 -0
- package/wdk-evm-wallet/run-local.sh +12 -0
- package/wdk-evm-wallet/src/config.js +461 -0
- package/wdk-evm-wallet/src/imd.js +231 -0
- package/wdk-evm-wallet/src/json.js +35 -0
- package/wdk-evm-wallet/src/local_vault.js +407 -0
- package/wdk-evm-wallet/src/network_state.js +96 -0
- package/wdk-evm-wallet/src/pending_transactions.js +148 -0
- package/wdk-evm-wallet/src/server.js +849 -0
- package/wdk-evm-wallet/src/shutdown.js +63 -0
- package/wdk-evm-wallet/src/wdk_evm_wallet.js +10036 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"""macOS login Keychain storage requiring its password on every secret read.
|
|
2
|
+
|
|
3
|
+
Deliberately independent of the wallet boot-key store, whose ACL permits silent
|
|
4
|
+
reads. Uses Security.framework directly: no passwords or keys in shell argv,
|
|
5
|
+
subprocess stdout, environment variables, or plaintext fallback files.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import ctypes as C
|
|
10
|
+
import hashlib
|
|
11
|
+
import platform
|
|
12
|
+
import sys
|
|
13
|
+
import threading
|
|
14
|
+
from contextlib import contextmanager
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
from agent_wallet.wallet_layer.base import WalletBackendError
|
|
18
|
+
|
|
19
|
+
PROTECTION = "macos-login-keychain-password"
|
|
20
|
+
REQUIRE_PASSWORD = 0x0001
|
|
21
|
+
_INTERACTION_LOCK = threading.RLock()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class MacCardKeychain:
|
|
25
|
+
def __init__(self, root: Path):
|
|
26
|
+
if sys.platform != "darwin":
|
|
27
|
+
raise WalletBackendError("Automatic card vault currently requires macOS login Keychain. No insecure fallback is used.")
|
|
28
|
+
version = tuple(int(part) for part in platform.mac_ver()[0].split(".") if part.isdigit())
|
|
29
|
+
if version < (10, 13, 1):
|
|
30
|
+
raise WalletBackendError("Card vault system authentication requires macOS 10.13.1 or newer.")
|
|
31
|
+
self.service = "tech.agentlayer.card-vault." + hashlib.sha256(str(root.resolve()).encode()).hexdigest()
|
|
32
|
+
self.cf = C.CDLL("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")
|
|
33
|
+
self.sec = C.CDLL("/System/Library/Frameworks/Security.framework/Security")
|
|
34
|
+
ptr, status = C.c_void_p, C.c_int32
|
|
35
|
+
signatures = {
|
|
36
|
+
"CFRelease": (None, [ptr]),
|
|
37
|
+
"CFStringCreateWithCString": (ptr, [ptr, C.c_char_p, C.c_uint32]),
|
|
38
|
+
"CFArrayCreate": (ptr, [ptr, ptr, C.c_long, ptr]),
|
|
39
|
+
"CFArrayGetCount": (C.c_long, [ptr]),
|
|
40
|
+
"CFArrayGetValueAtIndex": (ptr, [ptr, C.c_long]),
|
|
41
|
+
"CFDataCreate": (ptr, [ptr, ptr, C.c_long]),
|
|
42
|
+
"CFDictionaryCreateMutable": (ptr, [ptr, C.c_long, ptr, ptr]),
|
|
43
|
+
"CFDictionarySetValue": (None, [ptr, ptr, ptr]),
|
|
44
|
+
}
|
|
45
|
+
for name, (result, args) in signatures.items():
|
|
46
|
+
fn = getattr(self.cf, name)
|
|
47
|
+
fn.restype, fn.argtypes = result, args
|
|
48
|
+
security = {
|
|
49
|
+
"SecKeychainOpen": (status, [C.c_char_p, C.POINTER(ptr)]),
|
|
50
|
+
"SecAccessCreate": (status, [ptr, ptr, C.POINTER(ptr)]),
|
|
51
|
+
"SecAccessCopyACLList": (status, [ptr, C.POINTER(ptr)]),
|
|
52
|
+
"SecAccessCopyMatchingACLList": (ptr, [ptr, ptr]),
|
|
53
|
+
"SecACLCopyContents": (status, [ptr, C.POINTER(ptr), C.POINTER(ptr), C.POINTER(C.c_uint16)]),
|
|
54
|
+
"SecACLSetContents": (status, [ptr, ptr, ptr, C.c_uint16]),
|
|
55
|
+
"SecItemAdd": (status, [ptr, C.POINTER(ptr)]),
|
|
56
|
+
"SecItemCopyMatching": (status, [ptr, C.POINTER(ptr)]),
|
|
57
|
+
"SecKeychainItemCopyAccess": (status, [ptr, C.POINTER(ptr)]),
|
|
58
|
+
"SecKeychainItemCopyContent": (status, [ptr, ptr, ptr, C.POINTER(C.c_uint32), C.POINTER(ptr)]),
|
|
59
|
+
"SecKeychainItemFreeContent": (status, [ptr, ptr]),
|
|
60
|
+
"SecKeychainGetUserInteractionAllowed": (status, [C.POINTER(C.c_ubyte)]),
|
|
61
|
+
"SecKeychainSetUserInteractionAllowed": (status, [C.c_ubyte]),
|
|
62
|
+
}
|
|
63
|
+
for name, (result, args) in security.items():
|
|
64
|
+
fn = getattr(self.sec, name)
|
|
65
|
+
fn.restype, fn.argtypes = result, args
|
|
66
|
+
|
|
67
|
+
def _constant(self, name: str) -> int:
|
|
68
|
+
library = self.cf if name.startswith("kCF") else self.sec
|
|
69
|
+
return C.c_void_p.in_dll(library, name).value
|
|
70
|
+
|
|
71
|
+
def _callback(self, name: str) -> int:
|
|
72
|
+
return C.addressof(C.c_char.in_dll(self.cf, name))
|
|
73
|
+
|
|
74
|
+
def _string(self, text: str) -> int:
|
|
75
|
+
return self.cf.CFStringCreateWithCString(None, text.encode(), 0x08000100)
|
|
76
|
+
|
|
77
|
+
def _release(self, *references) -> None:
|
|
78
|
+
for reference in references:
|
|
79
|
+
if reference:
|
|
80
|
+
self.cf.CFRelease(reference)
|
|
81
|
+
|
|
82
|
+
@staticmethod
|
|
83
|
+
def _check(code: int) -> None:
|
|
84
|
+
if code:
|
|
85
|
+
raise WalletBackendError(
|
|
86
|
+
f"macOS Keychain denied or could not complete card vault access ({code}). "
|
|
87
|
+
"Unlock your login Keychain and retry in a local terminal."
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
@contextmanager
|
|
91
|
+
def _interaction(self, allowed: bool):
|
|
92
|
+
# This Security.framework setting applies to the whole process.
|
|
93
|
+
with _INTERACTION_LOCK:
|
|
94
|
+
previous = C.c_ubyte()
|
|
95
|
+
self._check(self.sec.SecKeychainGetUserInteractionAllowed(C.byref(previous)))
|
|
96
|
+
self._check(self.sec.SecKeychainSetUserInteractionAllowed(allowed))
|
|
97
|
+
try:
|
|
98
|
+
yield
|
|
99
|
+
finally:
|
|
100
|
+
self.sec.SecKeychainSetUserInteractionAllowed(previous.value)
|
|
101
|
+
|
|
102
|
+
@contextmanager
|
|
103
|
+
def _keychain(self):
|
|
104
|
+
# Pin the login keychain rather than following a user-selected default
|
|
105
|
+
# keychain, which may have a different, application-specific password.
|
|
106
|
+
keychain = C.c_void_p()
|
|
107
|
+
base = Path.home() / "Library" / "Keychains"
|
|
108
|
+
path = base / "login.keychain-db"
|
|
109
|
+
if not path.exists():
|
|
110
|
+
path = base / "login.keychain"
|
|
111
|
+
try:
|
|
112
|
+
self._check(self.sec.SecKeychainOpen(str(path).encode(), C.byref(keychain)))
|
|
113
|
+
yield keychain
|
|
114
|
+
finally:
|
|
115
|
+
self._release(keychain)
|
|
116
|
+
|
|
117
|
+
@contextmanager
|
|
118
|
+
def _query(self, account: str):
|
|
119
|
+
with self._keychain() as keychain:
|
|
120
|
+
service, user = self._string(self.service), self._string(account)
|
|
121
|
+
elements = (C.c_void_p * 1)(keychain.value)
|
|
122
|
+
keychains = self.cf.CFArrayCreate(None, elements, 1, self._callback("kCFTypeArrayCallBacks"))
|
|
123
|
+
query = self.cf.CFDictionaryCreateMutable(
|
|
124
|
+
None, 0, self._callback("kCFTypeDictionaryKeyCallBacks"),
|
|
125
|
+
self._callback("kCFTypeDictionaryValueCallBacks"),
|
|
126
|
+
)
|
|
127
|
+
try:
|
|
128
|
+
self._set(query, "kSecClass", self._constant("kSecClassGenericPassword"))
|
|
129
|
+
self._set(query, "kSecAttrService", service)
|
|
130
|
+
self._set(query, "kSecAttrAccount", user)
|
|
131
|
+
self._set(query, "kSecUseKeychain", keychain)
|
|
132
|
+
self._set(query, "kSecMatchSearchList", keychains)
|
|
133
|
+
self._set(query, "kSecReturnRef", self._constant("kCFBooleanTrue"))
|
|
134
|
+
yield query
|
|
135
|
+
finally:
|
|
136
|
+
self._release(query, keychains, service, user)
|
|
137
|
+
|
|
138
|
+
def _set(self, query, name: str, value) -> None:
|
|
139
|
+
self.cf.CFDictionarySetValue(query, self._constant(name), value)
|
|
140
|
+
|
|
141
|
+
def _acl_lists(self, access):
|
|
142
|
+
# A permissive wildcard OR decrypt/ACL-change entry could bypass a stricter
|
|
143
|
+
# entry. Check all entries granting any of those authorizations.
|
|
144
|
+
for name in ("kSecACLAuthorizationAny", "kSecACLAuthorizationDecrypt", "kSecACLAuthorizationChangeACL"):
|
|
145
|
+
entries = self.sec.SecAccessCopyMatchingACLList(access, self._constant(name))
|
|
146
|
+
try:
|
|
147
|
+
if entries:
|
|
148
|
+
for index in range(self.cf.CFArrayGetCount(entries)):
|
|
149
|
+
yield self.cf.CFArrayGetValueAtIndex(entries, index)
|
|
150
|
+
finally:
|
|
151
|
+
self._release(entries)
|
|
152
|
+
|
|
153
|
+
def _validate_access(self, access) -> None:
|
|
154
|
+
checked = 0
|
|
155
|
+
for acl in self._acl_lists(access):
|
|
156
|
+
applications, description = C.c_void_p(), C.c_void_p()
|
|
157
|
+
flags = C.c_uint16()
|
|
158
|
+
try:
|
|
159
|
+
self._check(self.sec.SecACLCopyContents(acl, C.byref(applications), C.byref(description), C.byref(flags)))
|
|
160
|
+
# NULL means trust everyone. An empty array means trust nobody.
|
|
161
|
+
trusted = not applications or self.cf.CFArrayGetCount(applications) != 0
|
|
162
|
+
# Since macOS 10.13.1 the OS ignores promptSelector and requires
|
|
163
|
+
# the Keychain password for untrusted callers. Persisted flags
|
|
164
|
+
# may be normalized by Security.framework; the empty trusted-app
|
|
165
|
+
# list is the essential per-access boundary on supported systems.
|
|
166
|
+
if trusted:
|
|
167
|
+
raise WalletBackendError("Card vault Keychain permissions allow silent access. Refusing to use this key.")
|
|
168
|
+
checked += 1
|
|
169
|
+
finally:
|
|
170
|
+
self._release(applications, description)
|
|
171
|
+
if not checked:
|
|
172
|
+
raise WalletBackendError("Card vault Keychain authentication policy is missing.")
|
|
173
|
+
|
|
174
|
+
def _validate_item(self, item) -> None:
|
|
175
|
+
access = C.c_void_p()
|
|
176
|
+
try:
|
|
177
|
+
self._check(self.sec.SecKeychainItemCopyAccess(item, C.byref(access)))
|
|
178
|
+
self._validate_access(access)
|
|
179
|
+
finally:
|
|
180
|
+
self._release(access)
|
|
181
|
+
|
|
182
|
+
@contextmanager
|
|
183
|
+
def _item(self, account: str):
|
|
184
|
+
item = C.c_void_p()
|
|
185
|
+
with self._query(account) as query:
|
|
186
|
+
try:
|
|
187
|
+
self._check(self.sec.SecItemCopyMatching(query, C.byref(item)))
|
|
188
|
+
self._validate_item(item)
|
|
189
|
+
yield item
|
|
190
|
+
finally:
|
|
191
|
+
self._release(item)
|
|
192
|
+
|
|
193
|
+
def create(self, account: str, key: bytes) -> None:
|
|
194
|
+
if len(key) != 32:
|
|
195
|
+
raise WalletBackendError("Invalid card vault private key.")
|
|
196
|
+
label = self._string("AgentLayer card vault — unlock saved cards")
|
|
197
|
+
empty = self.cf.CFArrayCreate(None, None, 0, self._callback("kCFTypeArrayCallBacks"))
|
|
198
|
+
access, entries, item = C.c_void_p(), C.c_void_p(), C.c_void_p()
|
|
199
|
+
buffer = C.create_string_buffer(key)
|
|
200
|
+
data = self.cf.CFDataCreate(None, buffer, len(key))
|
|
201
|
+
try:
|
|
202
|
+
with self._interaction(False):
|
|
203
|
+
self._check(self.sec.SecAccessCreate(label, empty, C.byref(access)))
|
|
204
|
+
self._check(self.sec.SecAccessCopyACLList(access, C.byref(entries)))
|
|
205
|
+
for index in range(self.cf.CFArrayGetCount(entries)):
|
|
206
|
+
acl = self.cf.CFArrayGetValueAtIndex(entries, index)
|
|
207
|
+
self._check(self.sec.SecACLSetContents(acl, empty, label, REQUIRE_PASSWORD))
|
|
208
|
+
self._validate_access(access)
|
|
209
|
+
with self._query(account) as query:
|
|
210
|
+
self._set(query, "kSecAttrAccess", access)
|
|
211
|
+
self._set(query, "kSecAttrLabel", label)
|
|
212
|
+
self._set(query, "kSecValueData", data)
|
|
213
|
+
# SecItemAdd is create-only; existing keys are never replaced.
|
|
214
|
+
self._check(self.sec.SecItemAdd(query, C.byref(item)))
|
|
215
|
+
self._validate_item(item)
|
|
216
|
+
finally:
|
|
217
|
+
C.memset(buffer, 0, len(buffer))
|
|
218
|
+
self._release(data, item, entries, access, empty, label)
|
|
219
|
+
|
|
220
|
+
def check(self, account: str) -> None:
|
|
221
|
+
"""Check existence and ACL without reading secret data or displaying UI."""
|
|
222
|
+
with self._interaction(False), self._item(account):
|
|
223
|
+
pass
|
|
224
|
+
|
|
225
|
+
def get(self, account: str) -> bytes:
|
|
226
|
+
"""The OS, not Python, collects the login Keychain password."""
|
|
227
|
+
data, length = C.c_void_p(), C.c_uint32()
|
|
228
|
+
with self._interaction(True), self._item(account) as item:
|
|
229
|
+
try:
|
|
230
|
+
self._check(self.sec.SecKeychainItemCopyContent(item, None, None, C.byref(length), C.byref(data)))
|
|
231
|
+
# Recheck in case the user changed trust settings in the dialog.
|
|
232
|
+
self._validate_item(item)
|
|
233
|
+
if length.value != 32:
|
|
234
|
+
raise WalletBackendError("Invalid card vault key in macOS Keychain.")
|
|
235
|
+
return C.string_at(data, length.value)
|
|
236
|
+
finally:
|
|
237
|
+
if data:
|
|
238
|
+
C.memset(data, 0, length.value)
|
|
239
|
+
self.sec.SecKeychainItemFreeContent(None, data)
|