Slowly, but surely, 2023 is closing the gap with 2021. 2024 is going to bring in new wonders... 
|
|
|
I am trying to get a standalone PHP code without any external dependency to generate an Ethereum address/key pair. So I asked OpenAI ChatGPT to write the code for me. I got two different versions from it... Version 1include "keccak.php"; use kornrunner\Keccak;
// Generate a random private key $private_key = bin2hex(openssl_random_pseudo_bytes(32));
// Compute the public key from the private key using elliptic curve cryptography $public_key = '0x'.bin2hex(gmp_export(gmp_mul(gmp_init('0x'.bin2hex(openssl_random_pseudo_bytes(32)), 16), gmp_init('0x'.bin2hex(gmp_powm(gmp_init(2), gmp_init('0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0', 16), gmp_init('0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A1', 16))), 16))));
// Compute the Keccak-256 hash of the public key (as a hex string) $address = '0x' . substr(Keccak::hash(hex2bin(substr($public_key, 2)), 256), -40);
echo "Private key: $private_key<br>"; echo "Address: $address<br>";
Version 2include "keccak.php"; use kornrunner\Keccak;
function generate_ethereum_address() { // Generate a new private key $privateKey = bin2hex(random_bytes(32)); echo "Private Key: " . $privateKey. "<br>";
// Derive the public key from the private key $publicKey = hex2bin('04' . str_pad(gmp_strval(gmp_init(substr($privateKey, 0, 64), 16), 16), 64, '0', STR_PAD_LEFT) . str_pad(gmp_strval(gmp_init(substr($privateKey, 64), 16), 16), 64, '0', STR_PAD_LEFT));
// Generate the Ethereum address from the public key $address = '0x' . substr(Keccak::hash(substr($publicKey, 1), 256), -40);
// Return the Ethereum address return $address; }
// Generate an Ethereum address $address = generate_ethereum_address();
// Output the Ethereum address echo "Address: " . $address. "<br>";
For Keccak, this code is used - https://github.com/kornrunner/php-keccak/blob/main/src/Keccak.phpSample o/p of Version 1 is...Private key: 1941069a40cc71a83b8df773e0b45cdb8aa70b748710c82eace662c07ede4cf8 Address: 0x753215ef5214d2494df5e19dafa5644d034d201c
Sample o/p of Version 2 is...Private key: 1941069a40cc71a83b8df773e0b45cdb8aa70b748710c82eace662c07ede4cf8 Address: 0x753215ef5214d2494df5e19dafa5644d034d201c
Clearly, address generated by both versions are wrong and AI is unable to fix the code. Can any of you please fix it?
|
|
|
I am trying to get a standalone PHP code without any external dependency to generate an Ethereum address/key pair. So I asked OpenAI ChatGPT to write the code for me. I got two different versions from it... Version 1include "keccak.php"; use kornrunner\Keccak;
// Generate a random private key $private_key = bin2hex(openssl_random_pseudo_bytes(32));
// Compute the public key from the private key using elliptic curve cryptography $public_key = '0x'.bin2hex(gmp_export(gmp_mul(gmp_init('0x'.bin2hex(openssl_random_pseudo_bytes(32)), 16), gmp_init('0x'.bin2hex(gmp_powm(gmp_init(2), gmp_init('0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0', 16), gmp_init('0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A1', 16))), 16))));
// Compute the Keccak-256 hash of the public key (as a hex string) $address = '0x' . substr(Keccak::hash(hex2bin(substr($public_key, 2)), 256), -40);
echo "Private key: $private_key<br>"; echo "Address: $address<br>";
Version 2include "keccak.php"; use kornrunner\Keccak;
function generate_ethereum_address() { // Generate a new private key $privateKey = bin2hex(random_bytes(32)); echo "Private Key: " . $privateKey. "<br>";
// Derive the public key from the private key $publicKey = hex2bin('04' . str_pad(gmp_strval(gmp_init(substr($privateKey, 0, 64), 16), 16), 64, '0', STR_PAD_LEFT) . str_pad(gmp_strval(gmp_init(substr($privateKey, 64), 16), 16), 64, '0', STR_PAD_LEFT));
// Generate the Ethereum address from the public key $address = '0x' . substr(Keccak::hash(substr($publicKey, 1), 256), -40);
// Return the Ethereum address return $address; }
// Generate an Ethereum address $address = generate_ethereum_address();
// Output the Ethereum address echo "Address: " . $address. "<br>";
For Keccak, this code is used - https://github.com/kornrunner/php-keccak/blob/main/src/Keccak.phpSample o/p of Version 1 is...Private key: 1941069a40cc71a83b8df773e0b45cdb8aa70b748710c82eace662c07ede4cf8 Address: 0x753215ef5214d2494df5e19dafa5644d034d201c
Sample o/p of Version 2 is...Private key: 1941069a40cc71a83b8df773e0b45cdb8aa70b748710c82eace662c07ede4cf8 Address: 0x753215ef5214d2494df5e19dafa5644d034d201c
Clearly, address generated by both versions are wrong and AI is unable to fix the code. Can any of you please fix it?
|
|
|
If you can not provide the content of 'easybitcoin.php', provide what you exactly get here... Array ( [version] => 1040203 [protocolversion] => 70929 [services] => NETWORK/BLOOM/ [walletversion] => 169900 [balance] => 6000.96068 [zerocoinbalance] => 0 [staking status] => Staking Active [blocks] => 1823565 [timeoffset] => 0 [connections] => 242 [proxy] => [difficulty] => 114235.22515094 [testnet] => [moneysupply] => 1114119657.5589 [keypoololdest] => 1666243740 [keypoolsize] => 99 [paytxfee] => 0 [relayfee] => 0.0001 [errors] => )
|
|
|
Could have been easier to debug by knowing the content of 'easybitcoin.php'. Anyways, try this... require_once('easybitcoin.php');
$bitcoin = new Bitcoin('user','pass','localhost','port');
$getinfo = $bitcoin->getinfo();
print_r($getinfo[staking status]);
|
|
|
Neither this...$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.coingecko.com/api/v3/coins/bitcoin/history?date=29-08-2019&localization=false'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); curl_close($ch); $object = json_decode($response); $usdVal = $object->market_data->current_price->usd; echo $usdVal;
Nor this...ini_set('max_execution_time', 300); $url ='https://api.coingecko.com/api/v3/coins/bitcoin/history?date=29-08-2019&localization=false'; $data = file_get_contents($url); $object = json_decode($data); $usdVal = $object->market_data->current_price->usd; echo $usdVal;
What am I doing wrong? p.s. I could not find a better place to ask this question on BitcoinTalk. So, asking it here. If mods think, it does not fit here, feel free to move.
|
|
|
Try to post the following by replacing p_h_p with php. <?p_h_p echo "Hello World"; ?>
|
|
|
I am using the following PHP code... echo round(($satoshiValue/pow(10,8)),8); When, $satoshiValue = 10000, result is 0.0001 as expected. But, when, $satoshiValue = 10000000, result is 0.10000000000000001. Expected was 0.1 though. Why is this happening? p.s. I could not find a better place to ask this question on BitcoinTalk. So, asking it here. If mods think, it does not fit here, feel free to move.
|
|
|
Given your use case, i.e. daily expenses, both Electrum wallet & Hardware wallet will provide same level of security. This is not true. A hardware wallet is meant to protect your funds against software attacks. It's much, much more difficult to create malware that steals funds from a hardware wallet than it is to steal funds from a hot Electrum client. True. But, malware is not the only attack vector that HW needs to withstand. There are other vectors, like compromised RNG, compromised Firmware etc. exists for HW, which is not there for open source SW. So, one can't really say that a hot wallet on HW is more secure than a hot wallet on SW, just because SW is more susceptible to malware attack.
|
|
|
Bumped, so that more people may get to know about this stuff.
|
|
|
Given your use case, i.e. daily expenses, both Electrum wallet & Hardware wallet will provide same level of security.
Why?
Because, your Hardware wallet is not airgapped. Every now & then you'll have to connect it to the internet.
Why?
Because, first your Hardware wallet needs to update its UTXO set to create a transaction. This requires connection to the internet. Signing can be done offline. Broadcasting can also be done by copying the signed transaction to mobile/laptop. Though, it would often expose it to an internet connected device.
So, unless you are storing your fund on an airgapped Hardware wallet, your are as secured as an Electrum wallet user.
|
|
|
This would be beneficial from the perspective of Global Warming on Planet Earth.
But, will it be technically and financially viable?
Interesting concept. As others have stated above, it is possibly not feasible as of yet. But, in future... 1. When 1 BTC = 1 Million USD or higher, Rocket companies will probably charge in Bitcoin Blocks to place Miner Payloads in the Space/Moon. In fact, for Government backed Mining, Government Space Agencies may charge much less for Government subsidy due to this operation being Environment friendly. 2. If substantial Hash power is parked at the Moon, even 30 second latency might not be much of a downside for 10 minutes block time. If orphaned, Moon miners may still keep building on that chain and eventually outperform Earth miners. 3. When human starts habitat at the Mars, there'll be need of Intergalactic Medium of Exchange. Miners, placed on the Space/Moon, may play a crucial role at that point. Having no/little atmosphere and very low temperature will probably benefit the mining operation.
|
|
|
Removing this as it no longer works.
|
|
|
But how is a system able to recognize this particular payment was done?
Generate unique address for each payment and monitor payment to it. May be you can have a timer running, within which time frame the payment needs to complete. Otherwise you'd stop monitoring that address. What if someone else just bought the same product and sent amount to this wallet?
Address is unique for each payment. So, this confusion will never occur. So would it be necessary to create a new wallet for every payment?
A wallet is a collection of addresses, which can be accessed from the same seed/phrase. You generate new address for each payment. Not wallet. Is this how popular systems work?
Not sure what do you mean by popular. But, this is standard practice. https://btcpayserver.org is an open source implementation of such a payment gateway. Anyone got a better understanding of this?
Hope you understood the basics.
|
|
|
Yes. Below is a step by step way to securely generate a paper wallet using bitaddress.org...1. Download BitAddress.org JS code from https://github.com/pointbiz/bitaddress.org. 2. Run it in an offline computer and generate Address + Private Key. 3. Copy the Address in a text file and write down the Private Key by hand in your notebook. 4. Write the Private Key from your notebook to the text file by typing and run it through BitAddress.org JS code to see whether it generates back the same Address in the text file. 5. Now remove all traces of the Private Key, save the text file with Address and wipe out the temporary cache from your browser. 6. Download Coinb.in JS code from https://github.com/OutCast3k/coinbin/ and use it to sweep fund received at the generated Address.
|
|
|
Example...
SegWit Address: 3Pih1gsGEufDcE3rnCvH7tSGxYCfAumr7N Private Key: L31MGtLmx3RVomrNYkNzJqrd5h788GDkJpT6sTRhSu1rd2ZwWimr
Non-SegWit Address: 3FcdxBkv4Va8YLfyCe11pRsZ2uTki7DWvH Private Key 1: L1QZg6Lqc8pH2RqWuEKzqv3rwjumQ2oMUyp4S8WPnZgWCnXPL4mu Private Key 2: L3Qh439DtmJS1xKEe2tL7KG2niM4FWE6UvdJzs5DwdBqPZc8rrBe Private Key 3: L5dhbsNKyzqPPgTFGe6kUVHibFv5QhoAhLJSVAqgTnyDXVimtm1E
Just looking at these addresses, how do we determine that 3Pih1gsGEufDcE3rnCvH7tSGxYCfAumr7N is SegWit and 3FcdxBkv4Va8YLfyCe11pRsZ2uTki7DWvH is not? And, if we can't determine, how do we decide whether to send SegWit Tx to these addresses or not?
|
|
|
|