From a229dfba6c35ed64b31eefa7c13f862381e74e60 Mon Sep 17 00:00:00 2001 From: Marcel Hodan Date: Sun, 11 Apr 2021 15:49:14 +0200 Subject: [PATCH 1/3] change printout to json format --- genkomodo.php | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/genkomodo.php b/genkomodo.php index 4f50111..3a4af92 100644 --- a/genkomodo.php +++ b/genkomodo.php @@ -143,11 +143,15 @@ public function getWIF($compressed = true, $PrivatePrefix = 128) $bitcoinECDSA->setPrivateKey($k); // uncomment the line below if you want to calc everything from WIF, instead of passphrase // $bitcoinECDSA->setPrivateKeyWithWif("Uqe8cy26KvC2xqfh3aCpKvKjtoLC5YXiDW3iYf4MGSSy1RgMm3V5"); -echo " Passphrase: '" . $passphrase . "'" . PHP_EOL; -echo PHP_EOL; +echo "{ \"passphrase\": \"" . $passphrase . "\"," . PHP_EOL; -foreach ($coins as $coin) { +echo "\"coins\":[" . PHP_EOL; + +$length = count($coins); +for ($i = 0; $i < $length; $i++) { + +$coin = $coins[$i]; if (is_array($coin["PUBKEY_ADDRESS"])) { $NetworkPrefix = bin2hex(implode("",array_map("chr", $coin["PUBKEY_ADDRESS"]))); @@ -158,20 +162,28 @@ public function getWIF($compressed = true, $PrivatePrefix = 128) // Returns the compressed public key. The compressed PubKey starts with 0x02 if it's y coordinate is even and 0x03 if it's odd, the next 32 bytes corresponds to the x coordinates. $NetworkPrefix = $bitcoinECDSA->getNetworkPrefix(); -echo "\x1B[01;37m[\x1B[01;32m " . $coin["name"] . " \x1B[01;37m]\x1B[0m" . PHP_EOL; -echo " Network Prefix: " . $NetworkPrefix . PHP_EOL; -echo " Compressed Public Key: " . $bitcoinECDSA->getPubKey() . PHP_EOL; -echo "Uncompressed Public Key: " . $bitcoinECDSA->getUncompressedPubKey() . PHP_EOL; -echo " Private Key: " . $bitcoinECDSA->getPrivateKey() . PHP_EOL; -echo " Compressed WIF: " . $bitcoinECDSA->getWIF( true, $coin["SECRET_KEY"]) . PHP_EOL; -echo " Uncompressed WIF: " . $bitcoinECDSA->getWIF(false, $coin["SECRET_KEY"]) . PHP_EOL; +echo "{" . PHP_EOL; +echo "\"coin\": \"" . $coin["name"] . "\"," . PHP_EOL; +echo "\"Network Prefix\": \"" . $NetworkPrefix . "\"," . PHP_EOL; +echo "\"Compressed Public Key\": \"" . $bitcoinECDSA->getPubKey() . "\"," . PHP_EOL; +echo "\"Uncompressed Public Key\": \"" . $bitcoinECDSA->getUncompressedPubKey() . "\"," . PHP_EOL; +echo "\"Private Key\": \"" . $bitcoinECDSA->getPrivateKey() . "\"," . PHP_EOL; +echo "\"Compressed WIF\": \"" . $bitcoinECDSA->getWIF( true, $coin["SECRET_KEY"]) . "\"," . PHP_EOL; +echo "\"Uncompressed WIF\": \"" . $bitcoinECDSA->getWIF(false, $coin["SECRET_KEY"]) . "\"," . PHP_EOL; $address = $bitcoinECDSA->getAddress(); //compressed Bitcoin address -echo " Compressed Address: " . sprintf("%34s",$address) . PHP_EOL; +echo "\"Compressed Address\": \"" . sprintf("%34s",$address) . "\"," . PHP_EOL; $address = $bitcoinECDSA->getUncompressedAddress(); -echo "Uncompressed Address: " . sprintf("%34s",$address) . PHP_EOL; +echo "\"Uncompressed Address\": \"" . sprintf("%34s",$address) . "\"" . PHP_EOL; +if( $i < $length -1 ) { + echo "}," . PHP_EOL; +}else{ + echo "}" . PHP_EOL; +} } +echo "]," . PHP_EOL; + /* ETH/ERC20 */ // https://ethereum.stackexchange.com/questions/3542/how-are-ethereum-addresses-generated @@ -182,11 +194,15 @@ public function getWIF($compressed = true, $PrivatePrefix = 128) // https://github.com/ethereum/EIPs/issues/55#issuecomment-187159063 // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md -echo "\x1B[01;37m[\x1B[01;32m " . "ETH/ERC20" . " \x1B[01;37m]\x1B[0m" . PHP_EOL; +echo "\"symbols\":" . PHP_EOL ; +echo "{ \"symbol\":\"" . "ETH/ERC20" . "\"," . PHP_EOL; $kec = new Keccak256(); $bitcoinECDSA->setPrivateKey($k); $pubkey = substr($bitcoinECDSA->getUncompressedPubKey(),2); $address = substr($kec->hash(pack("H*",$pubkey), 256), -40); -echo " ETH/ERC20 Address: 0x" . EIP55_2($address) . PHP_EOL; +echo "\"address\": \"0x" . EIP55_2($address) . "\"" . PHP_EOL; +echo "}" . PHP_EOL; + +echo "}" . PHP_EOL; ?> \ No newline at end of file From bb613082522d85a121988f8663035325244c5276 Mon Sep 17 00:00:00 2001 From: Marcel Hodan Date: Sun, 11 Apr 2021 15:52:41 +0200 Subject: [PATCH 2/3] change json keys pattern --- genkomodo.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/genkomodo.php b/genkomodo.php index 3a4af92..054b0a1 100644 --- a/genkomodo.php +++ b/genkomodo.php @@ -164,17 +164,17 @@ public function getWIF($compressed = true, $PrivatePrefix = 128) echo "{" . PHP_EOL; echo "\"coin\": \"" . $coin["name"] . "\"," . PHP_EOL; -echo "\"Network Prefix\": \"" . $NetworkPrefix . "\"," . PHP_EOL; -echo "\"Compressed Public Key\": \"" . $bitcoinECDSA->getPubKey() . "\"," . PHP_EOL; -echo "\"Uncompressed Public Key\": \"" . $bitcoinECDSA->getUncompressedPubKey() . "\"," . PHP_EOL; -echo "\"Private Key\": \"" . $bitcoinECDSA->getPrivateKey() . "\"," . PHP_EOL; -echo "\"Compressed WIF\": \"" . $bitcoinECDSA->getWIF( true, $coin["SECRET_KEY"]) . "\"," . PHP_EOL; -echo "\"Uncompressed WIF\": \"" . $bitcoinECDSA->getWIF(false, $coin["SECRET_KEY"]) . "\"," . PHP_EOL; +echo "\"network-prefix\": \"" . $NetworkPrefix . "\"," . PHP_EOL; +echo "\"compressed-public-key\": \"" . $bitcoinECDSA->getPubKey() . "\"," . PHP_EOL; +echo "\"uncompressed-public-key\": \"" . $bitcoinECDSA->getUncompressedPubKey() . "\"," . PHP_EOL; +echo "\"private-key\": \"" . $bitcoinECDSA->getPrivateKey() . "\"," . PHP_EOL; +echo "\"compressed-wif\": \"" . $bitcoinECDSA->getWIF( true, $coin["SECRET_KEY"]) . "\"," . PHP_EOL; +echo "\"uncompressed-wif\": \"" . $bitcoinECDSA->getWIF(false, $coin["SECRET_KEY"]) . "\"," . PHP_EOL; $address = $bitcoinECDSA->getAddress(); //compressed Bitcoin address -echo "\"Compressed Address\": \"" . sprintf("%34s",$address) . "\"," . PHP_EOL; +echo "\"compressed-address\": \"" . sprintf("%34s",$address) . "\"," . PHP_EOL; $address = $bitcoinECDSA->getUncompressedAddress(); -echo "\"Uncompressed Address\": \"" . sprintf("%34s",$address) . "\"" . PHP_EOL; +echo "\"uncompressed-address\": \"" . sprintf("%34s",$address) . "\"" . PHP_EOL; if( $i < $length -1 ) { echo "}," . PHP_EOL; }else{ From c4c7c7a8c1d3e8e97058062638f1d0316eb56cd7 Mon Sep 17 00:00:00 2001 From: marcelhodan Date: Wed, 14 Apr 2021 20:58:54 +0200 Subject: [PATCH 3/3] use underscore instead of dashes in json --- genkomodo.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/genkomodo.php b/genkomodo.php index 054b0a1..c006e01 100644 --- a/genkomodo.php +++ b/genkomodo.php @@ -164,17 +164,17 @@ public function getWIF($compressed = true, $PrivatePrefix = 128) echo "{" . PHP_EOL; echo "\"coin\": \"" . $coin["name"] . "\"," . PHP_EOL; -echo "\"network-prefix\": \"" . $NetworkPrefix . "\"," . PHP_EOL; -echo "\"compressed-public-key\": \"" . $bitcoinECDSA->getPubKey() . "\"," . PHP_EOL; -echo "\"uncompressed-public-key\": \"" . $bitcoinECDSA->getUncompressedPubKey() . "\"," . PHP_EOL; -echo "\"private-key\": \"" . $bitcoinECDSA->getPrivateKey() . "\"," . PHP_EOL; -echo "\"compressed-wif\": \"" . $bitcoinECDSA->getWIF( true, $coin["SECRET_KEY"]) . "\"," . PHP_EOL; -echo "\"uncompressed-wif\": \"" . $bitcoinECDSA->getWIF(false, $coin["SECRET_KEY"]) . "\"," . PHP_EOL; +echo "\"network_prefix\": \"" . $NetworkPrefix . "\"," . PHP_EOL; +echo "\"compressed_public_key\": \"" . $bitcoinECDSA->getPubKey() . "\"," . PHP_EOL; +echo "\"uncompressed_public_key\": \"" . $bitcoinECDSA->getUncompressedPubKey() . "\"," . PHP_EOL; +echo "\"private_key\": \"" . $bitcoinECDSA->getPrivateKey() . "\"," . PHP_EOL; +echo "\"compressed_wif\": \"" . $bitcoinECDSA->getWIF( true, $coin["SECRET_KEY"]) . "\"," . PHP_EOL; +echo "\"uncompressed_wif\": \"" . $bitcoinECDSA->getWIF(false, $coin["SECRET_KEY"]) . "\"," . PHP_EOL; $address = $bitcoinECDSA->getAddress(); //compressed Bitcoin address -echo "\"compressed-address\": \"" . sprintf("%34s",$address) . "\"," . PHP_EOL; +echo "\"compressed_address\": \"" . sprintf("%34s",$address) . "\"," . PHP_EOL; $address = $bitcoinECDSA->getUncompressedAddress(); -echo "\"uncompressed-address\": \"" . sprintf("%34s",$address) . "\"" . PHP_EOL; +echo "\"uncompressed_address\": \"" . sprintf("%34s",$address) . "\"" . PHP_EOL; if( $i < $length -1 ) { echo "}," . PHP_EOL; }else{ @@ -205,4 +205,4 @@ public function getWIF($compressed = true, $PrivatePrefix = 128) echo "}" . PHP_EOL; echo "}" . PHP_EOL; -?> \ No newline at end of file +?>