Skip to content

Commit 2ccba3f

Browse files
authored
chore: Reconcile shardeum to dev HEAD (#15)
1 parent 71544ab commit 2ccba3f

32 files changed

Lines changed: 3174 additions & 868 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ on:
1010
- main
1111
pull_request:
1212
branches:
13-
- dev
14-
- main
13+
- '**'
1514
issue_comment:
1615
inputs:
1716
workflowBranch:

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build
2+
node_modules
3+
dist
4+
target
5+
bin

CLAUDE.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Overview
6+
7+
lib-net is a hybrid TypeScript/Rust networking library (`@shardeum-foundation/lib-net`) that provides TCP-based JSON message passing between nodes with request/response patterns. The library uses native Rust code for performance-critical networking operations while exposing a TypeScript API for Node.js applications.
8+
9+
## Development Commands
10+
11+
### Building
12+
```bash
13+
# Full build (Rust + TypeScript)
14+
npm run build
15+
16+
# Build only TypeScript
17+
npm run build-node
18+
19+
# Build only Rust (debug mode)
20+
npm run build-rust-debug
21+
22+
# Build only Rust (release mode)
23+
npm run build-rust-release
24+
```
25+
26+
### Testing
27+
```bash
28+
# Run all tests
29+
npm test
30+
31+
# Run Rust tests
32+
npm run test:cargo
33+
# or
34+
cargo test
35+
36+
# Run specific integration tests
37+
npm run it-test
38+
npm run it-test2
39+
```
40+
41+
### Code Quality
42+
```bash
43+
# Run ESLint
44+
npm run lint
45+
46+
# Check formatting
47+
npm run format-check
48+
49+
# Fix formatting
50+
npm run format-fix
51+
```
52+
53+
### Release Process
54+
```bash
55+
# Patch release (1.6.0 -> 1.6.1)
56+
npm run release:patch
57+
58+
# Minor release (1.6.0 -> 1.7.0)
59+
npm run release:minor
60+
61+
# Major release (1.6.0 -> 2.0.0)
62+
npm run release:major
63+
64+
# Pre-release versions
65+
npm run release:prepatch
66+
npm run release:preminor
67+
npm run release:premajor
68+
npm run release:prerelease
69+
```
70+
71+
## Architecture
72+
73+
### Directory Structure
74+
- `src/`: TypeScript source code - API layer and Node.js bindings
75+
- `shardus_net/`: Main Rust crate implementing core networking functionality
76+
- `crypto/`: Rust crate for cryptographic operations (signing, verification)
77+
- `shardeum_utils/`: Shared Rust utilities
78+
- `test/`: Test files (unit tests in `test/unit/`, integration tests in root)
79+
- `build/`: TypeScript compilation output
80+
- `coverage/`: Test coverage reports
81+
82+
### Key Components
83+
84+
1. **TypeScript Layer** (`src/`)
85+
- `index.ts`: Main entry point, exports the network creation function
86+
- Handles Node.js integration and provides JavaScript-friendly API
87+
- Manages correlation of requests/responses using UUIDs
88+
89+
2. **Rust Layer** (`shardus_net/`)
90+
- `lib.rs`: Main Rust library entry point
91+
- Compiles to `shardus-net.node` native module
92+
- Implements high-performance TCP socket handling
93+
- Features compression (flate2, brotli) and LRU caching
94+
- Uses Tokio for async runtime
95+
96+
3. **Message Flow**
97+
- Messages are JSON-serialized with UUID correlation IDs
98+
- Supports request/response pattern with timeouts
99+
- Can send to multiple nodes simultaneously
100+
- Headers support compression options
101+
102+
### Build Process
103+
1. Rust code compiles to a C dynamic library (`cdylib`)
104+
2. `cargo-cp-artifact` copies the compiled artifact to `shardus-net.node`
105+
3. TypeScript compiles to JavaScript in `build/` directory
106+
4. The `postinstall` script automatically builds Rust code when installing
107+
108+
## Important Notes
109+
110+
- **Node.js Version**: Requires exactly Node.js 18.19.1
111+
- **Main Branch**: Development happens on `dev` branch (not `main` or `master`)
112+
- **Native Module**: The Rust code compiles to a native Node.js module - platform-specific builds required
113+
- **Security**: Follow responsible disclosure per SECURITY.md for vulnerabilities
114+
- **Testing**: Always run both TypeScript and Rust tests before submitting changes

Cargo.lock

Lines changed: 17 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SECURITY.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Security Policy
2+
3+
## Reporting a Vulnerability
4+
5+
If you believe you’ve found a security vulnerability in this project, we strongly encourage responsible disclosure and will work with you to resolve the issue promptly.
6+
7+
Please **do not** create a public issue or discuss the vulnerability in public forums.
8+
9+
### 🔒 Preferred Methods of Disclosure
10+
11+
You have two options to report security issues:
12+
13+
1. **Private Disclosure via GitHub (Recommended)**
14+
15+
- Use the **"Report a vulnerability"** button in the GitHub repository's **/security/advisories** page.
16+
- This will privately notify the maintainers through GitHub’s security advisory workflow.
17+
18+
2. **Email**
19+
- Send a detailed report to: **security at shardeum dot org**
20+
21+
### What to Include
22+
23+
To help us understand and resolve the issue quickly, please include (where possible):
24+
25+
- A detailed description of the vulnerability
26+
- Steps to reproduce it
27+
- Any relevant proof-of-concept code
28+
- The potential impact or affected components
29+
30+
### What to Expect
31+
32+
- We will acknowledge your report within **3 business days**.
33+
- We will investigate and confirm the issue.
34+
- If a fix is needed, we’ll prepare a patch and may issue a **GitHub Security Advisory** (and CVE if applicable).
35+
- We’ll keep you informed throughout the process and credit you if appropriate.
36+
37+
We appreciate your efforts in keeping our project and its users safe.
38+
39+
### Responsible Disclosure Guidelines
40+
41+
When conducting security research and reporting vulnerabilities, we request that you:
42+
43+
- Make every effort to avoid privacy violations, degradation of user experience, disruption to production systems, and destruction or manipulation of data.
44+
- Only interact with accounts or data that you own or have explicit permission to access.
45+
- Limit the amount of data you access or download to the minimum necessary to demonstrate the vulnerability.
46+
- Do not use a vulnerability to gain persistent access to systems or exfiltrate sensitive information.
47+
- Report the vulnerability to us as soon as you discover it.
48+
- Allow us a reasonable timeframe to investigate, fix, and announce the vulnerability before making it public.
49+
50+
## Supported Versions
51+
52+
We only provide security updates for the **latest stable release**. Make sure you're up-to-date.
53+
54+
### 🛡️ Safe Harbor
55+
56+
We consider security research conducted in accordance with this policy to be authorized. If you make a good faith effort to discover and report vulnerabilities by following these guidelines, we will not initiate legal action against you or ask law enforcement to investigate you. If any third party initiates legal action against you related to research conducted under this policy, we will make it known that your actions were authorized by us.
57+
58+
---
59+
60+
Thank you for helping improve the security of this project!

crypto/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ impl ShardusCrypto {
9292
}
9393
}
9494

