|
@ -1,7 +1,7 @@ |
|
|
package com.sparrowwallet.sparrow.io; |
|
|
package com.sparrowwallet.sparrow.io; |
|
|
|
|
|
|
|
|
import com.google.common.io.ByteStreams; |
|
|
import com.google.common.io.ByteStreams; |
|
|
import com.sparrowwallet.drongo.ExtendedPublicKey; |
|
|
import com.sparrowwallet.drongo.ExtendedKey; |
|
|
import com.sparrowwallet.drongo.policy.PolicyType; |
|
|
import com.sparrowwallet.drongo.policy.PolicyType; |
|
|
import com.sparrowwallet.drongo.protocol.ScriptType; |
|
|
import com.sparrowwallet.drongo.protocol.ScriptType; |
|
|
import com.sparrowwallet.drongo.wallet.Keystore; |
|
|
import com.sparrowwallet.drongo.wallet.Keystore; |
|
@ -15,46 +15,46 @@ public class ColdcardMultisigTest extends IoTest { |
|
|
@Test |
|
|
@Test |
|
|
public void importKeystore1() throws ImportException { |
|
|
public void importKeystore1() throws ImportException { |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
Keystore keystore = ccMultisig.getKeystore(ScriptType.P2SH_P2WSH, getInputStream("cc-multisig-keystore-1.json")); |
|
|
Keystore keystore = ccMultisig.getKeystore(ScriptType.P2SH_P2WSH, getInputStream("cc-multisig-keystore-1.json"), null); |
|
|
Assert.assertEquals("Coldcard 0F056943", keystore.getLabel()); |
|
|
Assert.assertEquals("Coldcard 0F056943", keystore.getLabel()); |
|
|
Assert.assertEquals("m/48'/1'/0'/1'", keystore.getKeyDerivation().getDerivationPath()); |
|
|
Assert.assertEquals("m/48'/1'/0'/1'", keystore.getKeyDerivation().getDerivationPath()); |
|
|
Assert.assertEquals("0f056943", keystore.getKeyDerivation().getMasterFingerprint()); |
|
|
Assert.assertEquals("0f056943", keystore.getKeyDerivation().getMasterFingerprint()); |
|
|
Assert.assertEquals(ExtendedPublicKey.fromDescriptor("Upub5T4XUooQzDXL58NCHk8ZCw9BsRSLCtnyHeZEExAq1XdnBFXiXVrHFuvvmh3TnCR7XmKHxkwqdACv68z7QKT1vwru9L1SZSsw8B2fuBvtSa6"), keystore.getExtendedPublicKey()); |
|
|
Assert.assertEquals(ExtendedKey.fromDescriptor("Upub5T4XUooQzDXL58NCHk8ZCw9BsRSLCtnyHeZEExAq1XdnBFXiXVrHFuvvmh3TnCR7XmKHxkwqdACv68z7QKT1vwru9L1SZSsw8B2fuBvtSa6"), keystore.getExtendedPublicKey()); |
|
|
Assert.assertTrue(keystore.isValid()); |
|
|
Assert.assertTrue(keystore.isValid()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test(expected = ImportException.class) |
|
|
@Test(expected = ImportException.class) |
|
|
public void importKeystore1IncorrectScriptType() throws ImportException { |
|
|
public void importKeystore1IncorrectScriptType() throws ImportException { |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
Keystore keystore = ccMultisig.getKeystore(ScriptType.P2SH_P2WPKH, getInputStream("cc-multisig-keystore-1.json")); |
|
|
Keystore keystore = ccMultisig.getKeystore(ScriptType.P2SH_P2WPKH, getInputStream("cc-multisig-keystore-1.json"), null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void importKeystore2() throws ImportException { |
|
|
public void importKeystore2() throws ImportException { |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
Keystore keystore = ccMultisig.getKeystore(ScriptType.P2SH, getInputStream("cc-multisig-keystore-2.json")); |
|
|
Keystore keystore = ccMultisig.getKeystore(ScriptType.P2SH, getInputStream("cc-multisig-keystore-2.json"), null); |
|
|
Assert.assertEquals("Coldcard 6BA6CFD0", keystore.getLabel()); |
|
|
Assert.assertEquals("Coldcard 6BA6CFD0", keystore.getLabel()); |
|
|
Assert.assertEquals("m/45'", keystore.getKeyDerivation().getDerivationPath()); |
|
|
Assert.assertEquals("m/45'", keystore.getKeyDerivation().getDerivationPath()); |
|
|
Assert.assertEquals("6ba6cfd0", keystore.getKeyDerivation().getMasterFingerprint()); |
|
|
Assert.assertEquals("6ba6cfd0", keystore.getKeyDerivation().getMasterFingerprint()); |
|
|
Assert.assertEquals(ExtendedPublicKey.fromDescriptor("tpubD9429UXFGCTKJ9NdiNK4rC5ygqSUkginycYHccqSg5gkmyQ7PZRHNjk99M6a6Y3NY8ctEUUJvCu6iCCui8Ju3xrHRu3Ez1CKB4ZFoRZDdP9"), keystore.getExtendedPublicKey()); |
|
|
Assert.assertEquals(ExtendedKey.fromDescriptor("tpubD9429UXFGCTKJ9NdiNK4rC5ygqSUkginycYHccqSg5gkmyQ7PZRHNjk99M6a6Y3NY8ctEUUJvCu6iCCui8Ju3xrHRu3Ez1CKB4ZFoRZDdP9"), keystore.getExtendedPublicKey()); |
|
|
Assert.assertTrue(keystore.isValid()); |
|
|
Assert.assertTrue(keystore.isValid()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void importKeystore2b() throws ImportException { |
|
|
public void importKeystore2b() throws ImportException { |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
Keystore keystore = ccMultisig.getKeystore(ScriptType.P2WSH, getInputStream("cc-multisig-keystore-2.json")); |
|
|
Keystore keystore = ccMultisig.getKeystore(ScriptType.P2WSH, getInputStream("cc-multisig-keystore-2.json"), null); |
|
|
Assert.assertEquals("Coldcard 6BA6CFD0", keystore.getLabel()); |
|
|
Assert.assertEquals("Coldcard 6BA6CFD0", keystore.getLabel()); |
|
|
Assert.assertEquals("m/48'/1'/0'/2'", keystore.getKeyDerivation().getDerivationPath()); |
|
|
Assert.assertEquals("m/48'/1'/0'/2'", keystore.getKeyDerivation().getDerivationPath()); |
|
|
Assert.assertEquals("6ba6cfd0", keystore.getKeyDerivation().getMasterFingerprint()); |
|
|
Assert.assertEquals("6ba6cfd0", keystore.getKeyDerivation().getMasterFingerprint()); |
|
|
Assert.assertEquals(ExtendedPublicKey.fromDescriptor("Vpub5nUnvPehg1VYQh13dGznx1P9moac3SNUrn3qhU9r85RhXabYbSSBNsNNwyR7akozAZJw1SZmRRjry1zY8PWMuw8Ga1vQZ5qzPjKyTDQwtzs"), keystore.getExtendedPublicKey()); |
|
|
Assert.assertEquals(ExtendedKey.fromDescriptor("Vpub5nUnvPehg1VYQh13dGznx1P9moac3SNUrn3qhU9r85RhXabYbSSBNsNNwyR7akozAZJw1SZmRRjry1zY8PWMuw8Ga1vQZ5qzPjKyTDQwtzs"), keystore.getExtendedPublicKey()); |
|
|
Assert.assertTrue(keystore.isValid()); |
|
|
Assert.assertTrue(keystore.isValid()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void importWallet1() throws ImportException { |
|
|
public void importWallet1() throws ImportException { |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
Wallet wallet = ccMultisig.importWallet(getInputStream("cc-multisig-export-1.txt")); |
|
|
Wallet wallet = ccMultisig.importWallet(getInputStream("cc-multisig-export-1.txt"), null); |
|
|
Assert.assertEquals("CC-2-of-4", wallet.getName()); |
|
|
Assert.assertEquals("CC-2-of-4", wallet.getName()); |
|
|
Assert.assertEquals(PolicyType.MULTI, wallet.getPolicyType()); |
|
|
Assert.assertEquals(PolicyType.MULTI, wallet.getPolicyType()); |
|
|
Assert.assertEquals(ScriptType.P2WSH, wallet.getScriptType()); |
|
|
Assert.assertEquals(ScriptType.P2WSH, wallet.getScriptType()); |
|
@ -66,7 +66,7 @@ public class ColdcardMultisigTest extends IoTest { |
|
|
@Test |
|
|
@Test |
|
|
public void importWallet2() throws ImportException { |
|
|
public void importWallet2() throws ImportException { |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
Wallet wallet = ccMultisig.importWallet(getInputStream("cc-multisig-export-2.txt")); |
|
|
Wallet wallet = ccMultisig.importWallet(getInputStream("cc-multisig-export-2.txt"), null); |
|
|
Assert.assertEquals("CC-2-of-4", wallet.getName()); |
|
|
Assert.assertEquals("CC-2-of-4", wallet.getName()); |
|
|
Assert.assertEquals(PolicyType.MULTI, wallet.getPolicyType()); |
|
|
Assert.assertEquals(PolicyType.MULTI, wallet.getPolicyType()); |
|
|
Assert.assertEquals(ScriptType.P2SH_P2WSH, wallet.getScriptType()); |
|
|
Assert.assertEquals(ScriptType.P2SH_P2WSH, wallet.getScriptType()); |
|
@ -78,7 +78,7 @@ public class ColdcardMultisigTest extends IoTest { |
|
|
@Test |
|
|
@Test |
|
|
public void importWalletMultiDeriv() throws ImportException { |
|
|
public void importWalletMultiDeriv() throws ImportException { |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
Wallet wallet = ccMultisig.importWallet(getInputStream("cc-multisig-export-multideriv.txt")); |
|
|
Wallet wallet = ccMultisig.importWallet(getInputStream("cc-multisig-export-multideriv.txt"), null); |
|
|
Assert.assertEquals("el-CC-3-of-3-sb-2", wallet.getName()); |
|
|
Assert.assertEquals("el-CC-3-of-3-sb-2", wallet.getName()); |
|
|
Assert.assertEquals(PolicyType.MULTI, wallet.getPolicyType()); |
|
|
Assert.assertEquals(PolicyType.MULTI, wallet.getPolicyType()); |
|
|
Assert.assertEquals(ScriptType.P2WSH, wallet.getScriptType()); |
|
|
Assert.assertEquals(ScriptType.P2WSH, wallet.getScriptType()); |
|
@ -96,7 +96,7 @@ public class ColdcardMultisigTest extends IoTest { |
|
|
public void exportWallet1() throws ImportException, ExportException, IOException { |
|
|
public void exportWallet1() throws ImportException, ExportException, IOException { |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
byte[] walletBytes = ByteStreams.toByteArray(getInputStream("cc-multisig-export-1.txt")); |
|
|
byte[] walletBytes = ByteStreams.toByteArray(getInputStream("cc-multisig-export-1.txt")); |
|
|
Wallet wallet = ccMultisig.importWallet(new ByteArrayInputStream(walletBytes)); |
|
|
Wallet wallet = ccMultisig.importWallet(new ByteArrayInputStream(walletBytes), null); |
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
|
ccMultisig.exportWallet(wallet, baos); |
|
|
ccMultisig.exportWallet(wallet, baos); |
|
|
byte[] exportedBytes = baos.toByteArray(); |
|
|
byte[] exportedBytes = baos.toByteArray(); |
|
@ -109,7 +109,7 @@ public class ColdcardMultisigTest extends IoTest { |
|
|
public void exportWalletMultiDeriv() throws ImportException, ExportException, IOException { |
|
|
public void exportWalletMultiDeriv() throws ImportException, ExportException, IOException { |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
ColdcardMultisig ccMultisig = new ColdcardMultisig(); |
|
|
byte[] walletBytes = ByteStreams.toByteArray(getInputStream("cc-multisig-export-multideriv.txt")); |
|
|
byte[] walletBytes = ByteStreams.toByteArray(getInputStream("cc-multisig-export-multideriv.txt")); |
|
|
Wallet wallet = ccMultisig.importWallet(new ByteArrayInputStream(walletBytes)); |
|
|
Wallet wallet = ccMultisig.importWallet(new ByteArrayInputStream(walletBytes), null); |
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
|
ccMultisig.exportWallet(wallet, baos); |
|
|
ccMultisig.exportWallet(wallet, baos); |
|
|
byte[] exportedBytes = baos.toByteArray(); |
|
|
byte[] exportedBytes = baos.toByteArray(); |
|
|