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


Java PrivateKey.createNew方法代码示例

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


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

示例1: test

import org.hyperledger.common.PrivateKey; //导入方法依赖的package包/类
@Test
public void test() throws HyperLedgerException {

    byte[] offset = new byte[32];
    for (int j = 0; j < 10; ++j) {
        PrivateKey key = PrivateKey.createNew();
        for (int i = 0; i < 10; ++i) {
            random.nextBytes(offset);
            BigInteger o = new BigInteger(offset);
            PrivateKey ok = key.offsetKey(o);
            PublicKey pk = key.getPublic().offsetKey(o);
            assertEquals(ok.getPublic(), pk);
            BigInteger no = o.negate();
            assertEquals(key, ok.offsetKey(no));
        }
    }
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:18,代码来源:HomomorphicTest.java

示例2: testECDSASpeed

import org.hyperledger.common.PrivateKey; //导入方法依赖的package包/类
@Test
public void testECDSASpeed() throws HyperLedgerException {
    PrivateKey key = PrivateKey.createNew(true);
    byte[] data = new byte[32];
    random.nextBytes(data);
    byte[] signature = key.sign(data);
    long cpu = -mxb.getCurrentThreadUserTime();
    for (int i = 0; i < 100; ++i) {
        assertTrue(key.getPublic().verify(data, signature));
    }
    cpu += mxb.getCurrentThreadUserTime();
    double speed = 100.0 / (cpu / 10.0e9);
    System.out.println("ECDSA validation speed : " + speed + " signatures/second");
    assertTrue(speed > 100.0);
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:16,代码来源:ExtendedKeyTest.java

示例3: signatureValidationSucceeds

import org.hyperledger.common.PrivateKey; //导入方法依赖的package包/类
@Test
public void signatureValidationSucceeds() {
    PrivateKey key = PrivateKey.createNew(crypto);

    Transaction t = new TransactionBuilder()
            .output(randomBytes(100))
            .endorse(key)
            .build();

    assertTrue(t.verify(t.getEndorsers().get(0), key.getPublic()));
}
 
开发者ID:hyperledger-archives,项目名称:fabric-api-archive,代码行数:12,代码来源:TransactionTest.java

示例4: signatureValidationFails

import org.hyperledger.common.PrivateKey; //导入方法依赖的package包/类
@Test
public void signatureValidationFails() {
    PrivateKey key1 = PrivateKey.createNew(crypto);
    PrivateKey key2 = PrivateKey.createNew(crypto);

    Transaction t = new TransactionBuilder()
            .output(randomBytes(100))
            .endorse(key1)
            .build();

    assertFalse(t.verify(t.getEndorsers().get(0), key2.getPublic()));
}
 
开发者ID:hyperledger-archives,项目名称:fabric-api-archive,代码行数:13,代码来源:TransactionTest.java

示例5: test

import org.hyperledger.common.PrivateKey; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
    BCSAPI bcsapi = regtestRule.getBCSAPI();
    TestServer testServer = regtestRule.getTestServer();

    ConfirmationManager confirmationManager = new ConfirmationManager();
    confirmationManager.init(bcsapi, 101);

    PrivateKey issuerKey = PrivateKey.createNew();
    PrivateKey receiverKey = PrivateKey.createNew();
    BaseAccount issuerAccount = new BaseAccount(new KeyListChain(issuerKey));
    ColoredAccount coloredAccount = new ColoredBaseAccount(new KeyListChain(receiverKey));

    ColorIssuer colorIssuer = new ColorIssuer(issuerKey);

    // listeners
    bcsapi.registerTransactionListener(issuerAccount);
    confirmationManager.addConfirmationListener(issuerAccount);
    bcsapi.registerTransactionListener(coloredAccount);
    confirmationManager.addConfirmationListener(coloredAccount);
    bcsapi.registerTransactionListener(colorIssuer);
    confirmationManager.addConfirmationListener(colorIssuer);

    // fund issuer address
    UIAddress issuerAddress = new UIAddress(UIAddress.Network.TEST, colorIssuer.getFundingAddress());
    ActionWaiter.execute(() -> testServer.sendTo(issuerAddress.toString(), 1000000000), expected(colorIssuer, 2));

    // check balance
    long b = issuerAccount.getCoins().getTotalSatoshis(); // 1000000000
    assertEquals(1000000000, b);
    long b2 = issuerAccount.getConfirmedCoins().getTotalSatoshis(); // 1000000000
    assertEquals(1000000000, b2);

    Color color = colorIssuer.getColor();
    // issue 100 units carried by 50000 satoshis
    Transaction issuing = colorIssuer.issueTokens(
            receiverKey.getAddress(),
            100, 50000,
            BaseTransactionFactory.MINIMUM_FEE);

    ActionWaiter.execute(() -> bcsapi.sendTransaction(issuing), expectedOneOnEach(colorIssuer, coloredAccount, issuerAccount));

    ActionWaiter.execute(() -> testServer.mineOneBlock(), expectedOne(coloredAccount));

    // receiver account received transaction with colored coin
    b = coloredAccount.getConfirmedCoins().getTotalSatoshis(); //50000
    assertEquals(50000, b);
    b2 = coloredAccount.getConfirmedCoins().getColoredCoins().getCoins().size(); // 1
    assertEquals(1, b2);

    long b3 = coloredAccount.getConfirmedCoins().getColoredCoins().getCoins(color).getTotalQuantity();
    assertEquals(100, b3);

    PrivateKey nextOwner = PrivateKey.createNew();
    Transaction transfer = coloredAccount.createTransactionFactory()
            .proposeColored(nextOwner.getAddress(),
                    color, 50)
            .sign(coloredAccount.getChain());

    ActionWaiter.execute(() -> bcsapi.sendTransaction(transfer), expectedOne(coloredAccount));

    ColoredAccount nextOwnerAccount = new ColoredBaseAccount(new KeyListChain(nextOwner));
    ActionWaiter.execute(() -> testServer.mineOneBlock(), expectedOne(coloredAccount));

    ActionWaiter.execute(() -> nextOwnerAccount.sync(bcsapi), expectedOne(nextOwnerAccount));

    assertEquals(50, nextOwnerAccount.getConfirmedCoins().getColoredCoins().getCoins(color).getTotalQuantity());
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:69,代码来源:ColoredAccountOperationsInBlocksTest.java


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