bitcoinphp / bitcoinecdsa.php Goto Github PK
View Code? Open in Web Editor NEWPHP library to generate BTC addresses and signatures from private keys.
PHP library to generate BTC addresses and signatures from private keys.
My issue is best explained by examples.
It works if I do it this way:
$bitcoinECDSA = new BitcoinECDSA();
$bitcoinECDSA->generateRandomPrivateKey();
$signedMessage = $bitcoinECDSA->signMessage("Test 1234");
echo $signedMessage . PHP_EOL;
$result = $bitcoinECDSA->checkSignatureForRawMessage($signedMessage);
echo 'Message Signature Valid: ' . ($result ? 'True' : 'False') . PHP_EOL;
Result:
-----BEGIN BITCOIN SIGNED MESSAGE-----
Test 1234
-----BEGIN SIGNATURE-----
1QByU6YzFcUwA5QX759cg2eFhkdTCV7CtW
H/B2dpyiirAV3dW1aqAtyu7KQylz47DyS/GSXo2DLEiiyfFArocW7T6TVss6WXhZDyeu6AraLPrJLju+DXRz6I0=
-----END BITCOIN SIGNED MESSAGE-----
Message Signature Valid: True
If I do this:
$bitcoinECDSA = new BitcoinECDSA();
$signedMessage = "-----BEGIN BITCOIN SIGNED MESSAGE-----" . PHP_EOL;
$signedMessage .= "Test 1234" . PHP_EOL;
$signedMessage .= "-----BEGIN SIGNATURE-----" . PHP_EOL;
$signedMessage .= "1QByU6YzFcUwA5QX759cg2eFhkdTCV7CtW" . PHP_EOL;
$signedMessage .= "H/B2dpyiirAV3dW1aqAtyu7KQylz47DyS/GSXo2DLEiiyfFArocW7T6TVss6WXhZDyeu6AraLPrJLju+DXRz6I0=" . PHP_EOL;
$signedMessage .= "-----END BITCOIN SIGNED MESSAGE-----";
echo $signedMessage . PHP_EOL;
$result = $bitcoinECDSA->checkSignatureForRawMessage($signedMessage);
echo 'Message Signature Valid: ' . ($result ? 'True' : 'False') . PHP_EOL;
I get this:
Fatal error: Uncaught exception 'Exception' with message 'No Private Key was defined'
Okay, so I add to the above:
$bitcoinECDSA->generateRandomPrivateKey();
Fails.
-----BEGIN BITCOIN SIGNED MESSAGE-----
Test 1234
-----BEGIN SIGNATURE-----
1QByU6YzFcUwA5QX759cg2eFhkdTCV7CtW
H/B2dpyiirAV3dW1aqAtyu7KQylz47DyS/GSXo2DLEiiyfFArocW7T6TVss6WXhZDyeu6AraLPrJLju+DXRz6I0=
-----END BITCOIN SIGNED MESSAGE-----
Message Signature Valid: False
What am I doing wrong?
Hi,
Please check the following code from BitcoinECDSA.php line 101
$table = [ '1','2','3','4','5','6','7','8','9','A','B','C','D', 'E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W', 'X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','m','n','o', 'p','q','r','s','t','u','v','w','x','y','z' ];
Why the capital "i" and capital "o" also number zero are missing?
Here's the sample of address: bc1qwjyrqmz07fjatnlzff9hs4qlpdkatpum8aclmc
The library returns: ErrorException: gmp_add(): Unable to convert variable to GMP - wrong type
As far as I understand it's a new format of addresses for BTC
Error: Call to undefined function BitcoinPHP\BitcoinECDSA\getWif()
in: src/BitcoinPHP/BitcoinECDSA/BitcoinECDSA.php
is:
public function getUncompressedWif()
{
return getWif(false);
}
should be:
public function getUncompressedWif()
{
return $this->getWif(false);
}
how can i Send My wallet Balance To another Wallet ?
Hi, im basic. I need to print private and public key. I tried to use $bitcoinECDSA->getPrivateKey();
, buto when i do this, the private key is not for generateg BTC address, but other. Can you help me?
Full code:
`require_once 'src/BitcoinPHP/BitcoinECDSA/BitcoinECDSA.php';
use BitcoinPHP\BitcoinECDSA\BitcoinECDSA;
$bitcoinECDSA = new BitcoinECDSA();
$bitcoinECDSA->generateRandomPrivateKey(); //generate new random private key
$address = $bitcoinECDSA->getAddress(); //compressed Bitcoin address
$p = $bitcoinECDSA->getPrivateKey();
echo "Address: " . $address . PHP_EOL;//Validate an address (Verify the checksum)
if($bitcoinECDSA->validateAddress($address)) {
echo "The address is valid" . PHP_EOL;
print $p . "
";
} else {
echo "The address is invalid" . PHP_EOL;
}`
The library doesn't supports this case yet.
see http://crypto.stackexchange.com/a/16441 for more details.
Hi
Would it be possible to have a fallback from gmp to for exaple using https://github.com/brick/math ?
Gmp is not enabled by default and usually impossible or hard to enable on a shared hosting.
Hi,
I'm working on a project where I'd be using your codebase :)
I was wondering if it can be tweaked for LTC addresses?
My use-case is to convert hexa private key to wallet address
In BitcoinECDSA.php on line 149, there is rand() with parameters 100000000000 and 1000000000000. Everything is okay on 64bit systems, but on 32bit systems, those ints overflow and they become float which causes that no number is generated. Possible solution is to use constant PHP_INT_MAX and generate this random number in range which is supported on current system.
Thanks for the code!
when I print signHash()
Result length is 140,
but when use Python (import ecdsa) Result length is 128
Is this code can do like Python to print result length just 128?
Here are the details of the wallet:
ADDRESS : 1GRTPtfbTk2oTfnrDhXajvmCHpEeJxWr7H
WIF : nvcAtj5QiQprwWQk6LW6gDVMxQGmvJsXjZU5qmndRjL83ZJGEK5
Private Key : ba24185ce261850993e13ff7f0ad2ab01d418b0f48534880ea33e304cb388b9d
When I am entering or scanning the qr code for WIF, the mycelium wallet app is not detecting it as valid.
I imported the Private Key in blockchain.info wallet, it was a success. Then I generated the WIF from their interface, the WIF generated was different:
L3TYYUQPQ6FjP2sCkfUjF48JP2jKRYwZJTJNaoB8tFfisYYmNJHp
and mycelium could read this format successfully.
What am I missing? Thanks.
Hi,
I'm getting different results with getAddress() when using compressed and uncompressed private keys.
compressed bitcoin address: 155NQk5psqEsDjfbYV5iWhGpVhm3GeLYBs
$key uncompressed: 5Hpepo99cdVV4xhMFUYteoHzW7M5hdccMmMpniKa11wNsUhxqfi
$key compressed: KwFKwxey2G4itUq6NtbkyqKzoV1dkLcB4enuvmNxf591XjhLzdCe
$bitcoinECDSA->setPrivateKeyWithWif($key);
$address = $bitcoinECDSA->getAddress();
echo $address;
Result for uncompressed key:
155NQk5psqEsDjfbYV5iWhGpVhm3GeLYBs (correct)
Result for compressed key:
1PShnSX6kerVFkC8MhuLwL1uhxL2aCBsJt (wrong)
Hi! It would be super useful if you implemented a method to support Diffie Hellman. That is, given one keypair's public key and another keypair's private key, multiplying the two yields a very useful symmetric key.
Hi, this is the only script that works immediately, without a composer installation and that is small and clear (all other scripts are massive, messy to read, and use 300+ files).
The only thing is that the generated address are not bech32 and so fees on such addresses are much higher.
HI,
I try the follow the url not getting correct value.
https://blockchain.info/de/q/addressbalance/1NjMT4p8Chz6XEyhp8cXCzTwU5ZG3xjFfp .
I know its unfinished but I would just like to say, good stuff!
I was thinking of doing something similar but you seem to be on the right track, looking forward to WIF, verify message and sign message completion.
hi,
line code 912 shows getwif as undefined function
public function getUncompressedWif()
{
return getWif(false);
}
Thanks for this module, you've done amazing work with it!
We're receiving the above warning when a user attempts to validate a CashAddr formatted address with this module, I'd guess due to the presence of non-base58 characters. Could the module detect this and throw a catchable Exception before gmp throws a warning? Happy to raise a pull request if you're happy with that!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.