Author

Topic: Bitcoin SCI [PHP]: process transactions yourself! (addresses gen, IPN, QR Codes) (Read 15646 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.
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
Nice work, even though I'm not entirely sure what a compressed key is.

But as I said most of that bitcoin.lib.php file wasn't made by me.

It is a very useful library though with the functions I added to it.

You can create a thread about it if you like, but I don't think it's necessary.
sr. member
Activity: 426
Merit: 250
Wow, your bitcoin.lib.php is really usefull and should alomst get a topic for itself!

Thank you very much!
Again: I really think your bitcoin.lib.php should have a topic on its own as I find it really helpfull. If you ever do, here is a little contribution of my own.

I have added these functions for compressed key handling:


Quote
  public static function privKeyToPubCompKey($privKey) {

    $g = SECcurve::generator_secp256k1();

        $privKey = self::decodeHex($privKey);
        $secretG = Point::mul($privKey, $g);

        $xHex = self::encodeHex($secretG->getX());
        $y = $secretG->getY();
        if (bcmod($y,2)){
                $pre = "03";
        } else {
                $pre = "02";
        }

        $xHex = str_pad($xHex, 64, '0', STR_PAD_LEFT);
        return $pre.$xHex;
  }

  public static function privKeyToCompAddress($privKey) {

        $pubKey = self::privKeyToPubCompKey($privKey);
        $pubAdd = self::pubKeyToAddress($pubKey);

        if (self::checkAddress($pubAdd)) {
          return $pubAdd;
        } else {
          return 'invalid pub address';
        }
  }


 public static function privKeyToCompWIF($privKey) {
    return self::hash160ToAddress($privKey, '80',true);
  }

 public static function CompWIFtoPrivKey($WIF) {
        return substr(self::addressToHash160($WIF),0,-2);
  }


And I changed this function:

Quote
public static function hash160ToAddress($hash160, $addressversion = BITCOIN_ADDRESS_VERSION,$compressed=false) {
        if($compressed){
                $hash160 = $addressversion . $hash160 . "01";
        }else{
                $hash160 = $addressversion . $hash160;
        }
    $check = @pack("H*", $hash160);
    $check = hash("sha256", hash("sha256", $check, true));
    $check = substr($check, 0, Cool;
        $hash160 = strtoupper($hash160 . $check);
    return self::encodeBase58($hash160);
  }

sr. member
Activity: 426
Merit: 250
Wow, your bitcoin.lib.php is really usefull and should alomst get a topic for itself!

Thank you very much!
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
is there a tutorial for how to set this up???
There isn't at the moment but I plan to make a short video overview/walkthrough soon. It should be released within a few weeks.
newbie
Activity: 47
Merit: 0
is there a tutorial for how to set this up???
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
Ok folks I just fixed another critical but rather uncommon bug which some times happened when converting private keys to bitcoin addresses. It was somewhat similar to the last bug, some hex values needed to be padded with '0' if less than 64 characters long. I took me a while to even notice this bug so I hope it hasn't affected anyone. I lost a few BTC because of it.  Cry

But I am now fairly certain the address generation and conversion functionality is totally bug free so that's a plus.
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
What was the problem?  How crucial is it to make the private key less than the order of the generator?
The problem it seems, was rather trivial. The private key hex string needs to be exactly 64 characters long but some of the keys generated were shorter (smaller number). I solved it by left padding the keys with '0' until 64 characters long. It appears my script was generating valid private keys but I wasn't padding the hex string properly when they were too small. The bitcoin address is generated via hashing and so it seems if you don't pad the private key correctly you'll still get a valid looking bitcoin address but the private key you have isn't the right one for that bitcoin address. Adding in that padding causes the hashing algorithm to output a totally different bitcoin address.
legendary
Activity: 1204
Merit: 1002
RUM AND CARROTS: A PIRATE LIFE FOR ME
I just found this, and I'll be sure to look at it in the next week. Sounds great, nice to hear that the problems with Key generation have been solved, but it does raise a question- why not include in the script a function to double check all generated keys to ensure they are valid?

you never know. :-)
sr. member
Activity: 448
Merit: 254
Another important update: I recently noticed that the private key generation wasn't producing valid private keys most of the time. I overlooked this problem because the public keys generated from those private keys seemed to be perfectly valid 100% of the time. It wasn't until I tried to import some of those keys into my StrongCoin eWallet account that I noticed the problem with the private keys (admittedly I should have tried importing the private keys earlier). Since this thread died out relatively quickly I assume not many people actually tested this script or took the time to look over the functions as I asked, otherwise I'm sure someone would have noticed this problem. So I hope it didn't cause anyone to loose any bitcoins, and I'm very sorry if this has caused you any inconveniences. Rest assured the problem appears to be completely fixed now and all private keys generated are valid. I also made a bunch of other small updates to the script if you want to test it out (such as support for blockchain.info). I can only make it better and weed out the bugs if people are willing to try it and provide me with feedback.

What was the problem?  How crucial is it to make the private key less than the order of the generator?
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
Another important update: I recently noticed that the private key generation wasn't producing valid private keys most of the time. I overlooked this problem because the public keys generated from those private keys seemed to be perfectly valid 100% of the time. It wasn't until I tried to import some of those keys into my StrongCoin eWallet account that I noticed the problem with the private keys (admittedly I should have tried importing the private keys earlier). Since this thread died out relatively quickly I assume not many people actually tested this script or took the time to look over the functions as I asked, otherwise I'm sure someone would have noticed this problem. So I hope it didn't cause anyone to loose any bitcoins, and I'm very sorry if this has caused you any inconveniences. Rest assured the problem appears to be completely fixed now and all private keys generated are valid. I also made a bunch of other small updates to the script if you want to test it out (such as support for blockchain.info). I can only make it better and weed out the bugs if people are willing to try it and provide me with feedback.
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
Update: I've extended the script so that it will also display addresses as QR Codes (by using the javascript library from ecdsa.org).

It also uses AJAX instead of meta refresh. It may be buggy in some really crap browsers like the PSP browser.

I also updated the OP with a screen and changed the thread title a little bit.
legendary
Activity: 1386
Merit: 1097
What parameters are sent together with the callback and in what form?

Generally: Input addresses, output addresses (where one of output address is subscribed one) and transferred amount. I want to provide information in high level form, so there won't be any advanced parsing necessary. Please note that this particular method isn't implemented yet, I'm working on blockchain indexing right now.

I also added example of expected HTTP response to the subscription call.
donator
Activity: 308
Merit: 250
Good point. I'll get around to it when I have more time. Can you recommend some alternative sites?

Yes, I hope that Stratum will be reasonable choice in few days :-).

