本文整理汇总了Java中org.bitcoinj.core.ECKey.ECDSASignature方法的典型用法代码示例。如果您正苦于以下问题:Java ECKey.ECDSASignature方法的具体用法?Java ECKey.ECDSASignature怎么用?Java ECKey.ECDSASignature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bitcoinj.core.ECKey
的用法示例。
在下文中一共展示了ECKey.ECDSASignature方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decodeFromBitcoin
import org.bitcoinj.core.ECKey; //导入方法依赖的package包/类
/**
* Returns a decoded signature.
*
* @param requireCanonicalEncoding if the encoding of the signature must
* be canonical.
* @param requireCanonicalSValue if the S-value must be canonical (below half
* the order of the curve).
* @throws RuntimeException if the signature is invalid or unparseable in some way.
*/
public static TransactionSignature decodeFromBitcoin(byte[] bytes,
boolean requireCanonicalEncoding,
boolean requireCanonicalSValue) throws VerificationException {
// Bitcoin encoding is DER signature + sighash byte.
if (requireCanonicalEncoding && !isEncodingCanonical(bytes))
throw new VerificationException("Signature encoding is not canonical.");
ECKey.ECDSASignature sig;
try {
sig = ECKey.ECDSASignature.decodeFromDER(bytes);
} catch (IllegalArgumentException e) {
throw new VerificationException("Could not decode DER", e);
}
if (requireCanonicalSValue && !sig.isCanonical())
throw new VerificationException("S-value is not canonical.");
// In Bitcoin, any value of the final byte is valid, but not necessarily canonical. See javadocs for
// isEncodingCanonical to learn more about this. So we must store the exact byte found.
return new TransactionSignature(sig.r, sig.s, bytes[bytes.length - 1]);
}
示例2: createTransaction
import org.bitcoinj.core.ECKey; //导入方法依赖的package包/类
@Override
public String createTransaction(String recipientId, Long satoshiAmount, String vendorField, String passphrase) {
Date beginEpoch;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
beginEpoch = dateFormat.parse("2017-03-21 13:00:00");
} catch (ParseException e) {
throw new RuntimeException("Failed to parse epoch start date");
}
long timestamp = (new Date().getTime() - beginEpoch.getTime()) / 1000L;
CreateArkTransactionRequest createArkTransactionRequest = new CreateArkTransactionRequest();
createArkTransactionRequest.setType((byte) 0);
createArkTransactionRequest.setRecipientId(recipientId);
createArkTransactionRequest.setFee(10000000L);
createArkTransactionRequest.setVendorField(vendorField);
createArkTransactionRequest.setTimestamp(timestamp);
createArkTransactionRequest.setAmount(satoshiAmount);
// sign transaction
String senderPublicKey = BaseEncoding.base16().lowerCase().encode(Crypto.getKeys(passphrase).getPubKey());
createArkTransactionRequest.setSenderPublicKey(senderPublicKey);
byte[] transactionBytes = getBytes(createArkTransactionRequest, senderPublicKey);
ECKey.ECDSASignature signature = Crypto.signBytes(transactionBytes, passphrase);
String signatureEncoded = BaseEncoding.base16().lowerCase().encode(signature.encodeToDER());
createArkTransactionRequest.setSignature(signatureEncoded);
String id = BaseEncoding.base16().lowerCase().encode(Sha256Hash.hash(transactionBytes));
createArkTransactionRequest.setId(id);
CreateArkTransactionsRequest createArkTransactionsRequest = new CreateArkTransactionsRequest();
createArkTransactionsRequest.setTransactions(Arrays.asList(createArkTransactionRequest));
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("nethash", arkNetwork.getNetHash());
headers.set("version", arkNetwork.getVersion());
headers.set("port", arkNetwork.getPort());
HttpEntity<CreateArkTransactionsRequest> requestEntity = new HttpEntity<>(createArkTransactionsRequest, headers);
return restTemplate
.exchange(
getRandomHostBaseUrl() + "/peer/transactions",
HttpMethod.POST,
requestEntity,
new ParameterizedTypeReference<TransactionIdsWrapper>() {}
)
.getBody()
.getTransactionIds()
.get(0);
}
示例3: getSignatureBytes
import org.bitcoinj.core.ECKey; //导入方法依赖的package包/类
/**
* Get array bayts signature
*
* @param chainId
* id chain (golos or steem)
* @param requiredPrivateKey
* this is private key
* @return signature bytes
*/
protected byte[] getSignatureBytes(String chainId, ECKey requiredPrivateKey) {
boolean isGrapheneCanonical = false;
byte[] signatureData = null;
while (!isGrapheneCanonical) {
List<Byte> serializedTransaction = this.toBytes();
List<Byte> listBytes = new ArrayList<Byte>();
listBytes.addAll(Util.hexToBytes(chainId));
listBytes.addAll(serializedTransaction);
byte[] arrayBytes = Util.listBytes2array(listBytes);
Sha256Hash hashTransaction = Sha256Hash
.wrap(Sha256Hash.hash(arrayBytes));
int recId = -1;
ECKey.ECDSASignature sig = requiredPrivateKey.sign(hashTransaction);
for (int i = 0; i < 4; i++) {
ECKey k = ECKey.recoverFromSignature(i, sig, hashTransaction,
requiredPrivateKey.isCompressed());
if (k != null && k.getPubKeyPoint()
.equals(requiredPrivateKey.getPubKeyPoint())) {
recId = i;
break;
}
}
// 1 header + 32 bytes for R + 32 bytes for S
signatureData = new byte[65];
int headerByte = recId + 27 + (requiredPrivateKey.isCompressed() ? 4 : 0);
signatureData[0] = (byte) headerByte;
System.arraycopy(Utils.bigIntegerToBytes(sig.r, 32), 0,
signatureData, 1, 32);
System.arraycopy(Utils.bigIntegerToBytes(sig.s, 32), 0,
signatureData, 33, 32);
// Further "canonicality" tests
if (isCanonical(signatureData)) {
this.setExpiration(Util.addTime(this.getExpiration(), 1));
} else {
isGrapheneCanonical = true;
}
}
return signatureData;
}
示例4: TransactionSignature
import org.bitcoinj.core.ECKey; //导入方法依赖的package包/类
/** Constructs a transaction signature based on the ECDSA signature. */
public TransactionSignature(ECKey.ECDSASignature signature, Transaction.SigHash mode, boolean anyoneCanPay) {
super(signature.r, signature.s);
sighashFlags = calcSigHashValue(mode, anyoneCanPay);
}
示例5: toCanonicalised
import org.bitcoinj.core.ECKey; //导入方法依赖的package包/类
@Override
public ECKey.ECDSASignature toCanonicalised() {
return new TransactionSignature(super.toCanonicalised(), sigHashMode(), anyoneCanPay());
}