Craig Raw
4 years ago
10 changed files with 105 additions and 16 deletions
@ -1 +1 @@ |
|||||
Subproject commit deb45687c08d4ff824ab7559233249c345d9c86a |
Subproject commit 05674097428d25de043310f8ecddf06d998b3943 |
@ -0,0 +1,64 @@ |
|||||
|
package com.sparrowwallet.sparrow.io; |
||||
|
|
||||
|
import com.google.common.io.CharStreams; |
||||
|
import com.sparrowwallet.drongo.OutputDescriptor; |
||||
|
import com.sparrowwallet.drongo.protocol.ScriptType; |
||||
|
import com.sparrowwallet.drongo.wallet.Keystore; |
||||
|
import com.sparrowwallet.drongo.wallet.KeystoreSource; |
||||
|
import com.sparrowwallet.drongo.wallet.Wallet; |
||||
|
import com.sparrowwallet.drongo.wallet.WalletModel; |
||||
|
|
||||
|
import java.io.File; |
||||
|
import java.io.IOException; |
||||
|
import java.io.InputStream; |
||||
|
import java.io.InputStreamReader; |
||||
|
|
||||
|
public class SpecterDIY implements KeystoreFileImport { |
||||
|
@Override |
||||
|
public Keystore getKeystore(ScriptType scriptType, InputStream inputStream, String password) throws ImportException { |
||||
|
try { |
||||
|
String text = CharStreams.toString(new InputStreamReader(inputStream)); |
||||
|
String outputDesc = "sh(" + text + ")"; |
||||
|
OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(outputDesc); |
||||
|
Wallet wallet = outputDescriptor.toWallet(); |
||||
|
|
||||
|
if(wallet.getKeystores().size() != 1) { |
||||
|
throw new ImportException("Could not determine keystore from import"); |
||||
|
} |
||||
|
|
||||
|
Keystore keystore = wallet.getKeystores().get(0); |
||||
|
keystore.setLabel(getName()); |
||||
|
keystore.setWalletModel(WalletModel.SPECTER_DIY); |
||||
|
keystore.setSource(KeystoreSource.HW_AIRGAPPED); |
||||
|
|
||||
|
return keystore; |
||||
|
} catch(IOException e) { |
||||
|
throw new ImportException(e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean isKeystoreImportScannable() { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getKeystoreImportDescription() { |
||||
|
return "Import file or QR created by using the Master Public Keys feature on your Specter DIY device. Note the default is P2WPKH for Single Signature, and P2WSH for Multi Signature."; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean isEncrypted(File file) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getName() { |
||||
|
return "Specter DIY"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public WalletModel getWalletModel() { |
||||
|
return WalletModel.SPECTER_DIY; |
||||
|
} |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
package com.sparrowwallet.sparrow.io; |
||||
|
|
||||
|
import com.sparrowwallet.drongo.ExtendedKey; |
||||
|
import com.sparrowwallet.drongo.Network; |
||||
|
import com.sparrowwallet.drongo.protocol.ScriptType; |
||||
|
import com.sparrowwallet.drongo.wallet.Keystore; |
||||
|
import org.junit.Assert; |
||||
|
import org.junit.Test; |
||||
|
|
||||
|
public class SpecterDIYTest extends IoTest { |
||||
|
@Test |
||||
|
public void testImport() throws ImportException { |
||||
|
Network.set(Network.TESTNET); |
||||
|
SpecterDIY specterDIY = new SpecterDIY(); |
||||
|
Keystore keystore = specterDIY.getKeystore(ScriptType.P2WPKH, getInputStream("specter-diy-keystore.txt"), null); |
||||
|
|
||||
|
Assert.assertEquals("Specter DIY", keystore.getLabel()); |
||||
|
Assert.assertEquals("m/84'/1'/0'", keystore.getKeyDerivation().getDerivationPath()); |
||||
|
Assert.assertEquals("b317ec86", keystore.getKeyDerivation().getMasterFingerprint()); |
||||
|
Assert.assertEquals(ExtendedKey.fromDescriptor("vpub5YHLPnkkpPW1ecL7Di7Gv2wDHDtBNqRdt17gMULpxJ27ZA1MmW7xbZjdg1S7d5JKaJ8CiZEmRUHrEB6CGuLomA6ioVa1Pcke6fEb5CzDBU1"), keystore.getExtendedPublicKey()); |
||||
|
Assert.assertTrue(keystore.isValid()); |
||||
|
Network.set(Network.MAINNET); |
||||
|
} |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
[b317ec86/84h/1h/0h]vpub5YHLPnkkpPW1ecL7Di7Gv2wDHDtBNqRdt17gMULpxJ27ZA1MmW7xbZjdg1S7d5JKaJ8CiZEmRUHrEB6CGuLomA6ioVa1Pcke6fEb5CzDBU1 |
Loading…
Reference in new issue