HD wallets are generated with mnemonic phrase for readability and better accessibility purposes. Creating a mnemonic phrase can give you control of many accounts, all accessible with that same phrase.
A mnemonic phrase generates addresses by taking the phrase and combining it with a piece of information called a “derivation path”. Together, they create an infinite number of accounts, using complex cryptography.
To derive literally means to obtain something from a specified source.
In the crypto world context it means to obtain (a function or equation) from another by a sequence of logical steps, for example by differentiation.
So, how a derivation path looks like? Well like this...
"m/44'/118'/0'/0/0"
Each of the numbers in that sequence play a part and each changes what the private key, public key, and address would be. The most important takeaway is that if you want the next address from a phrase, you just increase the last number by one:
Address #1: "m/44'/118'/0'/0/0"
Address #2: "m/44'/118'/0'/0/1"
Address #3: "m/44'/118'/0'/0/2"
….
Address #99: "m/44'/118'/0'/0/98"
Yes, as a programmer you should know we always start from 0 not 1.
You can generate a new wallet with your mnemonic by setting a different derivation path from the default one.
Create a dedicated address derived from the same seed to pairwise every single person we interact with.
The Sacco library, our own open source tool to sign and send transactions to any Cosmos SDK based blockchain, including Commercio.network.
- Wallet derive.
From Wikipedia:
A cryptocurrency wallet is a device, physical medium, program or a service which stores the public and private keys and can be used to track ownership, receive or spend cryptocurrencies.
- Call the wallet derive function setting the optional parameter lastDerivationPathSegment;
- Finally, the result is a new address.
Here's an example of the implementation in all the available languages.
final mnemonicString = 'final random flame cinnamon grunt hazard easily mutual resist pond solution define knife female tongue crime atom jaguar alert library best forum lesson rigid';
final mnemonic = mnemonicString.split(' ');
final networkInfo = NetworkInfo(bech32Hrp: 'did:com:', lcdUrl: 'http://localhost:1317');
final wallet = Wallet.derive(
mnemonic,
networkInfo,
lastDerivationPathSegment: '1',
);
final address = wallet.bech32Address;
val mnemonicString = "final random flame cinnamon grunt hazard easily mutual resist pond solution define knife female tongue crime atom jaguar alert library best forum lesson rigid"
val mnemonic = listOf(mnemonicString)
val networkInfo = NetworkInfo(bech32Hrp = "did:com:", lcdUrl = "http://localhost:1317")
val wallet = Wallet.derive(mnemonic = mnemonic, networkInfo = networkInfo, lastDerivationPathSegment = 1)
val address = wallet.bech32Address