Quote
That seems like it would be way over my head.

Come on, it's not so hard as it looks from reading "formal specification". This is full example of subscribing events (incoming transactions) for any given Bitcoin address (callback will expire in X-Session-Timeout second, whill will be presented in HTTP response, but can be prolonged by another call):

Code:
POST / HTTP/1.1
Host: stratum.bitcoin.cz
Connection: close
Content-Type: application/stratum
Content-Length: 81
X-Callback-Url: http://yourdomain.com/callback.php

{"id": 1, "method": "blockchain.address.subscribe", "params": ["1YourAddress"]}

(Note: there must be newline ("\n") on the end of every JSON command).

After this call, URL http://yourdomain.com/callback.php will be called everytime there will be some event on 1YourAddress.

Doesn't look so difficult, does it? ;-)

What parameters are sent together with the callback and in what form?
legendary
Activity: 1386
Merit: 1097
Good point. I'll get around to it when I have more time. Can you recommend some alternative sites?

Yes, I hope that Stratum will be reasonable choice in few days :-).

Quote
That seems like it would be way over my head.

Come on, it's not so hard as it looks from reading "formal specification". This is full example of subscribing events (incoming transactions) for any given Bitcoin address (callback will expire in X-Session-Timeout second, whill will be presented in HTTP response, but can be prolonged by another call):

