-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
85 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Foundation | ||
import TweetNacl | ||
|
||
public enum WalletTransferSignerError: Swift.Error { | ||
case failedToSignMessage | ||
} | ||
|
||
public protocol WalletTransferSigner { | ||
func signMessage(_ message: Data) throws -> Data | ||
} | ||
|
||
public struct WalletTransferSecretKeySigner: WalletTransferSigner { | ||
private let secretKey: Data | ||
|
||
public init(secretKey: Data) { | ||
self.secretKey = secretKey | ||
} | ||
|
||
public func signMessage(_ message: Data) throws -> Data { | ||
do { | ||
return try NaclSign.signDetached(message: message, secretKey: secretKey) | ||
} catch { | ||
throw WalletTransferSignerError.failedToSignMessage | ||
} | ||
} | ||
} | ||
|
||
public struct WalletTransferEmptyKeySigner: WalletTransferSigner { | ||
public func signMessage(_ message: Data) throws -> Data { | ||
guard let data = String(repeating: "0", count: .signatureBytesCount).data(using: .utf8) else { | ||
throw WalletTransferSignerError.failedToSignMessage | ||
} | ||
return data | ||
} | ||
} | ||
|
||
private extension Int { | ||
static let signatureBytesCount = 64 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters