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


Java TransactionSignature.isEncodingCanonical方法代码示例

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


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

示例1: isInputStandard

import org.bitcoinj.crypto.TransactionSignature; //导入方法依赖的package包/类
/** Checks if the given input passes some of the AreInputsStandard checks. Not complete. */
public static RuleViolation isInputStandard(TransactionInput input) {
    for (ScriptChunk chunk : input.getScriptSig().getChunks()) {
        if (chunk.data != null && !chunk.isShortestPossiblePushData())
            return RuleViolation.SHORTEST_POSSIBLE_PUSHDATA;
        if (chunk.isPushData()) {
            ECDSASignature signature;
            try {
                signature = ECKey.ECDSASignature.decodeFromDER(chunk.data);
            } catch (IllegalArgumentException x) {
                // Doesn't look like a signature.
                signature = null;
            }
            if (signature != null) {
                if (!TransactionSignature.isEncodingCanonical(chunk.data))
                    return RuleViolation.SIGNATURE_CANONICAL_ENCODING;
                if (!signature.isCanonical())
                    return RuleViolation.SIGNATURE_CANONICAL_ENCODING;
            }
        }
    }
    return RuleViolation.NONE;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:24,代码来源:DefaultRiskAnalysis.java

示例2: isInputStandard

import org.bitcoinj.crypto.TransactionSignature; //导入方法依赖的package包/类
/** Checks if the given input passes some of the AreInputsStandard checks. Not complete. */
public static RuleViolation isInputStandard(TransactionInput input) {
    for (ScriptChunk chunk : input.getScriptSig().getChunks()) {
        if (chunk.data != null && !chunk.isShortestPossiblePushData())
            return RuleViolation.SHORTEST_POSSIBLE_PUSHDATA;
        if (chunk.isPushData()) {
            ECDSASignature signature;
            try {
                signature = ECKey.ECDSASignature.decodeFromDER(chunk.data);
            } catch (RuntimeException x) {
                // Doesn't look like a signature.
                signature = null;
            }
            if (signature != null) {
                if (!TransactionSignature.isEncodingCanonical(chunk.data))
                    return RuleViolation.SIGNATURE_CANONICAL_ENCODING;
                if (!signature.isCanonical())
                    return RuleViolation.SIGNATURE_CANONICAL_ENCODING;
            }
        }
    }
    return RuleViolation.NONE;
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:24,代码来源:DefaultRiskAnalysis.java

示例3: testCreatedSigAndPubkeyAreCanonical

import org.bitcoinj.crypto.TransactionSignature; //导入方法依赖的package包/类
@Test
public void testCreatedSigAndPubkeyAreCanonical() throws Exception {
    // Tests that we will not generate non-canonical pubkeys or signatures
    // We dump failed data to error log because this test is not expected to be deterministic
    ECKey key = new ECKey();
    if (!ECKey.isPubKeyCanonical(key.getPubKey())) {
        log.error(Utils.HEX.encode(key.getPubKey()));
        fail();
    }

    byte[] hash = new byte[32];
    new Random().nextBytes(hash);
    byte[] sigBytes = key.sign(Sha256Hash.wrap(hash)).encodeToDER();
    byte[] encodedSig = Arrays.copyOf(sigBytes, sigBytes.length + 1);
    encodedSig[sigBytes.length] = Transaction.SigHash.ALL.byteValue();
    if (!TransactionSignature.isEncodingCanonical(encodedSig)) {
        log.error(Utils.HEX.encode(sigBytes));
        fail();
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:21,代码来源:ECKeyTest.java

示例4: testCreatedSigAndPubkeyAreCanonical

import org.bitcoinj.crypto.TransactionSignature; //导入方法依赖的package包/类
@Test
public void testCreatedSigAndPubkeyAreCanonical() throws Exception {
    // Tests that we will not generate non-canonical pubkeys or signatures
    // We dump failed data to error log because this test is not expected to be deterministic
    ECKey key = new ECKey();
    if (!ECKey.isPubKeyCanonical(key.getPubKey())) {
        log.error(Utils.HEX.encode(key.getPubKey()));
        fail();
    }

    byte[] hash = new byte[32];
    new Random().nextBytes(hash);
    byte[] sigBytes = key.sign(new Sha256Hash(hash)).encodeToDER();
    byte[] encodedSig = Arrays.copyOf(sigBytes, sigBytes.length + 1);
    encodedSig[sigBytes.length] = (byte) (Transaction.SigHash.ALL.ordinal() + 1);
    if (!TransactionSignature.isEncodingCanonical(encodedSig)) {
        log.error(Utils.HEX.encode(sigBytes));
        fail();
    }
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:21,代码来源:ECKeyTest.java


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