v1.4 get cryptoaccount from ur registry

This commit is contained in:
Craig Raw 2020-11-11 13:40:58 +02:00
parent 096c09f070
commit 7ad7545749
4 changed files with 24 additions and 3 deletions

View file

@ -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:

View file

@ -16,7 +16,7 @@ apply plugin: 'com.bmuschko.nexus'
archivesBaseName = 'hummingbird'
group 'com.sparrowwallet'
version '1.3'
version '1.4'
repositories {
mavenCentral()

View file

@ -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());

View file

@ -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;