Java implementation of Uniform Resources (UR)
Find a file
2020-10-15 08:46:52 +02:00
gradle/wrapper initial commit 2020-10-14 13:07:00 +02:00
src fix cbor exception exposure and improve crypto-psbt type handling 2020-10-15 08:46:52 +02:00
.gitignore gradle publish to maven repo 2020-10-14 18:36:37 +02:00
build.gradle fix cbor exception exposure and improve crypto-psbt type handling 2020-10-15 08:46:52 +02:00
gradlew initial commit 2020-10-14 13:07:00 +02:00
gradlew.bat initial commit 2020-10-14 13:07:00 +02:00
LICENSE initial commit 2020-10-14 13:07:00 +02:00
LICENSE (URKit) initial commit 2020-10-14 13:07:00 +02:00
README.md fix cbor exception exposure and improve crypto-psbt type handling 2020-10-15 08:46:52 +02:00
settings.gradle initial commit 2020-10-14 13:07:00 +02:00

Hummingbird

Java implementation of Uniform Resources (UR)

Hummingbird is a Java implementation of the Uniform Resources (UR) specification. It is a direct port of the URKit implementation by Wolf McNally. It contains both the classes to represent a UR, and a UR encoder and decoder to encode and decode to/from the QR representations.

Setup

Hummingbird is hosted in Maven Central and can be added as a dependency with the following:

implementation('com.sparrowwallet:hummingbird:1.1')

Usage

Decoding a UR can be done as follows (here decoding a crypto-psbt UR type):

URDecoder decoder = new URDecoder();
while(decoder.getResult() == null) {
    //Loop adding QR fragments to the decoder until it has a result
    String qrText = getFromNextQR();
    decoder.receivePart(qrText);
}

URDecoder.Result urResult = decoder.getResult();
if(urResult.type == ResultType.SUCCESS) {
    if(urResult.ur.getType().equals(UR.CRYPTO_PSBT_TYPE)) {
        byte[] psbt = urResult.ur.toBytes();       
    }
}

Encoding a UR:

final int MIN_FRAGMENT_LENGTH = 10;
final int MAX_FRAGMENT_LENGTH = 100;
String type = UR.BYTES_TYPE;

UR ur = UR.fromBytes(type, data);
UREncoder encoder = new UREncoder(ur, MAX_FRAGMENT_LENGTH, MIN_FRAGMENT_LENGTH, 0);
while(true) {
    String fragment = encoder.nextPart();
    //Show UR fragment as QR code...
}

Testing

Hummingbird has a thorough testsuite ported from URKit. The tests can be run with:

./gradlew test

License

Hummingbird is licensed under the Apache 2 software license.

Dependencies