-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from tkey/sha3
feat: add sha3
- Loading branch information
Showing
12 changed files
with
122 additions
and
34 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
Binary file modified
BIN
+81.7 KB
(100%)
Sources/curve_secp256k1/curve_secp256k1.xcframework/ios-arm64/libsecp256k1_rs.a
Binary file not shown.
Binary file modified
BIN
+122 KB
(100%)
.../curve_secp256k1/curve_secp256k1.xcframework/ios-arm64_x86_64-simulator/libsecp256k1_rs.a
Binary file not shown.
Binary file modified
BIN
+77.8 KB
(100%)
Sources/curve_secp256k1/curve_secp256k1.xcframework/macos-arm64_x86_64/libsecp256k1_rs.a
Binary file not shown.
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,28 @@ | ||
import Foundation | ||
|
||
public extension Data { | ||
var hexString: String { | ||
return map { String(format: "%02x", $0) }.joined() | ||
} | ||
|
||
init?(hexString: String) { | ||
// Ensure the string has an even number of characters | ||
guard hexString.count % 2 == 0 else { return nil } | ||
|
||
var data = Data(capacity: hexString.count / 2) | ||
|
||
// Convert each pair of characters to a byte and append to data | ||
var index = hexString.startIndex | ||
while index < hexString.endIndex { | ||
let nextIndex = hexString.index(index, offsetBy: 2) | ||
if let byte = UInt8(hexString[index..<nextIndex], radix: 16) { | ||
data.append(byte) | ||
} else { | ||
return nil // Invalid hexadecimal character | ||
} | ||
index = nextIndex | ||
} | ||
|
||
self = data | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Foundation | ||
|
||
#if canImport(curvelib) | ||
import curvelib | ||
#endif | ||
|
||
public func keccak256 ( data : Data ) throws -> Data { | ||
var errorCode: Int32 = -1 | ||
let hexPtr = UnsafeMutablePointer<Int8>(mutating: (data.hexString as NSString).utf8String) | ||
let result = withUnsafeMutablePointer(to: &errorCode, { error in | ||
curve_sha3_keccak256(hexPtr, error) | ||
}) | ||
guard errorCode == 0 else { | ||
throw CurveError(code: errorCode) | ||
} | ||
let value = String(cString: result!) | ||
curve_secp256k1_string_free(result) | ||
|
||
guard let hex_data = Data(hexString: value) else { | ||
throw CurveError(code: 3) | ||
} | ||
return hex_data | ||
} | ||
|
||
public enum Variants { | ||
case KECCAK256 | ||
} | ||
|
||
public extension Data { | ||
func sha3( varient : Variants ) throws -> Data { | ||
return try keccak256(data: self) | ||
} | ||
} |
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