-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic tests for xonly_[pubkey|privkey]_tweak_add, and xonly_pubkey_tw…
…eak_verify
- Loading branch information
Showing
10 changed files
with
329 additions
and
3 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
40 changes: 40 additions & 0 deletions
40
secp256k1/tests/secp256k1_xonly_privkey_tweak_add_basic.phpt
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,40 @@ | ||
--TEST-- | ||
secp256k1_xonly_privkey_tweak_add works | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN|SECP256K1_CONTEXT_VERIFY); | ||
|
||
$pubkey1 = null; | ||
$pubkey2 = null; | ||
$pubKey1Out = null; | ||
$pubKey2Out = null; | ||
$tweakedPub = null; | ||
$tweakTwo = str_repeat("\x00", 31) . "\x02"; | ||
$privKey1 = str_repeat("\x42", 32); | ||
//02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619 | ||
$privKey2 = str_repeat("\x42", 31) . "\x44"; | ||
|
||
$result = secp256k1_xonly_pubkey_create($ctx, $pubkey1, $privKey1); | ||
echo $result . PHP_EOL; | ||
echo get_resource_type($pubkey1) . PHP_EOL; | ||
|
||
$result = secp256k1_xonly_privkey_tweak_add($ctx, $privKey1, $tweakTwo); | ||
echo $result . PHP_EOL; | ||
|
||
if ($privKey1 === $privKey2) { | ||
echo "private keys equal"; | ||
} else { | ||
echo bin2hex($privKey1)." !== ".bin2hex($privKey2)."\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
1 | ||
secp256k1_xonly_pubkey | ||
1 | ||
private keys equal |
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
41 changes: 41 additions & 0 deletions
41
secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_basic1.phpt
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,41 @@ | ||
--TEST-- | ||
secp256k1_xonly_pubkey_from_pubkey works | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); | ||
|
||
$privKey = str_repeat("\x41", 32); | ||
//02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619 | ||
|
||
$pubkey = null; | ||
$xonlyPubKey = null; | ||
$sign = null; | ||
$pubkey2 = null; | ||
$result = secp256k1_ec_pubkey_create($ctx, $pubkey, $privKey); | ||
echo $result . PHP_EOL; | ||
echo get_resource_type($pubkey) . PHP_EOL; | ||
|
||
$result = secp256k1_xonly_pubkey_from_pubkey($ctx, $xonlyPubKey, $sign, $pubkey); | ||
echo $result . PHP_EOL; | ||
|
||
echo "sign: $sign\n"; | ||
|
||
$serialized = null; | ||
$result = secp256k1_xonly_pubkey_serialize($ctx, $serialized, $xonlyPubKey); | ||
echo $result . PHP_EOL; | ||
|
||
echo bin2hex($serialized) . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
1 | ||
secp256k1_pubkey | ||
1 | ||
sign: 1 | ||
1 | ||
eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619 |
41 changes: 41 additions & 0 deletions
41
secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_basic2.phpt
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,41 @@ | ||
--TEST-- | ||
secp256k1_xonly_pubkey_from_pubkey works | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); | ||
|
||
$privKey = str_repeat("\x42", 32); | ||
//0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c | ||
|
||
$pubkey = null; | ||
$xonlyPubKey = null; | ||
$sign = null; | ||
$pubkey2 = null; | ||
$result = secp256k1_ec_pubkey_create($ctx, $pubkey, $privKey); | ||
echo $result . PHP_EOL; | ||
echo get_resource_type($pubkey) . PHP_EOL; | ||
|
||
$result = secp256k1_xonly_pubkey_from_pubkey($ctx, $xonlyPubKey, $sign, $pubkey); | ||
echo $result . PHP_EOL; | ||
|
||
echo "sign: $sign\n"; | ||
|
||
$serialized = null; | ||
$result = secp256k1_xonly_pubkey_serialize($ctx, $serialized, $xonlyPubKey); | ||
echo $result . PHP_EOL; | ||
|
||
echo bin2hex($serialized) . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
1 | ||
secp256k1_pubkey | ||
1 | ||
sign: 0 | ||
1 | ||
24653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c |
36 changes: 36 additions & 0 deletions
36
secp256k1/tests/secp256k1_xonly_pubkey_to_pubkey_basic1.phpt
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,36 @@ | ||
--TEST-- | ||
secp256k1_xonly_pubkey_to_pubkey works | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); | ||
|
||
$pubKeyIn = hex2bin("eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619"); | ||
$sign = 1; | ||
$pubkey = null; | ||
$xonlyPubKey = null; | ||
|
||
$result = secp256k1_xonly_pubkey_parse($ctx, $xonlyPubKey, $pubKeyIn); | ||
echo $result . PHP_EOL; | ||
echo get_resource_type($xonlyPubKey) . PHP_EOL; | ||
|
||
$result = secp256k1_xonly_pubkey_to_pubkey($ctx, $pubkey, $xonlyPubKey, $sign); | ||
echo $result . PHP_EOL; | ||
|
||
$serialized = null; | ||
$result = secp256k1_ec_pubkey_serialize($ctx, $serialized, $pubkey, SECP256K1_EC_COMPRESSED); | ||
echo $result . PHP_EOL; | ||
|
||
echo bin2hex($serialized) . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
1 | ||
secp256k1_xonly_pubkey | ||
1 | ||
1 | ||
02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619 |
36 changes: 36 additions & 0 deletions
36
secp256k1/tests/secp256k1_xonly_pubkey_to_pubkey_basic2.phpt
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,36 @@ | ||
--TEST-- | ||
secp256k1_xonly_pubkey_to_pubkey works | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); | ||
|
||
$pubKeyIn = hex2bin("24653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c"); | ||
$sign = 0; | ||
$pubkey = null; | ||
$xonlyPubKey = null; | ||
|
||
$result = secp256k1_xonly_pubkey_parse($ctx, $xonlyPubKey, $pubKeyIn); | ||
echo $result . PHP_EOL; | ||
echo get_resource_type($xonlyPubKey) . PHP_EOL; | ||
|
||
$result = secp256k1_xonly_pubkey_to_pubkey($ctx, $pubkey, $xonlyPubKey, $sign); | ||
echo $result . PHP_EOL; | ||
|
||
$serialized = null; | ||
$result = secp256k1_ec_pubkey_serialize($ctx, $serialized, $pubkey, SECP256K1_EC_COMPRESSED); | ||
echo $result . PHP_EOL; | ||
|
||
echo bin2hex($serialized) . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
1 | ||
secp256k1_xonly_pubkey | ||
1 | ||
1 | ||
0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c |
55 changes: 55 additions & 0 deletions
55
secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_basic.phpt
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,55 @@ | ||
--TEST-- | ||
secp256k1_xonly_pubkey_tweak_add works | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN|SECP256K1_CONTEXT_VERIFY); | ||
|
||
$pubkey1 = null; | ||
$pubkey2 = null; | ||
$pubKey1Out = null; | ||
$pubKey2Out = null; | ||
$tweakedPub = null; | ||
$tweakTwo = str_repeat("\x00", 31) . "\x02"; | ||
$privKey1 = str_repeat("\x42", 32); | ||
//02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619 | ||
$privKey2 = str_repeat("\x42", 31) . "\x44"; | ||
|
||
$result = secp256k1_xonly_pubkey_create($ctx, $pubkey1, $privKey1); | ||
echo $result . PHP_EOL; | ||
echo get_resource_type($pubkey1) . PHP_EOL; | ||
|
||
$result = secp256k1_xonly_pubkey_create($ctx, $pubkey2, $privKey2); | ||
echo $result . PHP_EOL; | ||
echo get_resource_type($pubkey2) . PHP_EOL; | ||
|
||
|
||
$result = secp256k1_xonly_pubkey_tweak_add($ctx, $tweakedPub, $pubkey1, $tweakTwo); | ||
echo $result . PHP_EOL; | ||
|
||
$result = secp256k1_ec_pubkey_serialize($ctx, $pubKey1Out, $tweakedPub, SECP256K1_EC_COMPRESSED); | ||
echo $result . PHP_EOL; | ||
|
||
$result = secp256k1_xonly_pubkey_serialize($ctx, $pubKey2Out, $pubkey2); | ||
echo $result . PHP_EOL; | ||
|
||
if (substr($pubKey1Out, 1) === $pubKey2Out) { | ||
echo "public keys equal"; | ||
} else { | ||
echo bin2hex($pubKey1Out)." !== ".bin2hex($pubKey2Out)."\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
1 | ||
secp256k1_xonly_pubkey | ||
1 | ||
secp256k1_xonly_pubkey | ||
1 | ||
1 | ||
1 | ||
public keys equal |
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 @@ | ||
--TEST-- | ||
secp256k1_xonly_pubkey_tweak_verify works | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN|SECP256K1_CONTEXT_VERIFY); | ||
|
||
$pubkey1 = null; | ||
$pubKey1Out = null; | ||
$tweakedPub = null; | ||
$tweak = hex2bin("3e10c475efefd59fc14d56706902ef73d5759191065a4c286d4054ed5b6f8258"); | ||
$tweakInvalid = hex2bin("1c5bcae8f25cfff40a3cfb29bc59ed97d67e870f60c424aea12ea109696d373a"); | ||
$privKey1 = str_repeat("\x42", 32); | ||
//02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619 | ||
|
||
$result = secp256k1_xonly_pubkey_create($ctx, $pubkey1, $privKey1); | ||
echo $result . PHP_EOL; | ||
echo get_resource_type($pubkey1) . PHP_EOL; | ||
|
||
$result = secp256k1_xonly_pubkey_tweak_add($ctx, $tweakedPub, $pubkey1, $tweak); | ||
echo $result . PHP_EOL; | ||
|
||
$result = secp256k1_xonly_pubkey_tweak_verify($ctx, $tweakedPub, $pubkey1, $tweakInvalid); | ||
echo $result.PHP_EOL; | ||
|
||
$result = secp256k1_xonly_pubkey_tweak_verify($ctx, $tweakedPub, $pubkey1, $tweak); | ||
echo $result.PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
1 | ||
secp256k1_xonly_pubkey | ||
1 | ||
0 | ||
1 |
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