Skip to content

created a bit coin address, leveraged python's EllepticCurve library … #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.idea
test.txt
test.php

vendor
**/__pycache__/
Blockchain/Python_Package/virtual_env/
37 changes: 37 additions & 0 deletions Blockchain/Backend/API/Client_calls/BaseCurl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
abstract class BaseCurl
{
public static function curlSkeletonIfDataSend($curlObj, $OpType, $data)
{
curl_setopt($curlObj, CURLOPT_CUSTOMREQUEST, $OpType);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $data);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
// Set an authorization header if needed
// 'Authorization: Bearer YourAccessToken',
);
$response = curl_exec($curlObj);
// Get the HTTP response code
$httpCode = curl_getinfo($curlObj, CURLINFO_HTTP_CODE);

// Check for cURL errors and handle response code
if (curl_errno($curlObj))
{
return ["error"=>true, "errorType" => "Curl Error", "data"=>curl_error($curlObj)];
}
elseif ($httpCode >= 400)
{
return ["error" => true, "errorType" => "HTTP Error", "data" => $httpCode];
} else
{
return ["data" => $response];
}
}

public static function closeCurl($curlObj)
{
curl_close($curlObj);
}
}
25 changes: 25 additions & 0 deletions Blockchain/Backend/API/Client_calls/ClientAPI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
require_once 'Blockchain/Backend/API/Client_calls/BaseCurl.php';
class ClientAPI extends BaseCurl
{
public static $clientAddress = 'http://localhost:5000/generate_keys';

public static function postRequestAPI($curlObject)
{
curl_setopt($curlObject, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curlObject);

if (curl_errno($curlObject)) {
return ["error"=>true, "errorType" => "Curl Error", "data" => curl_error($curlObject)];
} else {
return ["data" => $response];
}
}

public static function errorHandleResponse($data): bool
{
return array_key_exists('error', $data);
}


}
16 changes: 15 additions & 1 deletion Blockchain/Backend/util/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@
function hash256($s) {
// Two rounds of SHA256
return hash('sha256', hash('sha256', $s, true), true);
}
}

function hash160($data) {
// Using RIPEMD160 with HMAC-SHA256
$sha256Hash = hash('sha256', $data, true);
return hash('ripemd160', $sha256Hash, true);
}

// Example usage
$input = 'some data to hash';
$hashed256 = hash256($input);
$hashed160 = hash160($input);

echo "Hashed 256: " . bin2hex($hashed256) . PHP_EOL;
echo "Hashed 160: " . bin2hex($hashed160) . PHP_EOL;
16 changes: 16 additions & 0 deletions Blockchain/Client/Account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
require_once 'Blockchain/Backend/API/Client_calls/ClientAPI.php';

//$ch = curl_init(ClientAPI::$clientAddress);
//$response = ClientAPI::curlSkeleton($ch, "POST", $data_string);

// URL of the Flask API
// Update with your actual API URL


$ch = curl_init(ClientAPI::$clientAddress);
$response = ClientAPI::postRequestAPI($ch);

$jsonData = $response['data'];
$data = json_decode($jsonData, true, 512, JSON_BIGINT_AS_STRING);
print_r($data['privateKey']);
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy