mirror of
https://github.com/sparrowwallet/hummingbird.git
synced 2024-11-02 18:46:45 +00:00
Merge branch 'master' of github.com:sparrowwallet/hummingbird
This commit is contained in:
commit
1fe0489ceb
6 changed files with 76 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -16,7 +16,7 @@ apply plugin: 'com.bmuschko.nexus'
|
|||
|
||||
archivesBaseName = 'hummingbird'
|
||||
group 'com.sparrowwallet'
|
||||
version '1.6.5'
|
||||
version '1.6.6'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue