recode

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: MIT Imports: 6 Imported by: 0

README ΒΆ

recode

test lint Go Reference

Package recode provides functionality to encode and decode any byte data into a mnemonic and back, using a custom word list.

The word list must have a length that is a power of two (e.g., 2, 4, 8, 16, ...).

Example

package main

import (
    "log"
    "github.com/fullpipe/recode"
)

func main() {
    rec, err := recode.NewDictionary(
        []string{"my", "own", "random", "words", "to", "have", "more", "fun"},
    )
    if err != nil {
        log.Fatal(err)
    }

    // Encode the byte data
    mnemonic, err := rec.Encode([]byte("nice!"))
    if err != nil {
        log.Fatal(err)
    }

    log.Println(mnemonic) // have words words to more to have ...

    // Decode the mnemonic back to byte data
    decoded, err := rec.Decode(mnemonic)
    if err != nil {
        log.Fatal(err)
        return
    }
    log.Println(string(decoded)) // nice!
}

You can use more familiar dictionaries like bip39 or slip39:

recBip, _ := recode.NewDictionary(recode.Bip39Dictionary)
recSlip, _ := recode.NewDictionary(recode.Slip39Dictionary)

Beware: The resulting mnemonic will differ from the original bip39 and slip39!

But who needs bip39 if you can use fruits & vegetables?

...
entropy, _ := bip39.NewEntropy(256)

fruits, _ := recode.NewDictionary([]string{"πŸ‡", "🍈", "πŸ‰", "🍊", "πŸ‹", "🍌", "🍍", "πŸ₯­", "🍎", "🍐", "πŸ‘", "πŸ’", "πŸ“", "🫐", "πŸ₯", "πŸ…", "πŸ«’", "πŸ₯₯", "πŸ₯‘", "πŸ†", "πŸ₯”", "πŸ₯•", "🌽", "🌢️", "πŸ«‘", "πŸ₯’", "πŸ₯¬", "πŸ₯¦", "πŸ§„", "πŸ§…", "πŸ₯œ", "🫘"})

salat, _ := fruits.Encode(entropy)

log.Println(string(salat)) // πŸ’ πŸ§„ πŸ† πŸ₯• πŸ₯‘ πŸ«‘ πŸ‰ πŸ‡ πŸ₯” 🫚 πŸ₯₯ 🍍 🍎 🌽 πŸ‘ ...

Features

  • Custom Word List: Use your own set of words for encoding and decoding.
  • Flexible: Works with any byte data, of any length.

Contributing

Contributions are welcome! Please submit a pull request or open an issue for any bugs or feature requests.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

View Source
var Bip39Dictionary = []string{} /* 2048 elements not displayed */
View Source
var Slip39Dictionary = []string{} /* 1024 elements not displayed */

Functions ΒΆ

This section is empty.

Types ΒΆ

type Recoder ΒΆ

type Recoder interface {
	// Encode converts the input byte slice into a mnemonic.
	Encode(data []byte) ([]string, error)

	// Decode takes a mnemonic and returns the original byte slice.
	Decode(mnemonic []string) ([]byte, error)
}

func NewDictionary ΒΆ

func NewDictionary(words []string) (Recoder, error)

NewDictionary creates a new Recoder instance using the provided slice of words. Returns an error if there are any problems with the words.

Jump to

Keyboard shortcuts

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