Bit-Wasp / bitcoin-php

Bitcoin implementation in PHP
The Unlicense
1.05k stars 418 forks source link

Verifying signature #532

Closed joaojoyce closed 7 years ago

joaojoyce commented 7 years ago

Hi.

I'm currently verifying a signature in the standard Bitcoin format by doing this:

        $sig = "-----BEGIN BITCOIN SIGNED MESSAGE-----\n$uri\n-----BEGIN SIGNATURE-----\n$signature\n-----END BITCOIN SIGNED MESSAGE-----";

        /** @var CompactSignatureSerializerInterface $compactSigSerializer */
        $compactSigSerializer = EcSerializer::getSerializer(CompactSignatureSerializerInterface::class);
        $serializer = new SignedMessageSerializer($compactSigSerializer);
        $signedMessage = $serializer->parse($sig);

        ........

I couldn't find a better way to get the SignedMessage instance. Is there a better away?

Thank you!

afk11 commented 7 years ago

Unfortunately that's the best way for now. realize it's a bit messy...

afk11 commented 7 years ago

Mostly it's because there are two EcAdapters - one using mdanter/ecc, one using ext-secp256k1. You'll see in the BitWasp\Bitcoin\Crypto namespace there's some public interfaces, and then in Impl you find the specific implementations..

EcSerializer works out what adapter to use and returns the concrete implementation of CompactSignatureSerializerInterface - the default is
\BitWasp\Bitcoin\Crypto\Impl\PhpEcc\Serializer\CompactSignatureSerializer unless you install https://github.com/bit-wasp/secp256k1-php (a PHP extension to a C library)

joaojoyce commented 7 years ago

That's ok. Thank you!