eosjs-keygen
eosjs-keygen copied to clipboard
Keys without network access
How to generate master key and derived keys without network access? How to convert keys to corresponding address?
- there is not a single network api call in eosjs-keygen .. there are however network calls in eosjs .. are you referring to eosjs?
- eos does not have addresses, only public keys..
-
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?
-
ok. great. thanks.
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
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.
Add keystore.deriveKeys({parent: keys.masterPrivateKey})
before you call getPublicKey("active/1")
..
It will be interesting to see ideas in how roles are used..
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
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
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?
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
Updated README https://github.com/EOSIO/eosjs-keygen/commit/02cea2f79e05a704a9430a933d003574eb6ebb41
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?
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 ..