Skip to content
Verified contractExactMIT

StateKeyRegistry

Address0xbb65e14799cb6106d2196caeb74e7c28742a53fb
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.34

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.34+commit.80d5c536
Language
solidity
Optimization
Yes, 200 runs
EVM version
osaka
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,342,327
Creation transaction
0x34b61edb7b…a4471a63ff

src/StateKeyRegistry.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;

/// @title StateKeyRegistry
/// @notice Each wallet publishes one ML-KEM public key, so others can seal vault keys to it.
contract StateKeyRegistry {
    enum Algorithm {
        None,
        MLKEM768,
        MLKEM1024
    }

    struct Key {
        Algorithm algorithm;
        uint64 updatedAt;
        bytes publicKey;
    }

    uint256 public constant MLKEM768_PK_LENGTH = 1184;
    uint256 public constant MLKEM1024_PK_LENGTH = 1568;

    mapping(address => Key) private keys;

    event KeyPublished(address indexed owner, Algorithm algorithm, bytes32 keyHash);
    event KeyRemoved(address indexed owner);

    error BadKeyLength(Algorithm algorithm, uint256 length);
    error NoKey(address owner);

    function publish(Algorithm algorithm, bytes calldata publicKey) external {
        uint256 want = algorithm == Algorithm.MLKEM768
            ? MLKEM768_PK_LENGTH
            : algorithm == Algorithm.MLKEM1024 ? MLKEM1024_PK_LENGTH : 0;
        if (want == 0 || publicKey.length != want) revert BadKeyLength(algorithm, publicKey.length);
        keys[msg.sender] = Key(algorithm, uint64(block.timestamp), publicKey);
        emit KeyPublished(msg.sender, algorithm, keccak256(publicKey));
    }

    function remove() external {
        if (keys[msg.sender].algorithm == Algorithm.None) revert NoKey(msg.sender);
        delete keys[msg.sender];
        emit KeyRemoved(msg.sender);
    }

    function keyOf(address owner) external view returns (Key memory key) {
        key = keys[owner];
        if (key.algorithm == Algorithm.None) revert NoKey(owner);
    }

    function hasKey(address owner) external view returns (bool) {
        return keys[owner].algorithm != Algorithm.None;
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "osaka",
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.