You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/web3swift/Utils/EIP/EIP712/EIP712Parser.swift
+98-2Lines changed: 98 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -98,7 +98,7 @@ public class EIP712Parser {
98
98
throwWeb3Error.inputError(desc:"EIP712Parser: cannot decode EIP712TypedData object. Failed to parse one of primaryType, domain or message fields. Is any field missing?")
@@ -130,11 +130,107 @@ public struct EIP712TypedData {
130
130
publicinit(types:[String:[EIP712TypeProperty]],
131
131
primaryType:String,
132
132
domain:[String:AnyObject],
133
-
message:[String:AnyObject]){
133
+
message:[String:AnyObject])throws{
134
134
self.types = types
135
135
self.primaryType = primaryType
136
136
self.domain = domain
137
137
self.message = message
138
+
iflet problematicType =hasCircularDependency(){
139
+
throwWeb3Error.inputError(desc:"Created EIP712TypedData has a circular dependency amongst it's types. Cycle was first identified in '\(problematicType)'. Review it's uses in 'types'.")
140
+
}
138
141
}
139
142
143
+
/// Checks for a circular dependency among the given types.
144
+
///
145
+
/// If a circular dependency is detected, it returns the name of the type where the cycle was first identified.
146
+
/// Otherwise, it returns `nil`.
147
+
///
148
+
/// - Returns: The type name where a circular dependency is detected, or `nil` if no circular dependency exists.
149
+
/// - Note: The function utilizes depth-first search to identify the circular dependencies.
150
+
func hasCircularDependency()->String?{
151
+
152
+
/// Generates an adjacency list for the given types, representing their dependencies.
153
+
///
154
+
/// - Parameter types: A dictionary mapping type names to their property definitions.
155
+
/// - Returns: An adjacency list representing type dependencies.
throwWeb3Error.processingError(desc:"EIP712. Attempting to encode type that doesn't exist in this payload. Given type: \(type). Available types: \(types.values).")
0 commit comments