aboutsummaryrefslogtreecommitdiffstats
path: root/gosrc
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2022-04-03 17:59:14 +0200
committersalaaad2 <arthurdurant263@gmail.com>2022-04-03 17:59:14 +0200
commitf2f7654a416b7ad0715ddf93f635021c62eb6c87 (patch)
treefd0a7b4b474eb4b411692ed5b0c0b86b2ec3a711 /gosrc
parentsigning requests (diff)
downloadsmith-f2f7654a416b7ad0715ddf93f635021c62eb6c87.tar.gz
smith-f2f7654a416b7ad0715ddf93f635021c62eb6c87.tar.bz2
smith-f2f7654a416b7ad0715ddf93f635021c62eb6c87.tar.xz
smith-f2f7654a416b7ad0715ddf93f635021c62eb6c87.tar.zst
smith-f2f7654a416b7ad0715ddf93f635021c62eb6c87.zip
go: trimmed signature switched to termui \nc: added get_timestamp function
Diffstat (limited to 'gosrc')
-rw-r--r--gosrc/main.go39
-rw-r--r--gosrc/pipes.go6
-rw-r--r--gosrc/requests.go28
3 files changed, 61 insertions, 12 deletions
diff --git a/gosrc/main.go b/gosrc/main.go
index 9923d09..435dac1 100644
--- a/gosrc/main.go
+++ b/gosrc/main.go
@@ -8,10 +8,13 @@ package main
import (
"encoding/json"
- "fmt"
"io/ioutil"
+ "fmt"
"log"
"os"
+
+ ui "github.com/gizak/termui/v3"
+ "github.com/gizak/termui/v3/widgets"
)
// #include "../csrc/smith.h"
@@ -28,28 +31,52 @@ func main() {
fmt.Println("Welcome, traveller, my name is " + Styles.colorGreen + C.GoString(C.mr_smith()) + Styles.colorReset +
"\nI will try to help you get the bag...")
+ // get user config from json file
config_path := "./config.json"
for i, a := range os.Args[1:] {
if a == "-c" || a == "--config" {
config_path = os.Args[i + 2]
}
}
-
config_content, err := ioutil.ReadFile(config_path)
if err != nil {
- log.Fatal("config file not found")
+ log.Fatal("error: config file not found", err)
}
-
var config Config
err = json.Unmarshal(config_content, &config)
if err != nil {
- log.Fatal("error during marshall() ", err)
+ log.Fatal("error: marshall() ", err)
}
+ make_ui()
+
fmt.Println("\n" +
Styles.colorBlue + "public_key: " + Styles.colorReset + config.Public_key + "\n" +
Styles.colorBlue + "secret_key: " + Styles.colorReset + config.Secret_key + "\n" +
Styles.colorBlue + "mirror: " + Styles.colorReset + config.Mirror)
- make_body("qwe", "qwe", "qwe")
+ // make request body and sign it
+ body := make_body("qwe", "qwe", "qwe")
+ fmt.Println(body)
+ signature := sign_request(body, config.Secret_key)
+ fmt.Println("[" + signature + "]")
+}
+
+func make_ui() error {
+ if err := ui.Init(); err != nil {
+ log.Fatal("error: failed to initialize termui", err)
+ }
+
+ p:= widgets.NewParagraph()
+ p.Text = "hello"
+ p.SetRect(0, 0, 25, 5)
+ ui.Render(p)
+
+ for e := range ui.PollEvents() {
+ if e.Type == ui.KeyboardEvent {
+ return nil
+ }
+ }
+
+ return nil
}
diff --git a/gosrc/pipes.go b/gosrc/pipes.go
index f668821..0d77b45 100644
--- a/gosrc/pipes.go
+++ b/gosrc/pipes.go
@@ -1,3 +1,9 @@
+// SMITH ( // /
+// pipes ( )/ /
+// by salade )(/ /
+// ________________ ( /) /
+// ()__)____________))))) :^} /
+
package main
import (
diff --git a/gosrc/requests.go b/gosrc/requests.go
index 4e94533..7be1d49 100644
--- a/gosrc/requests.go
+++ b/gosrc/requests.go
@@ -1,23 +1,39 @@
+// SMITH ( // /
+// requests ( )/ /
+// by salade )(/ /
+// ________________ ( /) /
+// ()__)____________))))) :^} /
+
package main
import (
"fmt"
"log"
+ "strings"
)
-func sign_request(body string, key string) {
+// sign request with given private key
+func sign_request(body string, key string) string {
fmt.Println("signing request : ", body)
+ // run pipeline
out2, err := RunStrings("/usr/bin/echo", "-n", body, "|", "/usr/bin/openssl", "dgst", "-sha256", "-hmac", key)
if err != nil {
- log.Fatal("hwhat")
+ log.Fatal("error: failed to sign request", err)
}
- fmt.Println(out2)
- // here
+ // remove unwanted characters
+ tok := strings.Index(out2, "(")
+ last := len(out2) - 1
+ first := tok + len("(stdin)= ")
+ out2 = out2[first:last]
+ return out2
}
-func make_body(order string, ticker string, price string) {
+// create body given choice ex :
+// GET /sapi/v1/capital/config/getall ||
+// POST /sapi/v1/asset/dust-btc
+func make_body(order string, ticker string, price string) string {
ret := "GET /sapi/v1/capital/config/getall"
- sign_request(ret, "heheheheh")
+ return ret
}