I am using Polkadot-js api and wondered if there is an API to generate hierarchical deterministic wallet addresses from a given seed?
I see that there is some mention of soft and hard derivation paths, in Substrate's subkey
documentation but do not know if this has been ported to Polkadot-js or how it could be invoked.
SURI are supported by Polkadot-js using createFromUri
or addFromUri
to create or add a new account to your keyring.
You can import keyring from '@polkadot/ui-keyring'
and then use it:
keyring.createFromUri(`${phrase.trim()}${derivePath}`, {}, pairType)
Here is the definition of the function
edit: The derive path could be any combination of /[soft]
, //[hard]
, that can be repeated and don't have to be in this order, on top of this, you can have an additional ///[password]
.
So you can pass as argument to the createFromUri
function, something like:[mnemonic phrase]//Kusama//DAO/1
or [mnemonic phrase]//MyMainFunds/0///ThisIsMyPassword
.