@@ -59,6 +59,80 @@ final class secp256k1Tests: XCTestCase {
5959 // Verify the generated public key matches the expected public key
6060 XCTAssertEqual ( expectedPublicKey, publicKey)
6161 }
62+
63+ func testECDHBindings( ) {
64+ // Initialize context
65+ let context = secp256k1_context_create ( UInt32 ( SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY) ) !
66+
67+ // Destroy context after execution
68+ defer { secp256k1_context_destroy ( context) }
69+
70+ var point = secp256k1_pubkey ( )
71+ var res = [ UInt8] ( repeating: 0 , count: 32 )
72+ var s_one = [ UInt8] ( repeating: 0 , count: 32 )
73+
74+ s_one [ 31 ] = 1 ;
75+
76+ XCTAssertEqual ( secp256k1_ec_pubkey_create ( context, & point, s_one) , 1 )
77+ XCTAssertEqual ( secp256k1_ecdh ( context, & res, & point, s_one, nil , nil ) , 1 )
78+ }
79+
80+ func testExtraKeysBindings( ) {
81+ // Initialize context
82+ let context = secp256k1_context_create ( UInt32 ( SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY) ) !
83+
84+ // Destroy context after execution
85+ defer { secp256k1_context_destroy ( context) }
86+
87+ var pubKey = secp256k1_pubkey ( )
88+ var xOnlyPubKey = secp256k1_xonly_pubkey ( )
89+ var pk_parity = Int32 ( )
90+
91+ let privateKey = try ! " 14E4A74438858920D8A35FB2D88677580B6A2EE9BE4E711AE34EC6B396D87B5C " . byteArray ( )
92+
93+ XCTAssertEqual ( secp256k1_ec_pubkey_create ( context, & pubKey, privateKey) , 1 )
94+ XCTAssertEqual ( secp256k1_xonly_pubkey_from_pubkey ( context, & xOnlyPubKey, & pk_parity, & pubKey) , 1 )
95+ }
96+
97+ func testRecoveryBindings( ) {
98+ // Initialize context
99+ let context = secp256k1_context_create ( UInt32 ( SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY) ) !
100+
101+ // Destroy context after execution
102+ defer { secp256k1_context_destroy ( context) }
103+
104+ var pubKey = secp256k1_pubkey ( )
105+ var recsig = secp256k1_ecdsa_recoverable_signature ( )
106+ var message = [ UInt8] ( repeating: 0 , count: 32 )
107+
108+ let privateKey = try ! " 14E4A74438858920D8A35FB2D88677580B6A2EE9BE4E711AE34EC6B396D87B5C " . byteArray ( )
109+
110+ XCTAssertEqual ( secp256k1_ec_seckey_verify ( context, privateKey) , 1 )
111+ XCTAssertEqual ( secp256k1_ec_pubkey_create ( context, & pubKey, privateKey) , 1 )
112+ XCTAssertEqual ( secp256k1_ecdsa_sign_recoverable ( context, & recsig, & message, privateKey, nil , nil ) , 1 )
113+ }
114+
115+ func testSchnorrBindings( ) {
116+ // Initialize context
117+ let context = secp256k1_context_create ( UInt32 ( SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY) ) !
118+
119+ // Destroy context after execution
120+ defer { secp256k1_context_destroy ( context) }
121+
122+ var keypair = secp256k1_keypair ( )
123+ var xpubKey = secp256k1_xonly_pubkey ( )
124+ var xpubKeyBytes = [ UInt8] ( repeating: 0 , count: 32 )
125+
126+ let privateKey = try ! " 14E4A74438858920D8A35FB2D88677580B6A2EE9BE4E711AE34EC6B396D87B5C " . byteArray ( )
127+
128+ XCTAssertEqual ( secp256k1_keypair_create ( context, & keypair, privateKey) , 1 )
129+ XCTAssertEqual ( secp256k1_keypair_xonly_pub ( context, & xpubKey, nil , & keypair) , 1 )
130+ XCTAssertEqual ( secp256k1_xonly_pubkey_serialize ( context, & xpubKeyBytes, & xpubKey) , 1 )
131+
132+ let expectedXPubKey = " 734b3511150a60fc8cac329cd5ff804555728740f2f2e98bc4242135ef5d5e4e "
133+
134+ XCTAssertEqual ( String ( byteArray: xpubKeyBytes) , expectedXPubKey)
135+ }
62136
63137 /// Compressed Key pair test
64138 func testCompressedKeypairImplementationWithRaw( ) {
@@ -219,6 +293,10 @@ final class secp256k1Tests: XCTestCase {
219293 static var allTests = [
220294 ( " testUncompressedKeypairCreation " , testUncompressedKeypairCreation) ,
221295 ( " testCompressedKeypairCreation " , testCompressedKeypairCreation) ,
296+ ( " testECDHBindings " , testECDHBindings) ,
297+ ( " testExtraKeysBindings " , testExtraKeysBindings) ,
298+ ( " testRecoveryBindings " , testRecoveryBindings) ,
299+ ( " testSchnorrBindings " , testSchnorrBindings) ,
222300 ( " testCompressedKeypairImplementationWithRaw " , testCompressedKeypairImplementationWithRaw) ,
223301 ( " testSha256 " , testSha256) ,
224302 ( " testSigning " , testSigning) ,
0 commit comments