Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DID mode compatibility issue #170

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion client/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c *Client) GetAllDIDs() (*model.GetAccountInfo, error) {
}

func (c *Client) CreateDID(cfg *did.DIDCreate) (string, bool) {
if cfg.Type < did.LiteDIDMode && cfg.Type > did.WalletDIDMode {
if cfg.Type < did.BasicDIDMode && cfg.Type > did.LiteDIDMode {
return "Invalid DID mode", false
}
switch cfg.Type {
Expand Down Expand Up @@ -186,6 +186,14 @@ func (c *Client) SetupDID(dc *did.DIDCreate) (string, bool) {
!strings.Contains(dc.QuorumPrivKeyFile, did.QuorumPvtKeyFileName) {
return "Required files are missing", false
}
default:
if !strings.Contains(dc.PubImgFile, did.PubShareFileName) ||
!strings.Contains(dc.DIDImgFileName, did.DIDImgFileName) ||
!strings.Contains(dc.PubKeyFile, did.PubKeyFileName) ||
!strings.Contains(dc.QuorumPubKeyFile, did.QuorumPubKeyFileName) ||
!strings.Contains(dc.QuorumPrivKeyFile, did.QuorumPvtKeyFileName) {
return "Required files are missing", false
}
}
jd, err := json.Marshal(&dc)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion command/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ func (cmd *Command) CreateDID() {
cmd.log.Error("failed to create image", "err", err)
return
}
} else if cmd.didType != did.BasicDIDMode {
}
if cmd.didType != did.BasicDIDMode && cmd.didType != did.LiteDIDMode {
if cmd.privKeyFile == "" || cmd.pubKeyFile == "" {
cmd.log.Error("private key & public key file names required")
return
Expand Down
4 changes: 2 additions & 2 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ func (c *Core) SetupForienDIDQuorum(didStr string) (did.DIDCrypto, error) {
case did.LiteDIDMode:
return did.InitDIDQuorum_Lt(didStr, c.didDir, ""), nil
default:
return nil, fmt.Errorf("invalid did type")
return did.InitDIDQuorumc(didStr, c.didDir, ""), nil
}
}

Expand Down Expand Up @@ -632,6 +632,6 @@ func (c *Core) InitialiseDID(didStr string, didType int) (did.DIDCrypto, error)
case did.BasicDIDMode:
return did.InitDIDBasic(didStr, c.didDir, nil), nil
default:
return nil, fmt.Errorf("invalid did type, couldn't initialise")
return did.InitDIDBasic(didStr, c.didDir, nil), nil
}
}
15 changes: 14 additions & 1 deletion core/quorum_initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,20 @@ func (c *Core) SetupQuorum(didStr string, pwd string, pvtKeyPwd string) error {
c.pqc[didStr] = dc
}
default:
return fmt.Errorf("DID Type is not supported")
dc := did.InitDIDQuorumc(didStr, c.didDir, pwd)
if dc == nil {
c.log.Error("Failed to setup quorum")
return fmt.Errorf("failed to setup quorum")
}
c.qc[didStr] = dc
if pvtKeyPwd != "" {
dc := did.InitDIDBasicWithPassword(didStr, c.didDir, pvtKeyPwd)
if dc == nil {
c.log.Error("Failed to setup quorum")
return fmt.Errorf("failed to setup quorum")
}
c.pqc[didStr] = dc
}
}

c.up.RunUnpledge()
Expand Down
6 changes: 6 additions & 0 deletions did/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ func (d *DID) CreateDID(didCreate *DIDCreate) (string, error) {
return "", err
}

} else if didCreate.Type != LiteDIDMode {
_, err := util.Filecopy(didCreate.PubKeyFile, dirName+"/public/"+PubKeyFileName)
if err != nil {
d.log.Error("failed to copy pub key", "err", err)
return "", err
}
}

if didCreate.Type == ChildDIDMode {
Expand Down