Skip to content

Commit

Permalink
Fix wrong ABNF Message construction (#2337)
Browse files Browse the repository at this point in the history
* fix: wrong ABNF Message construction

* added: changeset

* Update .changeset/clever-shoes-hope.md

* chore: snaps

---------

Co-authored-by: awkweb <tom@meagher.co>
  • Loading branch information
jaeil-wiki and tmm committed Jun 4, 2024
1 parent e754534 commit 8984eee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
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

0 comments on commit 8984eee

Please sign in to comment.