Golang: アルゴランド アドレスを公開鍵に変換する


アルゴランド SDK をインストールします.

$ go get -u github.com/algorand/go-algorand-sdk/...




import (
    "crypto/ed25519"
    "crypto/sha512"
    "encoding/base64"

    algocrypto "github.com/algorand/go-algorand-sdk/crypto"
    "github.com/algorand/go-algorand-sdk/types"
)


func algoAddrToPublicKey(address string) (ed25519.PublicKey, error) {
    addr, err := types.DecodeAddress(address)
    if err != nil {
        return nil, err
    }
    bytes := [sha512.Size256]byte(addr)
    return ed25519.PublicKey(bytes[:]), nil
}

func main() {
    addr := "<wallet address, 58 characters>"
    pubKey, _ := algoAddrToPublicKey(addr)
    msg := "message to sign"
    // if raw sigature is base64 encoded, we need to decode it
    sig, _ := base64.StdEncoding.DecodeString(rawSig)
    valid := algocrypto.VerifyBytes(pubKey, []byte(msg), sig)
}