Pages:
Author

Topic: Bitcoin SCI [PHP]: process transactions yourself! (addresses gen, IPN, QR Codes) (Read 15625 times)

newbie
Activity: 18
Merit: 0
Hi, thanks for publishing the script.

Can you tell me where to implement actions if payment was successfull?

I added an action in check-status.php after line 111..
Code:
$payment_status = 'payment verified!';

.. but it's not working.

Would be great if you could help me.

Best regards
legendary
Activity: 1064
Merit: 1000
There is a pretty good PHP bitcoin library project here https://github.com/Bit-Wasp/bitcoin-lib-php/ which relies on https://github.com/mdanter/phpecc

The projects are also well maintained.
full member
Activity: 168
Merit: 100
I always receive the error "*** Invalid Ciphertext ***" if I am trying to decrypt my private keys. This even happens when I am resetting the wif-keys file. Can you please tell me how to fix this?

Thanks!
legendary
Activity: 1064
Merit: 1000
    This is a little project I've been working on for the last few days. I first came up with this idea here: PHP script to create private key & public address. It was hard to find a decent Elliptic Curve library for PHP but eventually I came across this on a blog: Elliptic Curve PHP-OOP DSA and Diffie-Hellman. The library only came with a set of NIST curves so I had to create a set of SEC curves using the parameters supplied in sec2_final.pdf.

Then to convert the keys into bitcoin addresses I basically followed the instructions on this page: Technical background of version 1 Bitcoin addresses. I found that many of these steps had already been coded in PHP: bitcoin-php - Bitcoin utility functions. I did a lot of testing with it and it seems to generate valid bitcoin addresses each time, I even sent coins to one of the addresses generated in PHP and it worked fine. However, I am far from an expert on cryptography so please check the code and let me know if you see any problems.

If you have time, take a look at the bitcoin.lib.php file and check the following functions for problems. The mini key functions aren't really used for anything at this point, I just coded them because it seemed like a good idea at the time.

getNewPrivKey()
getNewKeyPair()
getNewKeySet()
privKeyToAddress($privKey)
privKeyToWIF($privKey)
checkMiniKey($miniKey)
getNewMiniKey()
miniKeyToWIF($miniKey)
miniKeyToAddress($miniKey)

The other part of this script is the Bitcoin Payment Gateway. Instead of passing the transaction through to a 3rd party for processing, payments are verified simply by using blockexplorer to monitor the status of a payment to a specified address. There's no need to install bitcoind on your server, everything is done in pure PHP. This script essentially enables you to have your own Payment Notification System without the need for a middleman (except blockchain.info/blockexplorer.com), very safe imo, and another amazing feature of bitcoin. This is the description from my website:

Quote
The Bitcoin Shopping Cart Interface package is a set of libraries and tools that enable you to process bitcoin transactions with only PHP. You can have your own Instant Payment Notification system without the need for a middleman. If you've been wondering how to handle customer payment since MyBitcoin went down, look no further, because this is the safest solution.

An elliptic curve library written in PHP is used to achieve server side generation of FRESH bitcoin addresses for each customer. The script monitors the status of a payment by making use of the data supplied by blockexplorer.com. As such, there is no need to install a heavy duty service such as bitcoind on your server. The only limitation with this PHP package is that you can't make outgoing payments.

The SCI package comes with a simple example to give you an idea about how to generate new keys and initiate a new payment through the Bitcoin Payment Gateway. This is NOT full shopping cart software, you would typically use this script to offer Bitcoins as one method of payment. Some of the Bitcoin SCI scripts (in the 'sci' folder) need to be modified to work properly on your website.

Info: Bitcoin SCI: process bitcoin transactions with PHP

Download: Bitcoin SCI

Demo: BitShop Integration

Is there any chance you could relicense the code as LGPL? As a library it should be LGPL rather than GPL or it reduces what can use it a lot.
sr. member
Activity: 252
Merit: 250
    This is a little project I've been working on for the last few days. I first came up with this idea here: PHP script to create private key & public address. It was hard to find a decent Elliptic Curve library for PHP but eventually I came across this on a blog: Elliptic Curve PHP-OOP DSA and Diffie-Hellman. The library only came with a set of NIST curves so I had to create a set of SEC curves using the parameters supplied in sec2_final.pdf.

