From e4fef0fb362ca5e48292d916c83c8aaefa7ac6fa Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Wed, 26 Oct 2022 10:14:05 +0200 Subject: [PATCH] add master addr export + private export --- examples/example-go/main.go | 3 ++- flow.go | 15 ++++++++++++++- flow_commands.go | 3 ++- flow_types.go | 3 +++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/examples/example-go/main.go b/examples/example-go/main.go index 85bfe23..29ac2f2 100644 --- a/examples/example-go/main.go +++ b/examples/example-go/main.go @@ -106,7 +106,8 @@ func main() { testFlow(skg.RecoverAccount, skg.FlowParams{skg.PairingPass: "WrongPass", skg.PIN: "234567"}) testFlow(skg.Login, skg.FlowParams{skg.KeyUID: "60a78c98d5dd659f714eb7072bfb2c0d8a65f74a8f6aff7bb27cf56ae1feec17"}) testFlow(skg.GetAppInfo, skg.FlowParams{}) - testFlow(skg.ExportPublic, skg.FlowParams{skg.BIP44Path: "m/44'/60'/0'/0/1"}) + testFlow(skg.ExportPublic, skg.FlowParams{skg.BIP44Path: "m/44'/60'/0'/0/1", skg.ExportMaster: true}) + testFlow(skg.ExportPublic, skg.FlowParams{skg.BIP44Path: "m/43'/60'/1581'/1'/0", skg.ExportPriv: true}) testFlow(skg.Sign, skg.FlowParams{skg.TXHash: "60a78c98d5dd659f714eb7072bfb2c0d8a65f74a8f6aff7bb27cf56ae1feec17", skg.BIP44Path: "m/44'/60'/0'/0/0"}) testFlow(skg.StoreMetadata, skg.FlowParams{skg.CardName: "TestCard", skg.WalletPaths: []interface{}{"m/44'/60'/0'/0/0", "m/44'/60'/0'/0/1", "m/44'/60'/0'/0/5", "m/44'/60'/0'/0/6"}}) testFlow(skg.GetMetadata, skg.FlowParams{}) diff --git a/flow.go b/flow.go index 8449bae..7f3cbd8 100644 --- a/flow.go +++ b/flow.go @@ -355,13 +355,26 @@ func (f *KeycardFlow) exportPublicFlow(kc *keycardContext) (FlowStatus, error) { return nil, err } + result := FlowStatus{KeyUID: f.cardInfo.keyUID} + + if exportMaster, ok := f.params[ExportMaster]; ok && exportMaster.(bool) { + masterKey, err := f.exportKey(kc, masterPath, true) + result[MasterAddr] = masterKey.Address + + if err != nil { + return nil, err + } + } + key, err := f.exportBIP44Key(kc) if err != nil { return nil, err } - return FlowStatus{KeyUID: f.cardInfo.keyUID, ExportedKey: key}, nil + result[ExportedKey] = key + + return result, nil } func (f *KeycardFlow) loadKeysFlow(kc *keycardContext) (FlowStatus, error) { diff --git a/flow_commands.go b/flow_commands.go index 9a0318a..ee59598 100644 --- a/flow_commands.go +++ b/flow_commands.go @@ -382,7 +382,8 @@ func (f *KeycardFlow) exportKey(kc *keycardContext, path string, onlyPublic bool func (f *KeycardFlow) exportBIP44Key(kc *keycardContext) (*KeyPair, error) { if path, ok := f.params[BIP44Path]; ok { - return f.exportKey(kc, path.(string), true) + exportPrivate, ok := f.params[ExportPriv] + return f.exportKey(kc, path.(string), (!ok || !exportPrivate.(bool))) } err := f.pauseAndWait(EnterPath, ErrorExporting) diff --git a/flow_types.go b/flow_types.go index 447c30f..83a773e 100644 --- a/flow_types.go +++ b/flow_types.go @@ -104,6 +104,7 @@ const ( PUK = "puk" NewPUK = "new-puk" MasterKey = "master-key" + MasterAddr = "master-key-address" WalleRootKey = "wallet-root-key" WalletKey = "wallet-key" EIP1581Key = "eip1581-key" @@ -118,6 +119,8 @@ const ( TXSignature = "tx-signature" Overwrite = "overwrite" ResolveAddr = "resolve-addresses" + ExportMaster = "export-master-address" + ExportPriv = "export-private" CardMeta = "card-metadata" CardName = "card-name" WalletPaths = "wallet-paths"