本文整理汇总了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));
}
}
}
示例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);
}
示例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()));
}
示例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()));
}
示例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