diff --git a/README.md b/README.md index 6ba24a4..1d2c6c3 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Hummingbird requires a minimum of Java 8. Hummingbird is hosted in Maven Central and can be added as a dependency with the following: ``` -implementation('com.sparrowwallet:hummingbird:1.6.5') +implementation('com.sparrowwallet:hummingbird:1.6.6') ``` ## Usage diff --git a/build.gradle b/build.gradle index 70bdf7f..53fe069 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ apply plugin: 'com.bmuschko.nexus' archivesBaseName = 'hummingbird' group 'com.sparrowwallet' -version '1.6.5' +version '1.6.6' repositories { mavenCentral() diff --git a/src/main/java/com/sparrowwallet/hummingbird/UR.java b/src/main/java/com/sparrowwallet/hummingbird/UR.java index 91e885f..dacfdb8 100644 --- a/src/main/java/com/sparrowwallet/hummingbird/UR.java +++ b/src/main/java/com/sparrowwallet/hummingbird/UR.java @@ -76,6 +76,8 @@ public class UR { return CryptoPSBT.fromCbor(item); } else if(registryType == RegistryType.CRYPTO_ACCOUNT) { return CryptoAccount.fromCbor(item); + } else if(registryType == RegistryType.CRYPTO_SSKR) { + return CryptoSskr.fromCbor(item); } } catch(CborException e) { throw new InvalidCBORException(e.getMessage()); diff --git a/src/main/java/com/sparrowwallet/hummingbird/registry/CryptoSskr.java b/src/main/java/com/sparrowwallet/hummingbird/registry/CryptoSskr.java new file mode 100644 index 0000000..fa806b0 --- /dev/null +++ b/src/main/java/com/sparrowwallet/hummingbird/registry/CryptoSskr.java @@ -0,0 +1,34 @@ +package com.sparrowwallet.hummingbird.registry; + +import java.util.Arrays; + +import co.nstant.in.cbor.model.ByteString; +import co.nstant.in.cbor.model.DataItem; + +public class CryptoSskr extends RegistryItem { + + private final byte[] split; + + public CryptoSskr(byte[] split) { + this.split = split; + } + + public byte[] getSplit() { + return split; + } + + public DataItem toCbor() { + return new ByteString(split); + } + + @Override + public RegistryType getRegistryType() { + return RegistryType.CRYPTO_SSKR; + } + + public static CryptoSskr fromCbor(DataItem item) { + byte[] itemBytes = ((ByteString)item).getBytes(); + byte[] normalisedSplit = Arrays.copyOfRange(itemBytes, 1, itemBytes.length); + return new CryptoSskr(normalisedSplit); + } +} diff --git a/src/main/java/com/sparrowwallet/hummingbird/registry/RegistryType.java b/src/main/java/com/sparrowwallet/hummingbird/registry/RegistryType.java index 5e143a4..822a496 100644 --- a/src/main/java/com/sparrowwallet/hummingbird/registry/RegistryType.java +++ b/src/main/java/com/sparrowwallet/hummingbird/registry/RegistryType.java @@ -20,7 +20,7 @@ public enum RegistryType { CRYPTO_ECKEY("crypto-eckey", 306, CryptoECKey.class), CRYPTO_ADDRESS("crypto-address", 307, CryptoAddress.class), CRYPTO_OUTPUT("crypto-output", 308, CryptoOutput.class), - CRYPTO_SSKR("crypto-sskr", 309, null), + CRYPTO_SSKR("crypto-sskr", 309, CryptoSskr.class), CRYPTO_PSBT("crypto-psbt", 310, CryptoPSBT.class), CRYPTO_ACCOUNT("crypto-account", 311, CryptoAccount.class); diff --git a/src/test/java/com/sparrowwallet/hummingbird/registry/CryptoSskrTest.java b/src/test/java/com/sparrowwallet/hummingbird/registry/CryptoSskrTest.java new file mode 100644 index 0000000..38f3bb4 --- /dev/null +++ b/src/test/java/com/sparrowwallet/hummingbird/registry/CryptoSskrTest.java @@ -0,0 +1,37 @@ +package com.sparrowwallet.hummingbird.registry; + +import com.sparrowwallet.hummingbird.TestUtils; +import com.sparrowwallet.hummingbird.UR; +import com.sparrowwallet.hummingbird.URDecoder; + +import org.junit.Assert; +import org.junit.Test; + +import java.nio.charset.StandardCharsets; +import java.util.List; + +import co.nstant.in.cbor.CborDecoder; +import co.nstant.in.cbor.CborException; +import co.nstant.in.cbor.model.ByteString; +import co.nstant.in.cbor.model.DataItem; +import co.nstant.in.cbor.model.UnicodeString; + +public class CryptoSskrTest { + + private final String splitVector = "4bbf1101025abd490ee65b6084859854ee67736e75"; + private final String urVector = "ur:crypto-sskr/gogrrsbyadaohtrygabavahphnlrlpmkghwyiojkjtkpmdkncfjp"; + + @Test + public void testSskrToUR() { + byte[] data = TestUtils.hexToBytes(splitVector); + CryptoSskr cryptoSskr = new CryptoSskr(data); + Assert.assertEquals(urVector, cryptoSskr.toUR().toString()); + } + + @Test + public void testURtoSskr() throws UR.URException { + UR ur = URDecoder.decode(urVector); + CryptoSskr cryptoSskr = CryptoSskr.fromCbor(new ByteString(ur.getCborBytes())); + Assert.assertEquals(splitVector, TestUtils.bytesToHex(cryptoSskr.getSplit())); + } +}