Skip to content
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

Keys without network access #6

Open
Vasiliy-Bondarenko opened this issue May 26, 2018 · 12 comments
Open

Keys without network access #6

Vasiliy-Bondarenko opened this issue May 26, 2018 · 12 comments
Labels

Comments

@Vasiliy-Bondarenko
Copy link

How to generate master key and derived keys without network access?
How to convert keys to corresponding address?

@jcalfee
Copy link
Contributor

jcalfee commented May 27, 2018

  1. there is not a single network api call in eosjs-keygen .. there are however network calls in eosjs .. are you referring to eosjs?
  2. eos does not have addresses, only public keys..

@jcalfee jcalfee added the help label May 27, 2018
@Vasiliy-Bondarenko
Copy link
Author

  1. yes. i get the keys, but can't get derived keys.
    so, yes, i'm referring to eosjs. is there any other way to create derived keys?

  2. ok. great. thanks.

@jcalfee
Copy link
Contributor

jcalfee commented May 27, 2018

yes, keystore.getPublicKey and keystore.getPrivateKey
https://github.com/EOSIO/eosjs-keygen/blob/master/API.md#module_Keystore

here are example keyPath parameter:
'owner', 'active', 'active/mypermission'
ref: https://github.com/EOSIO/eosjs-keygen/blob/master/API.md#keyPath

@Vasiliy-Bondarenko
Copy link
Author

ok. let's try:

let { Keystore, Keygen } = require( 'eosjs-keygen' )
Eos                      = require( 'eosjs' )

sessionConfig = {
    timeoutInMin: 30,
    uriRules: {
        'owner': '/account_recovery',
        'active': '/(transfer|contracts)',
        'active/**': '/producers'
    }
}

keystore = Keystore( 'myaccount1231548489', sessionConfig )
eos      = Eos.Testnet( { keyProvider: keystore.keyProvider } )

Keygen.generateMasterKeys()
    .then( keys => {
        // create blockchain account called 'myaccount1231548489'
        // console.log( keys )

        console.log(keystore.getPublicKey("active/1"));
    } )

prints out null
i've read docs, still don't get it.

@jcalfee
Copy link
Contributor

jcalfee commented May 27, 2018

Add keystore.deriveKeys({parent: keys.masterPrivateKey}) before you call getPublicKey("active/1") ..

It will be interesting to see ideas in how roles are used..

@jcalfee
Copy link
Contributor

jcalfee commented May 28, 2018

Here is a use-case showing how the roles, keys, and page navigation interact:
https://github.com/EOSIO/eosjs-keygen/blob/v1.3.2/src/keystore.test.js#L424-L443

@jcalfee
Copy link
Contributor

jcalfee commented May 28, 2018

In the uri rules history test pathname represents the browsers location bar: https://github.com/EOSIO/eosjs-keygen/blob/v1.3.2/src/keystore.test.js#L224-L253

@Vasiliy-Bondarenko
Copy link
Author

ok. i've managed to generate keys offline.
i've looked through the links above...
but i still don't understand the purpose of uris. is it just for storage?
i don't keep keys in storage at all. should i care about uris?

@jcalfee
Copy link
Contributor

jcalfee commented May 29, 2018

i don't keep keys in storage at all. should i care about uris?

No you don't need this library then.. Have a look at my comment here, please let me know if this helps and I'll see what I can do to document this better..

EOSIO/eosjs-ecc#7 (comment)

@jcalfee
Copy link
Contributor

jcalfee commented May 29, 2018

Updated README 02cea2f

@Vasiliy-Bondarenko
Copy link
Author

ok. i removed extra dependency.
so if i need a sequence of addresses, i need to do something like:

const master     = PrivateKey.fromSeed( 'test' )
const childKeys1 = master.getChildKey( 'active/1' )
const publicKey1 = childKeys1.toPublic().toString()
const childKeys2 = ownerPrivate.getChildKey( 'active/2' )
const publicKey2 = childKeys2.toPublic().toString()

does is look correct?

@jcalfee
Copy link
Contributor

jcalfee commented May 29, 2018

It was designed to go like this:
master.getChildKey( 'owner').getChildKey('active').getChildKey('1').toString()

Owner is the parent of all keys including active..
Active is the parent of all custom permission keys..

I am not aware of any use-case for owner having another child other than active .. Let me know if you see one..

You might do better with actual permission names instead of 1, 2, 3 ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants