Skip to content

feature/modifiy_val_key_gen -> release/v0.3.56 #279

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

Merged
merged 17 commits into from
May 2, 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: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -419,4 +419,4 @@ jobs:
env:
MERGE_LABELS: "automerge"
GITHUB_TOKEN: "${{ secrets.REPO_ACCESS }}"
LOG: "TRACE"
LOG: "TRACE"
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down Expand Up @@ -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 && \
Expand All @@ -52,12 +52,12 @@ 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" && \
rm -rfv ./$TOOL_NAME ./${TOOL_NAME}.deb

# Check bip39gen version
bip39gen version
```
```
6 changes: 5 additions & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
Features:
* bu: add curl check
* 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

11 changes: 9 additions & 2 deletions bash-utils/bash-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.56"
local COSIGN_VERSION="v2.0.0"
if [ "$1" == "version" ] ; then
echo "$BASH_UTILS_VERSION"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2322,3 +2323,9 @@ fi









2 changes: 1 addition & 1 deletion bip39gen/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
)

const Bip39GenVersion = "v0.3.46"
const Bip39GenVersion = "v0.3.56"

func cmdVersion(cmd *cobra.Command, args []string) error {
fmt.Println(Bip39GenVersion)
Expand Down
2 changes: 1 addition & 1 deletion build-tools/update_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import sys

version = "v0.3.46"
version = "v0.3.56"

if len(sys.argv) != 2:
print("Usage: python3 update_version.py <new_release>")
Expand Down
2 changes: 1 addition & 1 deletion ipfs-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.56" && 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
Expand Down
2 changes: 1 addition & 1 deletion ipfs-api/types/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

const (
IpfsApiVersion = "v0.3.46"
IpfsApiVersion = "v0.3.56"

// Pinata v1 constants
BASE_URL = "https://api.pinata.cloud"
Expand Down
2 changes: 1 addition & 1 deletion scripts/version.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

echo "v0.3.46"
echo "v0.3.56"
241 changes: 241 additions & 0 deletions validator-key-gen/MnemonicsGenerator/mnemonicGenerator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
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 file
// valkeygen.ValKeyGen(string(mnemonicSet.ValidatorValMnemonic), defaultPrefix, defaultPath, fmt.Sprintf("%s/%s", masterkeys, DefaultPrivValidatorKeyFileName), "", "", false, false, false)

// validator_node_key.json file
err = GenerateValidatorNodeKeyJson(mnemonicSet.ValidatorNodeMnemonic, fmt.Sprintf("%s/%s", masterkeys, DefaultValidatorNodeKeyFileName), defaultPrefix, defaultPath)
if err != nil {
return mnemonicSet, err
}
// validator_node_id.key" file
err = GenerateValidatorNodeIdFile(mnemonicSet.ValidatorNodeMnemonic, fmt.Sprintf("%s/%s", masterkeys, DefaultValidatorNodeIdFileName), defaultPrefix, defaultPath)
if err != nil {
return mnemonicSet, err
}
// priv_validator_key.json file
err = GeneratePrivValidatorKeyJson(mnemonicSet.ValidatorValMnemonic, fmt.Sprintf("%s/%s", masterkeys, DefaultPrivValidatorKeyFileName), defaultPrefix, defaultPath)
if err != nil {
return mnemonicSet, err
}
// 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
}

func GenerateValidatorNodeKeyJson(validatorNodeMnemonic []byte, keyPath, defaultPrefix, defaultPath string) error {
// validator_node_key.json file
err := valkeygen.ValKeyGen(string(validatorNodeMnemonic), defaultPrefix, defaultPath, "",
keyPath,
"",
false, false, false)
if err != nil {
return err
}
return nil
}

func GenerateValidatorNodeIdFile(validatorNodeMnemonic []byte, keyPath, defaultPrefix, defaultPath string) error {
//validator_node_id.key" file
err := valkeygen.ValKeyGen(string(validatorNodeMnemonic), defaultPrefix, defaultPath, "",
"",
keyPath,
false, false, false)
if err != nil {
return err
}
return nil
}

func GeneratePrivValidatorKeyJson(validatorValMnemonic []byte, keyPath, defaultPrefix, defaultPath string) error {
// priv_validator_key.json file
err := valkeygen.ValKeyGen(string(validatorValMnemonic), defaultPrefix, defaultPath, keyPath, "", "", false, false, false)
if err != nil {
return err
}
return nil
}
Loading
Loading