add command to convert pubkey to ipv6 addr

standalone cli tool like genkeys/main.go that uses
the address.AddrForKey function to convert a pubkey
to an IPv6 address.

```
+$ go run main.go <thepubkey>.
+IP: <theipv6ip>
```
This commit is contained in:
Rick van de Loo 2022-02-22 15:24:32 +01:00
parent 559e31c502
commit 01c48ed17d
2 changed files with 28 additions and 0 deletions

26
cmd/addrforkey/main.go Normal file
View file

@ -0,0 +1,26 @@
/*
This file converts a public to to an IPv6 address. Example:
$ go run main.go <pubkey>.
IP: <ipv6ip>
*/
package main
import (
"encoding/hex"
"fmt"
"net"
"os"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
)
func main() {
pub, err := hex.DecodeString(os.Args[1])
if err != nil {
fmt.Println("Failed to decode provided public key")
os.Exit(1)
}
addr := address.AddrForKey(pub)
fmt.Println("IP:", net.IP(addr[:]).String())
}