1

I'm trying to generate Private/Public Keys for Monero using only PHP.

This is the library I'm using:

https://github.com/sneurlax/monerophp/blob/master/src/cryptonote.php

This is my code:

require_once('src/cryptonote.php');

$Cryptonote = new Cryptonote();
$seed = $Cryptonote->gen_new_hex_seed(); //generate new random hex seed
$address = $Cryptonote->gen_private_keys($seed); //generate new random private key

print_r($address);

I receive this output:

Notice: Undefined variable: spendkey in /var/www/html/monero/src/cryptonote.php on line 72 Array ( [spendKey] => c2c511418397a682834576441911a68fb7fc0ab55db4cbf5e11ecd647a6c7402 [viewKey] => 4a078e76cd41a3d3b534b83dc6f2ea2de500b653ca82273b7bfad8045d85a400 )

The $seed seems to output and change but the viewKey stays the same.

How would I code this properly so that I can implement this in a webstore without using the Monero daemon?

Also, is there any downsides to generating keys like this?

  • The viewkey should change along with the spend key I believe researching Monero. Are these keys actually valid? – guest990455543 Apr 5 '19 at 10:25
  • The issue seems to be what @jtgrassie addressed. Simply change the lowercase K to uppercase and you should be set. I was able to generate these keys using your code: Array ( [spendKey] => acd05059cfb02793ac9e29598c345fffbd397d8691ee9408f7654b6cb9b1ab0c [viewKey] => 2bdeaed3876b9c7e76ce009bafb97b7967e88a45797d1a05a65bf3bdd1ac250b ) Array ( [spendKey] => e0733665e3daf59ebf3dad20f923d4b9d57c2cadd6a2c05d120e602fa1e9fd05 [viewKey] => 6ff2b6d65fe211733fffde88ccf26ba5c695c4049c7ff0fdad63331b2569f409 ) Array ( [spendKey] => a2c314fb21571f6486c2a176b0cbce6cd8968c409866e2f5f6d68c986a23f001 [viewKey] => – worksjustfine948594 Apr 5 '19 at 13:11
1

Line 72 in that file has a variable name that doesn't match the parameter name (notice the lowercase k in spendkey). Just edit that line replacing $spendkey with $spendKey should fix it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.