Skip to content

Commit 2888113

Browse files
authored
Merge pull request #260 from KiraCore/feature/integration_test_v0.0.4
feature/integration_test_v0.0.4 -> release/v0.3.45
2 parents a2ce0fe + 2c03f83 commit 2888113

File tree

14 files changed

+147
-65
lines changed

14 files changed

+147
-65
lines changed

RELEASE.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Features:
2-
* ipfs-api: add integration tests
3-
* bip39gen: refactor, fix err handling
2+
* bip39gen: add integration test
3+
* bip39gen: deprecate chacha20
4+
* bip39gen: fix bugs
5+
* bip39gen: refactor prefix logic

bash-utils/bash-utils.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function bashUtilsVersion() {
2626
# this is default installation script for utils
2727
# ./bash-utils.sh bashUtilsSetup "/var/kiraglob"
2828
function bashUtilsSetup() {
29-
local BASH_UTILS_VERSION="v0.3.44"
29+
local BASH_UTILS_VERSION="v0.3.45"
3030
local COSIGN_VERSION="v2.0.0"
3131
if [ "$1" == "version" ] ; then
3232
echo "$BASH_UTILS_VERSION"
@@ -2315,3 +2315,4 @@ fi
23152315

23162316

23172317

2318+

bip39gen/cmd/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func Execute() {
4545

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

5050
mnemonicCommand.Flags().Changed("entropy")
5151
mnemonicCommand.Flags().Changed("raw-entropy")

bip39gen/cmd/mnemonic.go

Lines changed: 80 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import (
55
"crypto/sha512"
66
"errors"
77
"fmt"
8-
"os"
98
"regexp"
109
"strings"
1110

1211
"github.com/kiracore/tools/bip39gen/pkg/bip39"
1312
"github.com/spf13/cobra"
14-
"golang.org/x/crypto/chacha20poly1305"
1513
)
1614

1715
var (
@@ -68,16 +66,26 @@ func validateHexEntropyFlagInput(str string) error {
6866
}
6967

7068
// Check if string contain hex or binary prefix and return string without it
71-
func checkInputPrefix(str string) string {
72-
if len(str) > 2 {
73-
switch str[0:2] {
74-
case "0x":
75-
return strings.TrimSpace(str[2:])
76-
case "0b":
77-
return strings.TrimSpace(str[2:])
69+
func checkInputPrefix(str string) (string, error) {
70+
if hex && len(str) > 2 {
71+
if str[0:2] == "0x" {
72+
if err := validateHexEntropyFlagInput(str[2:]); err != nil {
73+
return "", err
74+
}
75+
return strings.TrimSpace(str[2:]), nil
76+
}
77+
}
78+
if !hex && len(str) > 2 {
79+
if str[0:2] == "0b" {
80+
if err := validateEntropyFlagInput(str[2:]); err != nil {
81+
return "", err
82+
}
83+
return strings.TrimSpace(str[2:]), nil
7884
}
85+
7986
}
80-
return str
87+
88+
return str, nil
8189
}
8290
func processSHA256() error {
8391
hex = true
@@ -114,32 +122,49 @@ func processSHA512() error {
114122
return nil
115123
}
116124

117-
func processChaCha20() error {
118-
hex = true
119-
if words != 24 {
120-
fmt.Println(colors.Print("Warning. With sha256 you can generate 24 words", 3))
121-
words = 24
122-
}
123-
sum := sha256.Sum256([]byte(userEntropy))
124-
125-
// Flip bytes to string hex
126-
userEntropy = string(sum[:])
127-
userEntropy = fmt.Sprintf("%x", userEntropy)
128-
129-
aead, err := chacha20poly1305.NewX(sum[:])
130-
if err != nil {
131-
return err
132-
}
133-
134-
mnemonic := NewMnemonic()
135-
msg := mnemonic.String()
125+
// Deprecated
126+
// func processChaCha20() error {
127+
// hex = true
128+
// if words != 24 {
129+
// fmt.Println(colors.Print("Warning. With sha256 you can generate 24 words", 3))
130+
// words = 24
131+
// }
132+
133+
// // Generate a 256-bit key from the user-entered phrase using SHA-256
134+
// key := sha256.Sum256([]byte(userEntropy))
135+
136+
// // Generate random nonce
137+
// nonce := make([]byte, chacha20.NonceSize)
138+
// if _, err := rand.Read(nonce); err != nil {
139+
// panic(err)
140+
// }
141+
142+
// // Generate random plaintext (32 bytes) to be encrypted using ChaCha20
143+
// plaintext := make([]byte, 32)
144+
// if _, err := rand.Read(plaintext); err != nil {
145+
// panic(err)
146+
// }
147+
148+
// // Encrypt plaintext using ChaCha20
149+
// cipher, err := chacha20.NewUnauthenticatedCipher(key[:], nonce)
150+
// if err != nil {
151+
// panic(err)
152+
// }
153+
// ciphertext := make([]byte, len(plaintext))
154+
// cipher.XORKeyStream(ciphertext, plaintext)
155+
156+
// // Use the first 256 bits of the ciphertext as entropy for BIP39
157+
// entropy := ciphertext[:32]
158+
159+
// userEntropy = fmt.Sprintf("%x", entropy)
160+
// fmt.Fprintf(os.Stdout, "Key: %x\n", key)
161+
// fmt.Fprintf(os.Stdout, "Nonce(HEX): %x\n", nonce)
162+
// fmt.Fprintf(os.Stdout, "Ciphertex(HEX): %x\n", ciphertext)
163+
// mnemonic, err := bip39c.NewMnemonic(entropy)
164+
// fmt.Fprintf(os.Stdout, "Mnemonic: %v\n", mnemonic)
165+
// return nil
166+
// }
136167

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

156181
// cmdMnemonicPreRun validates the provided flags and sets the required variables.
157182
func cmdMnemonicPreRun(cmd *cobra.Command, args []string) error {
183+
var err error
184+
if len(userEntropy) > 0 {
185+
userEntropy, err = checkInputPrefix(userEntropy)
186+
_ = userEntropy
187+
if err != nil {
188+
return err
189+
}
190+
}
158191

159-
userEntropy = checkInputPrefix(userEntropy)
160-
rawEntropy = checkInputPrefix(rawEntropy)
192+
if len(rawEntropy) > 0 {
193+
rawEntropy, err = checkInputPrefix(rawEntropy)
194+
_ = rawEntropy
195+
return err
196+
}
161197

162198
input := []string{userEntropy, rawEntropy}
163199

@@ -198,10 +234,12 @@ func cmdMnemonicPreRun(cmd *cobra.Command, args []string) error {
198234
if err := processSHA512(); err != nil {
199235
return err
200236
}
201-
case "chacha20":
202-
if err := processChaCha20(); err != nil {
203-
return err
204-
}
237+
238+
// Deprecated
239+
// case "chacha20":
240+
// if err := processChaCha20(); err != nil {
241+
// return err
242+
// }
205243

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

219257
mnemonic := NewMnemonic()
220258
mnemonic.Print(verbose)
259+
221260
return nil
222261

223262
}

bip39gen/cmd/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/spf13/cobra"
77
)
88

9-
const Bip39GenVersion = "v0.3.44"
9+
const Bip39GenVersion = "v0.3.45"
1010

1111
func cmdVersion(cmd *cobra.Command, args []string) error {
1212
fmt.Println(Bip39GenVersion)

bip39gen/go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,5 @@ require (
1212
github.com/inconshreveable/mousetrap v1.0.1 // indirect
1313
github.com/pmezard/go-difflib v1.0.0 // indirect
1414
github.com/spf13/pflag v1.0.5 // indirect
15-
golang.org/x/crypto v0.5.0 // indirect
16-
golang.org/x/sys v0.4.0 // indirect
1715
gopkg.in/yaml.v3 v3.0.1 // indirect
1816
)

bip39gen/go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
1818
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
1919
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
2020
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
21-
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
22-
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
23-
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
24-
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2521
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2622
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2723
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

bip39gen/scripts/test.sh

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,70 @@ MNEMONIC_TEST_2="panther door little taxi unfold remain notable smooth trap beac
3232
[ "$MNEMONIC_TEST_1" != "$MNEMONIC_TEST_2" ] && \
3333
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"
3434

35+
set +x
3536
runTest() {
3637
local test_cmd="$1"
3738
local test_name="$2"
39+
local test_out="$3"
3840

3941

4042
# Execute the test command and get the exit code
41-
eval "$test_cmd &> /dev/null ||:"
43+
RESULT=$(eval "$test_cmd")
4244
exit_code=$?
4345

4446
# Get the command name
4547
# Check the exit code and print the result
46-
if [ $exit_code -eq 0 ]; then
47-
echo "[PASS] $test_name"
48+
if [[ $exit_code -eq 0 ]]; then
49+
if [[ $RESULT == $test_out ]]; then
50+
echo "[PASS] $test_name"
51+
else
52+
bu echoError "[FAIL] $test_name"
53+
fi
54+
4855
else
4956
bu echoError "[FAIL] $test_name"
5057
fi
5158
}
52-
53-
54-
55-
59+
#TestCase1(-l 12: default mnemonic lenght is 24 ):
60+
RAW_ENT_BIN_WITHOUT_PREFIX="10011101001100000001011100000001101110100010010110110011001010101111000001101101011000010000110011000010100100011101110101001001"
61+
RAW_ENT_HEX_WITHOUT_PREFIX="9d301701ba25b32af06d610cc291dd49"
62+
RAW_ENT_HEX_WITHOUT_PREFIX_UPPER="9D301701BA25B32AF06D610CC291DD49"
63+
RAW_ENT_BIN_WITH_PREFIX="0b10011101001100000001011100000001101110100010010110110011001010101111000001101101011000010000110011000010100100011101110101001001"
64+
RAW_ENT_HEX_WITH_PREFIX="0x9d301701ba25b32af06d610cc291dd49"
65+
RAW_ENT_HEX_WITH_PREFIX_UPPER="0x9D301701BA25B32AF06D610CC291DD49"
66+
MNEMONIC_TEST_CASE_1="outdoor level scatter inmate forest nice script promote art behind jar nation"
67+
68+
runTest "$BIN_bip39gen mnemonic -l 12 --raw-entropy=$RAW_ENT_BIN_WITHOUT_PREFIX" "RAW: binary entropy without prefix" "$MNEMONIC_TEST_CASE_1"
69+
runTest "$BIN_bip39gen mnemonic -l 12 --raw-entropy=$RAW_ENT_BIN_WITH_PREFIX" "RAW: binary entropy with prefix" "$MNEMONIC_TEST_CASE_1"
70+
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"
71+
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"
72+
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"
73+
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"
74+
75+
#TestCase2(24 words + prefix check. Hash starts from 0x):
76+
RAW_ENT_BIN_WITHOUT_PREFIX="0000101111011000111111101110000110001100100100001011011011011101010111000111101000001011101111111011000011011111011011110101111000011001100110010011011110010101111100100110000000011101011001101100001000111101101001000010001000110111010101010000111111000010"
77+
RAW_ENT_HEX_WITHOUT_PREFIX="0bd8fee18c90b6dd5c7a0bbfb0df6f5e19993795f2601d66c23da42237550fc2"
78+
RAW_ENT_HEX_WITHOUT_PREFIX_UPPER="0BD8FEE18C90B6DD5C7A0BBFB0DF6F5E19993795F2601D66C23DA42237550FC2"
79+
RAW_ENT_BIN_WITH_PREFIX="0b0000101111011000111111101110000110001100100100001011011011011101010111000111101000001011101111111011000011011111011011110101111000011001100110010011011110010101111100100110000000011101011001101100001000111101101001000010001000110111010101010000111111000010"
80+
RAW_ENT_HEX_WITH_PREFIX="0x0bd8fee18c90b6dd5c7a0bbfb0df6f5e19993795f2601d66c23da42237550fc2"
81+
RAW_ENT_HEX_WITH_PREFIX_UPPER="0x0BD8FEE18C90B6DD5C7A0BBFB0DF6F5E19993795F2601D66C23DA42237550FC2"
82+
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"
83+
84+
runTest "$BIN_bip39gen mnemonic --raw-entropy=$RAW_ENT_BIN_WITHOUT_PREFIX" "RAW: binary entropy without prefix" "$MNEMONIC_TEST_CASE_2"
85+
runTest "$BIN_bip39gen mnemonic --raw-entropy=$RAW_ENT_BIN_WITH_PREFIX" "RAW: binary entropy with prefix" "$MNEMONIC_TEST_CASE_2"
86+
runTest "$BIN_bip39gen mnemonic --raw-entropy=$RAW_ENT_HEX_WITHOUT_PREFIX --hex=true" "RAW: hex entropy without prefix, lower" "$MNEMONIC_TEST_CASE_2"
87+
runTest "$BIN_bip39gen mnemonic --raw-entropy=$RAW_ENT_HEX_WITHOUT_PREFIX_UPPER --hex=true" "RAW: hex entropy without prefix, upper" "$MNEMONIC_TEST_CASE_2"
88+
runTest "$BIN_bip39gen mnemonic --raw-entropy=$RAW_ENT_HEX_WITH_PREFIX --hex=true" "RAW: hex entropy with prefix, lower" "$MNEMONIC_TEST_CASE_2"
89+
runTest "$BIN_bip39gen mnemonic --raw-entropy=$RAW_ENT_HEX_WITH_PREFIX_UPPER --hex=true" "RAW: hex entropy with prefix, upper" "$MNEMONIC_TEST_CASE_2"
90+
91+
#TestCase3(Cipher: SHA256)
92+
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"
93+
runTest "$BIN_bip39gen mnemonic --raw-entropy=TestTest --cipher=sha256" "CIPHER[SHA256]: Test" "$MNEMONIC_TEST_CASE_3"
94+
95+
#TestCase4(Cipher: SHA512)
96+
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"
97+
runTest "$BIN_bip39gen mnemonic --raw-entropy=TestTest --cipher=sha512" "CIPHER[SHA512]: Test" "$MNEMONIC_TEST_CASE_4"
98+
99+
#TestCase6(Cipher: padding)
100+
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"
101+
runTest "$BIN_bip39gen mnemonic -l 12 --raw-entropy=100111010011000000010111 --cipher=padding" "CIPHER[padding]: Test" "$MNEMONIC_TEST_CASE_5"

build-tools/update_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
import sys
33

4-
version = "v0.3.44"
4+
version = "v0.3.45"
55

66
if len(sys.argv) != 2:
77
print("Usage: python3 update_version.py <new_release>")

ipfs-api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A command-line interface (CLI) for interacting with the IPFS API, providing func
55
To install the CLI, clone the repository and build the project using Go.= or dowload from existing release
66

77
```
8-
TOOLS_VERSION="v0.3.44" && rm -rfv /tmp/ipfs-api && \
8+
TOOLS_VERSION="v0.3.45" && rm -rfv /tmp/ipfs-api && \
99
safeWget /tmp/ipfs-api.deb "https://github.com/KiraCore/tools/releases/download/$TOOLS_VERSION/ipfs-api-$(getPlatform)-$(getArch).deb" "QmeqFDLGfwoWgCy2ZEFXerVC5XW8c5xgRyhK5bLArBr2ue" && \
1010
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 && \
1111
ipfs-api version

ipfs-api/types/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package types
22

33
const (
4-
IpfsApiVersion = "v0.3.44"
4+
IpfsApiVersion = "v0.3.45"
55

66
// Pinata v1 constants
77
BASE_URL = "https://api.pinata.cloud"

scripts/version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22

3-
echo "v0.3.44"
3+
echo "v0.3.45"

validator-key-gen/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Validator Key Generator is a CLI tool that generates validator keys, node keys,
55
### Setup from binary file
66

77
```bash
8-
TOOLS_VERSION="v0.3.44"
8+
TOOLS_VERSION="v0.3.45"
99

1010
# Quick-Install bash-utils or see root repository README file for secure download
1111
FILE_NAME="bash-utils.sh" && \

validator-key-gen/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/tendermint/tendermint/privval"
1919
)
2020

21-
const PrivValidatorKeyGenVersion = "v0.3.44"
21+
const PrivValidatorKeyGenVersion = "v0.3.45"
2222

2323
type Prefix struct {
2424
fullPath *hd.BIP44Params

0 commit comments

Comments
 (0)