Then to convert the keys into bitcoin addresses I basically followed the instructions on this page: Technical background of version 1 Bitcoin addresses. I found that many of these steps had already been coded in PHP: bitcoin-php - Bitcoin utility functions. I did a lot of testing with it and it seems to generate valid bitcoin addresses each time, I even sent coins to one of the addresses generated in PHP and it worked fine. However, I am far from an expert on cryptography so please check the code and let me know if you see any problems.

If you have time, take a look at the bitcoin.lib.php file and check the following functions for problems. The mini key functions aren't really used for anything at this point, I just coded them because it seemed like a good idea at the time.

getNewPrivKey()
getNewKeyPair()
getNewKeySet()
privKeyToAddress($privKey)
privKeyToWIF($privKey)
checkMiniKey($miniKey)
getNewMiniKey()
miniKeyToWIF($miniKey)
miniKeyToAddress($miniKey)

The other part of this script is the Bitcoin Payment Gateway. Instead of passing the transaction through to a 3rd party for processing, payments are verified simply by using blockexplorer to monitor the status of a payment to a specified address. There's no need to install bitcoind on your server, everything is done in pure PHP. This script essentially enables you to have your own Payment Notification System without the need for a middleman (except blockchain.info/blockexplorer.com), very safe imo, and another amazing feature of bitcoin. This is the description from my website:

Quote
The Bitcoin Shopping Cart Interface package is a set of libraries and tools that enable you to process bitcoin transactions with only PHP. You can have your own Instant Payment Notification system without the need for a middleman. If you've been wondering how to handle customer payment since MyBitcoin went down, look no further, because this is the safest solution.

An elliptic curve library written in PHP is used to achieve server side generation of FRESH bitcoin addresses for each customer. The script monitors the status of a payment by making use of the data supplied by blockexplorer.com. As such, there is no need to install a heavy duty service such as bitcoind on your server. The only limitation with this PHP package is that you can't make outgoing payments.

The SCI package comes with a simple example to give you an idea about how to generate new keys and initiate a new payment through the Bitcoin Payment Gateway. This is NOT full shopping cart software, you would typically use this script to offer Bitcoins as one method of payment. Some of the Bitcoin SCI scripts (in the 'sci' folder) need to be modified to work properly on your website.

Info: Bitcoin SCI: process bitcoin transactions with PHP

Download: Bitcoin SCI

Demo: BitShop Integration

I am testing this out now, this is great, smart move you made here, will fork around with it some more..
newbie
Activity: 24
Merit: 0
Quote
Try generating a new RSA key set and make sure you copy the full private RSA key properly and also make sure you save the full public RSAkey into the sci/config.php file.

The private RSA key is simply used for encryption, it's not a private key for Bitcoin. When you solve the invalid ciphertext problem you'll get the private keys you need.

Hi bitfreak!,

you're right with your analysis above. After repeating the mentioned steps I can now properly generate the private key for Bitcoin. Great!
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
No a new address must be generated each time because they need to start with an empty balance in order to detect payments. It's difficult, if not impossible, to determine who has paid what when you're using a single address to receive all payments.
newbie
Activity: 24
Merit: 0
Hello bitfreak!,

OK, understand, thanks.

Then another aspect of the usage: I really want to use this script for a donation purpose. For this purpose I would not need new adresses for any transaction, just one receiveing address for all. So could I "hardcode" this one adress somewhere in the code and then disable the address generation?

BTW: I found the version number in the config.php file at the bottom...
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
@thonglor: sorry I thought you were using the BitShop script. Those instructions only apply to the BitShop script. But your problem will be the same thing; you didn't copy the RSA keys properly. With this SCI script you'll have to decrypt each key separately, I don't think I included a function to decrypt them all at once. Ideally you should be saving the keys into a database and then building your own admin area based on the simple admin area I included with this script. It really isn't intended to be used as it is, it's supposed to be integrated with your projects and you should have a good knowledge of PHP to edit it.

