Skip to content

Commit

Permalink
write the did.json
Browse files Browse the repository at this point in the history
  • Loading branch information
wistefan committed May 3, 2024
1 parent 13e0cb3 commit 40cb620
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"os"

"github.com/wistefan/did-helper/did"
"go.uber.org/zap"
Expand All @@ -15,13 +17,15 @@ func init() {
func main() {
var path string
var password string
var outputFile string

flag.StringVar(&path, "keystorePath", "", "Path to the keystore to be read.")
flag.StringVar(&password, "keystorePassword", "", "Password for the keystore.")
flag.StringVar(&outputFile, "outputFile", "", "File to write the did.json. Will not write the file if empty.")

flag.Parse()

zap.L().Sugar().Infof("Path to the keystore: %s", path, "Password to be used: %s", password)
zap.L().Sugar().Infof("Path to the keystore: %s", path, "Password to be used: %s", password, "Output file: %s", outputFile)

did, err := did.GetDIDKeyFromECPKCS12(path, password)

Expand All @@ -30,4 +34,21 @@ func main() {
} else {
fmt.Println("Did key is: ", did)
}

if outputFile != "" {
didJson := Did{Context: []string{"https://www.w3.org/ns/did/v1"}, Id: did}
jsonFileContent, err := json.Marshal(didJson)
if err != nil {
zap.L().Sugar().Warnf("Was not able to marshal the did-json. Err: %s", err)
}
err = os.WriteFile(outputFile, jsonFileContent, 0644)
if err != nil {
zap.L().Sugar().Warnf("Was not able to write the did-json to %s. Err: %s", outputFile, err)
}
}
}

type Did struct {
Context []string `json:"issuerDid,omitempty"`
Id string `json:"id"`
}

0 comments on commit 40cb620

Please sign in to comment.