summaryrefslogtreecommitdiff
path: root/tools/boxkey/convertBoxKey.go
blob: 0d77d2f84b0255e1d6db538b9cb906cabafcb857 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand.  If not, see <https://www.gnu.org/licenses/>.

package main

import (
	"encoding/base64"
	"encoding/hex"
	"flag"
	"fmt"

	"github.com/algorand/avm-abi/apps"
)

func main() {
	var name string
	var appIdx uint64
	flag.Uint64Var(&appIdx, "a", 0, "base64/algorand address to convert to the other")
	flag.StringVar(&name, "n", "", "base64 box name")
	flag.Parse()

	if appIdx == 0 && name == "" {
		fmt.Println("provide input with '-a' and '-k' flags.")
		return
	}

	nameBytes, err := base64.StdEncoding.DecodeString(name)
	if err != nil {
		fmt.Println("invalid key value")
		return
	}
	key := apps.MakeBoxKey(appIdx, string(nameBytes))
	fmt.Println(base64.StdEncoding.EncodeToString([]byte(key)))
	fmt.Println(hex.EncodeToString([]byte(key)))
}