As for how to import the decrypted private keys into your bitcoin wallet, see this page:
https://en.bitcoin.it/wiki/How_to_import_private_keys_v7%2B
newbie
Activity: 24
Merit: 0
I asked the same question. Here the reply:

Quote
-clicking on the "(decrypt)" besides Private Key: what needs to be entered in the upcoming dialogue? If I enter the private key generated in the beginning I get "*** Invalid Ciphertext ***"?
Many people seem to have this problem and every single time it turns out to be that they didn't copy the private RSA key properly when they generated it. Try generating a new RSA key set and make sure you copy the full private RSA key properly and also make sure you save the full public RSAkey into the sci/config.php file. Watch the installation tutorial video if you need more help figuring it out. If you sent any money to those addresses then I'm afraid you may have lost it unless you can get your existing RSA keys to work.

Quote
-and now there is the Bitcoin address for each transaction. How to get this BTC transferred somewhere? Importing the private key generated in the beginning into an Armory wallet does not work.
The private RSA key is simply used for encryption, it's not a private key for Bitcoin. When you solve the invalid ciphertext problem you'll get the private keys you need.

For importing your keys into a blockchain.info wallet:

1. Login to admin area
2. Got to Orders
3. Select MANAGE KEYS
4. Select EXPORT KEYS
5. Input private RSA key when prompted
6. Scroll down and copy text from "Blockchain.info Format" box
7. Log into Blockchain.info wallet
8. Select "Import / Export" from top menu
9. Select "Import Wallet" from side menu
10. Paste text from step 6 into box and select "Import Wallet"
qrs
newbie
Activity: 47
Merit: 0
this script is great, I love it, when I will be rich I will donate you every day, bitfreak!

one question, I have working script on my site and now have few keys in wif-keys.csv file - what now? how to get BTC to my own wallet?

