# EIP712Domain.sol

> EIP712のドメインセパレータを取得するコントラクトです。メッセージの改ざん防止とスコープ明示のための固定値を提供します。

- URL: https://cardene.dev/books/usdc/d1ee2b
- 本: USDC (https://cardene.dev/books/usdc.md)
- 章: 6 / 13
- 前の章: https://cardene.dev/books/usdc/97f188.md
- 次の章: https://cardene.dev/books/usdc/59f0ab.md
- 公開日: 2025-07-08
- 更新日: 2025-07-08
- トピック: Blockchain
- タグ: ブロックチェーン, solidity, ethereum, smartcontract

## 概要

**EIP712**のドメインセパレータを取得するコントラクトです。
メッセージの改ざん防止とスコープ明示のための固定値を提供します。

:::message
**EIP712**については以下の記事を参考にしてください。
:::

https://qiita.com/cardene/items/f54bc85cb66de5a54257

## コード

https://github.com/circlefin/stablecoin-evm/blob/master/contracts/v2/EIP712Domain.sol

```sol
/**
 * Copyright 2023 Circle Internet Group, Inc. All rights reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

pragma solidity 0.6.12;

// solhint-disable func-name-mixedcase

/**
 * @title EIP712 Domain
 */
contract EIP712Domain {
    // was originally DOMAIN_SEPARATOR
    // but that has been moved to a method so we can override it in V2_2+
    bytes32 internal _DEPRECATED_CACHED_DOMAIN_SEPARATOR;

    /**
     * @notice Get the EIP712 Domain Separator.
     * @return The bytes32 EIP712 domain separator.
     */
    function DOMAIN_SEPARATOR() external view returns (bytes32) {
        return _domainSeparator();
    }

    /**
     * @dev Internal method to get the EIP712 Domain Separator.
     * @return The bytes32 EIP712 domain separator.
     */
    function _domainSeparator() internal virtual view returns (bytes32) {
        return _DEPRECATED_CACHED_DOMAIN_SEPARATOR;
    }
}
```

## 変数

```solidity
bytes32 internal _DEPRECATED_CACHED_DOMAIN_SEPARATOR
```

**EIP712**ドメインセパレータをキャッシュするためのバイト列。
デプロイ時に設定され、その後変更されません。

## 関数

### `DOMAIN_SEPARATOR`

```solidity
function DOMAIN_SEPARATOR() external view returns (bytes32) {
    return _domainSeparator();
}
```

ドメインセパレータを取得する関数。

**戻り値**

* `bytes32`
    * 現在の**EIP712**ドメインセパレータ。

### `_domainSeparator`

```solidity
function _domainSeparator() internal virtual view returns (bytes32) {
    return _DEPRECATED_CACHED_DOMAIN_SEPARATOR;
}
```

ドメインセパレータを取得する内部関数。
デフォルトではキャッシュ済みの `_DEPRECATED_CACHED_DOMAIN_SEPARATOR` を返します。
`virtual` 修飾子により、派生コントラクトで独自のドメインセパレータ生成ロジックを実装できます。

**戻り値**

* `bytes32`
    * キャッシュまたは派生ロジックで決定されたドメインセパレータ。
