{"eip":4361,"title":"Sign-In with Ethereum","description":"Off-chain authentication for Ethereum accounts to establish sessions.","authors":["Wayne Chang (@wyc)","Gregory Rocco (@obstropolos)","Brantly Millegan (@brantlymillegan)","Nick Johnson (@Arachnid)","Oliver Terbu (@awoie)"],"status":"Final","type":"Standards Track","category":"ERC","created":"2021-10-11","requires":[55,137,155,191,1271,1328],"discussionsTo":"https://ethereum-magicians.org/t/eip-4361-sign-in-with-ethereum/7263","repo":"ERCs","label":"ERC-4361","officialUrl":"https://eips.ethereum.org/EIPS/eip-4361","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-4361.md","url":"https://eips.huatuo.xyz/eip-4361/","tldr":{"en":"Sign-In with Ethereum (SIWE): a standard plain-text message that a wallet signs to log in to a website, giving apps a self-custodial alternative to 'Sign in with Google'.","ja":"Sign-In with Ethereum（SIWE）。ウォレットが署名してウェブサイトにログインするための標準的なプレーンテキストのメッセージで、アプリに「Google でログイン」に代わる、自己管理型の選択肢を提供する。","ko":"Sign-In with Ethereum(SIWE): 지갑이 서명해 웹사이트에 로그인하는 표준 일반 텍스트 메시지로, 앱에 'Google로 로그인'을 대체할 자기 보관형 방식을 제공한다.","zh":"Sign-In with Ethereum（SIWE）：钱包签署一条标准的纯文本消息即可登录网站，为应用提供了“使用 Google 登录”之外的自托管替代方案。"},"tags":["authentication","wallet","siwe","signature","identity"],"explainers":{"en":{"lang":"en","tldr":"Sign-In with Ethereum (SIWE): a standard plain-text message that a wallet signs to log in to a website, giving apps a self-custodial alternative to 'Sign in with Google'.","tags":["authentication","wallet","siwe","signature","identity"],"related":[191,1271,55,1328,5573],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-4361/","markdown":"## What problem does it solve?\n\nMany dapps already let users \"log in\" by signing a message with their wallet, then set a session cookie. But every site invented its own message text. Wallets could not tell a login request apart from any other signature, users saw inconsistent prompts, and many implementations forgot basics such as replay protection or checking which site actually asked for the signature, which made phishing easy.\n\nERC-4361 standardises the message format and the checks both sides must do, so any wallet can recognise and safely display a login request, and any server can verify it the same way.\n\n## How it works\n\n1. The site (relying party) builds a SIWE message, usually with a server-generated `nonce`.\n2. The wallet shows it and signs it with the [ERC-191](/eip-191/) `personal_sign` format (`\\x19Ethereum Signed Message:\\n\u003clen\u003e`).\n3. The server checks the message fields and the signature, then creates a session bound to the **address**.\n\nThe message is human-readable text with a strict grammar (defined in ABNF):\n\n```text\nexample.com wants you to sign in with your Ethereum account:\n0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\n\nI accept the ExampleOrg Terms of Service: https://example.com/tos\n\nURI: https://example.com/login\nVersion: 1\nChain ID: 1\nNonce: 32891756\nIssued At: 2021-09-30T16:25:24Z\n```\n\nRequired fields: `domain`, `address` ([EIP-55](/eip-55/) checksummed where applicable), `URI`, `Version` (`1`), `Chain ID`, `Nonce` (at least 8 alphanumerics) and `Issued At`. Optional: `scheme`, `statement`, `Expiration Time`, `Not Before`, `Request ID` and a list of `Resources` URIs.\n\nKey rules:\n\n- **Wallets** MUST check that `scheme`/`domain` match the real origin of the request and must show at least the domain, address, statement and resources before signing. This is the anti-phishing core of the spec.\n- **EOAs** are verified with ERC-191 `ecrecover`; **contract wallets** SHOULD be verified with [ERC-1271](/eip-1271/) `isValidSignature` on the chain given by `Chain ID`.\n- Servers must verify the nonce, timing fields and domain, and bind the session to the address, not to things that can change such as an ENS name.\n\n## Sample code\n\nClient side with ethers v6, building the message by hand:\n\n```ts\nimport { BrowserProvider } from \"ethers\";\n\nconst provider = new BrowserProvider(window.ethereum);\nconst signer = await provider.getSigner();\nconst address = await signer.getAddress();\nconst { chainId } = await provider.getNetwork();\nconst nonce = await fetch(\"/api/nonce\").then((r) =\u003e r.text()); // server-generated\n\nconst message = [\n  `${window.location.host} wants you to sign in with your Ethereum account:`,\n  address,\n  \"\",\n  \"Sign in to Example.\",\n  \"\",\n  `URI: ${window.location.origin}`,\n  \"Version: 1\",\n  `Chain ID: ${chainId}`,\n  `Nonce: ${nonce}`,\n  `Issued At: ${new Date().toISOString()}`,\n].join(\"\\n\");\n\nconst signature = await signer.signMessage(message); // ERC-191 personal_sign\nawait fetch(\"/api/verify\", { method: \"POST\", body: JSON.stringify({ message, signature }) });\n```\n\nOn the server, parse the message, check domain/nonce/expiry, then compare `ethers.verifyMessage(message, signature)` with the address (or call ERC-1271 for contract wallets).\n\n## Things to know\n\n- Status: **Final**. Libraries exist (e.g. the `siwe` npm package) that implement parsing and verification; prefer them over hand-rolled parsers.\n- Authentication only: authorisation and interpretation of `Resources` are out of scope. [ERC-5573](/eip-5573/) (ReCaps) builds capability delegation on top.\n- Use a fresh, high-entropy nonce per sign-in and reject reused ones, or a captured signature can be replayed.\n- ERC-1271 results depend on chain state, so sessions for contract wallets may need invalidating when signers change.\n- ERC-191 was chosen over EIP-712 because wallets display plain text more readably; the message is not designed for on-chain verification.\n"},"ja":{"lang":"ja","tldr":"Sign-In with Ethereum（SIWE）。ウォレットが署名してウェブサイトにログインするための標準的なプレーンテキストのメッセージで、アプリに「Google でログイン」に代わる、自己管理型の選択肢を提供する。","tags":["authentication","wallet","siwe","signature","identity"],"related":[191,1271,55,1328,5573],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-4361/","markdown":"## 何を解決するのか\n\n多くの dapp は、すでにユーザーがウォレットでメッセージに署名することで「ログイン」し、その後セッションクッキーを設定する方式を採っています。しかし、サイトごとに独自のメッセージ文面が作られていました。ウォレットはログイン要求を他の署名と区別できず、ユーザーは一貫性のない画面を見せられ、多くの実装がリプレイ対策や、署名を実際に求めているのがどのサイトかの確認といった基本を欠いており、フィッシングが容易でした。\n\nERC-4361 は、メッセージの形式と、双方が行うべき検証を標準化します。これにより、どのウォレットもログイン要求を認識して安全に表示でき、どのサーバーも同じ方法で検証できます。\n\n## 仕組み\n\n1. サイト（relying party）が、通常はサーバーが生成した `nonce` を使って、SIWE メッセージを組み立てます。\n2. ウォレットがそれを表示し、[ERC-191](/eip-191/) の `personal_sign` 形式（`\\x19Ethereum Signed Message:\\n\u003clen\u003e`）で署名します。\n3. サーバーはメッセージのフィールドと署名を検証し、**アドレス**に紐づくセッションを作成します。\n\nメッセージは、厳密な文法（ABNF で定義）を持つ、人が読めるテキストです。\n\n```text\nexample.com wants you to sign in with your Ethereum account:\n0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\n\nI accept the ExampleOrg Terms of Service: https://example.com/tos\n\nURI: https://example.com/login\nVersion: 1\nChain ID: 1\nNonce: 32891756\nIssued At: 2021-09-30T16:25:24Z\n```\n\n必須フィールド：`domain`、`address`（該当する場合は [EIP-55](/eip-55/) のチェックサム付き）、`URI`、`Version`（`1`）、`Chain ID`、`Nonce`（英数字 8 文字以上）、`Issued At`。任意フィールド：`scheme`、`statement`、`Expiration Time`、`Not Before`、`Request ID`、`Resources` URI のリスト。\n\n主なルールは次のとおりです。\n\n- **ウォレット**は、`scheme`/`domain` がリクエストの実際のオリジンと一致することを確認しなければならず（MUST）、署名の前に、少なくともドメイン、アドレス、ステートメント、リソースを表示しなければなりません。これが、この仕様のフィッシング対策の核心です。\n- **EOA** は ERC-191 の `ecrecover` で検証します。**コントラクトウォレット**は、`Chain ID` で指定されたチェーン上で、[ERC-1271](/eip-1271/) の `isValidSignature` で検証すべきです（SHOULD）。\n- サーバーは、nonce、時刻のフィールド、ドメインを検証し、セッションを ENS 名のような変わりうるものではなく、アドレスに紐づけなければなりません。\n\n## サンプルコード\n\nethers v6 を使ったクライアント側で、メッセージを手作業で組み立てる例です。\n\n```ts\nimport { BrowserProvider } from \"ethers\";\n\nconst provider = new BrowserProvider(window.ethereum);\nconst signer = await provider.getSigner();\nconst address = await signer.getAddress();\nconst { chainId } = await provider.getNetwork();\nconst nonce = await fetch(\"/api/nonce\").then((r) =\u003e r.text()); // server-generated\n\nconst message = [\n  `${window.location.host} wants you to sign in with your Ethereum account:`,\n  address,\n  \"\",\n  \"Sign in to Example.\",\n  \"\",\n  `URI: ${window.location.origin}`,\n  \"Version: 1\",\n  `Chain ID: ${chainId}`,\n  `Nonce: ${nonce}`,\n  `Issued At: ${new Date().toISOString()}`,\n].join(\"\\n\");\n\nconst signature = await signer.signMessage(message); // ERC-191 personal_sign\nawait fetch(\"/api/verify\", { method: \"POST\", body: JSON.stringify({ message, signature }) });\n```\n\nサーバー側では、メッセージをパースし、ドメイン・nonce・有効期限を確認してから、`ethers.verifyMessage(message, signature)` の結果とアドレスを比較します（コントラクトウォレットの場合は ERC-1271 を呼び出します）。\n\n## 知っておくべきこと\n\n- ステータス：**Final**。パースと検証を実装したライブラリ（たとえば npm の `siwe` パッケージ）があります。自前のパーサーより、そちらを使ってください。\n- 認証のみを扱います。認可や `Resources` の解釈は対象外です。[ERC-5573](/eip-5573/)（ReCaps）が、その上にケイパビリティの委任を構築しています。\n- サインインごとに、新しく、エントロピーの高い nonce を使い、再利用されたものは拒否してください。そうしないと、盗まれた署名がリプレイされるおそれがあります。\n- ERC-1271 の結果はチェーンの状態に依存するため、コントラクトウォレットのセッションは、署名者が変わったときに無効化が必要になる場合があります。\n- EIP-712 ではなく ERC-191 が選ばれたのは、ウォレットがプレーンテキストをより読みやすく表示できるためです。このメッセージは、オンチェーンでの検証を想定して設計されていません。\n"},"ko":{"lang":"ko","tldr":"Sign-In with Ethereum(SIWE): 지갑이 서명해 웹사이트에 로그인하는 표준 일반 텍스트 메시지로, 앱에 'Google로 로그인'을 대체할 자기 보관형 방식을 제공한다.","tags":["authentication","wallet","siwe","signature","identity"],"related":[191,1271,55,1328,5573],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-4361/","markdown":"## 어떤 문제를 해결하나요?\n\n많은 dapp이 이미 사용자가 지갑으로 메시지에 서명해 \"로그인\"하게 한 다음 세션 쿠키를 설정합니다. 하지만 사이트마다 자기만의 메시지 문구를 만들었습니다. 지갑은 로그인 요청을 다른 서명과 구별할 수 없었고, 사용자는 일관성 없는 화면을 봐야 했으며, 많은 구현이 리플레이 방지나 서명을 실제로 요청한 사이트가 어디인지 확인하는 기본 사항을 빠뜨려 피싱이 쉬웠습니다.\n\nERC-4361은 메시지 형식과 양쪽이 수행해야 하는 검증을 표준화합니다. 덕분에 어떤 지갑이든 로그인 요청을 알아보고 안전하게 보여 줄 수 있고, 어떤 서버든 같은 방식으로 검증할 수 있습니다.\n\n## 어떻게 동작하나요?\n\n1. 사이트(relying party)가 보통 서버가 생성한 `nonce`로 SIWE 메시지를 만듭니다.\n2. 지갑이 이를 보여 주고 [ERC-191](/eip-191/) `personal_sign` 형식(`\\x19Ethereum Signed Message:\\n\u003clen\u003e`)으로 서명합니다.\n3. 서버가 메시지 필드와 서명을 확인한 뒤 **주소**에 묶인 세션을 만듭니다.\n\n메시지는 엄격한 문법(ABNF로 정의)을 가진, 사람이 읽을 수 있는 텍스트입니다.\n\n```text\nexample.com wants you to sign in with your Ethereum account:\n0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\n\nI accept the ExampleOrg Terms of Service: https://example.com/tos\n\nURI: https://example.com/login\nVersion: 1\nChain ID: 1\nNonce: 32891756\nIssued At: 2021-09-30T16:25:24Z\n```\n\n필수 필드: `domain`, `address`(해당하는 경우 [EIP-55](/eip-55/) 체크섬 적용), `URI`, `Version`(`1`), `Chain ID`, `Nonce`(영숫자 8자 이상), `Issued At`. 선택 필드: `scheme`, `statement`, `Expiration Time`, `Not Before`, `Request ID`, 그리고 `Resources` URI 목록.\n\n핵심 규칙:\n\n- **지갑**은 `scheme`/`domain`이 요청의 실제 출처와 일치하는지 반드시(MUST) 확인해야 하며, 서명하기 전에 최소한 도메인, 주소, 문구(statement), 리소스를 보여 줘야 합니다. 이것이 명세의 피싱 방지 핵심입니다.\n- **EOA**는 ERC-191 `ecrecover`로 검증하고, **컨트랙트 지갑**은 `Chain ID`가 가리키는 체인에서 [ERC-1271](/eip-1271/) `isValidSignature`로 검증해야 합니다(SHOULD).\n- 서버는 nonce, 시간 필드, 도메인을 검증해야 하며, 세션을 ENS 이름처럼 바뀔 수 있는 것이 아니라 주소에 묶어야 합니다.\n\n## 샘플 코드\n\nethers v6를 사용한 클라이언트 측에서 메시지를 직접 만드는 예시입니다.\n\n```ts\nimport { BrowserProvider } from \"ethers\";\n\nconst provider = new BrowserProvider(window.ethereum);\nconst signer = await provider.getSigner();\nconst address = await signer.getAddress();\nconst { chainId } = await provider.getNetwork();\nconst nonce = await fetch(\"/api/nonce\").then((r) =\u003e r.text()); // server-generated\n\nconst message = [\n  `${window.location.host} wants you to sign in with your Ethereum account:`,\n  address,\n  \"\",\n  \"Sign in to Example.\",\n  \"\",\n  `URI: ${window.location.origin}`,\n  \"Version: 1\",\n  `Chain ID: ${chainId}`,\n  `Nonce: ${nonce}`,\n  `Issued At: ${new Date().toISOString()}`,\n].join(\"\\n\");\n\nconst signature = await signer.signMessage(message); // ERC-191 personal_sign\nawait fetch(\"/api/verify\", { method: \"POST\", body: JSON.stringify({ message, signature }) });\n```\n\n서버에서는 메시지를 파싱하고 도메인/nonce/만료를 확인한 다음, `ethers.verifyMessage(message, signature)`의 결과를 주소와 비교합니다(컨트랙트 지갑이라면 ERC-1271을 호출).\n\n## 알아둘 점\n\n- 상태: **Final**. 파싱과 검증을 구현한 라이브러리(예: npm의 `siwe` 패키지)가 있으니, 직접 만든 파서보다 그것을 사용하세요.\n- 인증만 다룹니다. 인가와 `Resources`의 해석은 범위 밖입니다. [ERC-5573](/eip-5573/)(ReCaps)이 그 위에 권한 위임을 구축합니다.\n- 로그인마다 새롭고 엔트로피가 높은 nonce를 사용하고 재사용된 것은 거부하세요. 그렇지 않으면 탈취된 서명이 리플레이될 수 있습니다.\n- ERC-1271 결과는 체인 상태에 따라 달라지므로, 서명자가 바뀌면 컨트랙트 지갑의 세션을 무효화해야 할 수 있습니다.\n- EIP-712 대신 ERC-191이 선택된 것은 지갑이 일반 텍스트를 더 읽기 쉽게 보여 주기 때문이며, 이 메시지는 온체인 검증을 염두에 두고 설계되지 않았습니다.\n"},"zh":{"lang":"zh","tldr":"Sign-In with Ethereum（SIWE）：钱包签署一条标准的纯文本消息即可登录网站，为应用提供了“使用 Google 登录”之外的自托管替代方案。","tags":["authentication","wallet","siwe","signature","identity"],"related":[191,1271,55,1328,5573],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-4361/","markdown":"## 它解决什么问题？\n\n许多 dapp 已经允许用户通过用钱包签署消息来\"登录\"，然后设置会话 cookie。但每个网站都自己发明了消息文本。钱包无法把登录请求与其他签名区分开，用户看到的提示五花八门，许多实现还漏掉了重放保护、核对究竟是哪个网站请求了签名等基本措施，这使钓鱼变得很容易。\n\nERC-4361 规范了消息格式以及双方必须执行的检查，使任何钱包都能识别并安全地显示登录请求，任何服务器也都能用同样的方式验证它。\n\n## 它如何运作\n\n1. 网站（依赖方）构造一条 SIWE 消息，通常带有服务器生成的 `nonce`。\n2. 钱包显示该消息，并使用 [ERC-191](/eip-191/) 的 `personal_sign` 格式（`\\x19Ethereum Signed Message:\\n\u003clen\u003e`）对其签名。\n3. 服务器检查消息字段和签名，然后创建一个绑定到**地址**的会话。\n\n消息是人类可读的文本，语法严格（用 ABNF 定义）：\n\n```text\nexample.com wants you to sign in with your Ethereum account:\n0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\n\nI accept the ExampleOrg Terms of Service: https://example.com/tos\n\nURI: https://example.com/login\nVersion: 1\nChain ID: 1\nNonce: 32891756\nIssued At: 2021-09-30T16:25:24Z\n```\n\n必填字段：`domain`、`address`（适用时采用 [EIP-55](/eip-55/) 校验和格式）、`URI`、`Version`（`1`）、`Chain ID`、`Nonce`（至少 8 个字母数字字符）和 `Issued At`。可选字段：`scheme`、`statement`、`Expiration Time`、`Not Before`、`Request ID` 以及一组 `Resources` URI。\n\n关键规则：\n\n- **钱包**必须（MUST）检查 `scheme`/`domain` 与请求的真实来源一致，并且在签名前至少要显示域名、地址、声明和资源。这是规范中防钓鱼的核心。\n- **EOA** 用 ERC-191 的 `ecrecover` 验证；**合约钱包**应当（SHOULD）在 `Chain ID` 指定的链上用 [ERC-1271](/eip-1271/) 的 `isValidSignature` 验证。\n- 服务器必须验证 nonce、时间字段和域名，并把会话绑定到地址，而不是绑定到 ENS 名称这类可能变化的东西上。\n\n## 示例代码\n\n使用 ethers v6 的客户端，手工构造消息：\n\n```ts\nimport { BrowserProvider } from \"ethers\";\n\nconst provider = new BrowserProvider(window.ethereum);\nconst signer = await provider.getSigner();\nconst address = await signer.getAddress();\nconst { chainId } = await provider.getNetwork();\nconst nonce = await fetch(\"/api/nonce\").then((r) =\u003e r.text()); // server-generated\n\nconst message = [\n  `${window.location.host} wants you to sign in with your Ethereum account:`,\n  address,\n  \"\",\n  \"Sign in to Example.\",\n  \"\",\n  `URI: ${window.location.origin}`,\n  \"Version: 1\",\n  `Chain ID: ${chainId}`,\n  `Nonce: ${nonce}`,\n  `Issued At: ${new Date().toISOString()}`,\n].join(\"\\n\");\n\nconst signature = await signer.signMessage(message); // ERC-191 personal_sign\nawait fetch(\"/api/verify\", { method: \"POST\", body: JSON.stringify({ message, signature }) });\n```\n\n在服务器端，解析消息，检查域名/nonce/过期时间，然后把 `ethers.verifyMessage(message, signature)` 的结果与地址比较（对于合约钱包则调用 ERC-1271）。\n\n## 需要注意\n\n- 状态：**Final**。已有实现了解析和验证的库（例如 npm 的 `siwe` 包）；请优先使用它们，而不是手写解析器。\n- 只负责身份认证：授权以及对 `Resources` 的解释不在范围之内。[ERC-5573](/eip-5573/)（ReCaps）在此基础上构建了能力委托。\n- 每次登录都使用新的、高熵的 nonce，并拒绝重复使用的 nonce，否则被截获的签名可能被重放。\n- ERC-1271 的结果取决于链状态，因此当签名者变更时，合约钱包的会话可能需要失效。\n- 选择 ERC-191 而不是 EIP-712，是因为钱包显示纯文本更易读；该消息的设计并不面向链上验证。\n"}},"requiredBy":[5573,8019]}
