当前位置: 首页>>代码示例>>Java>>正文


Java TransactionSignature.SigHash方法代码示例

本文整理汇总了Java中net.bither.bitherj.crypto.TransactionSignature.SigHash方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionSignature.SigHash方法的具体用法?Java TransactionSignature.SigHash怎么用?Java TransactionSignature.SigHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.bither.bitherj.crypto.TransactionSignature的用法示例。


在下文中一共展示了TransactionSignature.SigHash方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:bither,项目名称:bitherj,代码行数:30,代码来源:Tx.java

示例2: calculateSignature

import net.bither.bitherj.crypto.TransactionSignature; //导入方法依赖的package包/类
/**
 * Calculates a signature that is valid for being inserted into the input at the given
 * position. This is simply
 * a wrapper around calling {@link net.bither.bitherj.core.Tx#hashForSignature(int, byte[],
 * net.bither.bitherj.crypto.TransactionSignature.SigHash, boolean)}
 * followed by {@link net.bither.bitherj.crypto.ECKey#sign(byte[], org.spongycastle.crypto.params.KeyParameter)} and
 * then returning
 * a new {@link net.bither.bitherj.crypto.TransactionSignature}.
 *
 * @param inputIndex            Which input to calculate the signature for, as an index.
 * @param key                   The private key used to calculate the signature.
 * @param aesKey                If not null, this will be used to decrypt the key.
 * @param connectedPubKeyScript Byte-exact contents of the scriptPubKey that is being
 *                              satisified.
 * @param hashType              Signing mode, see the enum for documentation.
 * @param anyoneCanPay          Signing mode, see the SigHash enum for documentation.
 * @return A newly calculated signature object that wraps the r, s and sighash components.
 */
public synchronized TransactionSignature calculateSignature(int inputIndex, ECKey key,
                                                            @Nullable KeyParameter aesKey,
                                                            byte[] connectedPubKeyScript,
                                                            TransactionSignature.SigHash
                                                                    hashType,
                                                            boolean anyoneCanPay) {
    byte[] hash = hashForSignature(inputIndex, connectedPubKeyScript, hashType, anyoneCanPay);
    return new TransactionSignature(key.sign(hash, aesKey), hashType, anyoneCanPay);
}
 
开发者ID:bither,项目名称:bitherj,代码行数:28,代码来源:Tx.java

示例3: hashForSignature

import net.bither.bitherj.crypto.TransactionSignature; //导入方法依赖的package包/类
/**
 * <p>Calculates a signature hash, that is, a hash of a simplified form of the transaction.
 * How exactly the transaction
 * is simplified is specified by the type and anyoneCanPay parameters.</p>
 * <p/>
 * <p>You don't normally ever need to call this yourself. It will become more useful in
 * future as the contracts
 * features of Bitcoin are developed.</p>
 *
 * @param inputIndex      input the signature is being calculated for. Tx signatures are
 *                        always relative to an input.
 * @param connectedScript the bytes that should be in the given input during signing.
 * @param type            Should be SigHash.ALL
 * @param anyoneCanPay    should be false.
 */
public synchronized byte[] hashForSignature(int inputIndex, byte[] connectedScript,
                                            TransactionSignature.SigHash type,
                                            boolean anyoneCanPay) {
    byte sigHashType = (byte) TransactionSignature.calcSigHashValue(type, anyoneCanPay);
    return hashForSignature(inputIndex, connectedScript, sigHashType);
}
 
开发者ID:bither,项目名称:bitherj,代码行数:22,代码来源:Tx.java

示例4: signInputs

import net.bither.bitherj.crypto.TransactionSignature; //导入方法依赖的package包/类
/**
 * Once a transaction has some inputs and outputs added, the signatures in the inputs can be
 * calculated. The
 * signature is over the transaction itself, to prove the redeemer actually created that
 * transaction,
 * so we have to do this step last.<p>
 * <p/>
 * This method is similar to SignatureHash in script.cpp
 *
 * @param hashType This should always be set to SigHash.ALL currently. Other types are unused.
 * @param address  A wallet is required to fetch the keys needed for signing.
 */
public synchronized void signInputs(TransactionSignature.SigHash hashType,
                                    Address address) throws ScriptException {
    signInputs(hashType, address, null);
}
 
开发者ID:bither,项目名称:bitherj,代码行数:17,代码来源:Tx.java


注:本文中的net.bither.bitherj.crypto.TransactionSignature.SigHash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。