Substrate Uri
Substrate has a standard derivation format that applies on any seeds and mnemonics. This means that for a given secret, you can apply hard derivations, soft derivations to generate a new pair. In all the examples we have used either addFromUri
or createFromUri
and have supplied all with an empty derivation path.
In general the derivation format is specified as <mnemonic or mini-secret>[//hard-derivation][/soft-derivation][///password]
where
mnemonic or mini-secret
is either of the secret types. For mini-secrets we would supply 32 bytes in hex format (0x
-prefixed with 64 additional0
-f
bytes)hard-derivation
is a hard path, always prefixed by//
to indicate the type. Multiple hard derivations can be applied, i.e.//hard//again
would be valid. Underlying it will apply a hashing function on the secret, generating a new secret for the remainder of the derivations.soft-derivation
is a soft path, always prefixed by/
. This derivation is only available and supported onsr25519
pairs. While other crypto can do soft derivations, the Substrate implementation only supports this on Schnorrkel.password
, always prefixed by///
indicates a derivation password, not to be confused with a pair password as implemented on the keyring. Using these means that an initial kdf is applied upon derivation, which means that even if the seed would leak, accounts cannot be derived without the initial password. Unlike hard and soft derivations that can be mixed, only a single password should be specified per derivation.
#
Dev accountsIn a preceding section we created a development-specific Alice
account. Now that we have a breakdown of the suri formats, a note on these. For development chains, these accounts are pre-funded and derived from a known mnemonic via sr25519
crypto. Since these are known, the Keyring will use their seed (aligning with subkey) when no mnemonic is specified.
In cases where you want to use the dev seed itself (instead of it being defaulted), it is bottom drive obey lake curtain smoke basket hold race lonely fit walk
.
#
Putting it togetherWith an understanding of the suri in-hand, we can now derive multiple accounts from the same seed/mnemonic using derivation paths.
#
Working with non-mnemonicsAdditionally, as indicated the {add, create}FromUri
functions can also take a raw mini secret. Although mnemonic interactions are generally preferred (since it had checksums and users are generally bad at generating 32-bytes by themselves), raw secrets can be applied.
#
Overview... done.At this point you should have a good grasp on the Keyring, the interactions with pairs and how this relates to Substrate usage and addresses. While the keyring has additional functionality we have covered the basic interactions in-depth. Check back in the future for expansions on the features contained here.