From 643914a61ea5c81fd9fbad4b64e10346b1748706 Mon Sep 17 00:00:00 2001 From: PeepoFrog Date: Sat, 24 Feb 2024 17:15:54 +0200 Subject: [PATCH 01/14] Refactored for package ussage Added PrivKey mnemonic for key derivation --- .../MnemonicsGenerator/mnemonicGenerator.go | 194 ++++++++++++++ validator-key-gen/ValKeyGen/valKeyGen.go | 253 ++++++++++++++++++ 2 files changed, 447 insertions(+) create mode 100644 validator-key-gen/MnemonicsGenerator/mnemonicGenerator.go create mode 100644 validator-key-gen/ValKeyGen/valKeyGen.go diff --git a/validator-key-gen/MnemonicsGenerator/mnemonicGenerator.go b/validator-key-gen/MnemonicsGenerator/mnemonicGenerator.go new file mode 100644 index 00000000..363e2650 --- /dev/null +++ b/validator-key-gen/MnemonicsGenerator/mnemonicGenerator.go @@ -0,0 +1,194 @@ +package mnemonicsgenerator + +import ( + "crypto/sha256" + "encoding/hex" + "fmt" + "os" + "strings" + + valkeygen "github.com/KiraCore/tools/validator-key-gen/ValKeyGen" + "github.com/cosmos/go-bip39" + "github.com/tendermint/tendermint/crypto/ed25519" + "github.com/tendermint/tendermint/p2p" +) + +const ( + DefaultValidatorNodeKeyFileName string = "validator_node_key.json" + DefaultPrivValidatorKeyFileName string = "priv_validator_key.json" + DefaultValidatorNodeIdFileName string = "validator_node_id.key" + + DefaultPrefix string = "kira" + DefaultPath string = "44'/118'/0'/0/0" +) + +type MasterMnemonicSet struct { + ValidatorAddrMnemonic []byte + ValidatorValMnemonic []byte + SignerAddrMnemonic []byte + ValidatorNodeMnemonic []byte + ValidatorNodeId []byte + PrivKeyMnemonic []byte +} + +// returns nodeId from mnemonic +func generateNodeIdFromMnemonic(mnemonic string) []byte { + if err := valkeygen.CheckMnemonic(mnemonic); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + tmPrivKey := ed25519.GenPrivKeyFromSecret([]byte(mnemonic)) + filenodekey := p2p.NodeKey{ + PrivKey: tmPrivKey, + } + nodeId := []byte(filenodekey.ID()) + return nodeId +} + +func createMnemonicsFile(path string, mnemonicData []byte) error { + file, err := os.Create(path) + if err != nil { + fmt.Printf("Error creating %s file: %s", path, err) + return err + } + defer file.Close() + _, err = file.WriteString(string(mnemonicData)) + if err != nil { + fmt.Printf("Error creating %s file: %s", path, err) + return err + } + return nil +} + +// accepts name and typeOfMnemonic as salt and mnemonic, for example MnemonicGenerator --name="validator" --type="addr" - validator address +func generateFromMasterMnemonic(name, typeOfMnemonic string, masterMnemonic []byte) ([]byte, error) { + stringToHash := strings.ToLower(fmt.Sprintf("%s ; %s %s", masterMnemonic, name, typeOfMnemonic)) + stringToHash = strings.ReplaceAll(stringToHash, " ", "") + + hasher := sha256.New() + hasher.Write([]byte(stringToHash)) + entropyHex := hex.EncodeToString(hasher.Sum(nil)) + + entropy, err := hex.DecodeString(entropyHex) + if err != nil { + return []byte{}, fmt.Errorf("error decoding hex string: %w", err) + } + + mnemonic, err := bip39.NewMnemonic(entropy) + if err != nil { + return []byte{}, fmt.Errorf("error generating mnemonic: %w", err) + } + + return []byte(mnemonic), nil +} + +// # Generates set of mnemonics from master mnemonic, accepts masterMnemonic string as byte +// +// Default function call MasterKeysGen([]byte("mnemonic string"), "", "", "./path") +// +// go run .\main.go --mnemonic "want vanish frown filter resemble purchase trial baby equal never cinnamon claim wrap cash snake cable head tray few daring shine clip loyal series" --masterkeys .\test\ --master +// +// # FOR PACKAGE USAGE +// +// defaultPrefix: "kira" +// +// defaultPath: "44'/118'/0'/0/0" +func MasterKeysGen(masterMnemonic []byte, defaultPrefix, defaultPath, masterkeys string) (mnemonicSet MasterMnemonicSet, err error) { + err = valkeygen.CheckMnemonic(string(masterMnemonic)) + if err != nil { + fmt.Fprintln(os.Stderr, err) + return mnemonicSet, err + } + + ok, err := valkeygen.CheckPath([]string{masterkeys}) + if err != nil { + fmt.Fprintln(os.Stderr, err) + fmt.Println(ok, masterkeys) + return mnemonicSet, err + } + + if ok { + // VALIDATOR_NODE_MNEMONIC + mnemonicSet.ValidatorNodeMnemonic, err = generateFromMasterMnemonic("validator", "node", masterMnemonic) + if err != nil { + fmt.Fprintln(os.Stderr, err) + return mnemonicSet, err + } + + // VALIDATOR_NODE_ID + mnemonicSet.ValidatorNodeId = generateNodeIdFromMnemonic(string(mnemonicSet.ValidatorNodeMnemonic)) + + // VALIDATOR_ADDR_MNEMONIC + mnemonicSet.ValidatorAddrMnemonic, err = generateFromMasterMnemonic("validator", "addr", masterMnemonic) + if err != nil { + fmt.Fprintln(os.Stderr, err) + return mnemonicSet, err + } + + // VALIDATOR_VAL_MNEMONIC + mnemonicSet.ValidatorValMnemonic, err = generateFromMasterMnemonic("validator", "val", masterMnemonic) + if err != nil { + fmt.Fprintln(os.Stderr, err) + return mnemonicSet, err + } + + // SIGNER_ADDR_MNEMONIC + mnemonicSet.SignerAddrMnemonic, err = generateFromMasterMnemonic("signer", "addr", masterMnemonic) + if err != nil { + fmt.Fprintln(os.Stderr, err) + return mnemonicSet, err + } + + // privKey mnemonic + mnemonicSet.PrivKeyMnemonic, err = DerivePrivKeyMnemonicFromMasterMnemonic(masterMnemonic) + if err != nil { + fmt.Fprintln(os.Stderr, err) + return mnemonicSet, err + } + + if masterkeys != "" { + // validator_node_key.json validator_node_id.key" files + valkeygen.ValKeyGen(string(mnemonicSet.ValidatorNodeMnemonic), defaultPrefix, defaultPath, "", + fmt.Sprintf("%s/%s", masterkeys, DefaultValidatorNodeKeyFileName), + fmt.Sprintf("%s/%s", masterkeys, DefaultValidatorNodeIdFileName), + false, false, false) + + // priv_validator_key.json files + valkeygen.ValKeyGen(string(mnemonicSet.ValidatorValMnemonic), defaultPrefix, defaultPath, fmt.Sprintf("%s/%s", masterkeys, DefaultPrivValidatorKeyFileName), "", "", false, false, false) + + // mnemonics.env file + dataToWrite := []byte(fmt.Sprintf("MASTER_MNEMONIC=%s\nVALIDATOR_ADDR_MNEMONIC=%s\nVALIDATOR_NODE_MNEMONIC=%s\nVALIDATOR_NODE_ID=%s\nVALIDATOR_VAL_MNEMONIC=%s\nSIGNER_ADDR_MNEMONIC=%s\n ", masterMnemonic, mnemonicSet.ValidatorAddrMnemonic, mnemonicSet.ValidatorNodeMnemonic, mnemonicSet.ValidatorNodeId, mnemonicSet.ValidatorValMnemonic, mnemonicSet.SignerAddrMnemonic)) + + err = createMnemonicsFile(fmt.Sprintf("%s/mnemonics.env", masterkeys), dataToWrite) + if err != nil { + fmt.Fprintln(os.Stderr, err) + return mnemonicSet, err + } + dataToWrite = []byte{} + + } + + } + return mnemonicSet, nil +} + +// Accepts parent mnemonic as masterMnemonic and derives from it a PrivKeyMnemonic using generateFromMasterMnemonic func +// salt is name and typeOfMnemonic hardcoded as const +// +// Constants: +// name=priv, +// typeOfMnemonic=key. +func DerivePrivKeyMnemonicFromMasterMnemonic(masterMnemonic []byte) (privKey []byte, err error) { + const name string = "priv" + const typeOfMnemonic string = "key" + err = valkeygen.CheckMnemonic(string(masterMnemonic)) + if err != nil { + return nil, err + } + privKey, err = generateFromMasterMnemonic(name, typeOfMnemonic, masterMnemonic) + if err != nil { + return nil, fmt.Errorf("error while generating ") + } + return +} diff --git a/validator-key-gen/ValKeyGen/valKeyGen.go b/validator-key-gen/ValKeyGen/valKeyGen.go new file mode 100644 index 00000000..c1101644 --- /dev/null +++ b/validator-key-gen/ValKeyGen/valKeyGen.go @@ -0,0 +1,253 @@ +package valkeygen + +import ( + "fmt" + "io" + "io/ioutil" + "os" + "path/filepath" + "strconv" + "strings" + + "github.com/cosmos/cosmos-sdk/crypto/hd" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/go-bip39" + "github.com/tendermint/tendermint/crypto/ed25519" + "github.com/tendermint/tendermint/p2p" + "github.com/tendermint/tendermint/privval" +) + + + +type Prefix struct { + fullPath *hd.BIP44Params + bech32MainPrefix string + prefixAccount string + prefixValidator string + prefixConsensus string + prefixPublic string + prefixOperator string + bech32PrefixAccAddr string + bech32PrefixAccPub string + bech32PrefixValAddr string + bech32PrefixValPub string + bech32PrefixConsAddr string + bech32PrefixConsPub string +} + +func (p *Prefix) New(bech32MainPrefix string, fullPath string) error { + var err error + + p.bech32MainPrefix = bech32MainPrefix + p.fullPath, err = hd.NewParamsFromPath(fullPath) + if err != nil { + return err + } + + // PrefixAccount is the prefix for account keys + p.prefixAccount = "acc" + // PrefixValidator is the prefix for validator keys + p.prefixValidator = "val" + // PrefixConsensus is the prefix for consensus keys + p.prefixConsensus = "cons" + // PrefixPublic is the prefix for public keys + p.prefixPublic = "pub" + // PrefixOperator is the prefix for operator keys + p.prefixOperator = "oper" + // Bech32PrefixAccAddr defines the Bech32 prefix of an account's address + p.bech32PrefixAccAddr = p.bech32MainPrefix + // Bech32PrefixAccPub defines the Bech32 prefix of an account's public key + p.bech32PrefixAccPub = p.bech32MainPrefix + p.prefixPublic + // Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address + p.bech32PrefixValAddr = p.bech32MainPrefix + p.prefixValidator + p.prefixOperator + // Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key + p.bech32PrefixValPub = p.bech32MainPrefix + p.prefixValidator + p.prefixOperator + p.prefixPublic + // Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address + p.bech32PrefixConsAddr = p.bech32MainPrefix + p.prefixValidator + p.prefixConsensus + // Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key + p.bech32PrefixConsPub = p.bech32MainPrefix + p.prefixValidator + p.prefixConsensus + p.prefixPublic + return nil +} + +// TODO +// * add output plain, json + +func (p *Prefix) GetBech32PrefixAccAddr() string { + return p.bech32PrefixAccAddr +} + +func (p *Prefix) GetBech32PrefixAccPub() string { + return p.bech32PrefixAccPub +} +func (p *Prefix) GetBech32PrefixValAddr() string { + return p.bech32PrefixValAddr +} +func (p *Prefix) GetBech32PrefixValPub() string { + return p.bech32PrefixValPub +} +func (p *Prefix) GetBech32PrefixConsAddr() string { + return p.bech32PrefixConsAddr +} +func (p *Prefix) GetBech32PrefixConsPub() string { + return p.bech32PrefixConsPub +} + +func (p *Prefix) ParsePath(path string) (uint32, uint32, uint32, error) { + // Split path into its components + parts := strings.Split(path, "/") + if len(parts) != 5 { + return 0, 0, 0, fmt.Errorf("Invalid BIP44 path") + } + + // Check that the first part is "m" + if parts[0] != "m" { + return 0, 0, 0, fmt.Errorf("Invalid BIP44 path") + } + + // Parse account, chain, and address indexes + accountIndex, err := strconv.Atoi(strings.TrimSuffix(parts[2], "'")) + if err != nil { + return 0, 0, 0, fmt.Errorf("Invalid BIP44 path") + } + chainIndex, err := strconv.Atoi(parts[3]) + if err != nil { + return 0, 0, 0, fmt.Errorf("Invalid BIP44 path") + } + addressIndex, err := strconv.Atoi(parts[4]) + if err != nil { + return 0, 0, 0, fmt.Errorf("Invalid BIP44 path") + } + + return uint32(accountIndex), uint32(chainIndex), uint32(addressIndex), nil +} + +// function to check if paths exist and not empty +func CheckPath(path []string) (ok bool, err error) { + // Check if there are any paths provided + empty_path := 0 + for _, p := range path { + if p == "" { + empty_path++ + } + } + + // Check if paths are exist + if empty_path == 0 { + for _, p := range path { + dir := filepath.Dir(p) + // Check if the directory exists + _, err := os.Stat(dir) + switch os.IsNotExist(err) { + case true: + return false, err + } + + } + } + + if empty_path == 3 { + return false, nil + } + return true, nil +} + +func CheckMnemonic(mnemonic string) error { + if len(mnemonic) == 0 { + return fmt.Errorf("mnemonic can't be empty") + } + words := strings.Split(mnemonic, " ") + if len(words) != 12 && len(words) != 24 { + return fmt.Errorf("mnemonic should be 12 or 24 words") + } + + if isValid := bip39.IsMnemonicValid(mnemonic); !isValid { + return fmt.Errorf("mnemonic is invalid!") + } + return nil +} + +var out io.Writer = os.Stdout + +func ValKeyGen(mnemonic, defaultPrefix, defaultPath, valkey, nodekey, keyid string, acadr, valadr, consadr bool) { + prefix := Prefix{} + + // Setting up prefix with default or provided values + err := prefix.New(defaultPrefix, defaultPath) + if err != nil { + panic(fmt.Errorf("malformed prefix %v", err)) + } + + // Check if mnemonic is provided and valid + if err := CheckMnemonic(mnemonic); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + // Generate HD(Hierarchical Deterministic) path from string + hdPath, err := hd.NewParamsFromPath(defaultPath) + if err != nil { + panic(err) + } + + // Generate tendermint MASTER private key from mnemonic + tmPrivKey := ed25519.GenPrivKeyFromSecret([]byte(mnemonic)) + + // Generate tenderming private key from MASTER key + //tmPrivKey := ed25519.GenPrivKeyFromSecret(tmMasterPrivKey.Bytes()) + + // Derive MASTER key from mnemonic and HD path + masterPrivKey, err := hd.Secp256k1.Derive()(mnemonic, "", hdPath.String()) + + // Generate private key from MASTER key + privKey := hd.Secp256k1.Generate()(masterPrivKey) + pubKey := privKey.PubKey() + + config := sdk.GetConfig() + config.SetBech32PrefixForAccount(prefix.GetBech32PrefixAccAddr(), prefix.GetBech32PrefixAccPub()) + config.SetBech32PrefixForValidator(prefix.GetBech32PrefixValAddr(), prefix.GetBech32PrefixValPub()) + config.SetBech32PrefixForConsensusNode(prefix.GetBech32PrefixConsAddr(), prefix.GetBech32PrefixConsPub()) + config.SetPurpose(prefix.fullPath.Purpose) + config.SetCoinType(prefix.fullPath.CoinType) + // config.Seal() + if ok, err := CheckPath([]string{valkey, nodekey, keyid}); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } else { + if ok { + filepvkey := privval.NewFilePV(tmPrivKey, valkey, "").Key + filenodekey := p2p.NodeKey{ + PrivKey: tmPrivKey, + } + + if len(valkey) != 0 { + filepvkey.Save() + + } + if len(nodekey) != 0 { + err = filenodekey.SaveAs(nodekey) + if err != nil { + panic(err) + } + } + if len(keyid) != 0 { + err = ioutil.WriteFile(keyid, []byte(filenodekey.ID()), 0644) + if err != nil { + panic(err) + } + } + + } else { + if acadr { + fmt.Fprintln(out, sdk.AccAddress(pubKey.Address().Bytes()).String()) + } + if valadr { + fmt.Fprintln(out, sdk.ValAddress(pubKey.Address()).String()) + } + if consadr { + fmt.Fprintln(out, sdk.ConsAddress(pubKey.Address().Bytes()).String()) + } + + } + } + +} From 1f1c5219c0f190d02cdd27cec8baa07feebbf7a8 Mon Sep 17 00:00:00 2001 From: PeepoFrog Date: Sat, 24 Feb 2024 17:17:11 +0200 Subject: [PATCH 02/14] Added tests for key generation --- .../mnemonicsGenerator_test.go | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 validator-key-gen/MnemonicsGenerator/mnemonicsGenerator_test.go diff --git a/validator-key-gen/MnemonicsGenerator/mnemonicsGenerator_test.go b/validator-key-gen/MnemonicsGenerator/mnemonicsGenerator_test.go new file mode 100644 index 00000000..7dc5144b --- /dev/null +++ b/validator-key-gen/MnemonicsGenerator/mnemonicsGenerator_test.go @@ -0,0 +1,160 @@ +package mnemonicsgenerator_test + +import ( + "fmt" + "os" + "reflect" + "testing" + + mnemonicsgenerator "github.com/PeepoFrog/validator-key-gen/MnemonicsGenerator" +) + +// Test mnemonic: +// +// MASTER_MNEMONIC=bargain erosion electric skill extend aunt unfold cricket spice sudden insane shock purpose trumpet holiday tornado fiction check pony acoustic strike side gold resemble +// VALIDATOR_ADDR_MNEMONIC=result tank riot circle cost hundred exotic soft angle bulb sunset margin virus simple bean topic next initial embody sample ordinary what pulp engage +// VALIDATOR_NODE_MNEMONIC=shed history misery describe sail sight know snake route humor soda gossip lonely torch state drama salmon jungle possible lock runway wild cross tank +// VALIDATOR_NODE_ID=935ea41280fa8754a35bd2916d935f222b559488 +// VALIDATOR_VAL_MNEMONIC=stick about junk liberty same envelope boy machine zoo wide shrimp clutch oval mango diary strike round divorce toilet cross guard appear govern chief +// SIGNER_ADDR_MNEMONIC=near spirit dial february access song panda clean diesel legend clock remind name pupil drum general trap afford tuition side dune address alpha stool + +// files to test: + +// cat node_key.json +// {"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"XI+eMf0mqqX5a07cAgxBWpLKq8AicMETxQQoLIhxBw1u8GRu0kGFZ2jPpJhwp/aEUL9dPaGZ5taNaQFA0i8cMA=="}} + +// cat priv_validator_key.json && echo +// { +// "address": "47E4C09C2BF5782B634BF393D394464BE08728A7", +// "pub_key": { +// "type": "tendermint/PubKeyEd25519", +// "value": "jNh+yX/KQRAON8KnwI+fawpRcKpUFyqolEn4dAaESNI=" +// }, +// "priv_key": { +// "type": "tendermint/PrivKeyEd25519", +// "value": "OYqWRyEl48LdMSihUM3f2pv9LARabDZeeqmUqXejOzSM2H7Jf8pBEA43wqfAj59rClFwqlQXKqiUSfh0BoRI0g==" +// } +// } + +// cat validator_node_id.key +// 935ea41280fa8754a35bd2916d935f222b559488 + +const masterMnemonicForTest string = "bargain erosion electric skill extend aunt unfold cricket spice sudden insane shock purpose trumpet holiday tornado fiction check pony acoustic strike side gold resemble" + +var ( + nodeKeyForTest string = `{"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"XI+eMf0mqqX5a07cAgxBWpLKq8AicMETxQQoLIhxBw1u8GRu0kGFZ2jPpJhwp/aEUL9dPaGZ5taNaQFA0i8cMA=="}}` + + privValdatorKeyTest string = `{ + "address": "47E4C09C2BF5782B634BF393D394464BE08728A7", + "pub_key": { + "type": "tendermint/PubKeyEd25519", + "value": "jNh+yX/KQRAON8KnwI+fawpRcKpUFyqolEn4dAaESNI=" + }, + "priv_key": { + "type": "tendermint/PrivKeyEd25519", + "value": "OYqWRyEl48LdMSihUM3f2pv9LARabDZeeqmUqXejOzSM2H7Jf8pBEA43wqfAj59rClFwqlQXKqiUSfh0BoRI0g==" + } +}` + + wantedMnemonicSet mnemonicsgenerator.MasterMnemonicSet = mnemonicsgenerator.MasterMnemonicSet{ + ValidatorAddrMnemonic: []byte("result tank riot circle cost hundred exotic soft angle bulb sunset margin virus simple bean topic next initial embody sample ordinary what pulp engage"), + ValidatorNodeMnemonic: []byte("shed history misery describe sail sight know snake route humor soda gossip lonely torch state drama salmon jungle possible lock runway wild cross tank"), + ValidatorValMnemonic: []byte("stick about junk liberty same envelope boy machine zoo wide shrimp clutch oval mango diary strike round divorce toilet cross guard appear govern chief"), + SignerAddrMnemonic: []byte("near spirit dial february access song panda clean diesel legend clock remind name pupil drum general trap afford tuition side dune address alpha stool"), + ValidatorNodeId: []byte("935ea41280fa8754a35bd2916d935f222b559488"), + PrivKeyMnemonic: []byte("trash conduct welcome seek people duty enter monkey turtle holiday husband recall iron check gorilla bottom amused clump glue culture kidney news umbrella cancel"), + } +) + +// This test excludes PrivKeyMnemonic to check if func return the proper origin mnemonics from original tool +func TestMasterKeysGenWithOutPrivKeyMnemonic(t *testing.T) { + got, err := mnemonicsgenerator.MasterKeysGen([]byte(masterMnemonicForTest), mnemonicsgenerator.DefaultPrefix, mnemonicsgenerator.DefaultPath, "") + if err != nil { + t.Errorf("MasterKeysGen(%+s)\n error = %v", masterMnemonicForTest, err) + return + } + switch { + case string(wantedMnemonicSet.ValidatorAddrMnemonic) != string(got.ValidatorAddrMnemonic): + t.Errorf("wrong mnemonic: %v", string(got.ValidatorValMnemonic)) + case string(wantedMnemonicSet.ValidatorNodeMnemonic) != string(got.ValidatorNodeMnemonic): + t.Errorf("wrong mnemonic: %v", string(got.ValidatorNodeMnemonic)) + case string(wantedMnemonicSet.ValidatorValMnemonic) != string(got.ValidatorValMnemonic): + t.Errorf("wrong mnemonic: %v", string(got.ValidatorValMnemonic)) + case string(wantedMnemonicSet.SignerAddrMnemonic) != string(got.SignerAddrMnemonic): + t.Errorf("wrong mnemonic: %v", string(got.SignerAddrMnemonic)) + case string(wantedMnemonicSet.ValidatorNodeId) != string(got.ValidatorNodeId): + t.Errorf("wrong mnemonic: %v", string(got.ValidatorNodeId)) + } +} + +func TestMasterKeysGen(t *testing.T) { + mnemonicSetTest := []struct { + name string + masterMnemonic []byte + want mnemonicsgenerator.MasterMnemonicSet + wantErr bool + }{ + { + name: "working mnemonic", + masterMnemonic: []byte(masterMnemonicForTest), + want: wantedMnemonicSet, + wantErr: false, + }, + } + tmpFolder := os.TempDir() + for _, tt := range mnemonicSetTest { + t.Run(tt.name, func(t *testing.T) { + got, err := mnemonicsgenerator.MasterKeysGen(tt.masterMnemonic, mnemonicsgenerator.DefaultPrefix, mnemonicsgenerator.DefaultPath, tmpFolder) + if (err != nil) != tt.wantErr { + t.Errorf("MasterKeysGen(%+s)\n error = %v\n wantErr %v\n", string(tt.masterMnemonic), err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("ProcessData(%s) = %+v\n want %+v", string(tt.masterMnemonic), got, tt.want) + } + }) + } + + keyFileTest := []struct { + name string + fileName string + wantedData string + wantErr bool + }{ + { + name: mnemonicsgenerator.DefaultValidatorNodeKeyFileName, + fileName: fmt.Sprintf("%s/%s", tmpFolder, mnemonicsgenerator.DefaultValidatorNodeKeyFileName), + wantedData: nodeKeyForTest, + wantErr: false, + }, + { + name: mnemonicsgenerator.DefaultPrivValidatorKeyFileName, + fileName: fmt.Sprintf("%s/%s", tmpFolder, mnemonicsgenerator.DefaultPrivValidatorKeyFileName), + wantedData: privValdatorKeyTest, + wantErr: false, + }, + } + + for _, tt := range keyFileTest { + + out, err := os.ReadFile(tt.fileName) + if (err != nil) != tt.wantErr { + t.Errorf("unable to read %s file, error = %v", tt.fileName, err) + return + } + if string(out) != tt.wantedData { + t.Errorf("wrong key\nExpected: %v\nReceived: %v", []byte(tt.wantedData), out) + } + + } +} + +func TestDerivePrivKeyMnemonicFromMasterMnemonic(t *testing.T) { + privKeyMnemonic, err := mnemonicsgenerator.DerivePrivKeyMnemonicFromMasterMnemonic([]byte(masterMnemonicForTest)) + if err != nil { + t.Errorf("unable to derive privKey mnemonic from <%s>, error: %v", masterMnemonicForTest, err) + } + if string(privKeyMnemonic) != string(wantedMnemonicSet.PrivKeyMnemonic) { + t.Errorf("derived privKey mnemonic is not equal to wanted mnemonic\nGot: %s\nWanted:%s", privKeyMnemonic, wantedMnemonicSet.PrivKeyMnemonic) + } +} From 32f448bddd3e1d5d3c17a43767890901a2583248 Mon Sep 17 00:00:00 2001 From: PeepoFrog Date: Sat, 24 Feb 2024 17:19:26 +0200 Subject: [PATCH 03/14] import fix --- validator-key-gen/MnemonicsGenerator/mnemonicsGenerator_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator-key-gen/MnemonicsGenerator/mnemonicsGenerator_test.go b/validator-key-gen/MnemonicsGenerator/mnemonicsGenerator_test.go index 7dc5144b..eabb74f3 100644 --- a/validator-key-gen/MnemonicsGenerator/mnemonicsGenerator_test.go +++ b/validator-key-gen/MnemonicsGenerator/mnemonicsGenerator_test.go @@ -6,7 +6,7 @@ import ( "reflect" "testing" - mnemonicsgenerator "github.com/PeepoFrog/validator-key-gen/MnemonicsGenerator" + mnemonicsgenerator "github.com/KiraCore/tools/validator-key-gen/MnemonicsGenerator" ) // Test mnemonic: From b32839b39e785ce4c6e9c9a5a32f98588bd70470 Mon Sep 17 00:00:00 2001 From: PeepoFrog Date: Sat, 24 Feb 2024 17:20:16 +0200 Subject: [PATCH 04/14] refactored for package ussage, now importing default path and name values from package --- validator-key-gen/main.go | 271 +++----------------------------------- 1 file changed, 19 insertions(+), 252 deletions(-) diff --git a/validator-key-gen/main.go b/validator-key-gen/main.go index d81b154f..ba724ee0 100644 --- a/validator-key-gen/main.go +++ b/validator-key-gen/main.go @@ -3,256 +3,13 @@ package main import ( "flag" "fmt" - "io" - "io/ioutil" "os" - "path/filepath" - "strconv" - "strings" - "github.com/cosmos/cosmos-sdk/crypto/hd" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/go-bip39" - "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/p2p" - "github.com/tendermint/tendermint/privval" + mnemonicsgenerator "github.com/KiraCore/tools/validator-key-gen/MnemonicsGenerator" + valkeygen "github.com/KiraCore/tools/validator-key-gen/ValKeyGen" ) -const PrivValidatorKeyGenVersion = "v0.3.46" - -type Prefix struct { - fullPath *hd.BIP44Params - bech32MainPrefix string - prefixAccount string - prefixValidator string - prefixConsensus string - prefixPublic string - prefixOperator string - bech32PrefixAccAddr string - bech32PrefixAccPub string - bech32PrefixValAddr string - bech32PrefixValPub string - bech32PrefixConsAddr string - bech32PrefixConsPub string -} - -func (p *Prefix) New(bech32MainPrefix string, fullPath string) error { - var err error - - p.bech32MainPrefix = bech32MainPrefix - p.fullPath, err = hd.NewParamsFromPath(fullPath) - if err != nil { - return err - } - - // PrefixAccount is the prefix for account keys - p.prefixAccount = "acc" - // PrefixValidator is the prefix for validator keys - p.prefixValidator = "val" - // PrefixConsensus is the prefix for consensus keys - p.prefixConsensus = "cons" - // PrefixPublic is the prefix for public keys - p.prefixPublic = "pub" - // PrefixOperator is the prefix for operator keys - p.prefixOperator = "oper" - // Bech32PrefixAccAddr defines the Bech32 prefix of an account's address - p.bech32PrefixAccAddr = p.bech32MainPrefix - // Bech32PrefixAccPub defines the Bech32 prefix of an account's public key - p.bech32PrefixAccPub = p.bech32MainPrefix + p.prefixPublic - // Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address - p.bech32PrefixValAddr = p.bech32MainPrefix + p.prefixValidator + p.prefixOperator - // Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key - p.bech32PrefixValPub = p.bech32MainPrefix + p.prefixValidator + p.prefixOperator + p.prefixPublic - // Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address - p.bech32PrefixConsAddr = p.bech32MainPrefix + p.prefixValidator + p.prefixConsensus - // Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key - p.bech32PrefixConsPub = p.bech32MainPrefix + p.prefixValidator + p.prefixConsensus + p.prefixPublic - return nil -} - -// TODO -// * add output plain, json - -func (p *Prefix) GetBech32PrefixAccAddr() string { - return p.bech32PrefixAccAddr -} - -func (p *Prefix) GetBech32PrefixAccPub() string { - return p.bech32PrefixAccPub -} -func (p *Prefix) GetBech32PrefixValAddr() string { - return p.bech32PrefixValAddr -} -func (p *Prefix) GetBech32PrefixValPub() string { - return p.bech32PrefixValPub -} -func (p *Prefix) GetBech32PrefixConsAddr() string { - return p.bech32PrefixConsAddr -} -func (p *Prefix) GetBech32PrefixConsPub() string { - return p.bech32PrefixConsPub -} - -func (p *Prefix) ParsePath(path string) (uint32, uint32, uint32, error) { - // Split path into its components - parts := strings.Split(path, "/") - if len(parts) != 5 { - return 0, 0, 0, fmt.Errorf("Invalid BIP44 path") - } - - // Check that the first part is "m" - if parts[0] != "m" { - return 0, 0, 0, fmt.Errorf("Invalid BIP44 path") - } - - // Parse account, chain, and address indexes - accountIndex, err := strconv.Atoi(strings.TrimSuffix(parts[2], "'")) - if err != nil { - return 0, 0, 0, fmt.Errorf("Invalid BIP44 path") - } - chainIndex, err := strconv.Atoi(parts[3]) - if err != nil { - return 0, 0, 0, fmt.Errorf("Invalid BIP44 path") - } - addressIndex, err := strconv.Atoi(parts[4]) - if err != nil { - return 0, 0, 0, fmt.Errorf("Invalid BIP44 path") - } - - return uint32(accountIndex), uint32(chainIndex), uint32(addressIndex), nil -} - -// function to check if paths exist and not empty -func checkPath(path []string) (ok bool, err error) { - // Check if there are any paths provided - empty_path := 0 - for _, p := range path { - if p == "" { - empty_path++ - } - } - - // Check if paths are exist - if empty_path == 0 { - for _, p := range path { - dir := filepath.Dir(p) - // Check if the directory exists - _, err := os.Stat(dir) - switch os.IsNotExist(err) { - case true: - return false, err - } - - } - } - - if empty_path == 3 { - return false, nil - } - return true, nil -} - -func checkMnemonic(mnemonic string) error { - if len(mnemonic) == 0 { - return fmt.Errorf("mnemonic can't be empty") - } - words := strings.Split(mnemonic, " ") - if len(words) != 12 && len(words) != 24 { - return fmt.Errorf("mnemonic should be 12 or 24 words") - } - - if isValid := bip39.IsMnemonicValid(mnemonic); !isValid { - return fmt.Errorf("mnemonic is invalid!") - } - return nil -} - -var out io.Writer = os.Stdout - -func ValKeyGen(mnemonic, defaultPrefix, defaultPath, valkey, nodekey, keyid string, acadr, valadr, consadr bool) { - prefix := Prefix{} - - // Setting up prefix with default or provided values - err := prefix.New(defaultPrefix, defaultPath) - if err != nil { - panic(fmt.Errorf("malformed prefix %v", err)) - } - - // Check if mnemonic is provided and valid - if err := checkMnemonic(mnemonic); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - - // Generate HD(Hierarchical Deterministic) path from string - hdPath, err := hd.NewParamsFromPath(defaultPath) - if err != nil { - panic(err) - } - - // Generate tendermint MASTER private key from mnemonic - tmPrivKey := ed25519.GenPrivKeyFromSecret([]byte(mnemonic)) - - // Generate tenderming private key from MASTER key - //tmPrivKey := ed25519.GenPrivKeyFromSecret(tmMasterPrivKey.Bytes()) - - // Derive MASTER key from mnemonic and HD path - masterPrivKey, err := hd.Secp256k1.Derive()(mnemonic, "", hdPath.String()) - - // Generate private key from MASTER key - privKey := hd.Secp256k1.Generate()(masterPrivKey) - pubKey := privKey.PubKey() - - config := sdk.GetConfig() - config.SetBech32PrefixForAccount(prefix.GetBech32PrefixAccAddr(), prefix.GetBech32PrefixAccPub()) - config.SetBech32PrefixForValidator(prefix.GetBech32PrefixValAddr(), prefix.GetBech32PrefixValPub()) - config.SetBech32PrefixForConsensusNode(prefix.GetBech32PrefixConsAddr(), prefix.GetBech32PrefixConsPub()) - config.SetPurpose(prefix.fullPath.Purpose) - config.SetCoinType(prefix.fullPath.CoinType) - config.Seal() - - if ok, err := checkPath([]string{valkey, nodekey, keyid}); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } else { - if ok { - filepvkey := privval.NewFilePV(tmPrivKey, valkey, "").Key - filenodekey := p2p.NodeKey{ - PrivKey: tmPrivKey, - } - - if len(valkey) != 0 { - filepvkey.Save() - - } - if len(nodekey) != 0 { - err = filenodekey.SaveAs(nodekey) - if err != nil { - panic(err) - } - } - if len(keyid) != 0 { - err = ioutil.WriteFile(keyid, []byte(filenodekey.ID()), 0644) - if err != nil { - panic(err) - } - } - - } else { - if acadr { - fmt.Fprintln(out, sdk.AccAddress(pubKey.Address().Bytes()).String()) - } - if valadr { - fmt.Fprintln(out, sdk.ValAddress(pubKey.Address()).String()) - } - if consadr { - fmt.Fprintln(out, sdk.ConsAddress(pubKey.Address().Bytes()).String()) - } - - } - } - -} +const PrivValidatorKeyGenVersion = "v0.3.47" func main() { @@ -265,23 +22,27 @@ func main() { defaultPath string // Output path block - valkey string - nodekey string - keyid string + valkey string + nodekey string + keyid string + masterkeys string // Printout options block acadr bool valadr bool consadr bool version bool + master bool ) fs := flag.NewFlagSet("validator-key-gen", flag.ExitOnError) fs.StringVar(&mnemonic, "mnemonic", "", "Valid BIP39 mnemonic(required)") + fs.BoolVar(&master, "master", false, "boolean , if true - generate whole mnemonic set") // Path to place files. Path should exist. + fs.StringVar(&masterkeys, "masterkeys", "", "path, where master's mnemonic set and keys key files will be placed") fs.StringVar(&valkey, "valkey", "", "path, where validator key json file will be placed") fs.StringVar(&nodekey, "nodekey", "", "path, where node key json file will be placed") fs.StringVar(&keyid, "keyid", "", "path, where NodeID file will be placed") @@ -294,9 +55,9 @@ func main() { //Set prefix - fs.StringVar(&defaultPrefix, "prefix", "kira", "set prefix") + fs.StringVar(&defaultPrefix, "prefix", mnemonicsgenerator.DefaultPrefix, "set prefix") //Set derive path - fs.StringVar(&defaultPath, "path", "44'/118'/0'/0/0", "set derive path") + fs.StringVar(&defaultPath, "path", mnemonicsgenerator.DefaultPath, "set derive path") fs.Usage = func() { fmt.Printf("Usage: %s --mnemonic=\"over where ...\" [OPTIONS]\n\n", fs.Name()) @@ -315,7 +76,13 @@ func main() { fmt.Fprintln(os.Stdout, PrivValidatorKeyGenVersion) os.Exit(0) case false: - ValKeyGen(mnemonic, defaultPrefix, defaultPath, valkey, nodekey, keyid, acadr, valadr, consadr) + if master { + mnemonicsgenerator.MasterKeysGen([]byte(mnemonic), defaultPrefix, defaultPath, masterkeys) + } else { + valkeygen.ValKeyGen(mnemonic, defaultPrefix, defaultPath, valkey, nodekey, keyid, acadr, valadr, consadr) + + } + } } From 444b067d54a1d59e5cd077520bc9e3757fc820be Mon Sep 17 00:00:00 2001 From: mrlutik Date: Sun, 25 Feb 2024 14:04:20 +0100 Subject: [PATCH 05/14] Bump release ver. Update README.md --- RELEASE.md | 4 +++- scripts/version.sh | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 07d16176..09ec7625 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,2 +1,4 @@ Features: -* bu: add curl check +* Refactor: validator-key-gen refactored for package usage +* Add: new mnemonic to set - PrivKeyMnemonic + diff --git a/scripts/version.sh b/scripts/version.sh index c304e4ed..460f5add 100644 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo "v0.3.46" +echo "v0.3.47" From 4c61e5be5643a2f4ef599e82c9bd3be26ea7adaf Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 12 Mar 2024 15:05:57 +0100 Subject: [PATCH 06/14] bump release ver --- scripts/version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/version.sh b/scripts/version.sh index 460f5add..cf15fdc3 100644 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo "v0.3.47" +echo "v0.3.48" From 3a71f8eafdb1d3bedf8a566352a8b6fec6ddb72b Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 12 Mar 2024 15:08:54 +0100 Subject: [PATCH 07/14] bump ver --- .github/workflows/main.yml | 4 ++-- scripts/version.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d4cca7bc..246e45f4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ on: jobs: build-amd64: name: AMD64 - Repo Test & Build - runs-on: [ self-hosted, github-actions-amd64-runner-2 ] + runs-on: ubuntu:20.04 permissions: contents: read packages: write @@ -419,4 +419,4 @@ jobs: env: MERGE_LABELS: "automerge" GITHUB_TOKEN: "${{ secrets.REPO_ACCESS }}" - LOG: "TRACE" \ No newline at end of file + LOG: "TRACE" diff --git a/scripts/version.sh b/scripts/version.sh index cf15fdc3..8ef7c285 100644 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo "v0.3.48" +echo "v0.3.49" From 3db07730ea2ea7b27503e7ce7986fa9728fb79ff Mon Sep 17 00:00:00 2001 From: mrlutik Date: Wed, 13 Mar 2024 15:52:28 +0100 Subject: [PATCH 08/14] Return to self-hosted runner --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 246e45f4..495e339a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ on: jobs: build-amd64: name: AMD64 - Repo Test & Build - runs-on: ubuntu:20.04 + runs-on: [ self-hosted, github-actions-amd64-runner-2 ] permissions: contents: read packages: write From 29ca51dbe1e0598443affa894e2b35392e1a5033 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Wed, 13 Mar 2024 15:53:13 +0100 Subject: [PATCH 09/14] bump release ver --- scripts/version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/version.sh b/scripts/version.sh index 8ef7c285..9270e037 100644 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo "v0.3.49" +echo "v0.3.50" From 814fd53c131864297512f76c9dac7b161ccfb1c5 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Wed, 13 Mar 2024 16:21:50 +0100 Subject: [PATCH 10/14] bump all ver --- bash-utils/bash-utils.sh | 3 ++- bip39gen/cmd/version.go | 2 +- build-tools/update_version.py | 2 +- ipfs-api/README.md | 2 +- ipfs-api/types/constants.go | 2 +- scripts/version.sh | 2 +- validator-key-gen/README.md | 2 +- validator-key-gen/main.go | 2 +- 8 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bash-utils/bash-utils.sh b/bash-utils/bash-utils.sh index 19111252..04ce2d16 100644 --- a/bash-utils/bash-utils.sh +++ b/bash-utils/bash-utils.sh @@ -26,7 +26,7 @@ function bashUtilsVersion() { # this is default installation script for utils # ./bash-utils.sh bashUtilsSetup "/var/kiraglob" function bashUtilsSetup() { - local BASH_UTILS_VERSION="v0.3.46" + local BASH_UTILS_VERSION="v0.3.51" local COSIGN_VERSION="v2.0.0" if [ "$1" == "version" ] ; then echo "$BASH_UTILS_VERSION" @@ -2322,3 +2322,4 @@ fi + diff --git a/bip39gen/cmd/version.go b/bip39gen/cmd/version.go index 0df9ecd5..b5e531ae 100644 --- a/bip39gen/cmd/version.go +++ b/bip39gen/cmd/version.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -const Bip39GenVersion = "v0.3.46" +const Bip39GenVersion = "v0.3.51" func cmdVersion(cmd *cobra.Command, args []string) error { fmt.Println(Bip39GenVersion) diff --git a/build-tools/update_version.py b/build-tools/update_version.py index 4c4706c6..bedc22ae 100644 --- a/build-tools/update_version.py +++ b/build-tools/update_version.py @@ -1,7 +1,7 @@ import re import sys -version = "v0.3.46" +version = "v0.3.51" if len(sys.argv) != 2: print("Usage: python3 update_version.py ") diff --git a/ipfs-api/README.md b/ipfs-api/README.md index 5fc5b19b..11b9acfd 100644 --- a/ipfs-api/README.md +++ b/ipfs-api/README.md @@ -5,7 +5,7 @@ A command-line interface (CLI) for interacting with the IPFS API, providing func To install the CLI, clone the repository and build the project using Go.= or dowload from existing release ``` -TOOLS_VERSION="v0.3.46" && rm -rfv /tmp/ipfs-api && \ +TOOLS_VERSION="v0.3.51" && rm -rfv /tmp/ipfs-api && \ safeWget /tmp/ipfs-api.deb "https://github.com/KiraCore/tools/releases/download/$TOOLS_VERSION/ipfs-api-$(getPlatform)-$(getArch).deb" "QmeqFDLGfwoWgCy2ZEFXerVC5XW8c5xgRyhK5bLArBr2ue" && \ dpkg-deb -x /tmp/ipfs-api.deb /tmp/ipfs-api && cp -fv "/tmp/ipfs-api/bin/ipfs-api" /usr/local/bin/ipfs-api && chmod -v 755 /usr/local/bin/ipfs-api && \ ipfs-api version diff --git a/ipfs-api/types/constants.go b/ipfs-api/types/constants.go index f59a0b37..c4c612fd 100644 --- a/ipfs-api/types/constants.go +++ b/ipfs-api/types/constants.go @@ -1,7 +1,7 @@ package types const ( - IpfsApiVersion = "v0.3.46" + IpfsApiVersion = "v0.3.51" // Pinata v1 constants BASE_URL = "https://api.pinata.cloud" diff --git a/scripts/version.sh b/scripts/version.sh index 9270e037..cb892df1 100644 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo "v0.3.50" +echo "v0.3.51" diff --git a/validator-key-gen/README.md b/validator-key-gen/README.md index 477f1446..1df19f33 100644 --- a/validator-key-gen/README.md +++ b/validator-key-gen/README.md @@ -5,7 +5,7 @@ Validator Key Generator is a CLI tool that generates validator keys, node keys, ### Setup from binary file ```bash -TOOLS_VERSION="v0.3.46" +TOOLS_VERSION="v0.3.51" # Quick-Install bash-utils or see root repository README file for secure download FILE_NAME="bash-utils.sh" && \ diff --git a/validator-key-gen/main.go b/validator-key-gen/main.go index ba724ee0..b8ce8be7 100644 --- a/validator-key-gen/main.go +++ b/validator-key-gen/main.go @@ -9,7 +9,7 @@ import ( valkeygen "github.com/KiraCore/tools/validator-key-gen/ValKeyGen" ) -const PrivValidatorKeyGenVersion = "v0.3.47" +const PrivValidatorKeyGenVersion = "v0.3.51" func main() { From 51b6df1967e438ee6b903e3cb731458dea8d96ed Mon Sep 17 00:00:00 2001 From: mrlutik Date: Wed, 13 Mar 2024 16:53:24 +0100 Subject: [PATCH 11/14] change cosign installer --- .github/workflows/main.yml | 4 ++-- bash-utils/bash-utils.sh | 4 +++- bip39gen/cmd/version.go | 2 +- build-tools/update_version.py | 2 +- ipfs-api/README.md | 2 +- ipfs-api/types/constants.go | 2 +- scripts/version.sh | 2 +- validator-key-gen/README.md | 2 +- validator-key-gen/main.go | 2 +- 9 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 495e339a..28669d54 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -227,9 +227,9 @@ jobs: id-token: write pull-requests: write steps: - # ref.: https://github.com/sigstore/cosign-installer, v3.0.1 + # ref.: https://github.com/sigstore/cosign-installer, v3.2.0 - name: Install cosign - uses: sigstore/cosign-installer@c3667d99424e7e6047999fb6246c0da843953c65 + uses: sigstore/cosign-installer@1fc5bd396d372bee37d608f955b336615edf79c8 with: cosign-release: 'v2.0.0' - name: Download AMD64 artifacts diff --git a/bash-utils/bash-utils.sh b/bash-utils/bash-utils.sh index 04ce2d16..7ff4d19a 100644 --- a/bash-utils/bash-utils.sh +++ b/bash-utils/bash-utils.sh @@ -26,7 +26,7 @@ function bashUtilsVersion() { # this is default installation script for utils # ./bash-utils.sh bashUtilsSetup "/var/kiraglob" function bashUtilsSetup() { - local BASH_UTILS_VERSION="v0.3.51" + local BASH_UTILS_VERSION="v0.3.52" local COSIGN_VERSION="v2.0.0" if [ "$1" == "version" ] ; then echo "$BASH_UTILS_VERSION" @@ -2323,3 +2323,5 @@ fi + + diff --git a/bip39gen/cmd/version.go b/bip39gen/cmd/version.go index b5e531ae..150a00ba 100644 --- a/bip39gen/cmd/version.go +++ b/bip39gen/cmd/version.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -const Bip39GenVersion = "v0.3.51" +const Bip39GenVersion = "v0.3.52" func cmdVersion(cmd *cobra.Command, args []string) error { fmt.Println(Bip39GenVersion) diff --git a/build-tools/update_version.py b/build-tools/update_version.py index bedc22ae..86d21510 100644 --- a/build-tools/update_version.py +++ b/build-tools/update_version.py @@ -1,7 +1,7 @@ import re import sys -version = "v0.3.51" +version = "v0.3.52" if len(sys.argv) != 2: print("Usage: python3 update_version.py ") diff --git a/ipfs-api/README.md b/ipfs-api/README.md index 11b9acfd..75ff439f 100644 --- a/ipfs-api/README.md +++ b/ipfs-api/README.md @@ -5,7 +5,7 @@ A command-line interface (CLI) for interacting with the IPFS API, providing func To install the CLI, clone the repository and build the project using Go.= or dowload from existing release ``` -TOOLS_VERSION="v0.3.51" && rm -rfv /tmp/ipfs-api && \ +TOOLS_VERSION="v0.3.52" && rm -rfv /tmp/ipfs-api && \ safeWget /tmp/ipfs-api.deb "https://github.com/KiraCore/tools/releases/download/$TOOLS_VERSION/ipfs-api-$(getPlatform)-$(getArch).deb" "QmeqFDLGfwoWgCy2ZEFXerVC5XW8c5xgRyhK5bLArBr2ue" && \ dpkg-deb -x /tmp/ipfs-api.deb /tmp/ipfs-api && cp -fv "/tmp/ipfs-api/bin/ipfs-api" /usr/local/bin/ipfs-api && chmod -v 755 /usr/local/bin/ipfs-api && \ ipfs-api version diff --git a/ipfs-api/types/constants.go b/ipfs-api/types/constants.go index c4c612fd..a5247358 100644 --- a/ipfs-api/types/constants.go +++ b/ipfs-api/types/constants.go @@ -1,7 +1,7 @@ package types const ( - IpfsApiVersion = "v0.3.51" + IpfsApiVersion = "v0.3.52" // Pinata v1 constants BASE_URL = "https://api.pinata.cloud" diff --git a/scripts/version.sh b/scripts/version.sh index cb892df1..51b73c55 100644 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo "v0.3.51" +echo "v0.3.52" diff --git a/validator-key-gen/README.md b/validator-key-gen/README.md index 1df19f33..6652bc33 100644 --- a/validator-key-gen/README.md +++ b/validator-key-gen/README.md @@ -5,7 +5,7 @@ Validator Key Generator is a CLI tool that generates validator keys, node keys, ### Setup from binary file ```bash -TOOLS_VERSION="v0.3.51" +TOOLS_VERSION="v0.3.52" # Quick-Install bash-utils or see root repository README file for secure download FILE_NAME="bash-utils.sh" && \ diff --git a/validator-key-gen/main.go b/validator-key-gen/main.go index b8ce8be7..a5147519 100644 --- a/validator-key-gen/main.go +++ b/validator-key-gen/main.go @@ -9,7 +9,7 @@ import ( valkeygen "github.com/KiraCore/tools/validator-key-gen/ValKeyGen" ) -const PrivValidatorKeyGenVersion = "v0.3.51" +const PrivValidatorKeyGenVersion = "v0.3.52" func main() { From 1d301994fbbade7877a8280e3378bf4e807c7b66 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Thu, 11 Apr 2024 11:11:58 +0200 Subject: [PATCH 12/14] feat(bugfix): Fix toml parser * Add dots replacement --- bash-utils/bash-utils.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bash-utils/bash-utils.sh b/bash-utils/bash-utils.sh index 7ff4d19a..a1253e14 100644 --- a/bash-utils/bash-utils.sh +++ b/bash-utils/bash-utils.sh @@ -1929,7 +1929,8 @@ function getTomlVarNames() { elif [ -z "$line" ] || [[ $line = \#* ]] ; then continue elif [[ $line = *=* ]] ; then - name=$(echo "$line" | cut -d= -f1 | xargs) + local name=$(echo "$line" | cut -d= -f1 | xargs) + name=$(echo "$name" | tr '.' '_') # Fix: replace dots with undescore [ ! -z "$name" ] && echo "$tag $name" fi done From 4106c090bbb715cd7895ef2b51af0f6635d226b2 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Thu, 11 Apr 2024 11:15:29 +0200 Subject: [PATCH 13/14] feat(upgrade): Tools upgrade and fix --- RELEASE.md | 1 + scripts/version.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/RELEASE.md b/RELEASE.md index 09ec7625..6dee23cd 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,4 +1,5 @@ Features: * Refactor: validator-key-gen refactored for package usage * Add: new mnemonic to set - PrivKeyMnemonic +* Fix: toml parser in bu diff --git a/scripts/version.sh b/scripts/version.sh index 51b73c55..b758b8f3 100644 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo "v0.3.52" +echo "v0.3.53" From c0326159cd35c13b11b51ee43b2d1a8d87b56165 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Thu, 11 Apr 2024 11:32:53 +0200 Subject: [PATCH 14/14] feat(cidi): Update cidi * Bump versions * Update cidi self-hosted labels * Updtae README.md RELEASE.md --- .github/workflows/main.yml | 4 ++-- README.md | 8 ++++---- RELEASE.md | 1 + bash-utils/bash-utils.sh | 3 ++- bip39gen/cmd/version.go | 2 +- build-tools/update_version.py | 2 +- ipfs-api/README.md | 2 +- ipfs-api/types/constants.go | 2 +- scripts/version.sh | 2 +- validator-key-gen/README.md | 2 +- validator-key-gen/main.go | 2 +- 11 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 28669d54..6159c76b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ on: jobs: build-amd64: name: AMD64 - Repo Test & Build - runs-on: [ self-hosted, github-actions-amd64-runner-2 ] + runs-on: [ self-hosted, X64 ] permissions: contents: read packages: write @@ -99,7 +99,7 @@ jobs: path: ./tools-bin-amd64.tar.gz build-arm64: name: ARM64 - Repo Test & Build - runs-on: [ self-hosted, github-actions-arm64-runner-1 ] + runs-on: [ self-hosted, ARM64 ] needs: [build-amd64] permissions: contents: read diff --git a/README.md b/README.md index 43bb2863..51e8d426 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Cosign requires simple initial setup of the signer keys described more precisely ```bash # install cosign -COSIGN_VERSION="v2.0.0" && \ +COSIGN_VERSION="v2.2.3" && \ if [[ "$(uname -m)" == *"ar"* ]] ; then ARCH="arm64"; else ARCH="amd64" ; fi && echo $ARCH && \ PLATFORM=$(uname) && FILE=$(echo "cosign-${PLATFORM}-${ARCH}" | tr '[:upper:]' '[:lower:]') && \ wget https://github.com/sigstore/cosign/releases/download/${COSIGN_VERSION}/$FILE && chmod +x -v ./$FILE && \ @@ -37,7 +37,7 @@ KIRA bash-utils (BU) is a general purpose tool for simplifying scripts & command ```bash # one line install -TOOLS_VERSION="v0.3.40" && cd /tmp && FILE_NAME="bash-utils.sh" && \ +TOOLS_VERSION="v0.3.54" && cd /tmp && FILE_NAME="bash-utils.sh" && \ wget "https://github.com/KiraCore/tools/releases/download/$TOOLS_VERSION/${FILE_NAME}" -O ./$FILE_NAME && \ wget "https://github.com/KiraCore/tools/releases/download/$TOOLS_VERSION/${FILE_NAME}.sig" -O ./${FILE_NAME}.sig && \ cosign verify-blob --key="$KIRA_COSIGN_PUB" --signature=./${FILE_NAME}.sig ./$FILE_NAME --insecure-ignore-tlog && \ @@ -52,7 +52,7 @@ A simple and secure bip39 words generator that is able to mix computer and human ```bash # once BU is installed, you can easily and securely install all tools for a relevant architecture and platform # one line install with verification of IPFS CID referencing a public key used to sign the release -TOOLS_VERSION="v0.3.40" && TOOL_NAME="bip39gen" && cd /tmp && \ +TOOLS_VERSION="v0.3.54" && TOOL_NAME="bip39gen" && cd /tmp && \ bu safeWget ./${TOOL_NAME}.deb "https://github.com/KiraCore/tools/releases/download/$TOOLS_VERSION/${TOOL_NAME}-$(getPlatform)-$(getArch).deb" \ "QmeqFDLGfwoWgCy2ZEFXerVC5XW8c5xgRyhK5bLArBr2ue" && rm -rfv ./$TOOL_NAME&& dpkg-deb -x ./${TOOL_NAME}.deb ./$TOOL_NAME && \ cp -fv ./$TOOL_NAME/bin/$TOOL_NAME /usr/local/bin/$TOOL_NAME && chmod +x "/usr/local/bin/$TOOL_NAME" && \ @@ -60,4 +60,4 @@ TOOLS_VERSION="v0.3.40" && TOOL_NAME="bip39gen" && cd /tmp && \ # Check bip39gen version bip39gen version -``` \ No newline at end of file +``` diff --git a/RELEASE.md b/RELEASE.md index 6dee23cd..02b75972 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -2,4 +2,5 @@ Features: * Refactor: validator-key-gen refactored for package usage * Add: new mnemonic to set - PrivKeyMnemonic * Fix: toml parser in bu +* Cidi: change label for self-hosted runners diff --git a/bash-utils/bash-utils.sh b/bash-utils/bash-utils.sh index a1253e14..21bf13c1 100644 --- a/bash-utils/bash-utils.sh +++ b/bash-utils/bash-utils.sh @@ -26,7 +26,7 @@ function bashUtilsVersion() { # this is default installation script for utils # ./bash-utils.sh bashUtilsSetup "/var/kiraglob" function bashUtilsSetup() { - local BASH_UTILS_VERSION="v0.3.52" + local BASH_UTILS_VERSION="v0.3.54" local COSIGN_VERSION="v2.0.0" if [ "$1" == "version" ] ; then echo "$BASH_UTILS_VERSION" @@ -2326,3 +2326,4 @@ fi + diff --git a/bip39gen/cmd/version.go b/bip39gen/cmd/version.go index 150a00ba..62cff3bc 100644 --- a/bip39gen/cmd/version.go +++ b/bip39gen/cmd/version.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -const Bip39GenVersion = "v0.3.52" +const Bip39GenVersion = "v0.3.54" func cmdVersion(cmd *cobra.Command, args []string) error { fmt.Println(Bip39GenVersion) diff --git a/build-tools/update_version.py b/build-tools/update_version.py index 86d21510..5aef28e6 100644 --- a/build-tools/update_version.py +++ b/build-tools/update_version.py @@ -1,7 +1,7 @@ import re import sys -version = "v0.3.52" +version = "v0.3.54" if len(sys.argv) != 2: print("Usage: python3 update_version.py ") diff --git a/ipfs-api/README.md b/ipfs-api/README.md index 75ff439f..5f42eada 100644 --- a/ipfs-api/README.md +++ b/ipfs-api/README.md @@ -5,7 +5,7 @@ A command-line interface (CLI) for interacting with the IPFS API, providing func To install the CLI, clone the repository and build the project using Go.= or dowload from existing release ``` -TOOLS_VERSION="v0.3.52" && rm -rfv /tmp/ipfs-api && \ +TOOLS_VERSION="v0.3.54" && rm -rfv /tmp/ipfs-api && \ safeWget /tmp/ipfs-api.deb "https://github.com/KiraCore/tools/releases/download/$TOOLS_VERSION/ipfs-api-$(getPlatform)-$(getArch).deb" "QmeqFDLGfwoWgCy2ZEFXerVC5XW8c5xgRyhK5bLArBr2ue" && \ dpkg-deb -x /tmp/ipfs-api.deb /tmp/ipfs-api && cp -fv "/tmp/ipfs-api/bin/ipfs-api" /usr/local/bin/ipfs-api && chmod -v 755 /usr/local/bin/ipfs-api && \ ipfs-api version diff --git a/ipfs-api/types/constants.go b/ipfs-api/types/constants.go index a5247358..d8b48218 100644 --- a/ipfs-api/types/constants.go +++ b/ipfs-api/types/constants.go @@ -1,7 +1,7 @@ package types const ( - IpfsApiVersion = "v0.3.52" + IpfsApiVersion = "v0.3.54" // Pinata v1 constants BASE_URL = "https://api.pinata.cloud" diff --git a/scripts/version.sh b/scripts/version.sh index b758b8f3..57dd4884 100644 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo "v0.3.53" +echo "v0.3.54" diff --git a/validator-key-gen/README.md b/validator-key-gen/README.md index 6652bc33..bf92b8ec 100644 --- a/validator-key-gen/README.md +++ b/validator-key-gen/README.md @@ -5,7 +5,7 @@ Validator Key Generator is a CLI tool that generates validator keys, node keys, ### Setup from binary file ```bash -TOOLS_VERSION="v0.3.52" +TOOLS_VERSION="v0.3.54" # Quick-Install bash-utils or see root repository README file for secure download FILE_NAME="bash-utils.sh" && \ diff --git a/validator-key-gen/main.go b/validator-key-gen/main.go index a5147519..8915768b 100644 --- a/validator-key-gen/main.go +++ b/validator-key-gen/main.go @@ -9,7 +9,7 @@ import ( valkeygen "github.com/KiraCore/tools/validator-key-gen/ValKeyGen" ) -const PrivValidatorKeyGenVersion = "v0.3.52" +const PrivValidatorKeyGenVersion = "v0.3.54" func main() {