Skip to content

Commit

Permalink
Merge pull request #41 from cryptape/remove-eth-message-signer
Browse files Browse the repository at this point in the history
Remove eth message signer
  • Loading branch information
XiaoLu authored Nov 30, 2018
2 parents 9719694 + df8e17d commit 24d4966
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 121 deletions.
8 changes: 0 additions & 8 deletions AppChain.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
1AD65F9F21229AF500AA4C84 /* Signer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AD65F9E21229AF500AA4C84 /* Signer.swift */; };
1AD65FA12122A1F900AA4C84 /* TransactionSendingResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AD65FA02122A1F900AA4C84 /* TransactionSendingResult.swift */; };
1AD65FA62122AF4400AA4C84 /* SignerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AD65FA42122AF2F00AA4C84 /* SignerTest.swift */; };
893532EE217D7D9B00404C0B /* EthereumMessageSigner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 893532ED217D7D9B00404C0B /* EthereumMessageSigner.swift */; };
893532F2217DA03300404C0B /* EthereumMessageSignerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 893532F1217DA03300404C0B /* EthereumMessageSignerTests.swift */; };
89733041217EB559001B8D93 /* MessageSigner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89733040217EB559001B8D93 /* MessageSigner.swift */; };
A761B95773C2431357D1B0B9 /* Pods_AppChain.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A425B554C4D9A6E8284FEAC /* Pods_AppChain.framework */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -124,8 +122,6 @@
69F270D62F7F19A30770BD03 /* Pods-AppChainTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AppChainTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AppChainTests/Pods-AppChainTests.debug.xcconfig"; sourceTree = "<group>"; };
6A425B554C4D9A6E8284FEAC /* Pods_AppChain.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AppChain.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7FF8D9768BC7235E22EC11C8 /* Pods-AppChain.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AppChain.release.xcconfig"; path = "Pods/Target Support Files/Pods-AppChain/Pods-AppChain.release.xcconfig"; sourceTree = "<group>"; };
893532ED217D7D9B00404C0B /* EthereumMessageSigner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthereumMessageSigner.swift; sourceTree = "<group>"; };
893532F1217DA03300404C0B /* EthereumMessageSignerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthereumMessageSignerTests.swift; sourceTree = "<group>"; };
89733040217EB559001B8D93 /* MessageSigner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageSigner.swift; sourceTree = "<group>"; };
8990CDB62160682F00205129 /* Config.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Config.json; sourceTree = "<group>"; };
D9D78017E61E65184F73D1F8 /* Pods-AppChain.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AppChain.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AppChain/Pods-AppChain.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -284,7 +280,6 @@
1AD65F9E21229AF500AA4C84 /* Signer.swift */,
1A0529BF214258EC00C847CA /* Unsigner.swift */,
89733040217EB559001B8D93 /* MessageSigner.swift */,
893532ED217D7D9B00404C0B /* EthereumMessageSigner.swift */,
);
path = Signer;
sourceTree = "<group>";
Expand All @@ -303,7 +298,6 @@
children = (
1AD65FA42122AF2F00AA4C84 /* SignerTest.swift */,
1A0529C1214279A500C847CA /* UnsignerTests.swift */,
893532F1217DA03300404C0B /* EthereumMessageSignerTests.swift */,
);
path = Signer;
sourceTree = "<group>";
Expand Down Expand Up @@ -545,7 +539,6 @@
1A0D0C072185A8EF003E680D /* Data+Extension.swift in Sources */,
1A67ED50211D11C600DCE871 /* Request.swift in Sources */,
1A0D0C052185A861003E680D /* BloomFilter.swift in Sources */,
893532EE217D7D9B00404C0B /* EthereumMessageSigner.swift in Sources */,
1AD65F9021217AC000AA4C84 /* DecodeUtils.swift in Sources */,
1AD65F9F21229AF500AA4C84 /* Signer.swift in Sources */,
1A67ED54211D122000DCE871 /* Method.swift in Sources */,
Expand All @@ -569,7 +562,6 @@
files = (
1A67ED3D211BEAFD00DCE871 /* HTTPProviderTests.swift in Sources */,
1A58853A211DC759007043F1 /* RPCTests.swift in Sources */,
893532F2217DA03300404C0B /* EthereumMessageSignerTests.swift in Sources */,
1A0529C2214279A500C847CA /* UnsignerTests.swift in Sources */,
1AD65FA62122AF4400AA4C84 /* SignerTest.swift in Sources */,
1A64297F211C63E000352209 /* Config.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion AppChainSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "AppChainSwift"
s.version = "0.20.3"
s.version = "0.20.4"
s.summary = "Nervos AppChain SDK implementation in Swift for iOS"

s.description = <<-DESC
Expand Down
2 changes: 1 addition & 1 deletion Source/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.20.3</string>
<string>0.20.4</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
59 changes: 0 additions & 59 deletions Source/Signer/EthereumMessageSigner.swift

This file was deleted.

27 changes: 26 additions & 1 deletion Source/Signer/MessageSigner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@

import Foundation

public enum SignError: Error {
case invalidPrivateKey
case invalidSignature
}

// AppChain Message Signer
struct MessageSigner {
public init() {}

// TODO: AppChain sign personal message
public func sign(message: Data, privateKey: String, useExtraEntropy: Bool = true) throws -> String? {
return try signHash(EthereumMessageSigner().hashMessage(message), privateKey: privateKey, useExtraEntropy: useExtraEntropy).toHexString().addHexPrefix()
return try signHash(hashMessage(message), privateKey: privateKey, useExtraEntropy: useExtraEntropy).toHexString().addHexPrefix()
}

private func signHash(_ hash: Data, privateKey: String, useExtraEntropy: Bool = true) throws -> Data {
Expand All @@ -27,4 +32,24 @@ struct MessageSigner {
}
return signature
}

public func hashMessage(_ message: Data) -> Data {
return message.sha3(.keccak256)
}

public func hashPersonalMessage(_ personalMessage: Data) -> Data? {
return hashMessage(appendPersonalMessagePrefix(for: personalMessage))
}
}

extension MessageSigner {
func appendPersonalMessagePrefix(for message: Data) -> Data {
let prefix = "\u{19}Ethereum Signed Message:\n\(message.count)"
let prefixData = prefix.data(using: .ascii)!
if message.count >= prefixData.count && prefixData == message[0 ..< prefixData.count] {
return message
} else {
return prefixData + message
}
}
}
51 changes: 0 additions & 51 deletions Tests/Signer/EthereumMessageSignerTests.swift

This file was deleted.

0 comments on commit 24d4966

Please sign in to comment.