Skip to content

Commit d57fdcc

Browse files
feat: add DIG_MESSAGE opcode const (220) for directed dig-message envelopes (#3)
Additive public const `DIG_MESSAGE: u8 = 220` — the canonical wire opcode for a directed dig-message envelope (first of the free 220-255 band; 200-219 stay the consensus band, DigMessageType). The envelope rides as OPAQUE bytes in DigMessage.data; the transport never seals/opens it (WU6 of epic #796, Wave A). Release-first: this exposes the canonical const to the Wave-A/B dig-message consumers (dig-gossip mirrors it as ProtocolMessageTypes::DigMessage + dig_gossip::DIG_MESSAGE; dig-relay-protocol #874, dig-ipc-protocol #1074, ...). MINOR bump 0.1.2 -> 0.2.0. Refs #1164 #796 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4f31367 commit d57fdcc

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dig-protocol"
3-
version = "0.1.2"
3+
version = "0.2.0"
44
edition = "2021"
55
authors = ["Michael Taylor <michael@berkeleycompute.com>"]
66
description = "DIG Network L2 protocol types extending Chia's wire protocol (opcodes 200+)"

src/lib.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
//!
55
//! This crate re-exports the entire Chia protocol ecosystem (`chia-protocol`,
66
//! `chia-sdk-client`, `chia-ssl`, `chia-traits`) plus DIG-specific extensions
7-
//! (opcodes 200–219). Consumers depend on `dig-protocol` alone instead of
8-
//! importing multiple `chia-*` crates individually.
7+
//! (the `200..=219` consensus opcodes plus [`DIG_MESSAGE`] = 220, the directed
8+
//! dig-message envelope opcode). Consumers depend on `dig-protocol` alone instead
9+
//! of importing multiple `chia-*` crates individually.
910
//!
1011
//! ## What's included
1112
//!
@@ -80,3 +81,38 @@ pub use dig_message_type::{DigMessageType, UnknownDigMessageType};
8081
pub use introducer_wire::{
8182
RegisterAck, RegisterPeer, RequestPeersIntroducer, RespondPeersIntroducer,
8283
};
84+
85+
/// Wire opcode for a directed **dig-message** envelope (WU6, epic #796).
86+
///
87+
/// The `200..=219` band is the DIG L2 **consensus** band ([`DigMessageType`]); `220..=255`
88+
/// is the **free** band for directed application protocols. Opcode **220** carries a
89+
/// `dig-message` directed envelope as OPAQUE bytes in [`DigMessage::data`] — the transport
90+
/// (dig-gossip) never seals, opens, or parses it; end-to-end sealing to the recipient's DID
91+
/// key is `dig-message`'s job.
92+
///
93+
/// This is a cross-repo **canonical** constant — it MUST NOT drift. `dig-gossip` mirrors it
94+
/// as `dig_gossip::DIG_MESSAGE` (and `ProtocolMessageTypes::DigMessage`) for its transport.
95+
pub const DIG_MESSAGE: u8 = 220;
96+
97+
#[cfg(test)]
98+
mod dig_message_opcode_tests {
99+
use super::{DigMessage, DigMessageType, DIG_MESSAGE};
100+
101+
/// The opcode frames a real [`DigMessage`] and survives a wire round-trip with its
102+
/// `msg_type` intact — the canonical value (220) exercised through the actual encoder.
103+
#[test]
104+
fn dig_message_opcode_frames_and_round_trips() {
105+
let msg = DigMessage::new(DIG_MESSAGE, Some(9), vec![1, 2, 3].into());
106+
let back = DigMessage::from_bytes(&msg.to_bytes()).expect("round-trip");
107+
assert_eq!(back.msg_type, 220);
108+
assert_eq!(back.msg_type, DIG_MESSAGE);
109+
assert_eq!(back.data.as_ref(), &[1, 2, 3]);
110+
}
111+
112+
/// 220 is in the free band: it is NOT a consensus `DigMessageType` discriminant, so a
113+
/// consensus-band decode of the opcode fails — the two bands can never collide.
114+
#[test]
115+
fn dig_message_opcode_is_not_a_consensus_type() {
116+
assert!(DigMessageType::try_from(DIG_MESSAGE).is_err());
117+
}
118+
}

0 commit comments

Comments
 (0)