From 73e8c3e830087454fbcce4a7feed15abfc82fbde Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Thu, 29 Dec 2022 14:49:26 +0100 Subject: [PATCH] add key uid to all flows --- flow.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/flow.go b/flow.go index 1a11b85..1e4f4d3 100644 --- a/flow.go +++ b/flow.go @@ -434,7 +434,7 @@ func (f *KeycardFlow) changePINFlow(kc *keycardContext) (FlowStatus, error) { return nil, err } - return FlowStatus{InstanceUID: f.cardInfo.instanceUID}, nil + return FlowStatus{InstanceUID: f.cardInfo.instanceUID, KeyUID: f.cardInfo.keyUID}, nil } func (f *KeycardFlow) changePUKFlow(kc *keycardContext) (FlowStatus, error) { @@ -450,7 +450,7 @@ func (f *KeycardFlow) changePUKFlow(kc *keycardContext) (FlowStatus, error) { return nil, err } - return FlowStatus{InstanceUID: f.cardInfo.instanceUID}, nil + return FlowStatus{InstanceUID: f.cardInfo.instanceUID, KeyUID: f.cardInfo.keyUID}, nil } func (f *KeycardFlow) changePairingFlow(kc *keycardContext) (FlowStatus, error) { @@ -466,7 +466,7 @@ func (f *KeycardFlow) changePairingFlow(kc *keycardContext) (FlowStatus, error) return nil, err } - return FlowStatus{InstanceUID: f.cardInfo.instanceUID}, nil + return FlowStatus{InstanceUID: f.cardInfo.instanceUID, KeyUID: f.cardInfo.keyUID}, nil } func (f *KeycardFlow) unpairThisFlow(kc *keycardContext) (FlowStatus, error) { @@ -483,7 +483,7 @@ func (f *KeycardFlow) unpairThisFlow(kc *keycardContext) (FlowStatus, error) { } f.cardInfo.freeSlots++ - return FlowStatus{InstanceUID: f.cardInfo.instanceUID, FreeSlots: f.cardInfo.freeSlots}, nil + return FlowStatus{InstanceUID: f.cardInfo.instanceUID, KeyUID: f.cardInfo.keyUID, FreeSlots: f.cardInfo.freeSlots}, nil } func (f *KeycardFlow) unpairOthersFlow(kc *keycardContext) (FlowStatus, error) { @@ -506,7 +506,7 @@ func (f *KeycardFlow) unpairOthersFlow(kc *keycardContext) (FlowStatus, error) { } - return FlowStatus{InstanceUID: f.cardInfo.instanceUID, FreeSlots: f.cardInfo.freeSlots}, nil + return FlowStatus{InstanceUID: f.cardInfo.instanceUID, KeyUID: f.cardInfo.keyUID, FreeSlots: f.cardInfo.freeSlots}, nil } func (f *KeycardFlow) deleteUnpairFlow(kc *keycardContext) (FlowStatus, error) { @@ -548,7 +548,7 @@ func (f *KeycardFlow) storeMetadataFlow(kc *keycardContext) (FlowStatus, error) return nil, err } - return FlowStatus{InstanceUID: f.cardInfo.instanceUID}, nil + return FlowStatus{InstanceUID: f.cardInfo.instanceUID, KeyUID: f.cardInfo.keyUID}, nil } func (f *KeycardFlow) getMetadataFlow(kc *keycardContext) (FlowStatus, error) { @@ -558,6 +558,8 @@ func (f *KeycardFlow) getMetadataFlow(kc *keycardContext) (FlowStatus, error) { return nil, err } + result := FlowStatus{InstanceUID: f.cardInfo.instanceUID, KeyUID: f.cardInfo.keyUID} + if resolveAddr, ok := f.params[ResolveAddr]; ok && resolveAddr.(bool) { if f.cardInfo.keyUID == "" { return FlowStatus{ErrorKey: ErrorNoKeys, InstanceUID: f.cardInfo.instanceUID, CardMeta: m}, nil @@ -569,6 +571,15 @@ func (f *KeycardFlow) getMetadataFlow(kc *keycardContext) (FlowStatus, error) { return nil, err } + 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 + } + } + for i := range m.Wallets { k, err := f.exportKey(kc, m.Wallets[i].Path, true) @@ -580,5 +591,7 @@ func (f *KeycardFlow) getMetadataFlow(kc *keycardContext) (FlowStatus, error) { } } - return FlowStatus{InstanceUID: f.cardInfo.instanceUID, CardMeta: m}, nil + result[CardMeta] = m + + return result, nil }