Skip to content

Commit f6b75a3

Browse files
committed
add cryptographic primitives
1 parent 0e91134 commit f6b75a3

28 files changed

Lines changed: 906 additions & 31 deletions

File tree

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@ result/
88
result
99
doc/README.md
1010
doc/proof-of-transport.md
11-
lib/algo
12-
lib/chain
13-
lib/crypto
11+
lib/chain

Cargo.lock

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

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ members = [
88
"app/simulation-item/switch",
99
"image",
1010
"image_util",
11+
12+
"lib/cryptography",
13+
"lib/cryptography_algorithm/dilithium3", # cryptography_algorithm_dilithium3
14+
"lib/cryptography_algorithm/ed25519", # cryptography_algorithm_ed25519
15+
"lib/cryptography_algorithm/kyber1024", # cryptography_algorithm_hyber1024
1116
"lib/e2e",
17+
"lib/kore",
18+
"lib/packet",
19+
1220
# ... coming soon ...
1321
"task",
1422

app/node/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ build = "build.rs"
77
publish = false
88

99
[dependencies]
10+
kore = { version = "*", path = "../../lib/kore" }
1011
bytes = "*"
1112
rand = "*"
1213
rand_core = "*"

app/node/src/cmn.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use super::*;
2+
3+
modwire::expose! {
4+
pub packet
5+
}

app/node/src/cmn/packet.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#[derive(Debug)]
2+
#[derive(Clone)]
3+
#[derive(PartialEq)]
4+
#[derive(Eq)]
5+
#[derive(derive_more::Deref)]
6+
#[derive(derive_more::DerefMut)]
7+
pub struct Packet<T> {
8+
phantom_data: std::marker::PhantomData<T>,
9+
pub peer: libp2p::PeerId,
10+
#[deref]
11+
#[deref_mut]
12+
pub content: bytes::Bytes
13+
}

app/node/src/identity.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,21 @@ use ed25519_dalek::Signer as _;
33
use ed25519::signature::Keypair as _;
44

55
pub mod commitment {
6+
use super::*;
7+
8+
// a packet which may or may not contain encrypted data
9+
pub struct Puzzle {
10+
11+
}
12+
613

14+
pub struct Accumulator {
15+
pkts: Vec<sub_system::stream::Packet<sub_system::broker::An>>
16+
}
17+
18+
impl Accumulator {
19+
pub fn store(&mut self, pkt: sub_system::stream::Packet<>)
20+
}
721
}
822

923
pub mod multi_party {
@@ -38,18 +52,18 @@ pub mod multi_party {
3852
}
3953

4054
impl Partial {
41-
pub fn sign(self, pk: PublicKey, sg: Signature) -> Result<Or<Self, CompleteVerified>> {
55+
pub fn sign(self, pk: PublicKey, sg: Signature) -> Result<kore::Or<Self, CompleteVerified>> {
4256
sg.verify(mg, &pk)?;
4357

4458
self.pk_to_sg.insert(pk, sg);
45-
Ok(Or::Lhs(self))
59+
Ok(kore::Or::Lhs(self))
4660
}
4761
}
4862

49-
impl TryFrom<Vec<u8>> for Partial {
63+
impl TryFrom<bytes::Bytes> for Partial {
5064
type Error = Box<dyn std::error::Error>;
5165

52-
fn try_from(value: Vec<u8>) -> std::result::Result<Self, Self::Error> {
66+
fn try_from(value: bytes::Bytes) -> std::result::Result<Self, Self::Error> {
5367

5468
}
5569
}
@@ -83,7 +97,7 @@ pub mod single_party {
8397
}
8498
}
8599

86-
impl Unpack<(PublicKey, Unsigned)> for SignedVerified {
100+
impl kore::Unpack<(PublicKey, Unsigned)> for SignedVerified {
87101
fn unpack(self) -> (PublicKey, Unsigned) {
88102
let mg: Unsigned = self.content.into();
89103
(self.pk, mg)

app/node/src/main.rs

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ use clap::Parser as _;
104104
use ubyte::ToByteUnit as _;
105105
use num::ToPrimitive as _;
106106

107+
mod cmn;
107108
mod config;
108109
mod identity;
109110
mod env_key;
@@ -112,14 +113,6 @@ mod saga;
112113
mod stream;
113114
mod sub_system;
114115

115-
#[derive(Debug)]
116-
#[derive(Clone)]
117-
#[derive(derive_more::From)]
118-
enum Or<A, B> {
119-
Lhs(A),
120-
Rhs(B)
121-
}
122-
123116
#[derive(Debug)]
124117
#[derive(Clone)]
125118
#[derive(PartialEq)]
@@ -192,25 +185,15 @@ struct Proof {
192185
relays: Vec<(identity::PublicKey, identity::Signature)>
193186
}
194187

195-
trait Unpack<T> {
196-
fn unpack(self) -> T;
197-
}
198-
199-
trait TryUnpack<T> {
200-
type Error;
201-
202-
fn unpack(self) -> std::result::Result<T, Self::Error>;
203-
}
204-
205188
/// External dns source of truth provider, may be swapped and implemented by
206189
/// other chains or networks, the nodes rely on this sytem for value transfer
207190
/// and cryptographic proofs
208191
#[async_trait::async_trait]
209192
trait Dns {
210193
async fn receive_attestation(
211194
&self,
212-
public_key: identity::PublicKey,
213-
signature: identity::Signature
195+
pk: identity::PublicKey,
196+
sg: identity::Signature
214197
) -> Result;
215198

216199
/// Receives a proof of trasit from src to dst through possible relays.
@@ -219,7 +202,7 @@ trait Dns {
219202
// for a given foreign key will return the onchain identity
220203
//
221204
// i own this pk offchain, this is who i am onchain
222-
async fn attestation(&self, key: identity::PublicKey) -> Result<Address>;
205+
async fn attestation(&self, pk: identity::PublicKey) -> Result<Address>;
223206

224207
async fn foreign_attestation(&self) -> Result<identity::PublicKey>;
225208

@@ -263,6 +246,61 @@ trait Dns {
263246
async fn age(&self, pk: identity::PublicKey) -> Result<Option<Age>>;
264247
}
265248

249+
#[derive(Debug)]
250+
struct StellarTestnet;
251+
252+
#[async_trait::async_trait]
253+
impl Dns for StellarTestnet {
254+
async fn receive_attestation(
255+
&self,
256+
pk: identity::PublicKey,
257+
sg: identity::Signature
258+
) -> Result {
259+
260+
}
261+
262+
async fn receive_proof(&self, proof: Proof) -> Result {
263+
264+
}
265+
266+
async fn attestation(&self, pk: identity::PublicKey) -> Result<Address> {
267+
268+
}
269+
270+
async fn renew(&self, domain: Domain) -> Result {
271+
todo!()
272+
}
273+
274+
async fn mint(&self, domain: Domain) -> Result {
275+
todo!()
276+
}
277+
278+
async fn congestion_charge(&self) -> Result<Fee> {
279+
todo!()
280+
}
281+
282+
async fn fee(&self) -> Result<Fee> {
283+
todo!()
284+
}
285+
286+
async fn traffic(&self, domain: Domain) -> Result<Traffic> {
287+
todo!()
288+
}
289+
290+
async fn total_spend(&self) -> Result<Balance> {
291+
todo!()
292+
}
293+
294+
async fn total_claim(&self) -> Result<Balance> {
295+
todo!()
296+
}
297+
298+
async fn age(&self, pk: identity::PublicKey) -> Result<Option<Age>> {
299+
todo!()
300+
}
301+
}
302+
303+
266304
type Result<T = ()> = std::result::Result<T, Box<dyn std::error::Error>>;
267305

268306
type Swarm = swarm::Swarm<Behaviour>;

app/node/src/saga/reservation.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,16 @@ where
139139
};
140140

141141
tokio::runtime::Handle::current().block_on(async move {
142-
dns.receive_proof(proof).await.unwrap();
142+
match dns.receive_proof(proof).await {
143+
Ok(_) => {
144+
145+
},
146+
Err(_) => {
147+
148+
}
149+
}
143150
});
144151

145-
146152
},
147153
_ => self
148154
}

0 commit comments

Comments
 (0)