Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 77ec592672 | |||
| 9451fed838 | |||
| 61fecb0757 | |||
| af767856f0 | |||
| 02d48ecc72 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cryptoforknote-util",
|
||||
"version": "5.0.0",
|
||||
"version": "7.0.1",
|
||||
"main": "cryptoforknote-util",
|
||||
"author": {
|
||||
"name": "LucasJones",
|
||||
|
||||
@@ -16,6 +16,10 @@ namespace crypto {
|
||||
}
|
||||
|
||||
#pragma pack(push, 1)
|
||||
POD_CLASS cycle {
|
||||
public:
|
||||
uint32_t data[32];
|
||||
};
|
||||
POD_CLASS hash {
|
||||
char data[HASH_SIZE];
|
||||
};
|
||||
|
||||
+10
-7
@@ -3,11 +3,14 @@
|
||||
#define CURRENT_TRANSACTION_VERSION 1
|
||||
|
||||
enum BLOB_TYPE {
|
||||
BLOB_TYPE_CRYPTONOTE = 0,
|
||||
BLOB_TYPE_FORKNOTE1 = 1,
|
||||
BLOB_TYPE_FORKNOTE2 = 2,
|
||||
BLOB_TYPE_CRYPTONOTE2 = 3, // Masari
|
||||
BLOB_TYPE_CRYPTONOTE_RYO = 4, // Ryo
|
||||
BLOB_TYPE_CRYPTONOTE_LOKI = 5, // Loki
|
||||
BLOB_TYPE_CRYPTONOTE3 = 6, // Masari
|
||||
BLOB_TYPE_CRYPTONOTE = 0,
|
||||
BLOB_TYPE_FORKNOTE1 = 1,
|
||||
BLOB_TYPE_FORKNOTE2 = 2,
|
||||
BLOB_TYPE_CRYPTONOTE2 = 3, // Masari
|
||||
BLOB_TYPE_CRYPTONOTE_RYO = 4, // Ryo
|
||||
BLOB_TYPE_CRYPTONOTE_LOKI = 5, // Loki
|
||||
BLOB_TYPE_CRYPTONOTE3 = 6, // Masari
|
||||
BLOB_TYPE_AEON = 7, // Aeon
|
||||
BLOB_TYPE_CRYPTONOTE_CUCKOO8 = 8, // MoneroV / Swap
|
||||
BLOB_TYPE_CRYPTONOTE_CUCKOO = 9, // XTNC
|
||||
};
|
||||
|
||||
@@ -429,14 +429,27 @@ namespace cryptonote
|
||||
uint8_t minor_version;
|
||||
uint64_t timestamp;
|
||||
crypto::hash prev_id;
|
||||
uint32_t nonce;
|
||||
uint64_t nonce;
|
||||
uint64_t nonce8;
|
||||
crypto::cycle cycle;
|
||||
|
||||
BEGIN_SERIALIZE()
|
||||
VARINT_FIELD(major_version)
|
||||
VARINT_FIELD(minor_version)
|
||||
if (blob_type != BLOB_TYPE_FORKNOTE2) VARINT_FIELD(timestamp)
|
||||
FIELD(prev_id)
|
||||
if (blob_type != BLOB_TYPE_FORKNOTE2) FIELD(nonce)
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO8) FIELD(nonce8)
|
||||
if (blob_type != BLOB_TYPE_FORKNOTE2) {
|
||||
if (blob_type == BLOB_TYPE_AEON) {
|
||||
FIELD(nonce)
|
||||
} else {
|
||||
uint32_t nonce32;
|
||||
if (typename Archive<W>::is_saving()) nonce32 = (uint32_t)nonce;
|
||||
FIELD_N("nonce", nonce32);
|
||||
if (!typename Archive<W>::is_saving()) nonce = nonce32;
|
||||
}
|
||||
}
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO || blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO8) FIELD(cycle)
|
||||
END_SERIALIZE()
|
||||
};
|
||||
|
||||
|
||||
@@ -429,13 +429,24 @@ namespace cryptonote
|
||||
//---------------------------------------------------------------
|
||||
bool get_block_hashing_blob(const block& b, blobdata& blob)
|
||||
{
|
||||
blob = t_serializable_object_to_blob(static_cast<const block_header&>(b));
|
||||
if (b.blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO || b.blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO8) {
|
||||
blob = t_serializable_object_to_blob(b.major_version);
|
||||
blob.append(reinterpret_cast<const char*>(&b.minor_version), sizeof(b.minor_version));
|
||||
blob.append(reinterpret_cast<const char*>(&b.timestamp), sizeof(b.timestamp));
|
||||
blob.append(reinterpret_cast<const char*>(&b.prev_id), sizeof(b.prev_id));
|
||||
}
|
||||
else {
|
||||
blob = t_serializable_object_to_blob(static_cast<const block_header&>(b));
|
||||
}
|
||||
crypto::hash tree_root_hash = get_tx_tree_hash(b);
|
||||
blob.append(reinterpret_cast<const char*>(&tree_root_hash), sizeof(tree_root_hash));
|
||||
blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
|
||||
if (b.blob_type == BLOB_TYPE_CRYPTONOTE3) {
|
||||
blob.append(reinterpret_cast<const char*>(&b.uncle), sizeof(b.uncle));
|
||||
}
|
||||
if (b.blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO8) {
|
||||
blob.append(reinterpret_cast<const char*>(&b.nonce8), sizeof(b.nonce8));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
|
||||
+12
-5
@@ -191,11 +191,6 @@ NAN_METHOD(construct_block_blob) { // (parentBlockTemplateBuffer, nonceBuffer, c
|
||||
Local<Object> nonce_buf = info[1]->ToObject();
|
||||
|
||||
if (!Buffer::HasInstance(block_template_buf) || !Buffer::HasInstance(nonce_buf)) return THROW_ERROR_EXCEPTION("Both arguments should be buffer objects.");
|
||||
if (Buffer::Length(nonce_buf) != 4) return THROW_ERROR_EXCEPTION("Nonce buffer has invalid size.");
|
||||
|
||||
uint32_t nonce = *reinterpret_cast<uint32_t*>(Buffer::Data(nonce_buf));
|
||||
blobdata block_template_blob = std::string(Buffer::Data(block_template_buf), Buffer::Length(block_template_buf));
|
||||
blobdata output = "";
|
||||
|
||||
enum BLOB_TYPE blob_type = BLOB_TYPE_CRYPTONOTE;
|
||||
if (info.Length() >= 3) {
|
||||
@@ -203,6 +198,12 @@ NAN_METHOD(construct_block_blob) { // (parentBlockTemplateBuffer, nonceBuffer, c
|
||||
blob_type = static_cast<enum BLOB_TYPE>(Nan::To<int>(info[2]).FromMaybe(0));
|
||||
}
|
||||
|
||||
if (Buffer::Length(nonce_buf) != (blob_type == BLOB_TYPE_AEON ? 8 : 4)) return THROW_ERROR_EXCEPTION("Nonce buffer has invalid size.");
|
||||
|
||||
uint64_t nonce = blob_type == BLOB_TYPE_AEON ? *reinterpret_cast<uint64_t*>(Buffer::Data(nonce_buf)) : *reinterpret_cast<uint32_t*>(Buffer::Data(nonce_buf));
|
||||
blobdata block_template_blob = std::string(Buffer::Data(block_template_buf), Buffer::Length(block_template_buf));
|
||||
blobdata output = "";
|
||||
|
||||
block b = AUTO_VAL_INIT(b);
|
||||
b.set_blob_type(blob_type);
|
||||
if (!parse_and_validate_block_from_blob(block_template_blob, b)) return THROW_ERROR_EXCEPTION("Failed to parse block");
|
||||
@@ -215,6 +216,12 @@ NAN_METHOD(construct_block_blob) { // (parentBlockTemplateBuffer, nonceBuffer, c
|
||||
if (!mergeBlocks(parent_block, b, std::vector<crypto::hash>())) return THROW_ERROR_EXCEPTION("Failed to postprocess mining block");
|
||||
}
|
||||
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO || blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO8) {
|
||||
if (info.Length() != 4) return THROW_ERROR_EXCEPTION("You must provide 4 arguments.");
|
||||
Local<Array> cycle = Local<Array>::Cast(info[3]);
|
||||
for (int i = 0; i < 32; i++ ) b.cycle.data[i] = cycle->Get(i)->NumberValue();
|
||||
}
|
||||
|
||||
if (!block_to_blob(b, output)) return THROW_ERROR_EXCEPTION("Failed to convert block to blob");
|
||||
|
||||
v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked();
|
||||
|
||||
@@ -53,12 +53,14 @@ bool do_serialize(Archive<true> &ar, std::vector<crypto::signature> &v)
|
||||
|
||||
BLOB_SERIALIZER(crypto::chacha8_iv);
|
||||
BLOB_SERIALIZER(crypto::hash);
|
||||
BLOB_SERIALIZER(crypto::cycle);
|
||||
BLOB_SERIALIZER(crypto::hash8);
|
||||
BLOB_SERIALIZER(crypto::public_key);
|
||||
BLOB_SERIALIZER(crypto::secret_key);
|
||||
BLOB_SERIALIZER(crypto::key_derivation);
|
||||
BLOB_SERIALIZER(crypto::key_image);
|
||||
BLOB_SERIALIZER(crypto::signature);
|
||||
VARIANT_TAG(debug_archive, crypto::cycle, "cycle");
|
||||
VARIANT_TAG(debug_archive, crypto::hash, "hash");
|
||||
VARIANT_TAG(debug_archive, crypto::hash8, "hash8");
|
||||
VARIANT_TAG(debug_archive, crypto::public_key, "public_key");
|
||||
|
||||
Reference in New Issue
Block a user