Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
/ref/java/out
/ref/java/build
/ref/java/.gradle
50 changes: 50 additions & 0 deletions ref/java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Bech32 Java

## Usage

This [Bech32](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki) implementation is
designed to be a standalone drop-in library for your Java and Android projects. <br/>

Based entirely on the Java Standard library, it allows either to validate a **Bech32 String** or a **Bech32 Segwit Address**. <br/>
In the latter case it's possible to decode, with the **SegwitAddress** class, an address in a way that throws an exception with
the releated issue if it's an invalid one. Otherwise it's possible to get back a *null* object if the
address is invalid.


```java
Bech32 bech32 = new Bech32();

// Returns a valid Bech32Decoded object
mBech32.decode("A12UEL5L");

// Throws a Bech32ValidationException
mBech32.decode("x1b4n0q5v");
```
```java
SegwitAddress segwitAddress = new SegwitAddress();

// Returns a valid SegwitAddress object
segwitAddress.decode("bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", "bc");

// Returns a null object
segwitAddress.decode("bc1zw508d6qejxtdg4y5r3zarvaryvqyzf3du", "bc");

// Throws a Bech32ValidationException
segwitAddress.decodeThrowing("bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5", "bc");
```

## Running tests

The project is integrated with Gradle, but thanks to its design can be built using your favourite build system. </br>
It depends on JUnit's `org.junit.Assert` class in order to assert the test results. <br/>
In order to run the tests launch via the command line these two gradle tasks. <br/>
Note that a **gradlew** binary is already included when cloning this repository.

```
$ ./gradlew --refresh-dependencies
$ ./gradlew test

BUILD SUCCESSFUL in 0s
3 actionable tasks: 3 up-to-date
```

16 changes: 16 additions & 0 deletions ref/java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
id 'java'
}

group 'com.conio.wallet'
version '1.0'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
Binary file added ref/java/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions ref/java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
172 changes: 172 additions & 0 deletions ref/java/gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading