Skip to content

Commit

Permalink
refactor(core): signTransaction uses the signer in KeyPair
Browse files Browse the repository at this point in the history
  • Loading branch information
Cletitia committed Aug 5, 2021
1 parent 22b8e56 commit 968ce76
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,18 @@ public static String toHex(ByteString raw) {
}

public Transaction signTransaction(TransactionExtention txnExt, KeyPair keyPair) {
SECP256K1.KeyPair kp = keyPair.getRawPair();
SECP256K1.Signature sig = SECP256K1.sign(Bytes32.wrap(txnExt.getTxid().toByteArray()), kp);
Transaction signedTxn =
txnExt.getTransaction().toBuilder().addSignature(ByteString.copyFrom(sig.encodedBytes().toArray())).build();
byte[] txid = txnExt.getTxid().toByteArray();
byte[] signature = KeyPair.signTransaction(txid, keyPair);
Transaction signedTxn =
txnExt.getTransaction().toBuilder().addSignature(ByteString.copyFrom(signature)).build();

return signedTxn;
}

public Transaction signTransaction(Transaction txn, KeyPair keyPair) {
byte[] txid = calculateTransactionHash(txn);
SECP256K1.KeyPair kp = keyPair.getRawPair();
SECP256K1.Signature sig = SECP256K1.sign(Bytes32.wrap(txid), kp);
Transaction signedTxn = txn.toBuilder().addSignature(ByteString.copyFrom(sig.encodedBytes().toArray())).build();
byte[] signature = KeyPair.signTransaction(txid, keyPair);
Transaction signedTxn = txn.toBuilder().addSignature(ByteString.copyFrom(signature)).build();
return signedTxn;
}

Expand Down

0 comments on commit 968ce76

Please sign in to comment.