mirror of
https://github.com/sparrowwallet/hummingbird.git
synced 2024-11-02 18:46:45 +00:00
Merge pull request #7 from proxyco/feat/crypto-sskr
feat(Crypto-sskr): added crypto-sskr UR support
This commit is contained in:
commit
e9799146a2
5 changed files with 75 additions and 2 deletions
|
@ -16,7 +16,7 @@ apply plugin: 'com.bmuschko.nexus'
|
||||||
|
|
||||||
archivesBaseName = 'hummingbird'
|
archivesBaseName = 'hummingbird'
|
||||||
group 'com.sparrowwallet'
|
group 'com.sparrowwallet'
|
||||||
version '1.6.5'
|
version '1.6.6'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
|
@ -76,6 +76,8 @@ public class UR {
|
||||||
return CryptoPSBT.fromCbor(item);
|
return CryptoPSBT.fromCbor(item);
|
||||||
} else if(registryType == RegistryType.CRYPTO_ACCOUNT) {
|
} else if(registryType == RegistryType.CRYPTO_ACCOUNT) {
|
||||||
return CryptoAccount.fromCbor(item);
|
return CryptoAccount.fromCbor(item);
|
||||||
|
} else if(registryType == RegistryType.CRYPTO_SSKR) {
|
||||||
|
return CryptoSskr.fromCbor(item);
|
||||||
}
|
}
|
||||||
} catch(CborException e) {
|
} catch(CborException e) {
|
||||||
throw new InvalidCBORException(e.getMessage());
|
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_ECKEY("crypto-eckey", 306, CryptoECKey.class),
|
||||||
CRYPTO_ADDRESS("crypto-address", 307, CryptoAddress.class),
|
CRYPTO_ADDRESS("crypto-address", 307, CryptoAddress.class),
|
||||||
CRYPTO_OUTPUT("crypto-output", 308, CryptoOutput.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_PSBT("crypto-psbt", 310, CryptoPSBT.class),
|
||||||
CRYPTO_ACCOUNT("crypto-account", 311, CryptoAccount.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