@t-rex-network/onchainid 0.0.0-stage → 3.0.0-beta2
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.md +674 -0
- package/NOTICE.md +66 -0
- package/README.md +177 -2
- package/contracts/Identity.sol +235 -0
- package/contracts/IdentityUtilities.sol +269 -0
- package/contracts/KeyManager.sol +193 -0
- package/contracts/SmartAccount.sol +222 -0
- package/contracts/factory/IIdentityFactory.sol +325 -0
- package/contracts/factory/IdentityFactory.sol +818 -0
- package/contracts/interface/IClaimIssuer.sol +105 -0
- package/contracts/interface/IERC734.sol +69 -0
- package/contracts/interface/IERC735.sol +149 -0
- package/contracts/interface/IIdentity.sol +63 -0
- package/contracts/interface/IIdentityUtilities.sol +135 -0
- package/contracts/interface/IKeyExecutor.sol +84 -0
- package/contracts/libraries/Errors.sol +407 -0
- package/contracts/libraries/FormatResolver.sol +74 -0
- package/contracts/libraries/Hashing.sol +35 -0
- package/contracts/libraries/IdentityTypes.sol +53 -0
- package/contracts/libraries/KeyPurposes.sol +49 -0
- package/contracts/libraries/KeyTypes.sol +46 -0
- package/contracts/modules/claims/EASClaimIssuer.sol +348 -0
- package/contracts/modules/executors/KeyApprovalModule.sol +313 -0
- package/contracts/modules/executors/RecoveryModule.sol +88 -0
- package/contracts/modules/validators/ERC734Validator.sol +1000 -0
- package/contracts/modules/validators/ERC7579Validator.sol +74 -0
- package/contracts/proxy/IdentityUtilitiesProxy.sol +36 -0
- package/contracts/reputation/IReputationRegistry.sol +117 -0
- package/contracts/reputation/ReputationRegistry.sol +155 -0
- package/contracts/storage/Structs.sol +176 -0
- package/contracts/vendor/eas/IEAS.sol +36 -0
- package/contracts/vendor/utils/SafeCalldataBatch.sol +61 -0
- package/out/AbstractSigner.sol/AbstractSigner.json +1 -0
- package/out/AccessControlUpgradeable.sol/AccessControlUpgradeable.json +1 -0
- package/out/AccessManaged.sol/AccessManaged.json +1 -0
- package/out/AccessManager.sol/AccessManager.json +1 -0
- package/out/Account.sol/Account.json +1 -0
- package/out/AddClaimByTrustedIssuer.t.sol/AddClaimAsTrustedIssuerTest.json +1 -0
- package/out/Address.sol/Address.json +1 -0
- package/out/Arrays.sol/Arrays.json +1 -0
- package/out/AuthorityUtils.sol/AuthorityUtils.json +1 -0
- package/out/Base.sol/CommonBase.json +1 -0
- package/out/Base.sol/ScriptBase.json +1 -0
- package/out/Base.sol/TestBase.json +1 -0
- package/out/Base64.sol/Base64.json +1 -0
- package/out/BatchDecodeParity.t.sol/BatchDecodeParityTest.json +1 -0
- package/out/BeaconProxy.sol/BeaconProxy.json +1 -0
- package/out/Bytes.sol/Bytes.json +1 -0
- package/out/Calldata.sol/Calldata.json +1 -0
- package/out/ClaimSignatureDefinition.t.sol/ClaimSignatureDefinitionTest.json +1 -0
- package/out/ClaimSignatureDefinition.t.sol/NoERC1271Delegate.json +1 -0
- package/out/ClaimSignatureDefinition.t.sol/PickyERC1271Delegate.json +1 -0
- package/out/ClaimSignerHelper.sol/ClaimSignerHelper.json +1 -0
- package/out/ClaimTo.t.sol/ClaimToTest.json +1 -0
- package/out/Claims.t.sol/ClaimsTest.json +1 -0
- package/out/Claims.t.sol/ExternalIssuer.json +1 -0
- package/out/Comparators.sol/Comparators.json +1 -0
- package/out/Constants.sol/Constants.json +1 -0
- package/out/Context.sol/Context.json +1 -0
- package/out/ContextUpgradeable.sol/ContextUpgradeable.json +1 -0
- package/out/Create2.sol/Create2.json +1 -0
- package/out/Create3.sol/Create3.json +1 -0
- package/out/DeployOnchainID.s.sol/DeployOnchainID.json +1 -0
- package/out/EASClaimIssuer.sol/EASClaimIssuer.json +1 -0
- package/out/EASClaimIssuer.t.sol/EASClaimIssuerTest.json +1 -0
- package/out/EASClaimIssuer.t.sol/VmContractHelper29562166e1daff82a9ba4e08c324c14e885cfef135c42b5774ced18642e5fa19.json +1 -0
- package/out/EASTypes.sol/IEASTest.json +1 -0
- package/out/EASTypes.sol/ISchemaRegistryTest.json +1 -0
- package/out/ECDSA.sol/ECDSA.json +1 -0
- package/out/EIP712.sol/EIP712.json +1 -0
- package/out/ERC165.sol/ERC165.json +1 -0
- package/out/ERC165Upgradeable.sol/ERC165Upgradeable.json +1 -0
- package/out/ERC1967Proxy.sol/ERC1967Proxy.json +1 -0
- package/out/ERC1967Utils.sol/ERC1967Utils.json +1 -0
- package/out/ERC4337Utils.sol/ERC4337Utils.json +1 -0
- package/out/ERC4337Utils.sol/IEntryPointExtra.json +1 -0
- package/out/ERC734Validator.sol/ERC734Validator.json +1 -0
- package/out/ERC734Validator.t.sol/ERC734ValidatorTest.json +1 -0
- package/out/ERC734Validator.t.sol/PocCounter.json +1 -0
- package/out/ERC734Validator.t.sol/VmContractHelper7beb488c9b6c5f9f79178a8ce1e9ea8b7d447a9f1b366d4a3784214e9066b776.json +1 -0
- package/out/ERC7579DelayedExecutor.sol/ERC7579DelayedExecutor.json +1 -0
- package/out/ERC7579Executor.sol/ERC7579Executor.json +1 -0
- package/out/ERC7579Multisig.sol/ERC7579Multisig.json +1 -0
- package/out/ERC7579MultisigWeighted.sol/ERC7579MultisigWeighted.json +1 -0
- package/out/ERC7579SocialRecoveryExecutor.sol/ERC7579SocialRecoveryExecutor.json +1 -0
- package/out/ERC7579Validator.sol/ERC7579Validator.json +1 -0
- package/out/ERC7786Recipient.sol/ERC7786Recipient.json +1 -0
- package/out/ERC7913WebAuthnVerifier.sol/ERC7913WebAuthnVerifier.json +1 -0
- package/out/EnumerableSet.sol/EnumerableSet.json +1 -0
- package/out/Errors.sol/Errors.json +1 -0
- package/out/Executions.t.sol/ETHReceiver.json +1 -0
- package/out/Executions.t.sol/ExecutionsTest.json +1 -0
- package/out/Executions.t.sol/RevertingReceiver.json +1 -0
- package/out/FormatResolver.sol/FormatResolver.json +1 -0
- package/out/Hashes.sol/Hashes.json +1 -0
- package/out/IAccessControl.sol/IAccessControl.json +1 -0
- package/out/IAccessManaged.sol/IAccessManaged.json +1 -0
- package/out/IAccessManager.sol/IAccessManager.json +1 -0
- package/out/IAuthority.sol/IAuthority.json +1 -0
- package/out/IBeacon.sol/IBeacon.json +1 -0
- package/out/IClaimIssuer.sol/IClaimIssuer.json +1 -0
- package/out/IEAS.sol/IEAS.json +1 -0
- package/out/IERC1271.sol/IERC1271.json +1 -0
- package/out/IERC165.sol/IERC165.json +1 -0
- package/out/IERC1967.sol/IERC1967.json +1 -0
- package/out/IERC4337.sol/IAccount.json +1 -0
- package/out/IERC4337.sol/IAccountExecute.json +1 -0
- package/out/IERC4337.sol/IAggregator.json +1 -0
- package/out/IERC4337.sol/IEntryPoint.json +1 -0
- package/out/IERC4337.sol/IEntryPointNonces.json +1 -0
- package/out/IERC4337.sol/IEntryPointStake.json +1 -0
- package/out/IERC4337.sol/IPaymaster.json +1 -0
- package/out/IERC5267.sol/IERC5267.json +1 -0
- package/out/IERC734.sol/IERC734.json +1 -0
- package/out/IERC734Surface.t.sol/IERC734SurfaceTest.json +1 -0
- package/out/IERC735.sol/IERC735.json +1 -0
- package/out/IERC7913.sol/IERC7913SignatureVerifier.json +1 -0
- package/out/IIdentity.sol/IIdentity.json +1 -0
- package/out/IIdentityFactory.sol/IIdentityFactory.json +1 -0
- package/out/IIdentityUtilities.sol/IIdentityUtilities.json +1 -0
- package/out/IKeyExecutor.sol/IKeyExecutor.json +1 -0
- package/out/IMulticall3.sol/IMulticall3.json +1 -0
- package/out/IReputationRegistry.sol/IReputationRegistry.json +1 -0
- package/out/Identity.sol/Identity.json +1 -0
- package/out/IdentityFactory.sol/IdentityFactory.json +1 -0
- package/out/IdentityFactory.t.sol/IdentityFactoryTest.json +1 -0
- package/out/IdentityFactory.t.sol/VmContractHelper28a7b3ffc37fea8b5c41ecc8f253eb5ab470e21bb0401440d9a55fcb4f8afe5c.json +1 -0
- package/out/IdentityHelper.sol/IdentityHelper.json +1 -0
- package/out/IdentityHelper.sol/VmContractHelper78387a8fc41a64804f1f0fc2cbba310bbca11e4f057b06dfa169d4c103c08be5.json +1 -0
- package/out/IdentityTypes.sol/IdentityTypes.json +1 -0
- package/out/IdentityUtilities.sol/IdentityUtilities.json +1 -0
- package/out/IdentityUtilities.t.sol/IdentityUtilitiesTest.json +1 -0
- package/out/IdentityUtilities.t.sol/VmContractHelper7ed074704942d210565581d7e79e91a1d3425a5a7e758acb90866c42420e726c.json +1 -0
- package/out/IdentityUtilitiesProxy.sol/IdentityUtilitiesProxy.json +1 -0
- package/out/Init.t.sol/InitTest.json +1 -0
- package/out/Init.t.sol/VmContractHelper95bc81f417f4a3acb58eafba49b7834c5e65588c78654308ee428eb7d9276cce.json +1 -0
- package/out/Initializable.sol/Initializable.json +1 -0
- package/out/InteroperableAddressEncoding.t.sol/InteroperableAddressEncodingTest.json +1 -0
- package/out/KeyApprovalModule.sol/IIdentityAccount.json +1 -0
- package/out/KeyApprovalModule.sol/KeyApprovalModule.json +1 -0
- package/out/KeyApprovalModuleFactoryGuard.t.sol/KeyApprovalModuleFactoryGuardTest.json +1 -0
- package/out/KeyManager.sol/KeyManager.json +1 -0
- package/out/KeyPurposes.sol/KeyPurposes.json +1 -0
- package/out/KeyTypes.sol/KeyTypes.json +1 -0
- package/out/Keys.t.sol/KeysTest.json +1 -0
- package/out/LowLevelCall.sol/LowLevelCall.json +1 -0
- package/out/Math.sol/Math.json +1 -0
- package/out/MessageHashUtils.sol/MessageHashUtils.json +1 -0
- package/out/MockERC1271Signer.sol/MockERC1271Signer.json +1 -0
- package/out/MockERC1271Wallet.sol/MockERC1271Wallet.json +1 -0
- package/out/MockERC7786Gateway.sol/MockERC7786Gateway.json +1 -0
- package/out/MockERC7913PermissiveVerifier.sol/MockERC7913PermissiveVerifier.json +1 -0
- package/out/MockLyingERC734Getter.sol/MockLyingERC734Getter.json +1 -0
- package/out/MockStockECDSAValidator.sol/MockStockECDSAValidator.json +1 -0
- package/out/Multicall.sol/Multicall.json +1 -0
- package/out/Multisig.sol/Multisig.json +1 -0
- package/out/Nonces.sol/Nonces.json +1 -0
- package/out/OnchainIDSetup.sol/OnchainIDSetup.json +1 -0
- package/out/Ownable.sol/Ownable.json +1 -0
- package/out/P256.sol/P256.json +1 -0
- package/out/Packing.sol/Packing.json +1 -0
- package/out/Panic.sol/Panic.json +1 -0
- package/out/PrivilegedReentryGuard.t.sol/PocCounter.json +1 -0
- package/out/PrivilegedReentryGuard.t.sol/PrivilegedReentryGuardTest.json +1 -0
- package/out/Proxy.sol/Proxy.json +1 -0
- package/out/Proxy.t.sol/ProxyTest.json +1 -0
- package/out/Proxy.t.sol/VmContractHelper20ec29ce959b555228240226871c123d935ae49f617ce49540ee53c85f9f8cd4.json +1 -0
- package/out/ProxyPattern.t.sol/ProxyPatternTest.json +1 -0
- package/out/RecoveryModule.sol/RecoveryModule.json +1 -0
- package/out/RecoveryModule.t.sol/RecoveryModuleTest.json +1 -0
- package/out/RecoveryModule.t.sol/VmContractHelper84563bc19cefad0d2824def84f4cab79093d389b1866eff467a2908e14dd8421.json +1 -0
- package/out/ReputationRegistry.sol/ReputationRegistry.json +1 -0
- package/out/ReputationRegistry.t.sol/FakeIdentity.json +1 -0
- package/out/ReputationRegistry.t.sol/ReputationRegistryTest.json +1 -0
- package/out/ReputationRegistry.t.sol/VmContractHelper4353cedc5e63171396a0756138ec48ebba489252c7f4fef50b08f9e2c0989ec9.json +1 -0
- package/out/RevertingIdentity.sol/RevertingIdentity.json +1 -0
- package/out/SafeCalldataBatch.sol/SafeCalldataBatch.json +1 -0
- package/out/SafeCast.sol/SafeCast.json +1 -0
- package/out/Script.sol/Script.json +1 -0
- package/out/ShortStrings.sol/ShortStrings.json +1 -0
- package/out/SignatureChecker.sol/SignatureChecker.json +1 -0
- package/out/SignedMath.sol/SignedMath.json +1 -0
- package/out/SlotDerivation.sol/SlotDerivation.json +1 -0
- package/out/SmartAccount.sol/SmartAccount.json +1 -0
- package/out/SmartAccount.t.sol/AlwaysApprovePolicy.json +1 -0
- package/out/SmartAccount.t.sol/Counter.json +1 -0
- package/out/SmartAccount.t.sol/IAddKeyWithData.json +1 -0
- package/out/SmartAccount.t.sol/ReentrantUninstaller.json +1 -0
- package/out/SmartAccount.t.sol/SmartAccountTest.json +1 -0
- package/out/SmartAccount.t.sol/TestExecutor.json +1 -0
- package/out/StdAssertions.sol/StdAssertions.json +1 -0
- package/out/StdChains.sol/StdChains.json +1 -0
- package/out/StdCheats.sol/StdCheats.json +1 -0
- package/out/StdCheats.sol/StdCheatsSafe.json +1 -0
- package/out/StdConstants.sol/StdConstants.json +1 -0
- package/out/StdError.sol/stdError.json +1 -0
- package/out/StdInvariant.sol/StdInvariant.json +1 -0
- package/out/StdJson.sol/stdJson.json +1 -0
- package/out/StdMath.sol/stdMath.json +1 -0
- package/out/StdStorage.sol/stdStorage.json +1 -0
- package/out/StdStorage.sol/stdStorageSafe.json +1 -0
- package/out/StdStyle.sol/StdStyle.json +1 -0
- package/out/StdToml.sol/stdToml.json +1 -0
- package/out/StdUtils.sol/StdUtils.json +1 -0
- package/out/StorageSlot.sol/StorageSlot.json +1 -0
- package/out/Strings.sol/Strings.json +1 -0
- package/out/Structs.sol/Structs.json +1 -0
- package/out/Test.sol/Test.json +1 -0
- package/out/TestIdentityUtilities.sol/TestIdentityUtilities.json +1 -0
- package/out/Time.sol/Time.json +1 -0
- package/out/TokenOid.t.sol/TokenOidTest.json +1 -0
- package/out/UUPSUpgradeable.sol/UUPSUpgradeable.json +1 -0
- package/out/UnlockedIdentity.sol/UnlockedIdentity.json +1 -0
- package/out/UpgradeableBeacon.sol/UpgradeableBeacon.json +1 -0
- package/out/VersionUpgrade.t.sol/VersionUpgradeTest.json +1 -0
- package/out/Vm.sol/Vm.json +1 -0
- package/out/Vm.sol/VmSafe.json +1 -0
- package/out/WebAuthn.sol/WebAuthn.json +1 -0
- package/out/WebAuthn.t.sol/WebAuthnTest.json +1 -0
- package/out/build-info/1056f64abc9637ee.json +1 -0
- package/out/console.sol/console.json +1 -0
- package/out/draft-AccountERC7579Upgradeable.sol/AccountERC7579Upgradeable.json +1 -0
- package/out/draft-ERC7579Utils.sol/ERC7579Utils.json +1 -0
- package/out/draft-IERC1822.sol/IERC1822Proxiable.json +1 -0
- package/out/draft-IERC7579.sol/IERC7579AccountConfig.json +1 -0
- package/out/draft-IERC7579.sol/IERC7579Execution.json +1 -0
- package/out/draft-IERC7579.sol/IERC7579Hook.json +1 -0
- package/out/draft-IERC7579.sol/IERC7579Module.json +1 -0
- package/out/draft-IERC7579.sol/IERC7579ModuleConfig.json +1 -0
- package/out/draft-IERC7579.sol/IERC7579Validator.json +1 -0
- package/out/draft-IERC7786.sol/IERC7786GatewaySource.json +1 -0
- package/out/draft-IERC7786.sol/IERC7786Recipient.json +1 -0
- package/out/draft-InteroperableAddress.sol/InteroperableAddress.json +1 -0
- package/out/safeconsole.sol/safeconsole.json +1 -0
- package/out/src/Test.sol/Test.json +1 -0
- package/out/utils/Errors.sol/Errors.json +1 -0
- package/package.json +75 -4
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
2
|
+
//
|
|
3
|
+
// ONCHAINID Smart Contracts
|
|
4
|
+
// Digital identities for the T-REX ecosystem.
|
|
5
|
+
//
|
|
6
|
+
// Copyright (C) 2026 Digital Asset Operational Services ISAC Ltd. ("T-REX Network")
|
|
7
|
+
//
|
|
8
|
+
// This file is part of the ONCHAINID smart contract suite.
|
|
9
|
+
//
|
|
10
|
+
// This program is free software: you can redistribute it and/or modify
|
|
11
|
+
// it under the terms of the GNU General Public License as published by
|
|
12
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
13
|
+
// (at your option) any later version.
|
|
14
|
+
//
|
|
15
|
+
// This program is distributed in the hope that it will be useful,
|
|
16
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
+
// GNU General Public License for more details.
|
|
19
|
+
//
|
|
20
|
+
// You should have received a copy of the GNU General Public License
|
|
21
|
+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
22
|
+
|
|
23
|
+
pragma solidity ^0.8.27;
|
|
24
|
+
|
|
25
|
+
import { AccessManaged } from "@openzeppelin/contracts/access/manager/AccessManaged.sol";
|
|
26
|
+
import { InteroperableAddress } from "@openzeppelin/contracts/utils/draft-InteroperableAddress.sol";
|
|
27
|
+
|
|
28
|
+
import { IIdentityFactory } from "../../factory/IIdentityFactory.sol";
|
|
29
|
+
import { IClaimIssuer } from "../../interface/IClaimIssuer.sol";
|
|
30
|
+
import { IIdentity } from "../../interface/IIdentity.sol";
|
|
31
|
+
import { Errors } from "../../libraries/Errors.sol";
|
|
32
|
+
import { Structs } from "../../storage/Structs.sol";
|
|
33
|
+
import { Attestation, IEAS } from "../../vendor/eas/IEAS.sol";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @title EASClaimIssuer
|
|
37
|
+
* @notice A `ClaimIssuer` that reads EAS attestations live. It stores no claim state.
|
|
38
|
+
* Revocation, expiry, and wallet unlinking all take effect on the next call.
|
|
39
|
+
*
|
|
40
|
+
* @dev ERC-3643 asks a `ClaimIssuer` if a claim is valid. EAS is a general
|
|
41
|
+
* attestation layer that speaks a different vocabulary (schema UIDs). This
|
|
42
|
+
* adapter translates: a KYC provider already attesting on EAS does not have
|
|
43
|
+
* to re-issue the same fact as an OnchainID claim.
|
|
44
|
+
*
|
|
45
|
+
* Trust: EAS for everything `getAttestation` returns; the factory for the
|
|
46
|
+
* identity/wallet lookups; the AM admin for the topic-to-schema map and the
|
|
47
|
+
* per-topic attester allowlist. Both EAS and factory addresses are immutable so
|
|
48
|
+
* the admin cannot silently repoint them.
|
|
49
|
+
*
|
|
50
|
+
* An attestation may name the identity itself (identities are ERC-7579 smart
|
|
51
|
+
* accounts) or a wallet linked to the identity in `IdentityFactory`. The
|
|
52
|
+
* wallet's factory status is intentionally ignored: the attestation belongs
|
|
53
|
+
* to the identity, and requiring `Active` would deadlock recovery on a
|
|
54
|
+
* compromised wallet. Kills happen elsewhere: attester revokes on EAS, holder
|
|
55
|
+
* removes the local record via `removeClaim`. This adapter has no EIP-712 domain,
|
|
56
|
+
* so the registry has no digest to revoke on removal and skips that step. Re-adding
|
|
57
|
+
* is still blocked by EAS, which is re-read on every call.
|
|
58
|
+
*
|
|
59
|
+
* The `IClaimIssuer` `signature` field carries the EAS attestation UID as a
|
|
60
|
+
* bare 32-byte word (`abi.encodePacked(uid)`). Length-32 check rejects any
|
|
61
|
+
* other shape.
|
|
62
|
+
*
|
|
63
|
+
* The `ClaimData` envelope must mirror the attestation: `issuedAt` is the
|
|
64
|
+
* attestation `time`, `validUntil` its `expirationTime`, `payload` its `data`.
|
|
65
|
+
* The ERC-735 registry stores that envelope verbatim, so binding it here is what
|
|
66
|
+
* keeps the stored record equal to what the attester actually signed rather than
|
|
67
|
+
* a fabrication sitting next to a genuine UID. Callers build the envelope from
|
|
68
|
+
* `getAttestationData` plus the attestation's own timestamps.
|
|
69
|
+
*
|
|
70
|
+
* Not supported: off-chain EAS attestations, non-EVM wallets, cross-chain
|
|
71
|
+
* reads. Any `IIdentity` / ERC-734 / ERC-735 method that has no meaning on a
|
|
72
|
+
* stateless reader reverts with `Errors.EASNotSupported`.
|
|
73
|
+
*/
|
|
74
|
+
contract EASClaimIssuer is IClaimIssuer, AccessManaged {
|
|
75
|
+
|
|
76
|
+
/// @dev EAS deployment on this chain. Immutable so the admin cannot silently repoint
|
|
77
|
+
/// at a fake EAS and bypass revocation. Redeploy the adapter to change.
|
|
78
|
+
/// Read via {getEAS}.
|
|
79
|
+
IEAS private immutable _EAS;
|
|
80
|
+
|
|
81
|
+
/// @dev `IdentityFactory` used to resolve wallets to identities and to gate the
|
|
82
|
+
/// self-recipient branch. Immutable for the same reason as `_EAS`.
|
|
83
|
+
/// Read via {getFactory}.
|
|
84
|
+
IIdentityFactory private immutable _FACTORY;
|
|
85
|
+
|
|
86
|
+
/// @dev Topic to EAS schema UID map. The token side asks about a `uint256` topic,
|
|
87
|
+
/// EAS speaks in `bytes32` schema UIDs, this is the dictionary between them.
|
|
88
|
+
/// Unset (`bytes32(0)`) means the topic is not configured; `_resolve` returns
|
|
89
|
+
/// `NotIssued` for it. Setting a topic to zero is the intended kill switch.
|
|
90
|
+
/// Used twice in `_resolve`: first to reject unmapped topics, then to require
|
|
91
|
+
/// the attestation's own `schema` field to equal the mapped value, so an
|
|
92
|
+
/// attestation made under one topic's schema cannot be replayed against
|
|
93
|
+
/// another. The attester allowlist closes the other half of that gap by being
|
|
94
|
+
/// keyed per topic. Read via {getSchemaForTopic}.
|
|
95
|
+
mapping(uint256 topic => bytes32 schema) private _schemaOf;
|
|
96
|
+
|
|
97
|
+
/// @dev Attesters this adapter accepts, per topic. Any `address` can write an
|
|
98
|
+
/// attestation on EAS; only those listed for the queried topic are treated as
|
|
99
|
+
/// trusted issuers here. Scoped per topic like `trustedIssuersRegistry` on the
|
|
100
|
+
/// OnchainID side, so trusting an attester for one topic does not authorize it
|
|
101
|
+
/// for the rest. Read via {getIsAttesterAllowed}.
|
|
102
|
+
mapping(uint256 topic => mapping(address attester => bool allowed)) private _isAttesterAllowed;
|
|
103
|
+
|
|
104
|
+
/// @dev Adapter initialized. Emits the immutable EAS and factory addresses so
|
|
105
|
+
/// indexers can catalog every deployed adapter with a single topic scan.
|
|
106
|
+
event AdapterInitialized(address indexed eas, address indexed factory);
|
|
107
|
+
|
|
108
|
+
/// @dev Schema binding changed. `schema == 0` means the topic was unbound.
|
|
109
|
+
event SchemaForTopicSet(uint256 indexed topic, bytes32 indexed schema);
|
|
110
|
+
|
|
111
|
+
/// @dev Attester allowlist changed for one topic. Monitor `allowed == true` events:
|
|
112
|
+
/// they widen the trust surface.
|
|
113
|
+
event AttesterSet(uint256 indexed topic, address indexed attester, bool allowed);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @param authority_ AccessManager instance backing `restricted` setters.
|
|
117
|
+
* @param eas_ The EAS core contract on this chain.
|
|
118
|
+
* @param factory_ The IdentityFactory (global registry).
|
|
119
|
+
*/
|
|
120
|
+
constructor(address authority_, IEAS eas_, IIdentityFactory factory_) AccessManaged(authority_) {
|
|
121
|
+
require(address(eas_) != address(0), Errors.ZeroAddress());
|
|
122
|
+
require(address(factory_) != address(0), Errors.ZeroAddress());
|
|
123
|
+
_EAS = eas_;
|
|
124
|
+
_FACTORY = factory_;
|
|
125
|
+
emit AdapterInitialized(address(eas_), address(factory_));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/// @notice Bind an ERC-3643 topic to an EAS schema UID. Pass `schema = 0` to unbind
|
|
129
|
+
/// (kill switch for a compromised schema, no redeploy needed).
|
|
130
|
+
function setSchemaForTopic(uint256 topic, bytes32 schema) external restricted {
|
|
131
|
+
_schemaOf[topic] = schema;
|
|
132
|
+
emit SchemaForTopicSet(topic, schema);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/// @notice Add or remove an attester from the accepted set for one topic. Adding
|
|
136
|
+
/// widens the trust surface: attestations from `attester` under the schema
|
|
137
|
+
/// bound to `topic` will pass. Other topics are unaffected.
|
|
138
|
+
/// @dev Rejects `address(0)`: a deployment-script bug passing an unset address
|
|
139
|
+
/// would otherwise succeed silently, leaving the real attester unlisted.
|
|
140
|
+
function setAttester(uint256 topic, address attester, bool allowed) external restricted {
|
|
141
|
+
require(attester != address(0), Errors.ZeroAddress());
|
|
142
|
+
_isAttesterAllowed[topic][attester] = allowed;
|
|
143
|
+
emit AttesterSet(topic, attester, allowed);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/// @notice EAS core contract this adapter reads from.
|
|
147
|
+
function getEAS() public view returns (IEAS) {
|
|
148
|
+
return _EAS;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/// @notice `IdentityFactory` this adapter delegates identity and wallet lookups to.
|
|
152
|
+
function getFactory() public view returns (IIdentityFactory) {
|
|
153
|
+
return _FACTORY;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/// @notice EAS schema UID bound to `topic`, or `bytes32(0)` if unbound.
|
|
157
|
+
function getSchemaForTopic(uint256 topic) public view returns (bytes32) {
|
|
158
|
+
return _schemaOf[topic];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/// @notice Whether `attester` is in the accepted set for `topic`.
|
|
162
|
+
function getIsAttesterAllowed(uint256 topic, address attester) public view returns (bool) {
|
|
163
|
+
return _isAttesterAllowed[topic][attester];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/// @notice Raw read only — returns the payload even for revoked, expired, or
|
|
167
|
+
/// untrusted attestations. Always pair with `isClaimValid` (or
|
|
168
|
+
/// `getClaimStatus`) before making eligibility or display decisions.
|
|
169
|
+
/// @dev Returns empty bytes if `sig` is not a 32-byte UID or the attestation does
|
|
170
|
+
/// not exist. Does not check schema, attester, revocation, or expiry. A
|
|
171
|
+
/// front-end that renders this payload without calling `isClaimValid` will
|
|
172
|
+
/// show stale data for attestations revoked on EAS.
|
|
173
|
+
function getAttestationData(bytes calldata sig) external view returns (bytes memory) {
|
|
174
|
+
if (sig.length != 32) return "";
|
|
175
|
+
bytes32 uid = bytes32(sig);
|
|
176
|
+
return getEAS().getAttestation(uid).data;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/// @inheritdoc IClaimIssuer
|
|
180
|
+
/// @dev `sig` must be a 32-byte EAS attestation UID (`abi.encodePacked(uid)`).
|
|
181
|
+
/// `data` must mirror the attestation field for field; see `_resolve`.
|
|
182
|
+
function isClaimValid(IIdentity _identity, uint256 claimTopic, bytes calldata sig, Structs.ClaimData calldata data)
|
|
183
|
+
external
|
|
184
|
+
view
|
|
185
|
+
returns (bool)
|
|
186
|
+
{
|
|
187
|
+
return _resolve(_identity, claimTopic, sig, data) == ClaimStatus.Valid;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/// @inheritdoc IClaimIssuer
|
|
191
|
+
function getClaimStatus(
|
|
192
|
+
IIdentity _identity,
|
|
193
|
+
uint256 claimTopic,
|
|
194
|
+
bytes calldata sig,
|
|
195
|
+
Structs.ClaimData calldata data
|
|
196
|
+
) external view returns (ClaimStatus status) {
|
|
197
|
+
return _resolve(_identity, claimTopic, sig, data);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/// @inheritdoc IClaimIssuer
|
|
201
|
+
/// @dev Always `false`: this issuer keeps no digest registry, so it has never
|
|
202
|
+
/// revoked a digest. Reverting here would abort compliance call chains
|
|
203
|
+
/// (`isVerified` -> `isDigestRevoked` -> `isClaimValid`) on perfectly valid
|
|
204
|
+
/// claims. Revocation lives on EAS and surfaces as `Revoked` through
|
|
205
|
+
/// `isClaimValid` / `getClaimStatus` — those are the source of truth.
|
|
206
|
+
function isDigestRevoked(bytes32) external pure returns (bool) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/// @dev Live status resolution. Zero identity, missing config, missing attestation,
|
|
211
|
+
/// wrong schema, unaccepted attester, or `data` that does not mirror the attestation
|
|
212
|
+
/// map to `NotIssued`. Bad UID payload maps to `BadSignature`. EAS revocation and
|
|
213
|
+
/// expiry map to `Revoked` and `Expired`. Recipient binding to `_identity`
|
|
214
|
+
/// (self or any linked wallet, regardless of factory status) maps to `Valid`.
|
|
215
|
+
/// Wallet status is ignored on purpose; see the contract header.
|
|
216
|
+
function _resolve(IIdentity _identity, uint256 topic, bytes calldata sig, Structs.ClaimData calldata data)
|
|
217
|
+
internal
|
|
218
|
+
view
|
|
219
|
+
returns (ClaimStatus)
|
|
220
|
+
{
|
|
221
|
+
// The zero identity holds no claims. Without this, an unlinked recipient resolves to
|
|
222
|
+
// zero on the wallet branch below and matches it.
|
|
223
|
+
if (address(_identity) == address(0)) return ClaimStatus.NotIssued;
|
|
224
|
+
|
|
225
|
+
bytes32 schema = getSchemaForTopic(topic);
|
|
226
|
+
if (schema == bytes32(0)) return ClaimStatus.NotIssued;
|
|
227
|
+
|
|
228
|
+
if (sig.length != 32) return ClaimStatus.BadSignature;
|
|
229
|
+
bytes32 uid = bytes32(sig);
|
|
230
|
+
if (uid == bytes32(0)) return ClaimStatus.BadSignature;
|
|
231
|
+
|
|
232
|
+
Attestation memory attestation = getEAS().getAttestation(uid);
|
|
233
|
+
if (
|
|
234
|
+
attestation.uid == bytes32(0) || attestation.schema != schema
|
|
235
|
+
|| !getIsAttesterAllowed(topic, attestation.attester)
|
|
236
|
+
) {
|
|
237
|
+
return ClaimStatus.NotIssued;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// The caller hands us a ClaimData that ERC-735 mirrors into storage verbatim. Nothing
|
|
241
|
+
// upstream binds it to the attestation, so without this check a party allowed to add a
|
|
242
|
+
// claim could pair a genuine UID with a fabricated payload and validity window and this
|
|
243
|
+
// adapter would still call it Valid. Bind all three fields to what the attester signed.
|
|
244
|
+
if (
|
|
245
|
+
data.issuedAt != attestation.time || data.validUntil != attestation.expirationTime
|
|
246
|
+
|| keccak256(data.payload) != keccak256(attestation.data)
|
|
247
|
+
) {
|
|
248
|
+
return ClaimStatus.NotIssued;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (attestation.revocationTime != 0) return ClaimStatus.Revoked;
|
|
252
|
+
if (attestation.expirationTime != 0 && block.timestamp >= attestation.expirationTime) {
|
|
253
|
+
return ClaimStatus.Expired;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Recipient is the identity itself. `isFactoryIdentity` blocks arbitrary contracts
|
|
257
|
+
// from posing as `_identity`.
|
|
258
|
+
if (attestation.recipient == address(_identity)) {
|
|
259
|
+
return getFactory().isFactoryIdentity(address(_identity)) ? ClaimStatus.Valid : ClaimStatus.NotIssued;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Recipient is a wallet linked to `_identity`. `getIdentityIncludingRevoked`
|
|
263
|
+
// returns the identity for both Active and Revoked links; only `None` returns
|
|
264
|
+
// zero. Status is ignored on purpose (see header, recovery deadlock argument).
|
|
265
|
+
bytes memory envelope = InteroperableAddress.formatEvmV1(block.chainid, attestation.recipient);
|
|
266
|
+
(address linked,) = getFactory().getIdentityIncludingRevoked(envelope);
|
|
267
|
+
if (linked == address(_identity)) return ClaimStatus.Valid;
|
|
268
|
+
return ClaimStatus.NotIssued;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Unsupported surface. Revocation lives on EAS, not on this contract.
|
|
272
|
+
|
|
273
|
+
/// @inheritdoc IClaimIssuer
|
|
274
|
+
function revokeClaimByDigest(bytes32) external pure {
|
|
275
|
+
revert Errors.EASNotSupported();
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/// @inheritdoc IClaimIssuer
|
|
279
|
+
function addClaimTo(uint256, uint256, bytes calldata, Structs.ClaimData calldata, string calldata, IIdentity)
|
|
280
|
+
external
|
|
281
|
+
pure
|
|
282
|
+
{
|
|
283
|
+
revert Errors.EASNotSupported();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/// @inheritdoc IIdentity
|
|
287
|
+
function getClaimHash(address, uint256, Structs.ClaimData memory) external pure returns (bytes32) {
|
|
288
|
+
revert Errors.EASNotSupported();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/// @inheritdoc IIdentity
|
|
292
|
+
function getIdentityType() external pure returns (uint256) {
|
|
293
|
+
revert Errors.EASNotSupported();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// ERC-734 (key registry). The adapter is not an Identity so every method reverts.
|
|
297
|
+
|
|
298
|
+
function addKey(bytes32, uint256, uint256) external pure returns (bool) {
|
|
299
|
+
revert Errors.EASNotSupported();
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function removeKey(bytes32, uint256) external pure returns (bool) {
|
|
303
|
+
revert Errors.EASNotSupported();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function getKey(bytes32) external pure returns (uint256[] memory, uint256, bytes32) {
|
|
307
|
+
revert Errors.EASNotSupported();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function getKeyPurposes(bytes32) external pure returns (uint256[] memory) {
|
|
311
|
+
revert Errors.EASNotSupported();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function getKeysByPurpose(uint256) external pure returns (bytes32[] memory) {
|
|
315
|
+
revert Errors.EASNotSupported();
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function keyHasPurpose(bytes32, uint256) external pure returns (bool) {
|
|
319
|
+
revert Errors.EASNotSupported();
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ERC-735 (claim registry). The adapter holds no claims so every method reverts.
|
|
323
|
+
|
|
324
|
+
function addClaim(uint256, uint256, address, bytes calldata, Structs.ClaimData calldata, string calldata)
|
|
325
|
+
external
|
|
326
|
+
pure
|
|
327
|
+
returns (bytes32)
|
|
328
|
+
{
|
|
329
|
+
revert Errors.EASNotSupported();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function removeClaim(bytes32) external pure returns (bool) {
|
|
333
|
+
revert Errors.EASNotSupported();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function getClaim(bytes32)
|
|
337
|
+
external
|
|
338
|
+
pure
|
|
339
|
+
returns (uint256, uint256, address, bytes memory, Structs.ClaimData memory, string memory)
|
|
340
|
+
{
|
|
341
|
+
revert Errors.EASNotSupported();
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function getClaimIdsByTopic(uint256) external pure returns (bytes32[] memory) {
|
|
345
|
+
revert Errors.EASNotSupported();
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
2
|
+
//
|
|
3
|
+
// ONCHAINID Smart Contracts
|
|
4
|
+
// Digital identities for the T-REX ecosystem.
|
|
5
|
+
//
|
|
6
|
+
// Copyright (C) 2026 Digital Asset Operational Services ISAC Ltd. ("T-REX Network")
|
|
7
|
+
//
|
|
8
|
+
// This file is part of the ONCHAINID smart contract suite.
|
|
9
|
+
//
|
|
10
|
+
// This program is free software: you can redistribute it and/or modify
|
|
11
|
+
// it under the terms of the GNU General Public License as published by
|
|
12
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
13
|
+
// (at your option) any later version.
|
|
14
|
+
//
|
|
15
|
+
// This program is distributed in the hope that it will be useful,
|
|
16
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
+
// GNU General Public License for more details.
|
|
19
|
+
//
|
|
20
|
+
// You should have received a copy of the GNU General Public License
|
|
21
|
+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
22
|
+
|
|
23
|
+
pragma solidity ^0.8.28;
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
IERC7579Execution,
|
|
27
|
+
IERC7579Module,
|
|
28
|
+
MODULE_TYPE_EXECUTOR,
|
|
29
|
+
MODULE_TYPE_FALLBACK
|
|
30
|
+
} from "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
|
|
31
|
+
|
|
32
|
+
import { IERC734 } from "../../interface/IERC734.sol";
|
|
33
|
+
import { IKeyExecutor } from "../../interface/IKeyExecutor.sol";
|
|
34
|
+
import { Errors } from "../../libraries/Errors.sol";
|
|
35
|
+
import { hashAddress } from "../../libraries/Hashing.sol";
|
|
36
|
+
import { KeyPurposes } from "../../libraries/KeyPurposes.sol";
|
|
37
|
+
|
|
38
|
+
/// @dev Minimal view of the account: does a target need MANAGEMENT (self or factory)?
|
|
39
|
+
/// See {SmartAccount.isManagementTarget}.
|
|
40
|
+
interface IIdentityAccount {
|
|
41
|
+
|
|
42
|
+
function isManagementTarget(address target) external view returns (bool);
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @title KeyApprovalModule
|
|
48
|
+
* @notice Externalized ERC-734 `execute` / `approve` queue, served to identities via the
|
|
49
|
+
* ERC-7579 fallback handler + executor module pattern.
|
|
50
|
+
*
|
|
51
|
+
* The account owns the key registry (`keyHasPurpose`); this module owns the execution
|
|
52
|
+
* queue and the auto-approval rules. Per-identity state is keyed by `account` because
|
|
53
|
+
* a single module deployment is shared across every identity that installs it.
|
|
54
|
+
*
|
|
55
|
+
* Proposing vs auto-executing are separate gates. To queue a request via {execute}
|
|
56
|
+
* the caller must hold at least one of PROPOSER / ACTION / CLAIM_SIGNER /
|
|
57
|
+
* CLAIM_ADDER / MANAGEMENT on the identity. Random addresses cannot pollute the
|
|
58
|
+
* queue or the event log. PROPOSER is a queue-only purpose: it lets a key queue
|
|
59
|
+
* a request that then waits for an approver and never auto-runs by itself.
|
|
60
|
+
*
|
|
61
|
+
* A queued request records the key that proposed it. Approving re-checks that key, so a
|
|
62
|
+
* request whose proposer was revoked can no longer be dispatched. Rejecting does not:
|
|
63
|
+
* any authorized approver can still close a stale entry.
|
|
64
|
+
*
|
|
65
|
+
* Uninstalling the module (the executor or any of its fallback selectors) voids every
|
|
66
|
+
* request queued so far, so a pending queue cannot be resurrected across a reinstall.
|
|
67
|
+
*
|
|
68
|
+
* Auto-approval rules (unchanged by the propose gate):
|
|
69
|
+
* - MANAGEMENT: anything.
|
|
70
|
+
* - ACTION: external targets only.
|
|
71
|
+
* - Anything else on self: never.
|
|
72
|
+
*
|
|
73
|
+
* {execute} and {approve} only work when called through the account's ERC-7579 fallback,
|
|
74
|
+
* because that is what appends the caller for {_msgSender} to read. If the call arrives
|
|
75
|
+
* any other way, for example relayed by the EntryPoint or dispatched by the account
|
|
76
|
+
* itself, nothing is appended, so the recovered caller holds no key and the call is
|
|
77
|
+
* refused. To add or remove a claim on the identity itself, call that selector on the
|
|
78
|
+
* account directly instead of queueing it here.
|
|
79
|
+
*/
|
|
80
|
+
contract KeyApprovalModule is IERC7579Module, IKeyExecutor {
|
|
81
|
+
|
|
82
|
+
/// @dev Per-identity queue state. One slot per installing account. Requests with an id
|
|
83
|
+
/// below `firstValidId` are void; {onUninstall} bumps the floor to the current nonce.
|
|
84
|
+
struct AccountState {
|
|
85
|
+
uint256 executionNonce;
|
|
86
|
+
uint256 firstValidId;
|
|
87
|
+
mapping(uint256 => Execution) executions;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// @dev A queued (and possibly already-run) execution request.
|
|
91
|
+
struct Execution {
|
|
92
|
+
address to;
|
|
93
|
+
uint256 value;
|
|
94
|
+
bytes data;
|
|
95
|
+
address proposer;
|
|
96
|
+
bool approved;
|
|
97
|
+
bool executed;
|
|
98
|
+
// `executed` only says the request was attempted and is closed; it is set on a failed
|
|
99
|
+
// dispatch and on a rejection too. This is the one that says the call actually landed.
|
|
100
|
+
bool succeeded;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// @dev Storage shared across all identities that install this module singleton.
|
|
104
|
+
mapping(address => AccountState) private _state;
|
|
105
|
+
|
|
106
|
+
/// @inheritdoc IERC7579Module
|
|
107
|
+
function isModuleType(uint256 moduleTypeId) public pure returns (bool) {
|
|
108
|
+
return moduleTypeId == MODULE_TYPE_EXECUTOR || moduleTypeId == MODULE_TYPE_FALLBACK;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// @inheritdoc IERC7579Module
|
|
112
|
+
function onInstall(bytes calldata) external pure { }
|
|
113
|
+
|
|
114
|
+
/// @inheritdoc IERC7579Module
|
|
115
|
+
/// @dev Voids every request queued so far by the uninstalling account. Runs on each
|
|
116
|
+
/// uninstall of this module (the executor or any fallback selector), so even a
|
|
117
|
+
/// partial teardown kills the queue. Fails closed: nothing here can revert.
|
|
118
|
+
function onUninstall(bytes calldata) external {
|
|
119
|
+
AccountState storage state = _state[msg.sender];
|
|
120
|
+
uint256 nonce = state.executionNonce;
|
|
121
|
+
if (state.firstValidId < nonce) {
|
|
122
|
+
state.firstValidId = nonce;
|
|
123
|
+
emit QueueInvalidated(msg.sender, nonce);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/// @notice Queue an execution for the calling identity. Auto-runs if the caller's key
|
|
128
|
+
/// purpose authorizes it; otherwise waits for {approve}.
|
|
129
|
+
/// @dev Treasury model: any `msg.value` is pushed back to the identity; `_value` is
|
|
130
|
+
/// dispatched from the identity's balance when the request runs.
|
|
131
|
+
/// Gated: caller must hold a key on the identity that authorizes proposing.
|
|
132
|
+
function execute(address _to, uint256 _value, bytes calldata _data) external payable returns (uint256 executionId) {
|
|
133
|
+
address account = msg.sender;
|
|
134
|
+
address proposer = _msgSender();
|
|
135
|
+
bytes32 callerKeyHash = hashAddress(proposer);
|
|
136
|
+
|
|
137
|
+
// Reject random callers. Any key with a real purpose on the identity can propose;
|
|
138
|
+
// PROPOSER is the queue-only purpose for callers who should be able to push
|
|
139
|
+
// requests but cannot auto-run or approve them.
|
|
140
|
+
require(_canPropose(account, callerKeyHash), Errors.SenderCannotPropose(proposer));
|
|
141
|
+
|
|
142
|
+
// 1. Push any msg.value back to the identity so the module never holds ETH.
|
|
143
|
+
if (msg.value > 0) {
|
|
144
|
+
(bool returned,) = account.call{ value: msg.value }("");
|
|
145
|
+
require(returned, Errors.ReturnToAccountFailed());
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// 2. Allocate the next execution id and persist the request.
|
|
149
|
+
AccountState storage state = _state[account];
|
|
150
|
+
executionId = state.executionNonce++;
|
|
151
|
+
state.executions[executionId] = Execution({
|
|
152
|
+
to: _to, value: _value, data: _data, proposer: proposer, approved: false, executed: false, succeeded: false
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
emit ExecutionRequested(account, executionId, _to, _value, _data, proposer);
|
|
156
|
+
|
|
157
|
+
// 3. Auto-approve dispatches now; otherwise the request stays pending for {approve}.
|
|
158
|
+
if (_canAutoApprove(account, callerKeyHash, _to)) {
|
|
159
|
+
_runApproved(account, executionId);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/// @notice Approve (or reject) a queued execution. Management-grade targets (the account, its
|
|
164
|
+
/// factory, or the key registry) require MANAGEMENT; other external targets require ACTION.
|
|
165
|
+
/// @dev This gate is target-level (MANAGEMENT vs ACTION). Per-selector claim granularity (e.g.
|
|
166
|
+
/// addClaim needing only CLAIM_SIGNER) is handled by the claim branch in `_canAutoApprove`
|
|
167
|
+
/// and the account's fallback dispatch, not here.
|
|
168
|
+
function approve(uint256 _id, bool _shouldApprove) external returns (bool success) {
|
|
169
|
+
// 1. Resolve account + ERC-2771 caller, fetch the queued request.
|
|
170
|
+
address account = msg.sender;
|
|
171
|
+
bytes32 callerKeyHash = hashAddress(_msgSender());
|
|
172
|
+
AccountState storage state = _state[account];
|
|
173
|
+
Execution storage execution = state.executions[_id];
|
|
174
|
+
|
|
175
|
+
// 2. Sanity-check the request id, that it wasn't voided by an uninstall, and that
|
|
176
|
+
// it isn't already executed.
|
|
177
|
+
require(_id < state.executionNonce, Errors.InvalidRequestId());
|
|
178
|
+
require(_id >= state.firstValidId, Errors.RequestInvalidated());
|
|
179
|
+
require(!execution.executed, Errors.RequestAlreadyExecuted());
|
|
180
|
+
|
|
181
|
+
// 3. Authorize the approver. A management-grade target (the account, its factory, or the
|
|
182
|
+
// key registry) needs MANAGEMENT; other external targets need ACTION. Without this, an ACTION
|
|
183
|
+
// key could approve a queued factory call (e.g. terminally revoke a wallet) or a registry
|
|
184
|
+
// call (e.g. grant itself a MANAGEMENT key), dispatched under the module's MANAGEMENT key.
|
|
185
|
+
if (IIdentityAccount(account).isManagementTarget(execution.to)) {
|
|
186
|
+
require(
|
|
187
|
+
IERC734(account).keyHasPurpose(callerKeyHash, KeyPurposes.MANAGEMENT),
|
|
188
|
+
Errors.SenderDoesNotHaveManagementKey()
|
|
189
|
+
);
|
|
190
|
+
} else {
|
|
191
|
+
require(
|
|
192
|
+
IERC734(account).keyHasPurpose(callerKeyHash, KeyPurposes.ACTION), Errors.SenderDoesNotHaveActionKey()
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
emit Approved(account, _id, _shouldApprove);
|
|
197
|
+
|
|
198
|
+
// 4. Approval ⇒ the key that queued the request must still be able to propose, then
|
|
199
|
+
// dispatch now. A request whose proposer was revoked cannot run, but any authorized
|
|
200
|
+
// approver can still reject it and close the stale entry.
|
|
201
|
+
if (_shouldApprove) {
|
|
202
|
+
require(
|
|
203
|
+
_canPropose(account, hashAddress(execution.proposer)),
|
|
204
|
+
Errors.ProposerNoLongerAuthorized(execution.proposer)
|
|
205
|
+
);
|
|
206
|
+
return _runApproved(account, _id);
|
|
207
|
+
}
|
|
208
|
+
execution.executed = true;
|
|
209
|
+
execution.approved = false;
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/// @notice Current execution nonce for the calling identity.
|
|
214
|
+
function getCurrentNonce() external view returns (uint256) {
|
|
215
|
+
return _state[msg.sender].executionNonce;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/// @notice Returns a queued execution by `account` and `executionId`.
|
|
219
|
+
function getExecutionData(address account, uint256 executionId) external view returns (Execution memory) {
|
|
220
|
+
return _state[account].executions[executionId];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/// @dev Auto-approval policy. See contract NatSpec for the rule table. Module targets are
|
|
224
|
+
/// not special-cased here: the account itself refuses to dispatch into its own modules
|
|
225
|
+
/// (see {SmartAccount}), so such a request just fails there and emits `ExecutionFailed`.
|
|
226
|
+
function _canAutoApprove(address account, bytes32 keyHash, address to) internal view returns (bool) {
|
|
227
|
+
// OZ rewrites to 0 to the account before dispatch, so treat it as a self-call.
|
|
228
|
+
if (to == address(0)) to = account;
|
|
229
|
+
|
|
230
|
+
// MANAGEMENT keys pass any check.
|
|
231
|
+
if (IERC734(account).keyHasPurpose(keyHash, KeyPurposes.MANAGEMENT)) {
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Self-targeted calls never auto-approve below MANAGEMENT. There used to be a rule here
|
|
236
|
+
// letting claim keys auto-approve addClaim/removeClaim on self, but it could never work.
|
|
237
|
+
// `_runApproved` dispatches through `executeFromExecutor`, so the account calls the claim
|
|
238
|
+
// selector on itself and the fallback appends the account as the ERC-2771 caller. The
|
|
239
|
+
// claim registry then looks for a claim key on the account, finds none, and reverts. The
|
|
240
|
+
// try/catch turned that into a silent `ExecutionFailed`. Claim keys should call addClaim
|
|
241
|
+
// or removeClaim on the account directly.
|
|
242
|
+
if (to == account) return false;
|
|
243
|
+
|
|
244
|
+
// A management-grade target (the factory or the key registry) never auto-approves for a
|
|
245
|
+
// non-MANAGEMENT key; MANAGEMENT already returned above.
|
|
246
|
+
if (IIdentityAccount(account).isManagementTarget(to)) return false;
|
|
247
|
+
|
|
248
|
+
// External target: ACTION keys can dispatch directly.
|
|
249
|
+
if (to != account && IERC734(account).keyHasPurpose(keyHash, KeyPurposes.ACTION)) return true;
|
|
250
|
+
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/// @dev Gate for {execute}. Any purpose that can already authorize an auto-run or an
|
|
255
|
+
/// approval also passes here, plus the queue-only PROPOSER purpose. MANAGEMENT is
|
|
256
|
+
/// implicit: `keyHasPurpose` returns true for a MANAGEMENT key on any queried purpose.
|
|
257
|
+
function _canPropose(address account, bytes32 keyHash) internal view returns (bool) {
|
|
258
|
+
IERC734 acct = IERC734(account);
|
|
259
|
+
return acct.keyHasPurpose(keyHash, KeyPurposes.PROPOSER) || acct.keyHasPurpose(keyHash, KeyPurposes.ACTION)
|
|
260
|
+
|| acct.keyHasPurpose(keyHash, KeyPurposes.CLAIM_SIGNER)
|
|
261
|
+
|| acct.keyHasPurpose(keyHash, KeyPurposes.CLAIM_ADDER);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/// @dev Dispatches via `executeFromExecutor`, which spends `execution.value` from the
|
|
265
|
+
/// identity's balance. try/catch so a failed dispatch emits `ExecutionFailed`
|
|
266
|
+
/// instead of reverting.
|
|
267
|
+
/// @dev `executed`/`approved` are written before the dispatch on purpose: they are what stops
|
|
268
|
+
/// the target re-entering {approve} on the same id. They therefore cannot double as a
|
|
269
|
+
/// success flag, so the outcome is recorded separately in `succeeded`.
|
|
270
|
+
function _runApproved(address account, uint256 executionId) internal returns (bool success) {
|
|
271
|
+
Execution storage execution = _state[account].executions[executionId];
|
|
272
|
+
|
|
273
|
+
execution.executed = true;
|
|
274
|
+
execution.approved = true;
|
|
275
|
+
|
|
276
|
+
address to = execution.to;
|
|
277
|
+
uint256 value = execution.value;
|
|
278
|
+
bytes memory data = execution.data;
|
|
279
|
+
|
|
280
|
+
// CALLTYPE_SINGLE + EXECTYPE_DEFAULT: all-zero mode word.
|
|
281
|
+
bytes32 mode = bytes32(0);
|
|
282
|
+
bytes memory executionCalldata = abi.encodePacked(to, value, data);
|
|
283
|
+
|
|
284
|
+
try IERC7579Execution(account).executeFromExecutor(mode, executionCalldata) returns (bytes[] memory) {
|
|
285
|
+
execution.succeeded = true;
|
|
286
|
+
emit Executed(account, executionId, to, value, data);
|
|
287
|
+
return true;
|
|
288
|
+
} catch {
|
|
289
|
+
emit ExecutionFailed(account, executionId, to, value, data);
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/// @dev Reached via the account's fallback, `msg.sender` is the account, so the real caller is
|
|
295
|
+
/// appended (ERC-2771 style) as the trailing 20 bytes; we read it from there.
|
|
296
|
+
/// @dev We can trust that tail because {SmartAccount} blocks the only path that could forge it
|
|
297
|
+
/// (a direct call to this module, which arrives with no appended tail).
|
|
298
|
+
/// @dev The length check only says a tail could fit, not that one was actually appended. On a
|
|
299
|
+
/// path that skips the fallback the last 20 bytes are just ABI arguments, so the caller
|
|
300
|
+
/// reads back as some address that holds no key and the call is refused. We ask for a
|
|
301
|
+
/// selector plus the tail, so a call too short to carry one uses `msg.sender` instead.
|
|
302
|
+
function _msgSender() internal view returns (address sender) {
|
|
303
|
+
if (msg.data.length >= 24) {
|
|
304
|
+
// solhint-disable-next-line no-inline-assembly
|
|
305
|
+
assembly ("memory-safe") {
|
|
306
|
+
sender := shr(96, calldataload(sub(calldatasize(), 20)))
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
sender = msg.sender;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
}
|