Skip to content

Latest commit

 

History

History
108 lines (77 loc) · 3.08 KB

README.md

File metadata and controls

108 lines (77 loc) · 3.08 KB

Copper Multibase Encoder and Decoder.

A Java implementation of Multibase.

Java 8 CI Maven Central License

Features

  • static registry
    • no lookups when encoding
    • direct static access to an encoder
    • configurable set of encodings to support when decoding
  • built-in bases
    • Base2
    • Base16 (lower|upper)
    • Base32 (lower|upper, [no-]padding)
    • Base32Hex (lower|upper, [no-]padding)
    • Base58BTC
    • Base64 ([no-]padding)
    • Base64URL ([no-]padding)
  • no 3rd party dependencies
  • easily extendable

Examples

/* encode an input with Base58BTC */
String encoded = Multibase.BASE_58_BTC.encode(byte[]);

/* get decoder instance initialized with all supported bases */
var decoder = MultibaseDecoder.getInstance();

/* get decoder initialized with custom base(s) */
var decoder = MultibaseDecoder.getInstance(cbases...);

/* decode */
byte[] decoded = decoder.decode(encoded);

/* or check if base is supported  */
Multibase base = decoder.getBase(encoded).orElseThrow(() -> new IllegalArgumentException("Unsupported base."));
byte[] decoded = base.decode(encoded);

/* or directy when only one base is supported */
byte[] decoded = Multibase.BASE_58_BTC.decode(encoded);

/* check if encoded with a base */
if (Multibase.BASE_58_BTC.isEncoded(encoded)) {
  ...
}

/* a cutom base implementation */
var mybase = new Multibase(
                     prefix,   // multibase prefix letter
                     length,   // alphabet length
                     string -> byte[], // decode fnc.
                     byte[] -> string // encode fnc.
                     );

/* encode with a custom base */
String encoded = mybase.encode(byte[]);

/* directly decode with a custom base */
byte[] decoded = mybase.decode(encoded);

/* get decoder initialized with a custom base */
var decoder = MultibaseDecorer.getInstance(mybase, ...);

Installation

Maven

<dependency>
    <groupId>com.apicatalog</groupId>
    <artifactId>copper-multibase</artifactId>
    <version>1.0.0</version>
</dependency>

Documentation

javadoc

Contributing

All PR's welcome!

Building

Fork and clone the project repository.

> cd copper-multibase
> mvn clean package

Resources