本文整理汇总了Java中net.bither.bitherj.crypto.TransactionSignature类的典型用法代码示例。如果您正苦于以下问题:Java TransactionSignature类的具体用法?Java TransactionSignature怎么用?Java TransactionSignature使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransactionSignature类属于net.bither.bitherj.crypto包,在下文中一共展示了TransactionSignature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: signMyPart
import net.bither.bitherj.crypto.TransactionSignature; //导入依赖的package包/类
public ArrayList<TransactionSignature> signMyPart(List<byte[]> unsignedHashes,
CharSequence password) {
if (isInRecovery()) {
throw new AssertionError("recovery hdm address can not sign");
}
DeterministicKey key = keychain.getExternalKey(pubs.index, password);
ArrayList<TransactionSignature> sigs = new ArrayList<TransactionSignature>();
for (int i = 0;
i < unsignedHashes.size();
i++) {
TransactionSignature transactionSignature = new TransactionSignature(key.sign
(unsignedHashes.get(i)), TransactionSignature.SigHash.ALL, false);
sigs.add(transactionSignature);
}
key.wipe();
return sigs;
}
示例2: signMyPart
import net.bither.bitherj.crypto.TransactionSignature; //导入依赖的package包/类
public ArrayList<TransactionSignature> signMyPart(List<byte[]> unsignedHashes,
CharSequence password,
List<PathTypeIndex> pathTypeIndexList) {
ArrayList<TransactionSignature> sigs = new ArrayList<TransactionSignature>();
for (int i = 0;
i < unsignedHashes.size();
i++) {
PathTypeIndex pathTypeIndex = pathTypeIndexList.get(i);
DeterministicKey key;
if (pathTypeIndex.pathType == PathType.EXTERNAL_ROOT_PATH) {
key = getExternalKey(pathTypeIndex.index, password);
} else {
key = getInternalKey(pathTypeIndex.index, password);
}
TransactionSignature transactionSignature = new TransactionSignature(key.sign
(unsignedHashes.get(i)), TransactionSignature.SigHash.ALL, false);
sigs.add(transactionSignature);
key.wipe();
}
return sigs;
}
示例3: formatInScript
import net.bither.bitherj.crypto.TransactionSignature; //导入依赖的package包/类
public static List<byte[]> formatInScript(List<TransactionSignature> signs1,
List<TransactionSignature> signs2,
List<DesktopHDMAddress> addressList) {
List<byte[]> result = new ArrayList<byte[]>();
for (int i = 0;
i < signs1.size();
i++) {
DesktopHDMAddress a = addressList.get(i);
List<TransactionSignature> signs = new ArrayList<TransactionSignature>(2);
signs.add(signs1.get(i));
signs.add(signs2.get(i));
result.add(ScriptBuilder.createP2SHMultiSigInputScript(signs,
a.getPubKey()).getProgram());
}
return result;
}
示例4: signHashes
import net.bither.bitherj.crypto.TransactionSignature; //导入依赖的package包/类
public List<byte[]> signHashes(List<byte[]> unsignedInHashes, CharSequence passphrase) throws
PasswordException {
ECKey key = PrivateKeyUtil.getECKeyFromSingleString(this.getFullEncryptPrivKey(), passphrase);
if (key == null) {
throw new PasswordException("do not decrypt eckey");
}
KeyParameter assKey = key.getKeyCrypter().deriveKey(passphrase);
List<byte[]> result = new ArrayList<byte[]>();
for (byte[] unsignedInHash : unsignedInHashes) {
TransactionSignature signature = new TransactionSignature(key.sign(unsignedInHash,
assKey), TransactionSignature.SigHash.ALL, false);
result.add(ScriptBuilder.createInputScript(signature, key).getProgram());
}
key.clearPrivateKey();
return result;
}
示例5: addSignedInput
import net.bither.bitherj.crypto.TransactionSignature; //导入依赖的package包/类
/**
* Adds a new and fully signed input for the given parameters. Note that this method is
* <b>not</b> thread safe
* and requires external synchronization. Please refer to general documentation on Bitcoin
* scripting and contracts
* to understand the values of sigHash and anyoneCanPay: otherwise you can use the other form
* of this method
* that sets them to typical defaults.
*
* @throws net.bither.bitherj.exception.ScriptException if the scriptPubKey is not a pay to address or pay to pubkey script.
*/
public In addSignedInput(Out prevOut, Script scriptPubKey, ECKey sigKey,
TransactionSignature.SigHash sigHash, boolean anyoneCanPay) throws
ScriptException {
In input = new In(this, new byte[]{}, prevOut);
addInput(input);
byte[] hash = hashForSignature(ins.size() - 1, scriptPubKey, sigHash, anyoneCanPay);
ECKey.ECDSASignature ecSig = sigKey.sign(hash);
TransactionSignature txSig = new TransactionSignature(ecSig, sigHash, anyoneCanPay);
if (scriptPubKey.isSentToRawPubKey()) {
input.setInSignature(ScriptBuilder.createInputScript(txSig).getProgram());
} else if (scriptPubKey.isSentToAddress()) {
input.setInSignature(ScriptBuilder.createInputScript(txSig, sigKey).getProgram());
} else {
throw new ScriptException("Don't know how to sign for this kind of scriptPubKey: " +
scriptPubKey);
}
return input;
}
示例6: getOtherSignature
import net.bither.bitherj.crypto.TransactionSignature; //导入依赖的package包/类
@Override
public List<TransactionSignature> getOtherSignature(int addressIndex,
CharSequence password,
List<byte[]> unsignHash, final Tx tx) {
signingIndex = addressIndex;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
SendBitcoinConfirmPanel dialog = new SendBitcoinConfirmPanel(preConfirmListener,
bitcoinAddress, changeAddress, tx
);
dialog.showPanel();
}
});
sigs = null;
try {
lock.lockInterruptibly();
fetchedCondition.await();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
lock.unlock();
}
if (sigs == null) {
throw new CompleteTransactionRunnable.HDMSignUserCancelExcetion();
}
signingIndex = -1;
return sigs;
}
示例7: setQrCodeResult
import net.bither.bitherj.crypto.TransactionSignature; //导入依赖的package包/类
public boolean setQrCodeResult(String qr) {
if (!Utils.isEmpty(qr)) {
try {
String[] stringArray = QRCodeUtil.splitString(qr);
sigs = new ArrayList<TransactionSignature>();
for (String str : stringArray) {
if (!Utils.isEmpty(str)) {
TransactionSignature transactionSignature = new
TransactionSignature(ECKey.ECDSASignature.decodeFromDER
(Utils.hexStringToByteArray(str)),
TransactionSignature.SigHash.ALL, false);
sigs.add(transactionSignature);
}
}
} catch (Exception e) {
sigs = null;
e.printStackTrace();
new MessageDialog(LocaliserUtils.getString("send_failed")).showMsg();
}
} else {
sigs = null;
}
try {
lock.lock();
fetchedCondition.signal();
} finally {
lock.unlock();
}
return true;
}
示例8: getOtherSignature
import net.bither.bitherj.crypto.TransactionSignature; //导入依赖的package包/类
@Override
public List<TransactionSignature> getOtherSignature(int addressIndex,
CharSequence password,
List<byte[]> unsignHash, final Tx tx) {
signingIndex = addressIndex;
runOnUiThread(new Runnable() {
@Override
public void run() {
DialogSendConfirm dialog = new DialogSendConfirm(HdmSendActivity.this, tx,
dialogSelectChangeAddress.getChangeAddress().equals(address) ? null :
dialogSelectChangeAddress.getChangeAddress().getAddress(),
preConfirmListener);
dialog.show();
}
});
sigs = null;
try {
lock.lockInterruptibly();
fetchedCondition.await();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
lock.unlock();
}
if (sigs == null) {
throw new CompleteTransactionRunnable.HDMSignUserCancelExcetion();
}
signingIndex = -1;
return sigs;
}
示例9: onActivityResult
import net.bither.bitherj.crypto.TransactionSignature; //导入依赖的package包/类
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RequestCode) {
if (resultCode == RESULT_OK) {
final String qr = data.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
try {
String[] stringArray = QRCodeUtil.splitString(qr);
sigs = new ArrayList<TransactionSignature>();
for (String str : stringArray) {
if (!Utils.isEmpty(str)) {
TransactionSignature transactionSignature = new
TransactionSignature(ECKey.ECDSASignature.decodeFromDER
(Utils.hexStringToByteArray(str)),
TransactionSignature.SigHash.ALL, false);
sigs.add(transactionSignature);
}
}
} catch (Exception e) {
sigs = null;
e.printStackTrace();
DropdownMessage.showDropdownMessage(HdmSendActivity.this,
R.string.send_failed);
}
} else {
sigs = null;
}
try {
lock.lock();
fetchedCondition.signal();
} finally {
lock.unlock();
}
return true;
}
return false;
}
示例10: executeCheckSig
import net.bither.bitherj.crypto.TransactionSignature; //导入依赖的package包/类
private static void executeCheckSig(Tx txContainingThis, int index, Script script, LinkedList<byte[]> stack,
int lastCodeSepLocation, int opcode) throws ScriptException {
if (stack.size() < 2)
throw new ScriptException("Attempted OP_CHECKSIG(VERIFY) on a stack with size < 2");
byte[] pubKey = stack.pollLast();
byte[] sigBytes = stack.pollLast();
byte[] prog = script.getProgram();
byte[] connectedScript = Arrays.copyOfRange(prog, lastCodeSepLocation, prog.length);
UnsafeByteArrayOutputStream outStream = new UnsafeByteArrayOutputStream(sigBytes.length + 1);
try {
writeBytes(outStream, sigBytes);
} catch (IOException e) {
throw new RuntimeException(e); // Cannot happen
}
connectedScript = removeAllInstancesOf(connectedScript, outStream.toByteArray());
// TODO: Use int for indexes everywhere, we can't have that many inputs/outputs
boolean sigValid = false;
try {
TransactionSignature sig = TransactionSignature.decodeFromBitcoin(sigBytes, false);
byte[] hash = txContainingThis.hashForSignature(index, connectedScript, (byte) sig.sighashFlags);
sigValid = ECKey.verify(hash, sig, pubKey);
} catch (Exception e1) {
// There is (at least) one exception that could be hit here (EOFException, if the sig is too short)
// Because I can't verify there aren't more, we use a very generic Exception catch
log.warn(e1.toString());
}
if (opcode == OP_CHECKSIG)
stack.add(sigValid ? new byte[]{1} : new byte[]{0});
else if (opcode == OP_CHECKSIGVERIFY)
if (!sigValid)
throw new ScriptException("Script failed OP_CHECKSIGVERIFY");
}
示例11: createP2SHMultiSigInputScript
import net.bither.bitherj.crypto.TransactionSignature; //导入依赖的package包/类
/**
* Create a program that satisfies a pay-to-script hashed OP_CHECKMULTISIG program.
*/
public static Script createP2SHMultiSigInputScript(List<TransactionSignature> signatures,
byte[] multisigProgramBytes) {
List<byte[]> sigs = new ArrayList<byte[]>(signatures.size());
for (TransactionSignature signature : signatures)
sigs.add(signature.encodeToBitcoin());
return createMultiSigInputScriptBytes(sigs, multisigProgramBytes);
}
示例12: formatInScript
import net.bither.bitherj.crypto.TransactionSignature; //导入依赖的package包/类
public static List<byte[]> formatInScript(List<TransactionSignature> signs1,
List<TransactionSignature> signs2,
byte[] scriptPubKey) {
List<byte[]> result = new ArrayList<byte[]>();
for (int i = 0;
i < signs1.size();
i++) {
List<TransactionSignature> signs = new ArrayList<TransactionSignature>(2);
signs.add(signs1.get(i));
signs.add(signs2.get(i));
result.add(ScriptBuilder.createP2SHMultiSigInputScript(signs,
scriptPubKey).getProgram());
}
return result;
}
示例13: signMyPart
import net.bither.bitherj.crypto.TransactionSignature; //导入依赖的package包/类
public ArrayList<TransactionSignature> signMyPart(List<byte[]> unsignedHashes,
CharSequence password) {
DeterministicKey key = keychain.getExternalKey(pubs.index, password);
ArrayList<TransactionSignature> sigs = new ArrayList<TransactionSignature>();
for (int i = 0;
i < unsignedHashes.size();
i++) {
TransactionSignature transactionSignature = new TransactionSignature(key.sign
(unsignedHashes.get(i)), TransactionSignature.SigHash.ALL, false);
sigs.add(transactionSignature);
}
key.wipe();
return sigs;
}
示例14: addSignature
import net.bither.bitherj.crypto.TransactionSignature; //导入依赖的package包/类
public boolean addSignature(List<byte[]> sigs) {
if (sigs.size() != tx.getIns().size()) {
return false;
}
ArrayList<TransactionSignature> txSigs = new ArrayList<TransactionSignature>();
int pubIndex = -1;
for (int i = 0;
i < tx.getIns().size();
i++) {
TransactionSignature txSig = new TransactionSignature(ECKey.ECDSASignature
.decodeFromDER(sigs.get(i)), TransactionSignature.SigHash.ALL, false);
if (i == 0) {
byte[] pub = recoverPub(sigs.get(i), unsignedHashes().get(i));
if (pub == null) {
break;
}
pubIndex = pubs.indexOf(pub);
if (pubIndex < 0) {
break;
}
}
txSigs.add(txSig);
}
if (pubIndex < 0) {
return false;
}
signatures.put(Integer.valueOf(pubIndex), txSigs);
return true;
}
示例15: getUnsignedInHashes
import net.bither.bitherj.crypto.TransactionSignature; //导入依赖的package包/类
public List<byte[]> getUnsignedInHashes() {
List<byte[]> result = new ArrayList<byte[]>();
for (In in : this.getIns()) {
byte sigHashType = (byte) TransactionSignature.calcSigHashValue(TransactionSignature
.SigHash.ALL, false);
result.add(this.hashForSignature(in.getInSn(), in.getPrevOutScript(), sigHashType));
}
return result;
}