From 955ee3e031cf125addea074493973cec1a8f74d7 Mon Sep 17 00:00:00 2001 From: Lai Robin Date: Fri, 15 May 2020 15:33:33 +0800 Subject: [PATCH 1/2] BTFS-1968: Wallet BE: Initialize recovery phrases and save into config --- identity.go | 7 +++++-- init.go | 7 ++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/identity.go b/identity.go index f4e7c87..8a9e8d0 100644 --- a/identity.go +++ b/identity.go @@ -8,12 +8,15 @@ import ( const IdentityTag = "Identity" const PrivKeyTag = "PrivKey" +const MnemonicTag = "Mnemonic" const PrivKeySelector = IdentityTag + "." + PrivKeyTag +const MnemonicSelector = IdentityTag + "." + MnemonicTag // Identity tracks the configuration of the local node's identity. type Identity struct { - PeerID string - PrivKey string `json:",omitempty"` + PeerID string + PrivKey string `json:",omitempty"` + Mnemonic string `json:",omitempty"` } // DecodePrivateKey is a helper to decode the users PrivateKey diff --git a/init.go b/init.go index 38a1f18..2a0a5e6 100644 --- a/init.go +++ b/init.go @@ -14,8 +14,8 @@ import ( peer "github.com/libp2p/go-libp2p-core/peer" ) -func Init(out io.Writer, nBitsForKeypair int, keyType string, importKey string, rmOnUnpin bool) (*Config, error) { - identity, err := identityConfig(out, nBitsForKeypair, keyType, importKey) +func Init(out io.Writer, nBitsForKeypair int, keyType string, importKey string, mnemonic string, rmOnUnpin bool) (*Config, error) { + identity, err := identityConfig(out, nBitsForKeypair, keyType, importKey, mnemonic) if err != nil { return nil, err } @@ -229,7 +229,7 @@ func DefaultServicesConfigTestnet() Services { } // identityConfig initializes a new identity. -func identityConfig(out io.Writer, nbits int, keyType string, importKey string) (Identity, error) { +func identityConfig(out io.Writer, nbits int, keyType string, importKey string, mnemonic string) (Identity, error) { // TODO guard higher up ident := Identity{} @@ -281,6 +281,7 @@ func identityConfig(out io.Writer, nbits int, keyType string, importKey string) return ident, err } ident.PrivKey = base64.StdEncoding.EncodeToString(skbytes) + ident.Mnemonic = mnemonic id, err := peer.IDFromPublicKey(pk) if err != nil { From 423d03dcdd4ab8c1f53d68abebfb01ed97abb7de Mon Sep 17 00:00:00 2001 From: Robin Date: Mon, 18 May 2020 11:26:27 +0800 Subject: [PATCH 2/2] add Mnemonic/Password --- identity.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/identity.go b/identity.go index 8a9e8d0..f5aed9a 100644 --- a/identity.go +++ b/identity.go @@ -9,14 +9,17 @@ import ( const IdentityTag = "Identity" const PrivKeyTag = "PrivKey" const MnemonicTag = "Mnemonic" +const Password = "Password" const PrivKeySelector = IdentityTag + "." + PrivKeyTag const MnemonicSelector = IdentityTag + "." + MnemonicTag +const PasswordSelector = IdentityTag + "." + Password // Identity tracks the configuration of the local node's identity. type Identity struct { PeerID string PrivKey string `json:",omitempty"` Mnemonic string `json:",omitempty"` + Password string `json:",omitempty"` } // DecodePrivateKey is a helper to decode the users PrivateKey