Necesito un código PHP para generar direcciones de bitcoin a partir de una clave pública determinada.
Solo puedo encontrar algoritmos para generar direcciones a partir de la clave privada maestra, pero según https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses , la clave privada no es necesaria en absoluto.
Use la biblioteca BitWasp Bitcoin-php https://github.com/Bit-Wasp/bitcoin-php
<?php
use BitWasp\Bitcoin\Bitcoin;
use BitWasp\Bitcoin\Key\PrivateKeyFactory;
$network = Bitcoin::getNetwork();
$privateKey = PrivateKeyFactory::create(true);
$publicKey = $privateKey->getPublicKey();
$address = $publicKey->getAddress(); // returns AddressInterface
echo $address->getAddress($network); // prints address for $network as string
Si desea crear una dirección de Bitcoin a partir de una cadena de clave pública, verifique la documentación para las clases de fábrica
o versiones más nuevas:
<?php
use BitWasp\Bitcoin\Bitcoin;
use BitWasp\Bitcoin\Address\AddressCreator;
use BitWasp\Bitcoin\Key\PrivateKeyFactory;
use BitWasp\Bitcoin\Key\KeyToScript\Factory\P2pkhScriptDataFactory;
$network = Bitcoin::getNetwork();
$privateKey = PrivateKeyFactory::create(true);
$publicKey = $privateKey->getPublicKey();
$addrCreator = new AddressCreator();
$factory = new P2pkhScriptDataFactory();
$scriptPubKey = $factory->convertKey($publicKey)->getScriptPubKey();
$address = $addrCreator->fromOutputScript($scriptPubKey); // returns AddressInterface
echo $address->getAddress($network); // prints address for $network as string
Instrucciones completas basadas en la respuesta de @Farghaly: Ubuntu 16
Instalar dependencias
sudo apt-get install php-bcmath php-gmp
composer require bitwasp/bitcoin
Y luego en el campoapp.php
<?php
require 'vendor/autoload.php';
use BitWasp\Bitcoin\Bitcoin;
use BitWasp\Bitcoin\Address;
use BitWasp\Bitcoin\Key\PrivateKeyFactory;
$network = Bitcoin::getNetwork();
$privateKey = PrivateKeyFactory::create(true);
$publicKey = $privateKey->getPublicKey();
$address = $publicKey->getAddress();
composer install
Wouter
karimkorun