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

Request: Generate keypair for usage in e.g. BigChainDB (doc pub key gen) #9

Closed
stefanvangastel opened this Issue Oct 7, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@stefanvangastel
Contributor

stefanvangastel commented Oct 7, 2018

Hi there, I'm not a crypto expert so I have a question; Can I use this lib to generate a pub/priv keypair based on a seed or secret (so reproducable) to use with, in my case, BigChainDB? (https://docs.bigchaindb.com/projects/js-driver/en/latest/usage.html#cryptographic-identities-generation)

I can manage to get a private key using the $key->priv() method but the pub() method returns an array I do not know how to use? I''m expecting something like: DGNE3CjqfGoeJYYMzZZVWAw22eqxEZb46xg5zupC63a6

Can this be documented?

@stefanvangastel stefanvangastel changed the title from Request: Generate keypair for usage in e.g. BigChainDB to Request: Generate keypair for usage in e.g. BigChainDB (doc pub key gen) Oct 7, 2018

@ssmyczynski

This comment has been minimized.

Show comment
Hide comment
@ssmyczynski

ssmyczynski Oct 7, 2018

Member

This is low level library which provides general algorithms with operating on different kinds of elliptic curves. On of it is ed25519 which is used in BigChainDB.
The algorithms used to encode keys / generate them in some way from given seed that are specific for software using those keys are of course not in scope of this library.
As I see BigChainDB uses Base58 encoded private and public keys so below I put you an example how you can generate a pair of such keys using mnemonic seed (I did not check if it works with BigChainDB thought):

use Elliptic\EdDSA;
use StephenHill\Base58;

$mnemonic = "scheme spot photo card baby mountain device kick cradle pact join borrow";
$secret = hash_pbkdf2('sha512', $mnemonic, 'mnemonic', 2048);

$ec =  new EdDSA('ed25519');
$kp = $ec->keyFromSecret($secret);

assert($secret == $kp->getSecret('hex'));
echo "Secret:  " . $kp->getSecret('hex') . PHP_EOL;

echo "Private: " . $kp->priv()->toString('hex') . PHP_EOL;
echo "Public:  " . $kp->getPublic('hex') .  PHP_EOL;

$b58 = new Base58();
echo PHP_EOL;
echo "B58 Private: " . $b58->encode(hex2bin($kp->priv()->toString('hex'))) . PHP_EOL;
echo "B58 Public:  " . $b58->encode(hex2bin($kp->getPublic('hex'))) .  PHP_EOL;

Let me know if it helps.

Member

ssmyczynski commented Oct 7, 2018

This is low level library which provides general algorithms with operating on different kinds of elliptic curves. On of it is ed25519 which is used in BigChainDB.
The algorithms used to encode keys / generate them in some way from given seed that are specific for software using those keys are of course not in scope of this library.
As I see BigChainDB uses Base58 encoded private and public keys so below I put you an example how you can generate a pair of such keys using mnemonic seed (I did not check if it works with BigChainDB thought):

use Elliptic\EdDSA;
use StephenHill\Base58;

$mnemonic = "scheme spot photo card baby mountain device kick cradle pact join borrow";
$secret = hash_pbkdf2('sha512', $mnemonic, 'mnemonic', 2048);

$ec =  new EdDSA('ed25519');
$kp = $ec->keyFromSecret($secret);

assert($secret == $kp->getSecret('hex'));
echo "Secret:  " . $kp->getSecret('hex') . PHP_EOL;

echo "Private: " . $kp->priv()->toString('hex') . PHP_EOL;
echo "Public:  " . $kp->getPublic('hex') .  PHP_EOL;

$b58 = new Base58();
echo PHP_EOL;
echo "B58 Private: " . $b58->encode(hex2bin($kp->priv()->toString('hex'))) . PHP_EOL;
echo "B58 Public:  " . $b58->encode(hex2bin($kp->getPublic('hex'))) .  PHP_EOL;

Let me know if it helps.

@stefanvangastel

This comment has been minimized.

Show comment
Hide comment
@stefanvangastel

stefanvangastel Oct 7, 2018

Contributor
Contributor

stefanvangastel commented Oct 7, 2018

@stefanvangastel

This comment has been minimized.

Show comment
Hide comment
@stefanvangastel

stefanvangastel Oct 14, 2018

Contributor

Works like a charm with BigChainDB.

Contributor

stefanvangastel commented Oct 14, 2018

Works like a charm with BigChainDB.

stefanvangastel added a commit to stefanvangastel/elliptic-php that referenced this issue Oct 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment