Skip to content

Commit

Permalink
Merge pull request #260 from KiraCore/feature/integration_test_v0.0.4
Browse files Browse the repository at this point in the history
feature/integration_test_v0.0.4 -> release/v0.3.45
  • Loading branch information
MrLutik authored Apr 7, 2023
2 parents a2ce0fe + 2c03f83 commit 2888113
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 65 deletions.
6 changes: 4 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Features:
* ipfs-api: add integration tests
* bip39gen: refactor, fix err handling
* bip39gen: add integration test
* bip39gen: deprecate chacha20
* bip39gen: fix bugs
* bip39gen: refactor prefix logic
3 changes: 2 additions & 1 deletion 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.44"
local BASH_UTILS_VERSION="v0.3.45"
local COSIGN_VERSION="v2.0.0"
if [ "$1" == "version" ] ; then
echo "$BASH_UTILS_VERSION"
Expand Down Expand Up @@ -2315,3 +2315,4 @@ fi




2 changes: 1 addition & 1 deletion bip39gen/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Execute() {

mnemonicCommand.Flags().StringVarP(&userEntropy, "entropy", "e", "", "provide entropy for mixing and generating new mnemonic sentences")
mnemonicCommand.Flags().StringVarP(&rawEntropy, "raw-entropy", "r", "", "provide entropy to regenerate mnemonic sentences from")
mnemonicCommand.Flags().StringVarP(&cipher, "cipher", "c", "", "choose cipher to generate mnemonics. Available options are: sha256,sha512, chacha20, padding")
mnemonicCommand.Flags().StringVarP(&cipher, "cipher", "c", "", "choose cipher to generate mnemonics. Available options are: sha256, sha512, padding")

mnemonicCommand.Flags().Changed("entropy")
mnemonicCommand.Flags().Changed("raw-entropy")
Expand Down
121 changes: 80 additions & 41 deletions bip39gen/cmd/mnemonic.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import (
"crypto/sha512"
"errors"
"fmt"
"os"
"regexp"
"strings"

"github.com/kiracore/tools/bip39gen/pkg/bip39"
"github.com/spf13/cobra"
"golang.org/x/crypto/chacha20poly1305"
)

var (
Expand Down Expand Up @@ -68,16 +66,26 @@ func validateHexEntropyFlagInput(str string) error {
}

// Check if string contain hex or binary prefix and return string without it
func checkInputPrefix(str string) string {
if len(str) > 2 {
switch str[0:2] {
case "0x":
return strings.TrimSpace(str[2:])
case "0b":
return strings.TrimSpace(str[2:])
func checkInputPrefix(str string) (string, error) {
if hex && len(str) > 2 {
if str[0:2] == "0x" {
if err := validateHexEntropyFlagInput(str[2:]); err != nil {
return "", err
}
return strings.TrimSpace(str[2:]), nil
}
}
if !hex && len(str) > 2 {
if str[0:2] == "0b" {
if err := validateEntropyFlagInput(str[2:]); err != nil {
return "", err
}
return strings.TrimSpace(str[2:]), nil
}

}
return str

return str, nil
}
func processSHA256() error {
hex = true
Expand Down Expand Up @@ -114,32 +122,49 @@ func processSHA512() error {
return nil
}

func processChaCha20() error {
hex = true
if words != 24 {
fmt.Println(colors.Print("Warning. With sha256 you can generate 24 words", 3))
words = 24
}
sum := sha256.Sum256([]byte(userEntropy))

// Flip bytes to string hex
userEntropy = string(sum[:])
userEntropy = fmt.Sprintf("%x", userEntropy)

aead, err := chacha20poly1305.NewX(sum[:])
if err != nil {
return err
}

mnemonic := NewMnemonic()
msg := mnemonic.String()
// Deprecated
// func processChaCha20() error {
// hex = true
// if words != 24 {
// fmt.Println(colors.Print("Warning. With sha256 you can generate 24 words", 3))
// words = 24
// }

// // Generate a 256-bit key from the user-entered phrase using SHA-256
// key := sha256.Sum256([]byte(userEntropy))

// // Generate random nonce
// nonce := make([]byte, chacha20.NonceSize)
// if _, err := rand.Read(nonce); err != nil {
// panic(err)
// }

// // Generate random plaintext (32 bytes) to be encrypted using ChaCha20
// plaintext := make([]byte, 32)
// if _, err := rand.Read(plaintext); err != nil {
// panic(err)
// }

// // Encrypt plaintext using ChaCha20
// cipher, err := chacha20.NewUnauthenticatedCipher(key[:], nonce)
// if err != nil {
// panic(err)
// }
// ciphertext := make([]byte, len(plaintext))
// cipher.XORKeyStream(ciphertext, plaintext)

// // Use the first 256 bits of the ciphertext as entropy for BIP39
// entropy := ciphertext[:32]

// userEntropy = fmt.Sprintf("%x", entropy)
// fmt.Fprintf(os.Stdout, "Key: %x\n", key)
// fmt.Fprintf(os.Stdout, "Nonce(HEX): %x\n", nonce)
// fmt.Fprintf(os.Stdout, "Ciphertex(HEX): %x\n", ciphertext)
// mnemonic, err := bip39c.NewMnemonic(entropy)
// fmt.Fprintf(os.Stdout, "Mnemonic: %v\n", mnemonic)
// return nil
// }

nonce := make([]byte, chacha20poly1305.NonceSizeX)
ciphertext := aead.Seal(nil, nonce, []byte(msg), nil)
fmt.Fprintf(os.Stdout, "Cipher stream: %x\n", ciphertext)
mnemonic.Print(verbose)
return nil
}
func processPadding() error {
hex = false
if err := validateEntropyFlagInput(rawEntropy); err != nil {
Expand All @@ -155,9 +180,20 @@ func processPadding() error {

// cmdMnemonicPreRun validates the provided flags and sets the required variables.
func cmdMnemonicPreRun(cmd *cobra.Command, args []string) error {
var err error
if len(userEntropy) > 0 {
userEntropy, err = checkInputPrefix(userEntropy)
_ = userEntropy
if err != nil {
return err
}
}

userEntropy = checkInputPrefix(userEntropy)
rawEntropy = checkInputPrefix(rawEntropy)
if len(rawEntropy) > 0 {
rawEntropy, err = checkInputPrefix(rawEntropy)
_ = rawEntropy
return err
}

input := []string{userEntropy, rawEntropy}

Expand Down Expand Up @@ -198,10 +234,12 @@ func cmdMnemonicPreRun(cmd *cobra.Command, args []string) error {
if err := processSHA512(); err != nil {
return err
}
case "chacha20":
if err := processChaCha20(); err != nil {
return err
}

// Deprecated
// case "chacha20":
// if err := processChaCha20(); err != nil {
// return err
// }

case "padding":
if err := processPadding(); err != nil {
Expand All @@ -218,6 +256,7 @@ func cmdMnemonic(cmd *cobra.Command, args []string) error {

mnemonic := NewMnemonic()
mnemonic.Print(verbose)

return nil

}
Expand Down
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.44"
const Bip39GenVersion = "v0.3.45"

func cmdVersion(cmd *cobra.Command, args []string) error {
fmt.Println(Bip39GenVersion)
Expand Down
2 changes: 0 additions & 2 deletions bip39gen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ require (
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/sys v0.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 0 additions & 4 deletions bip39gen/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
60 changes: 53 additions & 7 deletions bip39gen/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,70 @@ MNEMONIC_TEST_2="panther door little taxi unfold remain notable smooth trap beac
[ "$MNEMONIC_TEST_1" != "$MNEMONIC_TEST_2" ] && \
echoErr "ERROR: When sha256 raw entropy is provided expected to end up with deterministic mnemonic, but results differ :(" && exit 1 || echoInfo "INFO: Test 2 passed"

set +x
runTest() {
local test_cmd="$1"
local test_name="$2"
local test_out="$3"


# Execute the test command and get the exit code
eval "$test_cmd &> /dev/null ||:"
RESULT=$(eval "$test_cmd")
exit_code=$?

# Get the command name
# Check the exit code and print the result
if [ $exit_code -eq 0 ]; then
echo "[PASS] $test_name"
if [[ $exit_code -eq 0 ]]; then
if [[ $RESULT == $test_out ]]; then
echo "[PASS] $test_name"
else
bu echoError "[FAIL] $test_name"
fi

else
bu echoError "[FAIL] $test_name"
fi
}




#TestCase1(-l 12: default mnemonic lenght is 24 ):
RAW_ENT_BIN_WITHOUT_PREFIX="10011101001100000001011100000001101110100010010110110011001010101111000001101101011000010000110011000010100100011101110101001001"
RAW_ENT_HEX_WITHOUT_PREFIX="9d301701ba25b32af06d610cc291dd49"
RAW_ENT_HEX_WITHOUT_PREFIX_UPPER="9D301701BA25B32AF06D610CC291DD49"
RAW_ENT_BIN_WITH_PREFIX="0b10011101001100000001011100000001101110100010010110110011001010101111000001101101011000010000110011000010100100011101110101001001"
RAW_ENT_HEX_WITH_PREFIX="0x9d301701ba25b32af06d610cc291dd49"
RAW_ENT_HEX_WITH_PREFIX_UPPER="0x9D301701BA25B32AF06D610CC291DD49"
MNEMONIC_TEST_CASE_1="outdoor level scatter inmate forest nice script promote art behind jar nation"

runTest "$BIN_bip39gen mnemonic -l 12 --raw-entropy=$RAW_ENT_BIN_WITHOUT_PREFIX" "RAW: binary entropy without prefix" "$MNEMONIC_TEST_CASE_1"
runTest "$BIN_bip39gen mnemonic -l 12 --raw-entropy=$RAW_ENT_BIN_WITH_PREFIX" "RAW: binary entropy with prefix" "$MNEMONIC_TEST_CASE_1"
runTest "$BIN_bip39gen mnemonic -l 12 --raw-entropy=$RAW_ENT_HEX_WITHOUT_PREFIX --hex=true" "RAW: hex entropy without prefix, lower" "$MNEMONIC_TEST_CASE_1"
runTest "$BIN_bip39gen mnemonic -l 12 --raw-entropy=$RAW_ENT_HEX_WITHOUT_PREFIX_UPPER --hex=true" "RAW: hex entropy without prefix, upper" "$MNEMONIC_TEST_CASE_1"
runTest "$BIN_bip39gen mnemonic -l 12 --raw-entropy=$RAW_ENT_HEX_WITH_PREFIX --hex=true" "RAW: hex entropy with prefix, lower" "$MNEMONIC_TEST_CASE_1"
runTest "$BIN_bip39gen mnemonic -l 12 --raw-entropy=$RAW_ENT_HEX_WITH_PREFIX_UPPER --hex=true" "RAW: hex entropy with prefix, upper" "$MNEMONIC_TEST_CASE_1"

#TestCase2(24 words + prefix check. Hash starts from 0x):
RAW_ENT_BIN_WITHOUT_PREFIX="0000101111011000111111101110000110001100100100001011011011011101010111000111101000001011101111111011000011011111011011110101111000011001100110010011011110010101111100100110000000011101011001101100001000111101101001000010001000110111010101010000111111000010"
RAW_ENT_HEX_WITHOUT_PREFIX="0bd8fee18c90b6dd5c7a0bbfb0df6f5e19993795f2601d66c23da42237550fc2"
RAW_ENT_HEX_WITHOUT_PREFIX_UPPER="0BD8FEE18C90B6DD5C7A0BBFB0DF6F5E19993795F2601D66C23DA42237550FC2"
RAW_ENT_BIN_WITH_PREFIX="0b0000101111011000111111101110000110001100100100001011011011011101010111000111101000001011101111111011000011011111011011110101111000011001100110010011011110010101111100100110000000011101011001101100001000111101101001000010001000110111010101010000111111000010"
RAW_ENT_HEX_WITH_PREFIX="0x0bd8fee18c90b6dd5c7a0bbfb0df6f5e19993795f2601d66c23da42237550fc2"
RAW_ENT_HEX_WITH_PREFIX_UPPER="0x0BD8FEE18C90B6DD5C7A0BBFB0DF6F5E19993795F2601D66C23DA42237550FC2"
MNEMONIC_TEST_CASE_2="armed side reveal bomb arena huge impose door sausage manage swift rotate office orange fit equal buddy current month embark casino pride disease firm"

runTest "$BIN_bip39gen mnemonic --raw-entropy=$RAW_ENT_BIN_WITHOUT_PREFIX" "RAW: binary entropy without prefix" "$MNEMONIC_TEST_CASE_2"
runTest "$BIN_bip39gen mnemonic --raw-entropy=$RAW_ENT_BIN_WITH_PREFIX" "RAW: binary entropy with prefix" "$MNEMONIC_TEST_CASE_2"
runTest "$BIN_bip39gen mnemonic --raw-entropy=$RAW_ENT_HEX_WITHOUT_PREFIX --hex=true" "RAW: hex entropy without prefix, lower" "$MNEMONIC_TEST_CASE_2"
runTest "$BIN_bip39gen mnemonic --raw-entropy=$RAW_ENT_HEX_WITHOUT_PREFIX_UPPER --hex=true" "RAW: hex entropy without prefix, upper" "$MNEMONIC_TEST_CASE_2"
runTest "$BIN_bip39gen mnemonic --raw-entropy=$RAW_ENT_HEX_WITH_PREFIX --hex=true" "RAW: hex entropy with prefix, lower" "$MNEMONIC_TEST_CASE_2"
runTest "$BIN_bip39gen mnemonic --raw-entropy=$RAW_ENT_HEX_WITH_PREFIX_UPPER --hex=true" "RAW: hex entropy with prefix, upper" "$MNEMONIC_TEST_CASE_2"

#TestCase3(Cipher: SHA256)
MNEMONIC_TEST_CASE_3="keen lunar camp clutch between glass offer garden brand blame easy couple use loop coin another tortoise stove stamp fence pet coach festival then"
runTest "$BIN_bip39gen mnemonic --raw-entropy=TestTest --cipher=sha256" "CIPHER[SHA256]: Test" "$MNEMONIC_TEST_CASE_3"

#TestCase4(Cipher: SHA512)
MNEMONIC_TEST_CASE_4="iron moral siege volume sad assume brass bless flock palm version lunar logic fault robot virus perfect stick health skate size enter pattern hold erupt able segment day simple void float vibrant major iron skate duty hard pretty state leisure panel verify still fork film icon empty garlic"
runTest "$BIN_bip39gen mnemonic --raw-entropy=TestTest --cipher=sha512" "CIPHER[SHA512]: Test" "$MNEMONIC_TEST_CASE_4"

#TestCase6(Cipher: padding)
MNEMONIC_TEST_CASE_5="outdoor level scale abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon antique"
runTest "$BIN_bip39gen mnemonic -l 12 --raw-entropy=100111010011000000010111 --cipher=padding" "CIPHER[padding]: Test" "$MNEMONIC_TEST_CASE_5"
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.44"
version = "v0.3.45"

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.44" && rm -rfv /tmp/ipfs-api && \
TOOLS_VERSION="v0.3.45" && 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.44"
IpfsApiVersion = "v0.3.45"

// 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.44"
echo "v0.3.45"
2 changes: 1 addition & 1 deletion validator-key-gen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.44"
TOOLS_VERSION="v0.3.45"

# Quick-Install bash-utils or see root repository README file for secure download
FILE_NAME="bash-utils.sh" && \
Expand Down
2 changes: 1 addition & 1 deletion validator-key-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/tendermint/tendermint/privval"
)

const PrivValidatorKeyGenVersion = "v0.3.44"
const PrivValidatorKeyGenVersion = "v0.3.45"

type Prefix struct {
fullPath *hd.BIP44Params
Expand Down

0 comments on commit 2888113

Please sign in to comment.