http://img713.imageshack.us/img713/3439/qi20.jpg
sr. member
Activity: 412
Merit: 287
I've written some code based on Bitcoin SCI, to back up live wallets once the balances exceed a certain amount. So far my work has only really touched the testnet. I've found the PHPECC class returns a keypair which allows valid bitcoin addresses to be derived (bitcoind's validateaddress function confirms this is OK), and have been successful in sending funds to one of these addresses.. However I can't import the private key?

Output from backup script:
Code:
Main Wallet Backup
------ 16 October 2013 10pm
Balance: BTC 0.0003
Bitcoin Address: mm5SSxdLbMV6yN59koD5kGUezgbaQbBEGE
Transaction ID: c507000c4ead8397337fdd93979b98df6759f938550e09bc0d4985e1e2cb4599
Private Key: 0017DDEEC21A492AD5D22046C890327C95ACFB290587F065BBDC19A35D128EDD
WIF Format: 4imfxryzuMUsrB4T7p48fBcBHhyiv624qkXdJBRUaLz5N3hg227

Testing:
Code:
~/bitcoin-0.8.5-linux/bin$ ./bitcoind importprivkey 0017DDEEC21A492AD5D22046C890327C95ACFB290587F065BBDC19A35D128EDD
error: {"code":-5,"message":"Invalid private key"}

~/bitcoin-0.8.5-linux/bin$ ./bitcoind importprivkey 4imfxryzuMUsrB4T7p48fBcBHhyiv624qkXdJBRUaLz5N3hg227
error: {"code":-5,"message":"Invalid private key"}

~/bitcoin-0.8.5-linux/bin$ ./bitcoind validateaddress mm5SSxdLbMV6yN59koD5kGUezgbaQbBEGE
{
    "isvalid" : true,
    "address" : "mm5SSxdLbMV6yN59koD5kGUezgbaQbBEGE",
    "ismine" : false
}
hero member
Activity: 907
Merit: 1003
I need to be able to send BTC payments too. Is this possible with your code?
No it's not because with this script. In order to send payments to another address using PHP you will probably need to have bitcoind installed on your server. I don't really think this is any easier way but I could be wrong.
Ok thanks
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
I need to be able to send BTC payments too. Is this possible with your code?
No it's not with this script. In order to send payments to another address using PHP you will probably need to have bitcoind installed on your server. I don't really think there is any easier way but I could be wrong.
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
Bitfreak website is now back online.
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
I'm having some issues with my web host at the moment but my website should be back online within a day or two. Sorry for the inconvenience.
full member
Activity: 224
Merit: 100
You can't kill math.
If you have problems with __autoload already declared, then open bitcoin.lib.php and remove the autoload include and include the ecc-lib files manually.

Replace this:

Code:
/**
* Bitcoin utility functions class (extended for sci lib)
*
* @author theymos (functionality)
* @author Mike Gogulski (http://www.gogulski.com/)
* @author Jacob Bruce (private/public/mini key generation)
* (encapsulation, string abstraction, PHPDoc)
*/
require_once(dirname(__FILE__).'/ecc-lib/auto_load.php');
define("BITCOIN_ADDRESS_VERSION""00");// this is a hex byte

class bitcoin {

With this:

Code:
/**
* Bitcoin utility functions class (extended for sci lib)
*
* @author theymos (functionality)
* @author Mike Gogulski (http://www.gogulski.com/)
* @author Jacob Bruce (private/public/mini key generation)
* (encapsulation, string abstraction, PHPDoc)
*/

set_time_limit(7200);

if(
extension_loaded('gmp') && !defined('USE_EXT')){
    
define ('USE_EXT''GMP');
}else if(
extension_loaded('bcmath') && !defined('USE_EXT')){
    
define ('USE_EXT''BCMATH');
}

require_once(
dirname(__FILE__).'/ecc-lib/classes/interface/PointInterface.php');
require_once(
dirname(__FILE__).'/ecc-lib/classes/interface/PrivateKeyInterface.php');
require_once(
dirname(__FILE__).'/ecc-lib/classes/interface/PublicKeyInterface.php');
require_once(
dirname(__FILE__).'/ecc-lib/classes/interface/SignatureInterface.php');
require_once(
dirname(__FILE__).'/ecc-lib/classes/interface/CurveFpInterface.php');
require_once(
dirname(__FILE__).'/ecc-lib/classes/NumberTheory.php');
require_once(
dirname(__FILE__).'/ecc-lib/classes/CurveFp.php');
require_once(
dirname(__FILE__).'/ecc-lib/classes/SECcurve.php');
require_once(
dirname(__FILE__).'/ecc-lib/classes/Point.php');
require_once(
dirname(__FILE__).'/ecc-lib/classes/PrivateKey.php');
require_once(
dirname(__FILE__).'/ecc-lib/classes/PublicKey.php');
require_once(
dirname(__FILE__).'/ecc-lib/classes/Signature.php');
require_once(
dirname(__FILE__).'/ecc-lib/classes/util/bcmath_Utils.php');

define("BITCOIN_ADDRESS_VERSION""00");// this is a hex byte

class bitcoin {
member
Activity: 88
Merit: 10
Anyone has a clue why i'm always gettin "*** Invalid Ciphertext ***" on the "http://127.0.0.1/sci/admin.php?page=keys#" page?
Tought it was sommething with $sec_str but im not shure as i have tried what ever i could think of.
Never mind, forgot to remove old wif keys.
member
Activity: 88
Merit: 10
Anyone has a clue why i'm always gettin "*** Invalid Ciphertext ***" on the "http://127.0.0.1/sci/admin.php?page=keys#" page?
Tought it was sommething with $sec_str but im not shure as i have tried what ever i could think of.
sr. member
Activity: 426
Merit: 250
Compressed keys are used since version 0.6 iirc. They take up less space in the blockchain, but they also require a new wallet input format.

With new clients, when you do a dumpprivkey, you will see that the private WIF won't start with a 5.
Pages:
Jump to: