The purpose of the keyring is to:
Where it comes to instantiating a Keyring there are 3 major pathways we are designing to support
Here's a visualization of all the paths (see them broken down in sub-sections below):
This user is brand new to Entropy, they want to get set up and running.
Their flow looks like this:
In code:
import { Keyring, generateMnemomnic, mnemonicToKeyData } from `@entropyxyz/keyring`
// 1. create (and write down) mnemonic
const mnemomnic = generateMnemomnic()
// 2. use mnemonic to generate keyData
const keyData = mnemonicToKeyData(mnemonic)
/*
{
programMod: { type, secret, public, address },
developer: { type, secret, public, address },
device: { type, secret, public, address }
}
where:
- type = the type of keypair, e.g. blake256
- secret = the secretKey of the keypair, stored in ...format?
- public = the publicKey of the keypair, stored in ...format?
- addresss = the formatted address of the keypair
*/
// 3. instantiate keyring
const keyring = new Keyring(keyData)
// 4. export keyData + persist
const keyData = keyring.json()
/*
{
programMod: { type, secret, ... },
developer: { type, secret, ... },
device: { type, secret, ... }
}
*/
await writeKeyData(keyData) // some function
Notes:
keyData
here is deterministic (mostly)
mnemonicToKeyData
takes care of mnemonic
=> seed
=> keyData
(programMod, developer, etc)keyData.device
is NOT derived from the seed
mnemonic
seed
seed
is used with paths
to derive each key in keyData
dev
key without revealing a programMod
keyQuestions:
keyData
β¦ how, where?
mnemonicToKeyData
?
type
for a particular key(s)mnemonicToKeyData
add keyData.device
?
keyData.device
keyData
formats
type
secret
public
address
programMod
?
account
- we "register" an account, accounts have addresses (derived from this secret?), and account key being the one which can modify the account seems right?
This path assume a user already has a working keyData
they have read from persistence.
Flow looks like this:
import { Keyring } from 'entropxyz/keyring'
const keyData = await readKeyData() // some function
// {
// programMod: { type, secret, ... },
// developer: { type, secret, ... },
// device: { type, secret, ... }
// }
const keyring = new Keyring(keyData)
Notes:
keyData
is not necessarily the same as the data generated from mnemonic, it could be: user-created, e.g. I make some new data for a new device:
βββconst newKeyData = mnemonicToKeyData(generateMnemonic())
βββconst keyData = {
βββ ..., // new keys
βββ programMod, // "admin" keys from an earlier install
βββ}
mnemonic
alone, as the determinism is brokenQuestions:
This path covers the case that a user has lost their setup, but has a record of their mnemonic
.
This flow looks like:
In code:
import { Keyring, mnemonicToKeyData } from `@entropyxyz/keyring`
// 1. User recreates keyData
const keyData = mnemonicToKeyData(mnemonic)
// 2. instantiate keyring
const keyring = new Keyring(keyData)
// 3. persistence of keyData
const keyData = keyring.json()
await writeKeyData(keyData) // some function
Notes:
keyData.device
is unique to every device, so:keyData
keyData
was custom in some way, this recovery path does not work (see Path B, Note 2)new Keyring(keyData: Keydata) => keyRing
keyring.json() => keyData
returns keyData
for persistence
Should be able to access:
signer
needed for creating extrinsicsShould NOT be able to access:
e.g.
keyring[keyname].signer
keyring.get(keyname).signer
creates a disposable key intended for singal use encryption while signing:
e.g.
keyring.createEphemeralSigner()
keyring.create(type).signer
generateMnemonic() => string
bip39, no password?
mnemonicToKeyData(mnemonic: string, opts) => keyData
KeyData
opts
(rename) is added to specify the keys + paths to derive, e.g
{
programMod: '/path/to/programMod',
developer: '/path/to/programMod',
device: Math.random(),
}
isValidKeyData(keyData) => boolean
mix: we should write this early because it makes the number of checks we need to do
everywhere else soooo much lighter if we can tightly check data before ingesting
are curent way of thinking is to have an admin key and registration key
the key that pays for registartion and the key that gets set as the programMod
they can be one in the same (infact they are right now)
however they can also be different. In my personal case i would want them to be different
i think also for "sponsorship" reason we should allow them to be different
init
should take all "3" seeds but only requires programMod i'm still stuck on this name
should you be able to set a different keyring to an already initialized entropy?
entropy.setKeyring(keyring)