@@ -142,6 +142,24 @@ class EIP712TypedDataPayloadTests: XCTestCase {
142142 }
143143 }
144144
145+ func testEIP712ParserWithCustomTypeArrays( ) throws {
146+ let problematicTypeExample = """
147+ { " types " :{ " EIP712Domain " :[{ " name " : " name " , " type " : " string " },{ " name " : " version " , " type " : " string " },{ " name " : " chainId " , " type " : " uint256 " },{ " name " : " verifyingContract " , " type " : " address " }], " OrderComponents " :[{ " name " : " offerer " , " type " : " address " },{ " name " : " zone " , " type " : " address " },{ " name " : " offer " , " type " : " OfferItem[] " },{ " name " : " consideration " , " type " : " ConsiderationItem[] " },{ " name " : " orderType " , " type " : " uint8 " },{ " name " : " startTime " , " type " : " uint256 " },{ " name " : " endTime " , " type " : " uint256 " },{ " name " : " zoneHash " , " type " : " bytes32 " },{ " name " : " salt " , " type " : " uint256 " },{ " name " : " conduitKey " , " type " : " bytes32 " },{ " name " : " counter " , " type " : " uint256 " }], " OfferItem " :[{ " name " : " itemType " , " type " : " uint8 " },{ " name " : " token " , " type " : " address " },{ " name " : " identifierOrCriteria " , " type " : " uint256 " },{ " name " : " startAmount " , " type " : " uint256 " },{ " name " : " endAmount " , " type " : " uint256 " }], " ConsiderationItem " :[{ " name " : " itemType " , " type " : " uint8 " },{ " name " : " token " , " type " : " address " },{ " name " : " identifierOrCriteria " , " type " : " uint256 " },{ " name " : " startAmount " , " type " : " uint256 " },{ " name " : " endAmount " , " type " : " uint256 " },{ " name " : " recipient " , " type " : " address " }]}, " primaryType " : " OrderComponents " , " domain " :{ " name " : " Seaport " , " version " : " 1.5 " , " chainId " : " 5 " , " verifyingContract " : " 0x00000000000000ADc04C56Bf30aC9d3c0aAF14dC " }, " message " :{ " offerer " : " 0xD0727E8a578DE9Dd19BcED635B1aa43576E638bC " , " offer " :[{ " itemType " : " 2 " , " token " : " 0xE84a7676aAe742770A179dd7431073429a88c7B8 " , " identifierOrCriteria " : " 44 " , " startAmount " : " 1 " , " endAmount " : " 1 " }], " consideration " :[{ " itemType " : " 0 " , " token " : " 0x0000000000000000000000000000000000000000 " , " identifierOrCriteria " : " 0 " , " startAmount " : " 950000000000000000 " , " endAmount " : " 950000000000000000 " , " recipient " : " 0xD0727E8a578DE9Dd19BcED635B1aa43576E638bC " },{ " itemType " : " 0 " , " token " : " 0x0000000000000000000000000000000000000000 " , " identifierOrCriteria " : " 0 " , " startAmount " : " 25000000000000000 " , " endAmount " : " 25000000000000000 " , " recipient " : " 0x0000a26b00c1F0DF003000390027140000fAa719 " },{ " itemType " : " 0 " , " token " : " 0x0000000000000000000000000000000000000000 " , " identifierOrCriteria " : " 0 " , " startAmount " : " 25000000000000000 " , " endAmount " : " 25000000000000000 " , " recipient " : " 0xbDEf201FB5BE36579b6B66971d40A6e162b92B80 " }], " startTime " : " 1698665491 " , " endTime " : " 1701343891 " , " orderType " : " 0 " , " zone " : " 0x004C00500000aD104D7DBd00e3ae0A5C00560C00 " , " zoneHash " : " 0x0000000000000000000000000000000000000000000000000000000000000000 " , " salt " : " 24446860302761739304752683030156737591518664810215442929808784621098726351597 " , " conduitKey " : " 0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000 " , " totalOriginalConsiderationItems " : " 3 " , " counter " : " 0 " }}
148+ """
149+ XCTAssertNoThrow ( try EIP712Parser . parse ( problematicTypeExample) )
150+ }
151+
152+ func testEIP712SignHashWithCustomTypeArrays( ) throws {
153+ let problematicTypeExample = """
154+ { " types " :{ " EIP712Domain " :[{ " name " : " name " , " type " : " string " },{ " name " : " version " , " type " : " string " },{ " name " : " chainId " , " type " : " uint256 " },{ " name " : " verifyingContract " , " type " : " address " }], " OrderComponents " :[{ " name " : " offerer " , " type " : " address " },{ " name " : " zone " , " type " : " address " },{ " name " : " offer " , " type " : " OfferItem[] " },{ " name " : " consideration " , " type " : " ConsiderationItem[] " },{ " name " : " orderType " , " type " : " uint8 " },{ " name " : " startTime " , " type " : " uint256 " },{ " name " : " endTime " , " type " : " uint256 " },{ " name " : " zoneHash " , " type " : " bytes32 " },{ " name " : " salt " , " type " : " uint256 " },{ " name " : " conduitKey " , " type " : " bytes32 " },{ " name " : " counter " , " type " : " uint256 " }], " OfferItem " :[{ " name " : " itemType " , " type " : " uint8 " },{ " name " : " token " , " type " : " address " },{ " name " : " identifierOrCriteria " , " type " : " uint256 " },{ " name " : " startAmount " , " type " : " uint256 " },{ " name " : " endAmount " , " type " : " uint256 " }], " ConsiderationItem " :[{ " name " : " itemType " , " type " : " uint8 " },{ " name " : " token " , " type " : " address " },{ " name " : " identifierOrCriteria " , " type " : " uint256 " },{ " name " : " startAmount " , " type " : " uint256 " },{ " name " : " endAmount " , " type " : " uint256 " },{ " name " : " recipient " , " type " : " address " }]}, " primaryType " : " OrderComponents " , " domain " :{ " name " : " Seaport " , " version " : " 1.5 " , " chainId " : " 5 " , " verifyingContract " : " 0x00000000000000ADc04C56Bf30aC9d3c0aAF14dC " }, " message " :{ " offerer " : " 0xD0727E8a578DE9Dd19BcED635B1aa43576E638bC " , " offer " :[{ " itemType " : " 2 " , " token " : " 0xE84a7676aAe742770A179dd7431073429a88c7B8 " , " identifierOrCriteria " : " 44 " , " startAmount " : " 1 " , " endAmount " : " 1 " }], " consideration " :[{ " itemType " : " 0 " , " token " : " 0x0000000000000000000000000000000000000000 " , " identifierOrCriteria " : " 0 " , " startAmount " : " 950000000000000000 " , " endAmount " : " 950000000000000000 " , " recipient " : " 0xD0727E8a578DE9Dd19BcED635B1aa43576E638bC " },{ " itemType " : " 0 " , " token " : " 0x0000000000000000000000000000000000000000 " , " identifierOrCriteria " : " 0 " , " startAmount " : " 25000000000000000 " , " endAmount " : " 25000000000000000 " , " recipient " : " 0x0000a26b00c1F0DF003000390027140000fAa719 " },{ " itemType " : " 0 " , " token " : " 0x0000000000000000000000000000000000000000 " , " identifierOrCriteria " : " 0 " , " startAmount " : " 25000000000000000 " , " endAmount " : " 25000000000000000 " , " recipient " : " 0xbDEf201FB5BE36579b6B66971d40A6e162b92B80 " }], " startTime " : " 1698665491 " , " endTime " : " 1701343891 " , " orderType " : " 0 " , " zone " : " 0x004C00500000aD104D7DBd00e3ae0A5C00560C00 " , " zoneHash " : " 0x0000000000000000000000000000000000000000000000000000000000000000 " , " salt " : " 24446860302761739304752683030156737591518664810215442929808784621098726351597 " , " conduitKey " : " 0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000 " , " totalOriginalConsiderationItems " : " 3 " , " counter " : " 0 " }}
155+ """
156+ let eip712Payload = try EIP712Parser . parse ( problematicTypeExample)
157+ XCTAssertEqual ( try eip712Payload. encodeType ( " OrderComponents " ) , " OrderComponents(address offerer,address zone,OfferItem[] offer,ConsiderationItem[] consideration,uint8 orderType,uint256 startTime,uint256 endTime,bytes32 zoneHash,uint256 salt,bytes32 conduitKey,uint256 counter)OfferItem(uint8 itemType,address token,uint256 identifierOrCriteria,uint256 startAmount,uint256 endAmount)ConsiderationItem(uint8 itemType,address token,uint256 identifierOrCriteria,uint256 startAmount,uint256 endAmount,address recipient) " )
158+ XCTAssertEqual ( try eip712Payload. encodeType ( " OfferItem " ) , " OfferItem(uint8 itemType,address token,uint256 identifierOrCriteria,uint256 startAmount,uint256 endAmount) " )
159+ XCTAssertEqual ( try eip712Payload. encodeType ( " ConsiderationItem " ) , " ConsiderationItem(uint8 itemType,address token,uint256 identifierOrCriteria,uint256 startAmount,uint256 endAmount,address recipient) " )
160+ XCTAssertNoThrow ( try eip712Payload. signHash ( ) )
161+ }
162+
145163 func testEIP712EncodeType( ) throws {
146164 let parsedEip712TypedData = try EIP712Parser . parse ( EIP712TestData . testTypedDataPayload)
147165 try XCTAssertEqual ( parsedEip712TypedData. encodeType ( " EIP712Domain " ) , " EIP712Domain(string name,string version,uint256 chainId,address verifyingContract) " )
0 commit comments