95+
pub fn hashslice(&self, input: &[u8], fmt: Format) -> HexStringOrBuffer {
96+
let digest = sodiumoxide::crypto::generichash::hash(input, Some(32), Some(&self.hash_key)).expect("Cannot digest input");
97+
98+
match fmt {
99+
Format::Hex => HexStringOrBuffer::Hex(sodiumoxide::hex::encode(&digest)),
100+
Format::Buffer => HexStringOrBuffer::Buffer(digest.as_ref().to_vec()),
101+
}
102+
}
103+
95104
/// Signs the input data using the provided secret key.
96105
///
97106
/// # Arguments

jest.config.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
module.exports = {
33
preset: 'ts-jest',
44
testEnvironment: 'node',
5-
roots: [
6-
"<rootDir>/test/unit"
7-
],
8-
testMatch: [
9-
"**/__tests__/**/*.+(ts|tsx|js)",
10-
"**/?(*.)+(spec|test).+(ts|tsx|js)"
11-
],
5+
roots: ['<rootDir>/test/unit'],
6+
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
127
transform: {
13-
"^.+\\.(ts|tsx)$": "ts-jest"
8+
'^.+\\.(ts|tsx)$': 'ts-jest',
149
},
15-
};
10+
setupFiles: ['<rootDir>/test/jest.setup.js'],
11+
}

0 commit comments

Comments
 (0)