Skip to content

Commit 5b8dbc8

Browse files
committed
Add summary helpers to mobile wrapper
1 parent 73705ff commit 5b8dbc8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

contrib/mobile/mobile.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mobile
22

33
import (
4+
"crypto/ed25519"
45
"encoding/hex"
56
"encoding/json"
67
"net"
@@ -273,3 +274,28 @@ func (m *Yggdrasil) GetMTU() int {
273274
func GetVersion() string {
274275
return version.BuildVersion()
275276
}
277+
278+
type ConfigSummary struct {
279+
PublicKey string
280+
IPv6Address string
281+
IPv6Subnet string
282+
}
283+
284+
func SummaryForConfig(b []byte) *ConfigSummary {
285+
cfg := config.GenerateConfig()
286+
if err := cfg.UnmarshalHJSON(b); err != nil {
287+
return nil
288+
}
289+
pub := ed25519.PrivateKey(cfg.PrivateKey).Public().(ed25519.PublicKey)
290+
hpub := hex.EncodeToString(pub)
291+
addr := net.IP(address.AddrForKey(pub)[:])
292+
snet := net.IPNet{
293+
IP: append(address.SubnetForKey(pub)[:], 0, 0, 0, 0, 0, 0, 0, 0),
294+
Mask: net.CIDRMask(64, 128),
295+
}
296+
return &ConfigSummary{
297+
PublicKey: hpub,
298+
IPv6Address: addr.String(),
299+
IPv6Subnet: snet.String(),
300+
}
301+
}

0 commit comments

Comments
 (0)