eosjs-keygen icon indicating copy to clipboard operation
eosjs-keygen copied to clipboard

Keys without network access

Open Vasiliy-Bondarenko opened this issue 6 years ago • 12 comments

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

Vasiliy-Bondarenko avatar May 26 '18 13:05 Vasiliy-Bondarenko

  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 avatar May 27 '18 16:05 jcalfee

  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.

Vasiliy-Bondarenko avatar May 27 '18 16:05 Vasiliy-Bondarenko

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

jcalfee avatar May 27 '18 17:05 jcalfee

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.

Vasiliy-Bondarenko avatar May 27 '18 19:05 Vasiliy-Bondarenko

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 avatar May 27 '18 23:05 jcalfee

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 avatar May 28 '18 00:05 jcalfee

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

jcalfee avatar May 28 '18 00:05 jcalfee

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?

Vasiliy-Bondarenko avatar May 28 '18 09:05 Vasiliy-Bondarenko

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 avatar May 29 '18 11:05 jcalfee

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

jcalfee avatar May 29 '18 11:05 jcalfee

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?

Vasiliy-Bondarenko avatar May 29 '18 13:05 Vasiliy-Bondarenko

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

jcalfee avatar May 29 '18 15:05 jcalfee