add hash subcommand
This commit is contained in:
parent
d2076da9a0
commit
bf5d18e73a
|
@ -21,6 +21,7 @@ Usage:
|
|||
hashcash new [subject *] [expires in 5m] [difficulty 10]
|
||||
hashcash parse <hashcash>
|
||||
hashcash solve <hashcash>
|
||||
hashcash hash <hashcash>
|
||||
hashcash verify <hashcash> [subject *]
|
||||
```
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -15,6 +17,7 @@ func help() {
|
|||
fmt.Println("\thashcash new [subject *] [difficulty 10] [expires in 5m]")
|
||||
fmt.Println("\thashcash parse <hashcash>")
|
||||
fmt.Println("\thashcash solve <hashcash>")
|
||||
fmt.Println("\thashcash hash <hashcash>")
|
||||
fmt.Println("\thashcash verify <hashcash> [subject *]")
|
||||
}
|
||||
|
||||
|
@ -107,6 +110,17 @@ func main() {
|
|||
|
||||
fmt.Println(h.String())
|
||||
return
|
||||
case "hash":
|
||||
var token string
|
||||
if 3 != nargs {
|
||||
help()
|
||||
os.Exit(1)
|
||||
return
|
||||
}
|
||||
token = args[2]
|
||||
hash := sha256.Sum256([]byte(token))
|
||||
fmt.Println(hex.EncodeToString(hash[:]))
|
||||
return
|
||||
case "verify":
|
||||
var token string
|
||||
if nargs < 3 {
|
||||
|
|
Loading…
Reference in New Issue