Skip to content

Commit

Permalink
Merge pull request #257 from KiraCore/feature/integration_test_v0.0.3
Browse files Browse the repository at this point in the history
feature/integration_test_v0.0.3 -> release/v0.3.44
  • Loading branch information
MrLutik authored Apr 6, 2023
2 parents 8abce88 + f43b6a5 commit 0bebba1
Show file tree
Hide file tree
Showing 21 changed files with 344 additions and 134 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
id-token: write
pull-requests: write
container:
image: ghcr.io/kiracore/docker/base-image:v0.11.2
image: ghcr.io/kiracore/docker/base-image:v0.13.7
steps:
# Work around https://github.com/actions/checkout/issues/760
- name: Add safe.directory
Expand Down Expand Up @@ -71,6 +71,8 @@ jobs:
echo " Release exists: ${{ env.RELEASE_EXISTS }}"
go version
- name: Testing & Building TOOLS
env:
PINATA_API_JWT_TEST: "${{ secrets.PINATA_API_JWT_TEST }}"
run: |
set -x
echo "(current dir): $PWD" && ls -l ./
Expand Down
4 changes: 2 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Features:

* added timeout and retry to safeWget
* ipfs-api: add integration tests
* bip39gen: refactor, fix err handling
5 changes: 4 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.42"
local BASH_UTILS_VERSION="v0.3.44"
local COSIGN_VERSION="v2.0.0"
if [ "$1" == "version" ] ; then
echo "$BASH_UTILS_VERSION"
Expand Down Expand Up @@ -2312,3 +2312,6 @@ fi






166 changes: 102 additions & 64 deletions bip39gen/cmd/mnemonic.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,30 @@ func validateLengthFlagInput(length int) error {
}
return nil
}
func validateLengthEntropyInput(str string) error {
if len(str) == 0 {
return nil
}

if (words/3)*32 != len(str) {
err := errors.New(fmt.Sprintf("human provided entropy has insufficient length, expected %v bits but supplied only %v of entropy, your mnemonic is NOT secure. You can specify a cipher flag to extrapolate your input.", (words/3)*32, len(str)))
return err
}
return nil

}

// validateEntropyFlagInput checks if the provided entropy string is valid.
func validateEntropyFlagInput(str string) error {
if len(str) > 0 {
match, _ := regexp.MatchString("^[0-1]{1,}$", str)
if !match {
return errBinary
}
if len(str) == 0 {
return nil
}

match, _ := regexp.MatchString("^[0-1]+$", str)
if !match {
return errBinary
}

return nil
}

Expand Down Expand Up @@ -64,6 +79,79 @@ func checkInputPrefix(str string) string {
}
return str
}
func processSHA256() 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))

userEntropy = string(sum[:])
userEntropy = fmt.Sprintf("%x", userEntropy)

if err := validateHexEntropyFlagInput(userEntropy); err != nil {
return err
}
return nil
}

func processSHA512() error {
hex = true
if words != 48 {
fmt.Println(colors.Print("Warning. With sha512 you can generate 48 words", 3))
words = 48
}
sum := sha512.Sum512([]byte(userEntropy))

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

if err := validateHexEntropyFlagInput(userEntropy); err != nil {
return err
}
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()

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 {
return err
}
bits := (words / 3) * 32
bitsEnt := len(rawEntropy)
for i := bitsEnt; i <= bits; i++ {
rawEntropy += "0"
}
return nil
}

// cmdMnemonicPreRun validates the provided flags and sets the required variables.
func cmdMnemonicPreRun(cmd *cobra.Command, args []string) error {
Expand All @@ -90,85 +178,35 @@ func cmdMnemonicPreRun(cmd *cobra.Command, args []string) error {
if err := validateEntropyFlagInput(i); err != nil {
return err
}
if (words/3)*32 != len(userEntropy) {
err := errors.New(fmt.Sprintf("human provided entropy has insufficient length, expected %v bits but only %v, your mnemonic is NOT secure. You can specify a cipher flag to extrapolate your input.", (words/3)*32, len(userEntropy)))
err := validateLengthEntropyInput(i)
if err != nil {
return err
}

}

}

}
if (len(userEntropy) > 0 || len(rawEntropy) > 0) && len(cipher) != 0 {
switch cipher {
case "sha256":
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))

userEntropy = string(sum[:])
userEntropy = fmt.Sprintf("%x", userEntropy)

if err := validateHexEntropyFlagInput(userEntropy); err != nil {
if err := processSHA256(); err != nil {
return err
}

case "sha512":
hex = true
if words != 48 {
fmt.Println(colors.Print("Warning. With sha512 you can generate 48 words", 3))
words = 48
}
sum := sha512.Sum512([]byte(userEntropy))

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

if err := validateHexEntropyFlagInput(userEntropy); err != nil {
if err := processSHA512(); err != nil {
return err
}

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

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

aead, _ := chacha20poly1305.NewX(sum[:])

mnemonic := NewMnemonic()
msg := mnemonic.String()

nonce := make([]byte, chacha20poly1305.NonceSizeX)
ciphertext := aead.Seal(nil, nonce, []byte(msg), nil)

fmt.Printf("Cipher stream: %x\n", ciphertext)

mnemonic.Print(verbose)
// should refactor this. Perhaps with a context.
os.Exit(0)
return nil

case "padding":
hex = false
if err := validateEntropyFlagInput(rawEntropy); err != nil {
if err := processPadding(); err != nil {
return err
}
bits := (words / 3) * 32
bitsEnt := len(rawEntropy)
for i := bitsEnt; i <= bits; i++ {
rawEntropy += "0"
}
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.39"
const Bip39GenVersion = "v0.3.44"

func cmdVersion(cmd *cobra.Command, args []string) error {
fmt.Println(Bip39GenVersion)
Expand Down
18 changes: 18 additions & 0 deletions bip39gen/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ 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"

runTest() {
local test_cmd="$1"
local test_name="$2"


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

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




4 changes: 3 additions & 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.39"
version = "v0.3.44"

if len(sys.argv) != 2:
print("Usage: python3 update_version.py <new_release>")
Expand Down Expand Up @@ -55,6 +55,8 @@ def updateVersion(path,ver):
"../bip39gen/cmd/version.go":updateVersion,
"../ipfs-api/types/constants.go":updateVersion,
"../validator-key-gen/main.go":updateVersion,
"../validator-key-gen/README.md":updateVersion,
"../ipfs-api/README.md":updateVersion,
}

new_release = sys.argv[1]
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.39" && rm -rfv /tmp/ipfs-api && \
TOOLS_VERSION="v0.3.44" && 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
3 changes: 1 addition & 2 deletions ipfs-api/pkg/cli/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cli

import (
"errors"
"os"

"github.com/ipld/go-ipld-prime/datamodel"
log "github.com/kiracore/tools/ipfs-api/pkg/ipfslog"
Expand Down Expand Up @@ -113,7 +112,7 @@ func pinAndOutputResult(p *pnt.PinataApi, content string) error {
}
if err := p.OutputPinJson(); err != nil {
log.Error("failed to print results: %v", err)
os.Exit(1)
return err
}
return nil
}
Expand Down
Loading

0 comments on commit 0bebba1

Please sign in to comment.