Skip to content

Commit c0447af

Browse files
fix: updated regex to check if message is probably SIWE - added \\n to SIWE domain regex
1 parent 208ebdc commit c0447af

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Sources/web3swift/Utils/EIP/EIP4361.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public final class EIP4361 {
8282
}
8383

8484
public static func validate(_ message: String) -> EIP4361ValidationResponse {
85-
let siweConstantMessageRegex = try! NSRegularExpression(pattern: "^\(domain)")
85+
let siweConstantMessageRegex = try! NSRegularExpression(pattern: "^\(domain)\\n")
8686
guard siweConstantMessageRegex.firstMatch(in: message, range: message.fullNSRange) != nil else {
8787
return EIP4361ValidationResponse(isEIP4361: false, eip4361: nil, capturedFields: [:])
8888
}

Tests/web3swiftTests/localTests/EIP4361Test.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class EIP4361Test: XCTestCase {
8585
}
8686

8787
func test_invalidEIP4361_missingAddress() {
88-
let rawSiweMessage = "service.invalid wants you to sign in with your Ethereum account:I accept the ServiceOrg Terms of Service: https://service.invalid/tos\n\nURI: https://service.invalid/login\nVersion: 1\nChain ID: 1\nNonce: 32891756\nIssued At: 2021-09-30T16:25:24.345Z\nExpiration Time: 2021-09-29T15:25:24.234Z\nNot Before: 2021-10-28T14:25:24.123Z\nRequest ID: random-request-id_STRING!@$%%&\nResources:\n- ipfs://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/\n- https://example.com/my-web2-claim.json"
88+
let rawSiweMessage = "service.invalid wants you to sign in with your Ethereum account:\nI accept the ServiceOrg Terms of Service: https://service.invalid/tos\n\nURI: https://service.invalid/login\nVersion: 1\nChain ID: 1\nNonce: 32891756\nIssued At: 2021-09-30T16:25:24.345Z\nExpiration Time: 2021-09-29T15:25:24.234Z\nNot Before: 2021-10-28T14:25:24.123Z\nRequest ID: random-request-id_STRING!@$%%&\nResources:\n- ipfs://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/\n- https://example.com/my-web2-claim.json"
8989

9090
let validationResponse = EIP4361.validate(rawSiweMessage)
9191
guard validationResponse.isEIP4361 && !validationResponse.isValid else {

0 commit comments

Comments
 (0)