File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed
Sources/Web3Core/EthereumAddress
Tests/web3swiftTests/localTests Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,8 @@ public struct EthereumAddress: Equatable {
63
63
/// represented as `ASCII` data. Otherwise, checksummed address is returned with `0x` prefix.
64
64
public static func toChecksumAddress( _ addr: String ) -> String ? {
65
65
let address = addr. lowercased ( ) . stripHexPrefix ( )
66
- guard let hash = address. data ( using: . ascii) ? . sha3 ( . keccak256) . toHexString ( ) . stripHexPrefix ( ) else { return nil }
66
+ guard address. count == 40 ,
67
+ let hash = address. data ( using: . ascii) ? . sha3 ( . keccak256) . toHexString ( ) . stripHexPrefix ( ) else { return nil }
67
68
var ret = " 0x "
68
69
69
70
for (i, char) in address. enumerated ( ) {
Original file line number Diff line number Diff line change @@ -35,6 +35,12 @@ class UncategorizedTests: LocalTestCase {
35
35
let output = EthereumAddress . toChecksumAddress ( input)
36
36
XCTAssert ( output == " 0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359 " , " Failed to checksum address " )
37
37
}
38
+
39
+ func testErrorAddressChecksumAddress( ) throws {
40
+ let input = " ethereum:0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359?chainId=1&action=transfer "
41
+ let output = EthereumAddress . toChecksumAddress ( input)
42
+ XCTAssert ( output == nil , " Failed to checksum address " )
43
+ }
38
44
39
45
func testChecksumAddressParsing( ) throws {
40
46
let input = " 0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359 "
You can’t perform that action at this time.
0 commit comments