function loadKeys() { $storageEngine = new \Bitpay\Storage\EncryptedFilesystemStorage('YourTopSecretPassword'); $privateKey = $storageEngine->load('/tmp/bitpay.pri'); $publicKey = $storageEngine->load('/tmp/bitpay.pub'); $token_id = file_get_contents('/tmp/token.json'); return array($privateKey, $publicKey, $token_id); }
// not an issue in this case since we have not used this key for // anything yet. /** * Once we have a private key, a public key is created from it. */ $publicKey = new \Bitpay\PublicKey('/tmp/bitpay.pub'); // Inject the private key into the public key $publicKey->setPrivateKey($privateKey); // Generate the public key $publicKey->generate(); // NOTE: You can again do all of this with one line of code like so: // `$publicKey = \Bitpay\PublicKey::create('/tmp/bitpay.pub')->setPrivateKey($privateKey)->generate();` /** * Now that you have a private and public key generated, you will need to store * them somewhere. This optioin is up to you and how you store them is up to * you. Please be aware that you MUST store the private key with some type * of security. If the private key is comprimised you will need to repeat this * process. */ /** * It's recommended that you use the EncryptedFilesystemStorage engine to persist your * keys. You can, of course, create your own as long as it implements the StorageInterface */ $storageEngine = new \Bitpay\Storage\EncryptedFilesystemStorage('YourTopSecretPassword'); $storageEngine->persist($privateKey); $storageEngine->persist($publicKey); /** * This is all for the first tutorial, you can run this script from the command * line `php examples/tutorial/001.php` This will generate and create two files * located at `/tmp/bitpay.pri` and `/tmp/bitpay.pub` */
* * 002 - Pairing * * Requirements: * - Baisic PHP Knowledge * - Private and Public keys from 001.php * - Account on https://test.bitpay.com * - Pairing code */ require __DIR__ . '/../../vendor/autoload.php'; /** * To load up keys that you have previously saved, you need to use the same * storage engine. You also need to tell it the location of the key you want * to load. */ $storageEngine = new \Bitpay\Storage\EncryptedFilesystemStorage('YourTopSecretPassword'); $privateKey = $storageEngine->load('/tmp/bitpay.pri'); $publicKey = $storageEngine->load('/tmp/bitpay.pub'); /** * Create the client, there's a lot to it and there are some easier ways, I am * showing the long form here to show how various things are injected into the * client. */ $client = new \Bitpay\Client\Client(); /** * The network is either livenet or testnet. You can also create your * own as long as it implements the NetworkInterface. In this example * we will use testnet */ $network = new \Bitpay\Network\Testnet(); /**