Skip to content

Commit

Permalink
chore: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
detherminal committed Jan 30, 2024
1 parent 414ae99 commit 42a6e53
Show file tree
Hide file tree
Showing 16 changed files with 240 additions and 276 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/rust_integration_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Rust Integration Tests

on:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Rust
uses: actions/setup-rust@v2
with:
toolchain: stable

- name: Build and Test
run: |
cargo build --verbose
cargo test --verbose
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repository = "https://github.com/monumexyz/libmonero"
readme = "README.md"
keywords = ["monero", "monero-library"]
categories = ["monero", "monero-library"]
exclude = ["main.rs"]

[dependencies]
base58-monero = "2.0.0"
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

> DISCLAIMER: This library is still in early development and doesn't have a stable version yet. It is not ready for production use and not cryptographically audited. We are working hard to make it as secure as possible. Please use it at your own risk.
libmonero is a library for the Monero cryptocurrency written in Rust. It is designed to be fast, safe and easy to use.
libmonero is a powerful, batteries-included library for the Monero cryptocurrency written in Rust. It is designed to be fast, safe and easy to use.

[Why another library?](#why-another-library)

Expand All @@ -28,7 +28,18 @@ And many more features... ([Roadmap](#roadmap))
Add the library to your project and use the functions: \
```cargo add libmonero```

For more details, please take a look at [docs](docs/start.md)
For more details, please take a look at [docs](https://docs.rs/libmonero).

## Sponsoring

You can sponsor this project for 20$/month. If you sponsor this project, you will get the following benefits:

- Mention in the README.md (with your logo and link to your website if you want)
- Request features or bugfixes
- Priority support
- Special role in the matrix room

If you want to sponsor this project, please contact us at the matrix room: [#monume:matrix.org](https://matrix.to/#/#monume:matrix.org)

## Licensing

Expand Down
28 changes: 0 additions & 28 deletions docs/examples.md

This file was deleted.

125 changes: 0 additions & 125 deletions docs/functions.md

This file was deleted.

18 changes: 0 additions & 18 deletions docs/start.md

This file was deleted.

42 changes: 0 additions & 42 deletions docs/structs.md

This file was deleted.

3 changes: 2 additions & 1 deletion precommit.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/sh
cd scripts && python3 copyright.py
cargo clippy --fix --lib -p libmonero --allow-dirty # For fixing clippy warnings
cargo clippy --fix --lib -p libmonero --allow-staged --allow-dirty # For fixing clippy warnings
cargo test
2 changes: 2 additions & 0 deletions scripts/copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def add_text_to_files(folder_path, text, ignored_extensions=[]):
file.write(text + '\n' + ''.join(lines))

def main():
print("Starting copyright script")
add_text_to_files(path, header, ignore)
print("Finished adding copyright headers")

if __name__ == "__main__":
main()
18 changes: 0 additions & 18 deletions src/crypt/cryptonight/aesu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,4 @@ fn shift_rows(block: &mut [u8]) {
block[col * 4 + 3] = block[col * 4 - 1];
}
block[3] = tmp;
}

pub fn aes_round16(blocks: &[u8; 16], round_keys: &[u8; 16]) -> [u8; 16] {
let mut block = *blocks;
let mut round_key = *round_keys;

aes_round(&mut block, &round_key);
round_key.rotate_left(4);

aes_round(&mut block, &round_key);
round_key.rotate_left(4);

aes_round(&mut block, &round_key);
round_key.rotate_left(4);

aes_round(&mut block, &round_key);

block
}
15 changes: 12 additions & 3 deletions src/crypt/cryptonight/slow_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ use crate::crypt::cryptonight::aesu::{aes_round, xor};

const SCRATCHPAD_SIZE: usize = 2 * 1024 * 1024; // 2 MiB

/// Main CryptoNight function defined in: https://web.archive.org/web/20190911221902/https://cryptonote.org/cns/cns008.txt
/// It is used in previous block hash calculation and in PoW calculation
/// Main CryptoNight function defined in: <https://web.archive.org/web/20190911221902/https://cryptonote.org/cns/cns008.txt>
///
/// Even though it's actually implemented in Rust for [Cuprate](https://github.com/Cuprate/cuprate), anyone can use it.
///
/// Example:
/// ```
/// use libmonero::crypt::cryptonight::slow_hash::cn_slow_hash;
///
/// let input: &str = "This is a test";
/// let output: String = cn_slow_hash(input.as_bytes());
/// assert_eq!(output, "a084f01d1437a09c6985401b60d43554ae105802c5f5d8a9b3253649c0be6605".to_string());
/// ```
pub fn cn_slow_hash(input: &[u8]) -> String {
// CryptoNight Step 1: Initialization Of Scratchpad

Expand Down Expand Up @@ -192,7 +202,6 @@ pub fn cn_slow_hash(input: &[u8]) -> String {

// Step 3C: Use the first byte of the Keccak state to select a hash function
let hash_function = keccak_hash[0] & 0x03;
println!("hash_function: {:?}", hash_function);
let final_byte = match hash_function {
0 => blake256_hash(keccak_hash),
1 => groestl256_hash(keccak_hash),
Expand Down
Loading

0 comments on commit 42a6e53

Please sign in to comment.