@@ -140,7 +140,7 @@ class CryptoUtilsTests: XCTestCase {
140
140
XCTAssertEqual ( normalized. hexString, " 5365F955FC45763383936BBC021A15D583E8D2300D1A65D21853B6A0FCAECE4E29AF6C44A13AD6E138336A4BD872F15FC517C30816E9B4C57858697AEBE25364 " )
141
141
}
142
142
143
- func testRecover ( ) {
143
+ func testSignatureUnmarshal ( ) {
144
144
let privateKey = Data ( hexString: " fd230007d4a39352f50d8c481456c1f86ddc5ff155df170af0100a62269852f0 " )
145
145
let publicKey = Data ( hexString: " 0432f507f6a3029028faa5913838c50f5ff3355b9b000b51889d03a2bdb96570cd750e8187482a27ca9d2dd0c92c632155d0384521ed406753c9883621ad0da68c " )
146
146
@@ -153,6 +153,22 @@ class CryptoUtilsTests: XCTestCase {
153
153
XCTAssertEqual ( unmarshalled? . v. hexString, " 1C " )
154
154
}
155
155
156
+ func testRecoverPublicKey( ) throws {
157
+ let privateKey = Data ( hexString: " fd230007d4a39352f50d8c481456c1f86ddc5ff155df170af0100a62269852f0 " )
158
+ let publicKey = Data ( hexString: " 0432f507f6a3029028faa5913838c50f5ff3355b9b000b51889d03a2bdb96570cd750e8187482a27ca9d2dd0c92c632155d0384521ed406753c9883621ad0da68c " )
159
+ let dummyData = Data ( repeating: UInt8 ( 1 ) , count: 64 )
160
+ let hash = dummyData. getSha256 ( )
161
+
162
+ let signature = try Secp256k1Utils ( ) . sign ( dummyData, with: privateKey)
163
+ let unmarshalled = try Secp256k1Signature ( with: signature) . unmarshal ( with: publicKey, hash: hash)
164
+
165
+ let key = try Secp256k1Key ( with: unmarshalled, hash: hash)
166
+ XCTAssertEqual ( try key. decompress ( ) . hexString, publicKey. hexString)
167
+
168
+ let key1 = try Secp256k1Key ( with: unmarshalled, message: dummyData)
169
+ XCTAssertEqual ( try key1. decompress ( ) . hexString, publicKey. hexString)
170
+ }
171
+
156
172
func testSecp256k1PrivateKeyValidation( ) {
157
173
let utils = Secp256k1Utils ( )
158
174
0 commit comments