You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 8, 2023. It is now read-only.
well, this is not really an issue, but somehow i do not get how to create a pull request.
I implemented the feature, that you can import private keys to your wallet. This is kind of a quick-shot solution. Error handling and internationalization can be improved. But i saw private key handling is on your todo list, and this would be a part of it
To view/wallet.php i added the following between WALLET_SUPPORT and WALLET_2FAON, so the button is show on the top of your wallet between the support button and the enable 2FA button:
to index.php i added this to the switch($_POST['action']):
// this part shows an input and a button at the top of the site to insert your private keys
case "enterprivkey":$user = new User($mysqli);$enterprivkey = $user->enterPrivKey(); echo $enterprivkey; break;// this part is handling the click on the submit button from the above codecase "submitprivkey":
if(empty($_POST['privkey'])) {
$error['message'] = "No private keys submitted!";
break;
}
$privkey = $_POST['privkey'];
// check length and check for valid characters depends on your *coind implementation.// this would be better to be checked by the *coind daemon,// since it checks them also and completely skip the checks here// check lengthif(strlen($privkey) !== 52) {
$error['message'] = "Length of private key is wrong: ". strval(strlen($privkey)) .". Has to be 52!";
break;
}
// check for valid charactersfor($i = 0; $i < strlen($privkey); $i++) {
// valid characters are between 0 and 9 and between a and fif($privkey[$i] < "0" || $privkey[$i] > "9") {
if(strtolower($privkey[$i]) < "a" || strtolower($privkey[$i]) > "z") {
$error['message'] = "Invalid characters are in the private key!";
break;
}
}
}
$result = $client->importPrivateKey($user_session, $privkey);
$r = json_decode($result);
if($r->{'error'} == null) {
$error['message'] = "Successfully added a Private Key to your wallet. It can take a while that it appears in your wallet since the network has to verify your action.";
} else {
$error['message'] = $r->{'error'}->{'message'};
}
break;
The change of jsonRPCClient.php was the toughest part. Since your code always resulted in a http error 500 when sending importprivkey, i had to use php-curl to call the *coind daemon. Maybe it is better so switch completely to php-curl because the error handling is much better and options can easier be set, than with fopen. So i enhanced the function __call by the following:
publicfunction__call($method,$params) {
/* ... your code ... */// my code handling "importprivkey"if($method === "importprivkey") {
$privkey = $params[0];
$account = $params[1];
$rescan = "true";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // enable return as stringcurl_setopt($curl, CURLOPT_POST, 1); // enable postcurl_setopt($curl, CURLOPT_POSTFIELDS, '{"jsonrpc":"1.0","method":"importprivkey","params":["'.$privkey.'", "'.$account.'", true]}'); // enable post fielscurl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); // set content-type$result = curl_exec($curl);
return$result;
} else {
// your old code handling all the other methodsif ($fp = fopen($this->url, 'r', false, $context)) {
$response = '';
while($row = fgets($fp)) {
$response.= trim($row)."\n";
}
$this->debug && $debug.='***** Server response *****'."\n".$response.'***** End of server response *****'."\n";
$response = json_decode($response,true);
} else {
thrownewException('Unable to connect to '.$this->url);
}
}
/* ... again your code ... */
}
Hope this helps,
Gottfried, servus.at
The text was updated successfully, but these errors were encountered:
A user's private key should never go in here without additional strong protections, such as encrypting the key properly in the database.
As a general rule: not your key, not your coins. Same for sharing it. Sometimes when there is no other option you just have enough coins you can lose on a web wallet.
The user can just spend to their Web wallet and dispense with importing private keys.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hello Johnathan,
well, this is not really an issue, but somehow i do not get how to create a pull request.
I implemented the feature, that you can import private keys to your wallet. This is kind of a quick-shot solution. Error handling and internationalization can be improved. But i saw private key handling is on your todo list, and this would be a part of it
To view/wallet.php i added the following between WALLET_SUPPORT and WALLET_2FAON, so the button is show on the top of your wallet between the support button and the enable 2FA button:
to index.php i added this to the switch($_POST['action']):
At the end of classes/Client.php i added this:
This function i added to classes/User.php
The change of jsonRPCClient.php was the toughest part. Since your code always resulted in a http error 500 when sending importprivkey, i had to use php-curl to call the *coind daemon. Maybe it is better so switch completely to php-curl because the error handling is much better and options can easier be set, than with fopen. So i enhanced the function __call by the following:
Hope this helps,
Gottfried, servus.at
The text was updated successfully, but these errors were encountered: