forked from bytehubplus/fusion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
295 additions
and
1,909 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
Copyright © 2022 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"crypto/ed25519" | ||
"encoding/json" | ||
"encoding/pem" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
ssi "github.com/nuts-foundation/go-did" | ||
"github.com/nuts-foundation/go-did/did" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// createCmd represents the create command | ||
var createCmd = &cobra.Command{ | ||
Use: "create", | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("create called") | ||
pubKey, _ := cmd.Flags().GetString("public") | ||
didFile, _ := cmd.Flags().GetString("output") | ||
createDIDDoc(pubKey, didFile) | ||
}, | ||
} | ||
|
||
func init() { | ||
didCmd.AddCommand(createCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
var pubKey string | ||
var didFile string | ||
createCmd.Flags().StringVarP(&pubKey, "public", "p", "public.pem", "public key in JsonWebKey2020 format.") | ||
createCmd.MarkFlagRequired("public") | ||
createCmd.Flags().StringVarP(&didFile, "output", "o", "", "DID document output file.") | ||
createCmd.MarkFlagRequired("output") | ||
} | ||
|
||
func createDIDDoc(pubKey string, didFile string) error { | ||
raw, _ := os.ReadFile(pubKey) | ||
block, rest := pem.Decode(raw) | ||
if block == nil || block.Type != "PUBLIC KEY" { | ||
log.Fatal(rest) | ||
} | ||
|
||
pub := ed25519.PublicKey(block.Bytes) | ||
|
||
didID, _ := did.ParseDID("did:example:123") | ||
doc := &did.Document{ | ||
Context: []ssi.URI{did.DIDContextV1URI()}, | ||
ID: *didID, | ||
} | ||
|
||
keyID, _ := did.ParseDIDURL("did:example:123#key-1") | ||
vm, _ := did.NewVerificationMethod(*keyID, ssi.JsonWebKey2020, did.DID{}, pub) | ||
doc.AddAssertionMethod(vm) | ||
didJson, _ := json.MarshalIndent(doc, "", " ") | ||
|
||
// fmt.Println(string(didJson)) | ||
// parsedDID := did.Document{} | ||
|
||
// err := json.Unmarshal(didJson, &parsedDID) | ||
// if err != nil { | ||
// log.Fatal(err) | ||
// } | ||
// parsedDID.AssertionMethod[0].JWK() | ||
// parsedDID.AssertionMethod[0].PublicKey() | ||
|
||
// fmt.Printf("public key arg = %s \n", pubKey) | ||
// fmt.Printf("out put did document file = %s\n", didFile) | ||
// // err = os.WriteFile(didFile, didJson, 0644) | ||
err := os.WriteFile(didFile, didJson, 0644) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright © 2022 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// didCmd represents the did command | ||
var didCmd = &cobra.Command{ | ||
Use: "did", | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("did called") | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(didCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// didCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// didCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright © 2022 ZHAO Zhenhua <[email protected]> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// nodeCmd represents the node command | ||
var nodeCmd = &cobra.Command{ | ||
Use: "node", | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("node called") | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(nodeCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// nodeCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// nodeCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Copyright © 2022 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// rootCmd represents the base command when called without any subcommands | ||
var rootCmd = &cobra.Command{ | ||
Use: "fusion", | ||
Short: "A brief description of your application", | ||
Long: `A longer description that spans multiple lines and likely contains | ||
examples and usage of using your application. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
// Uncomment the following line if your bare application | ||
// has an action associated with it: | ||
// Run: func(cmd *cobra.Command, args []string) {}, | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() { | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
// Here you will define your flags and configuration settings. | ||
// Cobra supports persistent flags, which, if defined here, | ||
// will be global for your application. | ||
|
||
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.fusion.yaml)") | ||
|
||
// Cobra also supports local flags, which will only run | ||
// when this action is called directly. | ||
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,45 @@ | ||
// The AGPLv3 License (AGPLv3) | ||
|
||
// Copyright (c) 2022 ZHAO Zhenhua <[email protected]> | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as | ||
// published by the Free Software Foundation, either version 3 of the | ||
// License, or (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
|
||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package crypto | ||
|
||
import "testing" | ||
|
||
func TestKeyGen(t *testing.T) { | ||
keyGenOpts := &Ed25519PrivateKey{} | ||
key, err := keyGenOpts.KeyGen(nil) | ||
b, _ := key.Bytes() | ||
if err != nil { | ||
t.Logf("key = %x", b) | ||
} | ||
} | ||
|
||
func TestSign(t *testing.T) { | ||
keyGenOpts := &Ed25519PrivateKey{} | ||
key, err := keyGenOpts.KeyGen(nil) | ||
if err != nil { | ||
t.Logf("key failed") | ||
} | ||
|
||
msg := []byte("Rich Zhao") | ||
signature, err := key.(*Ed25519PrivateKey).Sign(key, msg, nil) | ||
if err != nil { | ||
t.Logf("sign failed") | ||
} | ||
|
||
t.Logf("signature = %x", signature) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.