bech32

package
v0.0.0-...-b0f9579 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2024 License: ISC Imports: 3 Imported by: 0

README

bech32

ISC License GoDoc

Package bech32 provides a Go implementation of the bech32 format.

Examples

Documentation

Overview

Package bech32 provides a Go implementation of the bech32 format.

Bech32 strings consist of a prefix, followed by the separator :, then a checksummed data part encoded using the 32 characters "qpzry9x8gf2tvdw0s3jn54khce6mua7l".

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(encoded string) (string, []byte, byte, error)

Decode decodes a string that was encoded with Encode.

Example

This example demonstrates how to decode a bech32 encoded string.

package main

import (
	"encoding/hex"
	"fmt"

	"github.com/shatll-s/nautiliad/util/bech32"
)

func main() {
	encoded := "customprefix!:::::q:ppzxzarpyp6x7grzv5sx2mnrdajx2epqd9h8gmeqgfjkx6pnxgc3swlew4"
	prefix, decoded, version, err := bech32.Decode(encoded)
	if err != nil {
		fmt.Println("Error:", err)
	}

	// Show the decoded data.
	fmt.Println("Decoded prefix:", prefix)
	fmt.Println("Decoded version:", version)
	fmt.Println("Decoded Data:", hex.EncodeToString(decoded))

}
Output:

Decoded prefix: customprefix!:::::q
Decoded version: 8
Decoded Data: 4461746120746f20626520656e636f64656420696e746f20426563683332

func Encode

func Encode(prefix string, payload []byte, version byte) string

Encode prepends the version byte, converts to uint5, and encodes to Bech32.

Example

This example demonstrates how to encode data into a bech32 string.

package main

import (
	"fmt"

	"github.com/shatll-s/nautiliad/util/bech32"
)

func main() {
	data := []byte("Data to be encoded into Bech32")
	encoded := bech32.Encode("customprefix!:::::q", data, 8)

	// Show the encoded data.
	fmt.Println("Encoded Data:", encoded)

}
Output:

Encoded Data: customprefix!:::::q:ppzxzarpyp6x7grzv5sx2mnrdajx2epqd9h8gmeqgfjkx6pnxgc3swlew4

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL