Skip to content

feat(cmd): derive node key from bip39 mnemonic#562

Merged
lklimek merged 8 commits intov0.10-devfrom
feat-slip10
Jan 27, 2023
Merged

feat(cmd): derive node key from bip39 mnemonic#562
lklimek merged 8 commits intov0.10-devfrom
feat-slip10

Conversation

@lklimek
Copy link
Collaborator

@lklimek lklimek commented Jan 25, 2023

Issue being fixed or feature implemented

DIP-0009 defines feature path that should be used to derive cryptographic keys for various usages, in accordance to BIP-43 and BIP-44. Tenderdash doesn't support these schemes.

As we requested to add node ID to Deterministic Masternode Lists (DML, see DIP-0003), a practical problem arises: Masternode owners don't have Tenderdash deployed yet, and they cannot easily retrieve node ID without generating tenderdash node key ("p2p key"). This means they would need to generate - and manage - their keys when deploying planned enhancement (most likely, with Dash Core v19).

With BIP39 mnemonic support in Tenderdash, it will be enough to use their mnemonic to generate node ID. On Platform launch, they can use the same mnemonic to generate final private key. This also solves a problem of backing up the keys - standard offline BIP39 mnemonic should be enough for this.

This solution must be compatible with other implementations, to ensure interoperability.

What was done?

In this PR, --from-mnemonic flag was added to tenderdash gen-node-key command, to support key derivation from
BIP-39 compatible mnemonic. It uses implementation of SLIP-0010 from Oasis Protocol to generate ED25519 private key, basedon provided mnemonic , passphrase and BIP32 derivation path.

Added flags:

  • --derivation-path string BIP32 derivation path (default "m/9'/5'/3'/4'/0'")
  • --from-mnemonic derive key from BIP39 seed mnemonic phrase (read from stdin)

This command outputs JSON containing:

  • node ID in id field
  • private key in priv_key field

id field can be used as "node id" to register masternode in DML.

How Has This Been Tested?

Local execution

$ go run ./cmd/tenderdash gen-node-key --from-mnemonic
Enter BIP39 mnemonic: undo spend bread domain vocal digital cancel knife lecture coral flash rally
Enter passphrase (can be empty): 
{"id":"37d838adf93e2b5845966fdca62541818b563e8a","priv_key":{"type":"tendermint/PrivKeyEd25519","value":"P1XKEC71Qv+IcvQP9QvEz9Q26CijyCwjXqfFb2acbegtzxvfH84uNN/qU9Q1yQT3sSHsAiL/YP85ouiTfjLILQ=="}}

Added unit test

crypto/ed25519/bip39.go

Compared to javascript implementation

Using https://npm.runkit.com/ed25519-hd-key , compared results of execution of our unit tests with javascript library ed25519-hd-key.

Result:

Javascript library adds a null in the beginning of public key

Sample Tenderdash result: 9041e8deaddde890e6041b28a9239aa73bdaf7743531646ede9f198e53b1bed6
Sample Javascript result: 009041e8deaddde890e6041b28a9239aa73bdaf7743531646ede9f198e53b1bed6

Test code

var ed25519HdKey = require("ed25519-hd-key")
var bip39 = require("bip39")

const { derivePath, getMasterKeyFromSeed, getPublicKey } = require('ed25519-hd-key')
var hexSeed = bip39.mnemonicToSeedSync('injury urban mention wide beach cereal industry rule capital picnic aerobic hotel cable okay curious',"zazolc")

const { key, chainCode} = derivePath("m/9'/5'/3'/4'/0'", hexSeed); console.log(getPublicKey(key).toString('hex'))

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

@lklimek lklimek changed the title feat(cmd): SLIP10 generation of node key from bip39 mnemonic feat(cmd): derive node key from bip39 mnemonic Jan 25, 2023
@lklimek lklimek marked this pull request as draft January 25, 2023 13:34
@lklimek lklimek marked this pull request as ready for review January 25, 2023 15:09
shotonoff
shotonoff previously approved these changes Jan 26, 2023
Copy link
Collaborator

@shotonoff shotonoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
please look at a couple of minor comments

Copy link
Collaborator

@shotonoff shotonoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@lklimek lklimek merged commit bb17d98 into v0.10-dev Jan 27, 2023
@lklimek lklimek deleted the feat-slip10 branch February 1, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants