diff --git a/rfc/0019_Duniter_V2_derivation_path_convention_hd_wallets.md b/rfc/0019_Duniter_V2_derivation_path_convention_hd_wallets.md index 8b137891791fe96927ad78e64b0aad7bded08bdc..5161655839a7008a67b9a17a7db9661803f7c779 100644 --- a/rfc/0019_Duniter_V2_derivation_path_convention_hd_wallets.md +++ b/rfc/0019_Duniter_V2_derivation_path_convention_hd_wallets.md @@ -1 +1,72 @@ +# Duniter V2S conventions for Hierarchical Deterministic Wallet +## Master seed generation + +Master seed should be generated from a [BIP-39-Mnemonic]. + +## Key derivation + +Key derivation should use [Substrate-Derivation-Path] specifications. + +## Key derivation scheme + +First derivation step should be an hardened derivation and represent an `account_id`. + + <mnemonic>//<account_id> + +`account_id` is an integer beetween `0` and `(2^24) - 1`. + +There are 3 types of accounts : + +| Account type | `account_id` value conditions | +|-|-| +| Member | `account_id == 0` | +| Transparent | `account_id != 0 && account_id % 2 == 0` | +| Opaque | `account_id % 2 == 1` | + +* **Transparent:** Classic non-member wallet (even) +* **Opaque:** A wallet using single-use public keys for each payment received and for each payment to oneself (odd). + +### Opaque account derivation scheme + +For **self-payment**, it is first necessary to derive the so-called "internal keypair", by derivation `//1` from the opaque account keypair. + + <mnemonic>//<account_id>//1 + +Then, each single-use public key is obtained by soft derivation of the "internal public key". + + <mnemonic>//<account_id>//1/i + +Where `i` is the payment to oneself number, beginning from 1. + +For **external payments**, it is first necessary to derive the so-called "external keypair", by derivation `//0` from the opaque account keypair. + + <mnemonic>//<account_id>//0 + +Then, each single-use public key is obtained by soft derivation of the "external public key". + + <mnemonic>//<account_id>//0/i + +Where `i` is the public key derivation number, beginning from 1. + +[BIP-39-Mnemonic]: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki +[Substrate-Derivation-Path]: https://docs.substrate.io/v3/tools/subkey/ + +### Examples + +#### Example 1 + +* **Mnemonic:** `"acquire flat utility climb filter device liberty beyond matrix satisfy metal essence"` +* **Seed:** `0xc7de9b8c771078445f31b7e7ce0ef58b588ac37f85359527b7267ac3ad2d25f5` +* **Address:** `5HBUc4C28AWThgPZ47TKoY9RTebMJbkfrLKWveWH6EzfAye4` + +* **Account ID:** `1` +* **Type:** Opaque + +* **First External Public Key** +* **Path:** `"acquire flat utility climb filter device liberty beyond matrix satisfy metal essence//1/0/1"` +* **Address:** `5CcNUmAo5P4K9LC68fgqFKNDTcxZ7zheLeLgk4mnADXeor2K` + +* **Third External Public Key** +* **Path:** `"acquire flat utility climb filter device liberty beyond matrix satisfy metal essence//1/0/3"` +* **Address:** `5FpnSswqc97MScQ8cvEjXcT13kNBuNArJKFCxUU6SqeYoBrN`