-
Notifications
You must be signed in to change notification settings - Fork 0
Claim/encode decode #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements encoding and decoding for goset claim messages and updates related helper functions.
- Added encode/decode functionality for GOSetClaim with proper construction of the claim message.
- Updated the count and xor methods in GOSet, and added related tests.
- Introduced a public LENGTH constant for FeedId and GOSetXor to support the new implementations.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/lib.rs | Removed unused imports and commented out deprecated code |
| src/go_set/mod.rs | Implemented count and improved xor method with tests |
| src/go_set/go_set_xor.rs | Added LENGTH constant and exposed encoding functionality |
| src/go_set/go_set_claim.rs | Implemented encode and decode for goset claims with error handling |
| src/feed_id.rs | Added LENGTH constant to support encoding |
| const GOSET_DMX: [u8; 7] = [0, 1, 2, 3, 4, 5, 6]; | ||
| // TODO: calculate actual DMX | ||
| // ``` | ||
| // GOSET_DMX_MATERIAL = "tinySSB-0.1 GOset 1" | ||
| // GOSET_DMX = first 7 bytes of SHA256(GOSET_DMX_MATERIAL) | ||
| // ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 TODO
src/go_set/go_set_claim.rs
Outdated
| pub fn encode(go_set: &GOSet) -> [u8; 105] { | ||
| // NOTE: we're gonna want to make a range of claims | ||
| // 1. how do we deal with the concept of a "subset" of a claim? | ||
| // 2. where does the logic live about comparing a claim with a goset? | ||
| // 3. what's the algorithm for the claim-dance? | ||
|
|
||
| // [DMX (7B) | 'c' (1 byte) | lowest FeedId (32 bytes) | highest FeedId (32 bytes) | XOR (32 bytes) | cnt (1 byte) ] | ||
| let mut claim = [0; 105]; | ||
|
|
||
| let dmx = Self::GOSET_DMX; | ||
| let type_code: [u8; 1] = [b'c']; | ||
| let lowest_feed_id = go_set.lowest_feed_id().unwrap().encode(); | ||
| let highest_feed_id = go_set.highest_feed_id().unwrap().encode(); | ||
| let xor = go_set.xor().encode(); | ||
| let count: [u8; 1] = [go_set.count()]; | ||
|
|
||
| let chunks: [&[u8]; 6] = [ | ||
| &dmx, | ||
| &type_code, | ||
| &lowest_feed_id, | ||
| &highest_feed_id, | ||
| &xor, | ||
| &count, | ||
| ]; | ||
|
|
||
| let mut offset: usize = 0; | ||
| for chunk in chunks { | ||
| let len = chunk.len(); | ||
| claim[offset..offset + len].copy_from_slice(chunk); | ||
| offset += len; | ||
| } | ||
|
|
||
| claim | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the tidiest / most readable way I could write the pattern of concatenating / splitting.
I'm quite interested to know if there is a tidier was to concat/ split, as this feels... somewhat clunky (esp for concat).
ChatGPT suggested copy_from_slice which I was delighted to find. I was doing byte-wise copying before that!
Make some suggestions
Had a go at implementing encode/ decode on goset
claimmessages🔥 This PR is missing the calculation of
GOSET_CLAIM_DMX(needs some string encoding + hashing)