diff --git a/README.md b/README.md index ff08ec6..c2ac21b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ It contains both the classes to represent a UR, and a UR encoder and decoder to Hummingbird is hosted in Maven Central and can be added as a dependency with the following: ``` -implementation('com.sparrowwallet:hummingbird:1.3') +implementation('com.sparrowwallet:hummingbird:1.4') ``` ## Usage @@ -49,6 +49,25 @@ while(true) { } ``` +Hummingbird also includes a type registry to assist with decoding from CBOR to POJOs: + +```java +RegistryType urRegistryType = ur.getRegistryType(); +if(urRegistryType.equals(RegistryType.CRYPTO_PSBT)) { + CryptoPSBT cryptoPSBT = (CryptoPSBT)ur.decodeFromRegistry(); +} else if(urRegistryType.equals(RegistryType.CRYPTO_ADDRESS)) { + CryptoAddress cryptoAddress = (CryptoAddress)ur.decodeFromRegistry(); +} else if(urRegistryType.equals(RegistryType.CRYPTO_HDKEY)) { + CryptoHDKey cryptoHDKey = (CryptoHDKey)ur.decodeFromRegistry(); +} else if(urRegistryType.equals(RegistryType.CRYPTO_OUTPUT)) { + CryptoOutput cryptoOutput = (CryptoOutput)ur.decodeFromRegistry(); +} else if(urRegistryType.equals(RegistryType.CRYPTO_ACCOUNT)) { + CryptoAccount cryptoAccount = (CryptoAccount)ur.decodeFromRegistry(); +} +``` + +See `RegistryType.java` for the full list of supported types and their POJO implementation classes where available. + ## Testing Hummingbird has a thorough testsuite ported from URKit. The tests can be run with: diff --git a/build.gradle b/build.gradle index 7f5362b..d83d5e6 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ apply plugin: 'com.bmuschko.nexus' archivesBaseName = 'hummingbird' group 'com.sparrowwallet' -version '1.3' +version '1.4' repositories { mavenCentral() diff --git a/src/main/java/com/sparrowwallet/hummingbird/UR.java b/src/main/java/com/sparrowwallet/hummingbird/UR.java index 0426672..91e885f 100644 --- a/src/main/java/com/sparrowwallet/hummingbird/UR.java +++ b/src/main/java/com/sparrowwallet/hummingbird/UR.java @@ -74,6 +74,8 @@ public class UR { return CryptoOutput.fromCbor(item); } else if(registryType == RegistryType.CRYPTO_PSBT) { return CryptoPSBT.fromCbor(item); + } else if(registryType == RegistryType.CRYPTO_ACCOUNT) { + return CryptoAccount.fromCbor(item); } } catch(CborException e) { throw new InvalidCBORException(e.getMessage()); diff --git a/src/main/java/com/sparrowwallet/hummingbird/registry/CryptoAddress.java b/src/main/java/com/sparrowwallet/hummingbird/registry/CryptoAddress.java index e4aaa6c..43ddaa7 100644 --- a/src/main/java/com/sparrowwallet/hummingbird/registry/CryptoAddress.java +++ b/src/main/java/com/sparrowwallet/hummingbird/registry/CryptoAddress.java @@ -31,7 +31,7 @@ public class CryptoAddress { public static CryptoAddress fromCbor(DataItem item) { CryptoCoinInfo info = null; - Type type = null; + Type type = Type.P2PKH; byte[] data = null; Map map = (Map)item;