Skip to content

Latest commit

 

History

History

bech32m

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

bech32m

A Go package for encoding and decoding bech32m addresses.

Overview

This package provides functionality to work with bech32m addresses, including encoding, decoding, and validation. It supports creating addresses from byte arrays and ED25519 public keys.

Installation

To install the package, use:

go get github.com/astriaorg/astria-cli-go/modules/bech32m

Usage

Importing the package

import "github.com/astriaorg/astria-cli-go/modules/bech32m"

Creating an address

From bytes:

prefix := "cosmos"
var data [20]byte
// ... fill data ...
address, err := bech32m.EncodeFromBytes(prefix, data)
if err != nil {
    // Handle error
}

From ED25519 public key:

prefix := "cosmos"
pubkey := ed25519.PublicKey(...)
address, err := bech32m.EncodeFromPublicKey(prefix, pubkey)
if err != nil {
    // Handle error
}

Validating an address

err := bech32m.Validate("astria1...")
if err != nil {
    // Address is invalid
}

Decoding an address

prefix, bytes, err := bech32m.DecodeFromString("astria1...")
if err != nil {
    // Handle error
}

Working with Address struct

// Get string representation
addressStr := address.String()

// Get prefix
prefix := address.Prefix()

// Get underlying bytes
bytes := address.Bytes()