Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong ABNF Message construction #2337

Merged
merged 5 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clever-shoes-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Updated `createSiweMessage` `statement` construction to match ABNF Message Format.
7 changes: 7 additions & 0 deletions src/utils/siwe/createSiweMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test('default', () => {
"example.com wants you to sign in with your Ethereum account:
0xA0Cf798816D4b9b9866b5330EEa46a18382f251e


URI: https://example.com/path
Version: 1
Chain ID: 1
Expand All @@ -44,6 +45,7 @@ test('parameters: scheme', () => {
"https://example.com wants you to sign in with your Ethereum account:
0xA0Cf798816D4b9b9866b5330EEa46a18382f251e


URI: https://example.com/path
Version: 1
Chain ID: 1
Expand Down Expand Up @@ -86,6 +88,7 @@ test('parameters: issuedAt', () => {
"example.com wants you to sign in with your Ethereum account:
0xA0Cf798816D4b9b9866b5330EEa46a18382f251e


URI: https://example.com/path
Version: 1
Chain ID: 1
Expand All @@ -107,6 +110,7 @@ test('parameters: expirationTime', () => {
"example.com wants you to sign in with your Ethereum account:
0xA0Cf798816D4b9b9866b5330EEa46a18382f251e


URI: https://example.com/path
Version: 1
Chain ID: 1
Expand All @@ -131,6 +135,7 @@ test('parameters: notBefore', () => {
"example.com wants you to sign in with your Ethereum account:
0xA0Cf798816D4b9b9866b5330EEa46a18382f251e


URI: https://example.com/path
Version: 1
Chain ID: 1
Expand All @@ -155,6 +160,7 @@ test('parameters: requestId', () => {
"example.com wants you to sign in with your Ethereum account:
0xA0Cf798816D4b9b9866b5330EEa46a18382f251e


URI: https://example.com/path
Version: 1
Chain ID: 1
Expand Down Expand Up @@ -183,6 +189,7 @@ test('parameters: resources', () => {
"example.com wants you to sign in with your Ethereum account:
0xA0Cf798816D4b9b9866b5330EEa46a18382f251e


URI: https://example.com/path
Version: 1
Chain ID: 1
Expand Down
4 changes: 2 additions & 2 deletions src/utils/siwe/createSiweMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ export function createSiweMessage(
})()
const statement = (() => {
if (!parameters.statement) return ''
return `\n${parameters.statement}\n`
return `${parameters.statement}\n`
})()
const prefix = `${origin} wants you to sign in with your Ethereum account:\n${address}\n${statement}`
const prefix = `${origin} wants you to sign in with your Ethereum account:\n${address}\n\n${statement}`

let suffix = `URI: ${uri}\nVersion: ${version}\nChain ID: ${chainId}\nNonce: ${nonce}\nIssued At: ${issuedAt.toISOString()}`

Expand Down
Loading