Skip to content

Commit a2ce0fe

Browse files
authored
Merge pull request #259 from KiraCore/release/v0.3.44
2 parents 8abce88 + 0bebba1 commit a2ce0fe

File tree

21 files changed

+344
-134
lines changed

21 files changed

+344
-134
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
id-token: write
1616
pull-requests: write
1717
container:
18-
image: ghcr.io/kiracore/docker/base-image:v0.11.2
18+
image: ghcr.io/kiracore/docker/base-image:v0.13.7
1919
steps:
2020
# Work around https://github.com/actions/checkout/issues/760
2121
- name: Add safe.directory
@@ -71,6 +71,8 @@ jobs:
7171
echo " Release exists: ${{ env.RELEASE_EXISTS }}"
7272
go version
7373
- name: Testing & Building TOOLS
74+
env:
75+
PINATA_API_JWT_TEST: "${{ secrets.PINATA_API_JWT_TEST }}"
7476
run: |
7577
set -x
7678
echo "(current dir): $PWD" && ls -l ./

RELEASE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Features:
2-
3-
* added timeout and retry to safeWget
2+
* ipfs-api: add integration tests
3+
* bip39gen: refactor, fix err handling

bash-utils/bash-utils.sh

Lines changed: 4 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.42"
29+
local BASH_UTILS_VERSION="v0.3.44"
3030
local COSIGN_VERSION="v2.0.0"
3131
if [ "$1" == "version" ] ; then
3232
echo "$BASH_UTILS_VERSION"
@@ -2312,3 +2312,6 @@ fi
23122312

23132313

23142314

2315+
2316+
2317+

bip39gen/cmd/mnemonic.go

Lines changed: 102 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,30 @@ func validateLengthFlagInput(length int) error {
2828
}
2929
return nil
3030
}
31+
func validateLengthEntropyInput(str string) error {
32+
if len(str) == 0 {
33+
return nil
34+
}
35+
36+
if (words/3)*32 != len(str) {
37+
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)))
38+
return err
39+
}
40+
return nil
41+
42+
}
3143

3244
// validateEntropyFlagInput checks if the provided entropy string is valid.
3345
func validateEntropyFlagInput(str string) error {
34-
if len(str) > 0 {
35-
match, _ := regexp.MatchString("^[0-1]{1,}$", str)
36-
if !match {
37-
return errBinary
38-
}
46+
if len(str) == 0 {
47+
return nil
48+
}
49+
50+
match, _ := regexp.MatchString("^[0-1]+$", str)
51+
if !match {
52+
return errBinary
3953
}
54+
4055
return nil
4156
}
4257

@@ -64,6 +79,79 @@ func checkInputPrefix(str string) string {
6479
}
6580
return str
6681
}
82+
func processSHA256() error {
83+
hex = true
84+
if words != 24 {
85+
fmt.Println(colors.Print("Warning. With sha256 you can generate 24 words", 3))
86+
words = 24
87+
}
88+
sum := sha256.Sum256([]byte(userEntropy))
89+
90+
userEntropy = string(sum[:])
91+
userEntropy = fmt.Sprintf("%x", userEntropy)
92+
93+
if err := validateHexEntropyFlagInput(userEntropy); err != nil {
94+
return err
95+
}
96+
return nil
97+
}
98+
99+
func processSHA512() error {
100+
hex = true
101+
if words != 48 {
102+
fmt.Println(colors.Print("Warning. With sha512 you can generate 48 words", 3))
103+
words = 48
104+
}
105+
sum := sha512.Sum512([]byte(userEntropy))
106+
107+
// Flip bytes to string hex
108+
userEntropy = string(sum[:])
109+
userEntropy = fmt.Sprintf("%x", userEntropy)
110+
111+
if err := validateHexEntropyFlagInput(userEntropy); err != nil {
112+
return err
113+
}
114+
return nil
115+
}
116+
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()
136+
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+
}
143+
func processPadding() error {
144+
hex = false
145+
if err := validateEntropyFlagInput(rawEntropy); err != nil {
146+
return err
147+
}
148+
bits := (words / 3) * 32
149+
bitsEnt := len(rawEntropy)
150+
for i := bitsEnt; i <= bits; i++ {
151+
rawEntropy += "0"
152+
}
153+
return nil
154+
}
67155

68156
// cmdMnemonicPreRun validates the provided flags and sets the required variables.
69157
func cmdMnemonicPreRun(cmd *cobra.Command, args []string) error {
@@ -90,85 +178,35 @@ func cmdMnemonicPreRun(cmd *cobra.Command, args []string) error {
90178
if err := validateEntropyFlagInput(i); err != nil {
91179
return err
92180
}
93-
if (words/3)*32 != len(userEntropy) {
94-
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)))
181+
err := validateLengthEntropyInput(i)
182+
if err != nil {
95183
return err
96184
}
185+
97186
}
98187

