44#include " bcl/Ecdsa.hpp"
55#include " bcl/Sha256.hpp"
66#include " bcl/Uint256.hpp"
7- #include " helpers/encoding/der.h"
87#include " helpers/crypto_helpers.h"
98#include " rfc6979/rfc6979.h"
109#include " uECC.h"
10+ #include " bip66.h"
1111
1212void cryptoSign (Sha256Hash hash, Ark::Crypto::Identities::PrivateKey privateKey, std::vector<uint8_t >& signature) {
1313 Uint256 r;
@@ -19,13 +19,11 @@ void cryptoSign(Sha256Hash hash, Ark::Crypto::Identities::PrivateKey privateKey,
1919 auto ret = Ecdsa::sign (Uint256 (privateKey.toBytes ()), hash, Uint256 (nonce32), r, s);
2020 assert (ret);
2121
22- std::vector<uint8_t > r_der (PRIVATEKEY_SIZE);
23- r.getBigEndianBytes (&r_der[0 ]);
22+ std::vector<uint8_t > rValue (PRIVATEKEY_SIZE), sValue (PRIVATEKEY_SIZE);
23+ r.getBigEndianBytes (&rValue[0 ]);
24+ s.getBigEndianBytes (&sValue [0 ]);
2425
25- std::vector<uint8_t > s_der (PRIVATEKEY_SIZE);
26- s.getBigEndianBytes (&s_der[0 ]);
27-
28- encodeDER (toDER (r_der), toDER (s_der), signature);
26+ BIP66::encode (rValue, sValue , signature);
2927}
3028
3129bool cryptoVerify (Ark::Crypto::Identities::PublicKey publicKey, Sha256Hash hash, std::vector<uint8_t >& signature) {
@@ -52,12 +50,12 @@ bool cryptoVerify(Ark::Crypto::Identities::PublicKey publicKey, Sha256Hash hash,
5250 CurvePoint curvePoint (x, y);
5351
5452 /* Decode signature from DER into r & s buffers */
55- std::vector<uint8_t > r; // create r-value buffer
56- std::vector< uint8_t > s; // create s-value buffer
57- decodeDER (signature, r, s );
53+ std::vector<uint8_t > rValue (PRIVATEKEY_SIZE), sValue (PRIVATEKEY_SIZE);
54+
55+ BIP66::decode (signature, rValue, sValue );
5856
59- Uint256 r256 (r .data ()); // create Uint256/BigNumber from r-value buffer
60- Uint256 s256 (s .data ()); // create Uint256/BigNumber from s-value buffer
57+ Uint256 r256 (rValue .data ()); // create Uint256/BigNumber from r-value buffer
58+ Uint256 s256 (sValue .data ()); // create Uint256/BigNumber from s-value buffer
6159
6260 /* Verify */
6361 return Ecdsa::verify (curvePoint, hash, r256, s256);
0 commit comments