Code:
POST / HTTP/1.1
Host: stratum.bitcoin.cz
Connection: close
Content-Type: application/stratum
Content-Length: 81
X-Callback-Url: http://yourdomain.com/callback.php

{"id": 1, "method": "blockchain.address.subscribe", "params": ["1YourAddress"]}

(Note: there must be newline ("\n") on the end of every JSON command).

Expected response:
Code:
HTTP/1.1 200 OK
Content-Length: 36
X-Session-Timeout: 3600
Server: Stratum/0.1
X-Content-Sha256: fe2a156e058307b4b7782e0b236cbd631c5bce3091f8800f818c91fcb850bfc3
Connection: close
Date: Fri, 06 Jan 2012 12:36:17 GMT
Content-MD5: b0d24c6c203d57e8a998be226a16a3c1
Content-Type: application/stratum
Set-Cookie: STRATUM_SESSION=e6ad15c26f0fe711ba632a7978a3ab30; Path=/

{"error":null,"id":1,"result":true}

After this call, URL http://yourdomain.com/callback.php will be called everytime there will be some event on 1YourAddress.

Doesn't look so difficult, does it? ;-)

EDIT: Added example of response.
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
Quote
Don't forget that blockexplorer is technically run by private party and it's closed source. Support for alternative sites would be important for the safety.
Good point. I'll get around to it when I have more time. Can you recommend some alternative sites?

Quote
I'm looking exactly to this (handling keys in PHP) for writing PHP client for my Stratum project. Maybe you would be interested in writing API for it? It has basically JSON-RPC interface, with some significant benefits over using blockexplorer.
That seems like it would be way over my head. Even if I could, I don't really have time to help out. Sorry about that. Seems like a very interesting project though.

Quote
With this feature, there's no need for extra buttons like "confirm payment", website can detect incoming transaction by self, providing excellent user experience: Webpage with displayed bitcoin address will have open ajax connection to the website, when website receive notification about new transaction to this particular address, it send that transaction back to webpage over the ajax connection.
Well I was thinking about using AJAX, but I decided not to use any javascript at all so it would be more reliable. With AJAX I could have sent queries to blockexplorer in the background and automated everything. Even if I were to use AJAX, it would be rather pointless to send queries to blockexplorer when the user hasn't even sent the bitcoins; although you could automate it that way. The 'confirm' button simply tells the script that it can start looking for confirmations once the user has sent the payment. It's only one extra button they have to click anyway, and I think it helps to have it there with the cancel button before the confirmation stage.
legendary
Activity: 1386
Merit: 1097
Don't forget that blockexplorer is technically run by private party and it's closed source. Support for alternative sites would be important for the safety.

I'm looking exactly to this (handling keys in PHP) for writing PHP client for my Stratum project. Maybe you would be interested in writing API for it? It has basically JSON-RPC interface, with some significant benefits over using blockexplorer.

Main benefit is that you can actively subscribe for watching some Bitcoin address and Stratum server will push you notification to given URL when something change, in realtime. With this feature, there's no need for extra buttons like "confirm payment", website can detect incoming transaction by self, providing excellent user experience: Webpage with displayed bitcoin address will have open ajax connection to the website, when website receive notification about new transaction to this particular address, it send that transaction back to webpage over the ajax connection. No polling, no extra buttons, seamless integration...

This is still under development (I'm implementing blockchain handling right now), but will be ready in few days. However one Stratum server is already online, so writing client side is already possible.
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
Great! Cheesy
Do you think that it should be easy to add also the support to blockchain.info API ?
Yah it should be simple. Go ahead and do what you like with it.
staff
Activity: 4270
Merit: 1209
I support freedom of choice
Great! Cheesy
Do you think that it should be easy to add also the support to blockchain.info API ?
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
    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
Jump to: