Ich brauche etwas PHP-Code, um Bitcoin-Adressen aus einem bestimmten öffentlichen Schlüssel zu generieren.
Ich kann nur Algorithmen finden, um Adressen aus dem privaten Master-Schlüssel zu generieren, aber laut https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses ist der private Schlüssel überhaupt nicht erforderlich.
Verwenden Sie die BitWasp Bitcoin-php-Bibliothek 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
Wenn Sie eine Bitcoin-Adresse aus der Zeichenfolge des öffentlichen Schlüssels erstellen möchten, überprüfen Sie die Dokumentation für Factory-Klassen
oder neuere Versionen:
<?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
Vollständige Anleitung basierend auf der Antwort von @Farghaly: Ubuntu 16
Abhängigkeiten installieren
sudo apt-get install php-bcmath php-gmp
composer require bitwasp/bitcoin
Und dann im Feldapp.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