DEV Community

Bo
Bo

Posted on

 

Golang: convert algorand address to public key

Install Algorand SDK:

$ go get -u github.com/algorand/go-algorand-sdk/...
Enter fullscreen mode Exit fullscreen mode

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)
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.