<commit_before><?php

namespace BitWasp\Secp256k1Tests;

class Secp256k1EcdsaSignCompactTest extends TestCase
{
    public function testSignCompact()
    {
        $key = $this->toBinary32('404630ea0d36ec5fe8b036139872789bee54246233d9529661ccaf976f02904a');
        $msg = $this->toBinary32('03acc83ba10066e791d51e8a8eb90ec325feea7251cb8f979996848fff551d13');

        $sig = '';
        $recid = 0;

        $this->assertEquals(1, secp256k1_ecdsa_sign_compact(TestCase::getContext(), $msg, $key, $sig, $recid));

        $this->assertEquals('ebbf6d178d0d44ae8c2e42a52153199bfe9f33aa89eed264493e9ef965ee519840b4fe3bd58fa89eb65352eb969aaa7e309bd9d0eae6fe10695f4e7d10f1fd8e', bin2hex($sig));
        $this->assertEquals(1, $recid);
    }

    public function testRandomSign()
    {
        $context = TestCase::getContext();
        for ($i = 0; $i < 5; $i++) {
            $compressed = ($i%2==0);
            $private = $this->getPrivate();
            $publicKey = '';
            $this->assertEquals(1, secp256k1_ec_pubkey_create($context, $private, $compressed, $publicKey));

            $msg = hash('sha256', $i, true);
            $sig = '';
            $recid = 0;
            $this->assertEquals(1, secp256k1_ecdsa_sign_compact($context, $msg, $private, $sig, $recid));

            $byte = 27 + $recid + ($compressed ? 4 : 0);
            $byteHex = str_pad(dechex($byte), 2, '0', STR_PAD_LEFT);
            $bin = hex2bin($byteHex) . $sig;<commit_msg>Use \hex2bin - not sure why travis doesn't know this function?<commit_after><?php

namespace BitWasp\Secp256k1Tests;

class Secp256k1EcdsaSignCompactTest extends TestCase
{
    public function testSignCompact()
    {
        $key = $this->toBinary32('404630ea0d36ec5fe8b036139872789bee54246233d9529661ccaf976f02904a');
        $msg = $this->toBinary32('03acc83ba10066e791d51e8a8eb90ec325feea7251cb8f979996848fff551d13');

        $sig = '';
        $recid = 0;

        $this->assertEquals(1, secp256k1_ecdsa_sign_compact(TestCase::getContext(), $msg, $key, $sig, $recid));

        $this->assertEquals('ebbf6d178d0d44ae8c2e42a52153199bfe9f33aa89eed264493e9ef965ee519840b4fe3bd58fa89eb65352eb969aaa7e309bd9d0eae6fe10695f4e7d10f1fd8e', bin2hex($sig));
        $this->assertEquals(1, $recid);
    }

    public function testRandomSign()
    {
        $context = TestCase::getContext();
        for ($i = 0; $i < 5; $i++) {
            $compressed = ($i%2==0);
            $private = $this->getPrivate();
            $publicKey = '';
            $this->assertEquals(1, secp256k1_ec_pubkey_create($context, $private, $compressed, $publicKey));

            $msg = hash('sha256', $i, true);
            $sig = '';
            $recid = 0;
            $this->assertEquals(1, secp256k1_ecdsa_sign_compact($context, $msg, $private, $sig, $recid));

            $byte = 27 + $recid + ($compressed ? 4 : 0);
            $byteHex = str_pad(dechex($byte), 2, '0', STR_PAD_LEFT);
            $bin = \hex2bin($byteHex) . $sig;
{'fraction_non_alphanumeric': 0.14232839838492597, 'fraction_numerical': 0.13694481830417227, 'mean_word_length': 3.2230113636363638, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7136508', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1102, 'n_words': 158}