EOSIO / eosjs-keygen

Javascript keys generator for EOS
71 stars 42 forks source link

Keys without network access #6

Open Vasiliy-Bondarenko opened 6 years ago

Vasiliy-Bondarenko commented 6 years ago

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

jcalfee commented 6 years ago

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..

Vasiliy-Bondarenko commented 6 years ago
  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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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..

https://github.com/EOSIO/eosjs-ecc/issues/7#issuecomment-383617273

jcalfee commented 6 years ago

Updated README https://github.com/EOSIO/eosjs-keygen/commit/02cea2f79e05a704a9430a933d003574eb6ebb41

Vasiliy-Bondarenko commented 6 years ago

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 commented 6 years ago

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 ..