gn-native 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +23 -0
- package/README.md +135 -0
- package/gn-l0-multicorpus.snapshot +1 -0
- package/gn-native.linux-x64-gnu.node +0 -0
- package/index.d.ts +0 -0
- package/package.json +33 -0
- package/src/lib.rs +652 -0
- package/src/vtc_patch.rs +43 -0
package/src/vtc_patch.rs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
use napi_derive::napi;
|
|
2
|
+
use napi::bindgen_prelude::*;
|
|
3
|
+
use sha2::{Sha256, Digest};
|
|
4
|
+
|
|
5
|
+
#[napi]
|
|
6
|
+
pub async fn gn_compress_fractal_with_vtc(
|
|
7
|
+
data: Buffer,
|
|
8
|
+
shard_type: String,
|
|
9
|
+
session_id: String,
|
|
10
|
+
) -> Result<String> {
|
|
11
|
+
|
|
12
|
+
let frame = crate::gn_compress_fractal(
|
|
13
|
+
data.clone(),
|
|
14
|
+
shard_type.clone(),
|
|
15
|
+
session_id.clone()
|
|
16
|
+
).await?;
|
|
17
|
+
|
|
18
|
+
let mut hasher = Sha256::new();
|
|
19
|
+
|
|
20
|
+
// domain separation
|
|
21
|
+
hasher.update(shard_type.as_bytes());
|
|
22
|
+
|
|
23
|
+
if frame.len() > 5 {
|
|
24
|
+
let pairs_len = u16::from_le_bytes([frame[1], frame[2]]) as usize;
|
|
25
|
+
let l3_len = u16::from_le_bytes([frame[3], frame[4]]) as usize;
|
|
26
|
+
|
|
27
|
+
let start = 5 + l3_len;
|
|
28
|
+
let end = start + pairs_len;
|
|
29
|
+
|
|
30
|
+
if end <= frame.len() {
|
|
31
|
+
hasher.update(&frame[start..end]);
|
|
32
|
+
} else {
|
|
33
|
+
hasher.update(&frame);
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
hasher.update(&frame);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let hash = hasher.finalize();
|
|
40
|
+
let vtc = format!("VTC-v1-{}", hex::encode(&hash[..16]));
|
|
41
|
+
|
|
42
|
+
Ok(vtc)
|
|
43
|
+
}
|