99188
}
189+
100190
}
101191
if (len(userEntropy) > 0 || len(rawEntropy) > 0) && len(cipher) != 0 {
102192
switch cipher {
103193
case "sha256":
104-
hex = true
105-
if words != 24 {
106-
fmt.Println(colors.Print("Warning. With sha256 you can generate 24 words", 3))
107-
words = 24
108-
}
109-
sum := sha256.Sum256([]byte(userEntropy))
110-
111-
userEntropy = string(sum[:])
112-
userEntropy = fmt.Sprintf("%x", userEntropy)
113-
114-
if err := validateHexEntropyFlagInput(userEntropy); err != nil {
194+
if err := processSHA256(); err != nil {
115195
return err
116196
}
117-
118197
case "sha512":
119-
hex = true
120-
if words != 48 {
121-
fmt.Println(colors.Print("Warning. With sha512 you can generate 48 words", 3))
122-
words = 48
123-
}
124-
sum := sha512.Sum512([]byte(userEntropy))
125-
126-
// Flip bytes to string hex
127-
userEntropy = string(sum[:])
128-
userEntropy = fmt.Sprintf("%x", userEntropy)
129-
130-
if err := validateHexEntropyFlagInput(userEntropy); err != nil {
198+
if err := processSHA512(); err != nil {
131199
return err
132200
}
133-
134201
case "chacha20":
135-
hex = true
136-
if words != 24 {
137-
fmt.Println(colors.Print("Warning. With sha256 you can generate 24 words", 3))
138-
words = 24
202+
if err := processChaCha20(); err != nil {
203+
return err
139204
}
140-
sum := sha256.Sum256([]byte(userEntropy))
141-
142-
// Flip bytes to string hex
143-
userEntropy = string(sum[:])
144-
userEntropy = fmt.Sprintf("%x", userEntropy)
145-
146-
aead, _ := chacha20poly1305.NewX(sum[:])
147-
148-
mnemonic := NewMnemonic()
149-
msg := mnemonic.String()
150-
151-
nonce := make([]byte, chacha20poly1305.NonceSizeX)
152-
ciphertext := aead.Seal(nil, nonce, []byte(msg), nil)
153-
154-
fmt.Printf("Cipher stream: %x\n", ciphertext)
155-
156-
mnemonic.Print(verbose)
157-
// should refactor this. Perhaps with a context.
158-
os.Exit(0)
159-
return nil
160205

161206
case "padding":
162-
hex = false
163-
if err := validateEntropyFlagInput(rawEntropy); err != nil {
207+
if err := processPadding(); err != nil {
164208
return err
165209
}
166-
bits := (words / 3) * 32
167-
bitsEnt := len(rawEntropy)
168-
for i := bitsEnt; i <= bits; i++ {
169-
rawEntropy += "0"
170-
}
171-
return nil
172210
}
173211
}
174212

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.39"
9+
const Bip39GenVersion = "v0.3.44"
1010

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

bip39gen/scripts/test.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ 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+
runTest() {
36+
local test_cmd="$1"
37+
local test_name="$2"
38+
39+
40+
# Execute the test command and get the exit code
41+
eval "$test_cmd &> /dev/null ||:"
42+
exit_code=$?
43+
44+
# Get the command name
45+
# Check the exit code and print the result
46+
if [ $exit_code -eq 0 ]; then
47+
echo "[PASS] $test_name"
48+
else
49+
bu echoError "[FAIL] $test_name"
50+
fi
51+
}
52+
3553

3654

3755

build-tools/update_version.py

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

66
if len(sys.argv) != 2:
77
print("Usage: python3 update_version.py <new_release>")
@@ -55,6 +55,8 @@ def updateVersion(path,ver):
5555
"../bip39gen/cmd/version.go":updateVersion,
5656
"../ipfs-api/types/constants.go":updateVersion,
5757
"../validator-key-gen/main.go":updateVersion,
58+
"../validator-key-gen/README.md":updateVersion,
59+
"../ipfs-api/README.md":updateVersion,
5860
}
5961

6062
new_release = sys.argv[1]

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.39" && rm -rfv /tmp/ipfs-api && \
8+
TOOLS_VERSION="v0.3.44" && 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/pkg/cli/pin.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cli
22

33
import (
44
"errors"
5-
"os"
65

76
"github.com/ipld/go-ipld-prime/datamodel"
87
log "github.com/kiracore/tools/ipfs-api/pkg/ipfslog"
@@ -113,7 +112,7 @@ func pinAndOutputResult(p *pnt.PinataApi, content string) error {
113112
}
114113
if err := p.OutputPinJson(); err != nil {
115114
log.Error("failed to print results: %v", err)
116-
os.Exit(1)
115+
return err
117116
}
118117
return nil
119118
}

0 commit comments

Comments
 (0)