Skip to content

Commit 237d204

Browse files
fix: fixed nonce regex and variable type in EIP4361
1 parent 304d67c commit 237d204

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Sources/web3swift/Utils/EIP/EIP4361.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public final class EIP4361 {
2424
private static let uri = "\\nURI: (?<uri>(\(uriPattern))?)"
2525
private static let version = "\\nVersion: (?<version>1)"
2626
private static let chainId = "\\nChain ID: (?<chainId>[0-9a-fA-F]+)"
27-
private static let nonce = "\\nNonce: (?<nonce>[0-9a-fA-F]{8,})"
27+
private static let nonce = "\\nNonce: (?<nonce>[a-zA-Z0-9]{8,})"
2828
private static let issuedAt = "\\nIssued At: (?<issuedAt>(\(datetimePattern)))"
2929
private static let expirationTime = "(\\nExpiration Time: (?<expirationTime>(\(datetimePattern))))?"
3030
private static let notBefore = "(\\nNot Before: (?<notBefore>(\(datetimePattern))))?"
@@ -48,7 +48,7 @@ public final class EIP4361 {
4848
/// `chain-id` is the EIP-155 Chain ID to which the session is bound, and the network where Contract Accounts MUST be resolved.
4949
public let chainId: BigUInt
5050
/// `nonce` is a randomized token typically chosen by the relying party and used to prevent replay attacks, at least 8 alphanumeric characters.
51-
public let nonce: BigUInt
51+
public let nonce: String
5252
/// `issued-at` is the ISO 8601 datetime string of the current time.
5353
public let issuedAt: Date
5454
/// `expiration-time` (optional) is the ISO 8601 datetime string that, if present, indicates when the signed authentication message is no longer valid.
@@ -75,8 +75,7 @@ public final class EIP4361 {
7575
let version = BigUInt(rawVersion, radix: 10) ?? BigUInt(rawVersion, radix: 16),
7676
let rawChainId = groups["chainId"],
7777
let chainId = BigUInt(rawChainId, radix: 10) ?? BigUInt(rawChainId, radix: 16),
78-
let rawNonce = groups["nonce"],
79-
let nonce = BigUInt(rawNonce, radix: 10) ?? BigUInt(rawNonce, radix: 16),
78+
let nonce = groups["nonce"],
8079
let rawIssuedAt = groups["issuedAt"],
8180
let issuedAt = dateFormatter.date(from: rawIssuedAt)
8281
else {
@@ -111,7 +110,7 @@ public final class EIP4361 {
111110
descriptionParts.append("\n\nURI: \(uri)")
112111
descriptionParts.append("\nVersion: \(version.description)")
113112
descriptionParts.append("\nChain ID: \(chainId.description)")
114-
descriptionParts.append("\nNonce: \(nonce.description)")
113+
descriptionParts.append("\nNonce: \(nonce)")
115114
let dateFormatter = ISO8601DateFormatter()
116115
descriptionParts.append("\nIssued At: \(dateFormatter.string(from: issuedAt))")
117116
if let expirationTime = expirationTime {

0 commit comments

Comments
 (0)